void _bgWorkerLoad_DoWork(object sender, DoWorkEventArgs e) { // 取得學生類別 _StudentTagList = QueryTransfer.GetStudentTagList(); _SelectMappingDict1 = GetExcessCreditsBase1(); _SelectMappingDict2 = GetExcessCreditsBase2(); _SelectMappingDict3 = GetExcessCreditsBase3(); // 取得設定檔 _UDTConfigList = UDTTransfer.UDTConfigSelectByName(conf_name); if (_UDTConfigList.Count > 0) { UDTConfig cd = _UDTConfigList[0]; if (!string.IsNullOrWhiteSpace(cd.Data)) { try { _ConfigXML = XElement.Parse(cd.Data); } catch { } } } }
// 儲存畫面資料轉 XML private bool SaveConfigData() { bool pass = true; // 檢查畫面資料是否有選 foreach (DataGridViewRow row in dgStudD1.Rows) { if (row.IsNewRow) { continue; } foreach (DataGridViewCell cell in row.Cells) { if (cell.Value == null) { row.ErrorText = "不允許空值!"; pass = false; } } } // 檢查畫面資料是否有選 foreach (DataGridViewRow row in dgStudD2.Rows) { if (row.IsNewRow) { continue; } foreach (DataGridViewCell cell in row.Cells) { if (cell.Value == null) { row.ErrorText = "不允許空值!"; pass = false; } } } if (pass == false) { MsgBox.Show("畫面設定有錯誤,請檢查!"); return(pass); } XElement elm = new XElement(rootName); if (string.IsNullOrEmpty(cboType1.Text)) { elm.SetElementValue("地區代碼", ""); } else { elm.SetElementValue("地區代碼", cboType1.Text); } if (string.IsNullOrEmpty(cboType2.Text)) { elm.SetElementValue("低收入戶", ""); } else { elm.SetElementValue("低收入戶", cboType2.Text); } if (string.IsNullOrEmpty(cboType3.Text)) { elm.SetElementValue("中低收入戶", ""); } else { elm.SetElementValue("中低收入戶", cboType3.Text); } if (string.IsNullOrEmpty(cboType4.Text)) { elm.SetElementValue("失業勞工", ""); } else { elm.SetElementValue("失業勞工", cboType4.Text); } if (string.IsNullOrEmpty(cboType5.Text)) { elm.SetElementValue("地址", ""); } else { elm.SetElementValue("地址", cboType5.Text); } if (string.IsNullOrEmpty(cboType6.Text)) { elm.SetElementValue("市內電話", ""); } else { elm.SetElementValue("市內電話", cboType6.Text); } // 學生身分 if (dgStudD1.Rows.Count > 0) { XElement elm1 = new XElement("學生身分"); foreach (DataGridViewRow dr in dgStudD1.Rows) { if (dr.IsNewRow) { continue; } string name = "", value = ""; if (dr.Cells[dgSel1cbo1.Index].Value != null) { name = dr.Cells[dgSel1cbo1.Index].Value.ToString(); } if (dr.Cells[dgSel1cbo2.Index].Value != null) { value = dr.Cells[dgSel1cbo2.Index].Value.ToString(); } if (name != "" && value != "") { XElement elm1s = new XElement("item"); elm1s.SetAttributeValue("name", name); elm1s.SetAttributeValue("value", value); elm1.Add(elm1s); } } elm.Add(elm1); } // 身心障礙 if (dgStudD2.Rows.Count > 0) { XElement elm2 = new XElement("身心障礙"); foreach (DataGridViewRow dr in dgStudD2.Rows) { if (dr.IsNewRow) { continue; } string name = "", value = ""; if (dr.Cells[dgSel2cbo1.Index].Value != null) { name = dr.Cells[dgSel2cbo1.Index].Value.ToString(); } if (dr.Cells[dgSel2cbo2.Index].Value != null) { value = dr.Cells[dgSel2cbo2.Index].Value.ToString(); } if (name != "" && value != "") { XElement elm2s = new XElement("item"); elm2s.SetAttributeValue("name", name); elm2s.SetAttributeValue("value", value); elm2.Add(elm2s); } } elm.Add(elm2); } // 儲存資料 UDTConfig conf = new UDTConfig(); conf.Name = conf_name; conf.Data = elm.ToString(); // 更新 if (_UDTConfigList.Count > 0) { _UDTConfigList[0].Name = conf.Name; _UDTConfigList[0].Data = conf.Data; UDTTransfer.UDTConfigUpdate(_UDTConfigList); } else { // 新增 List <UDTConfig> addList = new List <UDTConfig>(); addList.Add(conf); UDTTransfer.UDTConfigInsert(addList); } return(pass); }