/// <summary> /// اعتبارسنجی عملیات درج /// </summary> /// <param name="assignRule">قوانین تخصیص داده شده به پرسنل</param> protected override void InsertValidate(PersonRuleCatAssignment assignRule) { UIValidationExceptions exception = new UIValidationExceptions(); RuleCategoryRepository catRep = new RuleCategoryRepository(false); PersonRepository personRep = new PersonRepository(false); DateTime fromDate, toDate; this.CheckUserInterfaceRuleGroup(assignRule.Person); if (assignRule.Person == null || personRep.GetCountByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new Person().ID), assignRule.Person.ID)) == 0) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRulePersonIdNotExsits, "پرسنلی با این مشخصات یافت نشد", ExceptionSrc)); } if (assignRule.RuleCategory == null || catRep.GetCountByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new RuleCategory().ID), assignRule.RuleCategory.ID)) == 0) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleIdNotExsits, "گروه قانون با این مشخصات یافت نشد", ExceptionSrc)); } if (!DateTime.TryParse(assignRule.FromDate, out fromDate) || !DateTime.TryParse(assignRule.ToDate, out toDate)) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleDateFormatProblem, "فرمت تاریخ انتساب گروه قانون نادرست میباشد", ExceptionSrc)); } else if (fromDate < Utility.GTSMinStandardDateTime || toDate < Utility.GTSMinStandardDateTime) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleDateSmallerThanStandardValue, "مقدار تاریخ انتساب گروه قانون از حد مجاز کمتر میباشد", ExceptionSrc)); } else if (toDate != Utility.GTSMinStandardDateTime && fromDate >= toDate) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleFromDateGreaterThanToDate, "تاریخ انتساب گروه قانون ابتدا از انتها بزرگتر است", ExceptionSrc)); } else if (exception.Count == 0) { IList <PersonRuleCatAssignment> list = asignRepository.GetByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new PersonRuleCatAssignment().PersonId), assignRule.Person.ID)); //IList<PersonRuleCatAssignment> sortedList = list.OrderBy(o => o.FromDate).ToList(); //if (Utility.ToMildiDateTime(sortedList.Last().ToDate).AddDays(1) != Utility.ToMildiDateTime(assignRule.FromDate) && Utility.ToMildiDateTime(assignRule.FromDate) > Utility.ToMildiDateTime(sortedList.Last().ToDate)) //{ // exception.Add(ExceptionResourceKeys.AssignParameterHasNotSpace, "بین محدوده انتسابها فاصله انتساب داده نشده نباید وجود داشته باشد", ExceptionSrc); //} if (list.Where(x => Utility.ToMildiDateTime(x.FromDate) <= Utility.ToMildiDateTime(assignRule.ToDate) && Utility.ToMildiDateTime(x.ToDate) >= Utility.ToMildiDateTime(assignRule.ToDate)).Count() > 0 || list.Where(x => Utility.ToMildiDateTime(x.FromDate) <= Utility.ToMildiDateTime(assignRule.FromDate) && Utility.ToMildiDateTime(x.ToDate) >= Utility.ToMildiDateTime(assignRule.FromDate)).Count() > 0 || list.Where(x => Utility.ToMildiDateTime(x.FromDate) >= Utility.ToMildiDateTime(assignRule.FromDate) && Utility.ToMildiDateTime(x.FromDate) <= Utility.ToMildiDateTime(assignRule.ToDate)).Count() > 0 ) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleDateHasConfilict, "تاریخ انتساب گروه قانون با تاریخ های قبلی همپوشانی دارد", ExceptionSrc)); } } if (exception.Count > 0) { throw exception; } }
/// <summary> /// شناسه گروه قانون بمنظور استفاده در عملیات دریافت میگردد /// </summary> /// <param name="ruleCategoryId"></param> public BRuleViewer(decimal ruleCategoryId) { RuleCategoryRepository repository = new RuleCategoryRepository(false); IList <RuleCategory> list = repository.GetByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new RuleCategory().ID), ruleCategoryId)); if (list.Count == 1) { workingRuleCategory = list[0]; } else { UIValidationExceptions exception = new UIValidationExceptions(); exception.Add(ExceptionResourceKeys.RuleCategoryIdIsInValid, "پارامتر ارسال شده معرف دسته قانون نمیباشد", ExceptionSrc); throw exception; } }
/// <summary> /// اعتبارسنجی عملیات ویرایش /// </summary> /// <param name="assignRule">قوانین تخصیص داده شده به پرسنل</param> protected override void UpdateValidate(PersonRuleCatAssignment assignRule) { UIValidationExceptions exception = new UIValidationExceptions(); RuleCategoryRepository catRep = new RuleCategoryRepository(false); DateTime fromDate, toDate; PersonRepository personRep = new PersonRepository(false); if (assignRule.Person == null || personRep.GetCountByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new Person().ID), assignRule.Person.ID)) == 0) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRulePersonIdNotExsits, "پرسنلی با این مشخصات یافت نشد", ExceptionSrc)); } if (assignRule.RuleCategory == null || catRep.GetCountByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new RuleCategory().ID), assignRule.RuleCategory.ID)) == 0) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleIdNotExsits, "گروه قانون با این مشخصات یافت نشد", ExceptionSrc)); } if (!DateTime.TryParse(assignRule.FromDate, out fromDate) || !DateTime.TryParse(assignRule.ToDate, out toDate)) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleDateFormatProblem, "فرمت تاریخ انتساب گروه قانون نادرست میباشد", ExceptionSrc)); } else if (fromDate < Utility.GTSMinStandardDateTime || toDate < Utility.GTSMinStandardDateTime) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleDateSmallerThanStandardValue, "مقدار تاریخ انتساب گروه قانون از حد مجاز کمتر میباشد", ExceptionSrc)); } else if (toDate != Utility.GTSMinStandardDateTime && fromDate >= toDate) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleFromDateGreaterThanToDate, "تاریخ انتساب گروه قانون ابتدا از انتها بزرگتر است", ExceptionSrc)); } else if (exception.Count == 0) { IList <PersonRuleCatAssignment> list = asignRepository.GetByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new PersonRuleCatAssignment().PersonId), assignRule.Person.ID), new CriteriaStruct(Utility.GetPropertyName(() => new PersonRuleCatAssignment().ID), assignRule.ID, CriteriaOperation.NotEqual)); if (list.Where(x => Utility.ToMildiDateTime(x.FromDate) <= Utility.ToMildiDateTime(assignRule.ToDate) && Utility.ToMildiDateTime(x.ToDate) >= Utility.ToMildiDateTime(assignRule.ToDate)).Count() > 0 || list.Where(x => Utility.ToMildiDateTime(x.FromDate) <= Utility.ToMildiDateTime(assignRule.FromDate) && Utility.ToMildiDateTime(x.ToDate) >= Utility.ToMildiDateTime(assignRule.FromDate)).Count() > 0 || list.Where(x => Utility.ToMildiDateTime(x.FromDate) >= Utility.ToMildiDateTime(assignRule.FromDate) && Utility.ToMildiDateTime(x.FromDate) <= Utility.ToMildiDateTime(assignRule.ToDate)).Count() > 0 ) { exception.Add(new ValidationException(ExceptionResourceKeys.AssignRuleDateHasConfilict, "تاریخ انتساب گروه قانون با تاریخ های قبلی همپوشانی دارد", ExceptionSrc)); } } if (exception.Count > 0) { throw exception; } }