/// <summary> /// 開始進行社團分配作業 /// </summary> private VolunteerJoinBox StartAllocation(List <ClassRowInfo> RowDataList) { //Step1.進行學生優先權判斷(社長副,社長) VolunteerJoinBox os = PriorityAllocation(RowDataList); #region 高優先學生 //設定亂數 SetRan(os.Step1Student); //開始進行社團分配之前,先進行亂數排序 os.Step1Student.Sort(SortStudent); if (os.Step1Student.Count > 0) { Step1(os.Step1Student); } #endregion #region 一般學生 List <OnlineStudent> list = new List <OnlineStudent>(); list.AddRange(os.Step1Student); //第一階段未入設之學生 //加入第二階段的亂數設定 foreach (OnlineStudent stud in list) { if (!stud.JoinSuccess) { os.Step2Student.Add(stud); if (os.Step1Student.Contains(stud)) { os.Step1Student.Remove(stud); } } } //設定亂數 SetRan(os.Step2Student); //開始進行社團分配之前,先進行亂數排序 os.Step2Student.Sort(SortStudent); if (os.Step2Student.Count > 0) { for (int Number = 1; Number <= tool.學生選填志願數; Number++) { Step2(os.Step2Student, Number); } } #endregion return(os); //進行學生原社團資料刪除 }
/// <summary> /// 學生優先權判斷 /// </summary> private VolunteerJoinBox PriorityAllocation(List <ClassRowInfo> list) { VolunteerJoinBox os = new VolunteerJoinBox(); foreach (ClassRowInfo row in list) //班級 { foreach (OnlineStudent student in row.StudentList) //學生 { //如果是鎖定學生,就不加入社團分配清單 if (student.IsLick) { continue; } if (!tool.已有社團記錄時 && student.原有社團 != null) { continue; } //學生是否有高優先權,會進行第一輪的志願分配 if (student.HighPriority) { os.Step1Student.Add(student); } else { os.Step2Student.Add(student); } } } return(os); }
void BGW_Run_DoWork(object sender, DoWorkEventArgs e) { LogDic = new List <LogAssignRecord>(); //資源整合社團 - MergerClubDic //目前要進行社團志願處理的班級 - RowDataList List <ClassRowInfo> RowDataList = (List <ClassRowInfo>)e.Argument; if (tool.已有社團記錄時) //有社團記錄時,不進行退社(True覆蓋,False略過) { //進行已選學生的退社處理 foreach (ClassRowInfo cl in RowDataList) { foreach (OnlineStudent student in cl.StudentList) { //退出社團 student.RetirementCommunity(MergerClubDic); } } } //開始社團分配 VolunteerJoinBox os = StartAllocation(RowDataList); #region 新增社團記錄 Dictionary <string, XmlHelper> InsertDic = os.GetNewStudSCJoinList(); foreach (string School_Name in InsertDic.Keys) { Connection me = new Connection(); me.Connect(School_Name, tool._contract, FISCA.Authentication.DSAServices.PassportToken); me = me.AsContract(tool._contract); try { Envelope rsp = me.SendRequest("_.InsterScjoin", new Envelope(InsertDic[School_Name])); } catch (Exception ex) { MsgBox.Show("新增社團參與記錄發生錯誤!!\n" + ex.Message); } } #endregion #region 刪除社團記錄 if (tool.已有社團記錄時) { Dictionary <string, XmlHelper> DeleteDic = os.GetDeleteStudSCJoinList(); foreach (string School_Name in DeleteDic.Keys) { Connection me = new Connection(); me.Connect(School_Name, tool._contract, FISCA.Authentication.DSAServices.PassportToken); me = me.AsContract(tool._contract); try { Envelope rsp = me.SendRequest("_.DeleteScjoin", new Envelope(DeleteDic[School_Name])); } catch (Exception ex) { MsgBox.Show("清除社團參與記錄發生錯誤!!\n" + ex.Message); } } } #endregion //LOG未完成 StringBuilder sbLog_s = new StringBuilder(); sbLog_s.AppendLine("志願分配結果如下:"); //LOG foreach (LogAssignRecord la in LogDic) { if (!string.IsNullOrEmpty(la.其它)) { sbLog_s.AppendLine("部別「" + la.部別 + "」班級「" + la.班級 + "」座號「" + la.座號 + "」學生「" + la.姓名 + "」志願「" + la.志願 + "」社團名稱「" + la.社團名稱 + "」(高優先學生)"); } else { sbLog_s.AppendLine("部別「" + la.部別 + "」班級「" + la.班級 + "」座號「" + la.座號 + "」學生「" + la.姓名 + "」志願「" + la.志願 + "」社團名稱「" + la.社團名稱 + "」"); } } FISCA.LogAgent.ApplicationLog.Log("[特殊歷程]", "志願分配", sbLog_s.ToString()); LogDic.Sort(SortLogRecord); StringBuilder sbLog = new StringBuilder(); sbLog.AppendLine("志願分配結果如下:"); //LOG foreach (LogAssignRecord la in LogDic) { if (!string.IsNullOrEmpty(la.其它)) { sbLog.AppendLine("部別「" + la.部別 + "」班級「" + la.班級 + "」座號「" + la.座號 + "」學生「" + la.姓名 + "」志願「" + la.志願 + "」社團名稱「" + la.社團名稱 + "」(高優先學生)"); } else { sbLog.AppendLine("部別「" + la.部別 + "」班級「" + la.班級 + "」座號「" + la.座號 + "」學生「" + la.姓名 + "」志願「" + la.志願 + "」社團名稱「" + la.社團名稱 + "」"); } } FISCA.LogAgent.ApplicationLog.Log("社團跨部別分配", "志願分配", sbLog.ToString()); }