private void 分發學生(推甄學生資料 學生, Dictionary <校系資料, 推甄學生資料[]> 蘿蔔坑) { 學生.分發結果 = null; foreach (var item in 學生.志願組) { if (!item.忽略 && 蘿蔔坑.ContainsKey(item.校系資料)) { 推甄學生資料 現實很殘酷 = null; for (int i = 0; i < 蘿蔔坑[item.校系資料].Length; i++) { if (蘿蔔坑[item.校系資料][i] == null) { 蘿蔔坑[item.校系資料][i] = 學生; 學生.分發結果 = item.校系資料; 現實很殘酷 = null; break; } else { if (蘿蔔坑[item.校系資料][i].排名 > 學生.排名) { 現實很殘酷 = 蘿蔔坑[item.校系資料][i]; } else if (蘿蔔坑[item.校系資料][i].排名 == 學生.排名 && item.校系資料.組別 == 學生.組別 && item.校系資料.組別 != 蘿蔔坑[item.校系資料][i].組別) { 現實很殘酷 = 蘿蔔坑[item.校系資料][i]; } } } if (現實很殘酷 != null) { 學生.分發結果 = item.校系資料; for (int i = 0; i < 蘿蔔坑[item.校系資料].Length; i++) { if (蘿蔔坑[item.校系資料][i] == 現實很殘酷) { 蘿蔔坑[item.校系資料][i] = 學生; 分發學生(現實很殘酷, 蘿蔔坑); break; } } } } if (學生.分發結果 != null) { break; } } }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { List <推甄學生資料> importRecords = new List <推甄學生資料>(); List <string> validatedID = new List <string>(); //可以匯入這麼多欄位喔~ wizard.ImportableFields.AddRange("排名", "總分", "成績內容", "分發校系代碼", "分發學校", "分發科系", "確定分發結果", "組別", "梯次", "備註"); //開始驗證前先收集一些資訊於驗證過程中使用 wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { FISCA.UDT.Condition.InCondition condition = new FISCA.UDT.Condition.InCondition(); condition.Field = "RefStudentID"; condition.Values.AddRange(e.List); importRecords = new AccessHelper().Select <推甄學生資料>(condition); importRecords.取得志願組(); }; //每一列資料會觸發一次驗證 wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { if (validatedID.Contains(e.Data.ID)) { e.ErrorMessage = "同一學生不應出現兩筆資料。"; } else { #region 驗證各欄位資料 validatedID.Add(e.Data.ID); foreach (var field in e.SelectFields) { string value = e.Data[field]; switch (field) { case "排名": int i = 0; if (!int.TryParse(value, out i) || i <= 0) { e.ErrorFields.Add(field, "必需是大於0之整數。"); } break; case "總分": decimal d; if (e.Data[field] != "" && (!decimal.TryParse(value, out d) || d < 0m)) { e.ErrorFields.Add(field, "必需為空白或大於等於0之數字。"); } break; case "成績內容": break; case "分發校系代碼": if (value != "") { if (!校系資料庫.Items.ContainsKey(value)) { e.ErrorFields.Add(field, "查無此校系代碼。"); } else { bool match = false; foreach (var data in importRecords) { if (data.StudentRecord.ID == e.Data.ID) { foreach (var wish in data.志願組) { if (wish.校系資料.代碼 == value) { match = true; break; } } break; } } if (!match) { e.WarningFields.Add(field, "此分發結果不在該學生的志願中,可能導致統計數字錯誤。"); } } } break; case "分發學校": if (!e.SelectFields.Contains("分發校系代碼")) { e.ErrorFields.Add(field, "分發結果必須以校系代碼為主,無法單獨由分發學校判斷。"); } else { if (校系資料庫.Items.ContainsKey(e.Data["分發校系代碼"]) && 校系資料庫.Items[e.Data["分發校系代碼"]].校名 != value) { e.ErrorFields.Add(field, "校名與校系代碼不相同。"); } } break; case "分發科系": if (!e.SelectFields.Contains("分發校系代碼")) { e.ErrorFields.Add(field, "分發結果必須以校系代碼為主,無法單獨由分發科系判斷。"); } else { if (校系資料庫.Items.ContainsKey(e.Data["分發校系代碼"]) && 校系資料庫.Items[e.Data["分發校系代碼"]].系名 != value) { e.ErrorFields.Add(field, "系名與校系代碼不相同。"); } } break; case "確定分發結果": if (value != "" && value != "是" && value != "否" && value.ToLower() != "true" && value.ToLower() != "false") { e.ErrorFields.Add(field, "輸入值不允許,請輸入是或否,若保留空白則視為否。"); } break; case "梯次": int j = 0; if (value != "" && !int.TryParse(value, out j) || j <= 0) { e.ErrorFields.Add(field, "必需是大於0之整數或空白。"); } break; case "備註": break; default: break; } } #endregion } }; //匯入會一次切一個package做批次,每次只處理package的資料匯入即可 wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { List <推甄學生資料> importPackage = new List <推甄學生資料>(); foreach (var rowData in e.Items) { 推甄學生資料 targetData = null; foreach (var rec in importRecords) { if (rec.StudentRecord.ID == rowData.ID) { targetData = rec; break; } } if (targetData == null) { targetData = new 推甄學生資料(); targetData.StudentRecord = K12.Data.Student.SelectByID(rowData.ID); } importPackage.Add(targetData); #region 填入資料 foreach (var field in e.ImportFields) { string value = rowData[field]; switch (field) { case "排名": targetData.排名 = int.Parse(value); break; case "總分": targetData.總分 = (value == "" ? null : new decimal?(decimal.Parse(value))); break; case "成績內容": targetData.成績內容 = value; break; case "分發校系代碼": targetData.分發結果 = (value == "" ? null : 校系資料庫.Items[value]); break; case "分發學校": break; case "分發科系": break; case "確定分發結果": targetData.確定分發結果 = ((value == "" || value == "否" || value.ToLower() == "false") ? false : true); break; case "組別": targetData.組別 = value; break; case "梯次": targetData.梯次 = (value == "" ? null : new int?(int.Parse(value))); break; case "備註": targetData.備註 = value; break; default: break; } } #endregion } importPackage.SaveAll(); }; }
public 推甄資料毛毛蟲() { InitializeComponent(); comboTree1.AdvTree.VisibleChanged += delegate { if (comboTree1.AdvTree.Visible) { comboTree1.AdvTree.Focus(); } }; _BKW.DoWork += delegate { var list = 校系資料庫.Items; var items = _AccessHelper.Select <推甄學生資料>(new FISCA.UDT.Condition.EqualsCondition() { Field = "RefStudentID", Value = _RunningID }); if (items.Count == 0) { _CurrentData = new 推甄學生資料() { StudentRecord = K12.Data.Student.SelectByID(_RunningID) } } ; else { _CurrentData = items[0]; if (items.Count > 1) { items.RemoveAt(0); foreach (var item in items) { item.Deleted = true; } items.SaveAll(); } } }; _BKW.RunWorkerCompleted += delegate { if (_RunningID != PrimaryKey) { _RunningID = PrimaryKey; _BKW.RunWorkerAsync(); } else { Node selectedNode = null; Dictionary <string, List <校系資料> > schoolGroup = new Dictionary <string, List <校系資料> >(); foreach (var item in 校系資料庫.Items.Values) { if (!schoolGroup.ContainsKey(item.校名)) { schoolGroup.Add(item.校名, new List <校系資料>()); } schoolGroup[item.校名].Add(item); } comboTree1.Nodes.Clear(); List <Node> schoolNodes = new List <Node>(); foreach (var school in schoolGroup.Keys) { Node schoolNode = new Node(); schoolNode.Cells.Clear(); schoolNodes.Add(schoolNode); schoolNode.Cells.Add(new DevComponents.AdvTree.Cell(school)); schoolNode.Cells.Add(new DevComponents.AdvTree.Cell("")); List <Node> nodes = new List <Node>(); foreach (var item in schoolGroup[school]) { Node node = new Node(); node.Cells.Clear(); nodes.Add(node); node.Cells.Add(new DevComponents.AdvTree.Cell(item.系名)); node.Cells.Add(new DevComponents.AdvTree.Cell(item.代碼)); node.Tag = item; if (item == _CurrentData.分發結果) { selectedNode = node; } } ; schoolNode.Nodes.AddRange(nodes.ToArray()); } comboTree1.Nodes.AddRange(schoolNodes.ToArray()); errorProvider1.Clear(); comboTree1.Tag = comboTree1.SelectedNode = selectedNode; comboTree1_PopupClose(null, null); chk確定分發.Tag = chk確定分發.Checked = _CurrentData.確定分發結果; txt梯次.Tag = txt梯次.Text = "" + _CurrentData.梯次; txt組別.Tag = txt組別.Text = _CurrentData.組別; txt總分.Tag = txt總分.Text = "" + _CurrentData.總分; txt備註.Tag = txt備註.Text = "" + _CurrentData.備註; txt排名.Tag = txt排名.Text = "" + _CurrentData.排名; txt成績內容.Tag = txt成績內容.Text = _CurrentData.成績內容; this.Loading = false; } }; }