コード例 #1
0
        protected override void OnSaveData()
        {
            //SCAttend.SCAttendID = row["sc_attend_id"].ToString();
            //SCAttend.StudentID = row["ref_student_id"].ToString();
            //SCAttend.Group = row["report_group"].ToString();
            //SCAttend.CourseID = PrimaryKey;
            //SCAttend.IsCancel = isCancel;
            //  1、先取得 SCAttendExt 物件
            List<dynamic> SCAttendExts = new List<dynamic>();
            foreach (DataGridViewRow row in this.dgvData.Rows)
            {
                if (row.IsNewRow)
                    continue;

                dynamic SCAttend = (row.Tag as dynamic);
                SCAttendExts.Add(SCAttend);
            }
            if (SCAttendExts.Count == 0)
                return;

            List<string> studentIDs = new List<string>();
            foreach (dynamic SCAttend in SCAttendExts)
                studentIDs.Add(SCAttend.StudentID);

            List<SCAttendExt> scattendExts = Access.Select<SCAttendExt>(string.Format("ref_student_id in ({0}) And ref_course_id='{1}'", string.Join(",", studentIDs), PrimaryKey));
            List<SCAttendExt> originalExts = new List<SCAttendExt>();
            if (scattendExts != null && scattendExts.Count>0)
                scattendExts.ForEach(x => originalExts.Add(x.Clone()));
            //  2、更新 SCAttendExt 物件內容
            List<SCAttendExt> updateRecords = new List<SCAttendExt>();
            foreach (DataGridViewRow row in this.dgvData.Rows)
            {
                if (row.IsNewRow)
                    continue;

                dynamic SCAttend = (row.Tag as dynamic);

                IEnumerable<SCAttendExt> SCAttendExtRecords = scattendExts.Where(x => (x.UID == SCAttend.SCAttendID));

                SCAttendExt scattendExtRecord = SCAttendExtRecords.ElementAt(0);

                scattendExtRecord.Group = (row.Cells["ReportGroup"].Value == null ? "" : row.Cells["ReportGroup"].Value.ToString());
                bool isCancel = false;
                bool.TryParse((row.Cells["IsCancel"].Value == null ? "" : row.Cells["IsCancel"].Value.ToString()), out isCancel);
                scattendExtRecord.IsCancel = isCancel;

                if (scattendExtRecord.RecordStatus == FISCA.UDT.RecordStatus.Update)
                    updateRecords.Add(scattendExtRecord);
            }

            List<string> updatedRecordUIDs = updateRecords.SaveAll();
            BatchLogAgent batchLogAgent = new BatchLogAgent();
            if (updatedRecordUIDs != null && updatedRecordUIDs.Count > 0)
            {
                List<SCAttendExt> updatedRecords = Access.Select<SCAttendExt>(updatedRecordUIDs);
                Dictionary<string, UDT.SCAttendExt> dicUpdatedRecords = new Dictionary<string, SCAttendExt>();
                if (updatedRecords.Count > 0)
                    dicUpdatedRecords = updatedRecords.ToDictionary(x => x.UID);
                CourseRecord courseRecord = Course.SelectByID(PrimaryKey);
                List<StudentRecord> studentRecords = K12.Data.Student.SelectByIDs(updatedRecords.Select(x => x.StudentID.ToString()));
                Dictionary<string, StudentRecord> dicStudentRecords = new Dictionary<string, StudentRecord>();
                if (studentRecords.Count > 0)
                    dicStudentRecords = studentRecords.ToDictionary(x => x.ID);
                foreach (string iRecords in dicUpdatedRecords.Keys)
                {
                    UDT.SCAttendExt updatedRecord = dicUpdatedRecords[iRecords];
                    StudentRecord student = dicStudentRecords[updatedRecord.StudentID.ToString()];
                    IEnumerable<UDT.SCAttendExt> originalRecords = originalExts.Where(x => (x.StudentID.ToString() == student.ID && x.CourseID == updatedRecord.CourseID));

                    LogAgent log = new LogAgent();
                    this.AddLog(log, originalRecords.ElementAt(0));
                    this.AddLog(log, updatedRecord);
                    batchLogAgent.AddLogAgent(log);
                    //StringBuilder sb = new StringBuilder();
                    //sb.Append("學生「" + student.Name + "」,學號「" + student.StudentNumber + "」");
                    //sb.AppendLine("被修改一筆「修課記錄」。");
                    //sb.AppendLine("詳細資料:");
                    //sb.Append("開課「" + courseRecord.Name + "」\n");
                    //if (!updatedRecord.Group.Equals(originalRecords.ElementAt(0).Group))
                    //    sb.Append("報告小組由「" + originalRecords.ElementAt(0).Group + "」改為「" + updatedRecord.Group + "」\n");
                    //if (!updatedRecord.IsCancel.Equals(originalRecords.ElementAt(0).IsCancel))
                    //    sb.Append("停修由「" + originalRecords.ElementAt(0).IsCancel + "」改為「" + updatedRecord.IsCancel + "」\n");
                }
            }
            if (batchLogAgent.Count > 0)
                batchLogAgent.Save();

            LoadData();

            SaveButtonVisible = false;
            CancelButtonVisible = false;
        }
コード例 #2
0
 void AddLog(LogAgent logAgent, SCAttendExt obj)
 {
     logAgent.SetLogValue("報告小組", obj.Group);
     logAgent.SetLogValue("停修", obj.IsCancel ? "是" : "否");
 }
コード例 #3
0
 public void AddLogAgent(LogAgent logAgent)
 {
     this._LogAgents.Add(logAgent);
 }