private void Save(string schoolyear, string semester, string groupName) { List <ActivityRecordItem> list = new List <ActivityRecordItem>(); foreach (DataGridViewRow row in dgEditor.Rows) { StudentRecord student = row.Tag as StudentRecord; if (student != null) { ActivityRecordItem item = new ActivityRecordItem(); item.StudentID = student.ID; item.SchoolYear = schoolyear; item.Semester = semester; item.Item = row.Cells[colItem.Name].Value.ToString(); item.Type = "社團幹部"; item.Unit = groupName; list.Add(item); } } ActivityRecordDAL.SaveGroupLeader(schoolyear, semester, groupName, list.ToArray()); _dirty = false; }
private void ChangeSelection() { _dirty = false; if (!_initialized) { return; } List <ActivityRecordItem> arItems = ActivityRecordDAL.GetActivityRecordItems(cboSchoolYear.Text, cboSemester.Text, "社團幹部", cboGroup.Text); dgEditor.Rows.Clear(); foreach (MappingItem item in _mappingItems) { for (int i = 0; i < item.Count; i++) { int rowIndex = dgEditor.Rows.Add(); DataGridViewRow row = dgEditor.Rows[rowIndex]; row.Cells[colItem.Index].Value = item.Item; } } foreach (ActivityRecordItem ari in arItems) { StudentRecord student = Student.Instance[ari.StudentID]; foreach (DataGridViewRow row in dgEditor.Rows) { if (row.Cells[colItem.Name].Value.ToString() == ari.Item && row.Tag == null && student != null) { FillStudentRow(row, student); break; } } } }
public GroupLeader() { InitializeComponent(); int schoolYear; if (!int.TryParse(School.DefaultSchoolYear, out schoolYear)) { schoolYear = 97; } for (int i = schoolYear; i > schoolYear - 3; i--) { cboSchoolYear.Items.Add(i); } cboSchoolYear.Text = schoolYear.ToString(); cboSemester.Items.Add(1); cboSemester.Items.Add(2); cboSemester.Text = School.DefaultSemester; //取出該學年度學期之社團 InitialGroupComboBox(cboSchoolYear.Text, cboSemester.Text); _mappingItems = ActivityRecordDAL.GetActivityRecordMappingItems("社團幹部"); _initialized = true; RecorverSchoolYear = cboSchoolYear.Text; RecorverSemester = cboSemester.Text; RecorverIndex = cboGroup.SelectedIndex; ChangeSelection(); }
private void ChangeSelection() { _dirty = false; if (!_initialized) { return; } List <ActivityRecordItem> arItems = ActivityRecordDAL.GetActivityRecordItems(cboSchoolYear.Text, cboSemester.Text, "競賽項目", string.Empty); dgEditor.Rows.Clear(); foreach (ActivityRecordItem ari in arItems) { StudentRecord student = Student.Instance[ari.StudentID]; if (student != null) { int rowIndex = dgEditor.Rows.Add(); DataGridViewRow row = dgEditor.Rows[rowIndex]; row.Cells[colClass.Name].Value = student.Class.Name; row.Cells[colStudentNumber.Name].Value = student.StudentNumber; row.Cells[colSeatNo.Name].Value = student.SeatNo; row.Cells[colName.Name].Value = student.Name; row.Cells[colItem.Name].Value = ari.Item; row.Tag = student; } } }
public SchoolLeader() { InitializeComponent(); int schoolYear; if (!int.TryParse(School.DefaultSchoolYear, out schoolYear)) { schoolYear = 97; } for (int i = schoolYear; i > schoolYear - 3; i--) { cboSchoolYear.Items.Add(i); } cboSchoolYear.Text = schoolYear.ToString(); cboSemester.Items.Add(1); cboSemester.Items.Add(2); cboSemester.Text = School.DefaultSemester; _mappingItems = ActivityRecordDAL.GetActivityRecordMappingItems("學校幹部"); _initialized = true; RecorverSchoolYear = cboSchoolYear.Text; RecorverSemester = cboSemester.Text; ChangeSelection(); }
private void dgEditor_CellEndEdit(object sender, DataGridViewCellEventArgs e) { _dirty = true; DataGridViewRow row = dgEditor.Rows[e.RowIndex]; DataGridViewCell cell = row.Cells[e.ColumnIndex]; string value = string.Empty; if (cell.Value != null) { value = cell.Value.ToString(); } row.Tag = null; row.ErrorText = string.Empty; if (e.ColumnIndex == colSeatNo.Index) { StudentRecord student = ActivityRecordDAL.GetStudent(cboClass.Text, value); FillStudentRow(row, student); } else if (e.ColumnIndex == colStudentNumber.Index) { StudentRecord student = ActivityRecordDAL.GetStudent(value); FillStudentRow(row, student); } }
private void btnSave_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dgEditor.Rows) { foreach (DataGridViewCell cell in row.Cells) { if (!string.IsNullOrEmpty(cell.ErrorText)) { MessageBoxEx.Show("輸入資料有誤, 請修正後再行儲存!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } List <MappingItem> items = new List <MappingItem>(); foreach (DataGridViewRow row in dgEditor.Rows) { MappingItem item = new MappingItem(); string value = string.Empty; DataGridViewCell cell = row.Cells["細項"]; if (cell.Value == null) { continue; } value = cell.Value.ToString(); if (value == string.Empty) { continue; } string countString; int count; cell = row.Cells["數量"]; if (cell.Value == null) { count = 1; } else { countString = cell.Value.ToString(); if (!int.TryParse(countString, out count)) { count = 1; } } item.Item = value; item.Count = count; items.Add(item); } ActivityRecordDAL.SetActivityRecordMapping(cboType.Text, items.ToArray()); MessageBoxEx.Show(cboType.Text + "類別已儲存完畢!"); }
private void dgEditor_CellEndEdit(object sender, DataGridViewCellEventArgs e) { _dirty = true; DataGridViewRow row = dgEditor.Rows[e.RowIndex]; DataGridViewCell cell = row.Cells[e.ColumnIndex]; string value = string.Empty; if (cell.Value != null) { value = cell.Value.ToString(); } row.ErrorText = string.Empty; if (e.ColumnIndex == colSeatNo.Index || e.ColumnIndex == colClass.Index) { string className = string.Empty; if (row.Cells[colClass.Name].Value != null) { className = row.Cells[colClass.Name].Value.ToString(); } string seatNo = string.Empty; if (row.Cells[colSeatNo.Name].Value != null) { seatNo = row.Cells[colSeatNo.Name].Value.ToString(); } if (string.IsNullOrEmpty(className) || string.IsNullOrEmpty(seatNo)) { row.ErrorText = "請輸入完整的班級與座號"; return; } StudentRecord student = ActivityRecordDAL.GetStudent(className, seatNo); FillStudentRow(row, student); } else if (e.ColumnIndex == colItem.Index) { if (string.IsNullOrEmpty(value)) { cell.ErrorText = "內容不可空白"; } else { cell.ErrorText = string.Empty; } } else if (e.ColumnIndex == colStudentNumber.Index) { StudentRecord student = ActivityRecordDAL.GetStudent(value); FillStudentRow(row, student); } }
public StudentActivityRecordItem() { InitializeComponent(); this.Group = "個人活動表現紀錄"; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate { ActivityRecordDAL.PrepareMetadata(); }; worker.RunWorkerAsync(); }
public ActivityTypeManager() { InitializeComponent(); _types = ActivityRecordDAL.GetActivityRecordTypes(); foreach (string type in _types) { cboType.Items.Add(type); } dgEditor.Columns.Add("細項", "細項"); dgEditor.Columns.Add("數量", "數量"); cboType.SelectedIndex = 0; }
private void cboType_SelectedIndexChanged(object sender, EventArgs e) { dgEditor.Rows.Clear(); foreach (MappingItem item in ActivityRecordDAL.GetActivityRecordMappingItems(cboType.Text)) { if (item.Type != cboType.Text) { continue; } int rowIndex = dgEditor.Rows.Add(); dgEditor.Rows[rowIndex].Cells["細項"].Value = item.Item; dgEditor.Rows[rowIndex].Cells["數量"].Value = item.Count; } }
private void InitialGroupComboBox(string schoolyear, string semester) { List <string> list = ActivityRecordDAL.GetGroupList(schoolyear, semester); cboGroup.Items.Clear(); foreach (DataGridViewRow row in dgEditor.Rows) { ClearStudentRow(row); } foreach (string group in list) { cboGroup.Items.Add(group); } if (list.Count > 0) { cboGroup.SelectedIndex = 0; } }
public ClassLeader() { InitializeComponent(); _mappingItems = ActivityRecordDAL.GetActivityRecordMappingItems("班級幹部"); int schoolYear; if (!int.TryParse(School.DefaultSchoolYear, out schoolYear)) { schoolYear = 97; } for (int i = schoolYear; i > schoolYear - 3; i--) { cboSchoolYear.Items.Add(i); } cboSchoolYear.Text = schoolYear.ToString(); RecorverSchoolYear = cboSchoolYear.Text; cboSemester.Items.Add(1); cboSemester.Items.Add(2); cboSemester.Text = School.DefaultSemester == "2" ? "2" : "1"; RecorverSemester = cboSemester.Text; foreach (ClassRecord cr in Class.Instance.Items) { cboClass.Items.Add(cr.Name); } if (cboClass.Items.Count > 0) { cboClass.SelectedIndex = 0; RecorverIndex = 0; } _initialized = true; ChangeSelection(); }
private void Fill() { if (string.IsNullOrEmpty(this.PrimaryKey)) { return; } List <ActivityRecordItem> list = ActivityRecordDAL.GetActivityRecordHistory(this.PrimaryKey); list.Sort(new ActivityRecordItemComparer()); dgView.Rows.Clear(); foreach (ActivityRecordItem item in list) { int rowIndex = dgView.Rows.Add(); DataGridViewRow row = dgView.Rows[rowIndex]; row.Cells[colItem.Name].Value = item.Item; row.Cells[this.colSchoolYear.Name].Value = item.SchoolYear; row.Cells[this.colSemester.Name].Value = item.Semester; row.Cells[this.colType.Name].Value = item.Type; } }
private void Save() { List <ActivityRecordItem> list = new List <ActivityRecordItem>(); if (!string.IsNullOrEmpty(errorProvider1.GetError(cboSemester)) || !string.IsNullOrEmpty(errorProvider1.GetError(cboSchoolYear))) { MessageBoxEx.Show("資料有誤, 請修正後再行儲存!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (DataGridViewRow row in dgEditor.Rows) { if (!string.IsNullOrEmpty(row.ErrorText)) { MessageBoxEx.Show("資料有誤, 請修正後再行儲存!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } StudentRecord student = row.Tag as StudentRecord; if (student != null) { ActivityRecordItem item = new ActivityRecordItem(); item.StudentID = student.ID; item.SchoolYear = cboSchoolYear.Text; item.Semester = cboSemester.Text; item.Item = row.Cells[colItem.Name].Value.ToString(); item.Type = "學校幹部"; item.Unit = string.Empty; list.Add(item); } } ActivityRecordDAL.SaveSchoolLeader(cboSchoolYear.Text, cboSemester.Text, list.ToArray()); _dirty = false; }