public SemesterScoreItem()
        {
            InitializeComponent();
            InitializeQuickAddButton();

            _domainList = new List <string>();
            InitializeColumnHeader();

            UserPermission = Framework.User.Acl[FCode.GetCode(GetType())];

            btnAdd.Visible    = UserPermission.Editable;
            btnModify.Visible = UserPermission.Editable;
            btnDelete.Visible = UserPermission.Editable;
            btnView.Visible   = UserPermission.Viewable & !UserPermission.Editable;

            _worker         = new BackgroundWorker();
            _worker.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                if (_student == null)
                {
                    _student = JHStudent.SelectByID("" + e.Argument);
                }
                else if (_student.ID != "" + e.Argument)
                {
                    _student = JHStudent.SelectByID("" + e.Argument);
                }

                e.Result = JHSemesterScore.SelectByStudentID("" + e.Argument);
            };
            _worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                if (_RunningID != PrimaryKey)
                {
                    _RunningID = PrimaryKey;
                    _worker.RunWorkerAsync(_RunningID);
                    return;
                }

                _recordList = e.Result as List <JHSemesterScoreRecord>;
                FillListView();
            };

            FISCA.InteractionService.SubscribeEvent("CalculationHelper.SaveSemesterScore", (sender, args) => {
                AfterSaveSemesterScore();
            });
        }
示例#2
0
        public void SetStudent(JHStudentRecord student)
        {
            ClearField();

            //JHParentRecord parent = JHParent.SelectByStudent(student);
            //JHPhoneRecord phone = JHPhone.SelectByStudent(student);
            //JHAddressRecord address = JHAddress.SelectByStudent(student);
            //string base64 = K12.Data.Photo.SelectGraduatePhoto(student.ID);

            _data["姓名"] = student.Name;
            //_data["性別"] = student.Gender;
            //_data["身分證號"] = student.IDNumber;
            _data["學號"] = student.StudentNumber;
            _data["班級"] = (student.Class != null ? student.Class.Name : "");
            _data["座號"] = "" + student.SeatNo;
            if (Config._StudSemesterHistoryItemDict.ContainsKey(student.ID))
            {
                _data["班級"] = Config._StudSemesterHistoryItemDict[student.ID].ClassName;
                if (Config._StudSemesterHistoryItemDict[student.ID].SeatNo.HasValue)
                {
                    _data["座號"] = Config._StudSemesterHistoryItemDict[student.ID].SeatNo.Value.ToString();
                }
            }

            _data["服務學習累計"] = "0";

            if (Config._SRDict.ContainsKey(student.ID))
            {
                _data["服務學習累計"] = Config._SRDict[student.ID].ToString();
            }

            //_data["出生日期"] = Common.CDate(student.Birthday.HasValue ? student.Birthday.Value.ToShortDateString() : "");
            //_data["國籍"] = student.Nationality;
            //_data["家長或監護人"] = (parent != null) ? parent.Custodian.Name : "";
            //_data["關係"] = (parent != null) ? parent.Custodian.Relationship : "";
            //_data["行動電話"] = (phone != null) ? phone.Cell : "";
            //_data["戶籍電話"] = (phone != null) ? phone.Permanent : "";
            //_data["戶籍地址"] = (address != null) ? address.Permanent.ToString() : "";
            //_data["聯絡電話"] = (phone != null) ? phone.Contact : "";
            //_data["聯絡地址"] = (address != null) ? address.Mailing.ToString() : "";
            //_data["證書字號"] = ""; //先放著…
            //_data["照片粘貼處"] = base64;

            _builder.Document.MailMerge.Execute(GetFieldName(), GetFieldValue());
        }
        //public void SetStudent(JHStudentRecord student,
        //    JHParentRecord parent,
        //    JHPhoneRecord phone,
        //    JHAddressRecord address,
        //    string base64)
        public void SetStudent(JHStudentRecord student)
        {
            ClearField();

            string teacherName = string.Empty;

            if (student.Class != null && student.Class.Teacher != null)
            {
                teacherName = student.Class.Teacher.Name;
            }

            _data["姓名"] = student.Name;
            //_data["性別"] = student.Gender;
            //_data["身分證號"] = student.IDNumber;
            _data["學號"]  = student.StudentNumber;
            _data["班級"]  = (student.Class != null ? student.Class.Name : "");
            _data["座號"]  = "" + student.SeatNo;
            _data["班導師"] = teacherName;

            if (Config._StudSemesterHistoryItemDict.ContainsKey(student.ID))
            {
                _data["班級"] = Config._StudSemesterHistoryItemDict[student.ID].ClassName;
                if (Config._StudSemesterHistoryItemDict[student.ID].SeatNo.HasValue)
                {
                    _data["座號"] = Config._StudSemesterHistoryItemDict[student.ID].SeatNo.Value.ToString();
                }

                _data["班導師"] = Config._StudSemesterHistoryItemDict[student.ID].Teacher;
            }

            //_data["出生日期"] = Common.CDate(student.Birthday.HasValue ? student.Birthday.Value.ToShortDateString() : "");
            //_data["國籍"] = student.Nationality;
            //_data["家長或監護人"] = (parent != null) ? parent.Custodian.Name : "";
            //_data["關係"] = (parent != null) ? parent.Custodian.Relationship : "";
            //_data["行動電話"] = (phone != null) ? phone.Cell : "";
            //_data["戶籍電話"] = (phone != null) ? phone.Permanent : "";
            //_data["戶籍地址"] = (address != null) ? address.Permanent.ToString() : "";
            //_data["聯絡電話"] = (phone != null) ? phone.Contact : "";
            //_data["聯絡地址"] = (address != null) ? address.Mailing.ToString() : "";
            //_data["證書字號"] = ""; //先放著…
            //_data["照片粘貼處"] = base64;


            _builder.Document.MailMerge.Execute(GetFieldName(), GetFieldValue());
        }
        protected override void OnSaveButtonClick(EventArgs e)
        {
            _BeforeEnrollmentRecord.School         = txtSchool.Text;
            _BeforeEnrollmentRecord.SchoolLocation = txtSchoolLocation.Text;
            _BeforeEnrollmentRecord.ClassName      = txtClass.Text;
            int intSeatNo;

            if (string.IsNullOrEmpty(txtSeatNo.Text))
            {
                _BeforeEnrollmentRecord.SeatNo = null;
            }
            else
            {
                if (int.TryParse(txtSeatNo.Text, out intSeatNo))
                {
                    _BeforeEnrollmentRecord.SeatNo = intSeatNo;
                }
                else
                {
                    epSeatNo.SetError(txtSeatNo, "請填入數字.");
                    return;
                }
            }


            _BeforeEnrollmentRecord.Memo = txtMemo.Text;

            JHBeforeEnrollment.Update(_BeforeEnrollmentRecord);
            listener.Reset();
            SaveButtonVisible   = false;
            CancelButtonVisible = SaveButtonVisible;

            prlp.SetAfterSaveText("學校名稱", txtSchool.Text);
            prlp.SetAfterSaveText("所在地", txtSchoolLocation.Text);
            prlp.SetAfterSaveText("班級", txtClass.Text);
            prlp.SetAfterSaveText("座號", txtSeatNo.Text);
            prlp.SetAfterSaveText("備註", txtMemo.Text);
            prlp.SetActionBy("學籍", "學生前級畢業資訊");
            prlp.SetAction("修改學生前級畢業資訊");
            JHStudentRecord studRec = JHStudent.SelectByID(PrimaryKey);

            prlp.SetDescTitle("學生姓名:" + studRec.Name + ",學號:" + studRec.StudentNumber + ",");
            prlp.SaveLog("", "", "student", PrimaryKey);
        }
        /// <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));
        }
示例#6
0
        private static string GetStudentInfo(JHStudentRecord student)
        {
            string s = "";

            if (student.Class != null)
            {
                s += student.Class.Name;
            }
            if (!string.IsNullOrEmpty("" + student.SeatNo))
            {
                s += " " + student.SeatNo + "號";
            }
            if (!string.IsNullOrEmpty(student.StudentNumber))
            {
                s += " (" + student.StudentNumber + ")";
            }
            s += " " + student.Name;
            return(s);
        }
        /// <summary>
        /// 將學生填入DataGridView。
        /// </summary>
        private void FillStudentsToDataGridView()
        {
            dgv.SuspendLayout();
            dgv.Rows.Clear();

            _scAttendRecordList = JHSCAttend.SelectByCourseIDs(new string[] { _course.ID });

            _ScAttendDic.Clear();
            foreach (JHSCAttendRecord record in _scAttendRecordList)
            {
                if (!_ScAttendDic.ContainsKey(record.RefStudentID))
                {
                    _ScAttendDic.Add(record.RefStudentID, record);
                }
            }
            _scAttendRecordList.Sort(SCAttendComparer);

            foreach (var record in _scAttendRecordList)
            {
                JHStudentRecord student = record.Student;
                if (student.StatusStr != "一般")
                {
                    continue;
                }

                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(dgv,
                                (student.Class != null) ? student.Class.Name : "",
                                student.SeatNo,
                                student.Name,
                                student.StudentNumber
                                );
                row.Tag = student.ID;
                dgv.Rows.Add(row);

                if (!_studentRow.ContainsKey(student.ID))
                {
                    _studentRow.Add(student.ID, row);
                }
            }

            dgv.ResumeLayout();
        }
        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);
            }
        }
示例#9
0
            public JHProgramPlanRecord GetProgramPlanRecord(JHStudentRecord student)
            {
                if (student == null)
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(student.OverrideProgramPlanID))
                {
                    if (student.Class != null)
                    {
                        return(GetProgramPlanRecord(student.Class));
                    }
                }
                else if (ContainsKey(student.OverrideProgramPlanID))
                {
                    return(this[student.OverrideProgramPlanID]);
                }

                return(null);
            }
示例#10
0
 public ReportStudent(JHStudentRecord student)
     : base(student)
 {
     Places         = new Campus.Rating.PlaceCollection();
     HeaderList     = new ReportHeaderList();
     Gender         = student.Gender;
     Birthday       = student.Birthday.HasValue ? student.Birthday.Value.ToString("yyyy/MM/dd") : "";
     Summaries      = new Dictionary <SemesterData, XmlElement>();
     EntranceDate   = string.Empty;
     GraduateDate   = string.Empty;
     EnglishName    = student.EnglishName;
     IDNumber       = student.IDNumber;
     StudentStatus  = student.Status;
     StudentID      = student.ID;
     nationality1   = string.Empty;
     passport_name1 = string.Empty;
     nationality2   = string.Empty;
     passport_name2 = string.Empty;
     Enationality1  = string.Empty;
     Enationality2  = string.Empty;
 }
示例#11
0
        private int SortStudentByClassSeatNo(JHStudentRecord x, JHStudentRecord y)
        {
            JHClassRecord c1 = x.Class;
            JHClassRecord c2 = y.Class;

            if (c1 == null || c2 == null)
            {
                if (c1 == null && c2 == null)
                {
                    return(x.StudentNumber.CompareTo(y.StudentNumber));
                }
                else if (c1 == null)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
            if (c1.ID == c2.ID)
            {
                int seatNo1 = x.SeatNo.HasValue ? x.SeatNo.Value : int.MinValue;
                int seatNo2 = y.SeatNo.HasValue ? y.SeatNo.Value : int.MinValue;

                if (seatNo1 == seatNo2)
                {
                    return(x.StudentNumber.CompareTo(y.StudentNumber));
                }
                else
                {
                    return(seatNo1.CompareTo(seatNo2));
                }
            }
            else
            {
                return(c1.Name.CompareTo(c2.Name));
            }
        }
示例#12
0
        internal void Add(JHStudentRecord student)
        {
            if (string.IsNullOrEmpty(student.StudentNumber))
            {
                return;
            }

            string studentNumber = SCValidatorCreator.GetStudentNumberFormat(student.StudentNumber);

            if (!studentNumberTable.ContainsKey(studentNumber))
            {
                studentNumberTable.Add(studentNumber, student.ID);
            }
            if (!studentTable.ContainsKey(student.ID))
            {
                studentTable.Add(student.ID, student);
            }
            if (!courseTable.ContainsKey(student.ID))
            {
                courseTable.Add(student.ID, new List <JHCourseRecord>());
            }
        }
示例#13
0
        // 儲存資料
        protected override void  OnSaveButtonClick(EventArgs e)
        {
            _PhoneRecord.Permanent = _PermanentPhone = txtEverPhone.Text;
            _PhoneRecord.Contact   = _ContactPhone = txtContactPhone.Text;
            _PhoneRecord.Cell      = _SMS = txtSMS.Text;
            if (btnOthers.Text.EndsWith("1"))
            {
                _OtherPhone1 = txtOtherPhone.Text;
            }
            if (btnOthers.Text.EndsWith("2"))
            {
                _OtherPhone2 = txtOtherPhone.Text;
            }
            if (btnOthers.Text.EndsWith("3"))
            {
                _OtherPhone3 = txtOtherPhone.Text;
            }

            _PhoneRecord.Phone1 = _OtherPhone1;
            _PhoneRecord.Phone2 = _OtherPhone2;
            _PhoneRecord.Phone3 = _OtherPhone3;

            prlp.SetAfterSaveText("戶籍電話", _PermanentPhone);
            prlp.SetAfterSaveText("聯絡電話", _ContactPhone);
            prlp.SetAfterSaveText("行動電話", _SMS);
            prlp.SetAfterSaveText("其他電話1", _OtherPhone1);
            prlp.SetAfterSaveText("其他電話2", _OtherPhone2);
            prlp.SetAfterSaveText("其他電話3", _OtherPhone3);
            JHSchool.Data.JHPhone.Update(_PhoneRecord);

            prlp.SetActionBy("學籍", "學生電話資訊");
            prlp.SetAction("修改學生電話資訊");
            JHStudentRecord studRec = JHStudent.SelectByID(PrimaryKey);

            prlp.SetDescTitle("學生姓名:" + studRec.Name + ",學號:" + studRec.StudentNumber + ",");
            Student.Instance.SyncDataBackground(PrimaryKey);
            prlp.SaveLog("", "", "student", PrimaryKey);
            BindDataToForm();
        }
示例#14
0
        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();
                }
            }
        }
        /// <summary>
        /// 將學生填入DataGridView。
        /// </summary>
        private void FillStudentsToDataGridView()
        {
            dgv.SuspendLayout();
            dgv.Rows.Clear();

            _scAttendRecordList.Sort(SCAttendComparer);

            foreach (var record in _scAttendRecordList)
            {
                JHStudentRecord student = record.Student;
                if (student.StatusStr != "一般")
                {
                    continue;
                }

                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(dgv,
                                (student.Class != null) ? student.Class.Name : "",
                                student.SeatNo,
                                student.Name,
                                student.StudentNumber
                                );
                dgv.Rows.Add(row);

                SCAttendTag tag = new SCAttendTag();
                tag.SCAttend = record;
                row.Tag      = tag;

                //加入 StudentID 與 Row 的對應
                if (!_studentRowDict.ContainsKey(student.ID))
                {
                    _studentRowDict.Add(student.ID, row);
                }
            }

            dgv.ResumeLayout();
        }
示例#16
0
        private void InitializeBackgroundWorker()
        {
            _worker         = new BackgroundWorker();
            _worker.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                JHStudentRecord student = JHStudent.SelectByID(PrimaryKey);

                List <string> courseIDs = new List <string>();
                foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(new string[] { student.ID }, new string[] { }))
                {
                    if (!courseIDs.Contains(record.RefCourseID))
                    {
                        courseIDs.Add(record.RefCourseID);
                    }
                }
                List <JHCourseRecord> courses = JHCourse.SelectByIDs(courseIDs);
                courses.Sort(delegate(JHCourseRecord x, JHCourseRecord y)
                {
                    return(x.Name.CompareTo(y.Name));
                });

                e.Result = courses;
            };
            _worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                if (_RunningID != PrimaryKey)
                {
                    _RunningID = PrimaryKey;
                    _worker.RunWorkerAsync(_RunningID);
                    return;
                }

                ResetListView();
                PrefillItems(e.Result as List <JHCourseRecord>);
            };
        }
示例#17
0
        public void SetStudent(JHStudentRecord student, List <SemesterHistoryItem> semesterHistoryList)
        {
            ClearField();
            // 學期歷程
            _semesterHistoryList = semesterHistoryList;
            JHParentRecord  parent  = JHParent.SelectByStudent(student);
            JHPhoneRecord   phone   = JHPhone.SelectByStudent(student);
            JHAddressRecord address = JHAddress.SelectByStudent(student);
            string          tmpStr  = "      ";

            JHLeaveInfoRecord leave   = JHLeaveIfno.SelectByStudent(student);
            string            number1 = string.Empty;
            string            number2 = string.Empty;

            if (leave != null)
            {
                if (leave.Reason == "畢業")
                {
                    number1 = leave.DiplomaNumber;
                }
                else if (leave.Reason == "修業")
                {
                    number2 = leave.DiplomaNumber;
                }
            }

            string base64 = K12.Data.Photo.SelectGraduatePhoto(student.ID);

            _data["姓名"]      = student.Name;
            _data["性別"]      = student.Gender;
            _data["身分證字號"]   = student.IDNumber;
            _data["學號"]      = student.StudentNumber;
            _data["班級"]      = (student.Class != null ? student.Class.Name : "");
            _data["座號"]      = "" + student.SeatNo;
            _data["出生"]      = DateConvert.ChineseUnitDate(DateConvert.CDate(student.Birthday.HasValue ? student.Birthday.Value.ToShortDateString() : ""));
            _data["出生地"]     = student.BirthPlace;
            _data["家長或監護人"]  = (parent != null) ? parent.Custodian.Name : "";
            _data["關係"]      = (parent != null) ? parent.Custodian.Relationship : "";
            _data["聯絡電話"]    = (phone != null) ? "" + phone.Contact : "";
            _data["戶籍電話"]    = (phone != null) ? "" + phone.Permanent : "";
            _data["戶籍地址"]    = (address != null) ? address.Permanent.ToString() : "";
            _data["通訊處"]     = (address != null) ? address.Mailing.ToString() : "";
            _data["行動電話"]    = (phone != null) ? "" + phone.Cell : "";
            _data["畢業證書字號"]  = number1;
            _data["修業證明書字號"] = number2;
            _data["照片"]      = base64;
            _data["簽呈"]      = "承辦人員:" + Global.TransferName + tmpStr + "註冊組長:" + Global.RegManagerName + tmpStr + "教務主任:" + JHSchoolInfo.EduDirectorName + tmpStr + "校長:" + JHSchoolInfo.ChancellorChineseName;
            // 處理服務學習時數
            if (Global._SLRDict.ContainsKey(student.ID))
            {
                foreach (SemesterHistoryItem shi in _semesterHistoryList)
                {
                    string key = shi.SchoolYear + "_" + shi.Semester;
                    if (Global._SLRDict[student.ID].ContainsKey(key))
                    {
                        string val = Global._SLRDict[student.ID][key];

                        if ((shi.GradeYear == 1 || shi.GradeYear == 7) && shi.Semester == 1)
                        {
                            _data["SLR1A"] = val;
                        }

                        if ((shi.GradeYear == 1 || shi.GradeYear == 7) && shi.Semester == 2)
                        {
                            _data["SLR1B"] = val;
                        }

                        if ((shi.GradeYear == 2 || shi.GradeYear == 8) && shi.Semester == 1)
                        {
                            _data["SLR2A"] = val;
                        }

                        if ((shi.GradeYear == 2 || shi.GradeYear == 8) && shi.Semester == 2)
                        {
                            _data["SLR2B"] = val;
                        }

                        if ((shi.GradeYear == 3 || shi.GradeYear == 9) && shi.Semester == 1)
                        {
                            _data["SLR3A"] = val;
                        }

                        if ((shi.GradeYear == 3 || shi.GradeYear == 9) && shi.Semester == 2)
                        {
                            _data["SLR3B"] = val;
                        }
                    }
                }
            }
            _builder.Document.MailMerge.Execute(GetFieldName(), GetFieldValue());
        }
        private int SortStudentByClassSeatNo(JHStudentRecord x, JHStudentRecord y)
        {
            JHClassRecord c1 = x.Class;
            JHClassRecord c2 = y.Class;
            if (c1.ID == c2.ID)
            {
                int seatNo1 = x.SeatNo.HasValue ? x.SeatNo.Value : int.MinValue;
                int seatNo2 = y.SeatNo.HasValue ? y.SeatNo.Value : int.MinValue;

                if (seatNo1 == seatNo2)
                    return x.StudentNumber.CompareTo(y.StudentNumber);
                else
                    return seatNo1.CompareTo(seatNo2);
            }
            else
            {
                if (c1 == null)
                    return -1;
                else if (c2 == null)
                    return 1;
                return c1.Name.CompareTo(c2.Name);
            }
        }
        public override void  InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            // 取得學生資料
            Dictionary <string, JHStudentRecord> Students = new Dictionary <string, JHStudentRecord>();

            // 取得異動資料
            Dictionary <string, List <JHUpdateRecordRecord> > UpdateRecs = new Dictionary <string, List <JHUpdateRecordRecord> >();

            wizard.PackageLimit = 3000;
            //wizard.ImportableFields.AddRange("學年度", "學期", "異動年級", "異動日期", "入學年月", "畢業年月", "畢修業別", "備註", "學籍核准日期", "學籍核准文號", "畢業證書字號", "異動班級", "異動姓名", "異動身分證號", "異動出生地", "異動學號", "異動性別", "異動生日", "核准日期", "核准文號", "異動類別", "畢(結)業證書字號");
            //wizard.RequiredFields.AddRange("異動類別", "異動日期", "學年度", "學期");
            wizard.ImportableFields.AddRange("學年度", "學期", "異動年級", "異動日期", "入學年月", "畢業年月", "畢修業別", "備註", "學籍核准日期", "學籍核准文號", "畢業證書字號", "異動班級", "異動姓名", "異動身分證號", "異動出生地", "異動學號", "異動性別", "異動生日", "核准日期", "核准文號", "畢(結)業證書字號");
            wizard.RequiredFields.AddRange("異動日期", "學年度", "學期");

            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                Students.Clear();
                UpdateRecs.Clear();

                // 取得學生資料
                foreach (JHStudentRecord studRec in JHStudent.SelectByIDs(e.List))
                {
                    if (!Students.ContainsKey(studRec.ID))
                    {
                        Students.Add(studRec.ID, studRec);
                    }
                }

                foreach (string str in Students.Keys)
                {
                    List <JHUpdateRecordRecord> UpdRecList = new List <JHUpdateRecordRecord>();
                    UpdateRecs.Add(str, UpdRecList);
                }


                // 取得異動
                MultiThreadWorker <string> loader1 = new MultiThreadWorker <string>();
                loader1.MaxThreads     = 3;
                loader1.PackageSize    = 250;
                loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs <string> e1)
                {
                    foreach (JHUpdateRecordRecord UpdRec in JHUpdateRecord.SelectByStudentIDs(e.List))
                    {
                        // 畢業
                        if (UpdRec.UpdateCode == "2")
                        {
                            if (UpdateRecs.ContainsKey(UpdRec.StudentID))
                            {
                                UpdateRecs[UpdRec.StudentID].Add(UpdRec);
                            }
                        }
                    }
                };
                loader1.Run(e.List);
            };

            wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e)
            {
                int      i = 0;
                DateTime dt;
                // 檢查學生是否存在
                JHStudentRecord studRec = null;
                if (Students.ContainsKey(e.Data.ID))
                {
                    studRec = Students[e.Data.ID];
                }
                else
                {
                    e.ErrorMessage = "沒有這位學生" + e.Data.ID;
                    return;
                }

                // 驗證格式資料
                bool InputFormatPass = true;
                CheckHasData = false;



                foreach (string field in e.SelectFields)
                {
                    string value = e.Data[field].Trim();

                    //// 驗證$無法匯入
                    //if (value.IndexOf('$') > -1)
                    //{
                    //    e.ErrorFields.Add(field, "儲存格有$無法匯入.");
                    //    break;
                    //}

                    // 檢查系統內是否已經有畢業異動
                    if (CheckHasData == false)
                    {
                        if (UpdateRecs.ContainsKey(e.Data.ID))
                        {
                            if (UpdateRecs[e.Data.ID].Count > 0)
                            {
                                e.WarningFields.Add(field, "系統內已有畢業異動,匯入將會取代系統內畢業異動");
                                CheckHasData = true;
                            }
                        }
                    }

                    switch (field)
                    {
                    default:
                        break;

                    //case "異動類別":
                    //    if (value != "畢業")
                    //    {
                    //        InputFormatPass &= false;
                    //        e.ErrorFields.Add(field, "必須填入畢業");
                    //    }
                    //    if (value == "畢業")
                    //    {
                    //        if (UpdateRecs.ContainsKey(e.Data.ID))
                    //            if (UpdateRecs[e.Data.ID].Count > 0)
                    //            {
                    //                e.WarningFields.Add(field, "系統內已有畢業異動,匯入將會取代系統內畢業異動");
                    //            }
                    //    }
                    //    break;

                    case "學年度":
                        int.TryParse(value, out i);
                        if (string.IsNullOrEmpty(value) || i < 1)
                        {
                            InputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入整數");
                        }

                        break;

                    case "學期":
                        int.TryParse(value, out i);
                        if (string.IsNullOrEmpty(value) || i < 1)
                        {
                            InputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入整數");
                        }

                        if (i > 2)
                        {
                            InputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入整數,1或2");
                        }

                        break;

                    case "異動年級":
                        int.TryParse(value, out i);
                        if (string.IsNullOrEmpty(value) || i < 1)
                        {
                            InputFormatPass &= false;
                            e.WarningFields.Add(field, "請填入整數");
                        }
                        break;

                    case "異動日期":
                        if (string.IsNullOrEmpty(value) || DateTime.TryParse(value, out dt) == false)
                        {
                            InputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1");
                        }
                        break;

                    case "入學年月":
                        int.TryParse(value, out i);
                        if (!string.IsNullOrEmpty(value) && i < 1)
                        {
                            e.WarningFields.Add(field, "必須填入年月格式,例如200901");
                        }
                        break;

                    case "畢業年月":
                        int.TryParse(value, out i);
                        if (!string.IsNullOrEmpty(value) && i < 1)
                        {
                            e.WarningFields.Add(field, "必須填入年月格式,例如200901");
                        }
                        break;

                    case "異動生日":
                        if (!string.IsNullOrEmpty(value))
                        {
                            if (DateTime.TryParse(value, out dt) == false)
                            {
                                InputFormatPass &= false;
                                e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1");
                            }
                        }
                        break;

                    case "學籍核准日期":
                        if (!string.IsNullOrEmpty(value))
                        {
                            if (DateTime.TryParse(value, out dt) == false)
                            {
                                InputFormatPass &= false;
                                e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1");
                            }
                        }
                        break;

                    case "核准日期":
                        if (!string.IsNullOrEmpty(value))
                        {
                            if (DateTime.TryParse(value, out dt) == false)
                            {
                                InputFormatPass &= false;
                                e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1");
                            }
                        }
                        break;

                    case "異動性別":
                        if (value == "男" || value == "女" || value == "")
                        {
                        }
                        else
                        {
                            e.WarningFields.Add(field, "請填入男或女");
                        }
                        break;
                    }
                }
            };


            wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e)
            {
                Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >();
                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);
                }

                List <JHUpdateRecordRecord> InsertList = new List <JHUpdateRecordRecord>();
                List <JHUpdateRecordRecord> UpdateList = new List <JHUpdateRecordRecord>();
                List <JHUpdateRecordRecord> DelList    = new List <JHUpdateRecordRecord>();

                foreach (string id in id_Rows.Keys)
                {
                    int      schoolYear, Semester;
                    string   GrYear = "";
                    DateTime dt;

                    foreach (RowData data in id_Rows[id])
                    {
                        if (!UpdateRecs.ContainsKey(id))
                        {
                            continue;
                        }
                        int.TryParse(data["學年度"], out schoolYear);
                        int.TryParse(data["學期"], out Semester);
                        DateTime.TryParse(data["異動日期"], out dt);
                        if (data.ContainsKey("異動年級"))
                        {
                            GrYear = data["異動年級"];
                        }
                        JHUpdateRecordRecord updateRec = null;
                        foreach (JHUpdateRecordRecord urr in UpdateRecs[id])
                        {
                            if (urr.UpdateCode == "2")
                            {
                                DelList.Add(urr);
                            }
                            //if (urr.SchoolYear == schoolYear && urr.Semester == Semester && urr.GradeYear == GrYear)
                            //{
                            //    DateTime dt1;
                            //    DateTime.TryParse(urr.UpdateDate, out dt1);
                            //    if (dt == dt1)
                            //        updateRec = urr;
                            //}
                        }
                        bool isInsert = true;

                        if (updateRec == null)
                        {
                            updateRec           = new JHUpdateRecordRecord();
                            updateRec.StudentID = id;
                        }
                        else
                        {
                            isInsert = false;
                        }

                        updateRec.UpdateCode = "2";

                        // 當已經有畢業異動使用新增方式
                        if (CheckHasData)
                        {
                            isInsert = true;
                        }

                        bool checkData = false;
                        foreach (string field in e.ImportFields)
                        {
                            string value = data[field].Trim();

                            switch (field)
                            {
                            //case "異動類別":
                            //    if (value == "畢業")
                            //    {
                            //        updateRec.UpdateCode = "2";
                            //        checkData = true;
                            //    }
                            //    break;
                            case "學年度":
                                int scYear;
                                if (int.TryParse(value, out scYear))
                                {
                                    updateRec.SchoolYear = scYear;
                                    checkData            = true;
                                }
                                break;

                            case "學期":
                                int Sems;
                                if (int.TryParse(value, out Sems))
                                {
                                    updateRec.Semester = Sems;
                                    checkData          = true;
                                }
                                break;

                            case "異動年級":
                                updateRec.GradeYear = GrYear;
                                break;

                            case "異動日期":
                                DateTime dtd;
                                if (DateTime.TryParse(value, out dtd))
                                {
                                    updateRec.UpdateDate = dtd.ToShortDateString();
                                }
                                break;

                            case "入學年月":
                                if (string.IsNullOrEmpty(value))
                                {
                                    updateRec.EnrollmentSchoolYear = string.Empty;
                                }
                                else
                                {
                                    updateRec.EnrollmentSchoolYear = value;
                                }
                                break;

                            case "畢業年月":
                                if (string.IsNullOrEmpty(value))
                                {
                                    updateRec.GraduateSchoolYear = string.Empty;
                                }
                                else
                                {
                                    updateRec.GraduateSchoolYear = value;
                                }
                                break;

                            case "畢修業別":
                                updateRec.Graduate = value;
                                break;

                            case "備註":
                                updateRec.Comment = value;
                                break;

                            case "學籍核准日期":
                                DateTime dtLD;
                                if (DateTime.TryParse(value, out dtLD))
                                {
                                    updateRec.LastADDate = dtLD.ToShortDateString();
                                }
                                break;

                            case "學籍核准文號":
                                updateRec.LastADNumber = value;
                                break;

                            case "畢業證書字號":
                                updateRec.GraduateCertificateNumber = value;
                                break;

                            case "畢(結)業證書字號":
                                updateRec.GraduateCertificateNumber = value;
                                break;

                            case "異動班級":
                                updateRec.OriginClassName = value;
                                break;

                            case "異動姓名":
                                updateRec.StudentName = value;
                                break;

                            case "異動身分證號":
                                updateRec.IDNumber = value;
                                break;

                            case "異動出生地":
                                updateRec.BirthPlace = value;
                                break;

                            case "異動學號":
                                updateRec.StudentNumber = value;
                                break;

                            case "異動性別":
                                if (value == "男" || value == "女" || value == "")
                                {
                                    updateRec.Gender = value;
                                }
                                break;

                            case "異動生日":
                                DateTime dtb;
                                if (DateTime.TryParse(value, out dtb))
                                {
                                    updateRec.Birthdate = dtb.ToShortDateString();
                                }
                                break;

                            case "核准日期":
                                DateTime dtAd;
                                if (DateTime.TryParse(value, out dtAd))
                                {
                                    updateRec.ADDate = dtAd.ToShortDateString();
                                }

                                break;

                            case "核准文號":
                                updateRec.ADNumber = value;
                                break;
                            }
                        }

                        if (string.IsNullOrEmpty(updateRec.StudentID) || string.IsNullOrEmpty(updateRec.UpdateDate) || string.IsNullOrEmpty(updateRec.UpdateCode))
                        {
                            continue;
                        }
                        else
                        {
                            if (isInsert)
                            {
                                InsertList.Add(updateRec);
                            }
                            else
                            {
                                UpdateList.Add(updateRec);
                            }
                        }
                    }
                }

                try
                {
                    // 先清空舊
                    if (DelList.Count > 0)
                    {
                        Delete(DelList);
                    }

                    if (InsertList.Count > 0)
                    {
                        Insert(InsertList);
                    }

                    if (UpdateList.Count > 0)
                    {
                        Update(UpdateList);
                    }


                    JHSchool.PermRecLogProcess prlp = new JHSchool.PermRecLogProcess();
                    prlp.SaveLog("學生.匯入異動", "匯入畢業異動", "匯入畢業異動:共新增" + InsertList.Count + "筆資料,共更新:" + UpdateList.Count + "筆資料");
                    JHSchool.Student.Instance.SyncAllBackground();
                }
                catch (Exception ex) {}
            };
        }
示例#20
0
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            //學生資訊 key: studentID
            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, JHSchool.Data.JHCourseRecord> >();
            //學生修習的課程對應的評量設定細節
            Dictionary <string, List <JHAEIncludeRecord> > courseAe = new Dictionary <string, List <JHSchool.Data.JHAEIncludeRecord> >();
            //學生的評量成績記錄
            Dictionary <string, List <JHSCETakeRecord> > existSces = new Dictionary <string, List <JHSchool.Data.JHSCETakeRecord> >();
            //所有試別
            Dictionary <string, JHExamRecord> exams = new Dictionary <string, JHSchool.Data.JHExamRecord>();

            // 取得努力程度對照
            K12.Data.Configuration.ConfigData cd = K12.Data.School.Configuration["努力程度對照表"];
            if (!string.IsNullOrEmpty(cd["xml"]))
            {
                XmlElement element = XmlHelper.LoadXml(cd["xml"]);

                foreach (XmlElement each in element.SelectNodes("Effort"))
                {
                    int     code = int.Parse(each.GetAttribute("Code"));
                    decimal score;
                    if (!decimal.TryParse(each.GetAttribute("Score"), out score))
                    {
                        score = 0;
                    }

                    if (!_EffortDict.ContainsKey(score))
                    {
                        _EffortDict.Add(score, code);
                    }
                }

                _ScoreList.AddRange(_EffortDict.Keys);
                _ScoreList.Reverse();
            }


            wizard.PackageLimit = 3000;
            // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
            wizard.ImportableFields.AddRange("學年度", "學期", "課程名稱", "評量名稱", "分數評量", "努力程度");
            wizard.RequiredFields.AddRange("學年度", "學期", "課程名稱", "評量名稱");

            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 <JHSchool.Data.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, JHSchool.Data.JHCourseRecord>());
                    }
                    if (!allcourses[key].ContainsKey(course.Name))
                    {
                        allcourses[key].Add(course.Name, course);
                    }
                }
                #endregion

                #region 取得目前評量成績記錄

                MultiThreadWorker <string> loader3 = new MultiThreadWorker <string>();
                loader3.MaxThreads     = 3;
                loader3.PackageSize    = 250;
                loader3.PackageWorker += delegate(object sender3, PackageWorkEventArgs <string> e3)
                {
                    foreach (JHSCETakeRecord sce in JHSCETake.SelectByStudentIDs(e3.List))
                    {
                        if (!existSces.ContainsKey(sce.RefSCAttendID))
                        {
                            existSces.Add(sce.RefSCAttendID, new List <JHSchool.Data.JHSCETakeRecord>());
                        }
                        existSces[sce.RefSCAttendID].Add(sce);
                    }
                };
                loader3.Run(e.List);
                #endregion

                #region 取得評量設定
                foreach (JHAEIncludeRecord ae in JHAEInclude.SelectAll())
                {
                    if (!courseAe.ContainsKey(ae.RefAssessmentSetupID))
                    {
                        courseAe.Add(ae.RefAssessmentSetupID, new List <JHSchool.Data.JHAEIncludeRecord>());
                    }
                    courseAe[ae.RefAssessmentSetupID].Add(ae);
                }
                #endregion

                #region 取得試別
                foreach (JHExamRecord exam in JHExam.SelectAll())
                {
                    if (!exams.ContainsKey(exam.ID))
                    {
                        exams.Add(exam.ID, exam);
                    }
                }
                #endregion
            };

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

                #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 != "" && !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或數值");
                        }
                        break;

                    case "努力程度":
                        if (value != "" && !int.TryParse(value, out i))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或整數");
                        }
                        else
                        {
                            // 2020/10/15 加入檢查,當分數與努力轉換後努力程度不同,需要顯示警告
                            if (value != "")
                            {
                                int x = ConvertEffort(d);
                                if (x != i)
                                {
                                    e.WarningFields.Add(field, "努力程度與使用分數轉換後不一致");
                                }
                            }
                        }
                        break;

                        // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
                        //case "文字描述":
                        //    break;
                    }
                }
                #endregion

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

                    string sy         = e.Data["學年度"];
                    string se         = e.Data["學期"];
                    string key        = e.Data.ID + "_" + sy + "_" + se;
                    string courseName = e.Data["課程名稱"];
                    string semsKey    = sy + "_" + se;
                    string examName   = e.Data["評量名稱"];

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

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

                    #region 檢查學生是否有修此課程 & 評量是否存在
                    bool attended = false;

                    JHCourseRecord attendCourse = null;
                    if (scattends.ContainsKey(e.Data.ID))
                    {
                        foreach (JHSCAttendRecord record in scattends[e.Data.ID])
                        {
                            bool HasRec = false;

                            // 當有學年度學期課程名稱相同
                            if (courses[record.RefCourseID].Name == courseName && courses[record.RefCourseID].SchoolYear.HasValue && courses[record.RefCourseID].Semester.HasValue)
                            {
                                if ((courses[record.RefCourseID].SchoolYear.Value.ToString().Trim() == sy.Trim()) && courses[record.RefCourseID].Semester.Value.ToString().Trim() == se.Trim())
                                {
                                    HasRec = true;
                                }
                            }
                            if (HasRec && courses.ContainsKey(record.RefCourseID))
                            {
                                attendCourse = courses[record.RefCourseID];
                            }
                        }
                    }
                    else //學生沒修半堂課
                    {
                    }

                    if (attendCourse == null && !noCourse)
                    {
                        if (!e.ErrorFields.ContainsKey("無修課記錄"))
                        {
                            e.ErrorFields.Add("無修課記錄", "學生在此學期並無修習此課程");
                        }
                    }
                    else if (attendCourse != null)
                    {
                        #region 驗證評量是否存在
                        if (string.IsNullOrEmpty(attendCourse.RefAssessmentSetupID))
                        {
                            if (!e.ErrorFields.ContainsKey("無評量設定"))
                            {
                                e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定");
                            }
                        }
                        else
                        {
                            if (!courseAe.ContainsKey(attendCourse.RefAssessmentSetupID))
                            {
                                if (!e.ErrorFields.ContainsKey("無評量設定"))
                                {
                                    e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定");
                                }
                            }
                            else
                            {
                                bool examValid = false;
                                foreach (JHAEIncludeRecord ae in courseAe[attendCourse.RefAssessmentSetupID])
                                {
                                    if (!exams.ContainsKey(ae.RefExamID))
                                    {
                                        continue;
                                    }

                                    // 2016/7/26,穎驊新增,由於高雄國中希望可以加入匯出匯入"平時評量的功能",因此必須要在原本的Exam.Name驗證
                                    // 加上 ||examName =="平時評量" ,避免平時評量的欄位被擋掉
                                    if (exams[ae.RefExamID].Name == examName || examName == "平時評量")
                                    {
                                        examValid = true;
                                    }
                                }

                                if (!examValid)
                                {
                                    if (!e.ErrorFields.ContainsKey("評量名稱無效"))
                                    {
                                        e.ErrorFields.Add("評量名稱無效", "評量名稱(" + examName + ")不存在系統中");
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    #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 <KH.JHSCETakeRecord> insertList = new List <KH.JHSCETakeRecord>();
                List <KH.JHSCETakeRecord> updateList = new List <KH.JHSCETakeRecord>();


                // 檢查是否有努力程度欄位
                bool isHasEffortField = false;

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

                    foreach (RowData data in id_Rows[id])
                    {
                        string examName   = data["評量名稱"];
                        string courseName = data["課程名稱"];
                        string SchoolYear = data["學年度"];
                        string Semester   = data["學期"];

                        if (isHasEffortField == false)
                        {
                            if (data.ContainsKey("努力程度"))
                            {
                                // 有努力程度這欄位
                                isHasEffortField = true;
                            }
                        }

                        // 2016/7/26,穎驊新增bool值避免 在有"平時評量"的評量名稱Row 進入算評量成績的判斷式
                        bool isOrdinarilyScore = false;

                        if (!scattends.ContainsKey(id))
                        {
                            continue;
                        }

                        foreach (JHSCAttendRecord record in scattends[id])
                        {
                            if (!courses.ContainsKey(record.RefCourseID))
                            {
                                continue;
                            }
                            JHCourseRecord course = courses[record.RefCourseID];
                            //if (course.Name != courseName) continue;

                            string sy = "", ss = "";
                            if (course.SchoolYear.HasValue)
                            {
                                sy = course.SchoolYear.Value.ToString();
                            }
                            if (course.Semester.HasValue)
                            {
                                ss = course.Semester.Value.ToString();
                            }

                            if (SchoolYear != sy || Semester != ss || course.Name != courseName)
                            {
                                continue;
                            }


                            KH.JHSCETakeRecord currentSCE = null;

                            if (SchoolYear == sy && Semester == ss && course.Name == courseName)
                            {
                                // 2016/7/26,穎驊新增,由於高雄國中希望可以加入匯出匯入"平時評量的功能",在原本的Code努力尋找見縫插針的位子,
                                //因為"平時評量"與一般的"評量成績"處理邏輯要分開
                                //後來決定這邊是最佳位子,邏輯為,當程序在一條一條讀取Excel Row時,讀到欄位"評量名稱"值為 "平時評量"
                                //則進入我們處理平時評量的程序,如果欄位"評量名稱"值非為 "平時評量" 則使用它原本的邏輯處理
                                // 上面的CODE會幫忙進行學年、學期、課程的驗證,確保是同一門課程成績資料,
                                //而 JHSCAttendRecord record內意外發現剛好有 平時評量OrdinarilyScore的欄位
                                //因此只要指定欄位為新的Excel 內的值,最後 使用JHSCAttend.Update(record) 更新即可

                                if (data.ContainsKey("評量名稱"))
                                {
                                    if (data["評量名稱"] == "平時評量")
                                    {
                                        if (data.ContainsKey("分數評量"))
                                        {
                                            if (data["分數評量"] != null && data["分數評量"] != "")
                                            {
                                                decimal d;

                                                // 使用TryParse 的轉換,是因為可能會有Row 的分數評量欄位是空的(EX: 社團成績) ,直接Parse會爆
                                                if (decimal.TryParse(data["分數評量"], out d))
                                                {
                                                    record.OrdinarilyScore = d;
                                                }
                                            }

                                            // 當分數評量是空白
                                            if (data["分數評量"] != null && data["分數評量"].Trim() == "")
                                            {
                                                record.OrdinarilyScore = null;
                                            }
                                        }

                                        if (data.ContainsKey("努力程度"))
                                        {
                                            if (data["努力程度"] != null && data["努力程度"] != "")
                                            {
                                                int i;
                                                if (int.TryParse(data["努力程度"], out i))
                                                {
                                                    record.OrdinarilyEffort = i;
                                                }
                                            }

                                            if (data["努力程度"] != null && data["努力程度"].Trim() == "")
                                            {
                                                record.OrdinarilyEffort = null;
                                            }
                                        }

                                        // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
                                        //if (data["文字描述"] != null)
                                        //{
                                        //    record.Text = data["文字描述"].ToString();
                                        //}

                                        // 2020/10/15 宏安與小組會議討論,當沒有努力程度欄位,會使用成績轉換努力程度
                                        if (isHasEffortField == false)
                                        {
                                            if (record.OrdinarilyScore.HasValue)
                                            {
                                                record.OrdinarilyEffort = ConvertEffort(record.OrdinarilyScore.Value);
                                            }
                                            else
                                            {
                                                record.OrdinarilyEffort = null;
                                            }
                                        }


                                        JHSCAttend.Update(record);

                                        isOrdinarilyScore = true;

                                        currentSCE = null;
                                    }

                                    else
                                    {
                                        if (existSces.ContainsKey(record.ID))
                                        {
                                            foreach (KH.JHSCETakeRecord sce in existSces[record.ID].AsKHJHSCETakeRecords())
                                            {
                                                if (!exams.ContainsKey(sce.RefExamID))
                                                {
                                                    continue;
                                                }

                                                if (exams[sce.RefExamID].Name == examName)
                                                {
                                                    currentSCE = sce;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            // 2016/7/26,穎驊新增bool值避免 在有"平時評量"的評量名稱Row 進入算評量成績的判斷式
                            if (currentSCE != null && isOrdinarilyScore == false)
                            {
                                //bool changed = false;

                                #region 填入資料
                                foreach (string field in e.ImportFields)
                                {
                                    string value = data[field];
                                    switch (field)
                                    {
                                    case "分數評量":
                                        if ("" + currentSCE.Score != value)
                                        {
                                            decimal d;
                                            if (decimal.TryParse(value, out d))
                                            {
                                                currentSCE.Score = d;
                                            }
                                            else
                                            {
                                                currentSCE.Score = null;
                                            }
                                            //   changed = true;
                                        }
                                        break;

                                    case "努力程度":
                                        if ("" + currentSCE.Effort != value)
                                        {
                                            int i;
                                            if (int.TryParse(value, out i))
                                            {
                                                currentSCE.Effort = i;
                                            }
                                            else
                                            {
                                                currentSCE.Effort = null;
                                            }
                                            //  changed = true;
                                        }
                                        break;
                                        // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
                                        //case "文字描述":
                                        //    if (currentSCE.Text != value)
                                        //    {
                                        //        currentSCE.Text = value;
                                        //        changed = true;
                                        //    }
                                        //    break;
                                    }
                                }
                                #endregion

                                //    if (changed)
                                updateList.Add(currentSCE);
                            }

                            // 2016/7/26,穎驊新增bool值避免 在有"平時評量"的評量名稱Row 進入算評量成績的判斷式
                            if (currentSCE == null && isOrdinarilyScore == false)
                            {
                                KH.JHSCETakeRecord newSCE = new KH.JHSCETakeRecord(new JHSCETakeRecord());
                                newSCE.RefStudentID  = id;
                                newSCE.RefSCAttendID = record.ID;
                                newSCE.RefCourseID   = record.RefCourseID;

                                foreach (JHExamRecord exam in exams.Values)
                                {
                                    if (exam.Name == examName)
                                    {
                                        newSCE.RefExamID = exam.ID;
                                        break;
                                    }
                                }

                                #region 填入資料
                                foreach (string field in e.ImportFields)
                                {
                                    string value = data[field];
                                    switch (field)
                                    {
                                    case "分數評量":
                                        if (value != "")
                                        {
                                            decimal d;
                                            if (decimal.TryParse(value, out d))
                                            {
                                                newSCE.Score = d;
                                            }
                                            else
                                            {
                                                newSCE.Score = null;
                                            }
                                        }
                                        else
                                        {
                                            newSCE.Score = null;
                                        }
                                        break;

                                    case "努力程度":
                                        if (value != "")
                                        {
                                            int i;
                                            if (int.TryParse(value, out i))
                                            {
                                                newSCE.Effort = i;
                                            }
                                            else
                                            {
                                                newSCE.Effort = null;
                                            }
                                        }
                                        else
                                        {
                                            newSCE.Effort = null;
                                        }
                                        break;

                                        // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
                                        //case "文字描述":
                                        //    newSCE.Text = value;
                                        //    break;
                                    }
                                }
                                #endregion

                                if (newSCE.RefExamID != "")
                                {
                                    insertList.Add(newSCE);
                                }
                            }
                        }
                    }
                }

                try
                {
                    // 解析並填入轉換空白的努力程度
                    // 2020/10/15 透過宏安討論,當沒有努力程度欄位才會使用成績轉換,如果有努力程度欄位不會使用成績轉換。
                    foreach (KH.JHSCETakeRecord rec in updateList)
                    {
                        //// 當努力程度沒有值卻有成績。
                        //if ((rec.Effort.HasValue == false) && rec.Score.HasValue)
                        //{
                        //    rec.Effort = ConvertEffort(rec.Score.Value);
                        //}

                        if (isHasEffortField == false)
                        {
                            if (rec.Score.HasValue)
                            {
                                rec.Effort = ConvertEffort(rec.Score.Value);
                            }
                            else
                            {
                                rec.Effort = null;
                            }
                        }
                    }

                    foreach (KH.JHSCETakeRecord rec in insertList)
                    {
                        //// 當努力程度沒有值卻有成績。
                        //if ((rec.Effort.HasValue == false) && rec.Score.HasValue)
                        //{
                        //    rec.Effort = ConvertEffort(rec.Score.Value);
                        //}

                        if (isHasEffortField == false)
                        {
                            if (rec.Score.HasValue)
                            {
                                rec.Effort = ConvertEffort(rec.Score.Value);
                            }
                            else
                            {
                                rec.Effort = null;
                            }
                        }
                    }



                    if (updateList.Count > 0)
                    {
                        #region 分批次兩路上傳
                        List <List <KH.JHSCETakeRecord> > updatePackages  = new List <List <KH.JHSCETakeRecord> >();
                        List <List <KH.JHSCETakeRecord> > updatePackages2 = new List <List <KH.JHSCETakeRecord> >();
                        {
                            List <KH.JHSCETakeRecord> package = null;
                            int count = 0;
                            foreach (KH.JHSCETakeRecord var in updateList)
                            {
                                if (count == 0)
                                {
                                    package = new List <KH.JHSCETakeRecord>(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 <KH.JHSCETakeRecord> > insertPackages  = new List <List <KH.JHSCETakeRecord> >();
                    List <List <KH.JHSCETakeRecord> > insertPackages2 = new List <List <KH.JHSCETakeRecord> >();
                    {
                        List <KH.JHSCETakeRecord> package = null;
                        int count = 0;
                        foreach (KH.JHSCETakeRecord var in insertList)
                        {
                            if (count == 0)
                            {
                                package = new List <KH.JHSCETakeRecord>(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
                }

                FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入評量成績", "總共匯入" + (insertList.Count + updateList.Count) + "筆評量成績。");
                #endregion
            };
        }
示例#21
0
        public ImportStartupForm()
        {
            InitializeComponent();
            InitializeSemesters();

            _effortMapper = new EffortMapper();

            // 載入預設儲存值
            LoadConfigData();

            _worker = new BackgroundWorker();
            _worker.WorkerReportsProgress = true;
            _worker.ProgressChanged      += delegate(object sender, ProgressChangedEventArgs e)
            {
                lblMessage.Text = "" + e.UserState;
            };
            _worker.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                #region Worker DoWork
                _worker.ReportProgress(0, "檢查讀卡文字格式…");

                #region 檢查文字檔
                ValidateTextFiles  vtf      = new ValidateTextFiles(intStudentNumberLenght.Value);
                ValidateTextResult vtResult = vtf.CheckFormat(_files);
                if (vtResult.Error)
                {
                    e.Result = vtResult;
                    return;
                }
                #endregion

                //文字檔轉 RawData
                RawDataCollection rdCollection = new RawDataCollection();
                rdCollection.ConvertFromFiles(_files);

                //RawData 轉 DataRecord
                DataRecordCollection drCollection = new DataRecordCollection();
                drCollection.ConvertFromRawData(rdCollection);

                _rawDataValidator    = new DataValidator <RawData>();
                _dataRecordValidator = new DataValidator <DataRecord>();

                #region 取得驗證需要的資料
                JHCourse.RemoveAll();
                _worker.ReportProgress(0, "取得學生資料…");
                List <JHStudentRecord> studentList = GetInSchoolStudents();

                List <string> s_ids = new List <string>();
                Dictionary <string, List <string> > studentNumberToStudentIDs = new Dictionary <string, List <string> >();
                foreach (JHStudentRecord student in studentList)
                {
                    string sn = SCValidatorCreator.GetStudentNumberFormat(student.StudentNumber);
                    if (!studentNumberToStudentIDs.ContainsKey(sn))
                    {
                        studentNumberToStudentIDs.Add(sn, new List <string>());
                    }
                    studentNumberToStudentIDs[sn].Add(student.ID);
                }
                foreach (var dr in drCollection)
                {
                    if (studentNumberToStudentIDs.ContainsKey(dr.StudentNumber))
                    {
                        s_ids.AddRange(studentNumberToStudentIDs[dr.StudentNumber]);
                    }
                }

                studentList.Clear();

                _worker.ReportProgress(0, "取得課程資料…");
                List <JHCourseRecord>    courseList = JHCourse.SelectBySchoolYearAndSemester(SchoolYear, Semester);
                List <JHAEIncludeRecord> aeList     = JHAEInclude.SelectAll();

                //List<JHSCAttendRecord> scaList = JHSCAttend.SelectAll();
                var c_ids = from course in courseList select course.ID;
                _worker.ReportProgress(0, "取得修課資料…");
                //List<JHSCAttendRecord> scaList2 = JHSCAttend.SelectByStudentIDAndCourseID(s_ids, c_ids.ToList<string>());
                List <JHSCAttendRecord> scaList = new List <JHSCAttendRecord>();
                FunctionSpliter <string, JHSCAttendRecord> spliter = new FunctionSpliter <string, JHSCAttendRecord>(300, 3);
                spliter.Function = delegate(List <string> part)
                {
                    return(JHSCAttend.Select(part, c_ids.ToList <string>(), null, SchoolYear.ToString(), Semester.ToString()));
                };
                scaList = spliter.Execute(s_ids);

                _worker.ReportProgress(0, "取得試別資料…");
                List <JHExamRecord> examList = JHExam.SelectAll();
                #endregion

                #region 註冊驗證
                _worker.ReportProgress(0, "載入驗證規則…");
                _rawDataValidator.Register(new SubjectCodeValidator());
                _rawDataValidator.Register(new ClassCodeValidator());
                _rawDataValidator.Register(new ExamCodeValidator());

                SCValidatorCreator scCreator = new SCValidatorCreator(JHStudent.SelectByIDs(s_ids), courseList, scaList);
                _dataRecordValidator.Register(scCreator.CreateStudentValidator());
                _dataRecordValidator.Register(new ExamValidator(examList));
                _dataRecordValidator.Register(scCreator.CreateSCAttendValidator());
                _dataRecordValidator.Register(new CourseExamValidator(scCreator.StudentCourseInfo, aeList, examList));
                #endregion

                #region 進行驗證
                _worker.ReportProgress(0, "進行驗證中…");
                List <string> msgList = new List <string>();

                foreach (RawData rawData in rdCollection)
                {
                    List <string> msgs = _rawDataValidator.Validate(rawData);
                    msgList.AddRange(msgs);
                }
                if (msgList.Count > 0)
                {
                    e.Result = msgList;
                    return;
                }

                foreach (DataRecord dataRecord in drCollection)
                {
                    List <string> msgs = _dataRecordValidator.Validate(dataRecord);
                    msgList.AddRange(msgs);
                }
                if (msgList.Count > 0)
                {
                    e.Result = msgList;
                    return;
                }
                #endregion

                #region 取得學生的評量成績
                _deleteScoreList.Clear();
                _addScoreList.Clear();

                //var student_ids = from student in scCreator.StudentNumberDictionary.Values select student.ID;
                //List<string> course_ids = scCreator.AttendCourseIDs;

                var scaIDs = from sca in scaList select sca.ID;

                Dictionary <string, JHSCETakeRecord>      sceList    = new Dictionary <string, JHSCETakeRecord>();
                FunctionSpliter <string, JHSCETakeRecord> spliterSCE = new FunctionSpliter <string, JHSCETakeRecord>(300, 3);
                spliterSCE.Function = delegate(List <string> part)
                {
                    return(JHSCETake.Select(null, null, null, null, part));
                };
                foreach (JHSCETakeRecord sce in spliterSCE.Execute(scaIDs.ToList()))
                {
                    string key = GetCombineKey(sce.RefStudentID, sce.RefCourseID, sce.RefExamID);
                    if (!sceList.ContainsKey(key))
                    {
                        sceList.Add(key, sce);
                    }
                }

                Dictionary <string, JHExamRecord>     examTable = new Dictionary <string, JHExamRecord>();
                Dictionary <string, JHSCAttendRecord> scaTable  = new Dictionary <string, JHSCAttendRecord>();

                foreach (JHExamRecord exam in examList)
                {
                    if (!examTable.ContainsKey(exam.Name))
                    {
                        examTable.Add(exam.Name, exam);
                    }
                }

                foreach (JHSCAttendRecord sca in scaList)
                {
                    string key = GetCombineKey(sca.RefStudentID, sca.RefCourseID);
                    if (!scaTable.ContainsKey(key))
                    {
                        scaTable.Add(key, sca);
                    }
                }

                foreach (DataRecord dr in drCollection)
                {
                    JHStudentRecord       student = student = scCreator.StudentNumberDictionary[dr.StudentNumber];
                    JHExamRecord          exam    = examTable[dr.Exam];
                    List <JHCourseRecord> courses = new List <JHCourseRecord>();
                    foreach (JHCourseRecord course in scCreator.StudentCourseInfo.GetCourses(dr.StudentNumber))
                    {
                        if (dr.Subjects.Contains(course.Subject))
                        {
                            courses.Add(course);
                        }
                    }

                    foreach (JHCourseRecord course in courses)
                    {
                        string key = GetCombineKey(student.ID, course.ID, exam.ID);

                        if (sceList.ContainsKey(key))
                        {
                            _deleteScoreList.Add(sceList[key]);
                        }

                        JHSCETakeRecord    jh     = new JHSCETakeRecord();
                        KH.JHSCETakeRecord sceNew = new KH.JHSCETakeRecord(jh);
                        sceNew.RefCourseID   = course.ID;
                        sceNew.RefExamID     = exam.ID;
                        sceNew.RefSCAttendID = scaTable[GetCombineKey(student.ID, course.ID)].ID;
                        sceNew.RefStudentID  = student.ID;
                        sceNew.Score         = dr.Score;
                        sceNew.Effort        = _effortMapper.GetCodeByScore(dr.Score);
                        _addScoreList.Add(sceNew.AsJHSCETakeRecord());
                    }
                }
                #endregion

                e.Result = null;
                #endregion
            };
            _worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                #region Worker Completed
                if (e.Error == null && e.Result == null)
                {
                    if (!_upload.IsBusy)
                    {
                        //如果學生身上已有成績,則提醒使用者
                        if (_deleteScoreList.Count > 0)
                        {
                            _warn.RunWorkerAsync();
                        }
                        else
                        {
                            lblMessage.Text = "成績上傳中…";
                            FISCA.Presentation.MotherForm.SetStatusBarMessage("成績上傳中…", 0);
                            counter = 0;
                            _upload.RunWorkerAsync();
                        }
                    }
                }
                else
                {
                    ControlEnable = true;

                    if (e.Error != null)
                    {
                        MsgBox.Show("匯入失敗。" + e.Error.Message);
                        SmartSchool.ErrorReporting.ReportingService.ReportException(e.Error);
                    }
                    else if (e.Result != null && e.Result is ValidateTextResult)
                    {
                        ValidateTextResult    result = e.Result as ValidateTextResult;
                        ValidationErrorViewer viewer = new ValidationErrorViewer();
                        viewer.SetTextFileError(result.LineIndexes, result.ErrorFormatLineIndexes, result.DuplicateLineIndexes);
                        viewer.ShowDialog();
                    }
                    else if (e.Result != null && e.Result is List <string> )
                    {
                        ValidationErrorViewer viewer = new ValidationErrorViewer();
                        viewer.SetErrorLines(e.Result as List <string>);
                        viewer.ShowDialog();
                    }
                }
                #endregion
            };

            _upload = new BackgroundWorker();
            _upload.WorkerReportsProgress = true;
            _upload.ProgressChanged      += new ProgressChangedEventHandler(_upload_ProgressChanged);
            //_upload.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            //{
            //    counter += double.Parse("" + e.ProgressPercentage);
            //    FISCA.Presentation.MotherForm.SetStatusBarMessage("成績上傳中…", (int)(counter * 100f / (double)_addScoreList.Count));
            //};
            _upload.DoWork += new DoWorkEventHandler(_upload_DoWork);

            //_upload.DoWork += delegate
            //{


            //#region Upload DoWork
            //Framework.MultiThreadWorker<JHSCETakeRecord> multi = new Framework.MultiThreadWorker<JHSCETakeRecord>();
            //multi.MaxThreads = 3;
            //multi.PackageSize = 500;
            //multi.PackageWorker += delegate(object sender, Framework.PackageWorkEventArgs<JHSCETakeRecord> e)
            //{
            //    JHSCETake.Delete(e.List);
            //};
            //multi.Run(_deleteScoreList);

            //Framework.MultiThreadWorker<JHSCETakeRecord> multi2 = new Framework.MultiThreadWorker<JHSCETakeRecord>();
            //multi2.MaxThreads = 3;
            //multi2.PackageSize = 500;
            //multi2.PackageWorker += delegate(object sender, Framework.PackageWorkEventArgs<JHSCETakeRecord> e)
            //{
            //    JHSCETake.Insert(e.List);
            //    lock (_upload)
            //    {
            //        _upload.ReportProgress(e.List.Count);
            //    }
            //};
            //multi2.Run(_addScoreList);
            //#endregion
            //};


            _upload.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_upload_RunWorkerCompleted);

            _warn = new BackgroundWorker();
            _warn.WorkerReportsProgress = true;
            _warn.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                _warn.ReportProgress(0, "產生警告訊息...");

                Dictionary <string, string> examDict = new Dictionary <string, string>();
                foreach (JHExamRecord exam in JHExam.SelectAll())
                {
                    if (!examDict.ContainsKey(exam.ID))
                    {
                        examDict.Add(exam.ID, exam.Name);
                    }
                }

                WarningForm form  = new WarningForm();
                int         count = 0;
                foreach (JHSCETakeRecord sce in _deleteScoreList)
                {
                    // 當成績資料是空值跳過
                    if (sce.Score.HasValue == false && sce.Effort.HasValue == false && string.IsNullOrEmpty(sce.Text))
                    {
                        continue;
                    }

                    count++;

                    JHStudentRecord student = JHStudent.SelectByID(sce.RefStudentID);
                    JHCourseRecord  course  = JHCourse.SelectByID(sce.RefCourseID);
                    string          exam    = (examDict.ContainsKey(sce.RefExamID) ? examDict[sce.RefExamID] : "<未知的試別>");

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

                    form.Add(student.ID, s, string.Format("學生在「{0}」課程「{1}」中已有成績。", course.Name, exam));
                    _warn.ReportProgress((int)(count * 100 / _deleteScoreList.Count), "產生警告訊息...");
                }

                e.Result = form;
            };
            _warn.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                WarningForm form = e.Result as WarningForm;

                if (form.ShowDialog() == DialogResult.OK)
                {
                    lblMessage.Text = "成績上傳中…";
                    FISCA.Presentation.MotherForm.SetStatusBarMessage("成績上傳中…", 0);
                    counter = 0;
                    _upload.RunWorkerAsync();
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                }
            };
            _warn.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            {
                FISCA.Presentation.MotherForm.SetStatusBarMessage("" + e.UserState, e.ProgressPercentage);
            };

            _files           = new List <FileInfo>();
            _addScoreList    = new List <JHSCETakeRecord>();
            _deleteScoreList = new List <JHSCETakeRecord>();
        }
示例#22
0
 private string GetStudentInfo(JHStudentRecord student)
 {
     return(HsinChu.JHEvaluation.Utility.StudentInfoConvertor.GetInfoWithClass(student));
 }
示例#23
0
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            Dictionary <string, int>             _ID_SchoolYear_Semester_GradeYear = new Dictionary <string, int>();
            Dictionary <string, List <string> >  _ID_SchoolYear_Semester_Subject   = new Dictionary <string, List <string> >();
            Dictionary <string, JHStudentRecord> _StudentCollection = new Dictionary <string, JHStudentRecord>();
            Dictionary <JHStudentRecord, Dictionary <int, decimal> > _StudentPassScore = new Dictionary <JHStudentRecord, Dictionary <int, decimal> >();
            Dictionary <string, List <JHSemesterScoreRecord> >       semsDict          = new Dictionary <string, List <JHSemesterScoreRecord> >();

            wizard.PackageLimit = 3000;
            //wizard.ImportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記");
            //wizard.ImportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "分數評量", "文字描述", "註記");

            //2015.1.27 Cloud新增
            wizard.ImportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "成績", "原始成績", "補考成績", "努力程度", "文字描述", "註記");

            wizard.RequiredFields.AddRange("領域", "科目", "學年度", "學期");

            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                #region ValidateStart
                _ID_SchoolYear_Semester_GradeYear.Clear();
                _ID_SchoolYear_Semester_Subject.Clear();
                _StudentCollection.Clear();

                List <JHStudentRecord> list = JHStudent.SelectByIDs(e.List);

                MultiThreadWorker <JHStudentRecord> loader = new MultiThreadWorker <JHStudentRecord>();
                loader.MaxThreads     = 3;
                loader.PackageSize    = 250;
                loader.PackageWorker += delegate(object sender1, PackageWorkEventArgs <JHStudentRecord> e1)
                {
                    foreach (var item in JHSemesterScore.SelectByStudents(e1.List))
                    {
                        if (!semsDict.ContainsKey(item.RefStudentID))
                        {
                            semsDict.Add(item.RefStudentID, new List <JHSchool.Data.JHSemesterScoreRecord>());
                        }
                        semsDict[item.RefStudentID].Add(item);
                    }
                };
                loader.Run(list);

                foreach (JHStudentRecord stu in list)
                {
                    if (!_StudentCollection.ContainsKey(stu.ID))
                    {
                        _StudentCollection.Add(stu.ID, stu);
                    }
                }
                #endregion
            };
            wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e)
            {
                #region ValidateRow
                int             t;
                decimal         d;
                JHStudentRecord student;
                if (_StudentCollection.ContainsKey(e.Data.ID))
                {
                    student = _StudentCollection[e.Data.ID];
                }
                else
                {
                    e.ErrorMessage = "壓根就沒有這個學生" + e.Data.ID;
                    return;
                }
                bool inputFormatPass = true;
                #region 驗各欄位填寫格式
                foreach (string field in e.SelectFields)
                {
                    string value = e.Data[field];
                    switch (field)
                    {
                    default:
                        break;

                    case "領域":
                        //if (value == "")
                        //{
                        //    inputFormatPass &= false;
                        //    e.ErrorFields.Add(field, "必須填寫");
                        //}
                        //else if (!Domains.Contains(value))
                        //{
                        //    inputFormatPass &= false;
                        //    e.ErrorFields.Add(field, "必須為七大領域");
                        //}
                        break;

                    case "科目":
                        if (value == "")
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填寫");
                        }
                        break;

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

                    case "權數":
                    case "節數":
                        if (value == "" || !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入數值");
                        }
                        break;

                    //case "成績年級":
                    //    if (value == "" || !int.TryParse(value, out t))
                    //    {
                    //        inputFormatPass &= false;
                    //        e.ErrorFields.Add(field, "必須填入整數");
                    //    }
                    //    break;
                    case "學期":
                        if (value == "" || !int.TryParse(value, out t) || t > 2 || t < 1)
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入1或2");
                        }
                        break;

                    //case "分數評量":
                    //    if (value != "" && !decimal.TryParse(value, out d))
                    //    {
                    //        inputFormatPass &= false;
                    //        e.ErrorFields.Add(field, "必須填入空白或數值");
                    //    }
                    //    break;
                    case "成績":
                        if (value != "" && !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或數值");
                        }
                        break;

                    case "原始成績":
                        if (value != "" && !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或數值");
                        }
                        break;

                    case "補考成績":
                        if (value != "" && !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或數值");
                        }
                        break;
                        //case "努力程度":
                        //    if (value != "" && !int.TryParse(value, out t))
                        //    {
                        //        inputFormatPass &= false;
                        //        e.ErrorFields.Add(field, "必須填入空白或數值");
                        //    }
                        //    break;
                    }
                }
                #endregion
                //輸入格式正確才會針對情節做檢驗
                if (inputFormatPass)
                {
                    string errorMessage = "";

                    string subject    = e.Data["科目"];
                    string schoolYear = e.Data["學年度"];
                    string semester   = e.Data["學期"];
                    int?   sy         = null;
                    int?   se         = null;
                    if (int.TryParse(schoolYear, out t))
                    {
                        sy = t;
                    }
                    if (int.TryParse(semester, out t))
                    {
                        se = t;
                    }
                    if (sy != null && se != null)
                    {
                        string key = e.Data.ID + "_" + sy + "_" + se;
                        #region 驗證新增科目成績
                        List <JHSemesterScoreRecord> semsList;
                        if (semsDict.ContainsKey(student.ID))
                        {
                            semsList = semsDict[student.ID];
                        }
                        else
                        {
                            semsList = new List <JHSemesterScoreRecord>();
                        }
                        foreach (JHSemesterScoreRecord record in semsList)
                        {
                            if (record.SchoolYear != sy)
                            {
                                continue;
                            }
                            if (record.Semester != se)
                            {
                                continue;
                            }

                            bool   isNewSubjectInfo = true;
                            string message          = "";
                            foreach (K12.Data.SubjectScore s in record.Subjects.Values)
                            {
                                if (s.Subject == subject)
                                {
                                    isNewSubjectInfo = false;
                                }
                            }
                            if (isNewSubjectInfo)
                            {
                                if (!e.WarningFields.ContainsKey("查無此科目"))
                                {
                                    e.WarningFields.Add("查無此科目", "學生在此學期並無此筆科目成績資訊,將會新增此科目成績");
                                }
                                foreach (string field in new string[] { "領域", "科目", "學年度", "學期", "權數", "節數" })
                                {
                                    if (!e.SelectFields.Contains(field))
                                    {
                                        message += (message == "" ? "發現此學期無此科目,\n將會新增成績\n缺少成績必要欄位" : "、") + field;
                                    }
                                }
                                if (message != "")
                                {
                                    errorMessage += (errorMessage == "" ? "" : "\n") + message;
                                }
                            }
                        }
                        #endregion
                        #region 驗證重複科目資料
                        //string skey = subject + "_" + le;
                        string skey = subject;
                        if (!_ID_SchoolYear_Semester_Subject.ContainsKey(key))
                        {
                            _ID_SchoolYear_Semester_Subject.Add(key, new List <string>());
                        }
                        if (_ID_SchoolYear_Semester_Subject[key].Contains(skey))
                        {
                            errorMessage += (errorMessage == "" ? "" : "\n") + "同一學期不允許多筆相同科目的資料";
                        }
                        else
                        {
                            _ID_SchoolYear_Semester_Subject[key].Add(skey);
                        }
                        #endregion
                    }
                    e.ErrorMessage = errorMessage;
                }
                #endregion
            };

            wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e)
            {
                #region ImportPackage
                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<SmartSchool.Feature.Score.AddScore.InsertInfo> insertList = new List<SmartSchool.Feature.Score.AddScore.InsertInfo>();
                //List<SmartSchool.Feature.Score.EditScore.UpdateInfo> updateList = new List<SmartSchool.Feature.Score.EditScore.UpdateInfo>();
                List <JHSemesterScoreRecord> insertList = new List <JHSemesterScoreRecord>();
                List <JHSemesterScoreRecord> updateList = new List <JHSemesterScoreRecord>();
                //交叉比對各學生資料
                #region 交叉比對各學生資料
                foreach (string id in id_Rows.Keys)
                {
                    XmlDocument     doc        = new XmlDocument();
                    JHStudentRecord studentRec = _StudentCollection[id];
                    //該學生的學期科目成績
                    Dictionary <SemesterInfo, JHSemesterScoreRecord> semesterScoreDictionary = new Dictionary <SemesterInfo, JHSemesterScoreRecord>();
                    #region 整理現有的成績資料
                    List <JHSchool.Data.JHSemesterScoreRecord> semsList;
                    if (semsDict.ContainsKey(studentRec.ID))
                    {
                        semsList = semsDict[studentRec.ID];
                    }
                    else
                    {
                        semsList = new List <JHSchool.Data.JHSemesterScoreRecord>();
                    }
                    foreach (JHSemesterScoreRecord var in semsList)
                    {
                        SemesterInfo info = new SemesterInfo();
                        info.SchoolYear = var.SchoolYear;
                        info.Semester   = var.Semester;

                        if (!semesterScoreDictionary.ContainsKey(info))
                        {
                            semesterScoreDictionary.Add(info, var);
                        }

                        //string key = var.Subject + "_" + var.Level;
                        //if (!semesterScoreDictionary.ContainsKey(var.SchoolYear))
                        //    semesterScoreDictionary.Add(var.SchoolYear, new Dictionary<int, Dictionary<string, SemesterSubjectScoreInfo>>());
                        //if (!semesterScoreDictionary[var.SchoolYear].ContainsKey(var.Semester))
                        //    semesterScoreDictionary[var.SchoolYear].Add(var.Semester, new Dictionary<string, SemesterSubjectScoreInfo>());
                        //if (!semesterScoreDictionary[var.SchoolYear][var.Semester].ContainsKey(key))
                        //    semesterScoreDictionary[var.SchoolYear][var.Semester].Add(key, var);
                    }
                    #endregion

                    //要匯入的學期科目成績
                    Dictionary <SemesterInfo, Dictionary <string, RowData> > semesterImportScoreDictionary = new Dictionary <SemesterInfo, Dictionary <string, RowData> >();

                    #region 整理要匯入的資料
                    foreach (RowData row in id_Rows[id])
                    {
                        int    t;
                        string subject    = row["科目"];
                        string schoolYear = row["學年度"];
                        string semester   = row["學期"];
                        int    sy         = int.Parse(schoolYear);
                        int    se         = int.Parse(semester);

                        SemesterInfo info = new SemesterInfo();
                        info.SchoolYear = sy;
                        info.Semester   = se;

                        if (!semesterImportScoreDictionary.ContainsKey(info))
                        {
                            semesterImportScoreDictionary.Add(info, new Dictionary <string, RowData>());
                        }
                        if (!semesterImportScoreDictionary[info].ContainsKey(subject))
                        {
                            semesterImportScoreDictionary[info].Add(subject, row);
                        }
                    }
                    #endregion

                    //學期年級重整
                    //Dictionary<SemesterInfo, int> semesterGradeYear = new Dictionary<SemesterInfo, int>();
                    //要變更成績的學期
                    List <SemesterInfo> updatedSemester = new List <SemesterInfo>();
                    //在變更學期中新增加的成績資料
                    Dictionary <SemesterInfo, List <RowData> > updatedNewSemesterScore = new Dictionary <SemesterInfo, List <RowData> >();
                    //要增加成績的學期
                    Dictionary <SemesterInfo, List <RowData> > insertNewSemesterScore = new Dictionary <SemesterInfo, List <RowData> >();
                    //開始處理ImportScore
                    #region 開始處理ImportScore
                    foreach (SemesterInfo info in semesterImportScoreDictionary.Keys)
                    {
                        foreach (string subject in semesterImportScoreDictionary[info].Keys)
                        {
                            RowData data = semesterImportScoreDictionary[info][subject];
                            //如果是本來沒有這筆學期的成績就加到insertNewSemesterScore
                            if (!semesterScoreDictionary.ContainsKey(info))
                            {
                                if (!insertNewSemesterScore.ContainsKey(info))
                                {
                                    insertNewSemesterScore.Add(info, new List <RowData>());
                                }
                                insertNewSemesterScore[info].Add(data);
                            }
                            else
                            {
                                bool hasChanged = false;
                                //修改已存在的資料
                                if (semesterScoreDictionary[info].Subjects.ContainsKey(subject))
                                {
                                    JHSemesterScoreRecord record = semesterScoreDictionary[info];

                                    #region 直接修改已存在的成績資料的Detail
                                    foreach (string field in e.ImportFields)
                                    {
                                        K12.Data.SubjectScore score = record.Subjects[subject];
                                        string value = data[field];
                                        //"分數評量", "努力程度", "文字描述", "註記"
                                        switch (field)
                                        {
                                        default:
                                            break;

                                        case "領域":
                                            if (score.Domain != value)
                                            {
                                                score.Domain = value;
                                                hasChanged   = true;
                                            }
                                            break;

                                        case "權數":
                                            if ("" + score.Credit != value)
                                            {
                                                score.Credit = decimal.Parse(value);
                                                hasChanged   = true;
                                            }
                                            break;

                                        case "節數":
                                            if ("" + score.Period != value)
                                            {
                                                score.Period = decimal.Parse(value);
                                                hasChanged   = true;
                                            }
                                            break;

                                        //case "成績年級":
                                        //    int gy = int.Parse(data["成績年級"]);
                                        //    if (record.GradeYear != gy)
                                        //    {
                                        //        semesterGradeYear[info] = gy;
                                        //        hasChanged = true;
                                        //    }
                                        //    break;
                                        //case "分數評量":
                                        //    if ("" + score.Score != value)
                                        //    {
                                        //        decimal d;
                                        //        if (decimal.TryParse(value, out d))
                                        //            score.Score = d;
                                        //        else
                                        //            score.Score = null;
                                        //        hasChanged = true;
                                        //    }
                                        //    break;
                                        case "成績":
                                            if ("" + score.Score != value)
                                            {
                                                decimal d;
                                                if (decimal.TryParse(value, out d))
                                                {
                                                    score.Score = d;
                                                }
                                                else
                                                {
                                                    score.Score = null;
                                                }
                                                hasChanged = true;
                                            }
                                            break;

                                        case "原始成績":
                                            if ("" + score.ScoreOrigin != value)
                                            {
                                                decimal d;
                                                if (decimal.TryParse(value, out d))
                                                {
                                                    score.ScoreOrigin = d;
                                                }
                                                else
                                                {
                                                    score.ScoreOrigin = null;
                                                }
                                                hasChanged = true;
                                            }
                                            break;

                                        case "補考成績":
                                            if ("" + score.ScoreMakeup != value)
                                            {
                                                decimal d;
                                                if (decimal.TryParse(value, out d))
                                                {
                                                    score.ScoreMakeup = d;
                                                }
                                                else
                                                {
                                                    score.ScoreMakeup = null;
                                                }
                                                hasChanged = true;
                                            }
                                            break;

                                        //case "努力程度":
                                        //    if ("" + score.Effort != value)
                                        //    {
                                        //        int i;
                                        //        if (int.TryParse(value, out i))
                                        //            score.Effort = i;
                                        //        else
                                        //            score.Effort = null;
                                        //        hasChanged = true;
                                        //    }
                                        //    break;
                                        case "文字描述":
                                            if ("" + score.Text != value)
                                            {
                                                score.Text = value;
                                                hasChanged = true;
                                            }
                                            break;

                                        case "註記":
                                            if (score.Comment != value)
                                            {
                                                score.Comment = value;
                                                hasChanged    = true;
                                            }
                                            break;
                                        }
                                    }
                                    #endregion
                                }
                                else//加入新成績至已存在的學期
                                {
                                    if (!updatedNewSemesterScore.ContainsKey(info))
                                    {
                                        updatedNewSemesterScore.Add(info, new List <RowData>());
                                    }
                                    updatedNewSemesterScore[info].Add(data);
                                    hasChanged = true;
                                }
                                //真的有變更
                                if (hasChanged)
                                {
                                    #region 登錄有變更的學期
                                    if (!updatedSemester.Contains(info))
                                    {
                                        updatedSemester.Add(info);
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                    #endregion
                    //處理已登錄要更新的學期成績
                    #region 處理已登錄要更新的學期成績
                    foreach (SemesterInfo info in updatedSemester)
                    {
                        //Dictionary<int, Dictionary<int, string>> semeScoreID = (Dictionary<int, Dictionary<int, string>>)studentRec.Fields["SemesterSubjectScoreID"];
                        //string semesterScoreID = semeScoreID[sy][se];//從學期抓ID
                        //int gradeyear = semesterGradeYear[info];//抓年級
                        //XmlElement subjectScoreInfo = doc.CreateElement("SemesterSubjectScoreInfo");
                        #region 產生該學期科目成績的XML
                        //foreach (SemesterSubjectScoreInfo scoreInfo in semesterScoreDictionary[sy][se].Values)
                        //{
                        //    subjectScoreInfo.AppendChild(doc.ImportNode(scoreInfo.Detail, true));
                        //}

                        updateList.Add(semesterScoreDictionary[info]);

                        //if (updatedNewSemesterScore.ContainsKey(sy) && updatedNewSemesterScore[sy].ContainsKey(se))
                        if (updatedNewSemesterScore.ContainsKey(info))
                        {
                            foreach (RowData row in updatedNewSemesterScore[info])
                            {
                                //XmlElement newScore = doc.CreateElement("Subject");
                                K12.Data.SubjectScore subjectScore = new K12.Data.SubjectScore();
                                #region 建立newScore
                                //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記" })
                                //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "文字描述", "註記" })
                                foreach (string field in new string[] { "領域", "科目", "權數", "節數", "成績", "原始成績", "補考成績", "文字描述", "註記" })
                                {
                                    if (e.ImportFields.Contains(field))
                                    {
                                        decimal d;

                                        #region 填入科目資訊
                                        string value = row[field];
                                        switch (field)
                                        {
                                        default:
                                            break;

                                        case "領域":
                                            subjectScore.Domain = value;
                                            break;

                                        case "科目":
                                            subjectScore.Subject = value;
                                            break;

                                        case "權數":
                                            subjectScore.Credit = decimal.Parse(value);
                                            break;

                                        case "節數":
                                            subjectScore.Period = decimal.Parse(value);
                                            break;

                                        //case "分數評量":
                                        //    decimal d;
                                        //    if (decimal.TryParse(value, out d))
                                        //        subjectScore.Score = d;
                                        //    else
                                        //        subjectScore.Score = null;
                                        //    break;
                                        case "成績":
                                            if (decimal.TryParse(value, out d))
                                            {
                                                subjectScore.Score = d;
                                            }
                                            else
                                            {
                                                subjectScore.Score = null;
                                            }
                                            break;

                                        case "原始成績":
                                            if (decimal.TryParse(value, out d))
                                            {
                                                subjectScore.ScoreOrigin = d;
                                            }
                                            else
                                            {
                                                subjectScore.ScoreOrigin = null;
                                            }
                                            break;

                                        case "補考成績":
                                            if (decimal.TryParse(value, out d))
                                            {
                                                subjectScore.ScoreMakeup = d;
                                            }
                                            else
                                            {
                                                subjectScore.ScoreMakeup = null;
                                            }
                                            break;

                                        //case "努力程度":
                                        //    int i;
                                        //    if (int.TryParse(value, out i))
                                        //        subjectScore.Effort = i;
                                        //    else
                                        //        subjectScore.Effort = null;
                                        //    break;
                                        case "文字描述":
                                            subjectScore.Text = value;
                                            break;

                                        case "註記":
                                            subjectScore.Comment = value;
                                            break;
                                        }
                                        #endregion
                                    }
                                }
                                #endregion
                                //subjectScoreInfo.AppendChild(newScore);
                                JHSemesterScoreRecord record = semesterScoreDictionary[info];
                                if (!record.Subjects.ContainsKey(subjectScore.Subject))
                                {
                                    record.Subjects.Add(subjectScore.Subject, subjectScore);
                                }
                                else
                                {
                                    record.Subjects[subjectScore.Subject] = subjectScore;
                                }

                                updateList.Add(record);
                            }
                        }
                        #endregion
                        //updateList.Add(new SmartSchool.Feature.Score.EditScore.UpdateInfo(semesterScoreID, gradeyear, subjectScoreInfo));
                    }
                    #endregion
                    //處理新增成績學期
                    #region 處理新增成績學期
                    foreach (SemesterInfo info in insertNewSemesterScore.Keys)
                    {
                        //int gradeyear = semesterGradeYear[info];//抓年級
                        foreach (RowData row in insertNewSemesterScore[info])
                        {
                            K12.Data.SubjectScore subjectScore = new K12.Data.SubjectScore();
                            //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記" })
                            //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "文字描述", "註記" })
                            foreach (string field in new string[] { "領域", "科目", "權數", "節數", "成績", "原始成績", "補考成績", "文字描述", "註記" })
                            {
                                if (e.ImportFields.Contains(field))
                                {
                                    decimal d;

                                    string value = row[field];
                                    switch (field)
                                    {
                                    default: break;

                                    case "領域":
                                        subjectScore.Domain = value;
                                        break;

                                    case "科目":
                                        subjectScore.Subject = value;
                                        break;

                                    case "權數":
                                        subjectScore.Credit = decimal.Parse(value);
                                        break;

                                    case "節數":
                                        subjectScore.Period = decimal.Parse(value);
                                        break;

                                    //case "分數評量":
                                    //    decimal d;
                                    //    if (decimal.TryParse(value, out d))
                                    //        subjectScore.Score = d;
                                    //    else
                                    //        subjectScore.Score = null;
                                    //    break;
                                    case "成績":
                                        if (decimal.TryParse(value, out d))
                                        {
                                            subjectScore.Score = d;
                                        }
                                        else
                                        {
                                            subjectScore.Score = null;
                                        }
                                        break;

                                    case "原始成績":
                                        if (decimal.TryParse(value, out d))
                                        {
                                            subjectScore.ScoreOrigin = d;
                                        }
                                        else
                                        {
                                            subjectScore.ScoreOrigin = null;
                                        }
                                        break;

                                    case "補考成績":
                                        if (decimal.TryParse(value, out d))
                                        {
                                            subjectScore.ScoreMakeup = d;
                                        }
                                        else
                                        {
                                            subjectScore.ScoreMakeup = null;
                                        }
                                        break;

                                    //case "努力程度":
                                    //    int i;
                                    //    if (int.TryParse(value, out i))
                                    //        subjectScore.Effort = i;
                                    //    else
                                    //        subjectScore.Effort = null;
                                    //    break;
                                    case "文字描述":
                                        subjectScore.Text = value;
                                        break;

                                    case "註記":
                                        subjectScore.Comment = value;
                                        break;
                                    }
                                }
                            }
                            //subjectScoreInfo.AppendChild(newScore);
                            JHSemesterScoreRecord record = new JHSemesterScoreRecord();
                            record.SchoolYear   = info.SchoolYear;
                            record.Semester     = info.Semester;
                            record.RefStudentID = studentRec.ID;
                            //record.GradeYear = gradeyear;

                            if (!record.Subjects.ContainsKey(subjectScore.Subject))
                            {
                                record.Subjects.Add(subjectScore.Subject, subjectScore);
                            }
                            else
                            {
                                record.Subjects[subjectScore.Subject] = subjectScore;
                            }

                            insertList.Add(record);
                        }
                        //insertList.Add(new SmartSchool.Feature.Score.AddScore.InsertInfo(studentRec.StudentID, "" + sy, "" + se, gradeyear, "", subjectScoreInfo));
                    }
                    #endregion
                }
                #endregion


                Dictionary <string, JHSemesterScoreRecord> iList = new Dictionary <string, JHSemesterScoreRecord>();
                Dictionary <string, JHSemesterScoreRecord> uList = new Dictionary <string, JHSemesterScoreRecord>();

                foreach (var record in insertList)
                {
                    string key = record.RefStudentID + "_" + record.SchoolYear + "_" + record.Semester;
                    if (!iList.ContainsKey(key))
                    {
                        iList.Add(key, new JHSemesterScoreRecord());
                    }
                    JHSemesterScoreRecord newRecord = iList[key];
                    newRecord.RefStudentID = record.RefStudentID;
                    newRecord.SchoolYear   = record.SchoolYear;
                    newRecord.Semester     = record.Semester;

                    foreach (var subject in record.Subjects.Keys)
                    {
                        if (!newRecord.Subjects.ContainsKey(subject))
                        {
                            newRecord.Subjects.Add(subject, record.Subjects[subject]);
                        }
                    }
                }

                foreach (var record in updateList)
                {
                    string key = record.RefStudentID + "_" + record.SchoolYear + "_" + record.Semester;
                    if (!uList.ContainsKey(key))
                    {
                        uList.Add(key, record);
                    }
                    JHSemesterScoreRecord newRecord = uList[key];
                    newRecord.RefStudentID = record.RefStudentID;
                    newRecord.SchoolYear   = record.SchoolYear;
                    newRecord.Semester     = record.Semester;
                    newRecord.ID           = record.ID;

                    foreach (var subject in record.Subjects.Keys)
                    {
                        if (!newRecord.Subjects.ContainsKey(subject))
                        {
                            newRecord.Subjects.Add(subject, record.Subjects[subject]);
                        }
                    }
                }

                List <string> ids = new List <string>(id_Rows.Keys);
                Dictionary <string, JHSemesterScoreRecord> origs = new Dictionary <string, JHSemesterScoreRecord>();
                foreach (var record in JHSemesterScore.SelectByStudentIDs(ids))
                {
                    if (!origs.ContainsKey(record.ID))
                    {
                        origs.Add(record.ID, record);
                    }
                }
                foreach (var record in uList.Values)
                {
                    if (origs.ContainsKey(record.ID))
                    {
                        foreach (var domain in origs[record.ID].Domains.Keys)
                        {
                            if (!record.Domains.ContainsKey(domain))
                            {
                                record.Domains.Add(domain, origs[record.ID].Domains[domain]);
                            }
                        }
                    }
                }

                JHSemesterScore.Insert(new List <JHSemesterScoreRecord>(iList.Values));

                JHSemesterScore.Update(new List <JHSemesterScoreRecord>(uList.Values));

                FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入學期科目成績", "總共匯入" + (insertList.Count + updateList.Count) + "筆學期科目成績。");
                #endregion
            };
            wizard.ImportComplete += delegate
            {
                MsgBox.Show("匯入完成");
            };
        }
示例#24
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <ExcelRow> rows = new List <ExcelRow>();

            #region 整理成一行一行
            foreach (string studentID in Info.DuplicateAttendInfo.Keys)
            {
                JHStudentRecord student = JHStudent.SelectByID(studentID);
                foreach (string subject in Info.DuplicateAttendInfo[studentID].Keys)
                {
                    ExcelRow row = new ExcelRow(student);
                    row.SetSubject(subject);
                    row.SetCourceIDs(Info.DuplicateAttendInfo[studentID][subject]);

                    rows.Add(row);
                }
            }
            #endregion

            rows.Sort(delegate(ExcelRow x, ExcelRow y)
            {
                if (x.ClassName == y.ClassName)
                {
                    int seatNoX, seatNoY;
                    if (!int.TryParse(x.SeatNo, out seatNoX))
                    {
                        seatNoX = int.MaxValue;
                    }
                    if (!int.TryParse(y.SeatNo, out seatNoY))
                    {
                        seatNoY = int.MaxValue;
                    }

                    if (seatNoX == seatNoY)
                    {
                        return(JHSchool.Evaluation.Subject.CompareSubjectOrdinal(x.Subject, y.Subject));
                    }
                    else
                    {
                        return(seatNoX.CompareTo(seatNoY));
                    }
                }
                else
                {
                    return(x.ClassName.CompareTo(y.ClassName));
                }
            });

            Workbook template = new Workbook();
            template.Open(new MemoryStream(Properties.Resources.重覆修課學生清單));
            Range tempRow = template.Worksheets[0].Cells.CreateRange(2, 1, false);

            Workbook book = new Workbook();
            book.Open(new MemoryStream(Properties.Resources.重覆修課學生清單));

            Worksheet ws = book.Worksheets[0];

            #region 填入 Excel
            double total = rows.Count;
            double count = 0;

            ws.Cells[0, 0].PutValue(string.Format("{0} 學年度 第 {1} 學期 學生學期修課檢查表", SchoolYear, Semester));

            int rowIndex = 2;
            foreach (ExcelRow row in rows)
            {
                count++;

                int colIndex = 0;
                ws.Cells.CreateRange(rowIndex, 1, false).Copy(tempRow);

                ws.Cells[rowIndex, colIndex++].PutValue(row.ClassName);
                ws.Cells[rowIndex, colIndex++].PutValue(row.SeatNo);
                ws.Cells[rowIndex, colIndex++].PutValue(row.StudentNumber);
                ws.Cells[rowIndex, colIndex++].PutValue(row.StudentName);
                ws.Cells[rowIndex, colIndex++].PutValue(row.Subject);
                ws.Cells[rowIndex, colIndex++].PutValue(row.CourseNames);

                rowIndex++;

                Worker.ReportProgress((int)(count * 100 / total));
            }
            #endregion

            e.Result = book;
        }
示例#25
0
        protected override void OnSaveButtonClick(EventArgs e)
        {
            //// 當輸入沒有 鄰自動補
            //if (!string.IsNullOrEmpty(txtArea.Text))
            //{
            //    if (txtArea.Text.IndexOf("鄰") == -1)
            //        txtArea.Text += "鄰";
            //}

            // 檢查畫面儲存相對應
            if (_address_type == AddressType.Permanent)
            {
                _StudAddressRec.Permanent.ZipCode   = txtZipcode.Text;
                _StudAddressRec.Permanent.County    = cboCounty.Text;
                _StudAddressRec.Permanent.Town      = cboTown.Text;
                _StudAddressRec.Permanent.District  = txtDistrict.Text;
                _StudAddressRec.Permanent.Area      = txtArea.Text;
                _StudAddressRec.Permanent.Detail    = txtDetail.Text;
                _StudAddressRec.Permanent.Longitude = txtLongtitude.Text;
                _StudAddressRec.Permanent.Latitude  = txtLatitude.Text;
            }

            if (_address_type == AddressType.Mailing)
            {
                _StudAddressRec.Mailing.ZipCode   = txtZipcode.Text;
                _StudAddressRec.Mailing.County    = cboCounty.Text;
                _StudAddressRec.Mailing.Town      = cboTown.Text;
                _StudAddressRec.Mailing.District  = txtDistrict.Text;
                _StudAddressRec.Mailing.Area      = txtArea.Text;
                _StudAddressRec.Mailing.Detail    = txtDetail.Text;
                _StudAddressRec.Mailing.Longitude = txtLongtitude.Text;
                _StudAddressRec.Mailing.Latitude  = txtLatitude.Text;
            }

            if (_address_type == AddressType.Other)
            {
                _StudAddressRec.Address1.ZipCode   = txtZipcode.Text;
                _StudAddressRec.Address1.County    = cboCounty.Text;
                _StudAddressRec.Address1.Town      = cboTown.Text;
                _StudAddressRec.Address1.District  = txtDistrict.Text;
                _StudAddressRec.Address1.Area      = txtArea.Text;
                _StudAddressRec.Address1.Detail    = txtDetail.Text;
                _StudAddressRec.Address1.Longitude = txtLongtitude.Text;
                _StudAddressRec.Address1.Latitude  = txtLatitude.Text;
            }

            prlp.SetAfterSaveText("戶籍郵遞區號", _StudAddressRec.Permanent.ZipCode);
            prlp.SetAfterSaveText("戶籍縣市", _StudAddressRec.Permanent.County);
            prlp.SetAfterSaveText("戶籍鄉鎮市區", _StudAddressRec.Permanent.Town);
            prlp.SetAfterSaveText("戶籍村里", _StudAddressRec.Permanent.District);
            prlp.SetAfterSaveText("戶籍鄰", _StudAddressRec.Permanent.Area);
            prlp.SetAfterSaveText("戶籍其它地址", _StudAddressRec.Permanent.Detail);
            prlp.SetAfterSaveText("戶籍經度", _StudAddressRec.Permanent.Longitude);
            prlp.SetAfterSaveText("戶籍緯度", _StudAddressRec.Permanent.Latitude);
            prlp.SetAfterSaveText("聯絡郵遞區號", _StudAddressRec.Mailing.ZipCode);
            prlp.SetAfterSaveText("聯絡縣市", _StudAddressRec.Mailing.County);
            prlp.SetAfterSaveText("聯絡鄉鎮市區", _StudAddressRec.Mailing.Town);
            prlp.SetAfterSaveText("聯絡村里", _StudAddressRec.Mailing.District);
            prlp.SetAfterSaveText("聯絡鄰", _StudAddressRec.Mailing.Area);
            prlp.SetAfterSaveText("聯絡其它地址", _StudAddressRec.Mailing.Detail);
            prlp.SetAfterSaveText("聯絡經度", _StudAddressRec.Mailing.Longitude);
            prlp.SetAfterSaveText("聯絡緯度", _StudAddressRec.Mailing.Latitude);
            prlp.SetAfterSaveText("其它郵遞區號", _StudAddressRec.Address1.ZipCode);
            prlp.SetAfterSaveText("其它縣市", _StudAddressRec.Address1.County);
            prlp.SetAfterSaveText("其它鄉鎮市區", _StudAddressRec.Address1.Town);
            prlp.SetAfterSaveText("其它村里", _StudAddressRec.Address1.District);
            prlp.SetAfterSaveText("其它鄰", _StudAddressRec.Address1.Area);
            prlp.SetAfterSaveText("其它其它地址", _StudAddressRec.Address1.Detail);
            prlp.SetAfterSaveText("其它經度", _StudAddressRec.Address1.Longitude);
            prlp.SetAfterSaveText("其它緯度", _StudAddressRec.Address1.Latitude);

            _errors.Clear();
            JHAddress.Update(_StudAddressRec);
            prlp.SetActionBy("學籍", "學生地址資訊");
            prlp.SetAction("修改學生地址資訊");
            JHStudentRecord studRec = JHStudent.SelectByID(PrimaryKey);

            prlp.SetDescTitle("學生姓名:" + studRec.Name + ",學號:" + studRec.StudentNumber + ",");
            prlp.SaveLog("", "", "student", PrimaryKey);
            BindDataToForm();
        }
示例#26
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();
        }
示例#27
0
 public StudentData(JHStudentRecord student)
 {
     Student = student;
     Attends = new AttendData();
     Scores  = new ScoreData();
 }
示例#28
0
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            // 學生
            Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHStudentRecord>();

            // 畢業資訊
            Dictionary <string, JHLeaveInfoRecord> StudJHLeaveInfoRecordDic = new Dictionary <string, JHLeaveInfoRecord>();


            // 可匯入項目
            List <string> ImportItemList = new List <string>();

            ImportItemList.Add("畢業學年度");
            ImportItemList.Add("畢業資格");
            ImportItemList.Add("畢業證書字號");
            ImportItemList.Add("畢業相關訊息");

            // 取得可加入學生 TagName
            wizard.PackageLimit = 3000;
            wizard.ImportableFields.AddRange(ImportItemList);
            wizard.RequiredFields.AddRange();
            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                // 取得學生資料
                students = JHStudent.SelectByIDs(e.List).ToDictionary(x => x.ID);
                // 取得畢業資訊
                StudJHLeaveInfoRecordDic = JHLeaveIfno.SelectByStudentIDs(e.List).ToDictionary(x => x.RefStudentID);
            };

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

                // 檢查學生是否存在
                JHStudentRecord studRec = null;
                if (students.ContainsKey(e.Data.ID))
                {
                    studRec = students[e.Data.ID];
                }
                else
                {
                    e.ErrorMessage = "沒有這位學生" + e.Data.ID;
                    return;
                }
            };

            wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e)
            {
                Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >();
                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);
                }

                List <JHLeaveInfoRecord> UpdateList = new List <JHLeaveInfoRecord>();

                foreach (string id in id_Rows.Keys)
                {
                    if (StudJHLeaveInfoRecordDic.ContainsKey(id))
                    {
                        foreach (RowData data in id_Rows[id])
                        {
                            foreach (string field in e.ImportFields)
                            {
                                if (field == "畢業學年度")
                                {
                                    int SchoolYear;
                                    if (int.TryParse(data[field], out SchoolYear))
                                    {
                                        StudJHLeaveInfoRecordDic[id].SchoolYear = SchoolYear;
                                    }
                                    else
                                    {
                                        StudJHLeaveInfoRecordDic[id].SchoolYear = null;
                                    }
                                }

                                if (field == "畢業資格")
                                {
                                    StudJHLeaveInfoRecordDic[id].Reason = data[field];
                                }

                                if (field == "畢業證書字號")
                                {
                                    StudJHLeaveInfoRecordDic[id].DiplomaNumber = data[field];
                                }

                                if (field == "畢業相關訊息")
                                {
                                    StudJHLeaveInfoRecordDic[id].Memo = data[field];
                                }
                            }
                        }
                    }
                }

                UpdateList = StudJHLeaveInfoRecordDic.Values.ToList();

                try
                {
                    if (UpdateList.Count > 0)
                    {
                        Update(UpdateList);
                    }

                    JHSchool.PermRecLogProcess prlp = new JHSchool.PermRecLogProcess();
                    prlp.SaveLog("學生.匯入畢業資訊", "匯入學生畢業資訊", "匯入學生畢業資訊:共更新:" + UpdateList.Count + "筆資料");
                    JHSchool.Student.Instance.SyncAllBackground();
                    JHSchool.StudentTag.Instance.SyncAllBackground();
                    JHSchool.Data.JHStudent.RemoveAll();
                    JHSchool.Data.JHStudent.SelectAll();
                }
                catch (Exception ex) { }
            };
        }
示例#29
0
        void bkwNotPassComputer_DoWork(object sender, DoWorkEventArgs e)
        {
            string        fileName         = (string)((object[])e.Argument)[0];
            List <string> studentFieldList = (List <string>)((object[])e.Argument)[1];
            List <string> exportFieldList  = (List <string>)((object[])e.Argument)[2];
            Dictionary <ManualResetEvent, List <RowData> > Filler = (Dictionary <ManualResetEvent, List <RowData> >)((object[])e.Argument)[3];
            double   totleProgress   = 0.0;
            double   packageProgress = 100.0 / Filler.Count;
            Workbook report          = new Workbook();

            report.Worksheets[0].Name = _Title;
            ((BackgroundWorker)sender).ReportProgress(1, _Title + " 資料整理中...");
            int RowIndex = 0;
            int i        = 0;

            //填表頭
            for (; i < studentFieldList.Count; i++)
            {
                report.Worksheets[0].Cells[0, i].PutValue(studentFieldList[i]);
            }
            for (int j = 0; j < exportFieldList.Count; j++)
            {
                report.Worksheets[0].Cells[0, i + j].PutValue(exportFieldList[j]);
            }
            RowIndex = 1;
            foreach (ManualResetEvent eve in Filler.Keys)
            {
                eve.WaitOne();
                if (RowIndex <= 65535)
                {
                    double miniProgress = Filler[eve].Count == 0 ? 1 : packageProgress / Filler[eve].Count;
                    double miniTotle    = 0;
                    foreach (RowData row in Filler[eve])
                    {
                        JHStudentRecord student = null;
                        if (row.ID != "")
                        {
                            student = JHStudent.SelectByID(row.ID);
                        }

                        if (student != null)
                        {
                            if (RowIndex <= 65535)
                            {
                                i = 0;
                                for (; i < studentFieldList.Count; i++)
                                {
                                    switch (studentFieldList[i])
                                    {
                                    case "學生系統編號": report.Worksheets[0].Cells[RowIndex, i].PutValue(student.ID); break;

                                    case "學號": report.Worksheets[0].Cells[RowIndex, i].PutValue(student.StudentNumber); break;

                                    case "班級": report.Worksheets[0].Cells[RowIndex, i].PutValue(student.Class == null ? "" : student.Class.Name); break;

                                    case "座號": report.Worksheets[0].Cells[RowIndex, i].PutValue(student.SeatNo); break;

                                    case "姓名": report.Worksheets[0].Cells[RowIndex, i].PutValue(student.Name); break;

                                    default:
                                        break;
                                    }
                                }
                                for (int j = 0; j < exportFieldList.Count; j++)
                                {
                                    report.Worksheets[0].Cells[RowIndex, i + j].PutValue(row.ContainsKey(exportFieldList[j]) ? row[exportFieldList[j]] : "");
                                }
                            }
                            RowIndex++;
                        }
                        miniTotle += miniProgress;
                        ((BackgroundWorker)sender).ReportProgress((int)(totleProgress + miniTotle), _Title + " 處理中...");
                    }
                }
                totleProgress += packageProgress;
                ((BackgroundWorker)sender).ReportProgress((int)(totleProgress), _Title + " 處理中...");
            }
            for (int k = 0; k < studentFieldList.Count + exportFieldList.Count; k++)
            {
                report.Worksheets[0].AutoFitColumn(k, 0, 150);
            }
            report.Worksheets[0].FreezePanes(1, 0, 1, studentFieldList.Count + exportFieldList.Count);
            e.Result = new object[] { report, fileName, RowIndex > 65535 };
        }
示例#30
0
        /// <summary>
        /// 設定使用者介面
        /// </summary>
        public void SetupPresentation()
        {
            if (_initialize)
            {
                return;
            }

            programPlanCache = new Dictionary <string, JHProgramPlanRecord>();

            _classProgramPlanField.PreloadVariableBackground += delegate
            {
                foreach (JHProgramPlanRecord record in JHProgramPlan.SelectAll())
                {
                    if (!programPlanCache.ContainsKey(record.ID))
                    {
                        programPlanCache.Add(record.ID, record);
                    }
                }
            };

            _classProgramPlanField.GetVariable += delegate(object sender, GetVariableEventArgs e)
            {
                JHProgramPlanRecord record = GetProgramPlan(JHClass.SelectByID(e.Key));

                if (record != null)
                {
                    e.Value = record.Name;
                }
                else
                {
                    e.Value = "";
                }
            };
            K12.Presentation.NLDPanels.Class.AddListPaneField(_classProgramPlanField);

            _studentProgramPlanField.PreloadVariableBackground += delegate
            {
                foreach (JHProgramPlanRecord record in JHProgramPlan.SelectAll())
                {
                    if (!programPlanCache.ContainsKey(record.ID))
                    {
                        programPlanCache.Add(record.ID, record);
                    }
                }
            };

            _studentProgramPlanField.GetVariable += delegate(object sender, GetVariableEventArgs e)
            {
                JHStudentRecord     stu    = JHStudent.SelectByID(e.Key);
                JHProgramPlanRecord record = GetProgramPlan(stu);
                if (record != null)
                {
                    e.Value = string.IsNullOrEmpty(stu.OverrideProgramPlanID) ? record.Name : "(指定)" + record.Name;
                }
                else
                {
                    e.Value = "";
                }
            };
            K12.Presentation.NLDPanels.Student.AddListPaneField(_studentProgramPlanField);

            JHClass.AfterUpdate += delegate
            {
                _classProgramPlanField.Reload();
            };

            JHStudent.AfterUpdate += delegate
            {
                _studentProgramPlanField.Reload();
            };

            AddAssignProgramPlanButtons();

            _initialize = true;
        }
示例#31
0
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            //學生資訊 key: studentID
            Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHSchool.Data.JHStudentRecord>();
            //學生修課資訊 studentID -> List:SCAttendRecord
            Dictionary <string, List <JHSCAttendRecord> > scattends = new Dictionary <string, List <JHSchool.Data.JHSCAttendRecord> >();
            //學生修習的課程 courseID -> CourseRecord
            Dictionary <string, JHCourseRecord> courses = new Dictionary <string, JHSchool.Data.JHCourseRecord>();
            //所有課程(依學年度學期分開) schoolYear_semester -> (courseName -> CourseRecord)
            Dictionary <string, Dictionary <string, JHCourseRecord> > allcourses = new Dictionary <string, Dictionary <string, JHSchool.Data.JHCourseRecord> >();
            //學生修習的課程對應的評量設定細節
            Dictionary <string, List <HC.JHAEIncludeRecord> > courseAe = new Dictionary <string, List <HC.JHAEIncludeRecord> >();
            //學生的評量成績記錄
            Dictionary <string, List <HC.JHSCETakeRecord> > existSces = new Dictionary <string, List <HC.JHSCETakeRecord> >();
            //所有試別
            Dictionary <string, JHExamRecord> exams = new Dictionary <string, JHSchool.Data.JHExamRecord>();

            wizard.PackageLimit = 3000;
            wizard.ImportableFields.AddRange("學年度", "學期", "課程名稱", "評量名稱", "定期分數", "平時分數", "文字描述");
            wizard.RequiredFields.AddRange("學年度", "學期", "課程名稱", "評量名稱");

            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

                #region 取得目前評量成績記錄

                MultiThreadWorker <string> loader3 = new MultiThreadWorker <string>();
                loader3.MaxThreads     = 3;
                loader3.PackageSize    = 250;
                loader3.PackageWorker += delegate(object sender3, PackageWorkEventArgs <string> e3)
                {
                    foreach (HC.JHSCETakeRecord sce in JHSCETake.SelectByStudentIDs(e3.List).AsHCJHSCETakeRecords())
                    {
                        if (!existSces.ContainsKey(sce.RefSCAttendID))
                        {
                            existSces.Add(sce.RefSCAttendID, new List <HC.JHSCETakeRecord>());
                        }
                        existSces[sce.RefSCAttendID].Add(sce);
                    }
                };
                loader3.Run(e.List);
                #endregion

                #region 取得評量設定
                foreach (HC.JHAEIncludeRecord ae in JHAEInclude.SelectAll().AsHCJHAEIncludeRecords())
                {
                    if (!courseAe.ContainsKey(ae.RefAssessmentSetupID))
                    {
                        courseAe.Add(ae.RefAssessmentSetupID, new List <HC.JHAEIncludeRecord>());
                    }
                    courseAe[ae.RefAssessmentSetupID].Add(ae);
                }
                #endregion

                #region 取得試別
                foreach (JHExamRecord exam in JHExam.SelectAll())
                {
                    if (!exams.ContainsKey(exam.ID))
                    {
                        exams.Add(exam.ID, exam);
                    }
                }
                #endregion
            };

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

                #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 "定期分數":
                    case "平時分數":
                        if (value != "" && !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或數值");
                        }
                        break;

                    //case "努力程度":
                    //    if (value != "" && !int.TryParse(value, out i))
                    //    {
                    //        inputFormatPass &= false;
                    //        e.ErrorFields.Add(field, "必須填入空白或整數");
                    //    }
                    //    break;
                    case "文字描述":
                        break;
                    }
                }
                #endregion

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

                    string sy         = e.Data["學年度"];
                    string se         = e.Data["學期"];
                    string key        = e.Data.ID + "_" + sy + "_" + se;
                    string courseName = e.Data["課程名稱"];
                    string semsKey    = sy + "_" + se;
                    string examName   = e.Data["評量名稱"];

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

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

                    #region 檢查學生是否有修此課程 & 評量是否存在
                    bool attended = false;

                    JHCourseRecord attendCourse = null;
                    if (scattends.ContainsKey(e.Data.ID))
                    {
                        foreach (JHSCAttendRecord record in scattends[e.Data.ID])
                        {
                            //if (courses[record.RefCourseID].Name == courseName)
                            //    attendCourse = courses[record.RefCourseID];
                            bool HasRec = false;

                            // 當有學年度學期課程名稱相同
                            if (courses[record.RefCourseID].Name == courseName && courses[record.RefCourseID].SchoolYear.HasValue && courses[record.RefCourseID].Semester.HasValue)
                            {
                                if ((courses[record.RefCourseID].SchoolYear.Value.ToString().Trim() == sy.Trim()) && courses[record.RefCourseID].Semester.Value.ToString().Trim() == se.Trim())
                                {
                                    HasRec = true;
                                }
                            }
                            if (HasRec && courses.ContainsKey(record.RefCourseID))
                            {
                                attendCourse = courses[record.RefCourseID];
                            }
                        }
                    }
                    else //學生沒修半堂課
                    {
                    }

                    if (attendCourse == null && !noCourse)
                    {
                        if (!e.ErrorFields.ContainsKey("無修課記錄"))
                        {
                            e.ErrorFields.Add("無修課記錄", "學生在此學期並無修習此課程");
                        }
                    }
                    else if (attendCourse != null)
                    {
                        #region 驗證評量是否存在
                        if (string.IsNullOrEmpty(attendCourse.RefAssessmentSetupID))
                        {
                            if (!e.ErrorFields.ContainsKey("無評量設定"))
                            {
                                e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定");
                            }
                        }
                        else
                        {
                            if (!courseAe.ContainsKey(attendCourse.RefAssessmentSetupID))
                            {
                                if (!e.ErrorFields.ContainsKey("無評量設定"))
                                {
                                    e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定");
                                }
                            }
                            else
                            {
                                bool examValid = false;
                                foreach (HC.JHAEIncludeRecord ae in courseAe[attendCourse.RefAssessmentSetupID])
                                {
                                    if (!exams.ContainsKey(ae.RefExamID))
                                    {
                                        continue;
                                    }

                                    if (exams[ae.RefExamID].Name == examName)
                                    {
                                        examValid = true;
                                    }
                                }

                                if (!examValid)
                                {
                                    if (!e.ErrorFields.ContainsKey("評量名稱無效"))
                                    {
                                        e.ErrorFields.Add("評量名稱無效", "評量名稱(" + examName + ")不存在系統中");
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    #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 <HC.JHSCETakeRecord> insertList = new List <HC.JHSCETakeRecord>();
                List <HC.JHSCETakeRecord> updateList = new List <HC.JHSCETakeRecord>();

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

                    foreach (RowData data in id_Rows[id])
                    {
                        string examName   = data["評量名稱"];
                        string courseName = data["課程名稱"];
                        string SchoolYear = data["學年度"];
                        string Semester   = data["學期"];


                        if (!scattends.ContainsKey(id))
                        {
                            continue;
                        }

                        foreach (JHSCAttendRecord record in scattends[id])
                        {
                            if (!courses.ContainsKey(record.RefCourseID))
                            {
                                continue;
                            }
                            JHCourseRecord course = courses[record.RefCourseID];
                            //if (course.Name != courseName) continue;

                            HC.JHSCETakeRecord currentSCE = null;


                            string sy = "", ss = "";
                            if (course.SchoolYear.HasValue)
                            {
                                sy = course.SchoolYear.Value.ToString();
                            }
                            if (course.Semester.HasValue)
                            {
                                ss = course.Semester.Value.ToString();
                            }

                            if (SchoolYear != sy || Semester != ss || courseName != course.Name)
                            {
                                continue;
                            }


                            if (SchoolYear == sy && Semester == ss && course.Name == courseName)
                            {
                                if (existSces.ContainsKey(record.ID))
                                {
                                    foreach (HC.JHSCETakeRecord sce in existSces[record.ID])
                                    {
                                        if (!exams.ContainsKey(sce.RefExamID))
                                        {
                                            continue;
                                        }

                                        if (exams[sce.RefExamID].Name == examName)
                                        {
                                            currentSCE = sce;
                                        }
                                    }
                                }
                            }

                            if (currentSCE != null)
                            {
                                bool changed = false;

                                #region 填入資料
                                foreach (string field in e.ImportFields)
                                {
                                    string value = data[field];
                                    switch (field)
                                    {
                                    case "定期分數":
                                        if ("" + currentSCE.Score != value)
                                        {
                                            decimal d;
                                            if (decimal.TryParse(value, out d))
                                            {
                                                currentSCE.Score = d;
                                            }
                                            else
                                            {
                                                currentSCE.Score = null;
                                            }
                                            changed = true;
                                        }
                                        break;

                                    case "平時分數":
                                        if ("" + currentSCE.AssignmentScore != value)
                                        {
                                            decimal d;
                                            if (decimal.TryParse(value, out d))
                                            {
                                                currentSCE.AssignmentScore = d;
                                            }
                                            else
                                            {
                                                currentSCE.AssignmentScore = null;
                                            }
                                            changed = true;
                                        }
                                        break;

                                    //case "努力程度":
                                    //    if ("" + currentSCE.Effort != value)
                                    //    {
                                    //        int i;
                                    //        if (int.TryParse(value, out i))
                                    //            currentSCE.Effort = i;
                                    //        else
                                    //            currentSCE.Effort = null;
                                    //        changed = true;
                                    //    }
                                    //    break;
                                    case "文字描述":
                                        if (currentSCE.Text != value)
                                        {
                                            currentSCE.Text = value;
                                            changed         = true;
                                        }
                                        break;
                                    }
                                }
                                #endregion

                                if (changed)
                                {
                                    updateList.Add(currentSCE);
                                }
                            }
                            else
                            {
                                HC.JHSCETakeRecord newSCE = new HC.JHSCETakeRecord(new JHSCETakeRecord());
                                newSCE.RefStudentID  = id;
                                newSCE.RefSCAttendID = record.ID;
                                newSCE.RefCourseID   = record.RefCourseID;

                                foreach (JHExamRecord exam in exams.Values)
                                {
                                    if (exam.Name == examName)
                                    {
                                        newSCE.RefExamID = exam.ID;
                                    }
                                }

                                #region 填入資料
                                foreach (string field in e.ImportFields)
                                {
                                    string value = data[field];
                                    switch (field)
                                    {
                                    case "定期分數":
                                        if (value != "")
                                        {
                                            decimal d;
                                            if (decimal.TryParse(value, out d))
                                            {
                                                newSCE.Score = d;
                                            }
                                            else
                                            {
                                                newSCE.Score = null;
                                            }
                                        }
                                        else
                                        {
                                            newSCE.Score = null;
                                        }
                                        break;

                                    case "平時分數":
                                        if (value != "")
                                        {
                                            decimal d;
                                            if (decimal.TryParse(value, out d))
                                            {
                                                newSCE.AssignmentScore = d;
                                            }
                                            else
                                            {
                                                newSCE.AssignmentScore = null;
                                            }
                                        }
                                        else
                                        {
                                            newSCE.AssignmentScore = null;
                                        }
                                        break;

                                    case "文字描述":
                                        newSCE.Text = value;
                                        break;
                                    }
                                }
                                #endregion

                                if (newSCE.RefExamID != "")
                                {
                                    insertList.Add(newSCE);
                                }
                            }
                        }
                    }
                }

                try
                {
                    if (updateList.Count > 0)
                    {
                        #region 分批次兩路上傳
                        List <List <HC.JHSCETakeRecord> > updatePackages  = new List <List <HC.JHSCETakeRecord> >();
                        List <List <HC.JHSCETakeRecord> > updatePackages2 = new List <List <HC.JHSCETakeRecord> >();
                        {
                            List <HC.JHSCETakeRecord> package = null;
                            int count = 0;
                            foreach (HC.JHSCETakeRecord var in updateList)
                            {
                                if (count == 0)
                                {
                                    package = new List <HC.JHSCETakeRecord>(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 <HC.JHSCETakeRecord> > insertPackages  = new List <List <HC.JHSCETakeRecord> >();
                    List <List <HC.JHSCETakeRecord> > insertPackages2 = new List <List <HC.JHSCETakeRecord> >();
                    {
                        List <HC.JHSCETakeRecord> package = null;
                        int count = 0;
                        foreach (HC.JHSCETakeRecord var in insertList)
                        {
                            if (count == 0)
                            {
                                package = new List <HC.JHSCETakeRecord>(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
                }

                FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入評量成績", "總共匯入" + (insertList.Count + updateList.Count) + "筆評量成績。");
                #endregion
            };
        }
        public void SetStudent(JHStudentRecord student, List<SemesterHistoryItem> semesterHistoryList)
        {
            ClearField();
            // 學期歷程
            _semesterHistoryList = semesterHistoryList;
            JHParentRecord parent = JHParent.SelectByStudent(student);
            JHPhoneRecord phone = JHPhone.SelectByStudent(student);
            JHAddressRecord address = JHAddress.SelectByStudent(student);
            string tmpStr = "      ";

            JHLeaveInfoRecord leave = JHLeaveIfno.SelectByStudent(student);
            string number1 = string.Empty;
            string number2 = string.Empty;
            if (leave != null)
            {
                if (leave.Reason == "畢業")
                    number1 = leave.DiplomaNumber;
                else if (leave.Reason == "修業")
                    number2 = leave.DiplomaNumber;
            }

            string base64 = K12.Data.Photo.SelectGraduatePhoto(student.ID);

            _data["姓名"] = student.Name;
            _data["性別"] = student.Gender;
            _data["身分證字號"] = student.IDNumber;
            _data["學號"] = student.StudentNumber;
            _data["班級"] = (student.Class != null ? student.Class.Name : "");
            _data["座號"] = "" + student.SeatNo;
            _data["出生"] = DateConvert.ChineseUnitDate(DateConvert.CDate(student.Birthday.HasValue ? student.Birthday.Value.ToShortDateString() : ""));
            _data["出生地"] = student.BirthPlace;
            _data["家長或監護人"] = (parent != null) ? parent.Custodian.Name : "";
            _data["關係"] = (parent != null) ? parent.Custodian.Relationship : "";
            _data["聯絡電話"] = (phone != null) ? "" + phone.Contact : "";
            _data["戶籍電話"] = (phone != null) ? "" + phone.Permanent : "";
            _data["戶籍地址"] = (address != null) ? address.Permanent.ToString() : "";
            _data["通訊處"] = (address != null) ? address.Mailing.ToString() : "";
            _data["行動電話"] = (phone != null) ? "" + phone.Cell : "";
            _data["畢業證書字號"] = number1;
            _data["修業證明書字號"] = number2;
            _data["照片"] = base64;
            _data["簽呈"] = "承辦人員:" + Global.TransferName + tmpStr + "註冊組長:" + Global.RegManagerName + tmpStr + "教務主任:" + JHSchoolInfo.EduDirectorName +tmpStr+ "校長:" + JHSchoolInfo.ChancellorChineseName;
            // 處理服務學習時數
            if (Global._SLRDict.ContainsKey(student.ID))
            {
                foreach (SemesterHistoryItem shi in _semesterHistoryList)
                {
                    string key = shi.SchoolYear + "_" + shi.Semester;
                    if (Global._SLRDict[student.ID].ContainsKey(key))
                    {
                        string val = Global._SLRDict[student.ID][key];

                        if (shi.GradeYear == 1 && shi.Semester == 1)
                            _data["SLR1A"] = val;

                        if (shi.GradeYear == 1 && shi.Semester == 2)
                            _data["SLR1B"] = val;

                        if (shi.GradeYear == 2 && shi.Semester == 1)
                            _data["SLR2A"] = val;

                        if (shi.GradeYear == 2 && shi.Semester == 2)
                            _data["SLR2B"] = val;

                        if (shi.GradeYear == 3 && shi.Semester == 1)
                            _data["SLR3A"] = val;

                        if (shi.GradeYear == 3 && shi.Semester == 2)
                            _data["SLR3B"] = val;
                    }
                }
            }
            _builder.Document.MailMerge.Execute(GetFieldName(), GetFieldValue());
        }