Example #1
0
 private void Insert(object item)
 {
     try
     {
         List <SHUpdateRecordRecord> InsertPackage = (List <SHUpdateRecordRecord>)item;
         SHUpdateRecord.Insert(InsertPackage);
     }
     catch (Exception ex) { FISCA.Presentation.Controls.MsgBox.Show("新增資料發生異常."); }
 }
        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("");
        }
        /// <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);
        }
Example #4
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;
            }
        }
Example #5
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;
            }
        }
Example #6
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();
                }
            }
        }
Example #7
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)
                {
                }
            }
        }