private void btnSave_Click(object sender, EventArgs e) { // 檢查資料是否又誤 if (itmPnlQuizName.SelectedItems.Count < 1) { FISCA.Presentation.Controls.MsgBox.Show("請選擇測驗."); return; } foreach (DataGridViewRow dr in dgDataField.Rows) { int errCot = 0; if (dr.Cells[colFieldName.Index].ErrorText != "") { errCot++; } if (dr.Cells[colDisplayOrder.Index].ErrorText != "") { errCot++; } if (errCot > 0) { FISCA.Presentation.Controls.MsgBox.Show("資料有錯誤無法儲存."); return; } } // 有修改名稱 if (txtQuizName.Text.Trim() != _selQuizName) { if (_QuizData.Select(x => x.QuizName).Contains(txtQuizName.Text.Trim())) { FISCA.Presentation.Controls.MsgBox.Show("已有相同名稱,無法修改!"); return; } } // 儲存資料 if (itmPnlQuizName.SelectedItems.Count == 1) { ButtonItem selItem = itmPnlQuizName.SelectedItems[0] as ButtonItem; DAO.UDT_QuizDef qd1 = selItem.Tag as DAO.UDT_QuizDef; if (selItem != null && qd1 != null) { qd1.QuizName = txtQuizName.Text.Trim(); List <XElement> xmlList = new List <XElement>(); List <string> itemList = new List <string>(); foreach (DataGridViewRow dgvr in dgDataField.Rows) { if (dgvr.IsNewRow) { continue; } if (("" + dgvr.Cells[colFieldName.Index].Value).Trim() == "") { continue; } XElement elm = new XElement("Field"); if (dgvr.Cells[colFieldName.Index].Value != null) { elm.SetAttributeValue("name", dgvr.Cells[colFieldName.Index].Value.ToString()); itemList.Add(dgvr.Cells[colFieldName.Index].Value.ToString()); } if (dgvr.Cells[colDisplayOrder.Index].Value != null) { elm.SetAttributeValue("order", dgvr.Cells[colDisplayOrder.Index].Value.ToString()); } xmlList.Add(elm); } _LogTransfer.SetLogValue("測驗名稱", txtQuizName.Text); _LogTransfer.SetLogValue("項目內容", string.Join(",", itemList.ToArray())); qd1.QuizDataField = Utility.ConvertXmlListToString1(xmlList); if (string.IsNullOrEmpty(qd1.UID)) { _LogTransfer.SaveInsertLog("輔導新增測驗", "新增", "", "", "", ""); _UDTTransfer.InsertQuizData(qd1); } else { _LogTransfer.SaveInsertLog("輔導修改測驗", "修改", "", "", "", ""); _UDTTransfer.UpdateQuizData(qd1); } } } FISCA.Presentation.Controls.MsgBox.Show("儲存完成."); LoadData(); }