Exemplo n.º 1
0
        public ActionResult ProfilePage(UserProfileModel userProfile, Validator.Validator validator)
        {
            var modelState = validator.Validate(userProfile);
            var validation = new List <string>();
            var success    = false;

            if (modelState.IsValid)
            {
                success = _userProfileService.SetUserProfile(userProfile);
                if (!success)
                {
                    validation.Add(DictionaryKeys.Messages.InvalidOldPassword);
                }
            }
            else
            {
                modelState.Errors.ForEach(err => validation.Add(err.ErrorMessage));
            }

            return(Json(new { validation, success }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 開始進行資料驗證
        /// </summary>
        private void StartValidate()
        {
            //建立資料驗證組合
            ValidatePair Pair = new ValidatePair();
            Pair.DataFile = mImportOption.SelectedDataFile; //資料驗證來源檔案
            Pair.DataSheet = mImportOption.SelectedSheetName; //資料驗證來源檔案資料表
            Pair.ValidatorFile = mImportOption.SelectedValidateFile; //資料驗證描述檔

            Validator.Validator valStart = new Validator.Validator();

            if (mImportWizard.CustomValidate != null)
            {
                //  2012/3/7    自訂驗證規則需要使用者選取的鍵值:paul.wang
                mImportWizard.SelectedKeyFields = mImportOption.SelectedKeyFields;
                mImportWizard.SelectedFields = mImportOption.SelectedFields;
                valStart.CustomValidate = mImportWizard.CustomValidate;
            }

            //執行資料驗證方法
            worker.DoWork += (sender, e) => valStart.Validate(Pair, mResultFilename);

            //將驗證過程顯示在畫面上
            worker.ProgressChanged += (sender, e) =>
            {
                //取得資訊物件(數量/訊息/檔名/工作表名)
                ValidatingPair obj = (ValidatingPair)e.UserState;

                //指定介面進度
                pgValidProgress.Value = e.ProgressPercentage;

                lblProgress.Text = obj.Message;

                //如果錯誤大於0
                if (obj.ErrorCount + obj.WarningCount + obj.AutoCorrectCount > 0)
                {
                    lblErrorCount.Text = ""+obj.ErrorCount;
                    lblWarningCount.Text = ""+obj.WarningCount;
                    lblCorrectCount.Text = ""+obj.AutoCorrectCount;
                }
            };

            //資料驗證完成
            worker.RunWorkerCompleted += (sender, e) =>
            {
                if (e.Error != null)
                    throw e.Error;

                int ErrorText = int.Parse(lblErrorCount.Text);
                int WarningText = int.Parse(lblWarningCount.Text);
                int CorrectText = int.Parse(lblCorrectCount.Text);

                //若是錯誤數量為0才可進行到下一步
                if (lblErrorCount.Text.Equals("0"))
                    this.NextButtonEnabled = true;

                if (ErrorText >= 1) //錯誤大於1
                    pictureBox1.Image = EMBA.Import.Properties.Resources.filter_data_close_64;
                else if (WarningText >= 1) //警告大於1
                    pictureBox1.Image = EMBA.Import.Properties.Resources.filter_data_info_64;
                else //無錯誤亦無警告時
                    pictureBox1.Image = EMBA.Import.Properties.Resources.filter_data_ok_64;

                //將檢視驗證報告的按鈕啟用
                btnViewResult.Enabled = true;

                //將可暫停非同步作業的按鈕取消
                lnkCancelValid.Enabled = false;

                if (mValidatedInfo.ValidatedPairs[0].Exceptions.Count > 0)
                {
                    string ExceptionMessage = string.Empty;

                    foreach (Exception Exception in mValidatedInfo.ValidatedPairs[0].Exceptions)
                        ExceptionMessage += Exception.Message + System.Environment.NewLine;

                    if (!string.IsNullOrEmpty(ExceptionMessage))
                    {
                        ExceptionMessage = "驗證過程中發生錯誤,以下為詳細錯誤訊息:" + System.Environment.NewLine + ExceptionMessage;
                        MessageBox.Show(ExceptionMessage);
                    }

                    pictureBox1.Image = EMBA.Import.Properties.Resources.filter_data_close_64;

                    this.NextButtonEnabled = false;
                }
            };

            //接收資料驗證進度回報函式
            valStart.Progress  = (message, progress) => worker.ReportProgress(progress, message);
            //接收資料驗證完成函式
            valStart.Complete = (message) =>
               {
                   mValidatedInfo = message;
               };

            //支援非同步取消及進度回報
            worker.WorkerSupportsCancellation = true;
            worker.WorkerReportsProgress = true;

            //運用非同步執行資料驗證
            worker.RunWorkerAsync();
        }
        /// <summary>
        /// 开始进行数据验证
        /// </summary>
        private void StartValidate()
        {
            //建立数据验证组合
            ValidatePair Pair = new ValidatePair();
            Pair.DataFile = mImportOption.SelectedDataFile; //数据验证来源档案
            Pair.DataSheet = mImportOption.SelectedSheetName; //数据验证来源档案数据表
            Pair.ValidatorFile = mImportOption.SelectedValidateFile; //数据验证描述文件

            Validator.Validator valStart = new Validator.Validator();

            if (mImportWizard.CustomValidate != null)
                valStart.CustomValidate = mImportWizard.CustomValidate;

            //执行数据验证方法
            worker.DoWork += (sender, e) => valStart.Validate(Pair, mResultFilename);

            //将验证过程显示在画面上
            worker.ProgressChanged += (sender, e) =>
            {
                //取得信息对象(数量/讯息/文件名/工作表名)
                ValidatingPair obj = (ValidatingPair)e.UserState;

                //指定接口进度
                pgValidProgress.Value = e.ProgressPercentage;

                lblProgress.Text = obj.Message;

                //如果错误大于0
                if (obj.ErrorCount + obj.WarningCount + obj.AutoCorrectCount > 0)
                {
                    lblErrorCount.Text = "" + obj.ErrorCount;
                    lblWarningCount.Text = "" + obj.WarningCount;
                    lblCorrectCount.Text = "" + obj.AutoCorrectCount;
                }
            };

            //数据验证完成
            worker.RunWorkerCompleted += (sender, e) =>
            {
                if (e.Error != null)
                    throw e.Error;

                int ErrorText = int.Parse(lblErrorCount.Text);
                int WarningText = int.Parse(lblWarningCount.Text);
                int CorrectText = int.Parse(lblCorrectCount.Text);

                //若是错误数量为0才可进行到下一步
                if (lblErrorCount.Text.Equals("0"))
                    this.NextButtonEnabled = true;

                if (ErrorText >= 1) //错误大于1
                    pictureBox1.Image = Properties.Resources.filter_data_close_64;
                else if (WarningText >= 1) //警告大于1
                    pictureBox1.Image = Properties.Resources.filter_data_info_64;
                else //无错误亦无警告时
                    pictureBox1.Image = Properties.Resources.filter_data_ok_64;

                //将检视验证报告的按钮启用
                btnViewResult.Enabled = true;

                //将可暂停异步操作的按钮取消
                lnkCancelValid.Enabled = false;

                if (mValidatedInfo.ValidatedPairs[0].Exceptions.Count > 0)
                {
                    string ExceptionMessage = string.Empty;

                    foreach (Exception Exception in mValidatedInfo.ValidatedPairs[0].Exceptions)
                        ExceptionMessage += Exception.Message + System.Environment.NewLine;

                    if (!string.IsNullOrEmpty(ExceptionMessage))
                    {
                        ExceptionMessage = "验证过程中发生错误,以下为详细错误讯息:" + System.Environment.NewLine + ExceptionMessage;
                        MessageBox.Show(ExceptionMessage);
                    }

                    pictureBox1.Image = Properties.Resources.filter_data_close_64;

                    this.NextButtonEnabled = false;
                }
            };

            //接收数据验证进度回报函式
            valStart.Progress = (message, progress) => worker.ReportProgress(progress, message);
            //接收数据验证完成函式
            valStart.Complete = (message) =>
            {
                mValidatedInfo = message;
            };

            //支持异步取消及进度回报
            worker.WorkerSupportsCancellation = true;
            worker.WorkerReportsProgress = true;

            //运用异步执行数据验证
            worker.RunWorkerAsync();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Set the input validation.
 /// </summary>
 /// <param name="_validator">A Validator param.</param>
 /// <returns></returns>
 public IMyTextBox setInputValidation(Validator.Validator _validator)
 {
     myRegex = _validator.getMyRegex();
     return(this);
 }