Skip to content

Commit cf7be68

Browse files
committed
1.0.3
Fixed all known issues: 1- Group controling. 2- No more fix loop. 3- Optimizing Excel. 4- Fix students data file.
1 parent 9dfab8f commit cf7be68

File tree

229 files changed

+493483
-1063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+493483
-1063
lines changed

.vs/CourseManagementSystem/v15/.suo

-29 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

CMSLibrary/CMSLibrary.csproj

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<WarningLevel>4</WarningLevel>
3232
</PropertyGroup>
3333
<ItemGroup>
34+
<Reference Include="Aspose.Cells, Version=19.11.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
35+
<HintPath>..\packages\Aspose.Cells.19.11.0\lib\net40\Aspose.Cells.dll</HintPath>
36+
</Reference>
3437
<Reference Include="Dapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
3538
<HintPath>..\packages\Dapper.2.0.30\lib\net461\Dapper.dll</HintPath>
3639
</Reference>
@@ -91,24 +94,6 @@
9194
<None Include="packages.config" />
9295
</ItemGroup>
9396
<ItemGroup>
94-
<COMReference Include="Microsoft.Office.Core">
95-
<Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
96-
<VersionMajor>2</VersionMajor>
97-
<VersionMinor>8</VersionMinor>
98-
<Lcid>0</Lcid>
99-
<WrapperTool>primary</WrapperTool>
100-
<Isolated>False</Isolated>
101-
<EmbedInteropTypes>True</EmbedInteropTypes>
102-
</COMReference>
103-
<COMReference Include="Microsoft.Office.Interop.Excel">
104-
<Guid>{00020813-0000-0000-C000-000000000046}</Guid>
105-
<VersionMajor>1</VersionMajor>
106-
<VersionMinor>9</VersionMinor>
107-
<Lcid>0</Lcid>
108-
<WrapperTool>primary</WrapperTool>
109-
<Isolated>False</Isolated>
110-
<EmbedInteropTypes>True</EmbedInteropTypes>
111-
</COMReference>
11297
<COMReference Include="VBIDE">
11398
<Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
11499
<VersionMajor>5</VersionMajor>

CMSLibrary/Evaluation/Evaluate.cs

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void FixingErrors()
3939
foreach(StudentAnswersModel ans in StudentsAnswersWithErrors)
4040
{
4141
bool isDuplicate = false;
42+
bool hasGroup = true;
4243
StudentModel model = GlobalConfig.Connection.GetStudent_ByRegNo(ans.Student.RegNo);
4344
var duplicate = StudentsAnswers.Find(s => s.Student.RegNo == model.RegNo);
4445
if (duplicate != null)
@@ -49,12 +50,21 @@ public void FixingErrors()
4950
err.Add(duplicate);
5051
StudentsAnswers.Remove(duplicate);
5152
}
53+
if(ans.Group.Name == "" || ans.Group.Name == " ")
54+
{
55+
hasGroup = false;
56+
model = null;
57+
}
5258
if (model == null)
5359
{
5460
if (isDuplicate)
5561
{
5662
ans.ErrorType = "Duplicated Value, Fix RegNo";
5763
}
64+
else if(!hasGroup)
65+
{
66+
ans.ErrorType = "No Group";
67+
}
5868
else
5969
{
6070
ans.ErrorType = "Student not found in DB";
@@ -64,6 +74,14 @@ public void FixingErrors()
6474
else
6575
{
6676
ans.Student = model;
77+
foreach (AnswerKeyModel answerKey in AnswerKeys)
78+
{
79+
if (answerKey.Group.Name == ans.Group.Name)
80+
{
81+
ans.AnswersList = ans.AnswersList.Substring(0, answerKey.QuestionCount);
82+
break;
83+
}
84+
}
6785
StudentsAnswers.Add(ans);
6886
}
6987
}
@@ -100,6 +118,7 @@ public List<StudentAnswersModel> GetStudentsAnswers(string studentListPath)
100118
StudentModel model;
101119
int regNo = 0;
102120
bool isDuplicate = false;
121+
bool isRightName = true;
103122
if (Int32.TryParse(listString.Substring(24, 9), out regNo))
104123
{
105124
model = GlobalConfig.Connection.GetStudent_ByRegNo(regNo);
@@ -108,11 +127,10 @@ public List<StudentAnswersModel> GetStudentsAnswers(string studentListPath)
108127
{
109128
if (model.FirstName != NamesFixer(listString.Substring(0, 12)))
110129
{
130+
isRightName = false;
111131
model = null;
112132
}
113-
}
114-
115-
133+
}
116134
if (model != null)
117135
{
118136
var duplicate = StudentsAnswers.Find(s => s.Student.RegNo == model.RegNo);
@@ -136,41 +154,70 @@ public List<StudentAnswersModel> GetStudentsAnswers(string studentListPath)
136154
{
137155
studentAnswers.ErrorType = "Duplicated Value, Fix RegNo";
138156
}
157+
else if(!isRightName)
158+
{
159+
studentAnswers.ErrorType = "Wrong Name, Check Student List";
160+
}
139161
else
140162
{
141163
studentAnswers.ErrorType = "Student not found in DB";
142164
}
143165

144166
studentAnswers.Student.FirstName = listString.Substring(0, 12);
145167
studentAnswers.Student.LastName = listString.Substring(12, 12);
146-
studentAnswers.Student.RegNo = regNo;
147-
studentAnswers.Group.Name = listString.Substring(33, 1);
148-
foreach (AnswerKeyModel answerKey in AnswerKeys)
168+
studentAnswers.Student.RegNo = regNo;
169+
try
149170
{
150-
if (answerKey.Group.Name == studentAnswers.Group.Name)
171+
StudentDataModel t = new StudentDataModel
151172
{
152-
studentAnswers.AnswersList = listString.Substring(34, answerKey.QuestionCount);
153-
break;
173+
Group = listString.Substring(33, 1)
174+
};
175+
studentAnswers.Group.Name = listString.Substring(33, 1);
176+
foreach (AnswerKeyModel answerKey in AnswerKeys)
177+
{
178+
if (answerKey.Group.Name == studentAnswers.Group.Name)
179+
{
180+
studentAnswers.AnswersList = listString.Substring(34, answerKey.QuestionCount);
181+
break;
182+
}
154183
}
155184
}
185+
catch (Exception e)
186+
{
187+
Console.WriteLine(e.Message);
188+
studentAnswers.AnswersList = listString.Substring(34, listString.Length - 34);
189+
studentAnswers.ErrorType = "No Group";
190+
}
156191
StudentsAnswersWithErrors.Add(studentAnswers);
157192
}
158193
else
159194
{
160-
studentAnswers.Student = model;
161-
//studentAnswers.Student.FirstName = listString.Substring(0, 12);
162-
//studentAnswers.Student.LastName = listString.Substring(12, 12);
163-
//studentAnswers.Student.RegNo = Int32.Parse(listString.Substring(24, 9));
164-
studentAnswers.Group.Name = listString.Substring(33, 1);
165-
foreach (AnswerKeyModel answerKey in AnswerKeys)
166-
{
167-
if (answerKey.Group.Name == studentAnswers.Group.Name)
195+
try
196+
{
197+
studentAnswers.Student = model;
198+
StudentDataModel t = new StudentDataModel
168199
{
169-
studentAnswers.AnswersList = listString.Substring(34, answerKey.QuestionCount);
170-
break;
200+
Group = listString.Substring(33, 1)
201+
};
202+
studentAnswers.Group.Name = listString.Substring(33, 1);
203+
foreach (AnswerKeyModel answerKey in AnswerKeys)
204+
{
205+
if (answerKey.Group.Name == studentAnswers.Group.Name)
206+
{
207+
studentAnswers.AnswersList = listString.Substring(34, answerKey.QuestionCount);
208+
break;
209+
}
171210
}
211+
StudentsAnswers.Add(studentAnswers);
172212
}
173-
StudentsAnswers.Add(studentAnswers);
213+
catch (Exception e)
214+
{
215+
Console.WriteLine(e.Message);
216+
studentAnswers.AnswersList = listString.Substring(34, listString.Length - 34);
217+
studentAnswers.ErrorType = "No Group";
218+
StudentsAnswersWithErrors.Add(studentAnswers);
219+
}
220+
174221
}
175222

176223
}

CMSLibrary/Evaluation/Excel.cs

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,54 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
6-
using Microsoft.Office.Interop.Excel;
7-
using _Excel = Microsoft.Office.Interop.Excel;
7+
using Aspose.Cells;
88

99
namespace CMSLibrary.Evaluation
1010
{
1111
public class Excel
12-
{
13-
//string path = "";
14-
_Application excel = new _Excel.Application();
15-
Workbook wb;
16-
Worksheet ws;
17-
public Excel()
18-
{
19-
20-
}
21-
/*
22-
public Excel (string path, int sheet)
23-
{
24-
this.path = path;
25-
wb = excel.Workbooks.Open(path);
26-
ws = excel.Worksheets[sheet];
27-
}*/
12+
{
13+
Workbook wb = new Workbook();
14+
string[][,] DataArray = { new string [1000,105],
15+
new string [500,5],
16+
new string [500,7]};
2817

29-
public void CreateNewFile()
18+
19+
public Excel(int studentsCount, int questionsCount, int outcomesCount)
3020
{
31-
wb=excel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
32-
ws = wb.Worksheets[1];
21+
string[][,] DataArray =
22+
{
23+
new string [studentsCount + 30, 105],
24+
new string [questionsCount + 20, 5],
25+
new string [outcomesCount + 20, 7]
26+
};
27+
wb.Worksheets.Clear();
28+
wb.Worksheets.Add("Students Statistics");
29+
wb.Worksheets.Add("Questions Statistics");
30+
wb.Worksheets.Add("Outcomes Statistics");
3331
}
34-
public void CreateNewSheet()
35-
{
36-
wb.Worksheets.Add(After:ws);
37-
ws = wb.Worksheets[2];
32+
33+
public void WriteToCell(int row, int col, string content, int sheetIndex)
34+
{
35+
DataArray[sheetIndex][row, col] = content;
3836
}
3937

40-
public decimal ReadCell(int i, int j)
38+
public void WriteFile()
4139
{
42-
i++;
43-
j++;
44-
if(ws.Cells[i, j].Value2 != null)
40+
for (int i = 0; i < 3; i++)
4541
{
46-
return Convert.ToDecimal(ws.Cells[i, j].Value2);
42+
wb.Worksheets[i].Cells.ImportTwoDimensionArray(DataArray[i], 0, 0, true);
43+
wb.Worksheets[i].AutoFitColumns();
4744
}
48-
else
49-
{
50-
return -1;
51-
}
52-
5345
}
54-
public void WriteToCell(int i, int j, string s)
55-
{
56-
i++;
57-
j++;
58-
ws.Cells[i, j].Value2 = s;
5946

60-
}
61-
public void SelectWorkSheet(int sheetNumber)
62-
{
63-
ws = wb.Worksheets[sheetNumber];
64-
65-
}
66-
public void Save()
67-
{
68-
wb.Save();
69-
}
7047
public void SaveAs(string path)
7148
{
72-
wb.SaveAs(path);
73-
}
74-
public void Close()
75-
{
76-
wb.Close();
77-
}
49+
WriteFile();
50+
wb.Save(path);
51+
}
7852

7953
}
8054
}

CMSLibrary/Evaluation/StudentDataModel.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,23 @@ public int RegNo
5555
}
5656
}
5757

58+
private string _group;
5859

60+
[Required(ErrorMessage = "Must not be empty.")]
61+
[GroupCount(ErrorMessage = "Format error")]
62+
public string Group
63+
{
64+
get { return _group; }
65+
set
66+
{
67+
ValidateProperty(value, "Group");
68+
OnPropertyChanged(ref _group, value);
69+
}
70+
}
5971

6072

73+
public string AnswersList { get; set; }
74+
6175
private void ValidateProperty<T>(T value, string name)
6276
{
6377
Validator.ValidateProperty(value, new ValidationContext(this, null, null)
@@ -103,4 +117,25 @@ public override bool IsValid(object value)
103117
return isValid;
104118
}
105119
}
120+
121+
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
122+
public class GroupCount : ValidationAttribute
123+
{
124+
public override bool IsValid(object value)
125+
{
126+
string inputValue = value.ToString();
127+
var isValid = true;
128+
129+
if (inputValue.Length > 1)
130+
{
131+
isValid = false;
132+
}
133+
if(!(inputValue == "A" || inputValue == "B" || inputValue == "C" || inputValue == "D"))
134+
{
135+
isValid = false;
136+
}
137+
138+
return isValid;
139+
}
140+
}
106141
}

0 commit comments

Comments
 (0)