/// <summary> /// 選擇試別時觸發。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cboExamList_SelectedIndexChanged(object sender, EventArgs e) { if (cboExamList.SelectedItem == null) { return; } ExamComboBoxItem item = cboExamList.SelectedItem as ExamComboBoxItem; HC.JHAEIncludeRecord aeIncludeRecord = item.AEIncludeRecord; dgv.SuspendLayout(); #region 依 AEIncludeRecord 決定哪些 Column 要顯示 chInputScore.Visible = aeIncludeRecord.UseScore; chInputAssignmentScore.Visible = aeIncludeRecord.UseAssignmentScore; chInputText.Visible = aeIncludeRecord.UseText; #endregion GetScoresAndFill(aeIncludeRecord); LoadDvScoreColor(); dgv.ResumeLayout(); SetLoadDataToLog(); }
/// <summary> /// 按下「儲存」時觸發。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { dgv.EndEdit(); if (!IsValid()) { MsgBox.Show("請先修正錯誤再儲存。"); return; } try { List <SCETakeRecordEditor> editors = MakeSCETakeRecordEditors(); if (editors.Count > 0) { editors.SaveAllEditors(); } MsgBox.Show("儲存成功。"); ExamComboBoxItem item = cboExamList.SelectedItem as ExamComboBoxItem; GetScoresAndFill(item.AEIncludeRecord); } catch (Exception ex) { MsgBox.Show("儲存失敗。\n" + ex.Message); //throw ex; } }
/// <summary> /// 更新畫面 /// </summary> private void ReLoad() { _dirtyCellList.Clear(); lblSave.Visible = false; _SceTakeDic.Clear(); ExamComboBoxItem cboitem = _cboSelectedItem as ExamComboBoxItem; _RunningExamId = cboitem.Value + ""; _RunningExamName = cboitem.DisplayText; List <JHSCETakeRecord> records = JHSCETake.SelectByCourseAndExam(_course.ID, _RunningExamId); foreach (JHSCETakeRecord record in records) { if (!_SceTakeDic.ContainsKey(record.RefStudentID)) { _SceTakeDic.Add(record.RefStudentID, new SCETakeRecord(record)); } } foreach (DataGridViewRow row in dgv.Rows) { //學生ID string sid = row.Tag + ""; //Cell初值設定 row.Cells[chInputScore.Index].Value = ""; row.Cells[chInputAssignmentScore.Index].Value = ""; //有紀錄則填值 if (_SceTakeDic.ContainsKey(sid)) { row.Cells[chInputScore.Index].Value = _SceTakeDic[sid].ExamScore; row.Cells[chInputAssignmentScore.Index].Value = _SceTakeDic[sid].RegularScore; } //將Cell的值填入tag作dirty判斷 row.Cells[chInputScore.Index].Tag = row.Cells[chInputScore.Index].Value; row.Cells[chInputAssignmentScore.Index].Tag = row.Cells[chInputAssignmentScore.Index].Value; //文字顏色修正 FixTextColor(row.Cells[chInputScore.Index]); FixTextColor(row.Cells[chInputAssignmentScore.Index]); } pictureBox1.Visible = false; }
/// <summary> /// 從DataGridView上取得SCETakeRecordEditors /// </summary> /// <returns></returns> //private List<SCETakeRecordEditor> MakeSCETakeRecordEditors() //{ // if (cboExamList.SelectedItem == null) return new List<SCETakeRecordEditor>(); // List<SCETakeRecordEditor> list = new List<SCETakeRecordEditor>(); // ExamComboBoxItem item = cboExamList.SelectedItem as ExamComboBoxItem; // ExamRecord exam = item.AEIncludeRecord.Exam; // foreach (DataGridViewRow row in dgv.Rows) // { // SCAttendTag tag = row.Tag as SCAttendTag; // if (tag.SCETake != null) // { // #region 修改or刪除 // bool is_remove = true; // SCETakeRecordEditor editor = tag.SCETake.GetEditor(); // if (chInputScore.Visible == true) // { // string value = "" + row.Cells[chInputScore.Index].Value; // is_remove &= string.IsNullOrEmpty(value); // if (!string.IsNullOrEmpty(value)) // editor.Score = decimal.Parse(value); // } // if (chInputEffort.Visible == true) // { // string value = "" + row.Cells[chInputEffort.Index].Value; // is_remove &= string.IsNullOrEmpty(value); // if (!string.IsNullOrEmpty(value)) // editor.Effort = int.Parse(value); // } // if (chInputText.Visible == true) // { // string value = "" + row.Cells[chInputText.Index].Value; // is_remove &= string.IsNullOrEmpty(value); // editor.Text = value; // } // editor.Remove = is_remove; // list.Add(editor); // #endregion // } // else // { // #region 新增 // bool is_add = false; // SCETakeRecordEditor editor = new SCETakeRecordEditor(tag.SCAttend, exam); // if (chInputScore.Visible == true) // { // string value = "" + row.Cells[chInputScore.Index].Value; // if (!string.IsNullOrEmpty(value)) // { // editor.Score = decimal.Parse(value); // is_add = true; // } // } // if (chInputEffort.Visible == true) // { // string value = "" + row.Cells[chInputEffort.Index].Value; // if (!string.IsNullOrEmpty(value)) // { // editor.Effort = int.Parse(value); // is_add = true; // } // } // if (chInputText.Visible == true) // { // string value = "" + row.Cells[chInputText.Index].Value; // if (!string.IsNullOrEmpty(value)) // { // editor.Text = value; // is_add = true; // } // } // if (is_add) list.Add(editor); // #endregion // } // } // return list; //} /// <summary> /// 從DataGridView上取得 HC.JHSCETakeRecord /// </summary> /// <returns></returns> private RecordIUDLists GetRecords() { if (cboExamList.SelectedItem == null) { return(new RecordIUDLists()); } RecordIUDLists lists = new RecordIUDLists(); ExamComboBoxItem item = cboExamList.SelectedItem as ExamComboBoxItem; JHExamRecord exam = item.AEIncludeRecord.Exam; foreach (DataGridViewRow row in dgv.Rows) { SCAttendTag tag = row.Tag as SCAttendTag; if (tag.SCETake != null) { HC.JHSCETakeRecord record = tag.SCETake; #region 修改or刪除 bool is_remove = true; if (chInputScore.Visible == true) { string value = ("" + row.Cells[chInputScore.Index].Value).Trim(); if (PluginMain.ScoreTextMap.ContainsKey(value)) { value = PluginMain.ScoreTextMap[value].UseValue.ToString(); } is_remove &= string.IsNullOrEmpty(value); if (!string.IsNullOrEmpty(value)) { record.Score = decimal.Parse(value); } // 小郭, 2013/12/30 else { record.Score = null; } } if (chInputAssignmentScore.Visible == true) { string value = ("" + row.Cells[chInputAssignmentScore.Index].Value).Trim(); if (PluginMain.ScoreTextMap.ContainsKey(value)) { value = PluginMain.ScoreTextMap[value].UseValue.ToString(); } is_remove &= string.IsNullOrEmpty(value); if (!string.IsNullOrEmpty(value)) { record.AssignmentScore = decimal.Parse(value); } // 小郭, 2013/12/30 else { record.AssignmentScore = null; } } if (chInputText.Visible == true) { string value = "" + row.Cells[chInputText.Index].Value; is_remove &= string.IsNullOrEmpty(value); record.Text = value; } if (is_remove) { lists.DeleteList.Add(record); } else { lists.UpdateList.Add(record); } #endregion } else { #region 新增 bool is_add = false; JHSchool.Data.JHSCETakeRecord jh = new JHSchool.Data.JHSCETakeRecord(); HC.JHSCETakeRecord record = new HC.JHSCETakeRecord(jh); record.RefCourseID = tag.SCAttend.Course.ID; record.RefExamID = exam.ID; record.RefSCAttendID = tag.SCAttend.ID; record.RefStudentID = tag.SCAttend.Student.ID; record.Score = null; record.AssignmentScore = null; record.Text = string.Empty; if (chInputScore.Visible == true) { string value = ("" + row.Cells[chInputScore.Index].Value).Trim(); if (PluginMain.ScoreTextMap.ContainsKey(value)) { value = PluginMain.ScoreTextMap[value].UseValue.ToString(); } if (!string.IsNullOrEmpty(value)) { record.Score = decimal.Parse(value); is_add = true; } } if (chInputAssignmentScore.Visible == true) { string value = ("" + row.Cells[chInputAssignmentScore.Index].Value).Trim(); if (PluginMain.ScoreTextMap.ContainsKey(value)) { value = PluginMain.ScoreTextMap[value].UseValue.ToString(); } if (!string.IsNullOrEmpty(value)) { record.AssignmentScore = decimal.Parse(value); is_add = true; } } if (chInputText.Visible == true) { string value = "" + row.Cells[chInputText.Index].Value; if (!string.IsNullOrEmpty(value)) { record.Text = value; is_add = true; } } if (is_add) { lists.InsertList.Add(record); } #endregion } } return(lists); }
/// <summary> /// 按下「儲存」時觸發。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(cboExamList.Text)) { FISCA.Presentation.Controls.MsgBox.Show("沒有試別無法儲存."); return; } dgv.EndEdit(); if (!IsValid()) { MsgBox.Show("請先修正錯誤再儲存。"); return; } try { //List<SCETakeRecordEditor> editors = MakeSCETakeRecordEditors(); //if (editors.Count > 0) editors.SaveAll(); bool checkLoadSave = false; RecordIUDLists lists = GetRecords(); // 檢查超過 0~100 if (lists.DeleteList.Count > 0) { foreach (HsinChu.JHEvaluation.Data.HC.JHSCETakeRecord sc in lists.DeleteList) { if (sc.AssignmentScore.HasValue) { if ((sc.AssignmentScore < 0 && !PluginMain.ScoreValueMap.ContainsKey(sc.AssignmentScore.Value)) || sc.AssignmentScore > 100) { checkLoadSave = true; } } if (sc.Score.HasValue) { if ((sc.Score < 0 && !PluginMain.ScoreValueMap.ContainsKey(sc.Score.Value)) || sc.Score > 100) { checkLoadSave = true; } } } } if (lists.InsertList.Count > 0) { foreach (HsinChu.JHEvaluation.Data.HC.JHSCETakeRecord sc in lists.InsertList) { if (sc.AssignmentScore.HasValue) { if ((sc.AssignmentScore < 0 && !PluginMain.ScoreValueMap.ContainsKey(sc.AssignmentScore.Value)) || sc.AssignmentScore > 100) { checkLoadSave = true; } } if (sc.Score.HasValue) { if ((sc.Score < 0 && !PluginMain.ScoreValueMap.ContainsKey(sc.Score.Value)) || sc.Score > 100) { checkLoadSave = true; } } } } if (lists.UpdateList.Count > 0) { foreach (HsinChu.JHEvaluation.Data.HC.JHSCETakeRecord sc in lists.UpdateList) { if (sc.AssignmentScore.HasValue) { if ((sc.AssignmentScore < 0 && !PluginMain.ScoreValueMap.ContainsKey(sc.AssignmentScore.Value)) || sc.AssignmentScore > 100) { checkLoadSave = true; } } if (sc.Score.HasValue) { if ((sc.Score < 0 && !PluginMain.ScoreValueMap.ContainsKey(sc.Score.Value)) || sc.Score > 100) { checkLoadSave = true; } } } } if (checkLoadSave) { CheckSaveForm csf = new CheckSaveForm(); csf.ShowDialog(); if (csf.DialogResult == DialogResult.Cancel) { return; } } if (lists.InsertList.Count > 0) { JHSchool.Data.JHSCETake.Insert(lists.InsertList.AsJHSCETakeRecords()); } if (lists.UpdateList.Count > 0) { JHSchool.Data.JHSCETake.Update(lists.UpdateList.AsJHSCETakeRecords()); } if (lists.DeleteList.Count > 0) { JHSchool.Data.JHSCETake.Delete(lists.DeleteList.AsJHSCETakeRecords()); } //記憶所選的試別 Campus.Configuration.ConfigData cd = Campus.Configuration.Config.User["新竹課程成績輸入考試別"]; cd["新竹課程成績輸入考試別"] = cboExamList.Text; cd.Save(); MsgBox.Show("儲存成功。"); // 記修改後 log SetSaveDataToLog(); // 存 Log prlp.SetActionBy("課程", "課程成績輸入"); prlp.SetAction("課程成績輸入"); prlp.SetDescTitle(""); prlp.SaveLog("", "", "Course", _course.ID); // 重新記修改前 Log SetLoadDataToLog(); ExamComboBoxItem item = cboExamList.SelectedItem as ExamComboBoxItem; GetScoresAndFill(item.AEIncludeRecord); } catch (Exception ex) { MsgBox.Show("儲存失敗。\n" + ex.Message); //throw ex; } // // 載入分數顏色 LoadDvScoreColor(); }
/// <summary> /// 從DataGridView上取得SCETakeRecordEditors /// </summary> /// <returns></returns> private List <SCETakeRecordEditor> MakeSCETakeRecordEditors() { if (cboExamList.SelectedItem == null) { return(new List <SCETakeRecordEditor>()); } List <SCETakeRecordEditor> list = new List <SCETakeRecordEditor>(); ExamComboBoxItem item = cboExamList.SelectedItem as ExamComboBoxItem; ExamRecord exam = item.AEIncludeRecord.Exam; foreach (DataGridViewRow row in dgv.Rows) { SCAttendTag tag = row.Tag as SCAttendTag; if (tag.SCETake != null) { #region 修改or刪除 bool is_remove = true; SCETakeRecordEditor editor = tag.SCETake.GetEditor(); if (chInputScore.Visible == true) { string value = "" + row.Cells[chInputScore.Index].Value; is_remove &= string.IsNullOrEmpty(value); if (!string.IsNullOrEmpty(value)) { editor.Score = decimal.Parse(value); } } if (chInputEffort.Visible == true) { string value = "" + row.Cells[chInputEffort.Index].Value; is_remove &= string.IsNullOrEmpty(value); if (!string.IsNullOrEmpty(value)) { editor.Effort = int.Parse(value); } } if (chInputText.Visible == true) { string value = "" + row.Cells[chInputText.Index].Value; is_remove &= string.IsNullOrEmpty(value); editor.Text = value; } editor.Remove = is_remove; list.Add(editor); #endregion } else { #region 新增 bool is_add = false; SCETakeRecordEditor editor = new SCETakeRecordEditor(new PrivateSCAttendRecord(tag.SCAttend), exam); if (chInputScore.Visible == true) { string value = "" + row.Cells[chInputScore.Index].Value; if (!string.IsNullOrEmpty(value)) { editor.Score = decimal.Parse(value); is_add = true; } } if (chInputEffort.Visible == true) { string value = "" + row.Cells[chInputEffort.Index].Value; if (!string.IsNullOrEmpty(value)) { editor.Effort = int.Parse(value); is_add = true; } } if (chInputText.Visible == true) { string value = "" + row.Cells[chInputText.Index].Value; if (!string.IsNullOrEmpty(value)) { editor.Text = value; is_add = true; } } if (is_add) { list.Add(editor); } #endregion } } return(list); }