/// <summary> /// 依年級進行排序 /// </summary> private int SortDTClub(DTClub dt1, DTClub dt2) { return(dt1.GradeYear.CompareTo(dt2.GradeYear)); }
private void btnSave_Click(object sender, EventArgs e) { if (IsDataValidity()) { #region 儲存學年、學期紀錄 //填入之前的紀錄 if (opensemester.Count > 0) { opensemester[0].SchoolYear = comboBoxEx1.Text; opensemester[0].Semester = comboBoxEx2.Text; opensemester.SaveAll(); } else { UDT.OpenSchoolYearSemester config = new UDT.OpenSchoolYearSemester(); config.SchoolYear = comboBoxEx1.Text; config.Semester = comboBoxEx2.Text; config.Save(); } #endregion #region 資料正確,進行儲存 List <DTClub> DTClubList = new List <DTClub>(); foreach (DataGridViewRow each in dgvTimes.Rows) { string Grade = "" + each.Cells[chGradeYear.Index].Value; string Start1 = "" + each.Cells[chStartTime1.Index].Value; string End1 = "" + each.Cells[chEndTime1.Index].Value; string Start2 = "" + each.Cells[chStartTime2.Index].Value; string End2 = "" + each.Cells[chEndTime2.Index].Value; string stage1_Mode = "" + each.Cells[chStage1_Mode.Index].Value; string stage2_Mode = "" + each.Cells[chStage2_Mode.Index].Value; DTClub dt = new DTClub(); dt.GradeYear = int.Parse(Grade); if (!string.IsNullOrEmpty(Start1)) { dt.Start1 = DateTime.Parse(Start1); } if (!string.IsNullOrEmpty(End1)) { dt.End1 = DateTime.Parse(End1); } if (!string.IsNullOrEmpty(Start2)) { dt.Start2 = DateTime.Parse(Start2); } if (!string.IsNullOrEmpty(End2)) { dt.End2 = DateTime.Parse(End2); } if (!string.IsNullOrEmpty(stage1_Mode)) { dt.Stage1_Mode = stage1_Mode; } if (!string.IsNullOrEmpty(stage2_Mode)) { dt.Stage2_Mode = stage2_Mode; } DTClubList.Add(dt); } try { _AccessHelper.InsertValues(DTClubList); _AccessHelper.DeletedValues(Low_DTClubList); DTClubList.Sort(SortDTClub); StringBuilder sb = new StringBuilder(); sb.AppendLine("已修改開放選社時間"); foreach (DTClub each in DTClubList) { if (each.Start1.HasValue && each.End1.HasValue) { string start1 = each.Start1.HasValue ? each.Start1.Value.ToString("yyyy/MM/dd HH:mm") : ""; string end1 = each.End1.HasValue ? each.End1.Value.ToString("yyyy/MM/dd HH:mm") : ""; sb.AppendLine(string.Format("階段1" + "「{0}」年級:開始時間「{1}」結束時間「{2}」", each.GradeYear, start1, end1)); } if (each.Start2.HasValue && each.End2.HasValue) { string start2 = each.Start2.HasValue ? each.Start2.Value.ToString("yyyy/MM/dd HH:mm") : ""; string end2 = each.End2.HasValue ? each.End2.Value.ToString("yyyy/MM/dd HH:mm") : ""; sb.AppendLine(string.Format("階段" + "「{0}」年級:開始時間「{1}」結束時間「{2}」", each.GradeYear, start2, end2)); } } FISCA.LogAgent.ApplicationLog.Log("社團", "修改選社時間", sb.ToString()); } catch (Exception ex) { MsgBox.Show("儲存失敗!!\n" + ex.Message); SmartSchool.ErrorReporting.ReportingService.ReportException(ex); return; } MsgBox.Show("儲存成功!!"); this.Close(); #endregion } else { MsgBox.Show("畫面中含有不正確資料。"); } }