private void Delete_Click(object sender, EventArgs e) { if (this.dgvData.SelectedRows.Count == 0) { System.Windows.Forms.MessageBox.Show("請先選擇科目。"); return; } DialogResult result = MsgBox.Show(string.Format("是否確定刪除 {0} 此科目?", this.dgvData.SelectedRows[0].Cells[2].Value), "警告", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { try { UDT.Subject record = this.dgvData.SelectedRows[0].Tag as UDT.Subject; record.Deleted = true; record.Save(); this.InitSubject(); } catch (Exception ex) { MsgBox.Show(ex.Message); } } }
private void Subject_Received(object sender, Event.DeliverActiveRecordEventArgs e) { IEnumerable <ActiveRecord> records = e.ActiveRecords; if (records == null || records.Count() == 0) { return; } this.no_change = true; IEnumerable <DataGridViewRow> rows = this.dgvData.Rows.Cast <DataGridViewRow>(); records.ToList().ForEach((x) => { UDT.Subject record = x as UDT.Subject; if ((rows.Where(y => (y.Tag == null ? "" : y.Tag.ToString()) == record.UID).Count() == 0)) { object[] rowData = new object[] { record.SubjectName, record.Level, "", "" }; int rowIndex = this.dgvData.Rows.Add(rowData); DataGridViewRow row = this.dgvData.Rows[rowIndex]; row.Tag = record.UID; } }); this.no_change = false; }
private void Update_Click(object sender, EventArgs e) { if (this.dgvData.SelectedRows.Count == 0) { MsgBox.Show("請先選擇科目。"); return; } try { frmSubjectCreator frm = new frmSubjectCreator("修改科目", cboSchoolYear.SelectedItem.ToString(), cboSemester.SelectedItem.ToString()); UDT.Subject record = this.dgvData.SelectedRows[0].Tag as UDT.Subject; List <UDT.Subject> records = new List <UDT.Subject>(); records.Add(record); Event.DeliverActiveRecord.RaiseSendingEvent(this, new Event.DeliverActiveRecordEventArgs(records)); frm.ShowDialog(); if (frm.DialogResult == System.Windows.Forms.DialogResult.OK) { this.InitSubject(); } } catch (Exception ex) { MsgBox.Show(ex.Message); } }
private void Subject_Received(object sender, Event.DeliverActiveRecordEventArgs e) { IEnumerable <ActiveRecord> records = e.ActiveRecords; if (records == null || records.Count() == 0) { mRecord = new UDT.Subject(); return; } mRecord = records.ElementAt(0) as UDT.Subject; this.SubjectName.Text = mRecord.SubjectName.Trim(); this.Institute.Text = mRecord.Institute.Trim(); this.Level.Text = mRecord.Level + ""; this.Credit.Text = mRecord.Credit + ""; this.Type.Text = mRecord.Type.Trim(); this.Limit.Text = mRecord.Limit.ToString(); this.Goal.Text = mRecord.Goal.Trim().Replace("\n", "\r\n"); this.Content.Text = mRecord.Content.Trim().Replace("\n", "\r\n"); this.Memo.Text = mRecord.Memo.Trim().Replace("\n", "\r\n"); //-- this.tbxPreSubject.Text = mRecord.PreSubject.Trim(); this.tbxPreSubjectLevel.Text = mRecord.PreSubjectLevel.ToString().Trim() == "0" ? "" : mRecord.PreSubjectLevel.ToString().Trim(); this.tbxCrossType1.Text = mRecord.CrossType1.Trim(); this.tbxCrossType2.Text = mRecord.CrossType2.Trim(); this.cbxPreSubjectBlockMode.Text = mRecord.PreSubjectBlockMode.Trim(); this.cbxRejoinMode.Text = mRecord.RejoinBlockMode.Trim(); this.ckbxDisable.Checked = mRecord.Disabled; this.cboEntryType.Text = mRecord.EntryType.Trim(); this.cboRequiredBy.Text = mRecord.RequiredBy.Trim(); this.cboRequired.Text = mRecord.Required.Trim(); }
private void frmSubjectCreator_Load(object sender, EventArgs e) { if (this.mRecord == null) { this.mRecord = new UDT.Subject(); this.mRecord.SchoolYear = int.Parse(this.school_year); this.mRecord.Semester = int.Parse(this.semester); } }
private void dgvData_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && this.forSendingSubject) { UDT.Subject record = this.dgvData.Rows[e.RowIndex].Tag as UDT.Subject; List <UDT.Subject> records = new List <UDT.Subject>(); records.Add(record); Event.DeliverActiveRecord.RaiseSendingEvent(this, new Event.DeliverActiveRecordEventArgs(records)); } }
private void frmSubjectCreator_Load(object sender, EventArgs e) { if (this.mRecord == null) { //新增科目 this.mRecord = new UDT.Subject(); this.mRecord.SchoolYear = int.Parse(this.school_year); this.mRecord.Semester = int.Parse(this.semester); cboRequired.SelectedIndex = 1; } GetSubjectList(); }
private void Subject_Received(object sender, Event.DeliverActiveRecordEventArgs e) { IEnumerable <ActiveRecord> records = e.ActiveRecords; if (records == null || records.Count() == 0) { mRecord = new UDT.Subject(); return; } mRecord = records.ElementAt(0) as UDT.Subject; this.SubjectName.Text = mRecord.SubjectName.Trim(); this.Institute.Text = mRecord.Institute.Trim(); this.Level.Text = mRecord.Level + ""; this.Credit.Text = mRecord.Credit + ""; this.Type.Text = mRecord.Type.Trim(); this.Limit.Text = mRecord.Limit.ToString(); this.Goal.Text = mRecord.Goal.Trim().Replace("\n", "\r\n"); this.Content.Text = mRecord.Content.Trim().Replace("\n", "\r\n"); this.Memo.Text = mRecord.Memo.Trim().Replace("\n", "\r\n"); }
private void Delete_Click(object sender, EventArgs e) { if (this.dgvData.SelectedRows.Count == 0) { System.Windows.Forms.MessageBox.Show("請先選擇科目。"); return; } try { UDT.Subject record = this.dgvData.SelectedRows[0].Tag as UDT.Subject; record.Deleted = true; record.Save(); this.InitSubject(); } catch (Exception ex) { MsgBox.Show(ex.Message); } }
public override string Import(List <EMBA.DocumentValidator.IRowStream> Rows) { List <UDT.Subject> ExistingSubjectRecords = _Access.Select <UDT.Subject>(); // 要新增的 CourseRecord List <UDT.Subject> insertSubjectRecords = new List <UDT.Subject>(); // 要更新的 CourseRecord List <UDT.Subject> updateSubjectRecords = new List <UDT.Subject>(); foreach (IRowStream row in Rows) { string subject_uid = row.GetValue("科目系統編號").Trim(); string school_year = row.GetValue("學年度").Trim(); string semester = row.GetValue("學期").Trim(); string institute = row.GetValue("教學單位").Trim(); string type = row.GetValue("課程時段").Trim(); string subject_name = row.GetValue("科目名稱").Trim(); string level = row.GetValue("級別").Trim(); UDT.Subject subjectRecord = new UDT.Subject(); IEnumerable <UDT.Subject> filterSubjectRecords = new List <UDT.Subject>(); // 若鍵值不為「科目系統編號」,則查出哪些課程是要新增的 if (_keyField != "科目系統編號") { filterSubjectRecords = ExistingSubjectRecords.Where(x => (x.SchoolYear.ToString() == school_year)).Where(x => (x.Semester.ToString() == semester)).Where(x => (x.Type.ToString() == type)).Where(x => (x.SubjectName.ToString().Trim() == subject_name)).Where(x => ((x.Level.HasValue ? x.Level.Value.ToString() : "") == level)); } else { filterSubjectRecords = ExistingSubjectRecords.Where(x => x.UID == subject_uid); } if (filterSubjectRecords.Count() > 0) { subjectRecord = filterSubjectRecords.ElementAt(0); } // 寫入: 學年度, 學期, 科目名稱, 級別, 學分, 課程時段, 修課人數上限, 教學目標, 教學內容, 備註 if (_keyField != "科目系統編號") { subjectRecord.SchoolYear = int.Parse(school_year); subjectRecord.Semester = int.Parse(semester); subjectRecord.Type = type; subjectRecord.SubjectName = subject_name; if (level == "") { subjectRecord.Level = null; } else { subjectRecord.Level = int.Parse(level); } } else { if (_mOption.SelectedFields.Contains("學年度") && !string.IsNullOrEmpty(school_year)) { subjectRecord.SchoolYear = int.Parse(school_year); } if (_mOption.SelectedFields.Contains("學期") && !string.IsNullOrEmpty(semester)) { subjectRecord.Semester = int.Parse(semester); } if (_mOption.SelectedFields.Contains("課程時段")) { subjectRecord.Type = type; } if (_mOption.SelectedFields.Contains("科目名稱") && !string.IsNullOrEmpty(subject_name)) { subjectRecord.SubjectName = subject_name; } if (_mOption.SelectedFields.Contains("級別")) { if (string.IsNullOrEmpty(level)) { subjectRecord.Level = null; } else { subjectRecord.Level = int.Parse(level); } } } if (_mOption.SelectedFields.Contains("教學單位") && !string.IsNullOrEmpty(institute)) { subjectRecord.Institute = institute; } if (_mOption.SelectedFields.Contains("學分數")) { int tryParseInt = 0; if (int.TryParse(row.GetValue("學分數"), out tryParseInt)) { subjectRecord.Credit = tryParseInt; } else { subjectRecord.Credit = null; } } //if (mOption.SelectedFields.Contains("課程時段") && !string.IsNullOrWhiteSpace(row.GetValue("課程時段"))) // subjectRecord.Type = row.GetValue("課程時段").Trim(); if (_mOption.SelectedFields.Contains("修課人數上限") && !string.IsNullOrWhiteSpace(row.GetValue("修課人數上限"))) { subjectRecord.Limit = int.Parse(row.GetValue("修課人數上限").Trim()); } // 2020/02/04 Cyn修正: 跨課程時段1、跨課程時段2、前導課程科目、前導課程級別、 前導課程採計方式、重複修課採計方式、教學目標、 教學內容、備註 匯入空白沒有以空白覆蓋原值問題 if (_mOption.SelectedFields.Contains("教學目標") && !string.IsNullOrWhiteSpace(row.GetValue("教學目標"))) { subjectRecord.Goal = row.GetValue("教學目標").Trim(); } else { subjectRecord.Goal = null; } if (_mOption.SelectedFields.Contains("教學內容") && !string.IsNullOrWhiteSpace(row.GetValue("教學內容"))) { subjectRecord.Content = row.GetValue("教學內容").Trim(); } else { subjectRecord.Content = null; } if (_mOption.SelectedFields.Contains("備註") && !string.IsNullOrWhiteSpace(row.GetValue("備註"))) { subjectRecord.Memo = row.GetValue("備註").Trim(); } else { subjectRecord.Memo = null; } // 2018/07/19 羿均 新增欄位 if (_mOption.SelectedFields.Contains("前導課程科目") && !string.IsNullOrWhiteSpace(row.GetValue("前導課程科目"))) { subjectRecord.PreSubject = row.GetValue("前導課程科目").Trim(); } else { subjectRecord.PreSubject = null; } if (_mOption.SelectedFields.Contains("前導課程級別") && !string.IsNullOrWhiteSpace(row.GetValue("前導課程級別"))) { subjectRecord.PreSubjectLevel = int.Parse(row.GetValue("前導課程級別").Trim()); } else { subjectRecord.PreSubjectLevel = null; } if (_mOption.SelectedFields.Contains("前導課程採計方式") && !string.IsNullOrWhiteSpace(row.GetValue("前導課程採計方式"))) { subjectRecord.PreSubjectBlockMode = row.GetValue("前導課程採計方式").Trim(); } else { subjectRecord.PreSubjectBlockMode = null; } if (_mOption.SelectedFields.Contains("重複修課採計方式") && !string.IsNullOrWhiteSpace(row.GetValue("重複修課採計方式"))) { subjectRecord.RejoinBlockMode = row.GetValue("重複修課採計方式").Trim(); } else { subjectRecord.RejoinBlockMode = null; } if (_mOption.SelectedFields.Contains("不開課") && !string.IsNullOrWhiteSpace(row.GetValue("不開課"))) { subjectRecord.Disabled = row.GetValue("不開課").Trim() == "是" ? true : false; } if (_mOption.SelectedFields.Contains("跨課程時段1") && !string.IsNullOrWhiteSpace(row.GetValue("跨課程時段1"))) { subjectRecord.CrossType1 = row.GetValue("跨課程時段1").Trim(); } else { subjectRecord.CrossType1 = null; } if (_mOption.SelectedFields.Contains("跨課程時段2") && !string.IsNullOrWhiteSpace(row.GetValue("跨課程時段2"))) { subjectRecord.CrossType2 = row.GetValue("跨課程時段2").Trim(); } else { subjectRecord.CrossType2 = null; } // 2021-12 Cyn 新增 //https://3.basecamp.com/4399967/buckets/15765350/todos/4448231024 if (_mOption.SelectedFields.Contains("分項類別") && !string.IsNullOrWhiteSpace(row.GetValue("分項類別"))) { subjectRecord.EntryType = row.GetValue("分項類別").Trim(); } else { subjectRecord.EntryType = null; } if (_mOption.SelectedFields.Contains("校部訂") && !string.IsNullOrWhiteSpace(row.GetValue("校部訂"))) { subjectRecord.RequiredBy = row.GetValue("校部訂").Trim(); } else { subjectRecord.RequiredBy = null; } if (_mOption.SelectedFields.Contains("必選修") && !string.IsNullOrWhiteSpace(row.GetValue("必選修"))) { subjectRecord.Required = row.GetValue("必選修").Trim(); } else { subjectRecord.Required = null; } if (subjectRecord.RecordStatus == RecordStatus.Insert) { insertSubjectRecords.Add(subjectRecord); } else { updateSubjectRecords.Add(subjectRecord); } } // 新增科目 List <string> insertedSubjectIDs = insertSubjectRecords.SaveAll(); // 更新科目 List <string> updatedSubjectIDs = updateSubjectRecords.SaveAll(); // RaiseEvent if (insertedSubjectIDs.Count > 0 || updatedSubjectIDs.Count > 0) { IEnumerable <string> uids = insertedSubjectIDs.Union(updatedSubjectIDs); UDT.Subject.RaiseAfterUpdateEvent(); } return(string.Empty); }
private void Save_Click(object sender, EventArgs e) { if (!this.Is_Validated()) { return; } List <UDT.Subject> records = new List <UDT.Subject>(); try { foreach (DataGridViewRow row in this.dgvData.Rows) { if (row.IsNewRow) { continue; } UDT.Subject subj = (UDT.Subject)row.Tag; if (subj == null) { subj = new UDT.Subject(); } subj.Institute = row.Cells["Institute"].Value + ""; subj.SubjectName = row.Cells["SubjectName"].Value + ""; int level = 0; if (int.TryParse(row.Cells["Level"].Value + "", out level)) { subj.Level = level; } subj.Type = row.Cells["Type"].Value + ""; int credit = 0; if (int.TryParse(row.Cells["Credit"].Value + "", out credit)) { subj.Credit = credit; } subj.Limit = int.Parse(row.Cells["Limit"].Value + ""); subj.Goal = row.Cells["Goal"].Value + ""; subj.Content = row.Cells["Content"].Value + ""; subj.Memo = row.Cells["Memo"].Value + ""; subj.SchoolYear = int.Parse(this.cboSchoolYear.Text); subj.Semester = int.Parse(this.cboSemester.Text); records.Add(subj); } List <UDT.Subject> dRecords = new List <UDT.Subject>(); oRecords.ForEach((x) => { if (records.Where(y => y.UID == x.UID).Count() == 0) { x.Deleted = true; dRecords.Add(x); } }); records.SaveAll(); dRecords.SaveAll(); MsgBox.Show("儲存成功!"); } catch (Exception ex) { MsgBox.Show(ex.Message); } }