/// <summary> /// 傳入單一社團ID /// 本功能用以取得社團學生清單 /// </summary> public ScJoinMag(string ClubRecordID) { //取得參與記錄 StringBuilder sb = new StringBuilder(); sb.Append(string.Format("ref_club_id='{0}'", ClubRecordID)); SCJoin_LIst = _AccessHelper.Select <SCJoin>(sb.ToString()); string Test = ""; //取得學生物件 List <string> list = new List <string>(); foreach (SCJoin each in SCJoin_LIst) { if (!list.Contains(each.RefStudentID)) { list.Add(each.RefStudentID); } if (!SCJoin_Dic.ContainsKey(each.RefStudentID)) { SCJoin_Dic.Add(each.RefStudentID, new List <SCJoin>()); } SCJoin_Dic[each.RefStudentID].Add(each); if (each.Lock) { if (!SCJoin_Lock.Contains(each.RefStudentID)) { SCJoin_Lock.Add(each.RefStudentID); } } } SCJoinStudent_LIst = Student.SelectByIDs(list); foreach (StudentRecord each in SCJoinStudent_LIst) { if (tool.CheckStatus(each)) { if (!StudentDic.ContainsKey(each.ID)) { StudentDic.Add(each.ID, each); } } if (!StudentAllDic.ContainsKey(each.ID)) { StudentAllDic.Add(each.ID, each); } } //排序 SCJoinStudent_LIst = SortClassIndex.K12Data_StudentRecord(SCJoinStudent_LIst); }
/// <summary> /// 社團學生排序 /// </summary> private Dictionary <string, List <StudentRecord> > SortStudentDic(Dictionary <string, List <StudentRecord> > ClubByStudentList) { Dictionary <string, List <StudentRecord> > dic = new Dictionary <string, List <StudentRecord> >(); foreach (string each in ClubByStudentList.Keys) { if (!dic.ContainsKey(each)) { dic.Add(each, new List <StudentRecord>()); } dic[each] = SortClassIndex.K12Data_StudentRecord(ClubByStudentList[each]); } return(dic); }
/// <summary> /// 建立待處理學生在按鈕內 /// </summary> private void CreateStudentMenuItem() { btnInserStudent.SubItems.Clear(); if (K12.Presentation.NLDPanels.Student.TempSource.Count == 0) { LabelItem item = new LabelItem("No", "沒有任何學生在待處理"); btnInserStudent.SubItems.Add(item); return; } List <StudentRecord> StudentList = Student.SelectByIDs(K12.Presentation.NLDPanels.Student.TempSource); foreach (ClassRecord cr in tool.GetClassDic(StudentList).Values) { if (!ClassDic.ContainsKey(cr.ID)) { ClassDic.Add(cr.ID, cr); } } StudentList = SortClassIndex.K12Data_StudentRecord(StudentList); foreach (StudentRecord each in StudentList) { StringBuilder sbstud = new StringBuilder(); string classname = ""; string seatno = ""; if (!string.IsNullOrEmpty(each.RefClassID)) { if (ClassDic.ContainsKey(each.RefClassID)) { classname = ClassDic[each.RefClassID].Name; seatno = (each.SeatNo.HasValue ? each.SeatNo.Value.ToString() : ""); } } sbstud.Append("班級「" + classname + "」"); sbstud.Append("座號「" + seatno + "」"); sbstud.Append("姓名「" + each.Name + "」"); ButtonItem item = new ButtonItem(each.ID, sbstud.ToString()); item.Tag = each; item.Click += new EventHandler(item_Click); btnInserStudent.SubItems.Add(item); } }
void BGW_DoWork(object sender, DoWorkEventArgs e) { //取得社團資料 List <CLUBRecord> ClubPrimaryList = _AccessHelper.Select <CLUBRecord>(string.Format("UID = '{0}'", this.PrimaryKey)); if (ClubPrimaryList.Count != 1) { //如果取得2門以上 或 沒取得社團時 e.Cancel = true; return; } ClubPrimary = ClubPrimaryList[0]; List <string> studList = new List <string>(); StringBuilder sb = new StringBuilder(); sb.Append(string.Format("ref_club_id='{0}'", ClubPrimary.UID)); List <SCJoin> SCJoin_LIst = _AccessHelper.Select <SCJoin>(sb.ToString()); foreach (SCJoin scj in SCJoin_LIst) { if (!studList.Contains(scj.RefStudentID)) { studList.Add(scj.RefStudentID); } } #region 社長 if (!string.IsNullOrEmpty(ClubPrimary.President)) { if (studList.Contains(ClubPrimary.President)) { StudPresident = Student.SelectByID(ClubPrimary.President); } else { StudPresident = null; } } else { StudPresident = null; } #endregion #region 副社長 if (!string.IsNullOrEmpty(ClubPrimary.VicePresident)) { if (studList.Contains(ClubPrimary.VicePresident)) { StudVicePresident = Student.SelectByID(ClubPrimary.VicePresident); } else { StudVicePresident = null; } } else { StudVicePresident = null; } #endregion //取得老師指定的幹部資料CadresRecord CadresList = _AccessHelper.Select <CadresRecord>(string.Format("ref_club_id = '{0}'", this.PrimaryKey)); //取得社團學生 //建立下拉式選單內的學生清單 StudentDic.Clear(); StudentIDIndexDic.Clear(); Log_StudentDic.Clear(); List <StudentRecord> _StudRecordlist = Student.SelectByIDs(studList); _StudRecordlist = SortClassIndex.K12Data_StudentRecord(_StudRecordlist); //studlist.Sort(); StudRecordlist = new List <CadreStudentObj>(); foreach (StudentRecord stud in _StudRecordlist) { CadreStudentObj obj = new CadreStudentObj(); StringBuilder sb1 = new StringBuilder(); sb1.Append(stud.Class != null ? stud.Class.Name : ""); sb1.Append(" "); sb1.Append(stud.SeatNo.HasValue ? stud.SeatNo.Value.ToString() : ""); sb1.Append(" "); sb1.Append(stud.Name); obj.TolName = sb1.ToString(); obj.stuent = stud; StudRecordlist.Add(obj); if (!StudentDic.ContainsKey(sb1.ToString())) { StudentDic.Add(sb1.ToString(), stud); } if (!Log_StudentDic.ContainsKey(stud.ID)) { Log_StudentDic.Add(stud.ID, stud); } } }
/// <summary> /// 取得學生的社團記錄 /// </summary> private void GetAndSortStudent() { SCjoinObjDic.Clear(); ClassByStudentDic.Clear(); //取得班級清單 List <string> ClassIDList = K12.Presentation.NLDPanels.Class.SelectedSource; foreach (ClassRecord each in Class.SelectByIDs(ClassIDList)) { if (!ClassDic.ContainsKey(each.ID)) { ClassDic.Add(each.ID, each); } } //取得學生清單 List <StudentRecord> studentList = K12.Data.Student.SelectByClassIDs(ClassIDList); studentList = SortClassIndex.K12Data_StudentRecord(studentList); foreach (StudentRecord stud in studentList) { if (tool.CheckStatus(stud)) { if (string.IsNullOrEmpty(stud.RefClassID)) { continue; } //班級:學生ID清單:學生Record if (!ClassByStudentDic.ContainsKey(stud.RefClassID)) { ClassByStudentDic.Add(stud.RefClassID, new List <StudentRecord>()); } if (!ClassByStudentDic[stud.RefClassID].Contains(stud)) { ClassByStudentDic[stud.RefClassID].Add(stud); } //學生ID:特殊Obj StudentSCjoinObj sc = new StudentSCjoinObj(stud); if (!SCjoinObjDic.ContainsKey(stud.ID)) { SCjoinObjDic.Add(stud.ID, sc); } } } List <string> StudentIDList = new List <string>(); foreach (StudentRecord sr in studentList) { if (!StudentIDList.Contains(sr.ID)) { StudentIDList.Add(sr.ID); } } //由學生ID去比對SCJoin List <SCJoin> SCJoinLIst = _AccessHelper.Select <SCJoin>("ref_student_id in ('" + string.Join("','", StudentIDList) + "')"); List <CLUBRecord> CLUBList = GetCLUB(SCJoinLIst); Dictionary <string, CLUBRecord> CLUBDic = new Dictionary <string, CLUBRecord>(); foreach (CLUBRecord each in CLUBList) { if (each.SchoolYear == _SchoolYear && each.Semester == _Semester) { if (!CLUBDic.ContainsKey(each.UID)) { CLUBDic.Add(each.UID, each); } } } //由SCJoin的ref_club_id取得社團資料 foreach (SCJoin each in SCJoinLIst) { if (SCjoinObjDic.ContainsKey(each.RefStudentID)) { if (CLUBDic.ContainsKey(each.RefClubID)) { SCjoinObjDic[each.RefStudentID].CLUBRecord.Add(CLUBDic[each.RefClubID]); } } } }
/// <summary> /// 將傳入的學生ID,加入此課程 /// </summary> private void AddListViewInTemp(List <string> IsSaft) { if (IsSaft.Count != 0) { cso = new ClubStudObj(); //Log StringBuilder sb_Message = new StringBuilder(); #region 可加入的學生清單 //排除已存在本課程的學生 cso.CheckTempStudentInCourse(IsSaft, scMAG.SCJoin_Dic, _CLUBRecord); StringBuilder sb_Log = new StringBuilder(); sb_Log.AppendLine(string.Format("加入「{0}」名社團參與學生:(學年度「{1}」學期「{2}」社團「{3}」)", cso.InsertList.Count.ToString(), _CLUBRecord.SchoolYear.ToString(), _CLUBRecord.Semester.ToString(), _CLUBRecord.ClubName)); if (cso.ReMoveTemp.Count != 0) { #region 是否有重覆加入本社學生 - 錯誤 sb_Message.AppendLine("共有" + cso.ReMoveTemp.Count + "名學生,存在本社團!!"); List <StudentRecord> studlist = Student.SelectByIDs(cso.ReMoveTemp); studlist = SortClassIndex.K12Data_StudentRecord(studlist); foreach (StudentRecord stud in studlist) { string class_981 = string.IsNullOrEmpty(stud.RefClassID) ? "" : stud.Class.Name; string SeatNo_981 = stud.SeatNo.HasValue ? stud.SeatNo.Value.ToString() : ""; sb_Message.AppendLine("班級「" + class_981 + "」座號「" + SeatNo_981 + "」姓名「" + stud.Name + "」"); } #endregion MsgBox.Show(sb_Message.ToString(), "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cso.ReDoubleTemp.Count != 0) { #region 重覆參與其它社團記錄 -警告 sb_Message.AppendLine("共有" + cso.ReDoubleTemp.Count + "筆,重覆參與其它社團記錄"); //取得重覆社團 List <CLUBRecord> cludlist = tool._A.Select <CLUBRecord>("uid in ('" + string.Join("','", cso.GetClubID()) + "')"); Dictionary <string, CLUBRecord> clubDic = new Dictionary <string, CLUBRecord>(); foreach (CLUBRecord each in cludlist) { if (!clubDic.ContainsKey(each.UID)) { clubDic.Add(each.UID, each); } } studentDic.Clear(); foreach (StudentRecord each in Student.SelectByIDs(cso.GetStudentID())) { if (!studentDic.ContainsKey(each.ID)) { studentDic.Add(each.ID, each); } } cso.ReDoubleTemp.Sort(SortSCJ); foreach (SCJoin SCJ in cso.ReDoubleTemp) { StudentRecord stud = studentDic[SCJ.RefStudentID]; CLUBRecord cr = clubDic[SCJ.RefClubID]; string class_981 = string.IsNullOrEmpty(stud.RefClassID) ? "" : stud.Class.Name; string SeatNo_981 = stud.SeatNo.HasValue ? stud.SeatNo.Value.ToString() : ""; sb_Message.AppendLine("班級「" + class_981 + "」座號「" + SeatNo_981 + "」姓名「" + stud.Name + "」重覆社團「" + cr.ClubName + "」"); } #endregion DialogResult dr = MsgBox.Show(sb_Message.ToString() + "\n您是否要繼續進行此作業?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dr != DialogResult.Yes) { MsgBox.Show("作業已中止!!"); return; } } if (cso.InsertList.Count != 0) { #region InsertList //取得Log學生物件 cso.GetLogStudent(); List <SCJoin> SCJoinlist = new List <SCJoin>(); foreach (string each in cso.InsertList) { SCJoin JHs = new SCJoin(); JHs.RefStudentID = each; //修課學生 JHs.RefClubID = this.PrimaryKey; SCJoinlist.Add(JHs); //加入修課LOG if (!string.IsNullOrEmpty(GetLogMessage(each))) { sb_Log.AppendLine(GetLogMessage(each)); } } try { tool._A.InsertValues(SCJoinlist); } catch (Exception ex) { MsgBox.Show("新增社員資料失敗\n" + ex.Message); SmartSchool.ErrorReporting.ReportingService.ReportException(ex); return; } //移出待處理 StringBuilder sbHelp = new StringBuilder(); sbHelp.AppendLine("已由待處理加入社員\n共「" + cso.InsertList.Count.ToString() + "」名學生\n"); MsgBox.Show(sbHelp.ToString()); FISCA.LogAgent.ApplicationLog.Log("社團", "加入社員", sb_Log.ToString()); K12.Presentation.NLDPanels.Student.RemoveFromTemp(cso.InsertList); ClubEvents.RaiseAssnChanged(); #endregion } #endregion } else { string message = "請檢查\n1.待處理無學生\n2.學生狀態有誤(非一般生)"; FISCA.Presentation.Controls.MsgBox.Show(message); } }