Пример #1
1
        /// <summary>
        /// 資料驗證
        /// </summary>
        /// <param name="ValidatorPairs">資料驗證相關資訊清單(檔案,工作表,規則)</param>
        /// <param name="OutputFile">報告輸出路徑</param>
        /// <param name="OutputOptions">輸出類型:全部(Full),正確(Correct),錯誤(Error)</param>
        protected void Validate(IEnumerable<ValidatePair> ValidatorPairs, string OutputFile, OutputOptions OutputOptions)
        {
            #region Step1:初始化動作
            //假設ValidatorPairs為0的話就不處理
            if (ValidatorPairs.Count() == 0)
                return;

            if (!OutputBuilder.SameSource(ValidatorPairs,OutputOptions))
                throw new Exception("目前驗證只支援ValidatePair中的DataFile需為一樣,並且OutputOptions為Full。");

            //建立OutputBuilder物件,用來協助產生最後的Excel檔案
            OutputBuilder outputBuilder = new OutputBuilder(ValidatorPairs, OutputFile, OutputOptions,this.ReportProgress);

            //建立ValidatedInfo物件,用來儲存資料驗證後的結果
            ValidatedInfo validatedInfo = new ValidatedInfo();

            //初始化DocumentValidate物件及事件
            DocumentValidate docValidate = new DocumentValidate();
            docValidate.AutoCorrect += new EventHandler<AutoCorrectEventArgs>(docValidate_AutoCorrect);
            docValidate.ErrorCaptured += new EventHandler<ErrorCapturedEventArgs>(docValidate_ErrorCaptured);
            #endregion

            #region Step2:進行資料驗證

            foreach (ValidatePair each in ValidatorPairs)
            {
                ValidatedPair validatedPair = new ValidatedPair();

                //初始化驗證訊息,在驗證每個資料表時會重新清空
                RowMessages = new RowMessages();

                //用來搜集資料驗證過程中的錯誤訊息, 等到資料驗證完後再一次回報錯誤訊息
                Dictionary<string, Exception> exceptions = new Dictionary<string, Exception>();

                List<FieldValidatedDescription> FieldDescriptions = new List<FieldValidatedDescription>();

                IList<DuplicateData> DuplicateDataList = new List<DuplicateData>();

                try
                {
                    #region Step2.1:讀取驗證規則
                    docValidate.Load(each.ValidatorFile);

                    #endregion

                    #region Step2.2:驗證資料
                    //將驗證訊息都清空
                    RowMessages.Clear();

                    //將錯誤、警告及自動修正數目設為0
                    ErrorCount = WarningCount = AutoCorrectCount = 0;

                    //根據目前的驗證資料組合切換
                    outputBuilder.Switch(each);

                    //開始進度回報
                    ReportProgress(each, ErrorCount, WarningCount, AutoCorrectCount, "目前驗證: " + each.DataSheet, 0);

                    double ValidateProgress = 0;
                    double ValidateTotal = outputBuilder.Sheet.DataRowCount;

                    //開始主鍵驗證
                    docValidate.BeginDetecteDuplicate();

                    #region Step2.2.1:資料驗證
                    SheetRowSource RowSource = new SheetRowSource(outputBuilder.Sheet);
                    for (int i = outputBuilder.Sheet.FirstDataRowIndex; i <= outputBuilder.Sheet.DataRowCount; i++)
                    {
                        try
                        {
                            RowSource.BindRow(i);

                            bool valid = docValidate.Validate(RowSource);

                            RowStream RowStream = RowSource.Clone() as RowStream; //將SheetRowSource目前所指向的內容複製

                            validatedPair.Rows.Add(RowStream);                   //將RowStream加入到集合中

                            ReportProgress(each, ErrorCount, WarningCount, AutoCorrectCount, "目前驗證: " + each.DataSheet, (int)(++ValidateProgress * 100 / ValidateTotal));
                        }
                        catch (Exception e)
                        {
                            ReportProgress(each, ErrorCount, WarningCount, AutoCorrectCount, "驗證錯誤: " + each.DataSheet, (int)(++ValidateProgress * 100 / ValidateTotal));

                            if (!exceptions.ContainsKey(e.Message))
                                exceptions.Add(e.Message, e);
                        }
                    }

                    //exceptions.Values.ToList().ForEach(ex => SmartSchool.ErrorReporting.ReportingService.ReportException(ex));
                    //需要將驗證有錯誤呈現給使用者
                    #endregion

                    #region Step2.2.2:主鍵驗證
                    DuplicateDataList = docValidate.EndDetecteDuplicate();

                    foreach (DuplicateData dup in DuplicateDataList)
                    {
                        ErrorType errorType = (dup.ErrorType == EMBA.DocumentValidator.ErrorType.Error) ? ErrorType.Error : ErrorType.Warning;

                        foreach (DuplicateRecord dupRecord in dup)
                        {
                            List<string> list = new List<string>();
                            for (int i = 0; i < dupRecord.Values.Count; i++)
                                list.Add(string.Format("「{0}:{1}」", dup.Fields[i], string.IsNullOrWhiteSpace(dupRecord.Values[i]) ? "缺" : dupRecord.Values[i]));

                            string fields = (list.Count == 1 ? list[0] : string.Join("、", list.ToArray()));
                            string msg = string.Format("{0}為鍵值,必須有資料且不得重覆。", fields);
                            foreach (int position in dupRecord.Positions)
                                RowMessages[position].MessageItems.Add(new MessageItem(errorType, ValidatorType.Row, msg));
                        }
                    }
                    #endregion

                    #region Step2.2.3:欄位驗證
                    RowSource.BindRow(0);

                    FieldDescriptions = docValidate.ValidateField(RowSource);

                    string HeaderMessage = FieldDescriptions.ToDisplay();
                    #endregion

                    #region Step2.2.4:客製驗證
                    if (CustomValidate != null)
                        CustomValidate.Invoke(validatedPair.Rows, RowMessages);
                    #endregion

                    #endregion

                    #region Step2.3:將驗證訊息寫到來源Excel
                    outputBuilder.InitialMessageHeader();

                    //判斷當沒有訊息時就跳過不輸出
                    //if (RowMessages.Count <= 0 && string.IsNullOrEmpty(HeaderMessage)) continue;

                    //寫入欄位驗證訊息
                    outputBuilder.SetHeaderMessage(HeaderMessage);

                    //寫入資料及主鍵驗證訊息
                    outputBuilder.SetMessages(RowMessages);

                    //調整驗證訊息欄寬
                    outputBuilder.AutoFitMessage();
                    #endregion
                }
                catch (Exception e)
                {
                    if (!exceptions.ContainsKey(e.Message))
                        exceptions.Add(e.Message, e);
                }

                #region Step2.4:儲存驗證結果
                validatedPair.AutoCorrectCount = RowMessages.AutoCorrectCount;
                validatedPair.ErrorCount = RowMessages.ErrorCount;
                validatedPair.WarningCount = RowMessages.WarningCount;
                validatedPair.DataFile = each.DataFile;
                validatedPair.DataSheet = each.DataSheet;
                validatedPair.ValidatorFile = each.ValidatorFile;
                validatedPair.FieldDescriptions = FieldDescriptions;
                validatedPair.Duplicates = DuplicateDataList;
                validatedPair.Exceptions = exceptions.Values.ToList();
                validatedPair.UpdateMessage();

                validatedInfo.ValidatedPairs.Add(validatedPair);
                #endregion
            }
            #endregion

            #region Step3:驗證報告存檔
            validatedInfo.OutputFile = OutputFile;
            validatedInfo.OutputOptions = OutputOptions;
            validatedInfo.Result = outputBuilder.Sheet.Book;
            validatedInfo.ResultHelper = outputBuilder.Sheet;

            outputBuilder.Save();
            #endregion

            #region 儲存驗證結果
            if (Complete != null)
                Complete(validatedInfo);
            #endregion
        }
Пример #2
0
        /// <summary>
        /// 客製驗證規則
        /// </summary>
        /// <param name="Rows"></param>
        /// <param name="Messages"></param>
        private void CustomValidator(List <IRowStream> Rows, RowMessages Messages)
        {
            // 取得資料庫社團資料
            string sql = @"
SELECT
    uid
    , school_year
    , semester
    , club_name
FROM
    $k12.clubrecord.universal
";

            DataTable             dt    = this._qh.Select(sql);
            IEnumerable <DataRow> clubs = dt.Rows.Cast <DataRow>();

            // 資料檢查
            Rows.ForEach((x) =>
            {
                string schoolYear = x.GetValue("學年度").Trim();
                string semester   = x.GetValue("學期").Trim();
                string clubName   = x.GetValue("社團名稱").Trim();

                if (clubs.Where(y => (y["school_year"] + "").Trim() == schoolYear).Where(y => (y["semester"] + "").Trim() == semester).Where(y => (y["club_name"] + "").Trim() == clubName).Count() == 0)
                {
                    Messages[x.Position].MessageItems.Add(new MessageItem(Campus.Validator.ErrorType.Error, Campus.Validator.ValidatorType.Row, "此學年度、學期、社團名稱不存在系統。"));
                }
            });
        }
        /// <summary>
        /// 建構式
        /// </summary>
        /// <param name="Rows"></param>
        /// <param name="Messages"></param>
        public TeacherBusyTimeConflictHelper(List<IRowStream> Rows,RowMessages Messages)
        {
            this.mTeacherPeriods = new Dictionary<string, List<Period>>();
            this.mMessages = Messages;

            foreach(IRowStream Row in Rows)
            {
                string TeacherFullName = Row.GetValue(constTeacehrName) + Row.GetValue(constTeacherNickName);

                if (!mTeacherPeriods.ContainsKey(TeacherFullName))
                    mTeacherPeriods.Add(TeacherFullName, new List<Period>());

                DateTime Date = K12.Data.DateTimeHelper.ParseDirect(Row.GetValue(constDate));
                string StartTime = Row.GetValue(constStartTime);
                string EndTime = Row.GetValue(constEndTime);

                Tuple<DateTime, int> StorageTime = Utility.GetStorageTime(StartTime, EndTime);

                DateTime BeginDatetime = StorageTime.Item1;
                int Duration = StorageTime.Item2;

                Period Period = new Period();
                Period.Date= Date;
                Period.Hour = BeginDatetime.Hour;
                Period.Minute = BeginDatetime.Minute;
                Period.Duration = Duration;
                Period.Position = Row.Position;

                mTeacherPeriods[TeacherFullName].Add(Period);
            }
        }
Пример #4
0
        /// <summary>
        /// 客製驗證規則
        /// </summary>
        /// <param name="Rows"></param>
        /// <param name="Messages"></param>
        private void CustomValidator(List <IRowStream> Rows, RowMessages Messages)
        {
            Dictionary <string, IRowStream> dicRowStreamByKey = new Dictionary <string, IRowStream>(); // 判斷資料是否重複

            // 資料檢查
            Rows.ForEach(x =>
            {
                // 規則1.位置名稱(階層1)欄位必填不可空白
                if (string.IsNullOrEmpty(x.GetValue("位置名稱(階層1)").Trim()))
                {
                    Messages[x.Position].MessageItems.Add(new MessageItem(Campus.Validator.ErrorType.Error, Campus.Validator.ValidatorType.Row, "位置名稱(階層1)欄位必填不可空白!"));
                }

                // 規則2.位置名稱(階層3)有資料,位置名稱(階層2)欄位必填不可空白
                if (string.IsNullOrEmpty(x.GetValue("位置名稱(階層2)").Trim()) && !string.IsNullOrEmpty(x.GetValue("位置名稱(階層3)").Trim()))
                {
                    Messages[x.Position].MessageItems.Add(new MessageItem(Campus.Validator.ErrorType.Error, Campus.Validator.ValidatorType.Row, "位置名稱(階層3)有資料,位置名稱(階層2)欄位必填不可空白!"));
                }

                // 規則3.位置名稱(階層1)_位置名稱(階層2)_位置名稱(階層3)_設施名稱 為KEY值不可重複
                string key = string.Format("{0}_{1}_{2}_{3}", "" + x.GetValue("位置名稱(階層1)").Trim(), x.GetValue("位置名稱(階層2)").Trim(), x.GetValue("位置名稱(階層3)").Trim(), x.GetValue("設施名稱").Trim());

                if (dicRowStreamByKey.ContainsKey(key))
                {
                    Messages[x.Position].MessageItems.Add(new MessageItem(Campus.Validator.ErrorType.Error, Campus.Validator.ValidatorType.Row, "位置名稱(階層1)+位置名稱(階層2)+位置名稱(階層3)+設施名稱 : 為KEY值不可重複!"));
                }
                else
                {
                    dicRowStreamByKey.Add(key, x);
                }
            });
        }
        public void CustomValidator(List<IRowStream> Rows, RowMessages Messages)
        {
            //  先移除匯入驗證機制已驗證之訊息(匯入機制已修正,無需覆蓋已驗證訊息)
            //List<MessageItem> messageItems;
            //foreach (IRowStream Row in Rows)
            //{
            //    //  必要欄位不存在的驗證訊息不移除
            //    if (Row.Position == 0)
            //        continue;

            //    messageItems = new List<MessageItem>();
            //    foreach (MessageItem messageItem in Messages[Row.Position].MessageItems)
            //        messageItems.Add(messageItem);

            //    messageItems.ForEach((x) => Messages[Row.Position].MessageItems.Remove(x));
            //}

            #  region 驗證流程
        public void CustomValidator(List<IRowStream> Rows, RowMessages Messages)
        {
            DataTable dataTables = this.Query.Select("select id_number, id, name from student");
            foreach (DataRow row in dataTables.Rows)
            {
                if (string.IsNullOrWhiteSpace(row["id_number"] + ""))
                    continue;

                if (!this.dicStudents.ContainsKey(row["id_number"] + ""))
                    this.dicStudents.Add(row["id_number"] + "", new Dictionary<string, string>() {{ row["id"] + "", row["name"] + "" }});
            }
            Dictionary<int, Dictionary<string, string>> Data = new Dictionary<int, Dictionary<string, string>>();
            Rows.ForEach((x) =>
            {
                Data.Add(x.Position, new Dictionary<string, string>());
                foreach(string Field in this.SurveyFields)
                {
                    Data[x.Position].Add(Field, x.GetValue(Field));
                }
            });
            Rows.ForEach((x) =>
            {
                string id_number = x.GetValue("身分證號").Trim();
                string name = x.GetValue("姓名").Trim();
                #region 檢查身分證號
                //  「身分證號」必須存在於系統
                if (!this.dicStudents.ContainsKey(id_number))
                {
                    Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "身分證號不存在。"));
                }
                //  「身分證號」必須與「姓名」一致
                else
                {
                    if (this.dicStudents[id_number].ElementAt(0).Value.Trim().ToLower() != name.ToLower())
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "使用身分證號驗證學生姓名錯誤。"));
                }
                #endregion
            });
            Dictionary<int, List<MessageItem>> dicMessages = Accessor.ApproachValidate.Execute(this.SchoolYear, Data);
            foreach(int key in dicMessages.Keys)
            {
                Messages[key].MessageItems.AddRange(dicMessages[key]);
            }
        }
        public void CustomValidator(List <IRowStream> Rows, RowMessages Messages)
        {
            #region 驗證流程
            if (this.SelectedKeyFields.Contains("科目系統編號"))
            {
                _keyField = "科目系統編號";
            }
            else
            {
                _keyField = "學年度+學期+課程時段+科目名稱+級別";
            }

            //  若「科目系統編號」不為空白,則必須存在於資料庫中。
            DataTable             dataTableSubjects = _queryHelper.Select("select uid, type, subject_name, level, school_year, semester from $ischool.course_selection.subject");
            IEnumerable <DataRow> subjects          = dataTableSubjects.Rows.Cast <DataRow>();

            Rows.ForEach((x) =>
            {
                string subject_uid         = x.GetValue("科目系統編號").Trim();
                string schoolYear          = x.GetValue("學年度").Trim();
                string semester            = x.GetValue("學期").Trim();
                string type                = x.GetValue("課程時段").Trim();
                string subjectName         = x.GetValue("科目名稱").Trim();
                string level               = x.GetValue("級別").Trim();
                string preSubject          = x.GetValue("前導課程科目").Trim();
                string preSubjectBlockMode = x.GetValue("前導課程採計方式").Trim();
                string entry_type          = x.GetValue("分項類別").Trim();
                string requiredBy          = x.GetValue("校部訂").Trim();
                string required            = x.GetValue("必選修").Trim();

                //DAO.SubjectDAO subjectDAO = new DAO.SubjectDAO(schoolYear, semester);

                //  若鍵值為「科目系統編號」,則必須存在於系統中,且「學年度+學期+課程時段+科目名稱+級別」不可重覆
                if (_keyField == "科目系統編號")
                {
                    if (!string.IsNullOrEmpty(subject_uid))
                    {
                        //  「科目系統編號」必須存在。
                        if (subjects.Where(y => (y["uid"] + "").Trim() == subject_uid).Count() == 0)
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "系統無此科目系統編號。"));
                        }
                    }
                    if (!string.IsNullOrEmpty(schoolYear) && !string.IsNullOrEmpty(semester) /*&& !string.IsNullOrEmpty(type)*/ && !string.IsNullOrEmpty(subjectName) /*&& !string.IsNullOrEmpty(level)*/)
                    {
                        if (Rows.Where(y => (y.GetValue("學年度").Trim() == schoolYear)).Where(y => (y.GetValue("學期").Trim() == semester)).Where(y => y.GetValue("課程時段").Trim() == type).Where(y => (y.GetValue("科目名稱").Trim() == subjectName)).Where(y => (y.GetValue("級別").Trim() == level)).Count() > 1)
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「學年度+學期+課程時段+科目名稱+級別」重覆。"));
                        }
                    }
                    // 如果前導課程科目不為NUL前導課程採計方式為必填
                    if (!string.IsNullOrEmpty(preSubject))
                    {
                        if (string.IsNullOrEmpty(preSubjectBlockMode))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "前導課程採計方式不可空白。"));
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(schoolYear) && !string.IsNullOrEmpty(semester) /*&& !string.IsNullOrEmpty(type)*/ && !string.IsNullOrEmpty(subjectName) /*&& !string.IsNullOrEmpty(level)*/)
                    {
                        if (Rows.Where(y => (y.GetValue("學年度").Trim() == schoolYear)).Where(y => (y.GetValue("學期").Trim() == semester)).Where(y => y.GetValue("課程時段").Trim() == type).Where(y => (y.GetValue("科目名稱").Trim() == subjectName)).Where(y => (y.GetValue("級別").Trim() == level)).Count() > 1)
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「學年度+學期+課程時段+科目名稱+級別」重覆。"));
                        }
                    }

                    if (string.IsNullOrEmpty(schoolYear))
                    {
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "學年度不可空白。"));
                    }
                    if (string.IsNullOrEmpty(semester))
                    {
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "學期不可空白。"));
                    }
                    if (string.IsNullOrEmpty(subjectName))
                    {
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "科目名稱不可空白。"));
                    }

                    // 如果前導課程科目不為NUL前導課程採計方式為必填
                    if (!string.IsNullOrEmpty(preSubject))
                    {
                        if (string.IsNullOrEmpty(preSubjectBlockMode))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "前導課程採計方式不可空白。"));
                        }
                    }

                    if (!string.IsNullOrEmpty(entry_type))
                    {
                        if (entry_type != "學業" && entry_type != "專業科目" && entry_type != "實習科目")
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "分項類別只允許「空白、學業、專業科目、實習科目」。"));
                        }
                    }

                    if (!string.IsNullOrEmpty(requiredBy))
                    {
                        if (requiredBy != "校訂" && requiredBy != "部定")
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "校部訂只允許「空白、校訂、部定」。"));
                        }
                    }

                    if (!string.IsNullOrEmpty(required))
                    {
                        if (required != "選修")
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "必選修只允許「空白、選修」。"));
                        }
                    }
                }
            });

            #endregion
        }
        public void CustomValidator(List<IRowStream> Rows, RowMessages Messages)
        {
            keyField = string.Empty;
            lstSubjects = new List<DataRow>();
            dataSet = new DataSet();
            dicStudent_Numbers = new Dictionary<string, string>();
            dicSubjectIDs = new Dictionary<string, string>();
            dicClass_Names = new Dictionary<string, string>();

            string strSQL = string.Empty;
            QueryHelper queryHelper = new QueryHelper();

            DataTable dataTable;

            //  科目(課程)
            strSQL = string.Format(@"select uid, name, subject_code, dept_name, dept_code, credit, is_required, new_subject_code from $ischool.emba.subject;");

            dataTable = queryHelper.Select(strSQL);
            dataTable.TableName = "科目";
            dataSet.Tables.Add(dataTable);

            //  科目(課程)學期成績
            strSQL = string.Format(@"select uid, ref_student_id, ref_course_id, school_year, semester, score, ref_subject_id, subject_name, subject_code, new_subject_code, credit, is_required, is_pass, offset_course, remark from $ischool.emba.subject_semester_score;");

            dataTable = queryHelper.Select(strSQL);
            dataTable.TableName = "科目學期成績";
            dataSet.Tables.Add(dataTable);

            //  開課
            strSQL = string.Format(@"select id, course_name, school_year, semester, credit from course;");

            dataTable = queryHelper.Select(strSQL);
            dataTable.TableName = "開課";
            dataSet.Tables.Add(dataTable);

            //  開課延伸資料
            strSQL = string.Format(@"select uid, ref_course_id, subject_code, new_subject_code, course_type, is_required, ref_subject_id, serial_no, class_name, score_confirmed from $ischool.emba.course_ext;");

            dataTable = queryHelper.Select(strSQL);
            dataTable.TableName = "開課延伸資料";
            dataSet.Tables.Add(dataTable);

            //  學生
            strSQL = string.Format(@"select id, name, id_number, ref_class_id, student_number, seat_no, status  from student;");

            dataTable = queryHelper.Select(strSQL);
            dataTable.TableName = "學生";
            dataSet.Tables.Add(dataTable);

            //  學生修課
            strSQL = string.Format(@"select ref_student_id, ref_course_id from $ischool.emba.scattend_ext;");

            dataTable = queryHelper.Select(strSQL);
            dataTable.TableName = "學生修課";
            dataSet.Tables.Add(dataTable);

            #region 1、無現存科目資料,則中斷驗證、中斷匯入。

            if (dataSet.Tables["科目"].Rows.Count == 0)
                throw new Exception("無課程總檔資料,無法匯入課程學期成績資料!");

            #endregion

            #region 2、無現存學生資料,則中斷驗證、中斷匯入。

            if (dataSet.Tables["學生"].Rows.Count == 0)
                throw new Exception("無學生資料,無法匯入課程學期成績資料!");

            #endregion

            #region 3、判讀鍵值為「課號」或「課程識別碼」

            if (this.SelectedKeyFields.Contains("課號")) keyField = "課號";
            if (this.SelectedKeyFields.Contains("課程識別碼")) keyField = "課程識別碼";

            #endregion

            #region 4、「學號」反查「學生系統編號」索引

            dataSet.Tables["學生"].Rows.Cast<DataRow>().ToList().ForEach((x) =>
            {
                if (!dicStudent_Numbers.ContainsKey((x["student_number"] + "").Trim().ToUpper()))
                    dicStudent_Numbers.Add((x["student_number"] + "").Trim().ToUpper(), x["id"] + "");
            });

            #endregion

            #region 5、「課號」或「課程識別碼」反查「科目(課程)系統編號」索引
            lstSubjects = dataSet.Tables["科目"].Rows.Cast<DataRow>().ToList();
            lstSubjects.ForEach((x) =>
            {
                string key = string.Empty;

                if (keyField == "課號")
                    key = (x["new_subject_code"] + "").Trim().ToUpper();

                if (keyField == "課程識別碼")
                    key = (x["subject_code"] + "").Trim().ToUpper();

                if (!dicSubjectIDs.ContainsKey(key))
                    dicSubjectIDs.Add(key, x["uid"] + "");
            });

            #endregion

            #region 6、鍵值必須存在、學號必須存在、以「學號」及「課號 或 課程識別碼」反查之開課系統編號必須為唯一

            Rows.ForEach((x) =>
            {
                string subject_code = x.GetValue("課程識別碼").Trim();
                string new_subject_code = x.GetValue("課號").Trim();
                string subject_name = x.GetValue("課程名稱").Trim();
                string school_year = x.GetValue("學年度").Trim();
                string semester = x.GetValue("學期").Trim();
                string student_number = x.GetValue("學號").Trim();
                string class_name = x.GetValue("班次").Trim();

                if (keyField == "課程識別碼")
                {
                    //  若鍵值為「課程識別碼」,則必須存在於系統中
                    IEnumerable<DataRow> filterDataRows = lstSubjects.Where(y => (y["subject_code"] + "").Trim().ToUpper() == subject_code.ToUpper());
                    if (filterDataRows.Count() == 0)
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "系統不存在此課程識別碼。"));

                    if (!IsValidCourseID(subject_code, dicStudent_Numbers[student_number.ToUpper()]))
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "以「學號」及「課程識別碼」反查出多筆「班次」資料,請查明是否學生重覆修習相同課程。"));
                }

                if (keyField == "課號")
                {
                    //  若鍵值為「課號」,則必須存在於系統中
                    IEnumerable<DataRow> filterDataRows = lstSubjects.Where(y => (y["new_subject_code"] + "").Trim().ToUpper() == new_subject_code.ToUpper());
                    if (filterDataRows.Count() == 0)
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "系統不存在此課號。"));

                    if (!IsValidCourseID(new_subject_code, dicStudent_Numbers[student_number.ToUpper()]))
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "以「學號」及「課號」反查出多筆「班次」資料,請查明是否學生重覆修習相同課程。"));
                }

                //  學號必須存在於系統中
                if (!dicStudent_Numbers.ContainsKey(student_number.ToUpper()))
                    Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "系統無此學號。"));
            });

            #endregion
        }
 public void CustomValidator(List <IRowStream> Rows, RowMessages Messages)
 {
     #  region 驗證流程
     if (this.SelectedKeyFields.Contains("科目系統編號"))
Пример #10
0
 /// <summary>
 /// 建構式
 /// </summary>
 public Validator()
 {
     RowMessages = new RowMessages();
 }
        /// <summary>
        /// 寫入多筆資料驗證訊息
        /// </summary>
        /// <param name="Messages"></param>
        public void SetMessages(RowMessages Messages)
        {
            if (mReportProgress!=null)
                mReportProgress(mCurrentPair, 0, 0, 0, "寫入驗證訊息:", 0);

            int WriteMessageProgress = 0;
            int WriteMessageTotal = Messages.Count;

            Dictionary<int, string> BestMessageDescription = new Dictionary<int, string>();

            foreach (RowMessage Message in Messages)
            {
                List<MessageItem> Items = Message.BestMessageItems;
                BestMessageDescription.Add(Message.Position, Items.GetDescription());
            }

            foreach (RowMessage Message in Messages)
            {
                string strMessage = BestMessageDescription[Message.Position];

                SetMessage(Message.Position, strMessage);

                if (mReportProgress!=null)
                    mReportProgress(mCurrentPair, Messages.ErrorCount, Messages.WarningCount, Messages.AutoCorrectCount, "寫入驗證訊息: " + mCurrentPair.DataSheet, (int)(++WriteMessageProgress * 100 / WriteMessageTotal));
            }

            //更新正確的錯誤、警告及自動修正數目
            Messages.UpdateErrorWarningAndAutoCorrectCount();

            if (mReportProgress!=null)
                mReportProgress(mCurrentPair, Messages.ErrorCount, Messages.WarningCount, Messages.AutoCorrectCount, "寫入驗證訊息:", 100);
        }
 public void CustomValidator(List<IRowStream> Rows, RowMessages Messages)
 {
     #  region 驗證流程
Пример #13
0
        public void CustomValidator(List <IRowStream> Rows, RowMessages Messages)
        {
            DataTable dataTables = this.Query.Select("select id_number, id, name from student");

            foreach (DataRow row in dataTables.Rows)
            {
                if (string.IsNullOrWhiteSpace(row["id_number"] + ""))
                {
                    continue;
                }

                if (!this.dicStudents.ContainsKey(row["id_number"] + ""))
                {
                    this.dicStudents.Add(row["id_number"] + "", new Dictionary <string, string>()
                    {
                        { row["id"] + "", row["name"] + "" }
                    });
                }
            }
            Rows.ForEach((x) =>
            {
                string id_number = x.GetValue("身分證號").Trim();
                string name      = x.GetValue("姓名").Trim();
                string q1_string = x.GetValue("升學與就業情形").Trim();
                string q2_string = x.GetValue("升學:就讀學校情形").Trim();
                string q3_string = x.GetValue("升學:學制別").Trim();
                string q4_string = x.GetValue("升學:入學方式").Trim();
                string q5_string = x.GetValue("未升學未就業:動向").Trim();
                string q6_string = x.GetValue("是否需要教育部協助").Trim();
                string memo      = x.GetValue("備註").Trim();

                int q1_int;
                int q2_int;
                int q3_int;
                int q4_int;
                int q5_int;

                #region 檢查身分證號
                //  「身分證號」必須存在於系統
                if (!this.dicStudents.ContainsKey(id_number))
                {
                    Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "身分證號不存在。"));
                }
                //  「身分證號」必須與「姓名」一致
                else
                {
                    if (this.dicStudents[id_number].ElementAt(0).Value.Trim().ToLower() != name.ToLower())
                    {
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "使用身分證號驗證學生姓名錯誤。"));
                    }
                }
                #endregion

                #region  檢查「升學與就業情形」
                if (int.TryParse(q1_string, out q1_int))
                {
                    //有填寫並且為 1
                    if (q1_int == 1)
                    {
                        //  升學:就讀學校情形,必須填寫且值為 1~8
                        if (!(int.TryParse(q2_string, out q2_int) && (q2_int > 0 && q2_int < 9)))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 1 時,「升學:就讀學校情形」必須填寫 1~8。"));
                        }
                        //  升學:學制別,必須填寫且值為 1~9
                        if (!(int.TryParse(q3_string, out q3_int) && (q3_int > 0 && q3_int < 10)))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 1 時,「升學:學制別」必須填寫 1~9。"));
                        }
                        //  升學:入學方式,必須填寫且值為 1~18
                        if (!(int.TryParse(q4_string, out q4_int) && (q4_int > 0 && q4_int < 19)))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 1 時,「升學:入學方式」必須填寫 1~18。"));
                        }
                    }
                    //  升學 或 就業
                    if (q1_int == 1 || q1_int == 2)
                    {
                        //  未升學未就業:動向,不得填寫
                        if (!string.IsNullOrEmpty(q5_string))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 1~2 時,「未升學未就業:動向」不得填寫。"));
                        }
                    }
                    if (q1_int == 3)
                    {
                        //  未升學未就業:動向,必須填寫且值為 1~6
                        if (!(int.TryParse(q5_string, out q5_int) && (q5_int > 0 && q5_int < 7)))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 3 時,「未升學未就業:動向」必須填寫 1~6。"));
                        }
                    }
                    //  非升學
                    if (q1_int == 3 || q1_int == 2)
                    {
                        //  升學:就讀學校情形,不得填寫
                        if (!string.IsNullOrEmpty(q2_string))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 2~3 時,「升學:就讀學校情形」不得填寫。"));
                        }
                        //  升學:入學方式,不得填寫
                        if (!string.IsNullOrEmpty(q3_string))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 2~3 時,「升學:入學方式」不得填寫。"));
                        }
                        //  升學:學制別,不得填寫
                        if (!string.IsNullOrEmpty(q4_string))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 2~3 時,「升學:學制別」不得填寫。"));
                        }
                    }
                }
                #endregion

                #region 檢查就讀學校
                if (int.TryParse(q2_string, out q2_int))
                {
                    if (q2_int == 5)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 8)
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 5 時,學制別僅填8。"));
                            }
                        }

                        if (int.TryParse(q4_string, out q4_int))
                        {
                            List <int> Contents = new List <int>()
                            {
                                16, 17
                            };

                            if (!Contents.Contains(q4_int))
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 5 時,入學方式僅填16、17。"));
                            }
                        }
                    }

                    if (q2_int == 6)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 9)
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 6 時,學制別僅填9。"));
                            }
                        }

                        if (int.TryParse(q4_string, out q4_int))
                        {
                            if (q4_int != 3)
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 6 時,入學方式僅填3。"));
                            }
                        }
                    }

                    if (q2_int == 7 || q2_int == 8)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 9)
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 7、8 時,學制別僅填9。"));
                            }
                        }

                        if (int.TryParse(q4_string, out q4_int))
                        {
                            if (q4_int != 18)
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 7、8 時,入學方式僅填18。"));
                            }
                        }
                    }
                }
                #endregion

                #region 檢查入學方式
                if (int.TryParse(q4_string, out q4_int))
                {
                    //1. 入學方式填12,學制別填5或6。
                    if (q4_int == 12)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            List <int> Contents = new List <int>()
                            {
                                5, 6
                            };

                            if (!Contents.Contains(q3_int))
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「入學方式」填12,「學制別」僅填5或6。"));
                            }
                        }
                    }

                    //2. 入學方式填14,學制別僅填4。
                    if (q4_int == 14)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 4)
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「入學方式」填14,「學制別」僅填4。"));
                            }
                        }
                    }

                    //3. 入學方式填6,學制別僅填1。
                    if (q4_int == 6)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 1)
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「入學方式」填6,「學制別」僅填1。"));
                            }
                        }
                    }
                    //4. 入學方式填9,學制別僅填3。
                    if (q4_int == 9)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 3)
                            {
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「入學方式」填9,「學制別」僅填3。"));
                            }
                        }
                    }
                }
                #endregion

                #region 檢查未升學未就業動向
                if (int.TryParse(q5_string, out q5_int))
                {
                    if (q5_int == 2)
                    {
                        #region 若為在家需填寫「是」「否」需教育部協助選項。
                        if (string.IsNullOrEmpty(q6_string))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「未升學未就業:動向」為2在家,請選填「是」「否」需教育部協助選項。"));
                        }
                        #endregion

                        #region 若填寫「是」,需在「備註」欄填寫聯絡電話及通訊地址
                        if (q6_string.Equals("是") && string.IsNullOrEmpty(memo))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「未升學未就業:動向」為2在家,請選填「是」「否」需教育部協助選項,需教育部協助者請於「備註」欄填寫聯絡電話及通訊地址。"));
                        }
                        #endregion
                    }

                    #region 若為1失聯,請於「備註」欄中註明失聯原因
                    if (q5_int == 1)
                    {
                        if (string.IsNullOrEmpty(memo))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「未升學未就業:動向」為1失聯,請於「備註」欄中註明失聯原因(如家長不知學生去向、電話空號等)。"));
                        }
                    }
                    #endregion

                    #region 若為6其他,請於「備註」欄中註明情況。
                    if (q5_int == 6)
                    {
                        if (string.IsNullOrEmpty(memo))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「未升學未就業:動向」為6其他,請於「備註」欄中註明情況。"));
                        }
                    }
                    #endregion
                }
                #endregion

                #region 檢查需教育部協助
                if (!string.IsNullOrEmpty(q6_string))
                {
                    if (!(q6_string.Equals("是") || q6_string.Equals("否")))
                    {
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「需教育部協助」僅能填入「是」或「否」。"));
                    }
                }
                #endregion
            });
        }
        public void CustomValidator(List<IRowStream> Rows, RowMessages Messages)
        {
            DataTable dataTables = this.Query.Select("select id_number, id, name from student");
            foreach (DataRow row in dataTables.Rows)
            {
                if (string.IsNullOrWhiteSpace(row["id_number"] + ""))
                    continue;

                if (!this.dicStudents.ContainsKey(row["id_number"] + ""))
                    this.dicStudents.Add(row["id_number"] + "", new Dictionary<string, string>() {{ row["id"] + "", row["name"] + "" }});
            }
            Rows.ForEach((x) =>
            {
                string id_number = x.GetValue("身分證號").Trim();
                string name = x.GetValue("姓名").Trim();
                string q1_string = x.GetValue("升學與就業情形").Trim();
                string q2_string = x.GetValue("升學:就讀學校情形").Trim();
                string q3_string = x.GetValue("升學:學制別").Trim();
                string q4_string = x.GetValue("升學:入學方式").Trim();
                string q5_string = x.GetValue("未升學未就業:動向").Trim();
                string q6_string = x.GetValue("是否需要教育部協助").Trim();
                string memo = x.GetValue("備註").Trim();

                int q1_int;
                int q2_int;
                int q3_int;
                int q4_int;
                int q5_int;

                #region 檢查身分證號
                //  「身分證號」必須存在於系統
                if (!this.dicStudents.ContainsKey(id_number))
                {
                    Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "身分證號不存在。"));
                }
                //  「身分證號」必須與「姓名」一致
                else
                {
                    if (this.dicStudents[id_number].ElementAt(0).Value.Trim().ToLower() != name.ToLower())
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "使用身分證號驗證學生姓名錯誤。"));
                }
                #endregion

                #region  檢查「升學與就業情形」
                if (int.TryParse(q1_string, out q1_int))
                {
                    //有填寫並且為 1
                    if (q1_int == 1)
                    {
                        //  升學:就讀學校情形,必須填寫且值為 1~8
                        if (!(int.TryParse(q2_string, out q2_int) && (q2_int > 0 && q2_int < 9)))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 1 時,「升學:就讀學校情形」必須填寫 1~8。"));
                        }
                        //  升學:學制別,必須填寫且值為 1~9
                        if (!(int.TryParse(q3_string, out q3_int) && (q3_int > 0 && q3_int < 10)))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 1 時,「升學:學制別」必須填寫 1~9。"));
                        }
                        //  升學:入學方式,必須填寫且值為 1~18
                        if (!(int.TryParse(q4_string, out q4_int) && (q4_int > 0 && q4_int < 19)))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 1 時,「升學:入學方式」必須填寫 1~18。"));
                        }
                    }
                    //  升學 或 就業
                    if (q1_int == 1 || q1_int == 2)
                    {
                        //  未升學未就業:動向,不得填寫
                        if (!string.IsNullOrEmpty(q5_string))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 1~2 時,「未升學未就業:動向」不得填寫。"));
                        }
                    }
                    if (q1_int == 3)
                    {
                        //  未升學未就業:動向,必須填寫且值為 1~6
                        if (!(int.TryParse(q5_string, out q5_int) && (q5_int > 0 && q5_int < 7)))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 3 時,「未升學未就業:動向」必須填寫 1~6。"));
                        }
                    }
                    //  非升學
                    if (q1_int == 3 || q1_int == 2)
                    {
                        //  升學:就讀學校情形,不得填寫
                        if (!string.IsNullOrEmpty(q2_string))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 2~3 時,「升學:就讀學校情形」不得填寫。"));
                        }
                        //  升學:入學方式,不得填寫
                        if (!string.IsNullOrEmpty(q3_string))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 2~3 時,「升學:入學方式」不得填寫。"));
                        }
                        //  升學:學制別,不得填寫
                        if (!string.IsNullOrEmpty(q4_string))
                        {
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「升學與就業情形」填寫 2~3 時,「升學:學制別」不得填寫。"));
                        }
                    }
                }
                #endregion

                #region 檢查就讀學校
                if (int.TryParse(q2_string, out q2_int))
                {
                    if (q2_int == 5)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 8)
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 5 時,學制別僅填8。"));
                        }

                        if (int.TryParse(q4_string, out q4_int))
                        {
                            List<int> Contents = new List<int>() {16,17};

                            if (!Contents.Contains(q4_int))
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 5 時,入學方式僅填16、17。"));
                        }
                    }

                    if (q2_int == 6)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 9)
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 6 時,學制別僅填9。"));
                        }

                        if (int.TryParse(q4_string, out q4_int))
                        {
                            if (q4_int != 3)
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 6 時,入學方式僅填3。"));
                        }
                    }

                    if (q2_int == 7 || q2_int == 8)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 9)
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 7、8 時,學制別僅填9。"));
                        }

                        if (int.TryParse(q4_string, out q4_int))
                        {
                            if (q4_int != 18)
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「就讀學校填」填寫 7、8 時,入學方式僅填18。"));
                        }
                    }
                }
                #endregion

                #region 檢查入學方式
                if (int.TryParse(q4_string, out q4_int))
                {
                    //1. 入學方式填12,學制別填5或6。
                    if (q4_int == 12)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            List<int> Contents = new List<int>() {5,6};

                            if (!Contents.Contains(q3_int))
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「入學方式」填12,「學制別」僅填5或6。"));
                        }
                    }

                    //2. 入學方式填14,學制別僅填4。
                    if (q4_int == 14)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 4)
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「入學方式」填14,「學制別」僅填4。"));
                        }
                    }

                    //3. 入學方式填6,學制別僅填1。
                    if (q4_int == 6)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 1)
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「入學方式」填6,「學制別」僅填1。"));
                        }
                    }
                    //4. 入學方式填9,學制別僅填3。
                    if (q4_int == 9)
                    {
                        if (int.TryParse(q3_string, out q3_int))
                        {
                            if (q3_int != 3)
                                Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「入學方式」填9,「學制別」僅填3。"));
                        }
                    }
                }
                #endregion

                #region 檢查未升學未就業動向
                if (int.TryParse(q5_string, out q5_int))
                {
                    if (q5_int == 2)
                    {
                        #region 若為在家需填寫「是」「否」需教育部協助選項。
                        if (string.IsNullOrEmpty(q6_string))
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「未升學未就業:動向」為2在家,請選填「是」「否」需教育部協助選項。"));
                        #endregion

                        #region 若填寫「是」,需在「備註」欄填寫聯絡電話及通訊地址
                        if (q6_string.Equals("是") && string.IsNullOrEmpty(memo))
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「未升學未就業:動向」為2在家,請選填「是」「否」需教育部協助選項,需教育部協助者請於「備註」欄填寫聯絡電話及通訊地址。"));
                        #endregion
                    }

                    #region 若為1失聯,請於「備註」欄中註明失聯原因
                    if (q5_int == 1)
                        if (string.IsNullOrEmpty(memo))
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「未升學未就業:動向」為1失聯,請於「備註」欄中註明失聯原因(如家長不知學生去向、電話空號等)。"));
                    #endregion

                    #region 若為6其他,請於「備註」欄中註明情況。
                    if (q5_int == 6)
                        if (string.IsNullOrEmpty(memo))
                            Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「未升學未就業:動向」為6其他,請於「備註」欄中註明情況。"));
                    #endregion
                }
                #endregion

                #region 檢查需教育部協助
                if (!string.IsNullOrEmpty(q6_string))
                {
                    if (!(q6_string.Equals("是") || q6_string.Equals("否")))
                        Messages[x.Position].MessageItems.Add(new MessageItem(EMBA.Validator.ErrorType.Error, EMBA.Validator.ValidatorType.Row, "「需教育部協助」僅能填入「是」或「否」。"));
                }
                #endregion
            });
        }
 public void CustomValidator(List<IRowStream> Rows, RowMessages Messages)
 {
     #  region 驗證流程
     if (this.SelectedKeyFields.Contains("個案英文名稱"))