void rb_CheckedChanged(object sender, EventArgs e) { #region 缺曠類別建立(事件) RadioButton rb = sender as RadioButton; if (rb.Checked) { _checkedAbsence = rb.Tag as AbsenceInfo; foreach (DataGridViewCell cell in dataGridView.SelectedCells) { if (cell.ColumnIndex < _startIndex || cell.OwningRow.Visible == false) { continue; } cell.Value = _checkedAbsence.Abbreviation; AbsenceCellInfo acInfo = cell.Tag as AbsenceCellInfo; if (acInfo == null) { acInfo = new AbsenceCellInfo(); } acInfo.SetValue(_checkedAbsence); cell.Value = acInfo.AbsenceInfo.Abbreviation; cell.Tag = acInfo; } dataGridView.Focus(); } #endregion }
private void dataGridView_KeyDown(object sender, KeyEventArgs e) { #region 如果按下按鈕 string key = KeyConverter.GetKeyMapping(e); if (!_absenceList.ContainsKey(key)) { if (e.KeyCode != Keys.Space && e.KeyCode != Keys.Delete) { return; } foreach (DataGridViewCell cell in dataGridView.SelectedCells) { if (cell.ColumnIndex < _startIndex || cell.OwningRow.Visible == false) { continue; } cell.Value = null; AbsenceCellInfo acInfo = cell.Tag as AbsenceCellInfo; if (acInfo != null) { acInfo.SetValue(null); } } } else { AbsenceInfo info = _absenceList[key]; foreach (DataGridViewCell cell in dataGridView.SelectedCells) { if (cell.ColumnIndex < _startIndex || cell.OwningRow.Visible == false) { continue; } AbsenceCellInfo acInfo = cell.Tag as AbsenceCellInfo; if (acInfo == null) { acInfo = new AbsenceCellInfo(); } acInfo.SetValue(info); if (acInfo.IsValueChanged) { cell.Value = acInfo.AbsenceInfo.Abbreviation; } else { cell.Value = string.Empty; acInfo.SetValue(AbsenceInfo.Empty); } cell.Tag = acInfo; } } #endregion }
private void InitializeRadioButton() { #region 缺曠類別建立 DSResponse dsrsp = Config.GetAbsenceList(); DSXmlHelper helper = dsrsp.GetContent(); foreach (XmlElement element in helper.GetElements("Absence")) { AbsenceInfo info = new AbsenceInfo(element); //熱鍵不重覆 if (!_absenceList.ContainsKey(info.Hotkey.ToUpper())) { _absenceList.Add(info.Hotkey.ToUpper(), info); } else { StringBuilder sb = new StringBuilder(); sb.Append("缺曠別:{0}\n熱鍵:{1} 已重覆\n(英文字母大小寫視為相同熱鍵)"); MsgBox.Show(string.Format(sb.ToString(), info.Name, info.Hotkey)); } RadioButton rb = new RadioButton(); rb.Text = info.Name + "(" + info.Hotkey + ")"; rb.AutoSize = true; //rb.Font = new Font(Framework.DotNetBar.FontStyles.GeneralFontFamily, 9.25f); rb.Tag = info; rb.CheckedChanged += new EventHandler(rb_CheckedChanged); rb.Click += new EventHandler(rb_CheckedChanged); panel.Controls.Add(rb); if (_checkedAbsence == null) { _checkedAbsence = info; rb.Checked = true; } } #endregion }
//儲存 private void btnSave_Click(object sender, EventArgs e) { #region Save if (!IsValid()) { FISCA.Presentation.Controls.MsgBox.Show("資料驗證失敗,請修正後再行儲存", "驗證失敗", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } List <SHAttendanceRecord> InsertHelper = new List <SHAttendanceRecord>(); //新增 List <SHAttendanceRecord> updateHelper = new List <SHAttendanceRecord>(); //更新 List <string> deleteList = new List <string>(); //清空 //List<string> synclist = new List<string>(); ISemester semester = SemesterProvider.GetInstance(); foreach (DataGridViewRow row in dataGridView.Rows) { RowTag tag = row.Tag as RowTag; semester.SetDate(tag.Date); ////log 紀錄修改後的資料 日期部分 if (row.Cells[0].Tag is string) { if (!LOG[row.Cells[0].Tag.ToString()].afterData.ContainsKey(tag.Date.ToShortDateString())) { LOG[row.Cells[0].Tag.ToString()].afterData.Add(tag.Date.ToShortDateString(), new Dictionary <string, string>()); } } else { SHAttendanceRecord attRecord = row.Cells[0].Tag as SHAttendanceRecord; if (!LOG[attRecord.RefStudentID].afterData.ContainsKey(tag.Date.ToShortDateString())) { LOG[attRecord.RefStudentID].afterData.Add(tag.Date.ToShortDateString(), new Dictionary <string, string>()); } } if (tag.IsNew) { #region IsNew string studentID = row.Cells[0].Tag as string; SHAttendanceRecord attRecord = new SHAttendanceRecord(); bool hasContent = false; for (int i = _startIndex; i < dataGridView.Columns.Count; i++) { DataGridViewCell cell = row.Cells[i]; if (string.IsNullOrEmpty(("" + cell.Value).Trim())) { continue; } PeriodInfo pinfo = dataGridView.Columns[i].Tag as PeriodInfo; AbsenceCellInfo acInfo = cell.Tag as AbsenceCellInfo; AbsenceInfo ainfo = acInfo.AbsenceInfo; K12.Data.AttendancePeriod ap = new K12.Data.AttendancePeriod(); ap.Period = pinfo.Name; ap.AbsenceType = ainfo.Name; attRecord.PeriodDetail.Add(ap); hasContent = true; //log 紀錄修改後的資料 缺曠明細部分 if (!LOG[studentID].afterData[tag.Date.ToShortDateString()].ContainsKey(pinfo.Name)) { LOG[studentID].afterData[tag.Date.ToShortDateString()].Add(pinfo.Name, ainfo.Name); } } if (hasContent) { attRecord.RefStudentID = studentID; attRecord.SchoolYear = int.Parse("" + row.Cells[ColumnIndex["學年度"]].Value); attRecord.Semester = int.Parse("" + row.Cells[ColumnIndex["學期"]].Value); attRecord.OccurDate = DateTime.Parse(tag.Date.ToShortDateString()); InsertHelper.Add(attRecord); } #endregion } else // 若是原本就有紀錄的 { #region 是舊的 SHAttendanceRecord attRecord = row.Cells[0].Tag as SHAttendanceRecord; attRecord.PeriodDetail.Clear(); //清空 bool hasContent = false; for (int i = _startIndex; i < dataGridView.Columns.Count; i++) { DataGridViewCell cell = row.Cells[i]; if (string.IsNullOrEmpty(("" + cell.Value).Trim())) { continue; } PeriodInfo pinfo = dataGridView.Columns[i].Tag as PeriodInfo; AbsenceCellInfo acInfo = cell.Tag as AbsenceCellInfo; AbsenceInfo ainfo = acInfo.AbsenceInfo; K12.Data.AttendancePeriod ap = new K12.Data.AttendancePeriod(); ap.Period = pinfo.Name; ap.AbsenceType = ainfo.Name; attRecord.PeriodDetail.Add(ap); hasContent = true; //log 紀錄修改後的資料 缺曠明細部分 if (!LOG[attRecord.RefStudentID].afterData[tag.Date.ToShortDateString()].ContainsKey(pinfo.Name)) { LOG[attRecord.RefStudentID].afterData[tag.Date.ToShortDateString()].Add(pinfo.Name, ainfo.Name); } } if (hasContent) { attRecord.SchoolYear = int.Parse("" + row.Cells[ColumnIndex["學年度"]].Value); attRecord.Semester = int.Parse("" + row.Cells[ColumnIndex["學期"]].Value); updateHelper.Add(attRecord); } else { deleteList.Add(tag.Key); //log 紀錄被刪除的資料 LOG[attRecord.RefStudentID].afterData.Remove(tag.Date.ToShortDateString()); LOG[attRecord.RefStudentID].deleteData.Add(tag.Date.ToShortDateString()); } #endregion } } #region InsertHelper if (InsertHelper.Count > 0) { try { SHAttendance.Insert(InsertHelper); } catch (Exception ex) { FISCA.Presentation.Controls.MsgBox.Show("缺曠紀錄新增失敗 : " + ex.Message, "新增失敗", MessageBoxButtons.OK, MessageBoxIcon.Error); } //log 寫入log foreach (string each in LOG.Keys) { foreach (string date in LOG[each].afterData.Keys) { if (!LOG[each].beforeData.ContainsKey(date) && LOG[each].afterData[date].Count > 0) { StringBuilder desc = new StringBuilder(""); desc.AppendLine("學生「" + K12.Data.Student.SelectByID(each).Name + "」"); desc.AppendLine("日期「" + date + "」"); foreach (string period in LOG[each].afterData[date].Keys) { desc.AppendLine("節次「" + period + "」設為「" + LOG[each].afterData[date][period] + "」"); } ApplicationLog.Log("學務系統.缺曠資料", "批次新增缺曠資料", "student", each, desc.ToString()); //Log部份 //CurrentUser.Instance.AppLog.Write(EntityType.Student, EntityAction.Insert, _student.ID, desc.ToString(), this.Text, ""); } } } } #endregion #region updateHelper if (updateHelper.Count > 0) { try { SHAttendance.Update(updateHelper); } catch (Exception ex) { FISCA.Presentation.Controls.MsgBox.Show("缺曠紀錄更新失敗 : " + ex.Message, "更新失敗", MessageBoxButtons.OK, MessageBoxIcon.Error); } //log 寫入log foreach (string each in LOG.Keys) { foreach (string date in LOG[each].afterData.Keys) { if (LOG[each].beforeData.ContainsKey(date) && LOG[each].afterData[date].Count > 0) { bool dirty = false; StringBuilder desc = new StringBuilder(""); desc.AppendLine("學生「" + K12.Data.Student.SelectByID(each).Name + "」 "); desc.AppendLine("日期「" + date + "」 "); foreach (string period in LOG[each].beforeData[date].Keys) { if (!LOG[each].afterData[date].ContainsKey(period)) { LOG[each].afterData[date].Add(period, ""); } } foreach (string period in LOG[each].afterData[date].Keys) { if (LOG[each].beforeData[date].ContainsKey(period)) { if (LOG[each].beforeData[date][period] != LOG[each].afterData[date][period]) { dirty = true; desc.AppendLine("節次「" + period + "」由「" + LOG[each].beforeData[date][period] + "」變更為「" + LOG[each].afterData[date][period] + "」"); } } else { dirty = true; desc.AppendLine("節次「" + period + "」由「」變更為「" + LOG[each].afterData[date][period] + "」 "); } } if (dirty) { //Log部份 ApplicationLog.Log("學務系統.缺曠資料", "批次修改缺曠資料", "student", each, desc.ToString()); //CurrentUser.Instance.AppLog.Write(EntityType.Student, EntityAction.Update, _student.ID, desc.ToString(), this.Text, ""); } } } } } #endregion #region deleteList if (deleteList.Count > 0) { try { SHAttendance.Delete(deleteList); } catch (Exception ex) { FISCA.Presentation.Controls.MsgBox.Show("缺曠紀錄刪除失敗 : " + ex.Message, "刪除失敗", MessageBoxButtons.OK, MessageBoxIcon.Error); } //log 寫入被刪除的資料的log foreach (string each in LOG.Keys) { StringBuilder desc = new StringBuilder(""); desc.AppendLine("學生「" + K12.Data.Student.SelectByID(each).Name + "」"); foreach (string date in LOG[each].deleteData) { desc.AppendLine("刪除「" + date + "」缺曠紀錄 "); } //Log部份 ApplicationLog.Log("學務系統.缺曠資料", "批次刪除缺曠資料", "student", each, desc.ToString()); //CurrentUser.Instance.AppLog.Write(EntityType.Student, EntityAction.Delete, _student.ID, desc.ToString(), this.Text, ""); } } #endregion //觸發變更事件 //Attendance.Instance.SyncDataBackground(_studentList); FISCA.Presentation.Controls.MsgBox.Show("儲存缺曠資料成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); #endregion }
private void GetAbsense() { LOG.Clear(); #region 取得缺曠記錄 List <SHAttendanceRecord> attendList = new List <SHAttendanceRecord>(); foreach (string each in _studentList) { if (!LOG.ContainsKey(each)) { LOG.Add(each, new LogStudent()); } } foreach (SHAttendanceRecord each in SHAttendance.SelectByDate(dateTimeInput1.Value, dateTimeInput2.Value)) { if (_studentList.Contains(each.RefStudentID)) { attendList.Add(each); } } foreach (SHAttendanceRecord attendanceRecord in attendList) { // 這裡要做一些事情 例如找到東西塞進去 string occurDate = attendanceRecord.OccurDate.ToShortDateString(); string schoolYear = attendanceRecord.SchoolYear.ToString(); string semester = attendanceRecord.Semester.ToString(); string id = attendanceRecord.ID; List <K12.Data.AttendancePeriod> dNode = attendanceRecord.PeriodDetail; //log 紀錄修改前的資料 日期部分 DateTime logDate; if (DateTime.TryParse(occurDate, out logDate)) { if (!LOG[attendanceRecord.RefStudentID].beforeData.ContainsKey(logDate.ToShortDateString())) { LOG[attendanceRecord.RefStudentID].beforeData.Add(logDate.ToShortDateString(), new Dictionary <string, string>()); } } DataGridViewRow row = null; foreach (DataGridViewRow r in dataGridView.Rows) { if (r.Cells[0].Tag as string == attendanceRecord.RefStudentID && "" + r.Cells[ColumnIndex["日期"]].Value == attendanceRecord.OccurDate.ToShortDateString()) { row = r; break; } } if (row == null) { continue; } RowTag rowTag = row.Tag as RowTag; rowTag.IsNew = false; rowTag.Key = id; row.Cells[0].Tag = attendanceRecord; //把資料儲存於Cell[0] row.Cells[ColumnIndex["學年度"]].Value = schoolYear; row.Cells[ColumnIndex["學年度"]].Tag = new SemesterCellInfo(schoolYear); row.Cells[ColumnIndex["學期"]].Value = semester; row.Cells[ColumnIndex["學期"]].Tag = new SemesterCellInfo(semester); for (int i = _startIndex; i < dataGridView.Columns.Count; i++) { DataGridViewColumn column = dataGridView.Columns[i]; PeriodInfo info = column.Tag as PeriodInfo; foreach (K12.Data.AttendancePeriod node in dNode) { if (node.Period != info.Name) { continue; } if (node.AbsenceType == null) { continue; } DataGridViewCell cell = row.Cells[i]; foreach (AbsenceInfo ai in _absenceList.Values) { if (ai.Name != node.AbsenceType) { continue; } AbsenceInfo ainfo = ai.Clone(); cell.Tag = new AbsenceCellInfo(ainfo); cell.Value = ai.Abbreviation; ////log 紀錄修改前的資料 缺曠明細部分 if (!LOG[node.RefStudentID].beforeData[logDate.ToShortDateString()].ContainsKey(info.Name)) { LOG[node.RefStudentID].beforeData[logDate.ToShortDateString()].Add(info.Name, ai.Name); } break; } } } } #endregion }