private void btnAdd_Click(object sender, EventArgs e) { try { DataTable dataTable = queryHelper.Select(string.Format("select class_name, student.name as student_name, student.id as id, student_number from student left join class on class.id=student.ref_class_id where student.status in (1, 4) and student_number ilike ('{0}')", this.txtStudentNumber.Text.Trim())); if (dataTable == null || dataTable.Rows.Count == 0) { MessageBox.Show("查無此人。"); return; } else { List<UDT.CSAttend> CSAttends = Access.Select<UDT.CSAttend>(string.Format("ref_student_id={0} and ref_course_id={1}", dataTable.Rows[0]["id"] + "", CourseID)); if (CSAttends.Count > 0) { MessageBox.Show(string.Format("已加入學生「班級:{0},學號:{1},姓名:{2}」。", dataTable.Rows[0]["class_name"] + "", dataTable.Rows[0]["student_number"] + "", dataTable.Rows[0]["student_name"] + "")); return; } UDT.CSAttend CSAttend = new UDT.CSAttend(); UDT.CSAttendLog CSAttendLog = new UDT.CSAttendLog(); CSAttend.CourseID = int.Parse(CourseID); CSAttend.StudentID = int.Parse(dataTable.Rows[0]["id"] + ""); CSAttend.SchoolYear = this.SchoolYear; CSAttend.Semester = this.Semester; CSAttend.Item = this.item; CSAttend.Manually = true; CSAttend.IsManual = true; CSAttendLog.CourseID = int.Parse(CourseID); CSAttendLog.StudentID = int.Parse(dataTable.Rows[0]["id"] + ""); CSAttendLog.SchoolYear = this.SchoolYear; CSAttendLog.Semester = this.Semester; CSAttendLog.Action = "insert_manually"; CSAttendLog.ActionBy = "staff"; CSAttendLog.Item = this.item; CSAttend.Save(); CSAttendLog.Save(); Event.DeliverCSAttendEventArgs ee = new Event.DeliverCSAttendEventArgs(new List<UDT.CSAttend> { CSAttend }); Event.DeliverActiveRecord.RaiseSendingEvent(this, ee); MessageBox.Show(string.Format("已加入學生「班級:{0},學號:{1},姓名:{2}」", dataTable.Rows[0]["class_name"] + "", dataTable.Rows[0]["student_number"] + "", dataTable.Rows[0]["student_name"] + "")); } } catch(Exception ex) { MessageBox.Show(ex.Message); } }
private void btnRecover_Click(object sender, EventArgs e) { if (this.lstCourse.SelectedIndex == -1) return; this.DisableButtons(); string CourseID = this.groupPanel1.Tag + ""; decimal school_year = this.nudSchoolYear.Value; string semester = (this.cboSemester.SelectedItem as DataItems.SemesterItem).Value; List<UDT.CSAttend> CSAttends = new List<UDT.CSAttend>(); List<UDT.CSAttendLog> CSAttendLogs = new List<UDT.CSAttendLog>(); if (this.dgvData.SelectedRows.Count == 0) return; this.dgvData.SelectedRows.Cast<DataGridViewRow>().ToList().ForEach((x) => { if (x.DefaultCellStyle.BackColor == System.Drawing.Color.Pink) { UDT.CSAttend CSAttend = new UDT.CSAttend(); UDT.CSAttendLog CSAttendLog = new UDT.CSAttendLog(); CSAttend.StudentID = int.Parse(x.Cells["lblStudentID"].Value + ""); CSAttend.CourseID = int.Parse(CourseID); CSAttend.SchoolYear = int.Parse(school_year.ToString()); CSAttend.Semester = int.Parse(semester); CSAttend.Item = this.item; CSAttends.Add(CSAttend); CSAttendLog.StudentID = int.Parse(x.Cells["lblStudentID"].Value + ""); CSAttendLog.CourseID = int.Parse(CourseID); CSAttendLog.SchoolYear = int.Parse(school_year.ToString()); CSAttendLog.Semester = int.Parse(semester); CSAttendLog.Item = this.item; CSAttendLog.Action = "insert"; CSAttendLog.ActionBy = "staff"; CSAttendLogs.Add(CSAttendLog); x.DefaultCellStyle.BackColor = System.Drawing.SystemColors.Window; } }); CSAttends.SaveAll(); CSAttendLogs.SaveAll(); this.InitCSAttend(CourseID); if (this.chkShowLog.Checked) this.AppendCSAttendLog(CourseID); this.EnableButtons(); }