public void EventInfo() { var id = new Guid(); var dt = DateTime.Now; EventInformation cons = new CourseInformation("test-room", dt, TimeSpan.Zero, "test-teacher", id); EventInformation test = new CourseInformation("test-room", dt, TimeSpan.Zero, "test-teacher", id); Assert.IsTrue(cons.Equals(test)); Assert.IsTrue(cons == test == cons.Equals(test)); Assert.IsTrue(cons != test == !cons.Equals(test)); cons = new CourseInformation("cons-room", dt, TimeSpan.Zero, "test-teacher", id); Assert.IsFalse(cons.Equals(test)); Assert.IsTrue(cons == test == cons.Equals(test)); Assert.IsTrue(cons != test == !cons.Equals(test)); cons = new ExamInformation("test-room", dt, TimeSpan.Zero, id); Assert.IsFalse(cons.Equals(test)); Assert.IsTrue(cons == test == cons.Equals(test)); Assert.IsTrue(cons != test == !cons.Equals(test)); test = new ExamInformation("test-room", dt, TimeSpan.Zero, id); Assert.IsTrue(cons.Equals(test)); Assert.IsTrue(cons == test == cons.Equals(test)); Assert.IsTrue(cons != test == !cons.Equals(test)); cons = new ExamInformation("cons-room", dt, TimeSpan.Zero, id); Assert.IsFalse(cons.Equals(test)); Assert.IsTrue(cons == test == cons.Equals(test)); Assert.IsTrue(cons != test == !cons.Equals(test)); }
public object getDetailExam(int id) { ExamInformation examInformation = new ExamInformation(); var query = from T in context.Tests join E in context.Exams on T.ExamId equals E.Id join C in context.Categorys on E.Category.Id equals C.Id where T.Id == id select new { T.TestName, T.TestTime, E.QuestionNumber, C.Name, T.Id, }; examInformation.TestName = query.FirstOrDefault().TestName; examInformation.NumberChoiceQuestion = query.FirstOrDefault().QuestionNumber * 3 / 4; examInformation.NumberStatementQuestion = query.FirstOrDefault().QuestionNumber - examInformation.NumberChoiceQuestion; examInformation.TestTime = query.FirstOrDefault().TestTime; examInformation.CategoryName = query.FirstOrDefault().Name; examInformation.QuestionNumber = query.FirstOrDefault().QuestionNumber; examInformation.TotalScore = 10; return(examInformation); }
ExamInformation ISemesterExamRepository <SemesterExam> .GetTestDetail(int id) { var query = from T in context.Tests join E in context.Exams on T.ExamId equals E.Id join C in context.Categorys on E.Category.Id equals C.Id select new { T.TestName, T.TestTime, E.QuestionNumber, C.Name, }; ExamInformation examInformation = new ExamInformation(); examInformation.TestName = query.FirstOrDefault().TestName; examInformation.NumberChoiceQuestion = query.FirstOrDefault().QuestionNumber * 3 / 4; examInformation.NumberStatementQuestion = query.FirstOrDefault().QuestionNumber - examInformation.NumberChoiceQuestion; examInformation.TestTime = query.FirstOrDefault().TestTime; examInformation.CategoryName = query.FirstOrDefault().Name; examInformation.QuestionNumber = query.FirstOrDefault().QuestionNumber; examInformation.TotalScore = 100; return(examInformation); }
private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { ExamInformation exam = e.Row.Tag as ExamInformation; try { if (exam != null) { int templateCount = QueryExam.GetExamTemplateUseCount(exam.Identity); int textCount = QueryExam.GetTextScoreUseCount(exam.Identity); int numberCount = QueryExam.GetNumberScoreUseCount(exam.Identity); if (templateCount > 0 || textCount > 0 || numberCount > 0) { //string msg = "已有其他資料使用【{3}】,無法刪除。\n\n評量樣版使用數:{0}\n數字評量使用數:{1}\n文字評量使用數:{2}"; string msg = "已有其他資料使用【{0}】,無法刪除。"; //msg = string.Format(msg, templateCount, numberCount, textCount, exam.ExamName); msg = string.Format(msg, exam.ExamName); MsgBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; } } } catch (Exception ex) { //CurrentUser current = CurrentUser.Instance; //BugReporter.ReportException(current.SystemName, current.SystemVersion, ex, false); MsgBox.Show(ex.Message, Application.ProductName); } }
public ExamManager() { InitializeComponent(); List <int> cols = new List <int>() { 1 }; Campus.Windows.DataGridViewImeDecorator dec = new Campus.Windows.DataGridViewImeDecorator(this.dataGridView, cols); try { _exam_list = new Dictionary <string, ExamInformation>(); XmlElement list = QueryExam.GetAbstractList(); foreach (XmlElement node in list.SelectNodes("Exam")) { ExamInformation exam = new ExamInformation(node); int index = dataGridView.Rows.Add(); DataGridViewRow row = dataGridView.Rows[index]; row.Cells[0].Value = exam.ExamName; row.Cells[1].Value = exam.DisplayOrder; row.Tag = exam; _exam_list.Add(exam.Identity, exam); } } catch (Exception ex) { MsgBox.Show("載入評量資訊錯誤。"); btnSave.Enabled = false; } }
/// <summary> /// 此建構式用於更新時。 /// </summary> public ExamInformation(DataGridViewRow row) { ExamInformation exam = row.Tag as ExamInformation; if (exam != null) { Identity = exam.Identity; } else { Identity = "-1"; } ExamName = row.Cells[0].Value + string.Empty; DisplayOrder = row.Cells[1].Value + string.Empty; }
public void ContentChanging() { var id = new Guid(); var cons = new Course("test-course", id); var test = new Course("test-course", id); var course = new CourseInformation("test-room", DateTime.Now, TimeSpan.Zero, "test-teacher", id); var exam = new ExamInformation("test-room", DateTime.Now, TimeSpan.Zero, id); Assert.AreEqual(cons, test); Assert.IsFalse(test.Contains(course)); Assert.IsFalse(test.Contains(exam)); Assert.IsTrue(test.AddCourse(course)); Assert.IsFalse(test.AddCourse(course)); Assert.IsTrue(test.Contains(course)); Assert.IsFalse(test.Contains(exam)); Assert.IsTrue(test.AddExam(exam)); Assert.IsFalse(test.AddExam(exam)); Assert.IsTrue(test.Contains(course)); Assert.IsTrue(test.Contains(exam)); Assert.AreNotEqual(cons, test); Assert.IsTrue(test.DeleteCourse(course)); Assert.IsFalse(test.DeleteCourse(course)); Assert.IsTrue(test.DeleteExam(exam)); Assert.IsFalse(test.DeleteExam(exam)); Assert.AreEqual(cons, test); Assert.IsFalse(test.Contains(course)); Assert.IsFalse(test.Contains(exam)); Assert.IsTrue(test.AddCourse(course)); Assert.IsTrue(test.AddExam(exam)); Assert.IsTrue(test.Contains(course)); Assert.IsTrue(test.Contains(exam)); }
private void btnSave_Click(object sender, EventArgs e) { if (!ValidateAllCell()) { MsgBox.Show("資料有錯誤,請修改後再儲存。", Application.ProductName); return; } List <ExamInformation> newList = new List <ExamInformation>(); List <string> deleteList = new List <string>(); Dictionary <string, ExamInformation> updateList = new Dictionary <string, ExamInformation>(); //處理「新增」、「更新」。 foreach (DataGridViewRow row in dataGridView.Rows) { if (row.IsNewRow) { continue; //如果是 NewRow 不處理。 } ExamInformation exam = row.Tag as ExamInformation; //這裡取得的是舊資料。 if (exam == null) //用 exam 判斷這筆資料是否為新的。 { ExamInformation newExam = new ExamInformation(row); newList.Add(newExam); } else { ExamInformation updateExam = new ExamInformation(row); updateList.Add(updateExam.Identity, updateExam); //其他的都是更新。 } } //處理「刪除」。 foreach (string each in _exam_list.Keys) { bool deleteRequired = true; foreach (DataGridViewRow row in dataGridView.Rows) { if (row.Tag == null) { continue; } ExamInformation deleteExam = row.Tag as ExamInformation; if (deleteExam != null && each == deleteExam.Identity) { deleteRequired = false; } } if (deleteRequired) { deleteList.Add(each); } } if (deleteList.Count > 0) { try { EditExam.Delete(deleteList); } catch (Exception ex) { MsgBox.Show("刪除試別失敗:" + ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (updateList.Count > 0) { try { DSXmlHelper helper = new DSXmlHelper("UpdateRequest"); foreach (ExamInformation each in updateList.Values) { helper.AddElement("Exam"); helper.AddElement("Exam", "ExamName", each.ExamName); helper.AddElement("Exam", "DisplayOrder", each.DisplayOrder); helper.AddElement("Exam", "Condition"); helper.AddElement("Exam/Condition", "ID", each.Identity); } EditExam.Update(helper); } catch (Exception ex) { MsgBox.Show("修改試別失敗:" + ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (newList.Count > 0) { try { DSXmlHelper helper = new DSXmlHelper("InsertRequest"); foreach (ExamInformation each in newList) { helper.AddElement("Exam"); helper.AddElement("Exam", "ExamName", each.ExamName); helper.AddElement("Exam", "DisplayOrder", each.DisplayOrder); } EditExam.Insert(helper); } catch (Exception ex) { MsgBox.Show("新增試別失敗:" + ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.Close(); }