private void btnDelete_Click(object sender, EventArgs e)
        {
            if (listView.SelectedItems.Count <= 0)
            {
                return;
            }

            ListViewItem   item   = listView.SelectedItems[0];
            JHCourseRecord course = item.Tag as JHCourseRecord;

            if (MsgBox.Show(string.Format("您確定要刪除課程「{0}」的修課記錄及相關評量成績嗎?", course.Name), MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                JHStudentRecord student = JHStudent.SelectByID(PrimaryKey);

                List <JHSCETakeRecord> sces = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID);
                if (sces.Count > 0)
                {
                    JHSCETake.Delete(sces);
                    FISCA.LogAgent.LogSaver logSaver = FISCA.LogAgent.ApplicationLog.CreateLogSaverInstance();
                    string studentInfo = StudentInfoConvertor.GetInfoWithClass(student);
                    foreach (var sce in sces)
                    {
                        string desc = studentInfo + " 刪除評量成績:" + sce.Course.Name + " " + sce.Exam.Name;
                        logSaver.AddBatch("成績系統.修課及評量成績", "刪除評量成績", "student", PrimaryKey, desc);
                    }
                    logSaver.LogBatch();
                }

                List <JHSCAttendRecord> scattends = JHSCAttend.SelectByStudentIDAndCourseID(new string[] { student.ID }, new string[] { course.ID });
                if (scattends.Count > 0)
                {
                    JHSCAttend.Delete(scattends);
                    StringBuilder builder = new StringBuilder("");
                    builder.Append(StudentInfoConvertor.GetInfoWithClass(student));
                    builder.Append(" 刪除修課:" + course.Name);
                    FISCA.LogAgent.ApplicationLog.Log("成績系統.修課及評量成績", "刪除修課", "student", PrimaryKey, builder.ToString());
                }

                listView.Items.Remove(item);
            }
        }
Exemple #2
0
        private void AddSCAttends(List <StudentRecord> students, List <CourseRecord> courses)
        {
            if (students.Count <= 0)
            {
                return;
            }
            if (courses.Count <= 0)
            {
                return;
            }

            FISCA.LogAgent.LogSaver logSaver = FISCA.LogAgent.ApplicationLog.CreateLogSaverInstance();

            Dictionary <string, List <string> > studentScattends = new Dictionary <string, List <string> >();
            List <string> courseIDs      = courses.AsKeyList();
            StringBuilder coursesBuilder = new StringBuilder("");
            string        coursesString  = string.Empty;

            foreach (CourseRecord courseRecord in courses)
            {
                coursesBuilder.Append(courseRecord.Name + "、");
            }
            coursesString = coursesBuilder.ToString();
            if (coursesString.EndsWith("、"))
            {
                coursesString = coursesString.Substring(0, coursesString.Length - 1);
            }

            foreach (var student in students)
            {
                if (!studentScattends.ContainsKey(student.ID))
                {
                    studentScattends.Add(student.ID, courseIDs);

                    string s = string.Empty;
                    if (student.Class != null)
                    {
                        s += student.Class.Name;
                        if (student.SeatNo != "")
                        {
                            s += "(" + student.SeatNo + "號)";
                        }
                        s += " ";
                    }
                    if (student.StudentNumber != "")
                    {
                        s += student.StudentNumber + " ";
                    }
                    if (s == "")
                    {
                        s += "學生:";
                    }
                    s += student.Name;

                    string desc = string.Format("學生「{0}」加入修課:{1}", s, coursesString);
                    logSaver.AddBatch("成績系統.修課", "學生指定修課", desc);
                }
            }

            foreach (Data.JHSCAttendRecord record in Data.JHSCAttend.SelectByStudentIDAndCourseID(students.AsKeyList(), courses.AsKeyList()))
            {
                if (studentScattends.ContainsKey(record.RefStudentID))
                {
                    if (studentScattends[record.RefStudentID].Contains(record.RefCourseID))
                    {
                        studentScattends[record.RefStudentID].Remove(record.RefCourseID);
                    }
                }
            }

            List <Data.JHSCAttendRecord> list = new List <JHSchool.Data.JHSCAttendRecord>();

            foreach (string studentID in studentScattends.Keys)
            {
                foreach (string courseID in studentScattends[studentID])
                {
                    Data.JHSCAttendRecord record = new JHSchool.Data.JHSCAttendRecord();
                    record.RefCourseID  = courseID;
                    record.RefStudentID = studentID;
                    list.Add(record);
                }
            }

            if (list.Count > 0)
            {
                MultiThreadBackgroundWorker <Data.JHSCAttendRecord> worker = new MultiThreadBackgroundWorker <JHSchool.Data.JHSCAttendRecord>();
                worker.PackageSize = 50;
                worker.Loading     = MultiThreadLoading.Light;
                worker.DoWork     += delegate(object sender, PackageDoWorkEventArgs <Data.JHSCAttendRecord> e)
                {
                    Data.JHSCAttend.Insert(e.Items);
                };
                worker.RunWorkerCompleted += delegate
                {
                    logSaver.LogBatch();
                    MsgBox.Show("指定修課完成");
                };
                worker.RunWorkerAsync(list);
            }
        }