private void 自畫面上移除ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dataGridViewX1.SelectedRows) { ServiceDataRow sdr = (ServiceDataRow)row.DataBoundItem; DataRowList.Remove(sdr); //dataGridViewX1.Rows.Remove(row); } }
private void 批次修改發生日期ToolStripMenuItem_Click(object sender, EventArgs e) { ServiceDataRow sdr = (ServiceDataRow)dataGridViewX1.CurrentRow.DataBoundItem; ChangeDateTimeForm ctf = new ChangeDateTimeForm("發生日期", sdr.OccurDate); DialogResult dr = ctf.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.Yes) { foreach (DataGridViewRow row in dataGridViewX1.SelectedRows) { sdr = (ServiceDataRow)row.DataBoundItem; sdr.OccurDate = ctf.ChangeTime.ToShortDateString(); } } }
private void 批次修改時數ToolStripMenuItem_Click(object sender, EventArgs e) { ServiceDataRow sdr = (ServiceDataRow)dataGridViewX1.CurrentRow.DataBoundItem; ChangeIntForm ctf = new ChangeIntForm("時數", sdr.Hours); DialogResult dr = ctf.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.Yes) { foreach (DataGridViewRow row in dataGridViewX1.SelectedRows) { sdr = (ServiceDataRow)row.DataBoundItem; sdr.Hours = ctf.ChangeInt; } } }
private void 批次修改學年度學期ToolStripMenuItem_Click(object sender, EventArgs e) { ServiceDataRow sdr = (ServiceDataRow)dataGridViewX1.CurrentRow.DataBoundItem; ChangeSchoolYearSemester ctf = new ChangeSchoolYearSemester("學年度/學期", sdr.SchoolYear, sdr.Semester); DialogResult dr = ctf.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.Yes) { foreach (DataGridViewRow row in dataGridViewX1.SelectedRows) { sdr = (ServiceDataRow)row.DataBoundItem; sdr.SchoolYear = ctf.ChangeSchoolYear; sdr.Semester = ctf.ChangeSemester; } } }
private void 批次修改所有資料toolStripMenuItem1_Click(object sender, EventArgs e) { ServiceDataRow sdr = (ServiceDataRow)dataGridViewX1.CurrentRow.DataBoundItem; ChangeAllDataForm ctf = new ChangeAllDataForm("所有", sdr._slr); DialogResult dr = ctf.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.Yes) { foreach (DataGridViewRow row in dataGridViewX1.SelectedRows) { sdr = (ServiceDataRow)row.DataBoundItem; sdr.SchoolYear = ctf.學年度; sdr.Semester = ctf.學期; sdr.OccurDate = ctf.日期; sdr.Reason = ctf.事由; sdr.Hours = ctf.時數; sdr.Organizers = ctf.主辦單位; sdr.Remark = ctf.備註; } } }
void BGW_DoWork(object sender, DoWorkEventArgs e) { List <string> lsid = new List <string>(); List <SLRecord> SelectList = new List <SLRecord>(); //取得資料 if (_cir.IsApproved) { XElement xe = _cir.ApprovedDetail; foreach (XElement item in xe.Elements("SLRecord")) { lsid.Add(item.Element("RefStudentID").Value); SelectList.Add(new SLRecord() { RefStudentID = item.Element("RefStudentID").Value, SchoolYear = int.Parse(item.Element("SchoolYear").Value), Semester = int.Parse(item.Element("Semester").Value), OccurDate = DateTime.Parse(item.Element("OccurDate").Value), Reason = item.Element("Reason").Value, Hours = decimal.Parse(item.Element("Hours").Value), Organizers = item.Element("Organizers").Value, RegisterDate = DateTime.Parse(item.Element("RegisterDate").Value), Remark = item.Element("Remark").Value, }); } } else { List <string> where = new List <string>(); where.Add("ref_creationitemsrecord_id = '" + _cir.UID + "'"); where.Add("can_participate = true"); List <CreationItemsParticipateRecord> lcipr = tool._A.Select <CreationItemsParticipateRecord>(string.Join(" and ", where)); foreach (CreationItemsParticipateRecord item in lcipr) { lsid.Add(item.RefStudentId); SelectList.Add(new SLRecord() { RefStudentID = item.RefStudentId, SchoolYear = _cir.SchoolYear, Semester = _cir.Semester, OccurDate = _cir.OccurDate, Reason = _cir.Reason, Hours = decimal.Parse("" + _cir.ExpectedHours), Organizers = _cir.Organizers, RegisterDate = DateTime.Now, Remark = _cir.Remark, }); } } Dictionary <string, StudentRecord> ds = K12.Data.Student.SelectByIDs(lsid).ToDictionary(x => x.ID, x => x); //取得學生基本資料 //建立DataGridView DataRow List <ServiceDataRow> newDataRowList = new List <ServiceDataRow>(); foreach (SLRecord each in SelectList) { if (ds.ContainsKey(each.RefStudentID)) { ServiceDataRow row = new ServiceDataRow(ds[each.RefStudentID], each); row.PropertyChanged += new PropertyChangedEventHandler(row_PropertyChanged); newDataRowList.Add(row); } } newDataRowList.Sort(SortByClassName); e.Result = newDataRowList; }
private int SortByClassName(ServiceDataRow row1, ServiceDataRow row2) { StudentRecord sr1 = row1._student; StudentRecord sr2 = row2._student; string studentSort1 = ""; string studentSort2 = ""; #region 年級 if (!string.IsNullOrEmpty(sr1.RefClassID)) { if (sr1.Class.GradeYear.HasValue) { studentSort1 += sr1.Class.GradeYear.Value.ToString().PadLeft(1, '0'); } else { studentSort1 += "0"; } } else { studentSort1 += "0"; } if (!string.IsNullOrEmpty(sr2.RefClassID)) { if (sr2.Class.GradeYear.HasValue) { studentSort2 += sr2.Class.GradeYear.Value.ToString().PadLeft(1, '0'); } else { studentSort2 += "0"; } } else { studentSort2 += "0"; } #endregion #region 班級序號 if (!string.IsNullOrEmpty(sr1.RefClassID)) { studentSort1 += sr1.Class.DisplayOrder.PadLeft(3, '0'); } else { studentSort1 += "000"; } if (!string.IsNullOrEmpty(sr2.RefClassID)) { studentSort2 += sr2.Class.DisplayOrder.PadLeft(3, '0'); } else { studentSort2 += "000"; } #endregion #region 班級 if (!string.IsNullOrEmpty(sr1.RefClassID)) { studentSort1 = sr1.Class.Name.PadLeft(6, '0'); } else { studentSort1 = "000000"; } if (!string.IsNullOrEmpty(sr2.RefClassID)) { studentSort2 = sr2.Class.Name.PadLeft(6, '0'); } else { studentSort2 = "000000"; } #endregion #region 座號 if (sr1.SeatNo.HasValue) { studentSort1 += sr1.SeatNo.Value.ToString().PadLeft(3, '0'); } else { studentSort1 += "000"; } if (sr2.SeatNo.HasValue) { studentSort2 += sr2.SeatNo.Value.ToString().PadLeft(3, '0'); } else { studentSort2 += "000"; } #endregion //姓名 studentSort1 += sr1.Name.PadLeft(10, '0'); studentSort2 += sr2.Name.PadLeft(10, '0'); return(studentSort1.CompareTo(studentSort2)); }
void BGW_DoWork(object sender, DoWorkEventArgs e) { List<string> lsid = new List<string>(); List<SLRecord> SelectList = new List<SLRecord>(); //取得資料 if (_cir.IsApproved) { XElement xe = _cir.ApprovedDetail; foreach (XElement item in xe.Elements("SLRecord")) { lsid.Add(item.Element("RefStudentID").Value); SelectList.Add(new SLRecord() { RefStudentID = item.Element("RefStudentID").Value, SchoolYear = int.Parse(item.Element("SchoolYear").Value), Semester = int.Parse(item.Element("Semester").Value), OccurDate = DateTime.Parse(item.Element("OccurDate").Value), Reason = item.Element("Reason").Value, Hours = decimal.Parse(item.Element("Hours").Value), Organizers = item.Element("Organizers").Value, RegisterDate = DateTime.Parse(item.Element("RegisterDate").Value), Remark = item.Element("Remark").Value, }); } } else { List<string> where = new List<string>(); where.Add("ref_creationitemsrecord_id = '" + _cir.UID + "'"); where.Add("can_participate = true"); List<CreationItemsParticipateRecord> lcipr = tool._A.Select<CreationItemsParticipateRecord>(string.Join(" and ", where)); foreach (CreationItemsParticipateRecord item in lcipr) { lsid.Add(item.RefStudentId); SelectList.Add(new SLRecord() { RefStudentID = item.RefStudentId, SchoolYear = _cir.SchoolYear, Semester = _cir.Semester, OccurDate = _cir.OccurDate, Reason = _cir.Reason, Hours = decimal.Parse("" + _cir.ExpectedHours), Organizers = _cir.Organizers, RegisterDate = DateTime.Now, Remark = _cir.Remark, }); } } Dictionary<string, StudentRecord> ds = K12.Data.Student.SelectByIDs(lsid).ToDictionary(x => x.ID, x => x); //取得學生基本資料 //建立DataGridView DataRow List<ServiceDataRow> newDataRowList = new List<ServiceDataRow>(); foreach (SLRecord each in SelectList) { if (ds.ContainsKey(each.RefStudentID)) { ServiceDataRow row = new ServiceDataRow(ds[each.RefStudentID], each); row.PropertyChanged += new PropertyChangedEventHandler(row_PropertyChanged); newDataRowList.Add(row); } } newDataRowList.Sort(SortByClassName); e.Result = newDataRowList; }
private int SortByClassName(ServiceDataRow row1, ServiceDataRow row2) { StudentRecord sr1 = row1._student; StudentRecord sr2 = row2._student; string studentSort1 = ""; string studentSort2 = ""; #region 年級 if (!string.IsNullOrEmpty(sr1.RefClassID)) { if (sr1.Class.GradeYear.HasValue) { studentSort1 += sr1.Class.GradeYear.Value.ToString().PadLeft(1, '0'); } else { studentSort1 += "0"; } } else { studentSort1 += "0"; } if (!string.IsNullOrEmpty(sr2.RefClassID)) { if (sr2.Class.GradeYear.HasValue) { studentSort2 += sr2.Class.GradeYear.Value.ToString().PadLeft(1, '0'); } else { studentSort2 += "0"; } } else { studentSort2 += "0"; } #endregion #region 班級序號 if (!string.IsNullOrEmpty(sr1.RefClassID)) { studentSort1 += sr1.Class.DisplayOrder.PadLeft(3, '0'); } else { studentSort1 += "000"; } if (!string.IsNullOrEmpty(sr2.RefClassID)) { studentSort2 += sr2.Class.DisplayOrder.PadLeft(3, '0'); } else { studentSort2 += "000"; } #endregion #region 班級 if (!string.IsNullOrEmpty(sr1.RefClassID)) { studentSort1 = sr1.Class.Name.PadLeft(6, '0'); } else { studentSort1 = "000000"; } if (!string.IsNullOrEmpty(sr2.RefClassID)) { studentSort2 = sr2.Class.Name.PadLeft(6, '0'); } else { studentSort2 = "000000"; } #endregion #region 座號 if (sr1.SeatNo.HasValue) studentSort1 += sr1.SeatNo.Value.ToString().PadLeft(3, '0'); else studentSort1 += "000"; if (sr2.SeatNo.HasValue) studentSort2 += sr2.SeatNo.Value.ToString().PadLeft(3, '0'); else studentSort2 += "000"; #endregion //姓名 studentSort1 += sr1.Name.PadLeft(10, '0'); studentSort2 += sr2.Name.PadLeft(10, '0'); return studentSort1.CompareTo(studentSort2); }