public UserControl CreateByUpdateType(string FormUpdateType)
        {
            // 001-新生
            List <XElement> UpdateCodeElms = (from elm in _UpdateCode.Elements("異動") where elm.Element("分類").Value == FormUpdateType select elm).ToList();

            if (_StudUpdateRec == null)
            {
                _StudUpdateRec = _DefStudUpdateRec;
            }

            // 日校
            if (FormUpdateType == "學籍異動")
            {
                return(new UpdateRecordInfo01(_StudUpdateRec, _prlp, UpdateCodeElms));
            }
            else if (FormUpdateType == "轉入異動")
            {
                return(new UpdateRecordInfo02(_StudUpdateRec, _prlp, UpdateCodeElms));
            }
            else if (FormUpdateType == "新生異動")
            {
                return(new UpdateRecordInfo03(_StudUpdateRec, _prlp, UpdateCodeElms));
            }
            else if (FormUpdateType == "畢業異動")
            {
                return(new UpdateRecordInfo04(_StudUpdateRec, _prlp, UpdateCodeElms));
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// 畢業異動
        /// </summary>
        public UpdateRecordInfo04(SHUpdateRecordRecord UpdateRec, PermRecLogProcess prlp, List <XElement> UpdateCodeElms, bool isInsert)
        {
            InitializeComponent();
            cbxGender.Items.Add("男");
            cbxGender.Items.Add("女");
            cbxClass.DropDownWidth = 300;
            _UpdateRec             = UpdateRec;
            _UpdateCodeElms        = UpdateCodeElms;
            _prlp = prlp;

            _UpdateCoodeList = (from x in _UpdateCodeElms select x.Element("代號").Value + " " + x.Element("原因及事項").Value).ToList();
            _DeptList        = SHDepartment.SelectAll();
            _faldn           = new UpdateRecordModule_KHSH_D.Utility.FormAndLogDataManager(_prlp);
            _epUpdateCode    = new ErrorProvider();
            _UCodeDict       = Utility.UITool.ConvertUpdateCodeDescDict(_UpdateCodeElms);

            if (isInsert)
            {
                //當畢業證書字號沒有值取得SHLeaveInfoRecord畢業證書字號
                if (string.IsNullOrEmpty(_UpdateRec.GraduateCertificateNumber))
                {
                    SHLeaveInfoRecord lvr = SHLeaveInfo.SelectByStudentID(_UpdateRec.StudentID);
                    _UpdateRec.GraduateCertificateNumber = lvr.DiplomaNumber;
                }

                if (string.IsNullOrEmpty(_UpdateRec.ExpectGraduateSchoolYear))
                {
                    SHLeaveInfoRecord shl = SHLeaveInfo.SelectByStudentID(_UpdateRec.StudentID);
                    if (shl.SchoolYear.HasValue)
                    {
                        _UpdateRec.ExpectGraduateSchoolYear = shl.SchoolYear.Value.ToString();
                    }
                }
            }

            // 載入資料
            cbxUpdateCode     = _faldn.SetFormData(_UpdateRec.UpdateCode, cbxUpdateCode, "異動代碼");
            txtDesc           = _faldn.SetFormData(_UpdateRec.UpdateDescription, txtDesc, "原因及事項");
            dtUpdateDate      = _faldn.SetFormData(_UpdateRec.UpdateDate, dtUpdateDate, "異動日期");
            txtMemo           = _faldn.SetFormData(_UpdateRec.Comment, txtMemo, "備註");
            cbxDept           = _faldn.SetFormData(_UpdateRec.Department, cbxDept, "科別");
            cbxClass          = _faldn.SetFormData(_UpdateRec.ClassType, cbxClass, "班別");
            txtName           = _faldn.SetFormData(_UpdateRec.StudentName, txtName, "姓名");
            txtStudentNumber  = _faldn.SetFormData(_UpdateRec.StudentNumber, txtStudentNumber, "學號");
            txtIDNumber       = _faldn.SetFormData(_UpdateRec.IDNumber, txtIDNumber, "身分證字號");
            dtBirthday        = _faldn.SetFormData(_UpdateRec.Birthdate, dtBirthday, "生日");
            txtIDNumber1      = _faldn.SetFormData(_UpdateRec.IDNumberComment, txtIDNumber1, "註1");
            cbxGender         = _faldn.SetFormData(_UpdateRec.Gender, cbxGender, "性別");
            dtLastUpdateDate  = _faldn.SetFormData(_UpdateRec.LastADDate, dtLastUpdateDate, "備查日期");
            txtLastDocNo      = _faldn.SetFormData(_UpdateRec.LastADNumber, txtLastDocNo, "備查文號");
            txtLastUpdateCode = _faldn.SetFormData(_UpdateRec.LastUpdateCode, txtLastUpdateCode, "最後異動代號");
            txtGradeDocNo     = _faldn.SetFormData(_UpdateRec.GraduateCertificateNumber, txtGradeDocNo, "畢業證書字號");
            dtADDate          = _faldn.SetFormData(_UpdateRec.ADDate, dtADDate, "核准日期");
            txtADDocNo        = _faldn.SetFormData(_UpdateRec.ADNumber, txtADDocNo, "核准文號");
            txtSpecial        = _faldn.SetFormData(_UpdateRec.SpecialStatus, txtSpecial, "特殊身分代碼");
            txtSHSchoolYear   = _faldn.SetFormData(_UpdateRec.ExpectGraduateSchoolYear, txtSHSchoolYear, "應畢業學年度");
        }
Exemple #3
0
        // 修改異動紀錄
        private void EditStudentUpdateRecord()
        {
            SHUpdateRecordRecord objUpdate = lstRecord.SelectedItems[0].Tag as SHUpdateRecordRecord;

            UpdateRecordItemForm form = new UpdateRecordItemForm(UpdateRecordItemForm.actMode.修改, objUpdate, PrimaryKey);

            if (form._chkLoadForm)
            {
                form.ShowDialog();
            }
        }
        /// <summary>
        /// 畢業異動
        /// </summary>
        public UpdateRecordInfo04(SHUpdateRecordRecord UpdateRec, PermRecLogProcess prlp, List<XElement> UpdateCodeElms)
        {
            InitializeComponent();
            cbxGender.Items.Add("男");
            cbxGender.Items.Add("女");

            _UpdateRec = UpdateRec;
            _UpdateCodeElms = UpdateCodeElms;
            _prlp = prlp;

            _UpdateCoodeList = (from x in _UpdateCodeElms select x.Element("代號").Value + " " + x.Element("原因及事項").Value).ToList();
            _DeptList = SHDepartment.SelectAll();
            _faldn = new UpdateRecordModule_SH_D.Utility.FormAndLogDataManager(_prlp);
            _epUpdateCode = new ErrorProvider();
            _UCodeDict = Utility.UITool.ConvertUpdateCodeDescDict(_UpdateCodeElms);

            //當畢業證書字號沒有值取得SHLeaveInfoRecord畢業證書字號
            if (string.IsNullOrEmpty(_UpdateRec.GraduateCertificateNumber))
            {
                SHLeaveInfoRecord lvr = SHLeaveInfo.SelectByStudentID(_UpdateRec.StudentID);
                _UpdateRec.GraduateCertificateNumber = lvr.DiplomaNumber;
            }

            if (string.IsNullOrEmpty(_UpdateRec.ExpectGraduateSchoolYear))
            {
                SHLeaveInfoRecord shl = SHLeaveInfo.SelectByStudentID(_UpdateRec.StudentID);
                if(shl.SchoolYear.HasValue)
                    _UpdateRec.ExpectGraduateSchoolYear = shl.SchoolYear.Value.ToString();
            }

            // 載入資料
            cbxUpdateCode = _faldn.SetFormData(_UpdateRec.UpdateCode, cbxUpdateCode, "異動代碼");
            txtDesc = _faldn.SetFormData(_UpdateRec.UpdateDescription, txtDesc, "原因及事項");
            dtUpdateDate = _faldn.SetFormData(_UpdateRec.UpdateDate, dtUpdateDate, "異動日期");
            txtMemo = _faldn.SetFormData(_UpdateRec.Comment, txtMemo, "備註");
            cbxDept = _faldn.SetFormData(_UpdateRec.Department, cbxDept, "科別");
            cbxClass = _faldn.SetFormData(_UpdateRec.ClassType, cbxClass, "班別");
            txtName = _faldn.SetFormData(_UpdateRec.StudentName, txtName, "姓名");
            txtStudentNumber = _faldn.SetFormData(_UpdateRec.StudentNumber, txtStudentNumber, "學號");
            txtIDNumber = _faldn.SetFormData(_UpdateRec.IDNumber, txtIDNumber, "身分證字號");
            dtBirthday = _faldn.SetFormData(_UpdateRec.Birthdate, dtBirthday, "生日");
            txtIDNumber1 = _faldn.SetFormData(_UpdateRec.IDNumberComment, txtIDNumber1, "註1");
            cbxGender = _faldn.SetFormData(_UpdateRec.Gender, cbxGender, "性別");
            dtLastUpdateDate = _faldn.SetFormData(_UpdateRec.LastADDate, dtLastUpdateDate, "備查日期");
            txtLastDocNo = _faldn.SetFormData(_UpdateRec.LastADNumber, txtLastDocNo, "備查文號");
            txtLastUpdateCode = _faldn.SetFormData(_UpdateRec.LastUpdateCode, txtLastUpdateCode, "最後異動代號");
            txtGradeDocNo = _faldn.SetFormData(_UpdateRec.GraduateCertificateNumber, txtGradeDocNo, "畢業證書字號");
            dtADDate = _faldn.SetFormData(_UpdateRec.ADDate, dtADDate, "核准日期");
            txtADDocNo = _faldn.SetFormData(_UpdateRec.ADNumber, txtADDocNo, "核准文號");
            txtSpecial = _faldn.SetFormData(_UpdateRec.SpecialStatus, txtSpecial, "特殊身分代碼");
            txtSHSchoolYear = _faldn.SetFormData(_UpdateRec.ExpectGraduateSchoolYear, txtSHSchoolYear, "應畢業學年度");
        }
Exemple #5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // 初始化資料
            SHUpdateRecordRecord updateRec = new SHUpdateRecordRecord();
            // 取得學生ID
            // 先清DAL Cache
            List <string> rmIDs = new List <string> ();

            rmIDs.Add(PrimaryKey);
            SHStudent.RemoveByIDs(rmIDs);
            SHStudentRecord studRec = SHStudent.SelectByID(PrimaryKey);

            // 取得最後一筆異動資料,備查使用。
            List <SHUpdateRecordRecord> UpdList = (from rec in SHUpdateRecord.SelectByStudentID(PrimaryKey) where rec.ID != updateRec.ID && rec.ADDate.Trim() != "" orderby DateTime.Parse(rec.ADDate) descending, int.Parse(rec.ID) descending select rec).ToList();

            if (UpdList.Count > 0)
            {
                updateRec.LastADDate     = UpdList[0].ADDate;
                updateRec.LastADNumber   = UpdList[0].ADNumber;
                updateRec.LastUpdateCode = UpdList[0].UpdateCode;
            }

            updateRec.StudentID     = studRec.ID;
            updateRec.StudentNumber = studRec.StudentNumber;
            updateRec.StudentName   = studRec.Name;
            updateRec.IDNumber      = studRec.IDNumber;
            if (studRec.Birthday.HasValue)
            {
                updateRec.Birthdate = studRec.Birthday.Value.ToShortDateString();
            }
            updateRec.Gender = studRec.Gender;
            if (studRec.Department != null)
            {
                updateRec.Department = studRec.Department.FullName;
            }

            // 取得學生學籍特殊身分代碼
            updateRec.SpecialStatus = DAL.DALTransfer.GetSpecialCode(studRec.ID);

            updateRec.UpdateDate = DateTime.Now.ToShortDateString();
            if (updateRec == null)
            {
                return;
            }
            UpdateRecordItemForm form = new UpdateRecordItemForm(UpdateRecordItemForm.actMode.新增, updateRec, PrimaryKey);

            form.ShowDialog();
        }
Exemple #6
0
        /// <summary>
        /// 他校轉入
        /// </summary>
        public UpdateRecordInfo02(SHUpdateRecordRecord UpdateRec, PermRecLogProcess prlp, List <XElement> UpdateCodeElms)
        {
            InitializeComponent();
            cbxGender.Items.Add("男");
            cbxGender.Items.Add("女");

            cbxClass.DropDownWidth = 300;

            _UpdateRec       = UpdateRec;
            _UpdateCodeElms  = UpdateCodeElms;
            _prlp            = prlp;
            _UpdateCoodeList = (from x in _UpdateCodeElms select x.Element("代號").Value + " " + x.Element("原因及事項").Value).ToList();
            _DeptList        = SHDepartment.SelectAll();
            _faldn           = new UpdateRecordModule_SH_D.Utility.FormAndLogDataManager(_prlp);
            _epUpdateCode    = new ErrorProvider();

            // 建異動索引
            _UCodeDict = Utility.UITool.ConvertUpdateCodeDescDict(_UpdateCodeElms);

            // 載入資料
            cbxUpdateCode     = _faldn.SetFormData(_UpdateRec.UpdateCode, cbxUpdateCode, "異動代碼");
            txtDesc           = _faldn.SetFormData(_UpdateRec.UpdateDescription, txtDesc, "原因及事項");
            dtUpdateDate      = _faldn.SetFormData(_UpdateRec.UpdateDate, dtUpdateDate, "異動日期");
            txtMemo           = _faldn.SetFormData(_UpdateRec.Comment, txtMemo, "備註");
            cbxDept           = _faldn.SetFormData(_UpdateRec.Department, cbxDept, "科別");
            cbxClass          = _faldn.SetFormData(_UpdateRec.ClassType, cbxClass, "班別");
            txtSpecial        = _faldn.SetFormData(_UpdateRec.SpecialStatus, txtSpecial, "特殊身分代碼");
            txtName           = _faldn.SetFormData(_UpdateRec.StudentName, txtName, "姓名");
            txtStudentNumber  = _faldn.SetFormData(_UpdateRec.StudentNumber, txtStudentNumber, "學號");
            txtIDNumber       = _faldn.SetFormData(_UpdateRec.IDNumber, txtIDNumber, "身分證字號");
            dtBirthday        = _faldn.SetFormData(_UpdateRec.Birthdate, dtBirthday, "生日");
            txtIDNumber1      = _faldn.SetFormData(_UpdateRec.IDNumberComment, txtIDNumber1, "註1");
            cbxGender         = _faldn.SetFormData(_UpdateRec.Gender, cbxGender, "性別");
            txtSSchool        = _faldn.SetFormData(_UpdateRec.PreviousSchool, txtSSchool, "原就讀學校");
            txtSStudentNumber = _faldn.SetFormData(_UpdateRec.PreviousStudentNumber, txtSStudentNumber, "原就讀學號");
            txtSDept          = _faldn.SetFormData(_UpdateRec.PreviousDepartment, txtSDept, "原就讀科別");
            txtSGradYear      = _faldn.SetFormData(_UpdateRec.PreviousGradeYear, txtSGradYear, "原就讀年級");
            dtSLastUpdateDate = _faldn.SetFormData(_UpdateRec.PreviousSchoolLastADDate, dtSLastUpdateDate, "原就讀備查日期");
            txtSLastDocNo     = _faldn.SetFormData(_UpdateRec.PreviousSchoolLastADNumber, txtSLastDocNo, "原就讀備查文號");
            dtADDate          = _faldn.SetFormData(_UpdateRec.ADDate, dtADDate, "核准日期");
            txtADDocNo        = _faldn.SetFormData(_UpdateRec.ADNumber, txtADDocNo, "核准文號");
            txtSSemester      = _faldn.SetFormData(_UpdateRec.PreviousSemester, txtSSemester, "原就讀學期");
            txtComment2       = _faldn.SetFormData(_UpdateRec.Comment2, txtComment2, "轉入身分別代碼");
        }
Exemple #7
0
        // 修改異動紀錄
        private void EditStudentUpdateRecord()
        {
            SHUpdateRecordRecord objUpdate = lstRecord.SelectedItems[0].Tag as SHUpdateRecordRecord;

            // 檢查畫面是否
            XElement      _UpdateCode = DALTransfer.GetUpdateCodeList();
            List <string> xx          = (from elm in _UpdateCode.Elements("異動") where elm.Element("代號").Value == objUpdate.UpdateCode select elm.Element("代號").Value).ToList();

            if (xx.Count == 0)
            {
                FISCA.Presentation.Controls.MsgBox.Show("異動代碼無法解析,無法開啟相關輸入畫面。");
                return;
            }


            UpdateRecordItemForm form = new UpdateRecordItemForm(UpdateRecordItemForm.actMode.修改, objUpdate, PrimaryKey);

            form.ShowDialog();
        }
        /// <summary>
        /// 他校轉入
        /// </summary>
        public UpdateRecordInfo02(SHUpdateRecordRecord UpdateRec, PermRecLogProcess prlp, List<XElement> UpdateCodeElms)
        {
            InitializeComponent();
            cbxGender.Items.Add("男");
            cbxGender.Items.Add("女");

            _UpdateRec = UpdateRec;
            _UpdateCodeElms = UpdateCodeElms;
            _prlp = prlp;
            _UpdateCoodeList = (from x in _UpdateCodeElms select x.Element("代號").Value + " " + x.Element("原因及事項").Value).ToList();
            _DeptList = SHDepartment.SelectAll();
            _faldn = new UpdateRecordModule_SH_D.Utility.FormAndLogDataManager(_prlp);
            _epUpdateCode = new ErrorProvider();

            // 建異動索引
            _UCodeDict = Utility.UITool.ConvertUpdateCodeDescDict(_UpdateCodeElms);

            // 載入資料
            cbxUpdateCode = _faldn.SetFormData(_UpdateRec.UpdateCode, cbxUpdateCode, "異動代碼");
            txtDesc = _faldn.SetFormData(_UpdateRec.UpdateDescription, txtDesc, "原因及事項");
            dtUpdateDate = _faldn.SetFormData(_UpdateRec.UpdateDate, dtUpdateDate, "異動日期");
            txtMemo = _faldn.SetFormData(_UpdateRec.Comment, txtMemo, "備註");
            cbxDept = _faldn.SetFormData(_UpdateRec.Department, cbxDept, "科別");
            cbxClass = _faldn.SetFormData(_UpdateRec.ClassType, cbxClass, "班別");
            txtSpecial = _faldn.SetFormData(_UpdateRec.SpecialStatus, txtSpecial, "特殊身分代碼");
            txtName = _faldn.SetFormData(_UpdateRec.StudentName, txtName, "姓名");
            txtStudentNumber = _faldn.SetFormData(_UpdateRec.StudentNumber, txtStudentNumber, "學號");
            txtIDNumber = _faldn.SetFormData(_UpdateRec.IDNumber, txtIDNumber, "身分證字號");
            dtBirthday = _faldn.SetFormData(_UpdateRec.Birthdate, dtBirthday, "生日");
            txtIDNumber1 = _faldn.SetFormData(_UpdateRec.IDNumberComment, txtIDNumber1, "註1");
            cbxGender = _faldn.SetFormData(_UpdateRec.Gender, cbxGender, "性別");
            txtSSchool = _faldn.SetFormData(_UpdateRec.PreviousSchool,txtSSchool, "原就讀學校");
            txtSStudentNumber = _faldn.SetFormData(_UpdateRec.PreviousStudentNumber, txtSStudentNumber, "原就讀學號");
            txtSDept = _faldn.SetFormData(_UpdateRec.PreviousDepartment, txtSDept, "原就讀科別");
            txtSGradYear = _faldn.SetFormData(_UpdateRec.PreviousGradeYear, txtSGradYear, "原就讀年級");
            dtSLastUpdateDate = _faldn.SetFormData(_UpdateRec.PreviousSchoolLastADDate, dtSLastUpdateDate, "原就讀備查日期");
            txtSLastDocNo = _faldn.SetFormData(_UpdateRec.PreviousSchoolLastADNumber, txtSLastDocNo, "原就讀備查文號");
            dtADDate = _faldn.SetFormData(_UpdateRec.ADDate, dtADDate, "核准日期");
            txtADDocNo = _faldn.SetFormData(_UpdateRec.ADNumber, txtADDocNo, "核准文號");
            txtSSemester = _faldn.SetFormData(_UpdateRec.PreviousSemester, txtSSemester, "原就讀學期");
            txtComment2 = _faldn.SetFormData(_UpdateRec.Comment2, txtComment2, "轉入身分別代碼");
        }
Exemple #9
0
        private void UpdateRecordItemForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            IUpdateRecordInfo IU;

            if (UpdateRecordEditorPanle.Controls.Count == 0)
            {
                e.Cancel = true;
            }


            IU = UpdateRecordEditorPanle.Controls[0] as IUpdateRecordInfo;

            //IU.GetStudUpdateRecord();

            _StudUpdateRec = IU.GetStudUpdateRecord();
            // 當資料有改變
            if (IU.GetLogData().GetDataHasChange() && _checkSave == false || string.IsNullOrEmpty(IU.GetStudUpdateRecord().UpdateCode))
            {
                if (FISCA.Presentation.Controls.MsgBox.Show("這個動作將放棄目前編輯中的資料,是否確定離開?", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    e.Cancel = true;
                }
            }



            // 當異動代碼是否存在問題,不存在不儲存。
            if (IU.GetStudUpdateRecord() == null)
            {
                return;
            }
            else
            {
                List <string> xx = (from elm in _UpdateCode.Elements("異動") where elm.Element("代號").Value == IU.GetStudUpdateRecord().UpdateCode select elm.Element("代號").Value).ToList();
                if (xx.Count == 0)
                {
                    return;
                }
            }
        }
Exemple #10
0
 private void btnRemove_Click(object sender, EventArgs e)
 {
     if (lstRecord.SelectedItems.Count < 1)
     {
         MsgBox.Show("您必須先選擇一筆資料");
     }
     if (lstRecord.SelectedItems.Count == 1)
     {
         SHUpdateRecordRecord record = lstRecord.SelectedItems[0].Tag as SHUpdateRecordRecord;
         if (MsgBox.Show("您確定將此筆異動資料永久刪除?", "確認", MessageBoxButtons.OKCancel) == DialogResult.OK)
         {
             try
             {
                 // 刪除異動記錄
                 SHUpdateRecord.Delete(record);
             }
             catch (Exception ex)
             {
                 MsgBox.Show("異動資料刪除失敗:" + ex.Message);
             }
         }
     }
 }
        public UserControl CreateByUpdateCode()
        {
            // 初始化資料
            string strSchoolYear = string.Empty, strSemester = string.Empty, strUpdateType = string.Empty;
            if (_StudUpdateRec.SchoolYear.HasValue)
                strSchoolYear = _StudUpdateRec.SchoolYear.Value.ToString();
            if (_StudUpdateRec.Semester.HasValue)
                strSemester = _StudUpdateRec.Semester.Value.ToString();

            // 設定畫面上學年度學期年級資料
            SetLoadUpdateSchoolYearSemester(strSchoolYear, strSemester,_StudUpdateRec.GradeYear);

            // 用異動代碼判斷是哪種異動
            string UpdateType=string.Empty;
            List<string> xx = (from elm in _UpdateCode.Elements("異動") where elm.Element("代號").Value == _StudUpdateRec.UpdateCode select elm.Element("分類").Value ).ToList();
            if (xx.Count > 0)
                UpdateType = xx[0];

            // 001-新生
            List<XElement> UpdateCodeElms = (from elm in _UpdateCode.Elements("異動") where elm.Element("分類").Value == UpdateType select elm).ToList();
            if (_StudUpdateRec == null)
                _StudUpdateRec = _DefStudUpdateRec;

                if (UpdateType == "學籍異動")
                {
                    cbxSel.Text = "學籍異動";
                    return new UpdateRecordInfo01(_StudUpdateRec, _prlp, UpdateCodeElms);
                }
                else if (UpdateType == "轉入異動")
                {
                    cbxSel.Text = "他校轉入";
                    return new UpdateRecordInfo02(_StudUpdateRec, _prlp, UpdateCodeElms);
                }
                else if (UpdateType == "新生異動")
                {
                    cbxSel.Text = "新生異動";
                    return new UpdateRecordInfo03(_StudUpdateRec, _prlp, UpdateCodeElms);
                }
                else if (UpdateType == "畢業異動")
                {
                    cbxSel.Text = "畢業異動";
                    return new UpdateRecordInfo04(_StudUpdateRec, _prlp, UpdateCodeElms);
                }
                else
                    return null;
        }
        /// <summary>
        /// 學籍異動
        /// </summary>
        public UpdateRecordInfo01(SHUpdateRecordRecord UpdateRec, PermRecLogProcess prlp, List <XElement> UpdateCodeElms)
        {
            SHUpdateRecordRecord rec = new SHUpdateRecordRecord();

            InitializeComponent();
            cbxGender.Items.Add("男");
            cbxGender.Items.Add("女");

            cbxClass.DropDownWidth = 300;

            _UpdateRec      = UpdateRec;
            _prlp           = prlp;
            _UpdateCodeElms = UpdateCodeElms;
            _epUpdateCode   = new ErrorProvider();

            _UpdateCoodeList = (from x in _UpdateCodeElms select x.Element("代號").Value + " " + x.Element("原因及事項").Value).ToList();
            _DeptList        = SHDepartment.SelectAll();

            // 更正學籍顯示對照用
            _updateCodeDict4 = new Dictionary <string, string>();


            // 日進校不同,所以需要檢查:
            // 日校
            _updateCodeDict4.Add("401", "新學號");
            _updateCodeDict4.Add("402", "新姓名");
            _updateCodeDict4.Add("403", "新性別");
            _updateCodeDict4.Add("404", "新籍貫");
            _updateCodeDict4.Add("405", "新生日");
            _updateCodeDict4.Add("406", "新科別");
            _updateCodeDict4.Add("407", "新身分證號");
            _updateCodeDict4.Add("408", "入學資格學校名稱");
            _updateCodeDict4.Add("409", "特殊身分");
            _updateCodeDict4.Add("499", "其他學籍事項");

            if (string.IsNullOrEmpty(_UpdateRec.ExpectGraduateSchoolYear))
            {
                SHLeaveInfoRecord shl = SHLeaveInfo.SelectByStudentID(_UpdateRec.StudentID);
                if (shl.SchoolYear.HasValue)
                {
                    _UpdateRec.ExpectGraduateSchoolYear = shl.SchoolYear.Value.ToString();
                }
            }

            _UCodeDict = Utility.UITool.ConvertUpdateCodeDescDict(_UpdateCodeElms);

            _faldn = new UpdateRecordModule_SH_D.Utility.FormAndLogDataManager(_prlp);

            if (!string.IsNullOrEmpty(_UpdateRec.NewStudentNumber))
            {
                int i;
                if (int.TryParse(_UpdateRec.NewStudentNumber.Trim(), out i))
                {
                    _UpdateRec.NewData          = i.ToString();
                    _UpdateRec.NewStudentNumber = i.ToString();
                }
                else
                {
                    _UpdateRec.NewStudentNumber = "";
                }
            }


            // 載入資料
            cbxUpdateCode    = _faldn.SetFormData(_UpdateRec.UpdateCode, cbxUpdateCode, "異動代碼");
            txtDesc          = _faldn.SetFormData(_UpdateRec.UpdateDescription, txtDesc, "原因及事項");
            dtUpdateDate     = _faldn.SetFormData(_UpdateRec.UpdateDate, dtUpdateDate, "異動日期");
            txtMemo          = _faldn.SetFormData(_UpdateRec.Comment, txtMemo, "備註");
            cbxDept          = _faldn.SetFormData(_UpdateRec.Department, cbxDept, "科別");
            cbxClass         = _faldn.SetFormData(_UpdateRec.ClassType, cbxClass, "班別");
            txtSpecial       = _faldn.SetFormData(_UpdateRec.SpecialStatus, txtSpecial, "特殊身分代碼");
            txtName          = _faldn.SetFormData(_UpdateRec.StudentName, txtName, "姓名");
            txtStudentNumber = _faldn.SetFormData(_UpdateRec.StudentNumber, txtStudentNumber, "學號");
            txtIDNumber      = _faldn.SetFormData(_UpdateRec.IDNumber, txtIDNumber, "身分證字號");
            txtNewData       = _faldn.SetFormData(_UpdateRec.NewData, txtNewData, "新資料");
            txtIDNumber1     = _faldn.SetFormData(_UpdateRec.IDNumberComment, txtIDNumber1, "註1");
            txtIDNumber2     = _faldn.SetFormData(_UpdateRec.Comment2, txtIDNumber2, "註2");
            dtLastUpdateDate = _faldn.SetFormData(_UpdateRec.LastADDate, dtLastUpdateDate, "備查日期");
            txtLastDocNo     = _faldn.SetFormData(_UpdateRec.LastADNumber, txtLastDocNo, "備查文號");
            dtADDate         = _faldn.SetFormData(_UpdateRec.ADDate, dtADDate, "核准日期");
            txtADDocNo       = _faldn.SetFormData(_UpdateRec.ADNumber, txtADDocNo, "核准文號");
            cbxGender        = _faldn.SetFormData(_UpdateRec.Gender, cbxGender, "性別");
            dtBirthday       = _faldn.SetFormData(_UpdateRec.Birthdate, dtBirthday, "生日");
            txtSHSchoolYear  = _faldn.SetFormData(_UpdateRec.ExpectGraduateSchoolYear, txtSHSchoolYear, "應畢業學年度");
            txtC7SchoolCode  = _faldn.SetFormData(_UpdateRec.Code7SchoolCode, txtC7SchoolCode, "借讀學校代碼");
            txtC7DeptCode    = _faldn.SetFormData(_UpdateRec.Code7DeptCode, txtC7DeptCode, "借讀科別代碼");
            dtC71BeginDate   = _faldn.SetFormData(_UpdateRec.Code71BeginDate, dtC71BeginDate, "申請開始日期");
            dtC71EndDate     = _faldn.SetFormData(_UpdateRec.Code71EndDate, dtC71EndDate, "申請結束日期");
            dtC72BeginDate   = _faldn.SetFormData(_UpdateRec.Code72BeginDate, dtC72BeginDate, "實際開始日期");
            dtC72EndDate     = _faldn.SetFormData(_UpdateRec.Code72EndDate, dtC72EndDate, "實際結束日期");

            txtReplicatedSchoolRollNumber = _faldn.SetFormData(_UpdateRec.ReplicatedSchoolRollNumber, txtReplicatedSchoolRollNumber, "雙重學籍編號");
        }
        void _bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            _bgWorker.ReportProgress(1);
            // 取得部別、班別對照
            ConfigData cd = new ConfigData();
            Dictionary <string, List <ConfigDataItem> > cdDict         = cd.GetConfigDataItemDict();
            Dictionary <string, string>         DepMappingDict         = new Dictionary <string, string>();
            Dictionary <string, string>         ClsMappingDict         = new Dictionary <string, string>();
            Dictionary <string, string>         DeptMappingDict        = new Dictionary <string, string>();
            Dictionary <string, string>         ClassNoMappingDict     = new Dictionary <string, string>();
            Dictionary <string, string>         ClassIDNameDict        = new Dictionary <string, string>();
            Dictionary <string, List <string> > StudTagNameDict        = new Dictionary <string, List <string> >();
            List <SHStudentTagRecord>           SHStudentTagRecordList = SHStudentTag.SelectByStudentIDs(_StudentIDList);

            // 取得學期對照班級座號轉成大學繁星班代
            Dictionary <string, string> StudentSHClassSeatNoDict = Utility.GetStudentClassCodeSeatNo(_StudentIDList, _SchoolYear, _Semester, true);

            // 取得學生科別名稱
            Dictionary <string, string> StudeDeptNameDict = Utility.GetStudDeptNameDict(_StudentIDList, _SchoolYear, _Semester);

            // 取得學生異動資料
            List <SHUpdateRecordRecord> SHUpdateRecordRecordList = SHUpdateRecord.SelectByStudentIDs(_StudentIDList);
            Dictionary <string, List <SHUpdateRecordRecord> > SHUpdateRecordRecordDict = new Dictionary <string, List <SHUpdateRecordRecord> >();

            // 沒有核准日期文號不排入,並符合所選的學年度學期
            foreach (SHUpdateRecordRecord urRec in SHUpdateRecordRecordList)
            {
                if (string.IsNullOrWhiteSpace(urRec.ADDate) || string.IsNullOrWhiteSpace(urRec.ADNumber))
                {
                    continue;
                }

                if (urRec.SchoolYear.HasValue && urRec.Semester.HasValue)
                {
                    if (urRec.SchoolYear <= _SchoolYear && urRec.Semester <= _Semester)
                    {
                        if (!SHUpdateRecordRecordDict.ContainsKey(urRec.StudentID))
                        {
                            SHUpdateRecordRecordDict.Add(urRec.StudentID, new List <SHUpdateRecordRecord>());
                        }

                        SHUpdateRecordRecordDict[urRec.StudentID].Add(urRec);
                    }
                }
            }

            // 取得學生類別
            foreach (SHStudentTagRecord TRec in SHStudentTagRecordList)
            {
                if (!StudTagNameDict.ContainsKey(TRec.RefStudentID))
                {
                    StudTagNameDict.Add(TRec.RefStudentID, new List <string>());
                }

                StudTagNameDict[TRec.RefStudentID].Add(TRec.FullName);
            }

            _bgWorker.ReportProgress(20);

            foreach (SHClassRecord rec in SHClass.SelectAll())
            {
                ClassIDNameDict.Add(rec.ID, rec.Name);
            }

            // 部別對照
            if (cdDict.ContainsKey("部別代碼"))
            {
                foreach (ConfigDataItem cdi in cdDict["部別代碼"])
                {
                    if (!DepMappingDict.ContainsKey(cdi.TargetName))
                    {
                        DepMappingDict.Add(cdi.TargetName, cdi.Value);
                    }
                }
            }

            // 班別對照
            if (cdDict.ContainsKey("班別代碼"))
            {
                foreach (ConfigDataItem cdi in cdDict["班別代碼"])
                {
                    if (!ClsMappingDict.ContainsKey(cdi.TargetName))
                    {
                        ClsMappingDict.Add(cdi.TargetName, cdi.Value);
                    }
                }
            }

            // 科別對照
            DeptMappingDict = Utility.GetDepartmetDict();

            // 班級代碼對照
            ClassNoMappingDict = Utility.GetLHClassCodeDict();

            _bgWorker.ReportProgress(40);

            // 取得學生本資料
            List <SHStudentRecord> StudentRecordList  = SHStudent.SelectByIDs(_StudentIDList);
            List <StudentBaseRec>  StudentBaseRecList = new List <StudentBaseRec>();

            // 整理資料
            foreach (SHStudentRecord studRec in StudentRecordList)
            {
                // 身分證號,出生日期,所屬學校代碼,科/班/學程別代碼,部別,班別,班級座號代碼
                StudentBaseRec sbr = new StudentBaseRec();
                sbr.StudentNumber = studRec.StudentNumber;
                sbr.IDNumber      = studRec.IDNumber.ToUpper();
                sbr.BirthDate     = Utility.ConvertChDateString(studRec.Birthday);
                sbr.SchoolCode    = _SchoolCode;
                sbr.Name          = studRec.Name;
                if (studRec.Gender == "男")
                {
                    sbr.GenderCode = "1";
                }
                if (studRec.Gender == "女")
                {
                    sbr.GenderCode = "2";
                }

                // 科/班/學程別代碼
                sbr.DCLCode = "";
                if (StudeDeptNameDict.ContainsKey(studRec.ID))
                {
                    string name = StudeDeptNameDict[studRec.ID];
                    if (DeptMappingDict.ContainsKey(name))
                    {
                        sbr.DCLCode = DeptMappingDict[name];
                    }
                }

                // 部別
                sbr.DepCode = _DepCode;
                // 班別
                sbr.ClCode = _ClassCode;

                if (StudTagNameDict.ContainsKey(studRec.ID))
                {
                    foreach (string str in StudTagNameDict[studRec.ID])
                    {
                        if (DepMappingDict.ContainsKey(str))
                        {
                            sbr.DepCode = DepMappingDict[str];
                        }

                        if (ClsMappingDict.ContainsKey(str))
                        {
                            sbr.ClCode = ClsMappingDict[str];
                        }
                    }
                }

                // 班級座號代碼
                sbr.ClassSeatCode = "";
                if (StudentSHClassSeatNoDict.ContainsKey(studRec.ID))
                {
                    sbr.ClassSeatCode = StudentSHClassSeatNoDict[studRec.ID];
                    if (sbr.ClassSeatCode.Length == 5)
                    {
                        sbr.ClassCode = sbr.ClassSeatCode.Substring(0, 3);
                    }
                }
                else
                {
                    //如果學年度學期和系統預設相同
                    if (K12.Data.School.DefaultSchoolYear == _SchoolYear.ToString() && K12.Data.School.DefaultSemester == _Semester.ToString())
                    {
                        if (ClassIDNameDict.ContainsKey(studRec.RefClassID))
                        {
                            string cName = ClassIDNameDict[studRec.RefClassID];
                            if (ClassNoMappingDict.ContainsKey(cName) && studRec.SeatNo.HasValue)
                            {
                                sbr.ClassSeatCode = ClassNoMappingDict[cName] + string.Format("{0:00}", studRec.SeatNo.Value);
                                sbr.ClassCode     = ClassNoMappingDict[cName];
                            }
                        }
                    }
                }

                // 處理異動相關
                if (SHUpdateRecordRecordDict.ContainsKey(studRec.ID))
                {
                    // 排序
                    List <SHUpdateRecordRecord> UrDataList = (from data in SHUpdateRecordRecordDict[studRec.ID] orderby DateTime.Parse(data.ADDate) descending, int.Parse(data.ID) descending select data).ToList();

                    if (UrDataList.Count > 0)
                    {
                        SHUpdateRecordRecord rec = UrDataList[0];
                        sbr.PermrecCode = rec.UpdateCode;
                        DateTime dt = DateTime.Parse(rec.UpdateDate);
                        sbr.PermrecDate = Utility.ConvertChDateString(dt);

                        sbr.OrBirthDate = "-1";
                        sbr.OrIDNumber  = "-1";
                        sbr.Remak1      = rec.IDNumberComment;
                        sbr.SpCode      = rec.SpecialStatus;
                    }
                    foreach (SHUpdateRecordRecord rec in UrDataList)
                    {
                        // 再次檢查身分證與生日是否有差異
                        int iUcode = int.Parse(rec.UpdateCode);
                        if (iUcode > 400 && iUcode < 411)
                        {
                            if (rec.IDNumber.ToUpper() != studRec.IDNumber.ToUpper())
                            {
                                sbr.OrIDNumber = rec.IDNumber.ToUpper();
                            }

                            if (studRec.Birthday.HasValue)
                            {
                                if (studRec.Birthday.Value.ToShortDateString() != rec.Birthdate)
                                {
                                    DateTime dto = DateTime.Parse(rec.Birthdate);
                                    sbr.OrBirthDate = Utility.ConvertChDateString(dto);
                                }
                            }
                        }
                    }
                }

                StudentBaseRecList.Add(sbr);
            }
            _bgWorker.ReportProgress(80);

            // 排序 班級座號代碼
            StudentBaseRecList = (from data in StudentBaseRecList orderby data.ClassSeatCode ascending select data).ToList();

            // 統計人數
            Dictionary <string, StudentBaseRecCount> StudentBaseRecCountDict = new Dictionary <string, StudentBaseRecCount>();

            foreach (StudentBaseRec rec in StudentBaseRecList)
            {
                string key = rec.ClCode + rec.DCLCode + rec.DepCode + rec.ClassCode;

                if (!StudentBaseRecCountDict.ContainsKey(key))
                {
                    StudentBaseRecCount sbrc = new StudentBaseRecCount();
                    sbrc.ClassCode    = rec.ClassCode;
                    sbrc.ClCode       = rec.ClCode;
                    sbrc.DCLCode      = rec.DCLCode;
                    sbrc.DepCode      = rec.DepCode;
                    sbrc.DocType      = _DocType;
                    sbrc.SchoolCode   = _SchoolCode;
                    sbrc.SchoolYear   = _SchoolYear;
                    sbrc.Semester     = _Semester;
                    sbrc.StudentCount = 0;
                    StudentBaseRecCountDict.Add(key, sbrc);
                }
                StudentBaseRecCountDict[key].StudentCount++;
            }

            List <StudentBaseRecCount> StudentBaseRecCountList = new List <StudentBaseRecCount>();

            foreach (string Key in StudentBaseRecCountDict.Keys)
            {
                StudentBaseRecCountList.Add(StudentBaseRecCountDict[Key]);
            }

            // 排序,依班級代碼
            StudentBaseRecCountList = (from data in StudentBaseRecCountList orderby data.ClassCode ascending select data).ToList();


            // 填值到 Excel
            _wb = new Workbook(new MemoryStream(Properties.Resources.學生資料名冊樣板_非國教署主管學校_));
            Worksheet wst1 = _wb.Worksheets["學生資料名冊封面"];
            Worksheet wst2 = _wb.Worksheets["學生資料名冊"];

            int rowIdx = 1;

            foreach (StudentBaseRecCount sbrc in StudentBaseRecCountList)
            {
                //學校代碼 0,學年度 1,學期 2,名冊別 3,科/班/學程別代碼 4,年級班級代碼 5,部別 6,班別 7,班級人數 8
                wst1.Cells[rowIdx, 0].PutValue(sbrc.SchoolCode);
                wst1.Cells[rowIdx, 1].PutValue(sbrc.SchoolYear);
                wst1.Cells[rowIdx, 2].PutValue(sbrc.Semester);
                wst1.Cells[rowIdx, 3].PutValue(sbrc.DocType);
                wst1.Cells[rowIdx, 4].PutValue(sbrc.DCLCode);
                wst1.Cells[rowIdx, 5].PutValue(sbrc.ClassCode);
                wst1.Cells[rowIdx, 6].PutValue(sbrc.DepCode);
                wst1.Cells[rowIdx, 7].PutValue(sbrc.ClCode);
                wst1.Cells[rowIdx, 8].PutValue(sbrc.StudentCount);
                rowIdx++;
            }

            rowIdx = 1;
            foreach (StudentBaseRec sbr in StudentBaseRecList)
            {
                // 學號 0,身分證號 1,註1 2,姓名 3,性別代碼 4,出生日期 5,所屬學校代碼 6,科/班/學程別代碼 7,部別 8,
                //班別 9,班級座號代碼 10,特殊身分代碼 11,原身分證號 12,原出生日期 13,學籍狀態代碼 14,學籍狀態生效日期 15
                wst2.Cells[rowIdx, 0].PutValue(sbr.StudentNumber);
                wst2.Cells[rowIdx, 1].PutValue(sbr.IDNumber);
                wst2.Cells[rowIdx, 2].PutValue(sbr.Remak1);
                wst2.Cells[rowIdx, 3].PutValue(sbr.Name);
                wst2.Cells[rowIdx, 4].PutValue(sbr.GenderCode);
                wst2.Cells[rowIdx, 5].PutValue(sbr.BirthDate);
                wst2.Cells[rowIdx, 6].PutValue(sbr.SchoolCode);
                wst2.Cells[rowIdx, 7].PutValue(sbr.DCLCode);
                wst2.Cells[rowIdx, 8].PutValue(sbr.DepCode);
                wst2.Cells[rowIdx, 9].PutValue(sbr.ClCode);
                wst2.Cells[rowIdx, 10].PutValue(sbr.ClassSeatCode);
                wst2.Cells[rowIdx, 11].PutValue(sbr.SpCode);
                wst2.Cells[rowIdx, 12].PutValue(sbr.OrIDNumber);
                wst2.Cells[rowIdx, 13].PutValue(sbr.OrBirthDate);
                wst2.Cells[rowIdx, 14].PutValue(sbr.PermrecCode);
                wst2.Cells[rowIdx, 15].PutValue(sbr.PermrecDate);
                rowIdx++;
            }

            _bgWorker.ReportProgress(100);
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // 初始化資料
            SHUpdateRecordRecord updateRec = new SHUpdateRecordRecord();
            // 取得學生ID
            // 先清DAL Cache
            List<string> rmIDs=new List<string> ();
            rmIDs.Add(PrimaryKey);
            SHStudent.RemoveByIDs(rmIDs);
            SHStudentRecord studRec = SHStudent.SelectByID(PrimaryKey);

            // 取得最後一筆異動資料,備查使用。
            List<SHUpdateRecordRecord> UpdList = (from rec in SHUpdateRecord.SelectByStudentID(PrimaryKey) where rec.ID !=updateRec.ID && rec .ADDate.Trim()!="" orderby DateTime.Parse(rec.ADDate) descending,int.Parse(rec.ID) descending select rec).ToList ();
            if (UpdList.Count > 0)
            {
                updateRec.LastADDate = UpdList[0].ADDate;
                updateRec.LastADNumber = UpdList[0].ADNumber;
                updateRec.LastUpdateCode =UpdList[0].UpdateCode;
            }

            updateRec.StudentID = studRec.ID;
            updateRec.StudentNumber = studRec.StudentNumber;
            updateRec.StudentName = studRec.Name;
            updateRec.IDNumber = studRec.IDNumber;
            if (studRec.Birthday.HasValue)
                updateRec.Birthdate = studRec.Birthday.Value.ToShortDateString();
            updateRec.Gender = studRec.Gender;
            if (studRec.Department != null)
                updateRec.Department = studRec.Department.FullName;

            // 取得學生學籍特殊身分代碼
            updateRec.SpecialStatus = DAL.DALTransfer.GetSpecialCode(studRec.ID);

            updateRec.UpdateDate = DateTime.Now.ToShortDateString();
            if (updateRec == null)
                return;
            UpdateRecordItemForm form = new UpdateRecordItemForm(UpdateRecordItemForm.actMode.新增, updateRec, PrimaryKey);
            form.ShowDialog();
        }
        /// <summary>
        /// 產生新生異動(傳入學生編號、異動日期、異動代碼、班別)
        /// </summary>
        /// <param name="StudentIDList"></param>
        /// <param name="UpdateDate"></param>
        /// <param name="UpdateCode"></param>
        /// <param name="ClassType"></param>
        /// <returns></returns>
        public bool Run(List <string> StudentIDList, string UpdateDate, string UpdateCode, string UpdateDesc, string ClassType)
        {
            bool pass = true;
            List <SHBeforeEnrollmentRecord> befRecList = SHBeforeEnrollment.SelectByStudentIDs(StudentIDList);

            Dictionary <string, DAL.SchoolData> schoolDataDict = new Dictionary <string, DAL.SchoolData> ();

            foreach (XElement elm in BL.Get.JHSchoolList().Elements("學校"))
            {
                DAL.SchoolData sd = new DAL.SchoolData();
                sd.SchoolCode         = elm.Attribute("代碼").Value;
                sd.SchoolLocation     = elm.Attribute("所在地").Value;
                sd.SchoolName         = elm.Attribute("名稱").Value;
                sd.SchoolLocationCode = elm.Attribute("所在地代碼").Value;
                if (sd.SchoolCode.Length > 3)
                {
                    sd.SchoolType = sd.SchoolCode.Substring(2, 1);
                }

                string s1 = elm.Attribute("所在地").Value + elm.Attribute("名稱").Value;

                if (!schoolDataDict.ContainsKey(s1))
                {
                    schoolDataDict.Add(s1, sd);
                }

                if (!schoolDataDict.ContainsKey(sd.SchoolName))
                {
                    schoolDataDict.Add(sd.SchoolName, sd);
                }
            }

            int SchoolYear = 0, Semester = 0;

            int.TryParse(K12.Data.School.DefaultSchoolYear, out SchoolYear);
            int.TryParse(K12.Data.School.DefaultSemester, out Semester);

            List <string> _CheckCodeList               = (from data in _UpdateCodeList select data.Substring(0, 3)).ToList();

            List <SHUpdateRecordRecord> insertData     = new List <SHUpdateRecordRecord>();
            List <SHUpdateRecordRecord> WaitDeleteData = new List <SHUpdateRecordRecord>();

            // 取得學生資料
            List <SHStudentRecord> studRecList         = SHStudent.SelectByIDs(StudentIDList);

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

            // 取得已有新生異動
            foreach (SHUpdateRecordRecord rec in SHUpdateRecord.SelectByStudentIDs(StudentIDList))
            {
                if (_CheckCodeList.Contains(rec.UpdateCode))
                {
                    WaitDeleteData.Add(rec);
                    if (!SIDList.Contains(rec.StudentID))
                    {
                        SIDList.Add(rec.StudentID);
                    }
                }
            }


            bool checkdelData = true;

            // 已有資料是否覆蓋
            if (SIDList.Count > 0)
            {
                WarningForm wf = new WarningForm();
                wf.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                wf.SetStudentCount(SIDList.Count);
                wf.SetStudRec(studRecList);
                wf.SetUpdateRecList(WaitDeleteData);
                if (wf.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                {
                    checkdelData = false;
                    pass         = false;
                }
            }


            // 清掉舊資料
            if (checkdelData)
            {
                SHUpdateRecord.Delete(WaitDeleteData);
            }

            // 取得新生異動
            foreach (SHStudentRecord studRec in studRecList)
            {
                // 不刪除代表不需要新增,所以略過
                if (checkdelData == false)
                {
                    if (SIDList.Contains(studRec.ID))
                    {
                        continue;
                    }
                }

                SHUpdateRecordRecord NewUpdateRec = new SHUpdateRecordRecord();

                if (SchoolYear > 0)
                {
                    NewUpdateRec.SchoolYear = SchoolYear;
                }

                if (Semester > 0)
                {
                    NewUpdateRec.Semester = Semester;
                }

                if (studRec.Class != null)
                {
                    if (studRec.Class.GradeYear.HasValue)
                    {
                        NewUpdateRec.GradeYear = studRec.Class.GradeYear.Value.ToString();
                    }
                }

                NewUpdateRec.GraduateComment   = "";
                NewUpdateRec.UpdateCode        = UpdateCode;
                NewUpdateRec.UpdateDescription = UpdateDesc;
                NewUpdateRec.UpdateDate        = UpdateDate;
                NewUpdateRec.ClassType         = ClassType;

                NewUpdateRec.SpecialStatus = DAL.DALTransfer.GetSpecialCode(studRec.ID);

                if (studRec.Department != null)
                {
                    NewUpdateRec.Department = studRec.Department.FullName;
                }
                NewUpdateRec.StudentID     = studRec.ID;
                NewUpdateRec.StudentName   = studRec.Name;
                NewUpdateRec.StudentNumber = studRec.StudentNumber;
                NewUpdateRec.IDNumber      = studRec.IDNumber;
                if (studRec.Birthday.HasValue)
                {
                    NewUpdateRec.Birthdate = studRec.Birthday.Value.ToShortDateString();
                }
                NewUpdateRec.Gender = studRec.Gender;

                if (int.Parse(UpdateCode) > 5)
                {
                    NewUpdateRec.GraduateComment = "1";
                }


                foreach (SHBeforeEnrollmentRecord brfRec in befRecList)
                {
                    if (brfRec.RefStudentID == NewUpdateRec.StudentID)
                    {
                        NewUpdateRec.GraduateSchool     = brfRec.School;
                        NewUpdateRec.GraduateSchoolYear = brfRec.GraduateSchoolYear;

                        // 用學校名稱解析
                        if (!string.IsNullOrEmpty(brfRec.School))
                        {
                            string key = brfRec.SchoolLocation.Replace("台", "臺") + brfRec.School.Trim();
                            if (schoolDataDict.ContainsKey(key))
                            {
                                NewUpdateRec.GraduateSchoolCode         = schoolDataDict[key].SchoolCode;
                                NewUpdateRec.GraduateSchoolLocationCode = schoolDataDict[key].SchoolLocationCode;
                            }
                        }
                    }
                }
                insertData.Add(NewUpdateRec);
            }

            // 新增異動
            SHUpdateRecord.Insert(insertData);

            return(pass);
        }
Exemple #16
0
        /// <summary>
        /// 學籍異動
        /// </summary>
        public UpdateRecordInfo01_N(SHUpdateRecordRecord UpdateRec, PermRecLogProcess prlp, List <XElement> UpdateCodeElms)
        {
            InitializeComponent();
            cbxGender.Items.Add("男");
            cbxGender.Items.Add("女");

            _UpdateRec      = UpdateRec;
            _prlp           = prlp;
            _UpdateCodeElms = UpdateCodeElms;
            _epUpdateCode   = new ErrorProvider();

            _UpdateCoodeList = (from x in _UpdateCodeElms select x.Element("代號").Value + " " + x.Element("原因及事項").Value).ToList();
            _DeptList        = SHDepartment.SelectAll();


            // 更正學籍顯示對照用
            _updateCodeDict4 = new Dictionary <string, string>();
            // 進校
            _updateCodeDict4.Add("301", "新學號");
            _updateCodeDict4.Add("302", "新姓名");
            _updateCodeDict4.Add("303", "新性別");
            _updateCodeDict4.Add("304", "新身分證號");
            _updateCodeDict4.Add("305", "新生日");


            //// 讀取畢業學年度
            //SHLeaveInfoRecord shl = SHLeaveInfo.SelectByStudentID(_UpdateRec.StudentID);
            //if (shl.SchoolYear.HasValue)
            //    txtSHSchoolYear.Text = shl.SchoolYear.Value.ToString();

            //// 當延修生要顯示
            //    if (_UpdateRec.GradeYear == "延修生")
            //    {
            //        txtSHSchoolYear.Enabled = true;
            //    }
            //    else
            //        txtSHSchoolYear.Enabled = false;


            _UCodeDict = Utility.UITool.ConvertUpdateCodeDescDict(_UpdateCodeElms);

            _faldn = new UpdateRecordModule_SH_N.Utility.FormAndLogDataManager(_prlp);

            if (!string.IsNullOrEmpty(_UpdateRec.NewStudentNumber))
            {
                int i;
                if (int.TryParse(_UpdateRec.NewStudentNumber.Trim(), out i))
                {
                    _UpdateRec.NewData          = i.ToString();
                    _UpdateRec.NewStudentNumber = i.ToString();
                }
                else
                {
                    _UpdateRec.NewStudentNumber = "";
                }
            }

            // 載入資料
            cbxUpdateCode    = _faldn.SetFormData(_UpdateRec.UpdateCode, cbxUpdateCode, "異動代碼");
            txtDesc          = _faldn.SetFormData(_UpdateRec.UpdateDescription, txtDesc, "原因及事項");
            dtUpdateDate     = _faldn.SetFormData(_UpdateRec.UpdateDate, dtUpdateDate, "異動日期");
            txtMemo          = _faldn.SetFormData(_UpdateRec.Comment, txtMemo, "備註");
            cbxDept          = _faldn.SetFormData(_UpdateRec.Department, cbxDept, "科別");
            cbxClass         = _faldn.SetFormData(_UpdateRec.ClassType, cbxClass, "班別");
            txtSHSchoolYear  = _faldn.SetFormData(_UpdateRec.SpecialStatus, txtSHSchoolYear, "特殊身分代碼");
            txtName          = _faldn.SetFormData(_UpdateRec.StudentName, txtName, "姓名");
            txtStudentNumber = _faldn.SetFormData(_UpdateRec.StudentNumber, txtStudentNumber, "學號");
            txtIDNumber      = _faldn.SetFormData(_UpdateRec.IDNumber, txtIDNumber, "身分證字號");
            txtNewData       = _faldn.SetFormData(_UpdateRec.NewData, txtNewData, "新資料");
            txtIDNumber1     = _faldn.SetFormData(_UpdateRec.IDNumberComment, txtIDNumber1, "註1");
            dtLastUpdateDate = _faldn.SetFormData(_UpdateRec.LastADDate, dtLastUpdateDate, "備查日期");
            txtLastDocNo     = _faldn.SetFormData(_UpdateRec.LastADNumber, txtLastDocNo, "備查文號");
            dtADDate         = _faldn.SetFormData(_UpdateRec.ADDate, dtADDate, "核准日期");
            txtADDocNo       = _faldn.SetFormData(_UpdateRec.ADNumber, txtADDocNo, "核准文號");
            txtSpecial       = _faldn.SetFormData(_UpdateRec.SpecialStatus, txtSpecial, "特殊身分代碼");
            cbxGender        = _faldn.SetFormData(_UpdateRec.Gender, cbxGender, "性別");
            dtBirthday       = _faldn.SetFormData(_UpdateRec.Birthdate, dtBirthday, "生日");
        }
        public UpdateRecordItemForm(actMode mode, SHUpdateRecordRecord StudUdRecEnty,string StudentID)
        {
            InitializeComponent();

            _actMode = mode;
            _StudentID = StudentID;
            _checkSave = false;
            if (FISCA.Permission.UserAcl.Current[GetType()].Editable)
                btnConfirm.Enabled = true;
            else
                btnConfirm.Enabled = false;

            _StudUpdateRec = StudUdRecEnty;

            _DefStudUpdateRec = StudUdRecEnty;
            _prlp = new UpdateRecordModule_SH_D.PermRecLogProcess();

            // 取得異動代碼
            _UpdateCode = DAL.DALTransfer.GetUpdateCodeList();

            // 先將畫面學年度、學期、年級設空
            intSchoolYear.IsEmpty = true;
            intSemester.IsEmpty = true;
            cbxGradeYear.Text = "";
            cbxGradeYear.Items.Add("1");
            cbxGradeYear.Items.Add("2");
            cbxGradeYear.Items.Add("3");
            cbxGradeYear.Items.Add("延修生");

            if (mode == actMode.新增)
            {
                cbxSel.Enabled = true;

                cbxSel.Items.Add("學籍異動");
                cbxSel.Items.Add("他校轉入");
                cbxSel.Items.Add("新生異動");
                cbxSel.Items.Add("畢業異動");

                cbxSel.SelectedIndex = 0;
                SetDefaultSchoolYearSemester();

                // 加入 log
                _prlp.SetAction("新增");
            }

            if (mode == actMode.修改)
            {
                cbxSel.Enabled = false;
                UpdateRecordEditorPanle.Controls.Clear();

                UserControl ui = CreateByUpdateCode();
                UpdateRecordEditorPanle.Controls.Add(ui);
                UpdateRecordEditorPanle.Size = ui.Size;
                Size s1 = new System.Drawing.Size();
                s1 = this.Size;
                s1.Height = ui.Size.Height + 120;
                this.Size = s1;

                // 加入 log
                _prlp.SetAction("修改");
            }

            // 加入 log
            _prlp.SetBeforeSaveText("學年度", intSchoolYear.Text);
            _prlp.SetBeforeSaveText("學期", intSemester.Text);
            if (_StudUpdateRec.Student.Status == K12.Data.StudentRecord.StudentStatus.延修)
                cbxGradeYear.Text = "延修生";
        }
Exemple #18
0
        public UpdateRecordItemForm(actMode mode, SHUpdateRecordRecord StudUdRecEnty, string StudentID)
        {
            InitializeComponent();

            _actMode   = mode;
            _StudentID = StudentID;
            _checkSave = false;
            if (FISCA.Permission.UserAcl.Current[GetType()].Editable)
            {
                btnConfirm.Enabled = true;
            }
            else
            {
                btnConfirm.Enabled = false;
            }

            _StudUpdateRec = StudUdRecEnty;

            _DefStudUpdateRec = StudUdRecEnty;
            _prlp             = new UpdateRecordModule_SH_D.PermRecLogProcess();

            // 取得異動代碼
            _UpdateCode = DAL.DALTransfer.GetUpdateCodeList();

            // 先將畫面學年度、學期、年級設空
            intSchoolYear.IsEmpty = true;
            intSemester.IsEmpty   = true;
            cbxGradeYear.Text     = "";
            cbxGradeYear.Items.Add("1");
            cbxGradeYear.Items.Add("2");
            cbxGradeYear.Items.Add("3");
            cbxGradeYear.Items.Add("延修生");

            if (mode == actMode.新增)
            {
                cbxSel.Enabled = true;

                cbxSel.Items.Add("學籍異動");
                cbxSel.Items.Add("他校轉入");
                cbxSel.Items.Add("新生異動");
                cbxSel.Items.Add("畢業異動");

                cbxSel.SelectedIndex = 0;
                SetDefaultSchoolYearSemester();

                // 加入 log
                _prlp.SetAction("新增");
            }

            if (mode == actMode.修改)
            {
                cbxSel.Enabled = false;
                UpdateRecordEditorPanle.Controls.Clear();

                UserControl ui = CreateByUpdateCode();
                if (ui != null)
                {
                    UpdateRecordEditorPanle.Controls.Add(ui);
                    UpdateRecordEditorPanle.Size = ui.Size;
                    Size s1 = new System.Drawing.Size();
                    s1        = this.Size;
                    s1.Height = ui.Size.Height + 120;
                    this.Size = s1;

                    // 加入 log
                    _prlp.SetAction("修改");
                }
                else
                {
                    FISCA.Presentation.Controls.MsgBox.Show("無法解析異動代碼");
                    this.Close();
                }
            }

            // 加入 log
            _prlp.SetBeforeSaveText("學年度", intSchoolYear.Text);
            _prlp.SetBeforeSaveText("學期", intSemester.Text);
            //if (_StudUpdateRec.Student.Status == K12.Data.StudentRecord.StudentStatus.延修)
            //    cbxGradeYear.Text = "延修生";
        }
Exemple #19
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (UpdateRecordEditorPanle.Controls.Count > 0)
            {
                IUpdateRecordInfo IU;
                IU             = UpdateRecordEditorPanle.Controls[0] as IUpdateRecordInfo;
                _StudUpdateRec = IU.GetStudUpdateRecord();
                _prlp          = IU.GetLogData();

                int codeInt;
                if (_StudUpdateRec != null)
                {
                    if (int.TryParse(_StudUpdateRec.UpdateCode, out codeInt) && _actMode == actMode.新增)
                    {
                        int icode;
                        List <SHUpdateRecordRecord> UpRec01List = new List <SHUpdateRecordRecord>();
                        // 檢查是否有新生異動
                        foreach (SHUpdateRecordRecord rec in SHUpdateRecord.SelectByStudentID(_StudentID))
                        {
                            if (int.TryParse(rec.UpdateCode, out icode))
                            {
                                if (icode > 0 && icode < 100)
                                {
                                    UpRec01List.Add(rec);
                                }
                            }
                        }
                        if (UpRec01List.Count > 0 && codeInt < 100)
                        {
                            if (FISCA.Presentation.Controls.MsgBox.Show("已有" + UpRec01List.Count + "筆新生異動,是否覆蓋", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                            {
                                SHUpdateRecord.Delete(UpRec01List);
                            }
                            else
                            {
                                return;
                            }
                        }

                        // 檢查是否有畢業異動
                        List <SHUpdateRecordRecord> UpRec05List = (from data in SHUpdateRecord.SelectByStudentID(_StudentID) where data.UpdateCode == "501" select data).ToList();
                        if (UpRec05List.Count > 0 && codeInt == 501)
                        {
                            if (FISCA.Presentation.Controls.MsgBox.Show("已有" + UpRec01List.Count + "筆畢業異動,是否覆蓋", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                            {
                                SHUpdateRecord.Delete(UpRec05List);
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                }

                if (_StudUpdateRec != null)
                {
                    // 儲存學年度學期 年級
                    _StudUpdateRec.SchoolYear = intSchoolYear.Value;
                    _StudUpdateRec.Semester   = intSemester.Value;

                    if (cbxGradeYear.Text == "延修生")
                    {
                        _StudUpdateRec.GradeYear = "延修生";
                    }
                    else
                    {
                        _StudUpdateRec.GradeYear = cbxGradeYear.Text;
                    }

                    // 儲存異動資料
                    string strItemName = "";
                    if (_actMode == actMode.新增)
                    {
                        SHUpdateRecord.Insert(_StudUpdateRec);
                        strItemName = "新增:";
                    }
                    else
                    {
                        SHUpdateRecord.Update(_StudUpdateRec);
                        strItemName = "修改:";
                    }

                    SHStudentRecord studRec = SHStudent.SelectByID(_StudentID);
                    // Log
                    strItemName += "學生姓名:" + studRec.Name + _actMode.ToString();

                    _prlp.SetActionBy("學生", strItemName);
                    _prlp.SaveLog("", ":", "student", _StudentID);
                    _checkSave = true;

                    // 取得 UpdateCode
                    int intUpdateCode;
                    int.TryParse(_StudUpdateRec.UpdateCode, out intUpdateCode);



                    // 學生資料 Cache
                    List <SHStudentRecord> AllStudRec = null;


                    // 復學,學生狀態是非一般,輸入異動代碼是復學,問使用者是否轉成一般。
                    if (intUpdateCode >= 221 && intUpdateCode <= 226 && studRec.Status != K12.Data.StudentRecord.StudentStatus.一般)
                    {
                        if (FISCA.Presentation.Controls.MsgBox.Show("請問是否將學生狀態變更成一般?", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            if (AllStudRec == null)
                            {
                                AllStudRec = SHStudent.SelectAll();
                            }

                            // 檢查將變更學生狀態
                            // 身分證
                            List <string> studIDNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.一般 && stud.IDNumber == studRec.IDNumber select stud.ID).ToList();
                            // 學號
                            List <string> studNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.一般 && stud.StudentNumber == studRec.StudentNumber select stud.ID).ToList();

                            if (studNumber.Count > 0)
                            {
                                FISCA.Presentation.Controls.MsgBox.Show("在一般狀態有相同的學號:" + studRec.StudentNumber + ",無法變更學生狀態");
                            }

                            if (studIDNumber.Count > 0)
                            {
                                FISCA.Presentation.Controls.MsgBox.Show("在一般狀態有相同的身分證號:" + studRec.IDNumber + ",無法變更學生狀態");
                            }

                            if (studIDNumber.Count == 0 && studNumber.Count == 0)
                            {
                                studRec.Status = K12.Data.StudentRecord.StudentStatus.一般;
                                SHStudent.Update(studRec);
                            }
                        }
                    }

                    // 轉出,學生狀態是一般,輸入異動代碼是轉出,問使用者是否轉成畢業或離校。
                    if (intUpdateCode >= 311 && intUpdateCode <= 316 && studRec.Status == K12.Data.StudentRecord.StudentStatus.一般)
                    {
                        if (FISCA.Presentation.Controls.MsgBox.Show("請問是否將學生狀態變更成畢業或離校?", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            if (AllStudRec == null)
                            {
                                AllStudRec = SHStudent.SelectAll();
                            }

                            // 檢查將變更學生狀態
                            // 身分證
                            List <string> studIDNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.畢業或離校 && stud.IDNumber == studRec.IDNumber select stud.ID).ToList();
                            // 學號
                            List <string> studNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.畢業或離校 && stud.StudentNumber == studRec.StudentNumber select stud.ID).ToList();

                            if (studNumber.Count > 0)
                            {
                                FISCA.Presentation.Controls.MsgBox.Show("在畢業或離校狀態有相同的學號:" + studRec.StudentNumber + ",無法變更學生狀態");
                            }

                            if (studIDNumber.Count > 0)
                            {
                                FISCA.Presentation.Controls.MsgBox.Show("在畢業或離校狀態有相同的身分證號:" + studRec.IDNumber + ",無法變更學生狀態");
                            }

                            if (studIDNumber.Count == 0 && studNumber.Count == 0)
                            {
                                studRec.Status = K12.Data.StudentRecord.StudentStatus.畢業或離校;
                                SHStudent.Update(studRec);
                            }
                        }
                    }

                    // 休學,學生狀態是一般,輸入異動代碼是休學,問使用者是否轉成休學。
                    if (intUpdateCode >= 341 && intUpdateCode <= 349 && studRec.Status == K12.Data.StudentRecord.StudentStatus.一般)
                    {
                        if (FISCA.Presentation.Controls.MsgBox.Show("請問是否將學生狀態變更成休學?", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            if (AllStudRec == null)
                            {
                                AllStudRec = SHStudent.SelectAll();
                            }

                            // 檢查將變更學生狀態
                            // 身分證
                            List <string> studIDNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.休學 && stud.IDNumber == studRec.IDNumber select stud.ID).ToList();
                            // 學號
                            List <string> studNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.休學 && stud.StudentNumber == studRec.StudentNumber select stud.ID).ToList();

                            if (studNumber.Count > 0)
                            {
                                FISCA.Presentation.Controls.MsgBox.Show("在休學狀態有相同的學號:" + studRec.StudentNumber + ",無法變更學生狀態");
                            }

                            if (studIDNumber.Count > 0)
                            {
                                FISCA.Presentation.Controls.MsgBox.Show("在休學狀態有相同的身分證號:" + studRec.IDNumber + ",無法變更學生狀態");
                            }


                            if (studIDNumber.Count == 0 && studNumber.Count == 0)
                            {
                                studRec.Status = K12.Data.StudentRecord.StudentStatus.休學;
                                SHStudent.Update(studRec);
                            }
                        }
                    }
                    this.Close();
                    // 畫面同步
                    SmartSchool.StudentRelated.Student.Instance.SyncAllBackground();
                }
            }
        }
Exemple #20
0
        public UserControl CreateByUpdateCode()
        {
            _chkLoadForm = true;
            try
            {
                // 初始化資料
                string strSchoolYear = string.Empty, strSemester = string.Empty, strUpdateType = string.Empty;
                if (_StudUpdateRec.SchoolYear.HasValue)
                {
                    strSchoolYear = _StudUpdateRec.SchoolYear.Value.ToString();
                }
                if (_StudUpdateRec.Semester.HasValue)
                {
                    strSemester = _StudUpdateRec.Semester.Value.ToString();
                }

                // 設定畫面上學年度學期年級資料
                SetLoadUpdateSchoolYearSemester(strSchoolYear, strSemester, _StudUpdateRec.GradeYear);

                // 用異動代碼判斷是哪種異動
                string UpdateType = utility.GetUpdateTypeByCode(_StudUpdateRec.UpdateCode);

                List <XElement> UpdateCodeElms = (from elm in _UpdateCode.Elements("異動") where elm.Element("分類").Value == UpdateType select elm).ToList();

                if (_StudUpdateRec == null)
                {
                    _StudUpdateRec = _DefStudUpdateRec;
                }


                if (UpdateType == "學籍異動")
                {
                    cbxSel.Text = "學籍異動";
                    return(new UpdateRecordInfo01(_StudUpdateRec, _prlp, UpdateCodeElms));
                }
                else if (UpdateType == "轉入異動")
                {
                    cbxSel.Text = "他校轉入";
                    return(new UpdateRecordInfo02(_StudUpdateRec, _prlp, UpdateCodeElms));
                }
                else if (UpdateType == "新生異動")
                {
                    cbxSel.Text = "新生異動";
                    if (_actMode == actMode.新增)
                    {
                        return(new UpdateRecordInfo03(_StudUpdateRec, _prlp, UpdateCodeElms, true));
                    }
                    else
                    {
                        return(new UpdateRecordInfo03(_StudUpdateRec, _prlp, UpdateCodeElms, false));
                    }
                }
                else if (UpdateType == "畢業異動")
                {
                    cbxSel.Text = "畢業異動";
                    if (_actMode == actMode.新增)
                    {
                        return(new UpdateRecordInfo04(_StudUpdateRec, _prlp, UpdateCodeElms, true));
                    }
                    else
                    {
                        return(new UpdateRecordInfo04(_StudUpdateRec, _prlp, UpdateCodeElms, false));
                    }
                }
                else
                {
                    _chkLoadForm = false;
                    return(null);
                }
            }
            catch (Exception ex)
            {
                FISCA.Presentation.Controls.MsgBox.Show("解析異動代碼錯誤," + ex.Message);
                _chkLoadForm = false;
                return(null);
            }
        }
        public UserControl CreateByUpdateCode()
        {
            // 初始化資料
            string strSchoolYear = string.Empty, strSemester = string.Empty, strUpdateType = string.Empty;

            if (_StudUpdateRec.SchoolYear.HasValue)
            {
                strSchoolYear = _StudUpdateRec.SchoolYear.Value.ToString();
            }
            if (_StudUpdateRec.Semester.HasValue)
            {
                strSemester = _StudUpdateRec.Semester.Value.ToString();
            }



            // 設定畫面上學年度學期年級資料
            SetLoadUpdateSchoolYearSemester(strSchoolYear, strSemester, _StudUpdateRec.GradeYear);

            // 用異動代碼判斷是哪種異動
            string        UpdateType = string.Empty;
            List <string> xx         = (from elm in _UpdateCode.Elements("異動") where elm.Element("代號").Value == _StudUpdateRec.UpdateCode select elm.Element("分類").Value).ToList();

            if (xx.Count > 0)
            {
                UpdateType = xx[0];
            }

            // 001-新生
            List <XElement> UpdateCodeElms = (from elm in _UpdateCode.Elements("異動") where elm.Element("分類").Value == UpdateType select elm).ToList();

            if (_StudUpdateRec == null)
            {
                _StudUpdateRec = _DefStudUpdateRec;
            }


            if (UpdateType == "學籍異動")
            {
                cbxSel.Text = "學籍異動";
                return(new UpdateRecordInfo01(_StudUpdateRec, _prlp, UpdateCodeElms));
            }
            else if (UpdateType == "轉入異動")
            {
                cbxSel.Text = "他校轉入";
                return(new UpdateRecordInfo02(_StudUpdateRec, _prlp, UpdateCodeElms));
            }
            else if (UpdateType == "新生異動")
            {
                cbxSel.Text = "新生異動";
                return(new UpdateRecordInfo03(_StudUpdateRec, _prlp, UpdateCodeElms));
            }
            else if (UpdateType == "畢業異動")
            {
                cbxSel.Text = "畢業異動";
                return(new UpdateRecordInfo04(_StudUpdateRec, _prlp, UpdateCodeElms));
            }
            else
            {
                return(null);
            }
        }
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            // 取得學生資料
            Dictionary<string, SHStudentRecord> Students = new Dictionary<string, SHStudentRecord>();

            // 取得異動資料
            Dictionary<string, List<SHUpdateRecordRecord>> UpdateRecs = new Dictionary<string, List<SHUpdateRecordRecord>>();
            wizard.PackageLimit = 3000;
            wizard.ImportableFields.AddRange("班別", "特殊身份代碼", "異動科別", "年級", "異動學號", "異動姓名", "身分證號", "註1", "異動代碼", "異動日期", "原因及事項", "新學號", "更正後資料", "舊班別", "舊科別代碼", "備查日期", "備查文號", "核准日期", "核准文號", "備註");
            wizard.RequiredFields.AddRange("異動代碼", "異動日期");
            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                Students.Clear();
                UpdateRecs.Clear();

                // 取得學生資料
                foreach (SHStudentRecord studRec in SHStudent.SelectByIDs(e.List))
                    if (!Students.ContainsKey(studRec.ID))
                        Students.Add(studRec.ID, studRec);
                foreach (string str in Students.Keys)
                {
                    List<SHUpdateRecordRecord> UpdRecList = new List<SHUpdateRecordRecord>();
                    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 (SHUpdateRecordRecord UpdRec in SHUpdateRecord.SelectByStudentIDs(e.List))
                    {

                        // 過濾非符合標準的異動(目前是學籍)
                        if(!_UpdateCodeList.Contains(UpdRec.UpdateCode))
                            continue;

                            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;
                // 檢查學生是否存在
                SHStudentRecord studRec = null;
                if (Students.ContainsKey(e.Data.ID))
                    studRec = Students[e.Data.ID];
                else
                {
                    e.ErrorMessage = "沒有這位學生" + e.Data.ID;
                    return;
                }

                // 驗證格式資料
                bool InputFormatPass = true;
                foreach (string field in e.SelectFields)
                {
                    string value = e.Data[field].Trim();
                    //// 驗證$無法匯入
                    //if (value.IndexOf('$') > -1)
                    //{
                    //    e.ErrorFields.Add(field, "儲存格有$無法匯入.");
                    //    break;
                    //}
                    switch (field)
                    {
                        default:
                            break;

                        //// 班別
                        //case "班別": break;
                        //// 特殊身份代碼
                        //case "特殊身份代碼": break;
                        //// 異動科別
                        //case "異動科別": break;
                        //// 年級
                        //case "年級": break;
                        //// 異動學號
                        //case "異動學號": break;
                        //// 異動姓名
                        //case "異動姓名": break;
                        //// 身分證號
                        //case "身分證號": break;
                        //// 註1
                        //case "註1": break;
                        //// 異動種類
                        //case "異動種類": break;
                        // 異動代碼
                        case "異動代碼":
                            if (!_UpdateCodeList.Contains(value))
                            {
                                InputFormatPass &= false;
                                e.ErrorFields.Add(field, "非學籍異動代碼!");
                            }
                            break;
                        // 異動日期(必填)
                        case "異動日期":
                            DateTime dtC1;
                            if (DateTime.TryParse(value, out dtC1))
                            { }
                            else
                            {
                                InputFormatPass &= false;
                                e.ErrorFields.Add(field, "日期錯誤!");
                            }

                            break;

                        case "備查日期":
                        case "核准日期":
                            DateTime dtC2;
                            if (value.Trim() != "")
                            {
                                if (DateTime.TryParse(value, out dtC2))
                                { }
                                else
                                {
                                    InputFormatPass &= false;
                                    e.ErrorFields.Add(field, "日期錯誤!");
                                }
                            }
                            break;
                        //// 原因及事項
                        //case "原因及事項": break;
                        //// 新學號
                        //case "新學號": break;
                        //// 更正後資料
                        //case "更正後資料": break;
                        //// 舊班別
                        //case "舊班別": break;
                        //// 舊科別代碼
                        //case "舊科別代碼": break;
                        //// 備查日期
                        //case "備查日期":
                        //    break;
                        //// 備查文號
                        //case "備查文號": break;
                        //// 核准日期
                        //case "核准日期": break;
                        //// 核准文號
                        //case "核准文號": break;
                        //// 備註
                        //case "備註": 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<SHUpdateRecordRecord> InsertList = new List<SHUpdateRecordRecord>();
                List<SHUpdateRecordRecord> UpdateList = new List<SHUpdateRecordRecord>();

                // 檢查新增或更新方式:
                // 每筆 Key 為:異動日期+異動代碼+原因及事項,如果三者內容相同更新,如果不同就新增。
                foreach (string id in id_Rows.Keys)
                {
                    DateTime dt;

                    // 讀取工作表內資料
                    foreach (RowData data in id_Rows[id])
                    {
                        // 當異動記錄內沒有工作表讀取轉換後學生ID,就跳過。
                        if (!UpdateRecs.ContainsKey(id))
                            continue;

                        DateTime.TryParse(data["異動日期"], out dt);

                        // 異動代碼
                        string UpdateCode = string.Empty;
                        if (data.ContainsKey("異動代碼"))
                            UpdateCode = data["異動代碼"];

                        // 取得原因及事項
                        string UpdateDesc = string.Empty;
                        if (data.ContainsKey("原因及事項"))
                            UpdateDesc = data["原因及事項"];

                        SHUpdateRecordRecord updateRec = null;
                        // 異動日期+異動代碼 (如果相同有當更新,不同就新增)
                        foreach (SHUpdateRecordRecord urr in UpdateRecs[id])
                        {
                            if (UpdateCode == urr.UpdateCode)
                            {
                                DateTime dt1;
                                DateTime.TryParse(urr.UpdateDate, out dt1);
                                if (dt == dt1)
                                {
                                    // 使用原因及事項當作Key
                                    if(UpdateDesc == urr.UpdateDescription )
                                        updateRec = urr;
                                }
                            }
                        }
                        bool isInsert = true;

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

                        // 這段在做資料填入異動紀錄
                        foreach (string field in e.ImportFields)
                        {
                            string value = data[field].Trim();
                            switch (field)
                            {
                                // 班別
                                case "班別":
                                    updateRec.ClassType = value;
                                    break;
                                // 特殊身份代碼
                                case "特殊身份代碼":
                                    updateRec.SpecialStatus = value;
                                    break;
                                // 異動科別
                                case "異動科別":
                                    updateRec.Department = value;
                                    break;
                                // 年級
                                case "年級":
                                    updateRec.GradeYear = value;
                                    break;
                                // 異動學號
                                case "異動學號":
                                    updateRec.StudentNumber = value;
                                    break;
                                // 異動姓名
                                case "異動姓名":
                                    updateRec.StudentName = value;
                                    break;
                                // 身分證號
                                case "身分證號":
                                    updateRec.IDNumber = value;
                                    break;
                                // 註1
                                case "註1":
                                    updateRec.IDNumberComment = value;
                                    break;
                                //// 異動種類
                                //case "異動種類":
                                //    break;
                                // 異動代碼
                                case "異動代碼":
                                    updateRec.UpdateCode = value;
                                    break;
                                // 異動日期
                                case "異動日期":
                                    DateTime dt1;
                                    if (DateTime.TryParse(value, out dt1))
                                        updateRec.UpdateDate = dt1.ToShortDateString();
                                    break;
                                // 原因及事項
                                case "原因及事項":
                                    updateRec.UpdateDescription = value;
                                    break;
                                // 新學號
                                case "新學號":
                                    updateRec.NewStudentNumber = value;
                                    break;
                                // 更正後資料
                                case "更正後資料":
                                    updateRec.NewData = value;
                                    break;
                                // 舊班別
                                case "舊班別":
                                    updateRec.OldClassType = value;
                                    break;
                                // 舊科別代碼
                                case "舊科別代碼":
                                    updateRec.OldDepartmentCode = value;
                                    break;
                                // 備查日期
                                case "備查日期":
                                    DateTime dt2;
                                    if (DateTime.TryParse(value,out dt2))
                                        updateRec.LastADDate = dt2.ToShortDateString ();
                                    break;
                                // 備查文號
                                case "備查文號":
                                    updateRec.LastADNumber = value;
                                    break;
                                // 核准日期
                                case "核准日期":
                                    DateTime dt3;
                                    if(DateTime.TryParse(value, out dt3))
                                        updateRec.ADDate = dt3.ToShortDateString();
                                    break;
                                // 核准文號
                                case "核准文號":
                                    updateRec.ADNumber = value;
                                    break;
                                // 備註
                                case "備註":
                                    updateRec.GraduateComment = 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 (InsertList.Count > 0)
                        Insert(InsertList);

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

                    PermRecLogProcess prlp = new PermRecLogProcess();
                    prlp.SaveLog("學生.匯入異動", "匯入學籍異動", "匯入學籍異動:共新增" + InsertList.Count + "筆資料,共更新:" + UpdateList.Count + "筆資料");
                    SmartSchool.StudentRelated.Student.Instance.SyncAllBackground();
                }
                catch (Exception ex) { }
            };
        }
        /// <summary>
        /// 產生新生異動(傳入學生編號、異動日期、異動代碼、班別)
        /// </summary>
        /// <param name="StudentIDList"></param>
        /// <param name="UpdateDate"></param>
        /// <param name="UpdateCode"></param>
        /// <param name="ClassType"></param>
        /// <returns></returns>
        public bool Run(List<string> StudentIDList, string UpdateDate, string UpdateCode,string UpdateDesc, string ClassType)
        {
            bool pass = true;
            List<SHBeforeEnrollmentRecord> befRecList = SHBeforeEnrollment.SelectByStudentIDs(StudentIDList);

            Dictionary<string,DAL.SchoolData> schoolDataDict =new Dictionary<string,DAL.SchoolData> ();

            foreach (XElement elm in BL.Get.JHSchoolList().Elements("學校"))
            {
                DAL.SchoolData sd = new DAL.SchoolData();
                sd.SchoolCode=elm.Attribute("代碼").Value ;
                sd.SchoolLocation=elm.Attribute("所在地").Value ;
                sd.SchoolName=elm.Attribute("名稱").Value ;
                sd.SchoolLocationCode=elm.Attribute("所在地代碼").Value;
                 if (sd.SchoolCode.Length > 3)
                    sd.SchoolType=sd.SchoolCode.Substring(2,1);

                string s1=elm.Attribute("所在地").Value +elm.Attribute("名稱").Value;

                if (!schoolDataDict.ContainsKey(s1))
                    schoolDataDict.Add(s1, sd);

                if (!schoolDataDict.ContainsKey(sd.SchoolName))
                    schoolDataDict.Add(sd.SchoolName, sd);

            }

            int SchoolYear=0, Semester=0;
            int.TryParse(K12.Data.School.DefaultSchoolYear, out SchoolYear);
            int.TryParse(K12.Data.School.DefaultSemester, out Semester);

            List<string> _CheckCodeList = (from data in _UpdateCodeList select data.Substring(0, 3)).ToList();

            List<SHUpdateRecordRecord> insertData = new List<SHUpdateRecordRecord>();
            List<SHUpdateRecordRecord> WaitDeleteData = new List<SHUpdateRecordRecord>();

            // 取得學生資料
            List<SHStudentRecord> studRecList = SHStudent.SelectByIDs(StudentIDList);

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

            // 取得已有新生異動
            foreach (SHUpdateRecordRecord rec in SHUpdateRecord.SelectByStudentIDs(StudentIDList))
            {
                if (_CheckCodeList.Contains(rec.UpdateCode))
                {
                    WaitDeleteData.Add(rec);
                    if (!SIDList.Contains(rec.StudentID))
                        SIDList.Add(rec.StudentID);
                }
            }

            bool checkdelData=true;

            // 已有資料是否覆蓋
            if (SIDList.Count > 0)
            {

                WarningForm wf = new WarningForm();
                wf.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                wf.SetStudentCount(SIDList.Count);
                wf.SetStudRec(studRecList);
                wf.SetUpdateRecList(WaitDeleteData);
                if (wf.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                {
                    checkdelData = false;
                    pass = false;
                }
            }

            // 清掉舊資料
            if (checkdelData)
            {
                SHUpdateRecord.Delete(WaitDeleteData);
            }

            // 取得新生異動
            foreach (SHStudentRecord studRec in studRecList)
            {
                // 不刪除代表不需要新增,所以略過
                if(checkdelData== false)
                    if (SIDList.Contains(studRec.ID))
                        continue;

                SHUpdateRecordRecord NewUpdateRec = new SHUpdateRecordRecord();

                if (SchoolYear > 0)
                    NewUpdateRec.SchoolYear = SchoolYear;

                if (Semester > 0)
                    NewUpdateRec.Semester = Semester;

                if (studRec.Class != null)
                    if (studRec.Class.GradeYear.HasValue)
                        NewUpdateRec.GradeYear = studRec.Class.GradeYear.Value.ToString();

                NewUpdateRec.GraduateComment = "";
                NewUpdateRec.UpdateCode = UpdateCode;
                NewUpdateRec.UpdateDescription = UpdateDesc;
                NewUpdateRec.UpdateDate = UpdateDate;
                NewUpdateRec.ClassType = ClassType;

                NewUpdateRec.SpecialStatus = DAL.DALTransfer.GetSpecialCode(studRec.ID);

                if (studRec.Department != null)
                {
                    NewUpdateRec.Department = studRec.Department.FullName;
                }
                NewUpdateRec.StudentID = studRec.ID;
                NewUpdateRec.StudentName = studRec.Name;
                NewUpdateRec.StudentNumber = studRec.StudentNumber;
                NewUpdateRec.IDNumber = studRec.IDNumber;
                if (studRec.Birthday.HasValue)
                    NewUpdateRec.Birthdate = studRec.Birthday.Value.ToShortDateString();
                NewUpdateRec.Gender = studRec.Gender;

                if (int.Parse(UpdateCode) > 5)
                    NewUpdateRec.GraduateComment = "1";

                foreach (SHBeforeEnrollmentRecord brfRec in befRecList)
                {
                    if (brfRec.RefStudentID == NewUpdateRec.StudentID)
                    {
                        NewUpdateRec.GraduateSchool = brfRec.School;
                        NewUpdateRec.GraduateSchoolYear = brfRec.GraduateSchoolYear;

                        // 用學校名稱解析
                        if (!string.IsNullOrEmpty(brfRec.School))
                        {
                            string key = brfRec.SchoolLocation.Replace("台", "臺") + brfRec.School.Trim();
                            if (schoolDataDict.ContainsKey(key))
                            {
                                NewUpdateRec.GraduateSchoolCode = schoolDataDict[key].SchoolCode;
                                NewUpdateRec.GraduateSchoolLocationCode = schoolDataDict[key].SchoolLocationCode;
                            }
                        }
                    }

                }
                insertData.Add(NewUpdateRec);
            }

            // 新增異動
            SHUpdateRecord.Insert(insertData);

            return pass;
        }
        public UserControl CreateByUpdateType(string FormUpdateType)
        {
            // 001-新生
            List<XElement> UpdateCodeElms = (from elm in _UpdateCode.Elements("異動") where elm.Element("分類").Value == FormUpdateType select elm).ToList();

            if (_StudUpdateRec == null)
                _StudUpdateRec = _DefStudUpdateRec;

                // 日校
                if (FormUpdateType == "學籍異動")
                    return new UpdateRecordInfo01(_StudUpdateRec, _prlp, UpdateCodeElms);
                else if (FormUpdateType == "轉入異動")
                    return new UpdateRecordInfo02(_StudUpdateRec, _prlp, UpdateCodeElms);
                else if (FormUpdateType == "新生異動")
                    return new UpdateRecordInfo03(_StudUpdateRec, _prlp, UpdateCodeElms);
                else if (FormUpdateType == "畢業異動")
                    return new UpdateRecordInfo04(_StudUpdateRec, _prlp, UpdateCodeElms);
                else
                    return null;
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (UpdateRecordEditorPanle.Controls.Count > 0)
            {

                IUpdateRecordInfo IU;
                IU = UpdateRecordEditorPanle.Controls[0] as IUpdateRecordInfo;
                _StudUpdateRec = IU.GetStudUpdateRecord();
                _prlp = IU.GetLogData();

                int codeInt;
                if(_StudUpdateRec!=null)
                if (int.TryParse(_StudUpdateRec.UpdateCode, out codeInt) && _actMode== actMode.新增)
                {
                    // 檢查是否有新生異動
                    List<SHUpdateRecordRecord> UpRec01List = (from data in SHUpdateRecord.SelectByStudentID(_StudentID) where int.Parse(data.UpdateCode) < 100 select data).ToList();
                    if (UpRec01List.Count > 0 && codeInt<100)
                        if (FISCA.Presentation.Controls.MsgBox.Show("已有" + UpRec01List.Count + "筆新生異動,是否覆蓋", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                            SHUpdateRecord.Delete(UpRec01List);
                        else
                            return;

                    // 檢查是否有畢業異動
                    List<SHUpdateRecordRecord> UpRec05List = (from data in SHUpdateRecord.SelectByStudentID(_StudentID) where int.Parse(data.UpdateCode) > 500 select data).ToList();
                    if (UpRec05List.Count > 0 && codeInt >500)
                        if (FISCA.Presentation.Controls.MsgBox.Show("已有" + UpRec01List.Count + "筆畢業異動,是否覆蓋", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                            SHUpdateRecord.Delete(UpRec05List);
                        else
                            return;
                }

                if (_StudUpdateRec != null)
                {
                    // 儲存學年度學期 年級
                    _StudUpdateRec.SchoolYear = intSchoolYear.Value;
                    _StudUpdateRec.Semester = intSemester.Value;

                    //// 過濾科別:
                    //int deptIdx = _StudUpdateRec.Department.IndexOf(":");
                    //if (deptIdx > 1)
                    //    _StudUpdateRec.Department = _StudUpdateRec.Department.Substring(0, deptIdx);

                    if (cbxGradeYear.Text == "延修生")
                        _StudUpdateRec.GradeYear = "延修生";
                    else
                        _StudUpdateRec.GradeYear = cbxGradeYear.Text;

                    // 儲存異動資料
                    string strItemName="";
                    if (_actMode == actMode.新增)
                    {
                        SHUpdateRecord.Insert(_StudUpdateRec);
                        strItemName = "新增:";
                    }
                    else
                    {
                        SHUpdateRecord.Update(_StudUpdateRec);
                        strItemName = "修改:";
                    }

                    SHStudentRecord studRec = SHStudent.SelectByID(_StudentID );
                    // Log
                    strItemName += "學生姓名:" + studRec.Name + _actMode.ToString();

                    _prlp.SetActionBy("學生", strItemName);
                    _prlp.SaveLog("", ":", "student",_StudentID);
                    _checkSave = true;

                    // 取得 UpdateCode
                    int intUpdateCode;
                    int.TryParse(_StudUpdateRec.UpdateCode, out intUpdateCode);

                    // 學生資料 Cache
                    List<SHStudentRecord> AllStudRec=null;

                    // 復學,學生狀態是非一般,輸入異動代碼是復學,問使用者是否轉成一般。
                    if(intUpdateCode>=221 && intUpdateCode <=226 && studRec.Status != K12.Data.StudentRecord.StudentStatus.一般 )
                    if (FISCA.Presentation.Controls.MsgBox.Show("請問是否將學生狀態變更成一般?", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (AllStudRec == null)
                            AllStudRec = SHStudent.SelectAll();

                            // 檢查將變更學生狀態
                            // 身分證
                            List<string> studIDNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.一般 && stud.IDNumber == studRec.IDNumber select stud.ID).ToList();
                            // 學號
                            List<string> studNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.一般 && stud.StudentNumber == studRec.StudentNumber select stud.ID).ToList();

                            if (studNumber.Count > 0)
                                FISCA.Presentation.Controls.MsgBox.Show("在一般狀態有相同的學號:" + studRec.StudentNumber + ",無法變更學生狀態");

                            if (studIDNumber.Count > 0)
                                FISCA.Presentation.Controls.MsgBox.Show("在一般狀態有相同的身分證號:" + studRec.IDNumber + ",無法變更學生狀態");

                            if (studIDNumber.Count == 0 && studNumber.Count == 0)
                            {
                                studRec.Status = K12.Data.StudentRecord.StudentStatus.一般;
                                SHStudent.Update(studRec);
                            }

                    }

                    // 轉出,學生狀態是一般,輸入異動代碼是轉出,問使用者是否轉成畢業或離校。
                    if (intUpdateCode >= 311 && intUpdateCode <= 316 && studRec.Status == K12.Data.StudentRecord.StudentStatus.一般)
                        if (FISCA.Presentation.Controls.MsgBox.Show("請問是否將學生狀態變更成畢業或離校?", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            if (AllStudRec == null)
                                AllStudRec = SHStudent.SelectAll();

                                // 檢查將變更學生狀態
                                // 身分證
                                List<string> studIDNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.畢業或離校 && stud.IDNumber == studRec.IDNumber select stud.ID).ToList();
                                // 學號
                                List<string> studNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.畢業或離校 && stud.StudentNumber == studRec.StudentNumber select stud.ID).ToList();

                                if (studNumber.Count > 0)
                                    FISCA.Presentation.Controls.MsgBox.Show("在畢業或離校狀態有相同的學號:" + studRec.StudentNumber + ",無法變更學生狀態");

                                if (studIDNumber.Count > 0)
                                    FISCA.Presentation.Controls.MsgBox.Show("在畢業或離校狀態有相同的身分證號:" + studRec.IDNumber + ",無法變更學生狀態");

                                if (studIDNumber.Count == 0 && studNumber.Count == 0)
                                {
                                    studRec.Status = K12.Data.StudentRecord.StudentStatus.畢業或離校;
                                    SHStudent.Update(studRec);
                                }
                        }

                    // 休學,學生狀態是一般,輸入異動代碼是休學,問使用者是否轉成休學。
                    if (intUpdateCode >= 341 && intUpdateCode <= 349 && studRec.Status == K12.Data.StudentRecord.StudentStatus.一般)
                        if (FISCA.Presentation.Controls.MsgBox.Show("請問是否將學生狀態變更成休學?", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            if (AllStudRec == null)
                                AllStudRec = SHStudent.SelectAll();

                                // 檢查將變更學生狀態
                                // 身分證
                                List<string> studIDNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.休學 && stud.IDNumber == studRec.IDNumber select stud.ID).ToList();
                                // 學號
                                List<string> studNumber = (from stud in AllStudRec where stud.Status == K12.Data.StudentRecord.StudentStatus.休學 && stud.StudentNumber == studRec.StudentNumber select stud.ID).ToList();

                                if (studNumber.Count > 0)
                                    FISCA.Presentation.Controls.MsgBox.Show("在休學狀態有相同的學號:" + studRec.StudentNumber + ",無法變更學生狀態");

                                if (studIDNumber.Count > 0)
                                    FISCA.Presentation.Controls.MsgBox.Show("在休學狀態有相同的身分證號:" + studRec.IDNumber + ",無法變更學生狀態");

                                if (studIDNumber.Count == 0 && studNumber.Count == 0)
                                {
                                    studRec.Status = K12.Data.StudentRecord.StudentStatus.休學;
                                    SHStudent.Update(studRec);
                                }

                        }
                    this.Close();
                    // 畫面同步
                    SmartSchool.StudentRelated.Student.Instance.SyncAllBackground();
                }

            }
        }
        /// <summary>
        /// 學籍異動
        /// </summary>
        public UpdateRecordInfo01()
        {
            SHUpdateRecordRecord rec = new SHUpdateRecordRecord();

            InitializeComponent();
            cbxGender.Items.Add("男");
            cbxGender.Items.Add("女");

            _UpdateRec = UpdateRec;
            _prlp = prlp;
            _UpdateCodeElms = UpdateCodeElms;
            _epUpdateCode = new ErrorProvider();

            _UpdateCoodeList = (from x in _UpdateCodeElms select x.Element("代號").Value + " " + x.Element("原因及事項").Value).ToList();
            _DeptList =SHDepartment.SelectAll();

            // 更正學籍顯示對照用
            _updateCodeDict4 = new Dictionary<string, string>();

            // 日進校不同,所以需要檢查:
                // 日校
                _updateCodeDict4.Add("401", "新學號");
                _updateCodeDict4.Add("402", "新姓名");
                _updateCodeDict4.Add("403", "新性別");
                _updateCodeDict4.Add("404", "新籍貫");
                _updateCodeDict4.Add("405", "新生日");
                _updateCodeDict4.Add("406", "新科別");
                _updateCodeDict4.Add("407", "新身分證號");
                _updateCodeDict4.Add("408", "入學資格學校名稱");
                _updateCodeDict4.Add("409", "特殊身分");
                _updateCodeDict4.Add("499", "其他學籍事項");

                if (string.IsNullOrEmpty(_UpdateRec.ExpectGraduateSchoolYear))
                {
                    SHLeaveInfoRecord shl = SHLeaveInfo.SelectByStudentID(_UpdateRec.StudentID);
                    if(shl.SchoolYear.HasValue )
                        _UpdateRec.ExpectGraduateSchoolYear = shl.SchoolYear.Value.ToString();
                }

            _UCodeDict = Utility.UITool.ConvertUpdateCodeDescDict(_UpdateCodeElms);

            _faldn = new UpdateRecordModule_SH_D.Utility.FormAndLogDataManager(_prlp);

            if (!string.IsNullOrEmpty(_UpdateRec.NewStudentNumber))
            {
                int i;
                if (int.TryParse(_UpdateRec.NewStudentNumber.Trim(), out i))
                {
                    _UpdateRec.NewData = i.ToString();
                    _UpdateRec.NewStudentNumber = i.ToString();
                }
                else
                    _UpdateRec.NewStudentNumber = "";
            }

            // 載入資料
            cbxUpdateCode = _faldn.SetFormData(_UpdateRec.UpdateCode, cbxUpdateCode, "異動代碼");
            txtDesc = _faldn.SetFormData(_UpdateRec.UpdateDescription, txtDesc, "原因及事項");
            dtUpdateDate = _faldn.SetFormData(_UpdateRec.UpdateDate, dtUpdateDate, "異動日期");
            txtMemo = _faldn.SetFormData(_UpdateRec.Comment,txtMemo,"備註");
            cbxDept = _faldn.SetFormData(_UpdateRec.Department, cbxDept, "科別");
            cbxClass = _faldn.SetFormData(_UpdateRec.ClassType, cbxClass, "班別");
            txtSpecial = _faldn.SetFormData(_UpdateRec.SpecialStatus,txtSpecial,"特殊身分代碼");
            txtName = _faldn.SetFormData(_UpdateRec.StudentName, txtName, "姓名");
            txtStudentNumber = _faldn.SetFormData(_UpdateRec.StudentNumber ,txtStudentNumber,"學號");
            txtIDNumber = _faldn.SetFormData(_UpdateRec.IDNumber,txtIDNumber,"身分證字號");
            txtNewData = _faldn.SetFormData(_UpdateRec.NewData, txtNewData, "新資料");
            txtIDNumber1 = _faldn.SetFormData(_UpdateRec.IDNumberComment,txtIDNumber1,"註1");
            txtIDNumber2 = _faldn.SetFormData(_UpdateRec.Comment2 , txtIDNumber2, "註2");
            dtLastUpdateDate = _faldn.SetFormData(_UpdateRec.LastADDate, dtLastUpdateDate, "備查日期");
            txtLastDocNo = _faldn.SetFormData(_UpdateRec.LastADNumber, txtLastDocNo, "備查文號");
            dtADDate = _faldn.SetFormData(_UpdateRec.ADDate, dtADDate, "核准日期");
            txtADDocNo = _faldn.SetFormData(_UpdateRec.ADNumber, txtADDocNo, "核准文號");
            cbxGender = _faldn.SetFormData(_UpdateRec.Gender, cbxGender, "性別");
            dtBirthday = _faldn.SetFormData(_UpdateRec.Birthdate, dtBirthday, "生日");
            txtSHSchoolYear = _faldn.SetFormData(_UpdateRec.ExpectGraduateSchoolYear, txtSHSchoolYear, "應畢業學年度");
        }
        private void UpdateRecordItemForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            IUpdateRecordInfo IU;

                if (UpdateRecordEditorPanle.Controls.Count ==0)
                    e.Cancel = true;

                IU = UpdateRecordEditorPanle.Controls[0] as IUpdateRecordInfo;

                //IU.GetStudUpdateRecord();

                _StudUpdateRec = IU.GetStudUpdateRecord();
                // 當資料有改變
                if (IU.GetLogData().GetDataHasChange() && _checkSave ==false || string.IsNullOrEmpty(IU.GetStudUpdateRecord().UpdateCode))
                    if (FISCA.Presentation.Controls.MsgBox.Show("這個動作將放棄目前編輯中的資料,是否確定離開?", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        e.Cancel = true;

                // 當異動代碼是否存在問題,不存在不儲存。
                if (IU.GetStudUpdateRecord() == null)
                    return;
                else
                {
                    List<string> xx = (from elm in _UpdateCode.Elements("異動") where elm.Element("代號").Value == IU.GetStudUpdateRecord().UpdateCode select elm.Element("代號").Value).ToList();
                    if (xx.Count == 0)
                        return;
                }
        }
Exemple #28
0
        void ImportNewStudentsUpdateRecord_DataImport(object sender, DataImportEventArgs e)
        {
            Dictionary <string, string> fieldNameMapping = new Dictionary <string, string>();

            #region 建立匯入欄位名稱跟Xml內欄位對照表
            fieldNameMapping.Add("Department", "異動科別");
            fieldNameMapping.Add("GradeYear", "年級");
            fieldNameMapping.Add("StudentNumber", "異動學號");
            fieldNameMapping.Add("StudentName", "異動姓名");
            fieldNameMapping.Add("IDNumber", "身分證號");
            fieldNameMapping.Add("Gender", "性別");
            fieldNameMapping.Add("Birthdate", "生日");
            fieldNameMapping.Add("UpdateCode", "異動代碼");
            fieldNameMapping.Add("UpdateDate", "異動日期");
            fieldNameMapping.Add("UpdateDescription", "原因及事項");
            fieldNameMapping.Add("NewStudentNumber", "新學號");
            fieldNameMapping.Add("PreviousDepartment", "轉入前學生資料-科別");
            fieldNameMapping.Add("PreviousGradeYear", "轉入前學生資料-年級");
            fieldNameMapping.Add("PreviousSchool", "轉入前學生資料-學校");
            fieldNameMapping.Add("PreviousSchoolLastADDate", "轉入前學生資料-(備查日期)");
            fieldNameMapping.Add("PreviousSchoolLastADNumber", "轉入前學生資料-(備查文號)");
            fieldNameMapping.Add("PreviousStudentNumber", "轉入前學生資料-學號");
            fieldNameMapping.Add("GraduateSchool", "入學資格-畢業國中");
            fieldNameMapping.Add("GraduateSchoolLocationCode", "入學資格-畢業國中所在地代碼");
            fieldNameMapping.Add("LastUpdateCode", "最後異動代碼");
            fieldNameMapping.Add("GraduateCertificateNumber", "畢(結)業證書字號");
            fieldNameMapping.Add("LastADDate", "備查日期");
            fieldNameMapping.Add("LastADNumber", "備查文號");
            fieldNameMapping.Add("ADDate", "核准日期");
            fieldNameMapping.Add("ADNumber", "核准文號");
            fieldNameMapping.Add("Comment", "備註");

            fieldNameMapping.Add("ClassType", "班別");
            fieldNameMapping.Add("SpecialStatus", "特殊身份代碼");
            fieldNameMapping.Add("IDNumberComment", "註1");
            fieldNameMapping.Add("OldClassType", "舊班別");
            fieldNameMapping.Add("OldDepartmentCode", "舊科別代碼");
            fieldNameMapping.Add("GraduateSchoolYear", "入學資格-畢業國中年度");
            fieldNameMapping.Add("GraduateComment", "入學資格-註2");
            #endregion
            List <SHUpdateRecordRecord> InsertUpdateRecords = new List <SHUpdateRecordRecord>();
            List <SHUpdateRecordRecord> UpdateUpdateRecords = new List <SHUpdateRecordRecord>();


            bool insert = false, update = false;
            foreach (RowData row in e.Items)
            {
                if (_NewStudentUpdateRecordInfoList.ContainsKey(row.ID))
                {
                    if (_NewStudentUpdateRecordInfoList[row.ID] == null)
                    {
                        insert = true;
                        #region 新增
                        SHUpdateRecordRecord InsertUpdateRecord = new SHUpdateRecordRecord();

                        InsertUpdateRecord.StudentID = row.ID;

                        foreach (string field in fieldNameMapping.Keys)
                        {
                            string fieldname = fieldNameMapping[field];

                            PropertyInfo Property = InsertUpdateRecord.GetType().GetProperty(field, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

                            if (Property != null)
                            {
                                Property.SetValue(InsertUpdateRecord, row.ContainsKey(fieldname) ? row[fieldname] : string.Empty, null);
                            }
                        }

                        InsertUpdateRecords.Add(InsertUpdateRecord);
                        #endregion
                    }
                    else
                    {
                        update = true;
                        #region 修改
                        SHUpdateRecordRecord UpdateUpdateRecord = new SHUpdateRecordRecord();


                        UpdateUpdateRecord.ID        = _NewStudentUpdateRecordInfoList[row.ID].ID;
                        UpdateUpdateRecord.StudentID = row.ID;

                        foreach (string field in fieldNameMapping.Keys)
                        {
                            string fieldname = fieldNameMapping[field];

                            PropertyInfo Property = UpdateUpdateRecord.GetType().GetProperty(field, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

                            if (Property != null)
                            {
                                Property.SetValue(UpdateUpdateRecord, row.ContainsKey(fieldname) ? row[fieldname] : string.Empty, null);
                            }
                        }

                        UpdateUpdateRecords.Add(UpdateUpdateRecord);
                        #endregion
                    }
                }
            }
            if (insert)
            {
                try
                {
                    SHUpdateRecord.Insert(InsertUpdateRecords);
                }
                catch (Exception ve)
                {
                }
            }
            if (update)
            {
                try
                {
                    SHUpdateRecord.Update(UpdateUpdateRecords);
                }
                catch (Exception ve)
                {
                }
            }
        }
Exemple #29
0
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            // 取得學生資料
            Dictionary <string, SHStudentRecord> Students = new Dictionary <string, SHStudentRecord>();



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

            wizard.PackageLimit = 3000;
            wizard.ImportableFields.AddRange("班別", "特殊身份代碼", "異動科別", "年級", "異動學號", "異動姓名", "身分證號", "註1", "異動代碼", "異動日期", "原因及事項", "新學號", "更正後資料", "舊班別", "舊科別代碼", "備查日期", "備查文號", "核准日期", "核准文號", "備註");
            wizard.RequiredFields.AddRange("異動代碼", "異動日期");
            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                Students.Clear();
                UpdateRecs.Clear();

                // 取得學生資料
                foreach (SHStudentRecord studRec in SHStudent.SelectByIDs(e.List))
                {
                    if (!Students.ContainsKey(studRec.ID))
                    {
                        Students.Add(studRec.ID, studRec);
                    }
                }
                foreach (string str in Students.Keys)
                {
                    List <SHUpdateRecordRecord> UpdRecList = new List <SHUpdateRecordRecord>();
                    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 (SHUpdateRecordRecord UpdRec in SHUpdateRecord.SelectByStudentIDs(e.List))
                    {
                        // 過濾非符合標準的異動(目前是學籍)
                        if (!_UpdateCodeList.Contains(UpdRec.UpdateCode))
                        {
                            continue;
                        }

                        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;
                // 檢查學生是否存在
                SHStudentRecord studRec = null;
                if (Students.ContainsKey(e.Data.ID))
                {
                    studRec = Students[e.Data.ID];
                }
                else
                {
                    e.ErrorMessage = "沒有這位學生" + e.Data.ID;
                    return;
                }

                // 驗證格式資料
                bool InputFormatPass = true;
                foreach (string field in e.SelectFields)
                {
                    string value = e.Data[field].Trim();
                    //// 驗證$無法匯入
                    //if (value.IndexOf('$') > -1)
                    //{
                    //    e.ErrorFields.Add(field, "儲存格有$無法匯入.");
                    //    break;
                    //}
                    switch (field)
                    {
                    default:
                        break;

                    //// 班別
                    //case "班別": break;
                    //// 特殊身份代碼
                    //case "特殊身份代碼": break;
                    //// 異動科別
                    //case "異動科別": break;
                    //// 年級
                    //case "年級": break;
                    //// 異動學號
                    //case "異動學號": break;
                    //// 異動姓名
                    //case "異動姓名": break;
                    //// 身分證號
                    //case "身分證號": break;
                    //// 註1
                    //case "註1": break;
                    //// 異動種類
                    //case "異動種類": break;
                    // 異動代碼
                    case "異動代碼":
                        if (!_UpdateCodeList.Contains(value))
                        {
                            InputFormatPass &= false;
                            e.ErrorFields.Add(field, "非學籍異動代碼!");
                        }
                        break;

                    // 異動日期(必填)
                    case "異動日期":
                        DateTime dtC1;
                        if (DateTime.TryParse(value, out dtC1))
                        {
                        }
                        else
                        {
                            InputFormatPass &= false;
                            e.ErrorFields.Add(field, "日期錯誤!");
                        }

                        break;

                    case "備查日期":
                    case "核准日期":
                        DateTime dtC2;
                        if (value.Trim() != "")
                        {
                            if (DateTime.TryParse(value, out dtC2))
                            {
                            }
                            else
                            {
                                InputFormatPass &= false;
                                e.ErrorFields.Add(field, "日期錯誤!");
                            }
                        }
                        break;
                        //// 原因及事項
                        //case "原因及事項": break;
                        //// 新學號
                        //case "新學號": break;
                        //// 更正後資料
                        //case "更正後資料": break;
                        //// 舊班別
                        //case "舊班別": break;
                        //// 舊科別代碼
                        //case "舊科別代碼": break;
                        //// 備查日期
                        //case "備查日期":
                        //    break;
                        //// 備查文號
                        //case "備查文號": break;
                        //// 核准日期
                        //case "核准日期": break;
                        //// 核准文號
                        //case "核准文號": break;
                        //// 備註
                        //case "備註": 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 <SHUpdateRecordRecord> InsertList = new List <SHUpdateRecordRecord>();
                List <SHUpdateRecordRecord> UpdateList = new List <SHUpdateRecordRecord>();

                // 檢查新增或更新方式:
                // 每筆 Key 為:異動日期+異動代碼+原因及事項,如果三者內容相同更新,如果不同就新增。
                foreach (string id in id_Rows.Keys)
                {
                    DateTime dt;

                    // 讀取工作表內資料
                    foreach (RowData data in id_Rows[id])
                    {
                        // 當異動記錄內沒有工作表讀取轉換後學生ID,就跳過。
                        if (!UpdateRecs.ContainsKey(id))
                        {
                            continue;
                        }

                        DateTime.TryParse(data["異動日期"], out dt);

                        // 異動代碼
                        string UpdateCode = string.Empty;
                        if (data.ContainsKey("異動代碼"))
                        {
                            UpdateCode = data["異動代碼"];
                        }

                        // 取得原因及事項
                        string UpdateDesc = string.Empty;
                        if (data.ContainsKey("原因及事項"))
                        {
                            UpdateDesc = data["原因及事項"];
                        }


                        SHUpdateRecordRecord updateRec = null;
                        // 異動日期+異動代碼 (如果相同有當更新,不同就新增)
                        foreach (SHUpdateRecordRecord urr in UpdateRecs[id])
                        {
                            if (UpdateCode == urr.UpdateCode)
                            {
                                DateTime dt1;
                                DateTime.TryParse(urr.UpdateDate, out dt1);
                                if (dt == dt1)
                                {
                                    // 使用原因及事項當作Key
                                    if (UpdateDesc == urr.UpdateDescription)
                                    {
                                        updateRec = urr;
                                    }
                                }
                            }
                        }
                        bool isInsert = true;

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

                        // 這段在做資料填入異動紀錄
                        foreach (string field in e.ImportFields)
                        {
                            string value = data[field].Trim();
                            switch (field)
                            {
                            // 班別
                            case "班別":
                                updateRec.ClassType = value;
                                break;

                            // 特殊身份代碼
                            case "特殊身份代碼":
                                updateRec.SpecialStatus = value;
                                break;

                            // 異動科別
                            case "異動科別":
                                updateRec.Department = value;
                                break;

                            // 年級
                            case "年級":
                                updateRec.GradeYear = value;
                                break;

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

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

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

                            // 註1
                            case "註1":
                                updateRec.IDNumberComment = value;
                                break;

                            //// 異動種類
                            //case "異動種類":
                            //    break;
                            // 異動代碼
                            case "異動代碼":
                                updateRec.UpdateCode = value;
                                break;

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

                            // 原因及事項
                            case "原因及事項":
                                updateRec.UpdateDescription = value;
                                break;

                            // 新學號
                            case "新學號":
                                updateRec.NewStudentNumber = value;
                                break;

                            // 更正後資料
                            case "更正後資料":
                                updateRec.NewData = value;
                                break;

                            // 舊班別
                            case "舊班別":
                                updateRec.OldClassType = value;
                                break;

                            // 舊科別代碼
                            case "舊科別代碼":
                                updateRec.OldDepartmentCode = value;
                                break;

                            // 備查日期
                            case "備查日期":
                                DateTime dt2;
                                if (DateTime.TryParse(value, out dt2))
                                {
                                    updateRec.LastADDate = dt2.ToShortDateString();
                                }
                                break;

                            // 備查文號
                            case "備查文號":
                                updateRec.LastADNumber = value;
                                break;

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

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

                            // 備註
                            case "備註":
                                updateRec.GraduateComment = 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 (InsertList.Count > 0)
                    {
                        Insert(InsertList);
                    }

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

                    PermRecLogProcess prlp = new PermRecLogProcess();
                    prlp.SaveLog("學生.匯入異動", "匯入學籍異動", "匯入學籍異動:共新增" + InsertList.Count + "筆資料,共更新:" + UpdateList.Count + "筆資料");
                    SmartSchool.StudentRelated.Student.Instance.SyncAllBackground();
                }
                catch (Exception ex) { }
            };
        }
        void _bgWorkerRun_DoWork(object sender, DoWorkEventArgs e)
        {
            // 處理資料
            try
            {
                _bgWorkerRun.ReportProgress(1);
                // 刪除舊資料
                List<SHUpdateRecordRecord> _oldDataList = _StudHasGraduateRecDict.Values.ToList();
                SHUpdateRecord.Delete(_oldDataList);

                int SchoolYear = int.Parse(K12.Data.School.DefaultSchoolYear);
                int Semester = int.Parse(K12.Data.School.DefaultSemester);

                _bgWorkerRun.ReportProgress(10);
                foreach (string sid in _StudentIDList)
                {
                    if (!_StudentDict.ContainsKey(sid))
                        continue;

                    SHUpdateRecordRecord rec = new SHUpdateRecordRecord();
                    // 學年度
                    rec.SchoolYear = SchoolYear;
                    // 學期
                    rec.Semester = Semester;

                    rec.StudentID = sid;

                    string ClassName = "";
                    string DeptName = "";

                    // 年級
                    if (_ClassRecDict.ContainsKey(_StudentDict[sid].RefClassID))
                    {
                        if (_ClassRecDict[_StudentDict[sid].RefClassID].GradeYear.HasValue)
                        {
                            rec.GradeYear = _ClassRecDict[_StudentDict[sid].RefClassID].GradeYear.Value.ToString();

                            // 班級名稱
                            ClassName = _ClassRecDict[_StudentDict[sid].RefClassID].Name;

                            // 科別名稱
                            if (_DeptRecDict.ContainsKey(_ClassRecDict[_StudentDict[sid].RefClassID].RefDepartmentID))
                                DeptName = _DeptRecDict[_ClassRecDict[_StudentDict[sid].RefClassID].RefDepartmentID].FullName;
                        }
                        else
                            rec.GradeYear = "";
                    }

                    // 畢業代碼
                    rec.UpdateCode = "501";

                    // 原因及事項
                    rec.UpdateDescription = "畢業";

                    // 異動日期
                    rec.UpdateDate = _UpdateDate.ToShortDateString();

                    // 姓名
                    rec.StudentName = _StudentDict[sid].Name;

                    // 學號
                    rec.StudentNumber = _StudentDict[sid].StudentNumber;

                    // 身分證字號
                    rec.IDNumber = _StudentDict[sid].IDNumber;

                    // 生日
                    if (_StudentDict[sid].Birthday.HasValue)
                        rec.Birthdate = _StudentDict[sid].Birthday.Value.ToShortDateString();

                    // 性別
                    rec.Gender = _StudentDict[sid].Gender;

                    if (_StudLastupdateRecDict.ContainsKey(sid))
                    {
                        // 備查日期
                        rec.LastADDate = _StudLastupdateRecDict[sid].ADDate;

                        // 備查文號
                        rec.LastADNumber = _StudLastupdateRecDict[sid].ADNumber;

                        // 最後異動代碼
                        rec.LastUpdateCode = _StudLastupdateRecDict[sid].UpdateCode;
                    }
                    // 畢業證書字號
                    if (_LeaveInfoRecordDict.ContainsKey(sid))
                    {
                        rec.GraduateCertificateNumber = _LeaveInfoRecordDict[sid].DiplomaNumber;
                        rec.Department = DeptName;
                        rec.ExpectGraduateSchoolYear = SchoolYear.ToString();
                        _LeaveInfoRecordDict[sid].SchoolYear = SchoolYear;
                        _LeaveInfoRecordDict[sid].ClassName = ClassName;
                        _LeaveInfoRecordDict[sid].DepartmentName = DeptName;
                    }
                    _InsertDataList.Add(rec);

                }
                _bgWorkerRun.ReportProgress(70);
                // 新增資料
                if (_InsertDataList.Count > 0)
                    SHUpdateRecord.Insert(_InsertDataList);

                // 更新畢業離校資訊 離校學年度、離校科別、離校班級
                SHLeaveInfo.Update(_LeaveInfoRecordDict.Values.ToList());

                _bgWorkerRun.ReportProgress(99);
            }
            catch (Exception ex)
            {
                e.Result = ex;
                e.Cancel = true;
            }
        }
        public override string Import(List <IRowStream> Rows)
        {
            _InsertRecList.Clear();
            _UpdateRecList.Clear();
            // 取得 Rows內學號
            List <string> StudentNumberList = new List <string>();

            foreach (IRowStream ir in Rows)
            {
                if (ir.Contains("學號"))
                {
                    StudentNumberList.Add(ir.GetValue("學號"));
                }
            }

            // 透過學號去取得學生ID
            Dictionary <string, string> StudNumDict = DAL.FDQuery.GetStudenNumberStatusDictByStudentNumber(StudentNumberList);

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

            foreach (IRowStream ir in Rows)
            {
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    string key = ir.GetValue("學號") + "_" + ir.GetValue("狀態");
                    if (StudNumDict.ContainsKey(key))
                    {
                        StudentIDList.Add(StudNumDict[key]);
                    }
                }
            }

            List <string> updateCodeList = Utility.UITool.GetUpdateCodeListByUpdateType("轉入異動");

            // 取得轉入異動資料
            List <SHUpdateRecordRecord> updateRecList = (from data in SHUpdateRecord.SelectByStudentIDs(StudentIDList) where updateCodeList.Contains(data.UpdateCode) select data).ToList();
            int totalCount = 0;

            // 判斷更新或新增
            foreach (IRowStream ir in Rows)
            {
                totalCount++;
                this.ImportProgress = totalCount;
                bool isInsert = true;
                SHUpdateRecordRecord UpdateRec = null;
                string StudentID = "";

                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    string key = ir.GetValue("學號") + "_" + ir.GetValue("狀態");
                    if (StudNumDict.ContainsKey(key))
                    {
                        StudentID = StudNumDict[key];
                    }
                }

                if (string.IsNullOrEmpty(StudentID))
                {
                    continue;
                }

                DateTime dt;
                DateTime.TryParse(ir.GetValue("異動日期"), out dt);

                foreach (SHUpdateRecordRecord rec in updateRecList.Where(x => x.StudentID == StudentID))
                {
                    string updateCode = string.Format("{0:000}", int.Parse(ir.GetValue("異動代碼").Trim()));
                    if (rec.UpdateCode.Trim() == updateCode)
                    {
                        DateTime dt1;
                        DateTime.TryParse(rec.UpdateDate, out dt1);

                        if (dt.ToShortDateString() == dt1.ToShortDateString())
                        {
                            isInsert  = false;
                            UpdateRec = rec;
                        }
                    }
                }

                if (isInsert || UpdateRec == null)
                {
                    UpdateRec = new SHUpdateRecordRecord();
                }

                UpdateRec.StudentID = StudentID;

                if (isInsert)
                {
                    int sy, ss;
                    // 學年度
                    if (ir.Contains("學年度"))
                    {
                        if (int.TryParse(ir.GetValue("學年度"), out sy))
                        {
                            UpdateRec.SchoolYear = sy;
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("學年度")))
                        {
                            UpdateRec.SchoolYear = null;
                        }
                    }
                    // 學期
                    if (ir.Contains("學期"))
                    {
                        if (int.TryParse(ir.GetValue("學期"), out ss))
                        {
                            UpdateRec.Semester = ss;
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("學期")))
                        {
                            UpdateRec.Semester = null;
                        }
                    }
                    // 異動年級
                    if (ir.Contains("異動年級"))
                    {
                        UpdateRec.GradeYear = ir.GetValue("異動年級");
                    }

                    // 異動代碼
                    UpdateRec.UpdateCode = string.Format("{0:000}", int.Parse(ir.GetValue("異動代碼").Trim()));

                    // 原因及事項
                    if (ir.Contains("原因及事項"))
                    {
                        UpdateRec.UpdateDescription = ir.GetValue("原因及事項");
                    }


                    // 異動日期
                    UpdateRec.UpdateDate = dt.ToShortDateString();

                    // 備註
                    if (ir.Contains("備註"))
                    {
                        UpdateRec.Comment = ir.GetValue("備註");
                    }

                    // 班別
                    if (ir.Contains("班別"))
                    {
                        UpdateRec.ClassType = ir.GetValue("班別");
                    }

                    // 科別
                    if (ir.Contains("科別"))
                    {
                        UpdateRec.Department = ir.GetValue("科別");
                    }

                    // 特殊身分代碼
                    if (ir.Contains("特殊身分代碼"))
                    {
                        UpdateRec.SpecialStatus = ir.GetValue("特殊身分代碼");
                    }

                    // 入學資格證明文件
                    if (ir.Contains("入學資格證明文件"))
                    {
                        UpdateRec.GraduateDocument = ir.GetValue("入學資格證明文件");
                    }

                    // 異動姓名
                    if (ir.Contains("異動姓名"))
                    {
                        UpdateRec.StudentName = ir.GetValue("異動姓名");
                    }

                    // 異動學號
                    if (ir.Contains("異動學號"))
                    {
                        UpdateRec.StudentNumber = ir.GetValue("異動學號");
                    }

                    // 異動身分證字號
                    if (ir.Contains("異動身分證字號"))
                    {
                        UpdateRec.IDNumber = ir.GetValue("異動身分證字號");
                    }

                    // 異動生日
                    if (ir.Contains("異動生日"))
                    {
                        DateTime dtd;
                        if (DateTime.TryParse(ir.GetValue("異動生日"), out dtd))
                        {
                            UpdateRec.Birthdate = dtd.ToShortDateString();
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("異動生日")))
                        {
                            UpdateRec.Birthdate = "";
                        }
                    }
                    // 異動身分證註記
                    if (ir.Contains("異動身分證註記"))
                    {
                        UpdateRec.IDNumberComment = ir.GetValue("異動身分證註記");
                    }

                    // 異動性別
                    if (ir.Contains("異動性別"))
                    {
                        UpdateRec.Gender = ir.GetValue("異動性別");
                    }

                    // 原就讀學校
                    if (ir.Contains("原就讀學校"))
                    {
                        UpdateRec.PreviousSchool = ir.GetValue("原就讀學校");
                    }

                    // 原就讀學號
                    if (ir.Contains("原就讀學號"))
                    {
                        UpdateRec.PreviousStudentNumber = ir.GetValue("原就讀學號");
                    }

                    // 原就讀科別
                    if (ir.Contains("原就讀科別"))
                    {
                        UpdateRec.PreviousDepartment = ir.GetValue("原就讀科別");
                    }

                    // 原就讀年級
                    if (ir.Contains("原就讀年級"))
                    {
                        UpdateRec.PreviousGradeYear = ir.GetValue("原就讀年級");
                    }

                    // 原就讀學期
                    if (ir.Contains("原就讀學期"))
                    {
                        UpdateRec.PreviousSemester = ir.GetValue("原就讀學期");
                    }


                    // 原就讀備查日期
                    if (ir.Contains("原就讀備查日期"))
                    {
                        DateTime dta;
                        if (DateTime.TryParse(ir.GetValue("原就讀備查日期"), out dta))
                        {
                            UpdateRec.PreviousSchoolLastADDate = dta.ToShortDateString();
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("原就讀備查日期")))
                        {
                            UpdateRec.PreviousSchoolLastADDate = "";
                        }
                    }
                    // 原就讀備查文號
                    if (ir.Contains("原就讀備查文號"))
                    {
                        UpdateRec.PreviousSchoolLastADNumber = ir.GetValue("原就讀備查文號");
                    }



                    // 核准日期
                    if (ir.Contains("核准日期"))
                    {
                        DateTime dta;
                        if (DateTime.TryParse(ir.GetValue("核准日期"), out dta))
                        {
                            UpdateRec.ADDate = dta.ToShortDateString();
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("核准日期")))
                        {
                            UpdateRec.ADDate = "";
                        }
                    }
                    // 核准文號
                    if (ir.Contains("核准文號"))
                    {
                        UpdateRec.ADNumber = ir.GetValue("核准文號");
                    }
                    //轉入身分別代碼
                    if (ir.Contains("轉入身分別代碼"))
                    {
                        UpdateRec.Comment2 = ir.GetValue("轉入身分別代碼");
                    }
                }
                else
                {
                    // 更新有勾選
                    int sy, ss;
                    // 學年度
                    if (ir.Contains("學年度") && mOption.SelectedFields.Contains("學年度"))
                    {
                        if (int.TryParse(ir.GetValue("學年度"), out sy))
                        {
                            UpdateRec.SchoolYear = sy;
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("學年度")))
                        {
                            UpdateRec.SchoolYear = null;
                        }
                    }
                    // 學期
                    if (ir.Contains("學期") && mOption.SelectedFields.Contains("學期"))
                    {
                        if (int.TryParse(ir.GetValue("學期"), out ss))
                        {
                            UpdateRec.Semester = ss;
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("學期")))
                        {
                            UpdateRec.Semester = null;
                        }
                    }
                    // 異動年級
                    if (ir.Contains("異動年級") && mOption.SelectedFields.Contains("異動年級"))
                    {
                        UpdateRec.GradeYear = ir.GetValue("異動年級");
                    }

                    //// 異動代碼
                    //UpdateRec.UpdateCode = ir.GetValue("異動代碼").Trim();

                    // 原因及事項
                    if (ir.Contains("原因及事項") && mOption.SelectedFields.Contains("原因及事項"))
                    {
                        UpdateRec.UpdateDescription = ir.GetValue("原因及事項");
                    }


                    //// 異動日期
                    //UpdateRec.UpdateDate = dt.ToShortDateString();

                    // 備註
                    if (ir.Contains("備註") && mOption.SelectedFields.Contains("備註"))
                    {
                        UpdateRec.Comment = ir.GetValue("備註");
                    }

                    // 班別
                    if (ir.Contains("班別") && mOption.SelectedFields.Contains("班別"))
                    {
                        UpdateRec.ClassType = ir.GetValue("班別");
                    }

                    // 科別
                    if (ir.Contains("科別") && mOption.SelectedFields.Contains("科別"))
                    {
                        UpdateRec.Department = ir.GetValue("科別");
                    }

                    // 特殊身分代碼
                    if (ir.Contains("特殊身分代碼") && mOption.SelectedFields.Contains("特殊身分代碼"))
                    {
                        UpdateRec.SpecialStatus = ir.GetValue("特殊身分代碼");
                    }

                    // 入學資格證明文件
                    if (ir.Contains("入學資格證明文件") && mOption.SelectedFields.Contains("入學資格證明文件"))
                    {
                        UpdateRec.GraduateDocument = ir.GetValue("入學資格證明文件");
                    }

                    // 異動姓名
                    if (ir.Contains("異動姓名") && mOption.SelectedFields.Contains("異動姓名"))
                    {
                        UpdateRec.StudentName = ir.GetValue("異動姓名");
                    }

                    // 異動學號
                    if (ir.Contains("異動學號") && mOption.SelectedFields.Contains("異動學號"))
                    {
                        UpdateRec.StudentNumber = ir.GetValue("異動學號");
                    }

                    // 異動身分證字號
                    if (ir.Contains("異動身分證字號") && mOption.SelectedFields.Contains("異動身分證字號"))
                    {
                        UpdateRec.IDNumber = ir.GetValue("異動身分證字號");
                    }

                    // 異動生日
                    if (ir.Contains("異動生日") && mOption.SelectedFields.Contains("異動生日"))
                    {
                        DateTime dtd;
                        if (DateTime.TryParse(ir.GetValue("異動生日"), out dtd))
                        {
                            UpdateRec.Birthdate = dtd.ToShortDateString();
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("異動生日")))
                        {
                            UpdateRec.Birthdate = "";
                        }
                    }
                    // 異動身分證註記
                    if (ir.Contains("異動身分證註記") && mOption.SelectedFields.Contains("異動身分證註記"))
                    {
                        UpdateRec.IDNumberComment = ir.GetValue("異動身分證註記");
                    }

                    // 異動性別
                    if (ir.Contains("異動性別") && mOption.SelectedFields.Contains("異動性別"))
                    {
                        UpdateRec.Gender = ir.GetValue("異動性別");
                    }


                    // 原就讀學校
                    if (ir.Contains("原就讀學校") && mOption.SelectedFields.Contains("原就讀學校"))
                    {
                        UpdateRec.PreviousSchool = ir.GetValue("原就讀學校");
                    }

                    // 原就讀學號
                    if (ir.Contains("原就讀學號") && mOption.SelectedFields.Contains("原就讀學號"))
                    {
                        UpdateRec.PreviousStudentNumber = ir.GetValue("原就讀學號");
                    }

                    // 原就讀科別
                    if (ir.Contains("原就讀科別") && mOption.SelectedFields.Contains("原就讀科別"))
                    {
                        UpdateRec.PreviousDepartment = ir.GetValue("原就讀科別");
                    }

                    // 原就讀年級
                    if (ir.Contains("原就讀年級") && mOption.SelectedFields.Contains("原就讀年級"))
                    {
                        UpdateRec.PreviousGradeYear = ir.GetValue("原就讀年級");
                    }

                    // 原就讀學期
                    if (ir.Contains("原就讀學期") && mOption.SelectedFields.Contains("原就讀學期"))
                    {
                        UpdateRec.PreviousSemester = ir.GetValue("原就讀學期");
                    }



                    // 原就讀備查日期
                    if (ir.Contains("原就讀備查日期") && mOption.SelectedFields.Contains("原就讀備查日期"))
                    {
                        DateTime dta;
                        if (DateTime.TryParse(ir.GetValue("原就讀備查日期"), out dta))
                        {
                            UpdateRec.PreviousSchoolLastADDate = dta.ToShortDateString();
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("原就讀備查日期")))
                        {
                            UpdateRec.PreviousSchoolLastADDate = "";
                        }
                    }
                    // 原就讀備查文號
                    if (ir.Contains("原就讀備查文號") && mOption.SelectedFields.Contains("原就讀備查文號"))
                    {
                        UpdateRec.PreviousSchoolLastADNumber = ir.GetValue("原就讀備查文號");
                    }


                    // 核准日期
                    if (ir.Contains("核准日期") && mOption.SelectedFields.Contains("核准日期"))
                    {
                        DateTime dta;
                        if (DateTime.TryParse(ir.GetValue("核准日期"), out dta))
                        {
                            UpdateRec.ADDate = dta.ToShortDateString();
                        }

                        if (string.IsNullOrEmpty(ir.GetValue("核准日期")))
                        {
                            UpdateRec.ADDate = "";
                        }
                    }
                    // 核准文號
                    if (ir.Contains("核准文號") && mOption.SelectedFields.Contains("核准文號"))
                    {
                        UpdateRec.ADNumber = ir.GetValue("核准文號");
                    }

                    // 轉入身分別代碼
                    if (ir.Contains("轉入身分別代碼") && mOption.SelectedFields.Contains("轉入身分別代碼"))
                    {
                        UpdateRec.Comment2 = ir.GetValue("轉入身分別代碼");
                    }
                }


                if (isInsert)
                {
                    _InsertRecList.Add(UpdateRec);
                }
                else
                {
                    _UpdateRecList.Add(UpdateRec);
                }
            }

            // 執行更新或新增
            if (_InsertRecList.Count > 0)
            {
                SHUpdateRecord.Insert(_InsertRecList);
            }

            if (_UpdateRecList.Count > 0)
            {
                SHUpdateRecord.Update(_UpdateRecList);
            }

            return("");
        }
Exemple #32
0
        void _bgWorkerLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            // 取得就學生畢業異動資料
            _StudHasGraduateRecDict.Clear();
            List <SHUpdateRecordRecord> recList = SHUpdateRecord.SelectByStudentIDs(_StudentIDList);

            foreach (SHUpdateRecordRecord rec in recList)
            {
                // 不是畢業異動跳過
                if (rec.UpdateCode != "501")
                {
                    continue;
                }

                if (!_StudHasGraduateRecDict.ContainsKey(rec.StudentID))
                {
                    _StudHasGraduateRecDict.Add(rec.StudentID, rec);
                }
            }

            // 取得最後一筆異動
            _StudLastupdateRecDict.Clear();
            foreach (string sid in _StudentIDList)
            {
                List <SHUpdateRecordRecord> recL = (from data in recList where data.StudentID == sid && data.ADDate.Trim() != "" orderby DateTime.Parse(data.ADDate) descending, int.Parse(data.ID) descending select data).ToList();
                if (recL.Count > 0)
                {
                    SHUpdateRecordRecord r1 = recL[0];
                    if (!_StudLastupdateRecDict.ContainsKey(r1.StudentID))
                    {
                        _StudLastupdateRecDict.Add(r1.StudentID, r1);
                    }
                }
            }

            // 學生資料
            _StudentDict.Clear();
            foreach (SHStudentRecord rec in SHStudent.SelectByIDs(_StudentIDList))
            {
                _StudentDict.Add(rec.ID, rec);
            }

            // 畢業證書
            _LeaveInfoRecordDict.Clear();
            foreach (SHLeaveInfoRecord rec in SHLeaveInfo.SelectByStudentIDs(_StudentIDList))
            {
                if (!_LeaveInfoRecordDict.ContainsKey(rec.RefStudentID))
                {
                    _LeaveInfoRecordDict.Add(rec.RefStudentID, rec);
                }
            }

            // 班級
            _ClassRecDict.Clear();
            foreach (SHClassRecord rec in SHClass.SelectAll())
            {
                if (!_ClassRecDict.ContainsKey(rec.ID))
                {
                    _ClassRecDict.Add(rec.ID, rec);
                }
            }

            // 科別
            _DeptRecDict.Clear();
            foreach (SHDepartmentRecord rec in SHDepartment.SelectAll())
            {
                if (!_DeptRecDict.ContainsKey(rec.ID))
                {
                    _DeptRecDict.Add(rec.ID, rec);
                }
            }
        }
        /// <summary>
        /// 新生異動
        /// </summary>
        public UpdateRecordInfo03(SHUpdateRecordRecord UpdateRec, PermRecLogProcess prlp, List<XElement> UpdateCodeElms)
        {
            InitializeComponent();
            cbxGender.Items.Add("男");
            cbxGender.Items.Add("女");

            _UpdateRec = UpdateRec;
            _prlp = prlp;
            _UpdateCodeElms = UpdateCodeElms;
            _UpdateCoodeList = (from x in _UpdateCodeElms select x.Element("代號").Value + " " + x.Element("原因及事項").Value).ToList();
            _DeptList = SHDepartment.SelectAll();
            _epUpdateCode = new ErrorProvider();

            _UCodeDict = Utility.UITool.ConvertUpdateCodeDescDict(_UpdateCodeElms);

            _faldn = new UpdateRecordModule_SH_D.Utility.FormAndLogDataManager(_prlp);

            // 載入資料
            // 載入預設前級畢業資訊
            Dictionary<string, DAL.SchoolData> schoolDataDict = new Dictionary<string, DAL.SchoolData>();

            foreach (XElement elm in BL.Get.JHSchoolList().Elements("學校"))
            {
                DAL.SchoolData sd = new DAL.SchoolData();
                sd.SchoolCode = elm.Attribute("代碼").Value;
                sd.SchoolLocation = elm.Attribute("所在地").Value;
                sd.SchoolName = elm.Attribute("名稱").Value;
                sd.SchoolLocationCode = elm.Attribute("所在地代碼").Value;
                if (sd.SchoolCode.Length > 3)
                    sd.SchoolType = sd.SchoolCode.Substring(2, 1);

                string s1 = elm.Attribute("所在地").Value + elm.Attribute("名稱").Value;

                if (!schoolDataDict.ContainsKey(s1))
                    schoolDataDict.Add(s1, sd);

                if (!schoolDataDict.ContainsKey(sd.SchoolName))
                    schoolDataDict.Add(sd.SchoolName, sd);

            }

            SHBeforeEnrollmentRecord brfRec = SHBeforeEnrollment.SelectByStudentID(_UpdateRec.StudentID);

            if (string.IsNullOrEmpty(_UpdateRec.GraduateSchool))
                _UpdateRec.GraduateSchool = brfRec.School;
            if (string.IsNullOrEmpty(_UpdateRec.GraduateSchoolYear))
                _UpdateRec.GraduateSchoolYear = brfRec.GraduateSchoolYear;

            // 用學校名稱解析
            if (!string.IsNullOrEmpty(brfRec.School))
            {
                string key = brfRec.SchoolLocation.Replace("台", "臺") + brfRec.School.Trim();
                if (schoolDataDict.ContainsKey(key))
                {
                    if (string.IsNullOrEmpty(_UpdateRec.GraduateSchoolCode))
                    {
                        _UpdateRec.GraduateSchoolCode = schoolDataDict[key].SchoolCode;
                        _UpdateRec.GraduateSchoolLocationCode = schoolDataDict[key].SchoolLocationCode;
                    }
                }
            }

            cbxUpdateCode = _faldn.SetFormData(_UpdateRec.UpdateCode, cbxUpdateCode, "資格代碼");
            txtDesc = _faldn.SetFormData(_UpdateRec.UpdateDescription, txtDesc, "原因及事項");
            dtUpdateDate = _faldn.SetFormData(_UpdateRec.UpdateDate, dtUpdateDate, "異動日期");
            txtMemo = _faldn.SetFormData(_UpdateRec.Comment, txtMemo, "備註");
            cbxDept = _faldn.SetFormData(_UpdateRec.Department, cbxDept, "科別");
            cbxClass = _faldn.SetFormData(_UpdateRec.ClassType, cbxClass, "班別");
            txtSpecial = _faldn.SetFormData(_UpdateRec.SpecialStatus, txtSpecial, "特殊身分代碼");
            txtName = _faldn.SetFormData(_UpdateRec.StudentName, txtName, "姓名");
            txtStudentNumber = _faldn.SetFormData(_UpdateRec.StudentNumber, txtStudentNumber, "學號");
            txtIDNumber = _faldn.SetFormData(_UpdateRec.IDNumber, txtIDNumber, "身分證字號");
            dtBirthday = _faldn.SetFormData(_UpdateRec.Birthdate, dtBirthday, "生日");
            txtIDNumber1 = _faldn.SetFormData(_UpdateRec.IDNumberComment, txtIDNumber1, "註1");
            cbxGender = _faldn.SetFormData(_UpdateRec.Gender, cbxGender, "性別");
            txtISchool = _faldn.SetFormData(_UpdateRec.GraduateSchool, txtISchool, "入學資格(畢業國中)");
            txtISpaceCode = _faldn.SetFormData(_UpdateRec.GraduateSchoolLocationCode,txtISpaceCode,"所在地代碼");
            txtISchoolCode = _faldn.SetFormData(_UpdateRec.GraduateSchoolCode, txtISchoolCode, "畢業國中學校代號");
            txtIJHGradeYear = _faldn.SetFormData(_UpdateRec.GraduateSchoolYear, txtIJHGradeYear, "國中畢業年度");
            dtADDate = _faldn.SetFormData(_UpdateRec.ADDate, dtADDate, "核准日期");
            txtADDocNo = _faldn.SetFormData(_UpdateRec.ADNumber, txtADDocNo, "核准文號");
            txtGradeDoc = _faldn.SetFormData(_UpdateRec.GraduateDocument, txtGradeDoc, "入學資格證明文件");
        }
Exemple #34
0
        void _bgWorkerRun_DoWork(object sender, DoWorkEventArgs e)
        {
            // 處理資料
            try
            {
                _bgWorkerRun.ReportProgress(1);
                // 刪除舊資料
                List <SHUpdateRecordRecord> _oldDataList = _StudHasGraduateRecDict.Values.ToList();
                SHUpdateRecord.Delete(_oldDataList);

                int SchoolYear = int.Parse(K12.Data.School.DefaultSchoolYear);
                int Semester   = int.Parse(K12.Data.School.DefaultSemester);


                // 學籍身分對照表
                Dictionary <string, List <string> > StudPermCodeMappingDict = utility.GetPermCodeMappingDict();

                // 取得學生類別對照
                Dictionary <string, List <string> > StudentTagDict = utility.GetStudentFullNameDictByStudentIDs(_StudentIDList);

                _bgWorkerRun.ReportProgress(10);
                foreach (string sid in _StudentIDList)
                {
                    if (!_StudentDict.ContainsKey(sid))
                    {
                        continue;
                    }

                    SHUpdateRecordRecord rec = new SHUpdateRecordRecord();
                    // 學年度
                    rec.SchoolYear = SchoolYear;
                    // 學期
                    rec.Semester = Semester;

                    rec.StudentID = sid;

                    string ClassName = "";
                    string DeptName  = "";

                    // 年級
                    if (_ClassRecDict.ContainsKey(_StudentDict[sid].RefClassID))
                    {
                        if (_ClassRecDict[_StudentDict[sid].RefClassID].GradeYear.HasValue)
                        {
                            rec.GradeYear = _ClassRecDict[_StudentDict[sid].RefClassID].GradeYear.Value.ToString();

                            // 班級名稱
                            ClassName = _ClassRecDict[_StudentDict[sid].RefClassID].Name;
                        }
                        else
                        {
                            rec.GradeYear = "";
                        }
                    }
                    string depID = _StudentDict[sid].DepartmentID;
                    // 科別名稱
                    if (_DeptRecDict.ContainsKey(depID))
                    {
                        DeptName = _DeptRecDict[depID].FullName;
                    }

                    //// 科別名稱
                    //if (_DeptRecDict.ContainsKey(_ClassRecDict[_StudentDict[sid].RefClassID].RefDepartmentID))
                    //    DeptName = _DeptRecDict[_ClassRecDict[_StudentDict[sid].RefClassID].RefDepartmentID].FullName;

                    // 畢業代碼
                    rec.UpdateCode = "501";

                    // 原因及事項
                    rec.UpdateDescription = "畢業";

                    // 異動日期
                    rec.UpdateDate = _UpdateDate.ToShortDateString();

                    // 姓名
                    rec.StudentName = _StudentDict[sid].Name;

                    // 學號
                    rec.StudentNumber = _StudentDict[sid].StudentNumber;

                    // 身分證字號
                    rec.IDNumber = _StudentDict[sid].IDNumber;

                    // 生日
                    if (_StudentDict[sid].Birthday.HasValue)
                    {
                        rec.Birthdate = _StudentDict[sid].Birthday.Value.ToShortDateString();
                    }

                    // 性別
                    rec.Gender = _StudentDict[sid].Gender;

                    if (_StudLastupdateRecDict.ContainsKey(sid))
                    {
                        // 備查日期
                        rec.LastADDate = _StudLastupdateRecDict[sid].ADDate;

                        // 備查文號
                        rec.LastADNumber = _StudLastupdateRecDict[sid].ADNumber;

                        // 最後異動代碼
                        rec.LastUpdateCode = _StudLastupdateRecDict[sid].UpdateCode;
                    }
                    // 畢業證書字號
                    if (_LeaveInfoRecordDict.ContainsKey(sid))
                    {
                        rec.GraduateCertificateNumber = _LeaveInfoRecordDict[sid].DiplomaNumber;
                        rec.Department = DeptName;
                        rec.ExpectGraduateSchoolYear             = SchoolYear.ToString();
                        _LeaveInfoRecordDict[sid].SchoolYear     = SchoolYear;
                        _LeaveInfoRecordDict[sid].ClassName      = ClassName;
                        _LeaveInfoRecordDict[sid].DepartmentName = DeptName;
                    }

                    // 學生特殊身分代碼
                    if (StudentTagDict.ContainsKey(sid))
                    {
                        List <string> codeList = new List <string>();
                        foreach (string fullName in StudentTagDict[sid])
                        {
                            if (StudPermCodeMappingDict.ContainsKey(fullName))
                            {
                                foreach (string code in StudPermCodeMappingDict[fullName])
                                {
                                    if (!codeList.Contains(code))
                                    {
                                        codeList.Add(code);
                                    }
                                }
                            }
                        }

                        if (codeList.Count > 0)
                        {
                            codeList.Sort();
                            rec.SpecialStatus = string.Join(",", codeList.ToArray());
                        }
                    }

                    _InsertDataList.Add(rec);
                }
                _bgWorkerRun.ReportProgress(70);
                // 新增資料
                if (_InsertDataList.Count > 0)
                {
                    SHUpdateRecord.Insert(_InsertDataList);
                }

                // 更新畢業離校資訊 離校學年度、離校科別、離校班級
                SHLeaveInfo.Update(_LeaveInfoRecordDict.Values.ToList());

                _bgWorkerRun.ReportProgress(99);
            }
            catch (Exception ex)
            {
                e.Result = ex;
                e.Cancel = true;
            }
        }
        /// <summary>
        /// 新生異動
        /// </summary>
        public UpdateRecordInfo03(SHUpdateRecordRecord UpdateRec, PermRecLogProcess prlp, List <XElement> UpdateCodeElms, bool isInsert)
        {
            InitializeComponent();
            cbxGender.Items.Add("男");
            cbxGender.Items.Add("女");

            cbxClass.DropDownWidth = 300;

            _UpdateRec       = UpdateRec;
            _prlp            = prlp;
            _UpdateCodeElms  = UpdateCodeElms;
            _UpdateCoodeList = (from x in _UpdateCodeElms select x.Element("代號").Value + " " + x.Element("原因及事項").Value).ToList();
            _DeptList        = SHDepartment.SelectAll();
            _epUpdateCode    = new ErrorProvider();

            _UCodeDict = Utility.UITool.ConvertUpdateCodeDescDict(_UpdateCodeElms);

            _faldn = new UpdateRecordModule_SH_D.Utility.FormAndLogDataManager(_prlp);

            // 新增帶入預設
            if (isInsert)
            {
                // 載入資料
                // 載入預設前級畢業資訊
                Dictionary <string, DAL.SchoolData> schoolDataDict = new Dictionary <string, DAL.SchoolData>();

                foreach (XElement elm in BL.Get.JHSchoolList().Elements("學校"))
                {
                    DAL.SchoolData sd = new DAL.SchoolData();
                    sd.SchoolCode         = elm.Attribute("代碼").Value;
                    sd.SchoolLocation     = elm.Attribute("所在地").Value;
                    sd.SchoolName         = elm.Attribute("名稱").Value;
                    sd.SchoolLocationCode = elm.Attribute("所在地代碼").Value;
                    if (sd.SchoolCode.Length > 3)
                    {
                        sd.SchoolType = sd.SchoolCode.Substring(2, 1);
                    }

                    string s1 = elm.Attribute("所在地").Value + elm.Attribute("名稱").Value;

                    if (!schoolDataDict.ContainsKey(s1))
                    {
                        schoolDataDict.Add(s1, sd);
                    }

                    if (!schoolDataDict.ContainsKey(sd.SchoolName))
                    {
                        schoolDataDict.Add(sd.SchoolName, sd);
                    }
                }

                SHBeforeEnrollmentRecord brfRec = SHBeforeEnrollment.SelectByStudentID(_UpdateRec.StudentID);

                if (string.IsNullOrEmpty(_UpdateRec.GraduateSchool))
                {
                    _UpdateRec.GraduateSchool = brfRec.School;
                }
                if (string.IsNullOrEmpty(_UpdateRec.GraduateSchoolYear))
                {
                    _UpdateRec.GraduateSchoolYear = brfRec.GraduateSchoolYear;
                }

                // 用學校名稱解析
                if (!string.IsNullOrEmpty(brfRec.School))
                {
                    string key = brfRec.SchoolLocation.Replace("台", "臺") + brfRec.School.Trim();
                    if (schoolDataDict.ContainsKey(key))
                    {
                        if (string.IsNullOrEmpty(_UpdateRec.GraduateSchoolCode))
                        {
                            _UpdateRec.GraduateSchoolCode         = schoolDataDict[key].SchoolCode;
                            _UpdateRec.GraduateSchoolLocationCode = schoolDataDict[key].SchoolLocationCode;
                        }
                    }
                }
            }

            cbxUpdateCode    = _faldn.SetFormData(_UpdateRec.UpdateCode, cbxUpdateCode, "資格代碼");
            txtDesc          = _faldn.SetFormData(_UpdateRec.UpdateDescription, txtDesc, "原因及事項");
            dtUpdateDate     = _faldn.SetFormData(_UpdateRec.UpdateDate, dtUpdateDate, "異動日期");
            txtMemo          = _faldn.SetFormData(_UpdateRec.Comment, txtMemo, "備註");
            cbxDept          = _faldn.SetFormData(_UpdateRec.Department, cbxDept, "科別");
            cbxClass         = _faldn.SetFormData(_UpdateRec.ClassType, cbxClass, "班別");
            txtSpecial       = _faldn.SetFormData(_UpdateRec.SpecialStatus, txtSpecial, "特殊身分代碼");
            txtName          = _faldn.SetFormData(_UpdateRec.StudentName, txtName, "姓名");
            txtStudentNumber = _faldn.SetFormData(_UpdateRec.StudentNumber, txtStudentNumber, "學號");
            txtIDNumber      = _faldn.SetFormData(_UpdateRec.IDNumber, txtIDNumber, "身分證字號");
            dtBirthday       = _faldn.SetFormData(_UpdateRec.Birthdate, dtBirthday, "生日");
            txtIDNumber1     = _faldn.SetFormData(_UpdateRec.IDNumberComment, txtIDNumber1, "註1");
            cbxGender        = _faldn.SetFormData(_UpdateRec.Gender, cbxGender, "性別");
            txtISchool       = _faldn.SetFormData(_UpdateRec.GraduateSchool, txtISchool, "入學資格(畢業國中)");
            txtISpaceCode    = _faldn.SetFormData(_UpdateRec.GraduateSchoolLocationCode, txtISpaceCode, "所在地代碼");
            txtISchoolCode   = _faldn.SetFormData(_UpdateRec.GraduateSchoolCode, txtISchoolCode, "畢業國中學校代號");
            txtIJHGradeYear  = _faldn.SetFormData(_UpdateRec.GraduateSchoolYear, txtIJHGradeYear, "國中畢業年度");
            dtADDate         = _faldn.SetFormData(_UpdateRec.ADDate, dtADDate, "核准日期");
            txtADDocNo       = _faldn.SetFormData(_UpdateRec.ADNumber, txtADDocNo, "核准文號");
            txtGradeDoc      = _faldn.SetFormData(_UpdateRec.GraduateDocument, txtGradeDoc, "入學資格證明文件");
        }
        private void _bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Document doc      = new Document();
            Document template = null;

            if (radioButton1.Checked == true)
            {
                //選擇預設範本時的動作
                template = new Document(new MemoryStream(defalutTemplate));
            }
            else if (radioButton2.Checked == true)
            {            //選擇自訂範本時的動作
                //School.Configuration.Remove(cd);
                //return;
                string str = cd["CustomizeTemplate"];

                if (template == null)
                {
                    try
                    {
                        template = (new Document(new MemoryStream(Convert.FromBase64String(str)))).Clone();
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException("尚未上傳自訂樣板");
                        //MsgBox.Show("尚未上傳自訂樣板");
                        //return;
                    }

                    //template = new Document(new MemoryStream(defalutTemplate));
                }
            }
            else
            {
                MsgBox.Show("");
                return;
            }
            //取得文號、字號、學年度學期取得
            string No1        = textBoxX1.Text;
            string No2        = textBoxX2.Text;
            int    schoolYear = int.Parse(K12.Data.School.DefaultSchoolYear);
            int    semester   = int.Parse(K12.Data.School.DefaultSemester);
            //取得學校名稱
            string DSNSName  = SHSchool.Data.SHSchoolInfo.ChineseName;
            string Principal = K12.Data.School.Configuration["學校資訊"].PreviousData.SelectSingleNode("ChancellorChineseName").InnerText;

            #region 取得選取學生
            List <SHStudentRecord>      studentAll   = SHStudent.SelectByIDs(studentIds);
            List <SHUpdateRecordRecord> updateRecord = SHUpdateRecord.SelectByStudentIDs(studentIds);

            Dictionary <string, StudentObj> dic = new Dictionary <string, StudentObj>();
            foreach (SHUpdateRecordRecord urr in updateRecord)
            {
                if (dic.ContainsKey(urr.StudentID))
                {
                    SHUpdateRecordRecord old = dic[urr.StudentID].URR;
                    int newSchoolYear        = urr.SchoolYear.HasValue ? urr.SchoolYear.Value : 0;
                    int newSemester          = urr.Semester.HasValue ? urr.Semester.Value : 0;
                    int oldSchoolYear        = old.SchoolYear.HasValue ? old.SchoolYear.Value : 0;
                    int oldSemester          = old.Semester.HasValue ? old.Semester.Value : 0;

                    if (newSchoolYear > oldSchoolYear)
                    {
                        dic[urr.StudentID].URR = urr;
                    }
                    else if (newSchoolYear == oldSchoolYear)
                    {
                        if (newSemester > oldSemester)
                        {
                            dic[urr.StudentID].URR = urr;
                        }
                    }
                }
                if (updateCode.Contains(urr.UpdateCode) && !dic.ContainsKey(urr.StudentID))
                {
                    dic.Add(urr.StudentID, new StudentObj());
                    dic[urr.StudentID].URR = urr;
                }
            }
            foreach (SHStudentRecord sr in studentAll)
            {
                if (dic.ContainsKey(sr.ID))
                {
                    dic[sr.ID].Student = sr;
                }
            }
            #endregion
            Dictionary <string, object> merge = new Dictionary <string, object>();
            string serverTime = GetServerTime();
            foreach (StudentObj obj in dic.Values)
            {
                Document perPage = template.Clone();
                merge.Clear();

                merge.Add("起始時間", dateTimeInput1.Value.ToString("yyyy年MM月dd日"));
                merge.Add("訖末時間", dateTimeInput2.Value.ToString("yyyy年MM月dd日"));
                merge.Add("編字", No1);
                merge.Add("編號", No2);
                merge.Add("年級", schoolYear);
                merge.Add("學期", semester);
                merge.Add("學校名稱", DSNSName);
                merge.Add("校長姓名", Principal);
                merge.Add("列印日期", serverTime);
                merge.Add("學生姓名", obj.Student.Name);
                merge.Add("學號", obj.Student.StudentNumber);
                merge.Add("休學年級", obj.URR.GradeYear);
                merge.Add("休學學期", obj.URR.Semester);
                merge.Add("科系", obj.URR == null ? string.Empty : obj.URR.Department);
                merge.Add("休學事由", obj.URR == null ? string.Empty : obj.URR.UpdateDescription);

                perPage.MailMerge.Execute(merge.Keys.ToArray <string>(), merge.Values.ToArray <object>());
                perPage.MailMerge.RemoveEmptyParagraphs = true;
                perPage.MailMerge.DeleteFields();

                doc.Sections.Add(doc.ImportNode(perPage.Sections[0], true));
            }
            doc.Sections.RemoveAt(0);
            e.Result = doc;
        }
        public override string Import(List<Campus.DocumentValidator.IRowStream> Rows)
        {
            //mOption.

            _InsertRecList.Clear();
            _UpdateRecList.Clear ();
            // 取得 Rows內學號
            List<string> StudentNumberList = new List<string>();
            foreach (IRowStream ir in Rows)
                if (ir.Contains("學號"))
                    StudentNumberList.Add(ir.GetValue("學號"));

            // 透過學號去取得學生ID
            Dictionary<string, string> StudNumDict = DAL.FDQuery.GetStudenNumberStatusDictByStudentNumber(StudentNumberList);

            List<string> StudentIDList = new List<string>();
            foreach (IRowStream ir in Rows)
            {
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    string key = ir.GetValue("學號") + "_" + ir.GetValue("狀態");
                    if (StudNumDict.ContainsKey(key))
                        StudentIDList.Add(StudNumDict[key]);
                }

            }

            List<string> updateCodeList = Utility.UITool.GetUpdateCodeListByUpdateType("新生異動");
            // 取得新生異動資料
            List<SHUpdateRecordRecord> updateRecList = (from data in SHUpdateRecord.SelectByStudentIDs(StudentIDList) where updateCodeList.Contains(data.UpdateCode) select data).ToList();

            int totalCount = 0;
            // 判斷更新或新增
            foreach (IRowStream ir in Rows)
            {
                totalCount++;
                this.ImportProgress = totalCount;
                bool isInsert = true;
                SHUpdateRecordRecord UpdateRec=null;
                string StudentID = "";

                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    string key = ir.GetValue("學號") + "_" + ir.GetValue("狀態");
                    if (StudNumDict.ContainsKey(key))
                        StudentID = StudNumDict[key];
                }

                if (string.IsNullOrEmpty(StudentID))
                    continue;

                DateTime dt;
                DateTime.TryParse(ir.GetValue("異動日期"),out dt);

                foreach (SHUpdateRecordRecord rec in updateRecList.Where(x => x.StudentID == StudentID))
                {
                    bool checkDel = true;
                    string updateCode = string.Format("{0:000}", int.Parse(ir.GetValue("異動代碼").Trim()));

                    if (rec.UpdateCode.Trim() == updateCode)
                    {
                        DateTime dt1;
                        DateTime.TryParse(rec.UpdateDate, out dt1);

                        if (dt.ToShortDateString() == dt1.ToShortDateString())
                        {
                            isInsert = false;
                            checkDel = false;
                            UpdateRec = rec;
                        }
                    }

                    if (checkDel)
                        _DeleteRecList.Add(rec);
                }

                if (isInsert || UpdateRec == null)
                    UpdateRec = new SHUpdateRecordRecord();

                UpdateRec.StudentID=StudentID;

                if (isInsert)
                {

                    int sy, ss;
                    // 學年度
                    if (ir.Contains("學年度"))
                    {
                        if (int.TryParse(ir.GetValue("學年度"), out sy))
                            UpdateRec.SchoolYear = sy;

                        if (string.IsNullOrEmpty(ir.GetValue("學年度")))
                            UpdateRec.SchoolYear = null;
                    }

                    // 學期
                    if (ir.Contains("學期"))
                    {
                        if (int.TryParse(ir.GetValue("學期"), out ss))
                            UpdateRec.Semester = ss;

                        if (string.IsNullOrEmpty(ir.GetValue("學期")))
                            UpdateRec.Semester = null;
                    }

                    // 異動年級
                    if (ir.Contains("異動年級"))
                        UpdateRec.GradeYear = ir.GetValue("異動年級");

                    // 異動代碼
                    UpdateRec.UpdateCode = string.Format("{0:000}",int.Parse(ir.GetValue("異動代碼").Trim()));

                    // 原因及事項
                    if (ir.Contains("原因及事項"))
                        UpdateRec.UpdateDescription = ir.GetValue("原因及事項");

                    // 異動日期
                    UpdateRec.UpdateDate = dt.ToShortDateString();

                    // 備註
                    if (ir.Contains("備註"))
                        UpdateRec.Comment = ir.GetValue("備註");

                    // 班別
                    if (ir.Contains("班別"))
                        UpdateRec.ClassType = ir.GetValue("班別");

                    // 科別
                    if (ir.Contains("科別"))
                        UpdateRec.Department = ir.GetValue("科別");

                    // 特殊身分代碼
                    if (ir.Contains("特殊身分代碼"))
                        UpdateRec.SpecialStatus = ir.GetValue("特殊身分代碼");

                    // 入學資格證明文件
                    if (ir.Contains("入學資格證明文件"))
                        UpdateRec.GraduateDocument = ir.GetValue("入學資格證明文件");

                    // 異動姓名
                    if (ir.Contains("異動姓名"))
                        UpdateRec.StudentName = ir.GetValue("異動姓名");

                    // 異動學號
                    if (ir.Contains("異動學號"))
                        UpdateRec.StudentNumber = ir.GetValue("異動學號");

                    // 異動身分證字號
                    if (ir.Contains("異動身分證字號"))
                        UpdateRec.IDNumber = ir.GetValue("異動身分證字號");

                    // 異動生日
                    if (ir.Contains("異動生日"))
                    {
                        DateTime dtd;
                        if (DateTime.TryParse(ir.GetValue("異動生日"), out dtd))
                            UpdateRec.Birthdate = dtd.ToShortDateString();

                        if (string.IsNullOrEmpty(ir.GetValue("異動生日")))
                            UpdateRec.Birthdate = "";
                    }
                    // 異動身分證註記
                    if (ir.Contains("異動身分證註記"))
                        UpdateRec.IDNumberComment = ir.GetValue("異動身分證註記");

                    // 異動性別
                    if (ir.Contains("異動性別"))
                        UpdateRec.Gender = ir.GetValue("異動性別");

                    // 畢業國中
                    if (ir.Contains("畢業國中"))
                        UpdateRec.GraduateSchool = ir.GetValue("畢業國中");

                    // 畢業國中所在地代碼
                    if (ir.Contains("畢業國中所在地代碼"))
                        UpdateRec.GraduateSchoolLocationCode = ir.GetValue("畢業國中所在地代碼");

                    // 畢業國中學校代碼
                    if (ir.Contains("畢業國中學校代碼"))
                        UpdateRec.GraduateSchoolCode = ir.GetValue("畢業國中學校代碼");

                    // 國中畢業學年度
                    if (ir.Contains("國中畢業學年度"))
                        UpdateRec.GraduateSchoolYear = ir.GetValue("國中畢業學年度");

                    // 畢業國中入學資格註記
                    if (ir.Contains("畢業國中入學資格註記"))
                        UpdateRec.GraduateComment = ir.GetValue("畢業國中入學資格註記");

                    // 核准日期
                    if (ir.Contains("核准日期"))
                    {
                        DateTime dta;
                        if (DateTime.TryParse(ir.GetValue("核准日期"), out dta))
                            UpdateRec.ADDate = dta.ToShortDateString();

                        if (string.IsNullOrEmpty(ir.GetValue("核准日期")))
                            UpdateRec.ADDate = "";

                    }
                    // 核准文號
                    if (ir.Contains("核准文號"))
                        UpdateRec.ADNumber = ir.GetValue("核准文號");
                }
                else
                {
                // 更新有勾選
                    int sy, ss;
                    // 學年度
                    if (ir.Contains("學年度") && mOption.SelectedFields.Contains("學年度"))
                    {
                        if (int.TryParse(ir.GetValue("學年度"), out sy))
                            UpdateRec.SchoolYear = sy;

                        if (string.IsNullOrEmpty(ir.GetValue("學年度")))
                            UpdateRec.SchoolYear = null;
                    }
                    // 學期
                    if (ir.Contains("學期") && mOption.SelectedFields.Contains("學期"))
                    {
                        if (int.TryParse(ir.GetValue("學期"), out ss))
                            UpdateRec.Semester = ss;

                        if (string.IsNullOrEmpty(ir.GetValue("學期")))
                            UpdateRec.Semester = null;
                    }
                    // 異動年級
                    if (ir.Contains("異動年級") && mOption.SelectedFields.Contains("異動年級"))
                        UpdateRec.GradeYear = ir.GetValue("異動年級");

                    //// 異動代碼
                    //UpdateRec.UpdateCode = ir.GetValue("異動代碼").Trim();

                    // 原因及事項
                    if (ir.Contains("原因及事項") && mOption.SelectedFields.Contains("原因及事項"))
                        UpdateRec.UpdateDescription = ir.GetValue("原因及事項");

                    //// 異動日期
                    //UpdateRec.UpdateDate = dt.ToShortDateString();

                    // 備註
                    if (ir.Contains("備註") && mOption.SelectedFields.Contains("備註"))
                        UpdateRec.Comment = ir.GetValue("備註");

                    // 班別
                    if (ir.Contains("班別") && mOption.SelectedFields.Contains("班別"))
                        UpdateRec.ClassType = ir.GetValue("班別");

                    // 科別
                    if (ir.Contains("科別") && mOption.SelectedFields.Contains("科別"))
                        UpdateRec.Department = ir.GetValue("科別");

                    // 特殊身分代碼
                    if (ir.Contains("特殊身分代碼") && mOption.SelectedFields.Contains("特殊身分代碼"))
                        UpdateRec.SpecialStatus = ir.GetValue("特殊身分代碼");

                    // 入學資格證明文件
                    if (ir.Contains("入學資格證明文件") && mOption.SelectedFields.Contains("入學資格證明文件"))
                        UpdateRec.GraduateDocument = ir.GetValue("入學資格證明文件");

                    // 異動姓名
                    if (ir.Contains("異動姓名") && mOption.SelectedFields.Contains("異動姓名"))
                        UpdateRec.StudentName = ir.GetValue("異動姓名");

                    // 異動學號
                    if (ir.Contains("異動學號") && mOption.SelectedFields.Contains("異動學號"))
                        UpdateRec.StudentNumber = ir.GetValue("異動學號");

                    // 異動身分證字號
                    if (ir.Contains("異動身分證字號") && mOption.SelectedFields.Contains("異動身分證字號"))
                        UpdateRec.IDNumber = ir.GetValue("異動身分證字號");

                    // 異動生日
                    if (ir.Contains("異動生日") && mOption.SelectedFields.Contains("異動生日"))
                    {
                        DateTime dtd;
                        if (DateTime.TryParse(ir.GetValue("異動生日"), out dtd))
                            UpdateRec.Birthdate = dtd.ToShortDateString();

                        if (string.IsNullOrEmpty(ir.GetValue("異動生日")))
                            UpdateRec.Birthdate = "";

                    }
                    // 異動身分證註記
                    if (ir.Contains("異動身分證註記") && mOption.SelectedFields.Contains("異動身分證註記"))
                        UpdateRec.IDNumberComment = ir.GetValue("異動身分證註記");

                    // 異動性別
                    if (ir.Contains("異動性別") && mOption.SelectedFields.Contains("異動性別"))
                        UpdateRec.Gender = ir.GetValue("異動性別");

                    // 畢業國中
                    if (ir.Contains("畢業國中") && mOption.SelectedFields.Contains("畢業國中"))
                        UpdateRec.GraduateSchool = ir.GetValue("畢業國中");

                    // 畢業國中所在地代碼
                    if (ir.Contains("畢業國中所在地代碼") && mOption.SelectedFields.Contains("畢業國中所在地代碼"))
                        UpdateRec.GraduateSchoolLocationCode = ir.GetValue("畢業國中所在地代碼");

                    // 畢業國中學校代碼
                    if (ir.Contains("畢業國中學校代碼") && mOption.SelectedFields.Contains("畢業國中學校代碼"))
                        UpdateRec.GraduateSchoolCode = ir.GetValue("畢業國中學校代碼");

                    // 國中畢業學年度
                    if (ir.Contains("國中畢業學年度") && mOption.SelectedFields.Contains("國中畢業學年度"))
                        UpdateRec.GraduateSchoolYear = ir.GetValue("國中畢業學年度");

                    // 畢業國中入學資格註記
                    if (ir.Contains("畢業國中入學資格註記") && mOption.SelectedFields.Contains("畢業國中入學資格註記"))
                        UpdateRec.GraduateComment = ir.GetValue("畢業國中入學資格註記");

                    // 核准日期
                    if (ir.Contains("核准日期") && mOption.SelectedFields.Contains("核准日期"))
                    {
                        DateTime dta;
                        if (DateTime.TryParse(ir.GetValue("核准日期"), out dta))
                            UpdateRec.ADDate = dta.ToShortDateString();

                        if (string.IsNullOrEmpty(ir.GetValue("核准日期")))
                            UpdateRec.ADDate = "";
                    }
                    // 核准文號
                    if (ir.Contains("核准文號") && mOption.SelectedFields.Contains("核准文號"))
                        UpdateRec.ADNumber = ir.GetValue("核准文號");

                }

                if(isInsert)
                   _InsertRecList.Add(UpdateRec);
                else
                    _UpdateRecList.Add(UpdateRec);
            }

            // 執行更新或新增
            if(_InsertRecList.Count>0)
                SHUpdateRecord.Insert(_InsertRecList);

            if(_UpdateRecList.Count>0)
                SHUpdateRecord.Update(_UpdateRecList);

            // 刪除多餘資料
            if (_DeleteRecList.Count > 0)
                SHUpdateRecord.Delete(_DeleteRecList);

            return "";
        }
Exemple #38
0
        void _bgWorkerRun_DoWork(object sender, DoWorkEventArgs e)
        {
            // 處理資料
            try
            {
                _bgWorkerRun.ReportProgress(1);
                // 刪除舊資料
                List <SHUpdateRecordRecord> _oldDataList = _StudHasGraduateRecDict.Values.ToList();
                SHUpdateRecord.Delete(_oldDataList);

                int SchoolYear = int.Parse(K12.Data.School.DefaultSchoolYear);
                int Semester   = int.Parse(K12.Data.School.DefaultSemester);


                _bgWorkerRun.ReportProgress(10);
                foreach (string sid in _StudentIDList)
                {
                    if (!_StudentDict.ContainsKey(sid))
                    {
                        continue;
                    }

                    SHUpdateRecordRecord rec = new SHUpdateRecordRecord();
                    // 學年度
                    rec.SchoolYear = SchoolYear;
                    // 學期
                    rec.Semester = Semester;

                    rec.StudentID = sid;
                    string ClassName = "";
                    string DeptName  = "";

                    // 年級
                    if (_ClassRecDict.ContainsKey(_StudentDict[sid].RefClassID))
                    {
                        if (_ClassRecDict[_StudentDict[sid].RefClassID].GradeYear.HasValue)
                        {
                            rec.GradeYear = _ClassRecDict[_StudentDict[sid].RefClassID].GradeYear.Value.ToString();

                            // 班級名稱
                            ClassName = _ClassRecDict[_StudentDict[sid].RefClassID].Name;

                            // 科別名稱
                            if (_DeptRecDict.ContainsKey(_ClassRecDict[_StudentDict[sid].RefClassID].RefDepartmentID))
                            {
                                DeptName = _DeptRecDict[_ClassRecDict[_StudentDict[sid].RefClassID].RefDepartmentID].FullName;
                            }
                        }
                        else
                        {
                            rec.GradeYear = "";
                        }
                    }

                    // 畢業代碼
                    rec.UpdateCode = "501";

                    // 原因及事項
                    rec.UpdateDescription = "畢業";

                    // 異動日期
                    rec.UpdateDate = _UpdateDate.ToShortDateString();

                    // 姓名
                    rec.StudentName = _StudentDict[sid].Name;

                    // 學號
                    rec.StudentNumber = _StudentDict[sid].StudentNumber;

                    // 身分證字號
                    rec.IDNumber = _StudentDict[sid].IDNumber;

                    // 生日
                    if (_StudentDict[sid].Birthday.HasValue)
                    {
                        rec.Birthdate = _StudentDict[sid].Birthday.Value.ToShortDateString();
                    }

                    // 性別
                    rec.Gender = _StudentDict[sid].Gender;

                    if (_StudLastupdateRecDict.ContainsKey(sid))
                    {
                        // 備查日期
                        rec.LastADDate = _StudLastupdateRecDict[sid].ADDate;

                        // 備查文號
                        rec.LastADNumber = _StudLastupdateRecDict[sid].ADNumber;

                        // 最後異動代碼
                        rec.LastUpdateCode = _StudLastupdateRecDict[sid].UpdateCode;
                    }
                    // 畢業證書字號
                    if (_LeaveInfoRecordDict.ContainsKey(sid))
                    {
                        rec.GraduateCertificateNumber = _LeaveInfoRecordDict[sid].DiplomaNumber;
                        rec.Department = DeptName;
                        rec.ExpectGraduateSchoolYear             = SchoolYear.ToString();
                        _LeaveInfoRecordDict[sid].SchoolYear     = SchoolYear;
                        _LeaveInfoRecordDict[sid].ClassName      = ClassName;
                        _LeaveInfoRecordDict[sid].DepartmentName = DeptName;
                    }
                    _InsertDataList.Add(rec);
                }
                _bgWorkerRun.ReportProgress(70);
                // 新增資料
                if (_InsertDataList.Count > 0)
                {
                    SHUpdateRecord.Insert(_InsertDataList);
                }

                // 更新畢業離校資訊 離校學年度、離校科別、離校班級
                SHLeaveInfo.Update(_LeaveInfoRecordDict.Values.ToList());

                _bgWorkerRun.ReportProgress(99);
            }
            catch (Exception ex)
            {
                e.Result = ex;
                e.Cancel = true;
            }
        }