private void _writeWorker_DoWork(object sender, DoWorkEventArgs e) { #region 寫入離校資訊 try { List <JHLeaveInfoRecord> leaveInfoRecordList = new List <JHLeaveInfoRecord>(); foreach (JHLeaveInfoRecord record in JHLeaveIfno.SelectByStudentIDs(_students.AsKeyList())) { if (!_passList.ContainsKey(record.RefStudentID)) { continue; } leaveInfoRecordList.Add(record); if (_passList[record.RefStudentID] == true) { record.Reason = "畢業"; record.Memo = string.Empty; } else { record.Reason = "修業"; StringBuilder builder = new StringBuilder(); _result[record.RefStudentID].Sort(); foreach (ResultDetail rd in _result[record.RefStudentID]) { string semester = rd.GradeYear + (rd.Semester.Equals("1") ? "上" : "下") + ":"; string details = string.Empty; foreach (string detail in rd.Details) { details += detail + ","; } if (details.EndsWith(",")) { details = details.Substring(0, details.Length - 1); } builder.AppendLine(semester + details); } record.Memo = builder.ToString(); } // 系統目前預設學年度 int SchoolYear; int.TryParse(JHSchool.School.DefaultSchoolYear, out SchoolYear); record.SchoolYear = SchoolYear; } JHLeaveIfno.Update(leaveInfoRecordList); } catch (Exception ex) { BugReporter.ReportException(ex, false); } #endregion #region 寫入類別(Tags) string FailurePrefix = "未達畢業標準"; try { List <JHTagConfigRecord> tagList = JHTagConfig.SelectByCategory(K12.Data.TagCategory.Student); TagConfigRecordComparer tagComparer = new TagConfigRecordComparer(); StudentTagRecordComparer studentTagComparer = new StudentTagRecordComparer(); #region 製作各種未達畢業標準的標籤 List <JHTagConfigRecord> tagConfigRecordList = new List <JHSchool.Data.JHTagConfigRecord>(); foreach (StudentRecord student in _students) { //如果學生通過畢業審查 if (_passList[student.ID]) { continue; } //如果審查結果沒有該學生編號則跳到下一筆 (這應該不會發生才對) if (!_result.ContainsKey(student.ID)) { continue; } List <ResultDetail> rdList = _result[student.ID]; foreach (ResultDetail rd in rdList) { foreach (string msg in rd.Messages) { JHTagConfigRecord tagConfigRecord = new JHTagConfigRecord(); tagConfigRecord.Prefix = FailurePrefix; tagConfigRecord.Name = msg; tagConfigRecord.Category = "Student"; if (!tagList.Contains(tagConfigRecord, tagComparer)) { tagConfigRecordList.Add(tagConfigRecord); tagList.Add(tagConfigRecord); //foreach (string tag_id in JHSchool.Data.TagConfig.Insert(tagConfigRecord)) //{ // if (!tagIDs.ContainsKey(tagConfigRecord.FullName)) // tagIDs.Add(tagConfigRecord.FullName, tag_id); //} } } } } JHTagConfig.Insert(tagConfigRecordList); tagList = JHTagConfig.SelectByCategory(K12.Data.TagCategory.Student); #endregion #region 貼上標籤 List <JHStudentTagRecord> studentTagsList = new List <JHStudentTagRecord>(); List <JHStudentTagRecord> deleteList = new List <JHStudentTagRecord>(); foreach (StudentRecord student in _students) { //如果學生通過畢業審查,應該把標籤拿下來 if (_passList[student.ID]) { foreach (JHStudentTagRecord student_tag in JHStudentTag.SelectByStudentID(student.ID)) { if (student_tag.Prefix == FailurePrefix) { deleteList.Add(student_tag); } } continue; } if (!_result.ContainsKey(student.ID)) { continue; } Dictionary <string, JHStudentTagRecord> studentTags = new Dictionary <string, JHStudentTagRecord>(); foreach (JHStudentTagRecord student_tag in JHStudentTag.SelectByStudentID(student.ID)) { if (!studentTags.ContainsKey(student_tag.RefTagID)) { studentTags.Add(student_tag.RefTagID, student_tag); } } List <ResultDetail> rdList = _result[student.ID]; foreach (ResultDetail rd in rdList) { foreach (string msg in rd.Messages) { string fullname = FailurePrefix + ":" + msg; foreach (JHTagConfigRecord record in tagList) { if (record.FullName == fullname && !studentTags.ContainsKey(record.ID)) { JHStudentTagRecord r = new JHStudentTagRecord(); r.RefTagID = record.ID; r.RefEntityID = student.ID; if (!studentTagsList.Contains(r, studentTagComparer)) { studentTagsList.Add(r); } } } } } } JHStudentTag.Insert(studentTagsList); JHStudentTag.Delete(deleteList); #endregion } catch (Exception ex) { BugReporter.ReportException(ex, false); } #endregion }
private void btnConfirm_Click(object sender, EventArgs e) { try { DialogResult = DialogResult.None; _OldTagRec = new JHTagConfigRecord(); _OldTagRec.Prefix = _current_tag.Prefix; _OldTagRec.Name = _current_tag.Name; _OldTagRec.ColorCode = _current_tag.ColorCode; _current_tag.Prefix = cboGroups.Text.Trim(); _current_tag.Name = txtName.Text.Trim(); _current_tag.Color = cpColor.SelectedColor; if (string.IsNullOrEmpty(_current_tag.Name)) { FISCA.Presentation.Controls.MsgBox.Show("您必須輸入類別名稱。"); return; } foreach (JHTagConfigRecord each in JHTagConfig.SelectAll()) { if (each == _current_tag) { continue; } if (_mode == ManageMode.Insert) { if (_current_tag.FullName == each.FullName && _current_tag.Category.ToUpper() == each.Category.ToUpper()) { FISCA.Presentation.Controls.MsgBox.Show("名稱重覆,請選擇其他名稱。"); return; } } } PermRecLogProcess prlp = new PermRecLogProcess(); if (_mode == ManageMode.Insert) { // Log prlp.SaveLog("學籍.類別管理", "類別管理新增類別", "新增 " + _current_tag.Category + " 類別,名稱:" + _current_tag.FullName); JHTagConfig.Insert(_current_tag); } else { // Log bool checkEdit = false; string strLogName = "更新 " + _current_tag.Category + " 類別,"; if (_OldTagRec.FullName != _current_tag.FullName) { strLogName += "名稱由「" + _OldTagRec.FullName + "」改為「" + _current_tag.FullName + "」,"; checkEdit = true; } if (_OldTagRec.ColorCode != _current_tag.ColorCode) { strLogName += "修改" + _current_tag.FullName + "顏色。"; checkEdit = true; } if (checkEdit) { prlp.SaveLog("學籍.類別管理", "類別管理更新類別", strLogName); } JHTagConfig.Update(_current_tag); } DialogResult = DialogResult.OK; } catch (Exception ex) { FISCA.Presentation.Controls.MsgBox.Show(ex.Message); DialogResult = DialogResult.None; } }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHStudentRecord>(); Dictionary <string, List <JHStudentTagRecord> > StudTagRecDic = new Dictionary <string, List <JHStudentTagRecord> > (); Dictionary <string, Dictionary <string, string> > StudTagNameDic = DAL.DALTransfer.GetStudentTagNameDic(); // 取得可加入學生 TagName wizard.PackageLimit = 3000; wizard.ImportableFields.AddRange(ImportItemList); wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { // 取得學生資料 foreach (JHStudentRecord studRec in JHStudent.SelectByIDs(e.List)) { if (!students.ContainsKey(studRec.ID)) { students.Add(studRec.ID, studRec); StudTagRecDic.Add(studRec.ID, new List <JHStudentTagRecord>()); } } // 取得學生類別 foreach (JHStudentTagRecord studTag in JHStudentTag.SelectByStudentIDs(students.Keys)) { //if (!StudTagRecDic.ContainsKey(studTag.RefStudentID)) //{ // List<JHStudentTagRecord> rec = new List<JHStudentTagRecord> (); // rec.Add(studTag ); // StudTagRecDic.Add(studTag.RefStudentID,rec); //} //else if (StudTagRecDic.ContainsKey(studTag.RefStudentID)) { StudTagRecDic[studTag.RefStudentID].Add(studTag); } } }; wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { int i = 0; // 檢查學生是否存在 JHStudentRecord studRec = null; if (students.ContainsKey(e.Data.ID)) { studRec = students[e.Data.ID]; } else { e.ErrorMessage = "沒有這位學生" + e.Data.ID; return; } // 驗證資料 foreach (string field in e.SelectFields) { string value = e.Data[field].Trim(); // 驗證$無法匯入 if (value.IndexOf('$') > -1) { e.ErrorFields.Add(field, "儲存格有$無法匯入."); break; } if (field == "類別名稱") { if (string.IsNullOrEmpty(value)) { e.ErrorFields.Add(field, "不允許空白"); } } } }; wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { // 目前學生類別管理,沒有新增標示類別,有的就不更動跳過。 Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >(); foreach (RowData data in e.Items) { if (!id_Rows.ContainsKey(data.ID)) { id_Rows.Add(data.ID, new List <RowData>()); } id_Rows[data.ID].Add(data); } List <JHStudentTagRecord> InsertList = new List <JHStudentTagRecord>(); // List<JHStudentTagRecord> UpdateList = new List<JHStudentTagRecord>(); // 放需要新增的學生類別 Dictionary <string, List <string> > NeedAddPrefixName = new Dictionary <string, List <string> >(); // 檢查用 List List <string> CheckStudTagName = new List <string>(); foreach (KeyValuePair <string, Dictionary <string, string> > data in StudTagNameDic) { foreach (KeyValuePair <string, string> data1 in data.Value) { CheckStudTagName.Add(data.Key + data1.Key); } } // 檢查類別是否已經存在 foreach (string id in id_Rows.Keys) { if (!StudTagRecDic.ContainsKey(id)) { continue; } foreach (RowData data in id_Rows[id]) { string strPrefix = string.Empty, strName = string.Empty; if (data.ContainsKey("群組")) { strPrefix = data["群組"]; } if (data.ContainsKey("類別名稱")) { strName = data["類別名稱"]; } string FullName = strPrefix + strName; // 需要新增的, if (!CheckStudTagName.Contains(FullName)) { CheckStudTagName.Add(FullName); if ((NeedAddPrefixName.ContainsKey(strPrefix))) { NeedAddPrefixName[strPrefix].Add(strName); } else { List <string> Names = new List <string>(); Names.Add(strName); NeedAddPrefixName.Add(strPrefix, Names); } } } } // 新增至學生類別管理 List <JHTagConfigRecord> Recs = new List <JHTagConfigRecord>(); foreach (KeyValuePair <string, List <string> > data in NeedAddPrefixName) { foreach (string data1 in data.Value) { JHTagConfigRecord rec = new JHTagConfigRecord(); rec.Category = "Student"; rec.Prefix = data.Key; rec.Name = data1; rec.Color = System.Drawing.Color.White; Recs.Add(rec); } } JHTagConfig.Insert(Recs); StudTagNameDic.Clear(); // 重新取得 StudTagNameDic = DAL.DALTransfer.GetStudentTagNameDic(); foreach (string id in id_Rows.Keys) { if (!StudTagRecDic.ContainsKey(id)) { continue; } foreach (RowData data in id_Rows[id]) { string strPrefix = string.Empty, strName = string.Empty; if (data.ContainsKey("群組")) { strPrefix = data["群組"]; } if (data.ContainsKey("類別名稱")) { strName = data["類別名稱"]; } // 欄位有在 Tag Prefix 內 bool isInsert = true; foreach (JHStudentTagRecord rec in StudTagRecDic[id]) { if (rec.Prefix == strPrefix && rec.Name == strName) { isInsert = false; break; } } if (isInsert) { // 學生類別管理名稱對照 if (StudTagNameDic.ContainsKey(strPrefix)) { if (StudTagNameDic[strPrefix].ContainsKey(strName)) { JHStudentTagRecord StudTag = new JHStudentTagRecord(); StudTag.RefEntityID = id; StudTag.RefTagID = StudTagNameDic[strPrefix][strName]; InsertList.Add(StudTag); } } } } } try { if (InsertList.Count > 0) { Insert(InsertList); } //if (UpdateList.Count > 0) // Update(UpdateList); JHSchool.PermRecLogProcess prlp = new JHSchool.PermRecLogProcess(); prlp.SaveLog("學生.匯入類別", "匯入學生類別", "匯入學生類別:共新增" + InsertList.Count + "筆資料"); JHSchool.Student.Instance.SyncAllBackground(); JHSchool.StudentTag.Instance.SyncAllBackground(); JHSchool.Data.JHStudent.RemoveAll(); JHSchool.Data.JHStudent.SelectAll(); } catch (Exception ex) {} }; }