示例#1
0
        public void Add(JHSCAttendRecord attend)
        {
            string subject = JHCourse.SelectByID(attend.RefCourseID).Subject;

            if (!Attends.ContainsKey(subject))
            {
                Attends.Add(subject, attend);
            }
        }
 /// <summary>
 /// Comparision
 /// 依班級、座號、學號排序修課學生。
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 private int SCAttendComparer(JHSCAttendRecord a, JHSCAttendRecord b)
 {
     if (a.Student.Class != null && b.Student.Class != null)
     {
         if (a.Student.Class.ID == b.Student.Class.ID)
         {
             int ia, ib;
             //if (int.TryParse(a.Student.SeatNo, out ia) && int.TryParse(b.Student.SeatNo, out ib))
             if (a.Student.SeatNo.HasValue && b.Student.SeatNo.HasValue)
             {
                 if (a.Student.SeatNo.Value == b.Student.SeatNo.Value)
                 {
                     return(a.Student.StudentNumber.CompareTo(b.Student.StudentNumber));
                 }
                 //return ia.CompareTo(ib);
                 return(a.Student.SeatNo.Value.CompareTo(b.Student.SeatNo.Value));
             }
             //else if (int.TryParse(a.Student.SeatNo, out ia))
             else if (a.Student.SeatNo.HasValue)
             {
                 return(-1);
             }
             //else if (int.TryParse(b.Student.SeatNo, out ib))
             else if (b.Student.SeatNo.HasValue)
             {
                 return(1);
             }
             else
             {
                 return(a.Student.StudentNumber.CompareTo(b.Student.StudentNumber));
             }
         }
         else
         {
             return(a.Student.Class.Name.CompareTo(b.Student.Class.Name));
         }
     }
     else if (a.Student.Class != null && b.Student.Class == null)
     {
         return(-1);
     }
     else if (a.Student.Class == null && b.Student.Class != null)
     {
         return(1);
     }
     else
     {
         return(a.Student.StudentNumber.CompareTo(b.Student.StudentNumber));
     }
 }
示例#3
0
        /*
         * <Extension>
         *      <Effort/>
         *      <Text/>
         *  <OrdinarilyEffort/> <!--平時評量努力程度-->
         *  <OrdinarilyScore/> <!--平時評量成績-->
         * </Extension>
         */

        public AttendScore(JHSCAttendRecord attend, decimal?weight, decimal?period, bool toSemester, string domain)
        {
            RawAttend  = attend;
            Subscores  = new TakeScoreCollection();
            Value      = attend.Score;
            Weight     = weight;
            Period     = period;
            Effort     = attend.Effort;
            Text       = attend.Text;
            ToSemester = toSemester;
            Domain     = domain;

            OrdinarilyEffort = attend.OrdinarilyEffort;
            OrdinarilyScore  = attend.OrdinarilyScore;
        }
        /// <summary>
        /// Comparision
        /// 依班級、座號、學號排序修課學生。
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        private int SCAttendComparer(JHSCAttendRecord a, JHSCAttendRecord b)
        {
            JHStudentRecord aStudent = a.Student;
            JHClassRecord   aClass   = a.Student.Class;
            JHStudentRecord bStudent = b.Student;
            JHClassRecord   bClass   = b.Student.Class;

            string aa = aClass == null ? (string.Empty).PadLeft(10, '0') : (aClass.Name).PadLeft(10, '0');

            aa += aStudent == null ? (string.Empty).PadLeft(3, '0') : (aStudent.SeatNo + "").PadLeft(3, '0');
            aa += aStudent == null ? (string.Empty).PadLeft(10, '0') : (aStudent.StudentNumber).PadLeft(10, '0');

            string bb = bClass == null ? (string.Empty).PadLeft(10, '0') : (bClass.Name).PadLeft(10, '0');

            bb += bStudent == null ? (string.Empty).PadLeft(3, '0') : (bStudent.SeatNo + "").PadLeft(3, '0');
            bb += bStudent == null ? (string.Empty).PadLeft(10, '0') : (bStudent.StudentNumber).PadLeft(10, '0');

            return(aa.CompareTo(bb));
        }
示例#5
0
        public List <JHSCETakeRecord> GetCopiedScores(string source, List <string> targets)
        {
            if (!Scores.SubjectExists(source))
            {
                return(new List <JHSCETakeRecord>());
            }

            List <JHSCETakeRecord> list = new List <JHSCETakeRecord>();

            SCETakeData sourceScore = new SCETakeData(Scores[source]);

            foreach (string subject in targets)
            {
                if (Scores.SubjectExists(subject))
                {
                    SCETakeData sce = new SCETakeData(Scores[subject]);
                    sce.Score           = sourceScore.Score;
                    sce.Text            = sourceScore.Text;
                    sce.AssignmentScore = sourceScore.AssignmentScore;
                    sce.Effort          = sourceScore.Effort;

                    list.Add(sce.AsJHSCETakeRecord());
                }
                else
                {
                    SCETakeData      sce    = new SCETakeData(new JHSCETakeRecord());
                    JHSCAttendRecord attend = Attends[subject];
                    sce.Origin.RefCourseID   = attend.RefCourseID;
                    sce.Origin.RefExamID     = sourceScore.Origin.RefExamID;
                    sce.Origin.RefSCAttendID = attend.ID;
                    sce.Origin.RefStudentID  = attend.RefStudentID;
                    sce.Score           = sourceScore.Score;
                    sce.Text            = sourceScore.Text;
                    sce.AssignmentScore = sourceScore.AssignmentScore;
                    sce.Effort          = sourceScore.Effort;

                    list.Add(sce.AsJHSCETakeRecord());
                }
            }
            return(list);
        }
        public void Save()
        {
            #region 儲存課程成績。
            List <JHSCAttendRecord> attends = new List <JHSCAttendRecord>();

            foreach (StudentScore student in Students)
            {
                foreach (string subject in student.AttendScore)
                {
                    if (FilterSubject.Contains(subject) || FilterSubject.Count <= 0)
                    {
                        AttendScore      attend    = student.AttendScore[subject];
                        JHSCAttendRecord DALAttend = attend.RawAttend;

                        DALAttend.Score  = attend.Value;
                        DALAttend.Effort = attend.Effort;
                        DALAttend.Text   = attend.Text;

                        attends.Add(DALAttend);
                    }
                }
            }

            if (attends.Count <= 0)
            {
                return;
            }

            FunctionSpliter <JHSCAttendRecord, JHSCAttendRecord> spliter = new FunctionSpliter <JHSCAttendRecord, JHSCAttendRecord>(300 * 10, Util.MaxThread);
            spliter.Function = delegate(List <JHSCAttendRecord> attendPart)
            {
                JHSCAttend.Update(attendPart);
                return(new List <JHSCAttendRecord>());
            };
            spliter.ProgressChange = delegate(int progress)
            {
                Reporter.Feedback("儲存計算結果...", Util.CalculatePercentage(attends.Count, progress));
            };
            spliter.Execute(attends);
            #endregion
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            JHStudentRecord student = JHStudent.SelectByID(PrimaryKey);
            CreateForm      form    = new CreateForm(student);

            if (form.ShowDialog() == DialogResult.OK)
            {
                if (form.Course == null)
                {
                    return;
                }

                try
                {
                    JHSCAttendRecord scattend = new JHSCAttendRecord();
                    scattend.RefCourseID  = form.Course.ID;
                    scattend.RefStudentID = PrimaryKey;
                    JHSCAttend.Insert(scattend);
                    StringBuilder builder = new StringBuilder("");
                    builder.Append(StudentInfoConvertor.GetInfoWithClass(student));
                    builder.Append(" 加入修課:" + form.Course.Name);
                    FISCA.LogAgent.ApplicationLog.Log("成績系統.修課及評量成績", "新增修課", "student", PrimaryKey, builder.ToString());
                }
                catch (Exception ex)
                {
                    MsgBox.Show("新增修課記錄失敗。" + ex.Message);
                }

                ScoreInputForm inputform = new ScoreInputForm(student, form.Course);
                inputform.ShowDialog();

                if (!_worker.IsBusy)
                {
                    _RunningID = PrimaryKey;
                    _worker.RunWorkerAsync();
                }
            }
        }
示例#8
0
        internal void AddAssignment(JHSCAttendRecord assignment)
        {
            if (!_courseDict.ContainsKey(assignment.RefCourseID))
            {
                return;
            }
            JHCourseRecord course = _courseDict[assignment.RefCourseID];

            if (!Domains.ContainsKey(course.Domain))
            {
                return;
            }

            DomainRow row = Domains[course.Domain];

            if (!row.Subjects.ContainsKey(course.Subject))
            {
                return;
            }

            SubjectRow subjectRow = row.Subjects[course.Subject];

            subjectRow.AssignmentScore = assignment.OrdinarilyScore;
        }
示例#9
0
        public ScoreInputForm(JHStudentRecord student, JHCourseRecord course)
        {
            InitializeComponent();
            InitializeListener();
            prlp = new PermRecLogProcess();
            lblCourseName.Text = course.Name;
            lblStudent.Text    = student.Name + " " + student.StudentNumber;

            _course  = course;
            _student = student;

            List <JHSCAttendRecord> scattendList = JHSCAttend.SelectByStudentIDAndCourseID(new string[] { student.ID }, new string[] { course.ID });

            if (scattendList.Count > 0)
            {
                _scattend = scattendList[0];
            }

            #region 取得評量成績
            _listener.SuspendListen();

            // 取得所有試別
            Dictionary <string, JHExamRecord> exams = JHExam.SelectAll().ToDictionary(x => x.ID);
            List <string> examIDs = new List <string>(exams.Keys);

            List <HC.JHAEIncludeRecord> aeList = new List <HC.JHAEIncludeRecord>();

            if (course.RefAssessmentSetupID != null)
            {
                JHAssessmentSetupRecord assessment = JHAssessmentSetup.SelectByID(course.RefAssessmentSetupID);
                if (assessment != null)
                {
                    foreach (JHAEIncludeRecord ae in JHAEInclude.SelectByAssessmentSetupID(assessment.ID))
                    {
                        aeList.Add(new HC.JHAEIncludeRecord(ae));
                    }
                }
                //{
                //    foreach (JHAEIncludeRecord ae in JHAEInclude.SelectAll())
                //    {
                //        if (ae.RefAssessmentSetupID == assessment.ID)
                //            aeList.Add(new HC.JHAEIncludeRecord(ae));
                //    }
                //}
            }

            List <JHSCETakeRecord> jhSCEList = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID);

            //aeList.Sort(delegate(HC.JHAEIncludeRecord x, HC.JHAEIncludeRecord y)
            //{
            //    return x.RefExamID.CompareTo(y.RefExamID);
            //});

            aeList.Sort(delegate(HC.JHAEIncludeRecord x, HC.JHAEIncludeRecord y)
            {
                int ix = examIDs.IndexOf(x.RefExamID);
                int iy = examIDs.IndexOf(y.RefExamID);
                if (ix == -1)
                {
                    ix = int.MaxValue;
                }
                if (iy == -1)
                {
                    iy = int.MaxValue;
                }
                return(ix.CompareTo(iy));
            });

            List <HC.JHSCETakeRecord> sceList = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID).AsHCJHSCETakeRecords();

            Dictionary <string, DataGridViewRow> rows = new Dictionary <string, DataGridViewRow>();
            foreach (HC.JHAEIncludeRecord ae in aeList)
            {
                DataGridViewRow row = new DataGridViewRow();
                //JHExamRecord exam = JHExam.SelectByID(ae.RefExamID);

                JHExamRecord exam = null;
                if (exams.ContainsKey(ae.RefExamID))
                {
                    exam = exams[ae.RefExamID];
                }
                row.CreateCells(dgv, (exam != null) ? exam.Name : "無此評量(" + ae.RefExamID + ")", "", "", "");
                dgv.Rows.Add(row);
                row.Cells[chExamName.Index].Tag = (exam != null) ? exam.ID : "";

                if (!ae.UseScore)
                {
                    DisableCell(row, chScore);
                }
                if (!ae.UseAssignmentScore)
                {
                    DisableCell(row, chAssignmentScore);
                }
                if (!ae.UseText)
                {
                    DisableCell(row, chText);
                }

                if (!rows.ContainsKey(ae.RefExamID))
                {
                    rows.Add(ae.RefExamID, row);
                }
            }

            //List<HC.JHSCETakeRecord> sceList = jhSCEList.AsHCJHSCETakeRecords();
            foreach (HC.JHSCETakeRecord sce in sceList)
            {
                if (rows.ContainsKey(sce.RefExamID))
                {
                    DataGridViewRow row = rows[sce.RefExamID];
                    row.Cells[chScore.Index].Value           = sce.Score.HasValue ? "" + sce.Score.Value : "";
                    row.Cells[chAssignmentScore.Index].Value = sce.AssignmentScore.HasValue ? "" + sce.AssignmentScore.Value : "";
                    row.Cells[chText.Index].Value            = sce.Text;
                    row.Tag = sce;
                }
                else
                {
                    DataGridViewRow row  = new DataGridViewRow();
                    JHExamRecord    exam = JHExam.SelectByID(sce.RefExamID);
                    row.CreateCells(dgv, (exam != null) ? exam.Name : "無此評量(" + sce.RefExamID + ")", sce.Score.HasValue ? "" + sce.Score.Value : "", sce.AssignmentScore.HasValue ? "" + sce.AssignmentScore.Value : "", sce.Text);
                    row.Tag = sce;
                    row.Cells[chExamName.Index].Tag = (exam != null) ? exam.ID : "";
                    dgv.Rows.Add(row);
                    DisableCell(row, chExamName);
                    DisableCell(row, chScore);
                    DisableCell(row, chAssignmentScore);
                    DisableCell(row, chText);
                }
            }

            #region 填入修課總成績
            if (_scattend != null)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(dgv, "課程總成績", "" + _scattend.Score, "", _scattend.Text);
                DisableCell(row, chAssignmentScore);
                row.Tag = "課程總成績";
                dgv.Rows.Add(row);
            }
            #endregion

            foreach (DataGridViewRow dgv1 in dgv.Rows)
            {
                foreach (DataGridViewCell cell in dgv1.Cells)
                {
                    cell.ErrorText = "";

                    if (cell.OwningColumn == chScore || cell.OwningColumn == chAssignmentScore)
                    {
                        cell.Style.ForeColor = Color.Black;
                        if (!string.IsNullOrEmpty("" + cell.Value))
                        {
                            decimal d;
                            if (!decimal.TryParse("" + cell.Value, out d))
                            {
                                cell.ErrorText = "分數必須為數字";
                            }
                            else
                            {
                                if (d < 60)
                                {
                                    cell.Style.ForeColor = Color.Red;
                                }
                                if (d > 100 || d < 0)
                                {
                                    cell.Style.ForeColor = Color.Green;
                                }
                            }
                        }
                    }
                }
            }


            _listener.Reset();
            _listener.ResumeListen();
            #endregion
            SetLoadDataToLog();
        }
        internal void Read()
        {
            Courses    = ReadCourse();
            AEIncludes = ReadAEInclude();
            Attends    = ReadCurrentSemesterAttend();
            List <JHSCETakeRecord> SCETakes = ReadSCETake();

            // 取得新竹評量樣版設定
            Util.ScorePercentageHSDict.Clear();
            Util.ScorePercentageHSDict = Util.GetScorePercentageHS();

            //清除原有的資料。
            foreach (StudentScore each in Students.Values)
            {
                each.AttendScore.Clear();
            }

            Reporter.Feedback("計算成績...", 0);
            int t1 = Environment.TickCount;

            foreach (JHSCAttendRecord Attend in Attends.Values)
            {
                if (!Students.ContainsKey(Attend.RefStudentID))
                {
                    continue;
                }
                StudentScore Student = Students[Attend.RefStudentID];

                if (!Courses.ContainsKey(Attend.RefCourseID))
                {
                    continue;
                }
                JHCourseRecord Course = Courses[Attend.RefCourseID];

                bool toSems = (Course.CalculationFlag == "1") ? true : false;

                string subjName = Course.Subject.Trim();

                // 如果科目名稱空白就不處理,因為無法計算到科目成績
                if (string.IsNullOrWhiteSpace(subjName))
                {
                    continue;
                }

                //傳入學年度,判斷103以前的學年度5:5而以後6:4比例計算
                if (!Student.AttendScore.Contains(subjName))
                {
                    Student.AttendScore.Add(subjName, new AttendScore(Attend, Course.Credit, Course.Period, toSems, Course.Domain, Course.SchoolYear));
                }
            }

            try
            {
                foreach (JHSCETakeRecord take in SCETakes)
                {
                    if (!Attends.ContainsKey(take.RefSCAttendID))
                    {
                        continue;
                    }
                    JHSCAttendRecord Attend = Attends[take.RefSCAttendID];

                    if (!Students.ContainsKey(Attend.RefStudentID))
                    {
                        continue;
                    }
                    StudentScore Student = Students[Attend.RefStudentID];

                    if (!Courses.ContainsKey(Attend.RefCourseID))
                    {
                        continue;
                    }
                    JHCourseRecord Course = Courses[Attend.RefCourseID];

                    if (!AEIncludes.ContainsKey(Course.RefAssessmentSetupID))
                    {
                        continue;
                    }
                    Dictionary <string, AEIncludeData> Include = AEIncludes[Course.RefAssessmentSetupID];

                    //沒有該次考試就不處理。
                    if (!Include.ContainsKey(take.RefExamID))
                    {
                        continue;
                    }

                    string subjName = Course.Subject.Trim();

                    // 如果科目名稱空白就不處理,因為無法計算到科目成績
                    if (string.IsNullOrWhiteSpace(subjName))
                    {
                        continue;
                    }

                    try
                    {
                        Student.AttendScore[subjName].Subscores.Add(take.RefExamID, new TakeScore(take, Include[take.RefExamID]));
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }



            Reporter.Feedback("時間:" + (Environment.TickCount - t1), 0);
        }
示例#11
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            #region DoWork

            SelectSemesterForm opt = e.Argument as SelectSemesterForm;

            Worker.ReportProgress(0, "正在進行開課...");

            double totalClass = K12.Presentation.NLDPanels.Class.SelectedSource.Count;
            if (totalClass <= 0)
            {
                totalClass = 0;
            }
            double classCount = 0;

            Dictionary <string, JHCourseRecord> subjectCourseDict = new Dictionary <string, JHCourseRecord>();

            foreach (JHClassRecord cla in JHClass.SelectByIDs(K12.Presentation.NLDPanels.Class.SelectedSource))
            {
                #region 班級開課

                classCount++;

                int gradeYear = 0; //取得班級年級
                if (!cla.GradeYear.HasValue)
                {
                    continue;
                }
                gradeYear = cla.GradeYear.Value;

                // TODO: 先寫著,之後再討論…
                if (gradeYear >= 7)
                {
                    gradeYear -= 6;
                }

                #region 取得班級內每個學生的課程規劃表
                List <JHProgramPlanRecord> programPlanList = new List <JHProgramPlanRecord>();

                List <JHStudentRecord> studentsInSchool = GetInSchoolStudents(cla.Students);
                if (studentsInSchool.Count > 0) //班級有學生,抓學生課程規劃表
                {
                    foreach (JHStudentRecord stu in studentsInSchool)
                    {
                        //取得學生的課程規劃表
                        JHProgramPlanRecord record = PPCollection.GetProgramPlanRecord(stu);
                        if (record != null)
                        {
                            if (!programPlanList.Contains(record))
                            {
                                programPlanList.Add(record);
                            }
                        }
                    }
                }
                else //班級沒有學生,也是要開課的!
                {
                    JHProgramPlanRecord record = PPCollection.GetProgramPlanRecord(cla);
                    if (record != null)
                    {
                        if (!programPlanList.Contains(record))
                        {
                            programPlanList.Add(record);
                        }
                    }
                }
                #endregion

                #region 所有課程規劃表中要開的課程
                Dictionary <string, K12.Data.ProgramSubject> courseDict = new Dictionary <string, K12.Data.ProgramSubject>();

                foreach (JHProgramPlanRecord record in programPlanList)
                {
                    foreach (K12.Data.ProgramSubject subject in record.Subjects)
                    {
                        if (subject.GradeYear == gradeYear &&
                            subject.Semester == opt.Semester &&
                            subject.Period.HasValue &&
                            subject.Credit.HasValue)
                        {
                            string key = subject.SubjectName.Trim();
                            if (!courseDict.ContainsKey(key))
                            {
                                courseDict.Add(key, subject);
                            }
                        }
                    }
                }
                #endregion

                //快取來源學期課程先放這
                Dictionary <string, JHCourseRecord> copySourceCourses = new Dictionary <string, JHCourseRecord>();

                #region 取得本學期已開的課程
                Dictionary <string, JHCourseRecord> existSubjects = new Dictionary <string, JHCourseRecord>();

                foreach (JHCourseRecord course in JHCourse.SelectAll())
                {
                    #region 取得複製來源學期的課程,智慧型開課需要
                    if (opt.CopyOptionEnabled && (opt.CopyTeacher || opt.CopyAssessmentSetup))
                    {
                        if (course.SchoolYear == opt.CopySchoolYear && course.Semester == opt.CopySemester && course.RefClassID == cla.ID)
                        {
                            if (!copySourceCourses.ContainsKey(course.Subject))
                            {
                                copySourceCourses.Add(course.Subject, course);
                            }
                        }
                    }
                    #endregion

                    //取得本學期的課程
                    if (course.SchoolYear == opt.SchoolYear && course.Semester == opt.Semester && course.RefClassID == cla.ID)
                    {
                        if (!existSubjects.ContainsKey(course.Subject))
                        {
                            existSubjects.Add(course.Subject, course);
                        }
                    }
                }
                #endregion

                #region 開課(加入新課程)
                List <JHCourseRecord> insertCourseList = new List <JHCourseRecord>();
                foreach (string key in courseDict.Keys)
                {
                    //是原來沒有的課程
                    if (!existSubjects.ContainsKey(key))
                    {
                        K12.Data.ProgramSubject subject   = courseDict[key];
                        JHCourseRecord          newCourse = new JHCourseRecord();

                        newCourse.Credit          = subject.Credit;
                        newCourse.Period          = subject.Period;
                        newCourse.Domain          = subject.Domain;
                        newCourse.Name            = cla.Name + " " + subject.SubjectName;
                        newCourse.SchoolYear      = opt.SchoolYear;
                        newCourse.Semester        = opt.Semester;
                        newCourse.Subject         = subject.SubjectName.Trim();
                        newCourse.RefClassID      = cla.ID;
                        newCourse.CalculationFlag = subject.CalcFlag ? "1" : "2";

                        insertCourseList.Add(newCourse);
                    }
                }
                if (insertCourseList.Count > 0)
                {
                    JHCourse.Insert(insertCourseList);
                }
                #endregion

                #region 重新取得本學期已開的課程(包含這次新開的課程)
                JHCourse.RemoveAll();
                Dictionary <string, JHCourseRecord> reloadedExistSubjects = new Dictionary <string, JHCourseRecord>();
                List <string> courseIDs = new List <string>();
                foreach (JHCourseRecord course in JHCourse.SelectAll())
                {
                    if (course.SchoolYear == opt.SchoolYear &&
                        course.Semester == opt.Semester &&
                        course.RefClassID == cla.ID)
                    {
                        string key = course.Subject;
                        if (!reloadedExistSubjects.ContainsKey(key))
                        {
                            reloadedExistSubjects.Add(key, course);
                        }

                        courseIDs.Add(course.ID);
                    }
                }
                #endregion

                #region 加入學生修課
                CourseAttendCollection caCollection = new CourseAttendCollection();
                foreach (JHSCAttendRecord sca in JHSCAttend.SelectByCourseIDs(courseIDs))
                {
                    if (!caCollection.ContainsKey(sca.RefCourseID))
                    {
                        caCollection.Add(sca.RefCourseID, new List <JHSCAttendRecord>());
                    }
                    caCollection[sca.RefCourseID].Add(sca);
                }

                List <JHSCAttendRecord> insertSCAttendList = new List <JHSCAttendRecord>();

                foreach (JHStudentRecord student in GetInSchoolStudents(cla.Students))
                {
                    if (PPCollection.GetProgramPlanRecord(student) == null)
                    {
                        continue;
                    }

                    foreach (K12.Data.ProgramSubject subject in PPCollection.GetProgramPlanRecord(student).Subjects)
                    {
                        string key = subject.SubjectName.Trim();

                        if (subject.GradeYear == gradeYear &&
                            subject.Semester == opt.Semester &&
                            reloadedExistSubjects.ContainsKey(key))
                        {
                            bool found = false;
                            foreach (JHStudentRecord attendStudent in caCollection.GetAttendStudents(reloadedExistSubjects[key]))
                            {
                                if (attendStudent.ID == student.ID)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (found == false)
                            {
                                JHSCAttendRecord newSCAttend = new JHSCAttendRecord();
                                newSCAttend.RefStudentID = student.ID;
                                newSCAttend.RefCourseID  = reloadedExistSubjects[key].ID;
                                insertSCAttendList.Add(newSCAttend);
                            }
                        }
                    }
                }
                if (insertSCAttendList.Count > 0)
                {
                    int t1 = Environment.TickCount;

                    JHSCAttend.Insert(insertSCAttendList);

                    Trace.WriteLine("寫入修課記錄時間:" + (Environment.TickCount - t1).ToString());
                }
                #endregion

                #region 判斷是否進行智慧型開課
                if (opt.CopyOptionEnabled)
                {
                    CourseInstructCollection ciCollection        = new CourseInstructCollection();
                    CourseInstructCollection currentCICollection = new CourseInstructCollection();
                    List <string>            copyCourseIDs       = new List <string>();
                    foreach (JHCourseRecord course in copySourceCourses.Values)
                    {
                        copyCourseIDs.Add(course.ID);
                    }
                    foreach (JHTCInstructRecord tc in JHTCInstruct.SelectByTeacherIDAndCourseID(new string[] { }, copyCourseIDs))
                    {
                        if (!ciCollection.ContainsKey(tc.RefCourseID))
                        {
                            ciCollection.Add(tc.RefCourseID, new List <JHTCInstructRecord>());
                        }
                        ciCollection[tc.RefCourseID].Add(tc);
                    }
                    foreach (JHTCInstructRecord tc in JHTCInstruct.SelectByTeacherIDAndCourseID(new string[] { }, courseIDs))
                    {
                        if (!currentCICollection.ContainsKey(tc.RefCourseID))
                        {
                            currentCICollection.Add(tc.RefCourseID, new List <JHTCInstructRecord>());
                        }
                        currentCICollection[tc.RefCourseID].Add(tc);
                    }

                    List <JHTCInstructRecord> insertTCList = new List <JHTCInstructRecord>();
                    List <JHTCInstructRecord> updateTCList = new List <JHTCInstructRecord>();

                    List <JHCourseRecord> updateCourseList = new List <JHCourseRecord>();

                    //針對目前這個班級在開課學年度學期的所有課程
                    foreach (JHCourseRecord course in reloadedExistSubjects.Values)
                    {
                        //如果課程不存在課程規劃表中,則不處理
                        if (!courseDict.ContainsKey(course.Subject))
                        {
                            continue;
                        }

                        //複製來源課程中,如果有相同科目名稱,則進行複製
                        if (copySourceCourses.ContainsKey(course.Subject))
                        {
                            JHCourseRecord copyCourseRecord = copySourceCourses[course.Subject];

                            #region 自動加入授課教師
                            if (opt.CopyTeacher == true)
                            {
                                for (int i = 1; i <= 3; i++)
                                {
                                    //取得來源課程的授課教師
                                    JHTeacherRecord teacherRecord = ciCollection.GetTeacher(copyCourseRecord, i);
                                    if (teacherRecord != null)
                                    {
                                        //取得開課課程的授課記錄
                                        JHTCInstructRecord tc = currentCICollection.GetInstruct(course, i);
                                        if (tc == null)
                                        {
                                            tc              = new JHTCInstructRecord();
                                            tc.RefCourseID  = course.ID;
                                            tc.RefTeacherID = teacherRecord.ID;
                                            tc.Sequence     = i;
                                            insertTCList.Add(tc);
                                        }
                                        else
                                        {
                                            tc.RefTeacherID = teacherRecord.ID;
                                            updateTCList.Add(tc);
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region 自動加入評量設定
                            if (opt.CopyAssessmentSetup == true)
                            {
                                course.RefAssessmentSetupID = copyCourseRecord.RefAssessmentSetupID;
                                updateCourseList.Add(course);
                            }
                            #endregion
                        }
                    }

                    if (insertTCList.Count > 0)
                    {
                        JHTCInstruct.Insert(insertTCList);
                    }
                    if (updateTCList.Count > 0)
                    {
                        JHTCInstruct.Update(updateTCList);
                    }
                    if (updateCourseList.Count > 0)
                    {
                        JHCourse.Update(updateCourseList);
                    }
                }
                #endregion

                #endregion

                //回報進度
                Worker.ReportProgress((int)(classCount * 100d / totalClass), "正在進行開課...");
            }
            #endregion
        }
示例#12
0
        public ScoreInputForm(JHStudentRecord student, JHCourseRecord course)
        {
            InitializeComponent();
            InitializeListener();
            prlp = new PermRecLogProcess();
            lblCourseName.Text = course.Name;
            lblStudent.Text    = student.Name + " " + student.StudentNumber;

            _course  = course;
            _student = student;

            List <JHSCAttendRecord> scattendList = JHSCAttend.SelectByStudentIDAndCourseID(new string[] { student.ID }, new string[] { course.ID });

            if (scattendList.Count > 0)
            {
                _scattend = scattendList[0];
            }


            #region 取得評量成績缺考暨免試設定

            PluginMain.ScoreTextMap.Clear();
            PluginMain.ScoreValueMap.Clear();
            Framework.ConfigData cd = JHSchool.School.Configuration["評量成績缺考暨免試設定"];
            if (!string.IsNullOrEmpty(cd["評量成績缺考暨免試設定"]))
            {
                XmlElement element = Framework.XmlHelper.LoadXml(cd["評量成績缺考暨免試設定"]);

                foreach (XmlElement each in element.SelectNodes("Setting"))
                {
                    var     UseText          = each.SelectSingleNode("UseText").InnerText;
                    var     AllowCalculation = bool.Parse(each.SelectSingleNode("AllowCalculation").InnerText);
                    decimal Score;
                    decimal.TryParse(each.SelectSingleNode("Score").InnerText, out Score);
                    var Active   = bool.Parse(each.SelectSingleNode("Active").InnerText);
                    var UseValue = decimal.Parse(each.SelectSingleNode("UseValue").InnerText);

                    if (Active)
                    {
                        if (!PluginMain.ScoreTextMap.ContainsKey(UseText))
                        {
                            PluginMain.ScoreTextMap.Add(UseText, new ScoreMap
                            {
                                UseText          = UseText,
                                AllowCalculation = AllowCalculation,
                                Score            = Score,
                                Active           = Active,
                                UseValue         = UseValue,
                            });
                        }
                        if (!PluginMain.ScoreValueMap.ContainsKey(UseValue))
                        {
                            PluginMain.ScoreValueMap.Add(UseValue, new ScoreMap
                            {
                                UseText          = UseText,
                                AllowCalculation = AllowCalculation,
                                Score            = Score,
                                Active           = Active,
                                UseValue         = UseValue,
                            });
                        }
                    }
                }
            }

            #endregion

            #region 取得評量成績
            _listener.SuspendListen();

            // 取得所有試別
            Dictionary <string, JHExamRecord> exams = JHExam.SelectAll().ToDictionary(x => x.ID);
            List <string> examIDs = new List <string>(exams.Keys);

            List <HC.JHAEIncludeRecord> aeList = new List <HC.JHAEIncludeRecord>();

            if (course.RefAssessmentSetupID != null)
            {
                JHAssessmentSetupRecord assessment = JHAssessmentSetup.SelectByID(course.RefAssessmentSetupID);
                if (assessment != null)
                {
                    foreach (JHAEIncludeRecord ae in JHAEInclude.SelectByAssessmentSetupID(assessment.ID))
                    {
                        aeList.Add(new HC.JHAEIncludeRecord(ae));
                    }
                }
                //{
                //    foreach (JHAEIncludeRecord ae in JHAEInclude.SelectAll())
                //    {
                //        if (ae.RefAssessmentSetupID == assessment.ID)
                //            aeList.Add(new HC.JHAEIncludeRecord(ae));
                //    }
                //}
            }

            List <JHSCETakeRecord> jhSCEList = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID);

            //aeList.Sort(delegate(HC.JHAEIncludeRecord x, HC.JHAEIncludeRecord y)
            //{
            //    return x.RefExamID.CompareTo(y.RefExamID);
            //});

            aeList.Sort(delegate(HC.JHAEIncludeRecord x, HC.JHAEIncludeRecord y)
            {
                int ix = examIDs.IndexOf(x.RefExamID);
                int iy = examIDs.IndexOf(y.RefExamID);
                if (ix == -1)
                {
                    ix = int.MaxValue;
                }
                if (iy == -1)
                {
                    iy = int.MaxValue;
                }
                return(ix.CompareTo(iy));
            });

            List <HC.JHSCETakeRecord> sceList = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID).AsHCJHSCETakeRecords();

            Dictionary <string, DataGridViewRow> rows = new Dictionary <string, DataGridViewRow>();
            foreach (HC.JHAEIncludeRecord ae in aeList)
            {
                DataGridViewRow row = new DataGridViewRow();
                //JHExamRecord exam = JHExam.SelectByID(ae.RefExamID);

                JHExamRecord exam = null;
                if (exams.ContainsKey(ae.RefExamID))
                {
                    exam = exams[ae.RefExamID];
                }
                row.CreateCells(dgv, (exam != null) ? exam.Name : "無此評量(" + ae.RefExamID + ")", "", "", "");
                dgv.Rows.Add(row);
                row.Cells[chExamName.Index].Tag = (exam != null) ? exam.ID : "";

                if (!ae.UseScore)
                {
                    DisableCell(row, chScore);
                }
                if (!ae.UseAssignmentScore)
                {
                    DisableCell(row, chAssignmentScore);
                }
                if (!ae.UseText)
                {
                    DisableCell(row, chText);
                }

                if (!rows.ContainsKey(ae.RefExamID))
                {
                    rows.Add(ae.RefExamID, row);
                }
            }

            //List<HC.JHSCETakeRecord> sceList = jhSCEList.AsHCJHSCETakeRecords();
            foreach (HC.JHSCETakeRecord sce in sceList)
            {
                if (rows.ContainsKey(sce.RefExamID))
                {
                    DataGridViewRow row = rows[sce.RefExamID];

                    if (sce.Score.HasValue)
                    {
                        if (PluginMain.ScoreValueMap.ContainsKey(decimal.Parse(sce.Score.Value + "")))
                        {
                            row.Cells[chScore.Index].Value = PluginMain.ScoreValueMap[decimal.Parse(sce.Score.Value + "")].UseText;
                        }
                        else
                        {
                            row.Cells[chScore.Index].Value = sce.Score.Value;
                        }
                    }
                    else
                    {
                        row.Cells[chScore.Index].Value = "";
                    }
                    if (sce.AssignmentScore.HasValue)
                    {
                        if (PluginMain.ScoreValueMap.ContainsKey(decimal.Parse(sce.AssignmentScore.Value + "")))
                        {
                            row.Cells[chAssignmentScore.Index].Value = PluginMain.ScoreValueMap[decimal.Parse(sce.AssignmentScore.Value + "")].UseText;
                        }
                        else
                        {
                            row.Cells[chAssignmentScore.Index].Value = sce.AssignmentScore.Value;
                        }
                    }
                    else
                    {
                        row.Cells[chAssignmentScore.Index].Value = "";
                    }
                    row.Cells[chText.Index].Value = sce.Text;
                    row.Tag = sce;
                }
                else
                {
                    DataGridViewRow row  = new DataGridViewRow();
                    JHExamRecord    exam = JHExam.SelectByID(sce.RefExamID);
                    row.CreateCells(dgv, (exam != null) ? exam.Name : "無此評量(" + sce.RefExamID + ")", sce.Score.HasValue ? "" + sce.Score.Value : "", sce.AssignmentScore.HasValue ? "" + sce.AssignmentScore.Value : "", sce.Text);
                    row.Tag = sce;
                    row.Cells[chExamName.Index].Tag = (exam != null) ? exam.ID : "";
                    dgv.Rows.Add(row);
                    DisableCell(row, chExamName);
                    DisableCell(row, chScore);
                    DisableCell(row, chAssignmentScore);
                    DisableCell(row, chText);
                }
            }

            #region 填入修課總成績
            if (_scattend != null)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(dgv, "課程總成績", "" + _scattend.Score, "", _scattend.Text);
                DisableCell(row, chAssignmentScore);
                row.Tag = "課程總成績";
                dgv.Rows.Add(row);
            }
            #endregion

            foreach (DataGridViewRow dgv1 in dgv.Rows)
            {
                foreach (DataGridViewCell cell in dgv1.Cells)
                {
                    cell.ErrorText = "";

                    if (cell.OwningColumn == chScore || cell.OwningColumn == chAssignmentScore)
                    {
                        cell.Style.ForeColor = Color.Black;
                        if (!string.IsNullOrEmpty("" + cell.Value))
                        {
                            decimal d;
                            if (!decimal.TryParse("" + cell.Value, out d))
                            {
                                if (PluginMain.ScoreTextMap.Keys.Count > 0)
                                {
                                    if (!PluginMain.ScoreTextMap.ContainsKey("" + cell.Value))
                                    {
                                        cell.ErrorText = "分數必須為數字或「" + string.Join("、", PluginMain.ScoreTextMap.Keys) + "」";
                                    }
                                }
                                else
                                {
                                    cell.ErrorText = "分數必須為數字";
                                }
                            }
                            else
                            {
                                if (d < 60)
                                {
                                    cell.Style.ForeColor = Color.Red;
                                }
                                if (d > 100 || d < 0)
                                {
                                    cell.Style.ForeColor = Color.Green;
                                }
                            }
                        }
                    }
                }
            }


            _listener.Reset();
            _listener.ResumeListen();
            #endregion
            SetLoadDataToLog();
        }
示例#13
0
        internal void Read()
        {
            Courses    = ReadCourse();
            AEIncludes = ReadAEInclude();
            Attends    = ReadCurrentSemesterAttend();
            List <JHSCETakeRecord> SCETakes = ReadSCETake();

            //清除原有的資料。
            foreach (StudentScore each in Students.Values)
            {
                each.AttendScore.Clear();
            }

            Reporter.Feedback("計算成績...", 0);
            int t1 = Environment.TickCount;

            foreach (JHSCAttendRecord Attend in Attends.Values)
            {
                if (!Students.ContainsKey(Attend.RefStudentID))
                {
                    continue;
                }
                StudentScore Student = Students[Attend.RefStudentID];

                if (!Courses.ContainsKey(Attend.RefCourseID))
                {
                    continue;
                }
                JHCourseRecord Course = Courses[Attend.RefCourseID];

                bool toSems = (Course.CalculationFlag == "1") ? true : false;

                string subjName = Course.Subject.Trim();

                if (!Student.AttendScore.Contains(subjName))
                {
                    Student.AttendScore.Add(subjName, new AttendScore(Attend, Course.Credit, Course.Period, toSems, Course.Domain));
                }
            }

            foreach (JHSCETakeRecord take in SCETakes)
            {
                if (!Attends.ContainsKey(take.RefSCAttendID))
                {
                    continue;
                }
                JHSCAttendRecord Attend = Attends[take.RefSCAttendID];

                if (!Students.ContainsKey(Attend.RefStudentID))
                {
                    continue;
                }
                StudentScore Student = Students[Attend.RefStudentID];

                if (!Courses.ContainsKey(Attend.RefCourseID))
                {
                    continue;
                }
                JHCourseRecord Course = Courses[Attend.RefCourseID];

                if (!AEIncludes.ContainsKey(Course.RefAssessmentSetupID))
                {
                    continue;
                }
                Dictionary <string, AEIncludeData> Include = AEIncludes[Course.RefAssessmentSetupID];

                //沒有該次考試就不處理。
                if (!Include.ContainsKey(take.RefExamID))
                {
                    continue;
                }

                string subjName = Course.Subject.Trim();
                Student.AttendScore[subjName].Subscores.Add(take.RefExamID, new TakeScore(take, Include[take.RefExamID]));
            }

            Reporter.Feedback("時間:" + (Environment.TickCount - t1), 0);
        }
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            //學生資訊
            Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHStudentRecord>();
            //學生修課資訊 studentID -> List:SCAttendRecord
            Dictionary <string, List <JHSCAttendRecord> > scattends = new Dictionary <string, List <JHSCAttendRecord> >();
            //學生修習的課程 courseID -> CourseRecord
            Dictionary <string, JHCourseRecord> courses = new Dictionary <string, JHCourseRecord>();
            //所有課程(依學年度學期分開) schoolYear_semester -> (courseName -> CourseRecord)
            Dictionary <string, Dictionary <string, JHCourseRecord> > allcourses = new Dictionary <string, Dictionary <string, JHCourseRecord> >();
            //studentID_schoolYear_semester -> List:courseName
            Dictionary <string, List <string> > semesterCourseName = new Dictionary <string, List <string> >();
            //準備加入修課的資料 studentID -> (schoolYear_semester_courseName -> RowData)
            Dictionary <string, Dictionary <string, RowData> > prepareAttends = new Dictionary <string, Dictionary <string, RowData> >();


            wizard.PackageLimit = 3000;
            if (Item != "社團")
            {
                wizard.ImportableFields.Add("課程系統編號");
            }
            wizard.ImportableFields.AddRange("學年度", "學期");
            if (Item != "社團")
            {
                wizard.ImportableFields.Add("課程名稱");
            }
            else
            {
                wizard.ImportableFields.Add("社團名稱");
            }
            wizard.ImportableFields.AddRange("班級", "座號");
            wizard.RequiredFields.AddRange("學年度", "學期");
            if (Item != "社團")
            {
                wizard.RequiredFields.Add("課程名稱");
            }
            else
            {
                wizard.RequiredFields.Add("社團名稱");
            }

            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                #region 取得學生資訊
                foreach (JHStudentRecord stu in JHStudent.SelectByIDs(e.List))
                {
                    if (!students.ContainsKey(stu.ID))
                    {
                        students.Add(stu.ID, stu);
                    }
                }
                #endregion

                #region 取得修課記錄
                MultiThreadWorker <string> loader1 = new MultiThreadWorker <string>();
                loader1.MaxThreads     = 3;
                loader1.PackageSize    = 250;
                loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs <string> e1)
                {
                    foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(e1.List, new string[] { }))
                    {
                        if (!scattends.ContainsKey(record.RefStudentID))
                        {
                            scattends.Add(record.RefStudentID, new List <JHSCAttendRecord>());
                        }
                        scattends[record.RefStudentID].Add(record);

                        if (!courses.ContainsKey(record.RefCourseID))
                        {
                            courses.Add(record.RefCourseID, null);
                        }
                    }
                };
                loader1.Run(e.List);
                #endregion

                #region 取得課程資訊
                MultiThreadWorker <string> loader2 = new MultiThreadWorker <string>();
                loader2.MaxThreads     = 3;
                loader2.PackageSize    = 250;
                loader2.PackageWorker += delegate(object sender2, PackageWorkEventArgs <string> e2)
                {
                    foreach (JHCourseRecord record in JHCourse.SelectByIDs(new List <string>(e2.List)))
                    {
                        if (courses.ContainsKey(record.ID))
                        {
                            courses[record.ID] = record;
                        }
                    }
                };
                loader2.Run(courses.Keys);

                foreach (JHCourseRecord course in JHCourse.SelectAll())
                {
                    string key = course.SchoolYear + "_" + course.Semester;
                    if (!allcourses.ContainsKey(key))
                    {
                        allcourses.Add(key, new Dictionary <string, JHCourseRecord>());
                    }
                    if (!allcourses[key].ContainsKey(course.Name))
                    {
                        allcourses[key].Add(course.Name, course);
                    }
                }
                #endregion
            };

            wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e)
            {
                int i;

                #region 檢查學生是否存在
                JHStudentRecord student = null;
                if (students.ContainsKey(e.Data.ID))
                {
                    student = students[e.Data.ID];
                }
                else
                {
                    e.ErrorMessage = "壓根就沒有這個學生" + e.Data.ID;
                    return;
                }
                #endregion

                #region 驗證各個欄位格式
                bool inputFormatPass = true;
                foreach (string field in e.SelectFields)
                {
                    string value = e.Data[field];
                    switch (field)
                    {
                    default:
                        break;

                    case "學年度":
                    case "學期":
                        if (value == "" || !int.TryParse(value, out i))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入整數");
                        }
                        break;

                    case "課程名稱":
                        if (value == "")
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入課程名稱");
                        }
                        break;

                    case "社團名稱":
                        if (value == "")
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入社團名稱");
                        }
                        break;

                    case "班級":
                        if (value == "")
                        {
                        }
                        break;

                    case "座號":
                        if (value != "" && !int.TryParse(value, out i))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或整數");
                        }
                        break;
                    }
                }
                #endregion

                //輸入格式正確才會針對情節做檢驗
                #region 驗證各種情節
                if (inputFormatPass)
                {
                    string errorMessage = "";

                    string sy         = e.Data["學年度"];
                    string se         = e.Data["學期"];
                    string courseName = (Item != "社團") ? e.Data["課程名稱"] : e.Data["社團名稱"];
                    string key        = e.Data.ID + "_" + sy + "_" + se;
                    string semsKey    = sy + "_" + se;

                    //int schoolyear = Framework.Int.ParseInt(sy);
                    //int semester = Framework.Int.ParseInt(se);

                    #region  一個學年度學期不能有重覆的課程名稱
                    if (!semesterCourseName.ContainsKey(key))
                    {
                        semesterCourseName.Add(key, new List <string>());
                    }
                    if (semesterCourseName[key].Contains(courseName))
                    {
                        if (Item != "社團")
                        {
                            errorMessage += (errorMessage == "" ? "" : "\n") + " 同一學年度學期不允許修習多筆相同名稱的課程";
                        }
                        else
                        {
                            errorMessage += (errorMessage == "" ? "" : "\n") + " 同一學年度學期不允許參與多個相同名稱的社團";
                        }
                    }
                    else
                    {
                        semesterCourseName[key].Add(courseName);
                    }
                    #endregion

                    #region 檢查課程是否存在系統中
                    bool noCourse = false;
                    if (!allcourses.ContainsKey(semsKey))
                    {
                        noCourse = true;
                        if (Item != "社團")
                        {
                            errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程";
                        }
                        else
                        {
                            errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該社團";
                        }
                    }
                    else if (!allcourses[semsKey].ContainsKey(courseName))
                    {
                        noCourse = true;
                        if (Item != "社團")
                        {
                            errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程";
                        }
                        else
                        {
                            errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該社團";
                        }
                    }
                    else
                    {
                    }
                    #endregion

                    #region 檢查學生是否有修此課程
                    bool attended = false;

                    if (scattends.ContainsKey(e.Data.ID))
                    {
                        foreach (JHSCAttendRecord record in scattends[e.Data.ID])
                        {
                            if (courses[record.RefCourseID].Name == courseName &&
                                "" + courses[record.RefCourseID].SchoolYear == sy &&
                                "" + courses[record.RefCourseID].Semester == se)
                            {
                                attended = true;
                            }
                        }
                    }
                    else //學生沒修半堂課
                    {
                    }

                    if (!attended && !noCourse)
                    {
                        if (Item != "社團")
                        {
                            if (!e.WarningFields.ContainsKey("無修課記錄"))
                            {
                                e.WarningFields.Add("無修課記錄", "學生在此學期並無修習此課程,將會新增修課記錄");
                            }
                        }
                        else
                        {
                            if (!e.WarningFields.ContainsKey("無參與記錄"))
                            {
                                e.WarningFields.Add("無參與記錄", "學生在此學期並無參與此社團,將會新增參與記錄");
                            }
                        }

                        if (!prepareAttends.ContainsKey(e.Data.ID))
                        {
                            prepareAttends.Add(e.Data.ID, new Dictionary <string, RowData>());
                        }
                        if (!prepareAttends[e.Data.ID].ContainsKey(semsKey + "_" + courseName))
                        {
                            prepareAttends[e.Data.ID].Add(semsKey + "_" + courseName, e.Data);
                        }
                    }
                    #endregion

                    e.ErrorMessage = errorMessage;
                }
                #endregion
            };

            wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e)
            {
                Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >();

                #region 分包裝
                foreach (RowData data in e.Items)
                {
                    if (!id_Rows.ContainsKey(data.ID))
                    {
                        id_Rows.Add(data.ID, new List <RowData>());
                    }
                    id_Rows[data.ID].Add(data);
                }
                #endregion

                List <JHSCAttendRecord> insertList = new List <JHSCAttendRecord>();
                List <JHSCAttendRecord> updateList = new List <JHSCAttendRecord>();

                //交叉比對各學生資料
                #region 交叉比對各學生資料
                foreach (string id in id_Rows.Keys)
                {
                    JHStudentRecord studentRec = students[id];

                    #region 處理要新增的修課記錄
                    if (prepareAttends.ContainsKey(id))
                    {
                        foreach (RowData data in prepareAttends[id].Values)
                        {
                            string sy         = data["學年度"];
                            string se         = data["學期"];
                            string semsKey    = sy + "_" + se;
                            string courseName = (Item != "社團") ? data["課程名稱"] : data["社團名稱"];

                            if (allcourses.ContainsKey(semsKey) && allcourses[semsKey].ContainsKey(courseName))
                            {
                                JHSCAttendRecord record = new JHSCAttendRecord();
                                record.RefStudentID = id;
                                record.RefCourseID  = allcourses[semsKey][courseName].ID;

                                insertList.Add(record);
                            }
                        }
                    }
                    #endregion
                }

                try
                {
                    if (updateList.Count > 0)
                    {
                        #region 分批次兩路上傳
                        List <List <JHSCAttendRecord> > updatePackages  = new List <List <JHSCAttendRecord> >();
                        List <List <JHSCAttendRecord> > updatePackages2 = new List <List <JHSCAttendRecord> >();
                        {
                            List <JHSCAttendRecord> package = null;
                            int count = 0;
                            foreach (JHSCAttendRecord var in updateList)
                            {
                                if (count == 0)
                                {
                                    package = new List <JHSCAttendRecord>(30);
                                    count   = 30;
                                    if ((updatePackages.Count & 1) == 0)
                                    {
                                        updatePackages.Add(package);
                                    }
                                    else
                                    {
                                        updatePackages2.Add(package);
                                    }
                                }
                                package.Add(var);
                                count--;
                            }
                        }
                        Thread threadUpdateSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Update));
                        threadUpdateSemesterSubjectScore.IsBackground = true;
                        threadUpdateSemesterSubjectScore.Start(updatePackages);
                        Thread threadUpdateSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Update));
                        threadUpdateSemesterSubjectScore2.IsBackground = true;
                        threadUpdateSemesterSubjectScore2.Start(updatePackages2);

                        threadUpdateSemesterSubjectScore.Join();
                        threadUpdateSemesterSubjectScore2.Join();
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                }

                if (insertList.Count > 0)
                {
                    #region 分批次兩路上傳

                    List <List <JHSCAttendRecord> > insertPackages  = new List <List <JHSCAttendRecord> >();
                    List <List <JHSCAttendRecord> > insertPackages2 = new List <List <JHSCAttendRecord> >();
                    {
                        List <JHSCAttendRecord> package = null;
                        int count = 0;
                        foreach (JHSCAttendRecord var in insertList)
                        {
                            if (count == 0)
                            {
                                package = new List <JHSCAttendRecord>(30);
                                count   = 30;
                                if ((insertPackages.Count & 1) == 0)
                                {
                                    insertPackages.Add(package);
                                }
                                else
                                {
                                    insertPackages2.Add(package);
                                }
                            }
                            package.Add(var);
                            count--;
                        }
                    }
                    Thread threadInsertSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Insert));
                    threadInsertSemesterSubjectScore.IsBackground = true;
                    threadInsertSemesterSubjectScore.Start(insertPackages);
                    Thread threadInsertSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Insert));
                    threadInsertSemesterSubjectScore2.IsBackground = true;
                    threadInsertSemesterSubjectScore2.Start(insertPackages2);

                    threadInsertSemesterSubjectScore.Join();
                    threadInsertSemesterSubjectScore2.Join();
                    #endregion
                }

                if (Item != "社團")
                {
                    FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入課程修課學生", "總共匯入" + (insertList.Count + updateList.Count) + "筆課程修課學生。");
                }
                #endregion
            };
        }
示例#15
0
 public PrivateSCAttendRecord(JHSCAttendRecord record)
     : base(record.RefStudentID, record.RefCourseID, record.ID, "", "", "")
 {
 }