/// <summary> /// 以學生學號取得學生清單 /// </summary> public void GetStudentIDList(List <string> StudentNumberList) { StudentDic = new Dictionary <string, StudDe>(); StringBuilder sb_log = new StringBuilder(); sb_log.Append(@"select student.id,student.student_number,student.name,student.seat_no,class.class_name from student join class on student.ref_class_id=class.id where student.student_number in ('{0}')"); DataTable dt = tool._Q.Select(string.Format(sb_log.ToString(), string.Join("','", StudentNumberList))); foreach (DataRow row in dt.Rows) { string number = "" + row["student_number"]; StudDe stuf = new StudDe(row); if (!StudentDic.ContainsKey(stuf.number)) { StudentDic.Add(stuf.number, stuf); } } }
public override string Import(List <IRowStream> Rows) { if (mOption.Action == ImportAction.InsertOrUpdate) { StringBuilder sb_log = new StringBuilder(); //加入 社長/副社長 List <CLUBRecord> ClubUpdateList = new List <CLUBRecord>(); //加入 其他社團幹部 List <CadresRecord> CadreInsertList = new List <CadresRecord>(); //取得學號對應ID List <string> studentNumber = new List <string>(); foreach (IRowStream Row in Rows) { string StudentNumber = Row.GetValue("學號"); if (!studentNumber.Contains(StudentNumber)) { studentNumber.Add(StudentNumber); } } Importbot.GetStudentIDList(studentNumber); foreach (IRowStream Row in Rows) { //教師名稱 string SchoolYear = Row.GetValue("學年度"); string Semester = Row.GetValue("學期"); string CLUBName = Row.GetValue("社團名稱"); string CadreName = Row.GetValue("幹部名稱"); string StudentNumber = Row.GetValue("學號"); string name = SchoolYear + "," + Semester + "," + CLUBName; if (Importbot.ClubDic.ContainsKey(name)) { CLUBRecord record = Importbot.ClubDic[name]; if (Importbot.StudentDic.ContainsKey(StudentNumber)) { StudDe stud = Importbot.StudentDic[StudentNumber]; if (CadreName == "社長") { if (record.President != stud.id) { record.President = stud.id; ClubUpdateList.Add(record); sb_log.AppendLine(string.Format("學年度「{0}」學期「{1}」社團名稱「{2}」", SchoolYear, Semester, CLUBName)); sb_log.AppendLine(string.Format("班級「{0}」座號「{1}」姓名「{2}」幹部名稱「{3}」", stud.ClassName, stud.seat_no, stud.Name, CadreName)); sb_log.AppendLine(""); } else { sb_log.AppendLine(string.Format("學年度「{0}」學期「{1}」社團名稱「{2}」", SchoolYear, Semester, CLUBName)); sb_log.AppendLine(string.Format("學生「{0}」已是社長(未調整)", stud.Name)); sb_log.AppendLine(""); } } else if (CadreName == "副社長") { if (record.VicePresident != stud.id) { record.VicePresident = stud.id; ClubUpdateList.Add(record); sb_log.AppendLine(string.Format("學年度「{0}」學期「{1}」社團名稱「{2}」", SchoolYear, Semester, CLUBName)); sb_log.AppendLine(string.Format("班級「{0}」座號「{1}」姓名「{2}」幹部名稱「{3}」", stud.ClassName, stud.seat_no, stud.Name, CadreName)); sb_log.AppendLine(""); } else { sb_log.AppendLine(string.Format("學年度「{0}」學期「{1}」社團名稱「{2}」", SchoolYear, Semester, CLUBName)); sb_log.AppendLine(string.Format("學生「{0}」已是副社長(未調整)", stud.Name)); sb_log.AppendLine(""); } } else { //其他幹部直接新增 CadresRecord cadres = new CadresRecord(); cadres.CadreName = CadreName; cadres.RefClubID = record.UID; cadres.RefStudentID = stud.id; CadreInsertList.Add(cadres); sb_log.AppendLine(string.Format("學年度「{0}」學期「{1}」社團名稱「{2}」", SchoolYear, Semester, CLUBName)); sb_log.AppendLine(string.Format("班級「{0}」座號「{1}」姓名「{2}」幹部名稱「{3}」", stud.ClassName, stud.seat_no, stud.Name, CadreName)); sb_log.AppendLine(""); } } } } if (ClubUpdateList.Count > 0) { tool._A.UpdateValues(ClubUpdateList); } if (CadreInsertList.Count > 0) { tool._A.InsertValues(CadreInsertList); } if (ClubUpdateList.Count > 0 || CadreInsertList.Count > 0) { FISCA.LogAgent.ApplicationLog.Log("社團", "匯入社團幹部", sb_log.ToString()); } } return(""); }