private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(cbxQuizName.Text)) { FISCA.Presentation.Controls.MsgBox.Show("請選擇測驗名稱."); return; } if (dtAnalysisDate.IsEmpty) { FISCA.Presentation.Controls.MsgBox.Show("請輸入解析日期."); return; } if (dtImplementationDate.IsEmpty) { FISCA.Presentation.Controls.MsgBox.Show("請輸入實施日期."); return; } foreach (DataGridViewRow dr in dgQuizData.Rows) { int errCot = 0; if (dr.Cells[colDataField.Index].ErrorText != "") { errCot++; } if (errCot > 0) { FISCA.Presentation.Controls.MsgBox.Show("資料有錯誤無法儲存."); return; } } LogData(); if (_StudQuizData == null) { _StudQuizData = new DAO.UDT_StudQuizDataDef(); } _StudQuizData.StudentID = int.Parse(_StudentID); _StudQuizData.ImplementationDate = dtImplementationDate.Value; _StudQuizData.AnalysisDate = dtAnalysisDate.Value; List <XElement> xmlList = new List <XElement>(); foreach (DataGridViewRow dgvr in dgQuizData.Rows) { if (dgvr.IsNewRow) { continue; } XElement elm = new XElement("Item"); if (dgvr.Cells[colDataField.Index].Value != null) { elm.SetAttributeValue("name", dgvr.Cells[colDataField.Index].Value.ToString()); } if (dgvr.Cells[colDataValue.Index].Value != null) { elm.SetAttributeValue("value", dgvr.Cells[colDataValue.Index].Value.ToString()); } xmlList.Add(elm); } _StudQuizData.Content = Utility.ConvertXmlListToString1(xmlList); if (_EditMode == EditMode.Edit) { _UDTTransfer.UpdateStudQuizData(_StudQuizData); // log _LogTransfer.SaveChangeLog("學生.輔導測驗相關-修改", "修改", _LogStudentName + ",修改測驗名稱:" + cbxQuizName.Text + "\n", "", "student", _StudentID); } else { // 取得所選測驗ID foreach (DAO.UDT_QuizDef data in _AllQuiz.Where(x => x.QuizName == cbxQuizName.Text)) { _StudQuizData.QuizID = int.Parse(data.UID); } // 檢查學生測驗是否有名稱id if (_StudQuizData.QuizID < 1) { FISCA.Presentation.Controls.MsgBox.Show("測驗名稱無法對應."); return; } bool pass = true; // 檢查學生測驗資料是否有相同:測驗名稱 if (_StudQuizDataList == null) { _StudQuizDataList = new List <DAO.UDT_StudQuizDataDef>(); } foreach (DAO.UDT_StudQuizDataDef data in _StudQuizDataList.Where(x => x.QuizID == _StudQuizData.QuizID)) { pass = false; } if (pass == false) { FISCA.Presentation.Controls.MsgBox.Show("已有相同測驗名稱無法新增."); return; } if (pass) { _UDTTransfer.InsertStudQuizData(_StudQuizData); _LogTransfer.SaveInsertLog("學生.輔導相關測驗-新增", "新增", _LogStudentName + ",新增測驗名稱:" + cbxQuizName.Text + "\n", "", "student", _StudentID); } } _LogTransfer.Clear(); LogData(); this.Close(); }