public void DataValidation(ProjectAllocationFramework.Statues.ProgressChangedEventHandler OnProgress, List <WorkerEntity> entityList)
        {
            if (entityList == null || entityList.Count == 0)
            {
                return;
            }

            List <WorkerEntity> userDBList = GetDataFromDB(OnProgress);
            var WorkerCodeDBList           = from item in userDBList
                                             select item.WorkerCode;
            ListRangeValidator <string> WorkerCodeListRangeValidator = new ListRangeValidator <string>(WorkerCodeDBList.ToList <string>(), true, ProjectAllocationResource.Message.Worker_WorkerCode_Exists);


            var WorkerCodeList = from item in entityList
                                 select item.WorkerCode;
            UniqueValidator <string> UniqueValidator = new UniqueValidator <string>(WorkerCodeList.ToList <string>(), ProjectAllocationResource.Message.Worker_WorkerCode_Unique);

            ValidatorFactory         valFactory      = EnterpriseLibraryContainer.Current.GetInstance <ValidatorFactory>();
            Validator <WorkerEntity> entityValidator = valFactory.CreateValidator <WorkerEntity>();
            int           i       = 1;
            bool          noError = true;
            int           count   = entityList.Count();
            StringBuilder builder = new StringBuilder();

            foreach (WorkerEntity entity in entityList)
            {
                ValidationResults results = entityValidator.Validate(entity);

                if (!entity.ReadOnly)
                {
                    ValidationResults userExistCheckResults = WorkerCodeListRangeValidator.Validate(entity.WorkerCode);
                    results.AddAllResults(userExistCheckResults);
                }

                ValidationResults uniqueCheckResult = UniqueValidator.Validate(entity.WorkerCode);
                results.AddAllResults(uniqueCheckResult);

                bool isValid = results.IsValid;

                noError &= isValid;

                if (!isValid)
                {
                    builder.AppendLine(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            ProjectAllocationResource.Message.Common_Row_Error,
                            entity.Row));

                    foreach (ValidationResult result in results)
                    {
                        builder.AppendLine(
                            string.Format(
                                CultureInfo.CurrentCulture,
                                ProjectAllocationResource.Message.Common_Field_Error,
                                result.Message));
                    }
                }
                if (OnProgress != null)
                {
                    string InfomationMessage = string.Format(ProjectAllocationResource.Message.Common_Master_Validate_Info, i);
                    int    Percentage        = (int)(i * Constant.ProgressBarMaximum / count);
                    ProjectAllocationFramework.Statues.ProgressChangedEventArgs args = new ProjectAllocationFramework.Statues.ProgressChangedEventArgs(InfomationMessage, Percentage, null);
                    OnProgress(this, args);
                }

                i++;
            }

            if (!noError)
            {
                throw new ProjectAllocationFramework.RuntimeException("Validation Error", builder.ToString());
            }
        }
        public void DataValidation(BudgetProgressChangedEventHandler OnProgress, List <CurrencyEntity> entityList)
        {
            if (entityList == null || entityList.Count == 0)
            {
                return;
            }

            //List<CategoryEntity> categoryDBList = GetAllCategoryDataFromDB(OnProgress);
            //var categoryCodeDBList = from item in categoryDBList
            //          select item.CategoryCode;
            //ListRangeValidator<string> categoryCodelistRangeValidator = new ListRangeValidator<string>(categoryCodeDBList.ToList<string>(), BudgetResource.Message.Currency_CategoryCode_NoExist);

            List <CurrencyEntity> currencyDBList = GetDataFromDB(OnProgress);
            var currencyCodeDBList = from item in currencyDBList
                                     select item.CurrencyCode;
            ListRangeValidator <string> currencyCodeListRangeValidator = new ListRangeValidator <string>(currencyCodeDBList.ToList <string>(), true, BudgetResource.Message.Currency_CurrencyCode_Exists);


            var currencyCodeList = from item in entityList
                                   select item.CurrencyCode;
            UniqueValidator <string> UniqueValidator = new UniqueValidator <string>(currencyCodeList.ToList <string>(), BudgetResource.Message.Currency_CurrencyCode_Unique);

            ValidatorFactory           valFactory      = EnterpriseLibraryContainer.Current.GetInstance <ValidatorFactory>();
            Validator <CurrencyEntity> entityValidator = valFactory.CreateValidator <CurrencyEntity>();
            int           i       = 1;
            bool          noError = true;
            int           count   = entityList.Count();
            StringBuilder builder = new StringBuilder();

            foreach (CurrencyEntity entity in entityList)
            {
                ValidationResults results = entityValidator.Validate(entity);

                //ValidationResults categoryExistCheckResults = categoryCodelistRangeValidator.Validate(entity.CategoryCode);
                //results.AddAllResults(categoryExistCheckResults);

                if (!entity.ReadOnly)
                {
                    ValidationResults currencyExistCheckResults = currencyCodeListRangeValidator.Validate(entity.CurrencyCode);
                    results.AddAllResults(currencyExistCheckResults);
                }

                ValidationResults uniqueCheckResult = UniqueValidator.Validate(entity.CurrencyCode);
                results.AddAllResults(uniqueCheckResult);

                bool isValid = results.IsValid;

                noError &= isValid;

                if (!isValid)
                {
                    builder.AppendLine(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            BudgetResource.Message.Common_Row_Error,
                            entity.Row));

                    foreach (ValidationResult result in results)
                    {
                        builder.AppendLine(
                            string.Format(
                                CultureInfo.CurrentCulture,
                                BudgetResource.Message.Common_Field_Error,
                                result.Message));
                    }
                }
                if (OnProgress != null)
                {
                    string InfomationMessage            = string.Format("you are validating No. {0} data", i);
                    int    Percentage                   = (int)(i * BudgetConstant.ProgressBarMaximum / count);
                    BudgetProgressChangedEventArgs args = new BudgetProgressChangedEventArgs(InfomationMessage, Percentage, null);
                    OnProgress(this, args);
                }

                i++;
            }

            if (!noError)
            {
                throw new BudgetRuntimeException("Validation Error", builder.ToString());
            }
        }