/// <summary> /// 設定畫面的預設狀況。 /// 例:一般:曠課,事假,病假;集合:曠課,事假,公假 /// </summary> /// <param name="content"></param> public void ApplySetting() { ResetValues(false); foreach (KeyValuePair <string, List <string> > type in SettingResult) { if (!RowIndexs.ContainsKey(type.Key)) { lblLost.Visible = true; continue; } int rowIndex = RowIndexs[type.Key]; foreach (string absence in type.Value) { if (!ColumnIndexs.ContainsKey(absence)) { lblLost.Visible = true; continue; } int columnIndex = ColumnIndexs[absence]; dgAbsence.Rows[rowIndex].Cells[columnIndex].Value = true; } } }
private void AbsenceTypeForm_Load(object sender, EventArgs e) { try { List <PeriodMappingInfo> periods = K12.Data.PeriodMapping.SelectAll(); UniqueSet <string> pSet = new UniqueSet <string>(); foreach (PeriodMappingInfo each in periods) { if (!pSet.Contains(each.Type)) { pSet.Add(each.Type); } } List <AbsenceMappingInfo> absences = K12.Data.AbsenceMapping.SelectAll(); UniqueSet <string> aSet = new UniqueSet <string>(); foreach (AbsenceMappingInfo each in absences) { if (!aSet.Contains(each.Name)) { aSet.Add(each.Name); } } dgAbsence.Columns.Clear(); dgAbsence.Columns.Add(chCatalog); foreach (string eachAbsence in aSet.ToList()) { int index = dgAbsence.Columns.Add(chAbsenceTemplate.Clone() as DataGridViewColumn); dgAbsence.Columns[index].HeaderText = eachAbsence; ColumnIndexs.Add(eachAbsence, index); } foreach (string eachType in pSet.ToList()) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dgAbsence); row.Cells[chCatalog.Index].Value = eachType; dgAbsence.Rows.Add(row); RowIndexs.Add(eachType, row.Index); } ApplySetting(); } catch (Exception ex) { MsgBox.Show(string.Format("顯示資料失敗({0})。", ex.Message)); } }