public void Save(List<string> students) { List<SCAttendExt> scattendRecords = new List<SCAttendExt>(); foreach (string student in students) { SCAttendExt scattendRecord = new SCAttendExt(); scattendRecord.StudentID = int.Parse(student); scattendRecord.CourseID = int.Parse(PrimaryKey); scattendRecord.IsCancel = false; scattendRecords.Add(scattendRecord); } try { List<string> insertedRecordUIDs = scattendRecords.SaveAll(); List<K12.Data.StudentRecord> studentRecords = new List<StudentRecord>(); if (insertedRecordUIDs != null && insertedRecordUIDs.Count > 0) { // 寫入「新增」的 Log List<UDT.SCAttendExt> insertedRecords = Access.Select<UDT.SCAttendExt>(insertedRecordUIDs); Dictionary<string, UDT.SCAttendExt> dicInsertedRecords = new Dictionary<string, SCAttendExt>(); if (insertedRecords.Count > 0) dicInsertedRecords = insertedRecords.ToDictionary(x => x.UID); CourseRecord courseRecord = Course.SelectByID(PrimaryKey); studentRecords = K12.Data.Student.SelectByIDs(insertedRecords.Select(x => x.StudentID.ToString())); Dictionary<string, StudentRecord> dicStudentRecords = new Dictionary<string, StudentRecord>(); if (studentRecords.Count > 0) dicStudentRecords = studentRecords.ToDictionary(x => x.ID); LogSaver logBatch = ApplicationLog.CreateLogSaverInstance(); foreach (string iRecords in dicInsertedRecords.Keys) { UDT.SCAttendExt insertedRecord = dicInsertedRecords[iRecords]; StudentRecord student = dicStudentRecords[insertedRecord.StudentID.ToString()]; StringBuilder sb = new StringBuilder(); sb.Append("學生「" + student.Name + "」,學號「" + student.StudentNumber + "」"); sb.AppendLine("被新增一筆「修課記錄」。"); sb.AppendLine("詳細資料:"); sb.Append("開課「" + courseRecord.Name + "」\n"); logBatch.AddBatch("管理學生修課.新增", "新增", "course", PrimaryKey, sb.ToString()); } logBatch.LogBatch(true); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
void AddLog(LogAgent logAgent, SCAttendExt obj) { logAgent.SetLogValue("報告小組", obj.Group); logAgent.SetLogValue("停修", obj.IsCancel ? "是" : "否"); }