예제 #1
0
        private void ChangeStudentsProgramPlanID(string id)
        {
            _logSaver.ClearBatch();

            List <JHStudentRecord> studentList = new List <JHStudentRecord>();

            foreach (var stu in JHStudent.SelectByIDs(K12.Presentation.NLDPanels.Student.SelectedSource))
            {
                stu.OverrideProgramPlanID = id;
                studentList.Add(stu);

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

                string desc = string.Empty;
                if (string.IsNullOrEmpty(id))
                {
                    desc = string.Format("學生「{0}」不指定課程規劃", s);
                }
                else
                {
                    desc = string.Format("學生「{0}」指定課程規劃為:{1}", s, ProgramPlan.Instance.Items[id].Name);
                }
                _logSaver.AddBatch("成績系統.課程規劃", "學生指定課程規劃", desc);
            }
            if (studentList.Count > 0)
            {
                JHStudent.Update(studentList);
                _logSaver.LogBatch();
            }
        }
예제 #2
0
        protected override void OnSaveButtonClick(EventArgs e)
        {
            SetFormDataToDALRec();

            // 檢查生日


            // 檢查性別
            List <string> checkGender = new List <string>();

            checkGender.Add("男");
            checkGender.Add("");
            checkGender.Add("女");

            if (!checkGender.Contains(cboGender.Text))
            {
                _errors.SetError(cboGender, "性別錯誤,請確認資料。");
                return;
            }

            DateTime dt;

            if (!string.IsNullOrEmpty(txtBirthDate.Text))
            {
                if (!DateTime.TryParse(txtBirthDate.Text, out dt))
                {
                    _errors.SetError(txtBirthDate, "日期錯誤,請確認資料。");
                    return;
                }
            }
            else
            {
                _StudRec.Birthday = null;
            }

            List <string> checkID  = new List <string>();
            List <string> checkSSN = new List <string>();


            foreach (JHStudentRecord studRec in JHStudent.SelectAll())
            {
                checkID.Add(studRec.SALoginName);
                checkSSN.Add(studRec.IDNumber);
            }
            if (!string.IsNullOrEmpty(_StudRec.SALoginName))
            {
                if (checkID.Contains(_StudRec.SALoginName))
                {
                    if (_defaultLoginID != _StudRec.SALoginName)
                    {
                        _errors.SetError(txtLoginID, "學生登入帳號重覆,請確認資料。");
                        return;
                    }
                }
            }
            if (!string.IsNullOrEmpty(_StudRec.IDNumber))
            {
                if (checkSSN.Contains(_StudRec.IDNumber))
                {
                    if (_defaultIDNumber != _StudRec.IDNumber)
                    {
                        _errors.SetError(txtSSN, "身分證號重覆,請確認資料。");
                        return;
                    }
                }
            }

            JHStudent.Update(_StudRec);
            SetAfterEditLog();
            Student.Instance.SyncDataBackground(PrimaryKey);
            _errors.Clear();
            //BindDataToForm();
        }
예제 #3
0
        protected override void OnSaveButtonClick(EventArgs e)
        {
            DateTime dt;

            //入學日期檢查
            if (!string.IsNullOrEmpty(txtEntranceDate.Text))
            {
                if (DateTime.TryParse(txtEntranceDate.Text, out dt))
                {
                    _errors.SetError(txtEntranceDate, string.Empty);
                }
                else
                {
                    _errors.SetError(txtEntranceDate, "入學日期錯誤,請確認資料。");
                    return;
                }
            }

            //離校日期檢查
            if (!string.IsNullOrEmpty(txtLeavingDate.Text))
            {
                if (DateTime.TryParse(txtLeavingDate.Text, out dt))
                {
                    _errors.SetError(txtLeavingDate, string.Empty);
                }
                else
                {
                    _errors.SetError(txtLeavingDate, "離校日期錯誤,請確認資料。");
                    return;
                }
            }

            SetFormDataToDALRec();

            // 檢查生日


            // 檢查性別
            List <string> checkGender = new List <string>();

            checkGender.Add("男");
            checkGender.Add("");
            checkGender.Add("女");

            if (!checkGender.Contains(cboGender.Text))
            {
                _errors.SetError(cboGender, "性別錯誤,請確認資料。");
                return;
            }

            //DateTime dt;

            if (!string.IsNullOrEmpty(txtBirthDate.Text))
            {
                if (!DateTime.TryParse(txtBirthDate.Text, out dt))
                {
                    _errors.SetError(txtBirthDate, "日期錯誤,請確認資料。");
                    return;
                }
            }
            else
            {
                _StudRec.Birthday = null;
            }

            List <string> checkID  = new List <string>();
            List <string> checkSSN = new List <string>();


            foreach (JHStudentRecord studRec in JHStudent.SelectAll())
            {
                checkID.Add(studRec.SALoginName);
                checkSSN.Add(studRec.IDNumber);
            }
            if (!string.IsNullOrEmpty(_StudRec.SALoginName))
            {
                if (checkID.Contains(_StudRec.SALoginName))
                {
                    if (_defaultLoginID != _StudRec.SALoginName)
                    {
                        _errors.SetError(txtLoginID, "學生登入帳號重覆,請確認資料。");
                        return;
                    }
                }
            }
            if (!string.IsNullOrEmpty(_StudRec.IDNumber))
            {
                if (checkSSN.Contains(_StudRec.IDNumber))
                {
                    if (_defaultIDNumber != _StudRec.IDNumber)
                    {
                        _errors.SetError(txtSSN, "身分證號重覆,請確認資料。");
                        return;
                    }
                }
            }

            //儲存延伸資料
            List <StudentRecord_Ext> list = new List <StudentRecord_Ext>();

            list.Add(_StudRec_Ext);
            if (!string.IsNullOrEmpty(_StudRec_Ext.UID))
            {
                tool._A.UpdateValues(list);
            }
            else
            {
                tool._A.InsertValues(list);
            }

            UpdateUDTData();

            eh(null, EventArgs.Empty);


            JHStudent.Update(_StudRec);
            SetAfterEditLog();
            JHSchool.Student.Instance.SyncDataBackground(PrimaryKey);
            _errors.Clear();
            //BindDataToForm();
        }
        public void ExecuteAutoCorrect(IEnumerable <string> EntityIDs)
        {
            if (!K12.Data.Utility.Utility.IsNullOrEmpty(CanAutoCorrectStudentIDs))
            {
                if (MsgBox.Show("自動修正將依照檢查結果學其狀態變更為『刪除』,強烈建議您務必將檢查結果匯出備份;是否進行自動修正?", "您是否要進行自動修正?", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    try
                    {
                        //取得要變更為『刪除』狀態的學生編號
                        List <string> AutoCorrectStudentIDs = K12.Data.Utility.Utility.IsNullOrEmpty(EntityIDs) ? CanAutoCorrectStudentIDs : EntityIDs.ToList();

                        //取得所有學生資料
                        List <JHStudentRecord> AllStudent = JHStudent.SelectAll();

                        //取得要變更為『刪除』狀態的學生
                        List <JHStudentRecord> Students = AllStudent.Where(x => AutoCorrectStudentIDs.Contains(x.ID)).ToList();

                        //取得『刪除』狀態的學生
                        List <JHStudentRecord> DeleteStudents = AllStudent.Where(x => x.Status == K12.Data.StudentRecord.StudentStatus.刪除).ToList();

                        #region 檢查『學號』在一般及刪除狀態重覆
                        List <string> RepeatStudentNumber = DeleteStudents.Select(x => x.StudentNumber).Intersect(Students.Select(x => x.StudentNumber)).ToList();

                        if (RepeatStudentNumber.Count > 0)
                        {
                            MsgBox.Show("以下學號" + string.Join(",", RepeatStudentNumber.ToArray()) + "在『一般』及『刪除』狀態重覆,無法變更狀態!");
                            return;
                        }
                        #endregion

                        #region 檢查『身分證號』在一般及刪除狀態重覆
                        List <string> RepeatIDNumber = DeleteStudents.Select(x => x.IDNumber).Intersect(Students.Select(x => x.IDNumber)).ToList();

                        if (RepeatIDNumber.Count > 0)
                        {
                            MsgBox.Show("以下身分證號" + string.Join(",", RepeatIDNumber.ToArray()) + "在『一般』及『刪除』狀態重覆,無法變更狀態!");
                            return;
                        }
                        #endregion

                        #region 檢查『登入帳號』在一般及刪除狀態重覆
                        List <string> RepeatLoginName = DeleteStudents.Select(x => x.SALoginName).Intersect(Students.Select(x => x.SALoginName)).ToList();

                        if (RepeatLoginName.Count > 0)
                        {
                            MsgBox.Show("以下登入帳號" + string.Join(",", RepeatLoginName.ToArray()) + "在『一般』及『刪除』狀態重覆,無法變更狀態!");
                            return;
                        }
                        #endregion

                        Students.ForEach(x => x.Status = K12.Data.StudentRecord.StudentStatus.刪除);

                        int SuccessCount = JHStudent.Update(Students);

                        FISCA.LogAgent.ApplicationLog.Log("資料合理性檢查.一般生轉出異動記錄檢查", "將一般生有轉出異動記錄學生狀態改為『刪除』", LogBuilder.ToString());
                    }
                    catch (Exception e)
                    {
                        SmartSchool.ErrorReporting.ReportingService.ReportException(e);

                        MsgBox.Show(e.Message);
                    }

                    MsgBox.Show("已自動修正完成!");
                }
            }
        }
예제 #5
0
        void wizard_ImportPackage(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e)
        {
            // 尋找主要Key來判斷,如果有學生系統編號先用系統編號,沒有使用學號,
            Dictionary <string, RowData> RowDataDict          = new Dictionary <string, RowData>();
            Dictionary <string, int>     chkSidDict           = new Dictionary <string, int>();
            Dictionary <string, string>  chkSnumDict          = new Dictionary <string, string>();
            List <JHStudentRecord>       InsertStudentRecList = new List <JHStudentRecord>();
            List <JHStudentRecord>       StudentRecAllList    = JHStudent.SelectAll();

            foreach (JHStudentRecord rec in StudentRecAllList)
            {
                chkSidDict.Add(rec.ID, 0);
                string key = rec.StudentNumber + rec.StatusStr;
                if (!chkSnumDict.ContainsKey(key))
                {
                    chkSnumDict.Add(key, rec.ID);
                }
            }

            // 先處理學生基本資料
            foreach (RowData Row in e.Items)
            {
                string StudentID = "";

                if (Row.ContainsKey("學生系統編號"))
                {
                    string id = Row["學生系統編號"].ToString();
                    if (chkSidDict.ContainsKey(id))
                    {
                        StudentID = id;
                    }
                }

                if (StudentID == "")
                {
                    string ssNum = "", snum = "";
                    if (Row.ContainsKey("學號"))
                    {
                        snum = Row["學號"].ToString();
                        string status = "一般";
                        if (Row.ContainsKey("狀態"))
                        {
                            if (Row["狀態"].ToString() != "")
                            {
                                status = Row["狀態"].ToString();
                            }
                        }
                        ssNum = snum + status;
                    }

                    if (chkSnumDict.ContainsKey(ssNum))
                    {
                        StudentID = chkSnumDict[ssNum];
                    }
                    else
                    {
                        // 新增
                        if (chkSnumDict.ContainsKey(snum + "一般"))
                        {
                            // 有重複
                        }
                        else
                        {
                            // 批次新增
                            JHStudentRecord newRec = new JHStudentRecord();
                            newRec.StudentNumber = snum;
                            newRec.Status        = StudentRecord.StudentStatus.一般;
                            if (Row.ContainsKey("姓名"))
                            {
                                newRec.Name = Row["姓名"].ToString();
                            }

                            InsertStudentRecList.Add(newRec);
                        }
                    }
                }
            }

            // 如有新學生處理新增學生
            if (InsertStudentRecList.Count > 0)
            {
                JHStudent.Insert(InsertStudentRecList);
            }

            // 再次建立索引
            Dictionary <string, JHStudentRecord> StudRecAllDict = new Dictionary <string, JHStudentRecord>();

            StudentRecAllList = JHStudent.SelectAll();
            chkSidDict.Clear();
            chkSnumDict.Clear();
            foreach (JHStudentRecord rec in StudentRecAllList)
            {
                chkSidDict.Add(rec.ID, 0);
                string key = rec.StudentNumber + rec.StatusStr;
                if (!chkSnumDict.ContainsKey(key))
                {
                    chkSnumDict.Add(key, rec.ID);
                }

                StudRecAllDict.Add(rec.ID, rec);
            }

            List <string> StudentIDList = new List <string>();

            //比對
            foreach (RowData Row in e.Items)
            {
                string StudentID = "";

                if (Row.ContainsKey("學生系統編號"))
                {
                    string id = Row["學生系統編號"].ToString();
                    if (chkSidDict.ContainsKey(id))
                    {
                        StudentID = id;
                    }
                }

                if (StudentID == "")
                {
                    string ssNum = "", snum = "";
                    if (Row.ContainsKey("學號"))
                    {
                        snum = Row["學號"].ToString();
                        string status = "一般";
                        if (Row.ContainsKey("狀態"))
                        {
                            if (Row["狀態"].ToString() != "")
                            {
                                status = Row["狀態"].ToString();
                            }
                        }
                        ssNum = snum + status;
                    }

                    if (chkSnumDict.ContainsKey(ssNum))
                    {
                        StudentID = chkSnumDict[ssNum];
                    }
                }

                if (!string.IsNullOrEmpty(StudentID))
                {
                    if (!RowDataDict.ContainsKey(StudentID))
                    {
                        RowDataDict.Add(StudentID, Row);
                    }

                    StudentIDList.Add(StudentID);
                }
            }
            // 取得學生基本、父母監護人、電話、地址、UDT
            List <JHStudentRecord> StudentRecordList = JHStudent.SelectByIDs(StudentIDList);
            Dictionary <string, JHStudentRecord> StudentRecordDict = new Dictionary <string, JHStudentRecord>();

            foreach (JHStudentRecord rec in StudentRecordList)
            {
                if (!StudentRecordDict.ContainsKey(rec.ID))
                {
                    StudentRecordDict.Add(rec.ID, rec);
                }
            }

            List <JHParentRecord> ParentRecordList = JHParent.SelectByStudentIDs(StudentIDList);
            Dictionary <string, JHParentRecord> ParentRecordDict = new Dictionary <string, JHParentRecord>();

            foreach (JHParentRecord rec in ParentRecordList)
            {
                if (!ParentRecordDict.ContainsKey(rec.RefStudentID))
                {
                    ParentRecordDict.Add(rec.RefStudentID, rec);
                }
            }

            List <JHPhoneRecord> PhoneRecordList = JHPhone.SelectByStudentIDs(StudentIDList);
            Dictionary <string, JHPhoneRecord> PhoneRecordDict = new Dictionary <string, JHPhoneRecord>();

            foreach (JHPhoneRecord rec in PhoneRecordList)
            {
                if (!PhoneRecordDict.ContainsKey(rec.RefStudentID))
                {
                    PhoneRecordDict.Add(rec.RefStudentID, rec);
                }
            }

            List <JHAddressRecord> AddressRecordList = JHAddress.SelectByStudentIDs(StudentIDList);
            Dictionary <string, JHAddressRecord> AddressRecordDict = new Dictionary <string, JHAddressRecord>();

            foreach (JHAddressRecord rec in AddressRecordList)
            {
                if (!AddressRecordDict.ContainsKey(rec.RefStudentID))
                {
                    AddressRecordDict.Add(rec.RefStudentID, rec);
                }
            }

            AccessHelper             accHepler             = new AccessHelper();
            string                   qry                   = "ref_student_id in('" + string.Join("','", StudentIDList.ToArray()) + "')";
            List <StudentRecord_Ext> StudentRecord_ExtList = accHepler.Select <StudentRecord_Ext>(qry);
            Dictionary <string, StudentRecord_Ext> StudentRecord_ExtDict = new Dictionary <string, StudentRecord_Ext> ();

            foreach (StudentRecord_Ext rec in StudentRecord_ExtList)
            {
                if (!StudentRecord_ExtDict.ContainsKey(rec.RefStudentID))
                {
                    StudentRecord_ExtDict.Add(rec.RefStudentID, rec);
                }
            }

            // 開始處理
            List <JHStudentRecord>      updateStudentRecList        = new List <JHStudentRecord>();
            List <JHParentRecord>       updateParentRecList         = new List <JHParentRecord>();
            List <JHPhoneRecord>        updatePhoneList             = new List <JHPhoneRecord>();
            List <JHAddressRecord>      updateAddressList           = new List <JHAddressRecord>();
            List <StudentRecord_Ext>    insertStudentRecord_ExtList = new List <StudentRecord_Ext>();
            List <StudentRecord_Ext>    updateStudentRecord_ExtList = new List <StudentRecord_Ext>();
            List <JHClassRecord>        classRecAllList             = JHClass.SelectAll();
            Dictionary <string, string> classNameIDDict             = new Dictionary <string, string>();

            foreach (JHClassRecord rec in classRecAllList)
            {
                classNameIDDict.Add(rec.Name, rec.ID);
            }

            StringBuilder sbLog = new StringBuilder();

            foreach (string StudentID in RowDataDict.Keys)
            {
                RowData rd = RowDataDict[StudentID];

                if (StudentRecordDict.ContainsKey(StudentID))
                {
                    string tt = "學生系統編號:" + StudentID + ",學號:" + StudentRecordDict[StudentID].StudentNumber;
                    if (StudentRecordDict[StudentID].Class != null)
                    {
                        tt += "班級:" + StudentRecordDict[StudentID].Class.Name;
                    }

                    if (StudentRecordDict[StudentID].SeatNo.HasValue)
                    {
                        tt += "座號:" + StudentRecordDict[StudentID].SeatNo.Value;
                    }

                    sbLog.AppendLine(tt);
                    if (rd.ContainsKey("學號"))
                    {
                        string value = rd["學號"].ToString();
                        if (StudentRecordDict[StudentID].StudentNumber != value)
                        {
                            sbLog.AppendLine(string.Format("學號由「{0}」改為「{1}」", StudentRecordDict[StudentID].StudentNumber, value));
                        }
                        StudentRecordDict[StudentID].StudentNumber = value;
                    }
                    if (rd.ContainsKey("班級"))
                    {
                        string value    = rd["班級"].ToString();
                        string oldValue = "";

                        if (StudentRecordDict[StudentID].Class != null)
                        {
                            oldValue = StudentRecordDict[StudentID].Class.Name;
                        }

                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("班級由「{0}」改為「{1}」", oldValue, value));
                        }

                        if (classNameIDDict.ContainsKey(value))
                        {
                            StudentRecordDict[StudentID].RefClassID = classNameIDDict[value];
                        }
                    }
                    if (rd.ContainsKey("座號"))
                    {
                        string value    = rd["座號"].ToString();
                        string oldValue = "";
                        if (StudentRecordDict[StudentID].SeatNo.HasValue)
                        {
                            oldValue = StudentRecordDict[StudentID].SeatNo.Value.ToString();
                        }

                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("座號由「{0}」改為「{1}」", oldValue, value));
                        }

                        StudentRecordDict[StudentID].SeatNo = null;
                        int i;
                        if (int.TryParse(value, out i))
                        {
                            StudentRecordDict[StudentID].SeatNo = i;
                        }
                    }
                    if (rd.ContainsKey("姓名"))
                    {
                        string value = rd["姓名"].ToString();
                        if (StudentRecordDict[StudentID].Name != value)
                        {
                            sbLog.AppendLine(string.Format("姓名由「{0}」改為「{1}」", StudentRecordDict[StudentID].Name, value));
                        }

                        StudentRecordDict[StudentID].Name = value;
                    }
                    if (rd.ContainsKey("身分證號"))
                    {
                        string value = rd["身分證號"].ToString();
                        if (StudentRecordDict[StudentID].IDNumber != value)
                        {
                            sbLog.AppendLine(string.Format("身分證號由「{0}」改為「{1}」", StudentRecordDict[StudentID].IDNumber, value));
                        }

                        StudentRecordDict[StudentID].IDNumber = value;
                    }
                    if (rd.ContainsKey("國籍"))
                    {
                        string value = rd["國籍"].ToString();
                        if (StudentRecordDict[StudentID].Nationality != value)
                        {
                            sbLog.AppendLine(string.Format("國籍由「{0}」改為「{1}」", StudentRecordDict[StudentID].Nationality, value));
                        }

                        StudentRecordDict[StudentID].Nationality = value;
                    }
                    if (rd.ContainsKey("出生地"))
                    {
                        string value = rd["出生地"].ToString();
                        if (StudentRecordDict[StudentID].BirthPlace != value)
                        {
                            sbLog.AppendLine(string.Format("出生地由「{0}」改為「{1}」", StudentRecordDict[StudentID].BirthPlace, value));
                        }

                        StudentRecordDict[StudentID].BirthPlace = value;
                    }
                    if (rd.ContainsKey("生日"))
                    {
                        string value    = rd["生日"].ToString();
                        string oldValue = "";
                        if (StudentRecordDict[StudentID].Birthday.HasValue)
                        {
                            oldValue = StudentRecordDict[StudentID].Birthday.Value.ToShortDateString();
                        }

                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("生日由「{0}」改為「{1}」", oldValue, value));
                        }

                        StudentRecordDict[StudentID].Birthday = null;
                        DateTime dt;
                        if (DateTime.TryParse(value, out dt))
                        {
                            StudentRecordDict[StudentID].Birthday = dt;
                        }
                    }
                    if (rd.ContainsKey("性別"))
                    {
                        string value = rd["性別"].ToString();
                        if (StudentRecordDict[StudentID].Gender != value)
                        {
                            sbLog.AppendLine(string.Format("性別由「{0}」改為「{1}」", StudentRecordDict[StudentID].Gender, value));
                        }
                        StudentRecordDict[StudentID].Gender = value;
                    }
                    if (rd.ContainsKey("英文姓名"))
                    {
                        string value = rd["英文姓名"].ToString();
                        if (StudentRecordDict[StudentID].EnglishName != value)
                        {
                            sbLog.AppendLine(string.Format("英文姓名由「{0}」改為「{1}」", StudentRecordDict[StudentID].EnglishName, value));
                        }
                        StudentRecordDict[StudentID].EnglishName = value;
                    }
                    if (rd.ContainsKey("登入帳號"))
                    {
                        string value = rd["登入帳號"].ToString();
                        if (StudentRecordDict[StudentID].SALoginName != value)
                        {
                            sbLog.AppendLine(string.Format("登入帳號由「{0}」改為「{1}」", StudentRecordDict[StudentID].SALoginName, value));
                        }
                        StudentRecordDict[StudentID].SALoginName = value;
                    }
                    if (rd.ContainsKey("狀態"))
                    {
                        string value    = rd["狀態"].ToString();
                        string oldValue = StudentRecordDict[StudentID].StatusStr;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("狀態由「{0}」改為「{1}」", oldValue, value));
                        }

                        switch (value)
                        {
                        case "":
                        case "一般": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.一般; break;

                        case "畢業或離校": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.畢業或離校; break;

                        case "休學": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.休學; break;

                        case "輟學": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.輟學; break;

                        case "刪除": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.刪除; break;
                        }
                    }
                }
                // 和班級走
                //if (rd.ContainsKey("年級") && StudentRecordDict.ContainsKey(StudentID)) { string value = rd["年級"].ToString(); }

                StudentRecord_Ext exRec = null;

                bool isNewExRec = false;
                if (StudentRecord_ExtDict.ContainsKey(StudentID))
                {
                    exRec = StudentRecord_ExtDict[StudentID];
                }
                else
                {
                    exRec = new StudentRecord_Ext();
                    exRec.RefStudentID = StudentID;
                    isNewExRec         = true;
                }

                if (rd.ContainsKey("英文別名"))
                {
                    string value = rd["英文別名"].ToString();
                    if (exRec.Nickname != value)
                    {
                        sbLog.AppendLine(string.Format("英文別名由「{0}」改為「{1}」", exRec.Nickname, value));
                    }
                    exRec.Nickname = value;
                }
                if (rd.ContainsKey("居留證號"))
                {
                    string value = rd["居留證號"].ToString();
                    if (exRec.PassportNumber != value)
                    {
                        sbLog.AppendLine(string.Format("居留證號由「{0}」改為「{1}」", exRec.PassportNumber, value));
                    }
                    exRec.PassportNumber = value;
                }
                if (rd.ContainsKey("GivenName"))
                {
                    string value = rd["GivenName"].ToString();
                    if (exRec.GivenName != value)
                    {
                        sbLog.AppendLine(string.Format("GivenName由「{0}」改為「{1}」", exRec.GivenName, value));
                    }

                    exRec.GivenName = value;
                }
                if (rd.ContainsKey("MiddleName"))
                {
                    string value = rd["MiddleName"].ToString();
                    if (exRec.MiddleName != value)
                    {
                        sbLog.AppendLine(string.Format("MiddleName由「{0}」改為「{1}」", exRec.MiddleName, value));
                    }

                    exRec.MiddleName = value;
                }
                if (rd.ContainsKey("FamilyName"))
                {
                    string value = rd["FamilyName"].ToString();
                    if (exRec.FamilyName != value)
                    {
                        sbLog.AppendLine(string.Format("FamilyName由「{0}」改為「{1}」", exRec.FamilyName, value));
                    }

                    exRec.FamilyName = value;
                }
                if (rd.ContainsKey("入學日期"))
                {
                    string value    = rd["入學日期"].ToString();
                    string oldValue = "";
                    if (exRec.EntranceDate.HasValue)
                    {
                        oldValue = exRec.EntranceDate.Value.ToShortDateString();
                    }
                    exRec.EntranceDate = null;
                    if (oldValue != value)
                    {
                        sbLog.AppendLine(string.Format("入學日期由「{0}」改為「{1}」", oldValue, value));
                    }

                    DateTime dt1;
                    if (DateTime.TryParse(value, out dt1))
                    {
                        exRec.EntranceDate = dt1;
                    }
                }
                if (rd.ContainsKey("畢業日期"))
                {
                    string value    = rd["畢業日期"].ToString();
                    string oldValue = "";
                    if (exRec.LeavingDate.HasValue)
                    {
                        oldValue = exRec.LeavingDate.Value.ToShortDateString();
                    }

                    if (oldValue != value)
                    {
                        sbLog.AppendLine(string.Format("畢業日期由「{0}」改為「{1}」", oldValue, value));
                    }

                    exRec.LeavingDate = null;
                    DateTime dt2;
                    if (DateTime.TryParse(value, out dt2))
                    {
                        exRec.LeavingDate = dt2;
                    }
                }


                if (isNewExRec)
                {
                    insertStudentRecord_ExtList.Add(exRec);
                }
                else
                {
                    updateStudentRecord_ExtList.Add(exRec);
                }

                if (ParentRecordDict.ContainsKey(StudentID))
                {
                    if (rd.ContainsKey("父親姓名"))
                    {
                        string value    = rd["父親姓名"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Father.Name;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("父親姓名由「{0}」改為「{1}」", oldValue, value));
                        }
                        ParentRecordDict[StudentID].Father.Name = value;
                    }
                    if (rd.ContainsKey("父親學歷"))
                    {
                        string value    = rd["父親學歷"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Father.EducationDegree;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("父親學歷由「{0}」改為「{1}」", oldValue, value));
                        }
                        ParentRecordDict[StudentID].Father.EducationDegree = value;
                    }
                    if (rd.ContainsKey("父親職業"))
                    {
                        string value    = rd["父親職業"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Father.Job;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("父親職業由「{0}」改為「{1}」", oldValue, value));
                        }
                        ParentRecordDict[StudentID].Father.Job = value;
                    }
                    if (rd.ContainsKey("父親電話"))
                    {
                        string value    = rd["父親電話"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Father.Phone;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("父親電話由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Father.Phone = value;
                    }

                    if (rd.ContainsKey("父親電子郵件"))
                    {
                        string value    = rd["父親電子郵件"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Father.EMail;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("父親電子郵件由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Father.EMail = value;
                    }


                    if (rd.ContainsKey("母親姓名"))
                    {
                        string value    = rd["母親姓名"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Mother.Name;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("母親姓名由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Mother.Name = value;
                    }
                    if (rd.ContainsKey("母親學歷"))
                    {
                        string value    = rd["母親學歷"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Mother.EducationDegree;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("母親學歷由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Mother.EducationDegree = value;
                    }
                    if (rd.ContainsKey("母親職業"))
                    {
                        string value    = rd["母親職業"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Mother.Job;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("母親職業由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Mother.Job = value;
                    }
                    if (rd.ContainsKey("母親電話"))
                    {
                        string value    = rd["母親電話"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Mother.Phone;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("母親電話由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Mother.Phone = value;
                    }

                    if (rd.ContainsKey("母親電子郵件"))
                    {
                        string value    = rd["母親電子郵件"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Mother.EMail;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("母親電子郵件由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Mother.EMail = value;
                    }


                    if (rd.ContainsKey("監護人姓名"))
                    {
                        string value    = rd["監護人姓名"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Custodian.Name;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("監護人姓名由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Custodian.Name = value;
                    }
                    if (rd.ContainsKey("監護人電話"))
                    {
                        string value    = rd["監護人電話"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Custodian.Phone;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("監護人電話由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Custodian.Phone = value;
                    }

                    if (rd.ContainsKey("監護人電子郵件"))
                    {
                        string value    = rd["監護人電子郵件"].ToString();
                        string oldValue = ParentRecordDict[StudentID].Custodian.EMail;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("監護人電子郵件由「{0}」改為「{1}」", oldValue, value));
                        }

                        ParentRecordDict[StudentID].Custodian.EMail = value;
                    }


                    updateParentRecList.Add(ParentRecordDict[StudentID]);
                }

                if (PhoneRecordDict.ContainsKey(StudentID))
                {
                    if (rd.ContainsKey("戶籍電話"))
                    {
                        string value    = rd["戶籍電話"].ToString();
                        string oldValue = PhoneRecordDict[StudentID].Permanent;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("戶籍電話由「{0}」改為「{1}」", oldValue, value));
                        }
                        PhoneRecordDict[StudentID].Permanent = value;
                    }
                    if (rd.ContainsKey("聯絡電話"))
                    {
                        string value    = rd["聯絡電話"].ToString();
                        string oldValue = PhoneRecordDict[StudentID].Contact;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("聯絡電話由「{0}」改為「{1}」", oldValue, value));
                        }

                        PhoneRecordDict[StudentID].Contact = value;
                    }
                    if (rd.ContainsKey("行動電話"))
                    {
                        string value    = rd["行動電話"].ToString();
                        string oldValue = PhoneRecordDict[StudentID].Cell;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("行動電話由「{0}」改為「{1}」", oldValue, value));
                        }

                        PhoneRecordDict[StudentID].Cell = value;
                    }
                    if (rd.ContainsKey("其它電話1"))
                    {
                        string value    = rd["其它電話1"].ToString();
                        string oldValue = PhoneRecordDict[StudentID].Phone1;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("其它電話1由「{0}」改為「{1}」", oldValue, value));
                        }

                        PhoneRecordDict[StudentID].Phone1 = value;
                    }
                    updatePhoneList.Add(PhoneRecordDict[StudentID]);
                }

                if (AddressRecordDict.ContainsKey(StudentID))
                {
                    if (rd.ContainsKey("戶籍:郵遞區號"))
                    {
                        string value    = rd["戶籍:郵遞區號"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Permanent.ZipCode;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("戶籍:郵遞區號由「{0}」改為「{1}」", oldValue, value));
                        }
                        AddressRecordDict[StudentID].Permanent.ZipCode = value;
                    }
                    if (rd.ContainsKey("戶籍:縣市"))
                    {
                        string value    = rd["戶籍:縣市"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Permanent.County;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("戶籍:縣市由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Permanent.County = value;
                    }
                    if (rd.ContainsKey("戶籍:鄉鎮市區"))
                    {
                        string value    = rd["戶籍:鄉鎮市區"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Permanent.Town;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("戶籍:鄉鎮市區由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Permanent.Town = value;
                    }
                    if (rd.ContainsKey("戶籍:村里"))
                    {
                        string value    = rd["戶籍:村里"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Permanent.District;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("戶籍:村里由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Permanent.District = value;
                    }
                    if (rd.ContainsKey("戶籍:鄰"))
                    {
                        string value    = rd["戶籍:鄰"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Permanent.Area;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("戶籍:鄰由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Permanent.Area = value;
                    }
                    if (rd.ContainsKey("戶籍:其他"))
                    {
                        string value    = rd["戶籍:其他"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Permanent.Detail;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("戶籍:其他由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Permanent.Detail = value;
                    }
                    if (rd.ContainsKey("聯絡:郵遞區號"))
                    {
                        string value    = rd["聯絡:郵遞區號"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Mailing.ZipCode;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("聯絡:郵遞區號由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Mailing.ZipCode = value;
                    }
                    if (rd.ContainsKey("聯絡:縣市"))
                    {
                        string value    = rd["聯絡:縣市"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Mailing.County;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("聯絡:縣市由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Mailing.County = value;
                    }
                    if (rd.ContainsKey("聯絡:鄉鎮市區"))
                    {
                        string value    = rd["聯絡:鄉鎮市區"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Mailing.Town;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("聯絡:鄉鎮市區由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Mailing.Town = value;
                    }
                    if (rd.ContainsKey("聯絡:村里"))
                    {
                        string value    = rd["聯絡:村里"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Mailing.District;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("聯絡:村里由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Mailing.District = value;
                    }
                    if (rd.ContainsKey("聯絡:鄰"))
                    {
                        string value    = rd["聯絡:鄰"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Mailing.Area;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("聯絡:鄰由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Mailing.Area = value;
                    }
                    if (rd.ContainsKey("聯絡:其他"))
                    {
                        string value    = rd["聯絡:其他"].ToString();
                        string oldValue = AddressRecordDict[StudentID].Mailing.Detail;
                        if (oldValue != value)
                        {
                            sbLog.AppendLine(string.Format("聯絡:其他由「{0}」改為「{1}」", oldValue, value));
                        }

                        AddressRecordDict[StudentID].Mailing.Detail = value;
                    }
                    sbLog.AppendLine();
                    updateAddressList.Add(AddressRecordDict[StudentID]);
                }
            }

            // 處理學生資料
            foreach (string key in StudentRecordDict.Keys)
            {
                updateStudentRecList.Add(StudentRecordDict[key]);
            }

            if (updateStudentRecList.Count > 0)
            {
                JHStudent.Update(updateStudentRecList);
            }

            if (updateParentRecList.Count > 0)
            {
                JHParent.Update(updateParentRecList);
            }

            if (updatePhoneList.Count > 0)
            {
                JHPhone.Update(updatePhoneList);
            }

            if (updateAddressList.Count > 0)
            {
                JHAddress.Update(updateAddressList);
            }

            if (insertStudentRecord_ExtList.Count > 0)
            {
                insertStudentRecord_ExtList.SaveAll();
            }

            if (updateStudentRecord_ExtList.Count > 0)
            {
                updateStudentRecord_ExtList.SaveAll();
            }

            FISCA.LogAgent.ApplicationLog.Log("匯入學生基本資料(New)", "匯入", sbLog.ToString());

            // 同步
            JHSchool.Student.Instance.SyncAllBackground();
            JHSchool.Data.JHStudent.RemoveAll();
            JHSchool.Data.JHStudent.SelectAll();
        }
        protected override void OnSaveButtonClick(EventArgs e)
        {
            Errors.Clear();

            objStudent = JHSchool.Data.JHStudent.SelectByID(PrimaryKey);


            // 檢查學號是否重複
            if (txtStudentNumber.Text != this._DefaultStudNum)
            {
                // 判斷是否是空
                if (string.IsNullOrEmpty(txtStudentNumber.Text))
                {
                    objStudent.StudentNumber = "";
                }
                else
                {
                    // 取得目前學生狀態
                    JHStudentRecord.StudentStatus studtStatus = JHSchool.Data.JHStudent.SelectByID(PrimaryKey).Status;

                    List <string> checkData = new List <string>();
                    // 同狀態下學號不能重複
                    foreach (JHSchool.Data.JHStudentRecord studRec in JHSchool.Data.JHStudent.SelectAll())
                    {
                        if (studRec.Status == studtStatus)
                        {
                            checkData.Add(studRec.StudentNumber);
                        }
                    }

                    if (checkData.Contains(txtStudentNumber.Text))
                    {
                        Errors.SetError(txtStudentNumber, "學號重複!");
                        return;
                    }
                    objStudent.StudentNumber = txtStudentNumber.Text;
                }
            }


            JHStudent.Update(objStudent);

            SaveButtonVisible   = false;
            CancelButtonVisible = false;

            prlp.SetAfterSaveText("班級", lblClassName.Text);
            prlp.SetAfterSaveText("座號", lblSeatNo.Text);
            prlp.SetAfterSaveText("學號", txtStudentNumber.Text);
            prlp.SetActionBy("學籍", "學生班級資訊");
            prlp.SetAction("修改學生班級資訊");
            prlp.SetDescTitle("學生姓名:" + objStudent.Name + ",學號:" + objStudent.StudentNumber + ",");

            prlp.SaveLog("", "", "student", PrimaryKey);


            this._DefaultClassName = lblClassName.Text;
            this._DefaultSeatNo    = lblSeatNo.Text;
            this._DefaultStudNum   = txtStudentNumber.Text;
            //      Student.Instance.SyncDataBackground(PrimaryKey);

            reloadChkdData();
        }