/// <summary> /// 排序學期資料 /// </summary> private int SortRSRList(ResultScoreRecord a1, ResultScoreRecord b2) { string aa1 = a1.SchoolYear.ToString().PadLeft(3, '0'); aa1 += a1.Semester.ToString().PadLeft(2, '0'); string bb2 = b2.SchoolYear.ToString().PadLeft(3, '0'); bb2 += b2.Semester.ToString().PadLeft(2, '0'); return aa1.CompareTo(bb2); }
/// <summary> /// 按下儲存時 /// </summary> /// <param name="e"></param> protected override void OnSaveButtonClick(EventArgs e) { //資料檢查 if (!CheckCell()) { MsgBox.Show("请修正资料再储存!!"); return; } List<ResultScoreRecord> InsertList = new List<ResultScoreRecord>(); List<ResultScoreRecord> updateList = new List<ResultScoreRecord>(); //沒有Tag就是一筆新記錄 foreach (DataGridViewRow row in dataGridViewX1.Rows) { if (row.IsNewRow) continue; if (row.Tag == null) { ResultScoreRecord rsr = new ResultScoreRecord(); rsr.SchoolYear = int.Parse("" + row.Cells[0].Value); rsr.Semester = int.Parse("" + row.Cells[1].Value); //rsr.RefClubID = cr.UID; //社團ID rsr.RefStudentID = _Studentecord.ID; //學生ID //rsr.RefSCJoinID = scj.UID; //參與記錄ID rsr.ClubName = "" + row.Cells[2].Value; decimal xy; if (decimal.TryParse("" + row.Cells[3].Value, out xy)) { rsr.ResultScore = xy; //成績 } rsr.CadreName = "" + row.Cells[4].Value; //幹部 InsertList.Add(rsr); } else { ResultScoreRecord rsr = (ResultScoreRecord)row.Tag; rsr.SchoolYear = int.Parse("" + row.Cells[0].Value); rsr.Semester = int.Parse("" + row.Cells[1].Value); rsr.ClubName = "" + row.Cells[2].Value; decimal xy; if (!string.IsNullOrEmpty("" + row.Cells[3].Value)) { if (decimal.TryParse("" + row.Cells[3].Value, out xy)) { rsr.ResultScore = xy; //成績 } else { rsr.ResultScore = null; } } else { rsr.ResultScore = null; } rsr.CadreName = "" + row.Cells[4].Value; //幹部 updateList.Add(rsr); } } if (InsertList.Count != 0) _AccessHelper.InsertValues(InsertList); if (updateList.Count != 0) _AccessHelper.UpdateValues(updateList); if (deleteList.Count != 0) _AccessHelper.DeletedValues(deleteList); SaveButtonVisible = false; CancelButtonVisible = false; Changed(); }