public void EntityValidation(ValidationResults results)
 {
     //--- Required
     if (bill_of_material_head_id == null)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Bill Of Material Head"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (IsCheckedMaterial && material_id == null)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Material"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     else if (!IsCheckedMaterial && bill_of_material_head_id_sub == null)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "BOM"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (amount == null)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Amount"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (lost_factor == null)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Lost Factor"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
 }
        /// <summary>
        /// Un curs poate fi ales cel mult o data de catre un student.
        /// </summary>
        /// <param name="student"></param>
        /// <param name="results"></param>
        internal void ValidateCourseCanOnlyBeChoosenASingleTime(Student student, ValidationResults results)
        {
            if (student.Courses.Where(c => c.CourseId != 0).GroupBy(c => c.CourseId).Any(g => g.Count() > 1))
            {
                results.AddResult(new ValidationResult
                    (
                    "The there are duplicate courses (same id) in the list of courses chosen by the student", results, "ValidationMethod", "error", null)
                    );
                return;
            }

            if (student.Courses.Where(c => c.CourseId != 0).GroupBy(c => new { c.Name, c.Description }).Any(g => g.Count() > 1))
            {
                results.AddResult(new ValidationResult
                   (
                   "The there are duplicate courses (same name & description) in the list of courses chosen by the student", results, "ValidationMethod", "error", null)
                   );
                return;
            }

            if (student.Courses.Where(c => c.CourseId != 0).GroupBy(c => c.Name).Any(g => g.Count() > 1))
            {
                 results.AddResult(new ValidationResult
                    (
                    "The there are duplicate courses in the list of courses (same name) chosen by the student", results, "ValidationMethod", "error", null)
                    );
            }
        }
Beispiel #3
0
 public void EntityValidation(ValidationResults results)
 {
     //--- Required
     if (string.IsNullOrEmpty(employee_no))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Employee No"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (string.IsNullOrEmpty(first_name))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "First Name"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (string.IsNullOrEmpty(last_name))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Last Name"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (string.IsNullOrEmpty(user_name))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "User Name"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (string.IsNullOrEmpty(user_password))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Password"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
 }
Beispiel #4
0
        public void EntityValidation(ValidationResults results)
        {
            //--- Required
            if (menu_id == null)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Menu"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            if (bill_of_material_head_id == null)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Bill of Material Head"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            if (quantity == null)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Quantity"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }

            //---
            if (quantity <= 0)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.CompareValueMore, "Quantity", 0), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
        }
        public void ValidationResultsWithMultipleFailureResultsIsFail()
        {
            ValidationResults validationResults = new ValidationResults();

            validationResults.AddResult(new ValidationResult("message1", null, null, null, null));
            validationResults.AddResult(new ValidationResult("message2", null, null, null, null));

            Assert.IsFalse(validationResults.IsValid);
        }
		public void ReturnsActualResultsCount()
		{
			ValidationResults validationResults = new ValidationResults();
			Assert.AreEqual(0, validationResults.Count);
			validationResults.AddResult(new ValidationResult("message1", null, null, null, null));
			Assert.AreEqual(1, validationResults.Count);
			validationResults.AddResult(new ValidationResult("message2", null, null, null, null));
			Assert.AreEqual(2, validationResults.Count);
		}
 public void EntityValidation(ValidationResults results)
 {
     //--- Required
     if (string.IsNullOrEmpty(bill_of_material_group_code))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Bill Of Material Group Code"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (string.IsNullOrEmpty(bill_of_material_group_name))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Bill Of Material Group Name"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
 }
        public void CanGetTextualRepresentationForExceptionWithMultipleValidationResults()
        {
            var results = new ValidationResults();
            results.AddResult(new ValidationResult("message1", null, null, null, null));
            results.AddResult(new ValidationResult("message2", null, "the key", null, null));
            results.AddResult(new ValidationResult("message3", null, null, null, null));
            var exception = new ArgumentValidationException(results, "param");
            var toString = exception.ToString();

            Assert.IsNotNull(toString);
            Assert.IsTrue(toString.Contains("message1"));
            Assert.IsTrue(toString.Contains("message2"));
            Assert.IsTrue(toString.Contains("message3"));
        }
        public void CanEnumerateThroughNonGenericEnumeratorInterface()
        {
            ValidationResults validationResults = new ValidationResults();
            validationResults.AddResult(new ValidationResult("message1", null, null, null, null));
            validationResults.AddResult(new ValidationResult("message2", null, null, null, null));

            IEnumerator enumerator = (validationResults as IEnumerable).GetEnumerator();

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual("message1", ((ValidationResult)enumerator.Current).Message);
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual("message2", ((ValidationResult)enumerator.Current).Message);
            Assert.IsFalse(enumerator.MoveNext());
        }
Beispiel #10
0
 public void EntityValidation(ValidationResults results)
 {
     //--- Required
     if (string.IsNullOrEmpty(menu_code))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Menu Code"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (string.IsNullOrEmpty(menu_name))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Menu Name"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
 }
Beispiel #11
0
 public void EntityValidation(ValidationResults results)
 {
     //--- Required
     if (string.IsNullOrEmpty(material_code))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Material Code"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (string.IsNullOrEmpty(material_name))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Material Name"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (uom_id_receive == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "UOM Receive"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (uom_id_count == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "UOM Count"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (uom_id_use == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "UOM Use"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (max_stock == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Maximum Stock"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (min_stock == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Minimum Stock"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (shelf_life == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Shelf Life"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (material_cost == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Material Cost"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (acceptable_variance == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Acceptable Variance"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (material_group_id == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Material Group"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
 }
Beispiel #12
0
        public void Validate(ValidationResults results)
        {
            if (string.IsNullOrEmpty(this.control_code) && this.control_parent_id == null)
            {
                ValidationResult result = new ValidationResult(ErrorMessage.ScreenCodeIsRequire, this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }

            List<DuplicateItemDTO> listDuplicateItemDTO = ServiceProvider.ScreenConfigService.IsDuplication(this);
            if (listDuplicateItemDTO.Where(item => item.isDuplicate == true).FirstOrDefault() != null)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsDuplicate, "Screen Code"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
        }
Beispiel #13
0
 public void DoValidateSubmit(ValidationResults results)
 {
     if (this.Modes.Count == 0)
         results.AddResult(new ValidationResult("At least one ground transportation mode is required.",
             typeof(Ground),
             "", "", null));
 }
        public void ControlValidationMappingsFailureTest()
        {
            IBugzillaPageView viewMock = MockRepository.StrictMock<IBugzillaPageView>();

            Expect.Call(viewMock.Model).PropertyBehavior();
            viewMock.ValidationRequested += null;
            LastCall.IgnoreArguments();
            viewMock.ControlValidationTriggered += null;
            LastCall.IgnoreArguments();
            IEventRaiser raiser = LastCall.GetEventRaiser();
            Expect.Call(FacadeMock.GetSourceList()).Return(new string[0]);
            Expect.Call(viewMock.SourceList).PropertyBehavior().Return(new string[0]);
            Expect.Call(FacadeMock.GetProjectWrapperList()).Return(null);
            Expect.Call(viewMock.VersionOneProjects).PropertyBehavior();
            Expect.Call(FacadeMock.GetVersionOnePriorities()).Return(null);
            Expect.Call(viewMock.VersionOnePriorities).PropertyBehavior();
            viewMock.DataBind();
            ValidationResults results = new ValidationResults();
            ValidationResult generalResult = new ValidationResult(string.Empty, new BugzillaProjectMapping(), null, null, null);
            results.AddResult(generalResult);
            Expect.Call(FacadeMock.ValidateEntity(viewMock.Model)).IgnoreArguments().Return(results);
            viewMock.SetGeneralTabValid(true);
            viewMock.SetMappingTabValid(false);

            MockRepository.ReplayAll();

            BugzillaController controller = CreateController();
            controller.RegisterView(viewMock);
            controller.PrepareView();
            raiser.Raise(viewMock, EventArgs.Empty);

            MockRepository.VerifyAll();
        }
        public void Validate(ValidationResults results)
        {
            string msg = string.Empty;

            if (!DateDue.HasValue)
            {
                if (OnOrder > 0)
                {
                    msg = "Must provide a delivery due date for stock on back order.";
                    results.AddResult(new ValidationResult(msg, this, "ProductSelfValidation", "", null));
                }
            }
            else
            {
                if (OnOrder == 0)
                {
                    msg = "Can specify delivery due date only when stock is on back order.";
                    results.AddResult(new ValidationResult(msg, this, "ProductSelfValidation", "", null));
                }
            }

            if (InStock + OnOrder > 100)
            {
                msg = "Total inventory (in stock and on order) cannot exceed 100 items.";
                results.AddResult(new ValidationResult(msg, this, "ProductSelfValidation", "", null));
            }
        }
        internal static void Validate(ProductAuction productAuction, ValidationResults results)
        {
            //Console.Write()
            //Console.WriteLine(productAuction.Currency.Name + " " + productAuction.Auction.Currency.Name);
            if (!productAuction.Currency.Name.Equals(productAuction.Auction.Currency.Name))
                results.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult("the same currency is required", productAuction, "ValidatePrice", "error", null));

            if (productAuction.Price <= 0)
                results.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult("price is negative or zero", productAuction, "ValidatePrice", "error", null));

            if (productAuction.Price <= productAuction.Auction.StartPrice)
                results.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult("price is lower than start auction price", productAuction, "ValidatePrice", "error", null));

            if (productAuction.Date != DateTime.Today)
                results.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult("date must be today", productAuction, "ValidateDate", "error", null));
        }
Beispiel #17
0
 public void ValidateCorequisitesInSameSemester(ValidationResults validationResult)
 {
     foreach(var semester in Semesters)
         if(semester.Courses.Contains(this))
             foreach (var course in Corequisites)
                 if(!semester.Courses.Contains(course))
                     validationResult.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult("Corequisite: " + course.Name + " must be in same semester with this course", this, "ValidateCorequisitesInSameSemester", "error", null));
 }
 public void VerifyCoursesCredit(ValidationResults validationResult)
 {
     int creditSum = 0;
     foreach (var course in Courses)
         creditSum += course.Credit;
     if (creditSum < MinCredit)
         validationResult.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult("Courses credit sum smaller than MinCredit",this, "VerifyCoursesCredit", "error",null));
 }
 public void VerifyCoursesHaveNoPrerequisitesInFirstSemester(ValidationResults validationResult)
 {
     if (Number > 1)
         return;
     foreach (var course in Courses)
         if(course.Prerequisites.Count>0)
             validationResult.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult("Courses from the first semester should not have prerequisites", this, "VerifyCoursesHaveNoPrerequisitesInFirstSemester", "error", null));
 }
 public override void Validate(ValidationResults results)
 {
     string msg = string.Empty;
     if (String.IsNullOrEmpty(ZoneCode))
     {
         msg = "ZoneCode cannot be empty";
         results.AddResult(new ValidationResult(msg, this, "ZoneCodeSelfValidation", "", null));
     }
 }
Beispiel #21
0
 public void ValValue(ValidationResults result)
 {
     if (this.ValueType == DiscountValueType.Amount)
     {
         if ((this.DiscountValue < Convert.ToDecimal((double) 0.01)) || (this.DiscountValue > 10000000M))
         {
             result.AddResult(new ValidationResult("折扣值在0.01-1000万之间", this, "", "", null));
         }
         if (this.DiscountValue > this.Amount)
         {
             result.AddResult(new ValidationResult("折扣值不能大于满足金额", this, "", "", null));
         }
     }
     else if ((this.ValueType == DiscountValueType.Percent) && ((this.DiscountValue < 1M) || (this.DiscountValue > 100M)))
     {
         result.AddResult(new ValidationResult("折扣率在1-100之间", this, "", "", null));
     }
 }
        internal static void Validate(Auction auction, ValidationResults results)
        {
            if (auction.StartPrice > 10000000 || auction.StartPrice < 0.1)//some business-logic derived condition
             {
                 results.AddResult
                     (
                         new ValidationResult("In a auction start price must be between 0.1 and 10000000", auction, "ValidateMethod", "error", null)
                     );
             }

             if (auction.BeginDate > auction.EndDate)//some business-logic derived condition
             {
                 results.AddResult
                     (
                         new ValidationResult("In a auction begin date can not be grater than end date", auction, "ValidateMethod", "error", null)
                     );
             }
        }
 internal void ExamValidateDate(Exam exam, DateTime examinationDate, ValidationResults results)
 {
     if (examinationDate < DateTime.Today.Date)
     {
         results.AddResult(new ValidationResult
             (
                 "The start date cannot be in the past", exam, "ValidationMethod", "error", null)
             );
     }
 }
 internal static void Validate(Category category, ValidationResults results)
 {
     if ( category.Name.Length < 3 || category.Name.Length > 30 || category.Description.Length > 200)//some business-logic derived condition
     {
         results.AddResult
             (
                 new ValidationResult("Invalid category's name/description.", category, "ValidateMethod", "error", null)
             );
     }
 }
 internal void ValidateDates(Semester semester, DateTime startDate, DateTime endDate, ValidationResults results)
 {
     if (startDate > endDate)
     {
         results.AddResult(new ValidationResult
         (
           "The end date cannot be before the start date", semester, "ValidationMethod", "error", null)
         );
     }
 }
 public void ValidateStudentIsPresent(Address address, ValidationResults results)
 {
     if (address.StudentId == 0 && address.Student == null)
     {
         results.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult
             (
             "The address must have a student", results, "ValidationMethod", "error", null)
             );
     }
 }
 internal void ValidateEndOfSemester(Semester semester, ValidationResults results)
 {
     if (semester.EndDate < DateTime.Now.Date)
     {
         results.AddResult(new ValidationResult
             (
             "You semester is already finished", semester, "ValidationMethod", "error", null)
             );
     }
 }
Beispiel #28
0
 public void EntityValidation(ValidationResults results)
 {
     //--- Required
     if (period_group_id == 0)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Period Group"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (string.IsNullOrEmpty(period_code))
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Period Code"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
     if (period_date == null)
     {
         ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Period Date"), this, string.Empty, string.Empty, null);
         results.AddResult(result);
     }
 }
 internal static void Validate(Product product, ValidationResults results)
 {
     if (product.Name.Length < 3 || product.Name.Length > 30 || product.Description.Length > 200)//some business-logic derived condition
     {
         results.AddResult
             (
                 new ValidationResult("Invalid product's name/description.", product, "ValidateMethod", "error", null)
             );
     }
 }
        public void Validate(ValidationResults results)
        {
            string msg = string.Empty;

            // Rules that cannot be validated using Data Annotations.

						var enumConverterValidator = new EnumConversionValidator(typeof(ProductType), "Product type must be a value from the '{3}' enumeration.");
            enumConverterValidator.DoValidate(ProductType, this, "ProductType", results);


						if (DateDue.HasValue)
            {
                if (DateDue.Value < DateTime.Today ||
                    DateDue.Value > DateTime.Today.AddMonths(6))
                {
                    msg = "Date due must be between today and six months time.";
                    results.AddResult(new ValidationResult(msg, this, "DateDue", "", null));
                }
            }

            if (!DateDue.HasValue)
            {
                if (OnOrder > 0)
                {
                    msg = "Must provide a delivery due date for stock on back order.";
                    results.AddResult(new ValidationResult(msg, this, "ProductSelfValidation", "", null));
                }
            }
            else
            {
                if (OnOrder == 0)
                {
                    msg = "Can specify delivery due date only when stock is on back order.";
                    results.AddResult(new ValidationResult(msg, this, "ProductSelfValidation", "", null));
                }
            }

            if (InStock + OnOrder > 100)
            {
                msg = "Total inventory (in stock and on order) cannot exceed 100 items.";
                results.AddResult(new ValidationResult(msg, this, "ProductSelfValidation", "", null));
            }
        }
 public void MethodWithSelfValidationAttributesWithRuleset(ValidationResults validationResults)
 {
     validationResults.AddResult(new ValidationResult("MethodWithSelfValidationAttributesWithRuleset", null, null, null, null));
 }
 public void MethodWithoutSelfValidationAttributes(ValidationResults validationResults)
 {
     validationResults.AddResult(new ValidationResult("MethodWithoutSelfValidationAttributes", null, null, null, null));
 }
        protected override void DoValidate(Invoice objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            if (objectToValidate.Contact == null)
            {
                validationResults.AddResult(new ValidationResult("The document has no Contact", currentTarget, key, "Contact", this));
            }

            if (objectToValidate.LineItems == null || !objectToValidate.LineItems.Any())
            {
                validationResults.AddResult(new ValidationResult("The document has no LineItems", currentTarget, key, "LineItems", this));
            }
            else
            {
                ValidationResults vr = new ValidationResults();
                foreach (var item in objectToValidate.LineItems)
                {
                    lineItemValidator.Validate(item, vr);
                }
                if (vr.Any())
                {
                    validationResults.AddResult(new ValidationResult("Invalid LineItems", currentTarget, key, "LineItems", this, vr));
                }

                if (objectToValidate.LineItems.GetLineItemTotal() < 0)
                {
                    validationResults.AddResult(new ValidationResult("The LineItems total must be greater than 0.", currentTarget, key, "LineItems", this));
                }
            }

            if (objectToValidate.Total.HasValue)
            {
                if (objectToValidate.Total.Value != objectToValidate.LineItems.GetLineItemTotal())
                {
                    validationResults.AddResult(new ValidationResult("The document total does not equal the sum of the lines.", currentTarget, key, "Total", this));
                }
                if (objectToValidate.Total.Value < 0)
                {
                    validationResults.AddResult(new ValidationResult("The document total must be greater than 0.", currentTarget, key, "Total", this));
                }
            }

            if (objectToValidate.SubTotal.HasValue)
            {
                if (objectToValidate.SubTotal.Value != objectToValidate.LineItems.GetLineItemSubTotal())
                {
                    validationResults.AddResult(new ValidationResult("The document subtotal does not equal the sum of the lines.", currentTarget, key, "SubTotal", this));
                }
                if (objectToValidate.SubTotal.Value < 0)
                {
                    validationResults.AddResult(new ValidationResult("The document subtotal must be greater than 0.", currentTarget, key, "SubTotal", this));
                }
            }

            if (objectToValidate.TotalTax.HasValue)
            {
                if (objectToValidate.TotalTax.Value != objectToValidate.LineItems.Sum(a => a.TaxAmount))
                {
                    validationResults.AddResult(new ValidationResult("The document totaltax does not equal the sum of the lines.", currentTarget, key, "TotalTax", this));
                }
                if (objectToValidate.TotalTax.Value < 0)
                {
                    validationResults.AddResult(new ValidationResult("The document totaltax must be greater than or equal to 0.", currentTarget, key, "TotalTax", this));
                }
            }

            if (objectToValidate.Type == InvoiceType.AccountsReceivable)
            {
                if (string.IsNullOrEmpty(objectToValidate.Number))
                {
                    validationResults.AddResult(new ValidationResult("Document InvoiceNumber must be specified.", currentTarget, key, "InvoiceNumber", this));
                }
            }

            if (!objectToValidate.DueDate.HasValue)
            {
                validationResults.AddResult(new ValidationResult("DueDate must be specified.", currentTarget, key, "DueDate", this));
            }
        }
Beispiel #34
0
 /// <summary>
 /// Adds the result.
 /// </summary>
 /// <typeparam name="TModel">The type of the model.</typeparam>
 /// <param name="validationResults">The validation results.</param>
 /// <param name="expression">The expression.</param>
 /// <param name="message">The message.</param>
 /// <param name="tag">The tag.</param>
 public static void AddResult <TModel>(this ValidationResults validationResults, Expression <Func <TModel, object> > expression, string message, string tag = null)
 {
     validationResults.AddResult(new ValidationResult(message, null, expression.Body.Type.Name, tag ?? String.Empty, null));
 }
Beispiel #35
0
 public void PublicMethodWithMatchingSignatureButWithoutSelfValidationAttribute(ValidationResults validationResults)
 {
     validationResults.AddResult(new ValidationResult("PublicMethodWithMatchingSignatureButWithoutSelfValidationAttribute", null, null, null, null));
 }
Beispiel #36
0
        public bool PublicMethodWithSelfValidationAttributeAndWithoutReturnType(ValidationResults validationResults)
        {
            validationResults.AddResult(new ValidationResult("PublicMethodWithSelfValidationAttributeAndWithoutReturnType", null, null, null, null));

            return(false);
        }
 private void InheritedProtectedMethodWithSelfValidationAttributeAndMatchingSignature(ValidationResults validationResults)
 {
     validationResults.AddResult(new ValidationResult("InheritedProtectedMethodWithSelfValidationAttributeAndMatchingSignature", null, null, null, null));
 }
Beispiel #38
0
 public override void OverridenPublicMethodWithMatchingSignatureAndSelfValidationAttributeOnBaseAndOnOverride(ValidationResults validationResults)
 {
     validationResults.AddResult(new ValidationResult("OverridenPublicMethodWithMatchingSignatureAndSelfValidationAttributeOnBaseAndOnOverride-Derived", null, null, null, null));
 }
 public virtual void OverridenPublicMethodWithMatchingSignatureAndSelfValidationAttributeOnBaseButNotOnOverride(ValidationResults validationResults)
 {
     validationResults.AddResult(new ValidationResult("OverridenPublicMethodWithMatchingSignatureAndSelfValidationAttributeOnBaseButNotOnOverride", null, null, null, null));
 }
Beispiel #40
0
 public void PublicMethodWithSelfValidationAttributeAndWithInvalidParameters(ValidationResults validationResults, bool invalid)
 {
     validationResults.AddResult(new ValidationResult("PublicMethodWithSelfValidationAttributeAndWithInvalidParameters", null, null, null, null));
 }
Beispiel #41
0
        private void ValidationDetail(TranDetail entity)
        {
            ValidationResults results = new ValidationResults();

            if (baseGridDetail.FormMode == ObjectState.Add)
            {
                if (entity.material_id == 0)
                {
                    ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Material"), this, string.Empty, string.Empty, null);
                    results.AddResult(result);
                }
                else
                {
                    if (entity.warehouse_id_dest != 0)
                    {
                        DataRow[] drs = this.GetDataRowDetail(entity.material_id, entity.warehouse_id_dest);
                        if (drs.Count() >= 1)
                        {
                            ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsDuplicate, "Material"), this, string.Empty, string.Empty, null);
                            results.AddResult(result);
                        }
                    }
                }

                if (entity.warehouse_id_dest == 0)
                {
                    ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Warehouse"), this, string.Empty, string.Empty, null);
                    results.AddResult(result);
                }
            }

            if (string.IsNullOrEmpty(txtLotNo.Text))
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Lot No."), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else if (Converts.ParseDoubleNullable(txtLotNo.Text) == null)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IncorrectFormatOne, "Lot No."), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else if (entity.lot_no == 0)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.CompareValueMore, "Lot No.", "0"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else
            {
                if (entity.material_id != 0 && entity.warehouse_id_dest != 0)
                {
                    PhyLot entityPhyLot = ServiceProvider.PhyLotService.GetPhyLot(entity.material_id, entity.warehouse_id_dest, entity.lot_no.Value, false);
                    if (entityPhyLot == null || entityPhyLot.phy_lot_id == 0)
                    {
                        ValidationResult result = new ValidationResult(string.Format(ErrorMessage.NotExistsField, "Lot No.", entity.lot_no.Value), this, string.Empty, string.Empty, null);
                        results.AddResult(result);
                    }
                    else
                    {
                        if ((entityPhyLot.bal_qty - entity.quantity) < 0)
                        {
                            ValidationResult result = new ValidationResult(string.Format(ErrorMessage.CompareValueMore, "Quantity", "material in stock"), this, string.Empty, string.Empty, null);
                            results.AddResult(result);
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(txtQuantity.Text))
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Quantity"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else if (Converts.ParseDoubleNullable(txtQuantity.Text) == null)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IncorrectFormatOne, "Quantity"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else if (entity.quantity == 0)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.CompareValueMore, "Quantity", "0"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }

            if (results.Count > 0)
            {
                throw new ValidationException(results);
            }
        }
Beispiel #42
0
 private void PrivateMethodWithSelfValidationAttributeAndMatchingSignature(ValidationResults validationResults)
 {
     validationResults.AddResult(new ValidationResult("PrivateMethodWithSelfValidationAttributeAndMatchingSignature", null, null, null, null));
 }
Beispiel #43
0
        public void CheckDistributor(ValidationResults results)
        {
            HiConfiguration config = HiConfiguration.GetConfig();

            if ((string.IsNullOrEmpty(this.Username) || (this.Username.Length > config.UsernameMaxLength)) || (this.Username.Length < config.UsernameMinLength))
            {
                results.AddResult(new ValidationResult(string.Format("用户名不能为空,长度必须在{0}-{1}个字符之间", config.UsernameMinLength, config.UsernameMaxLength), this, "", "", null));
            }
            else if (!Regex.IsMatch(this.Username, config.UsernameRegex))
            {
                results.AddResult(new ValidationResult("用户名的格式错误", this, "", "", null));
            }
            if (string.IsNullOrEmpty(this.Email) || (this.Email.Length > 0x100))
            {
                results.AddResult(new ValidationResult("电子邮件不能为空,长度必须小于256个字符", this, "", "", null));
            }
            else if (!Regex.IsMatch(this.Email, config.EmailRegex))
            {
                results.AddResult(new ValidationResult("电子邮件的格式错误", this, "", "", null));
            }
            if (this.IsCreate)
            {
                if ((string.IsNullOrEmpty(this.Password) || (this.Password.Length > config.PasswordMaxLength)) || (this.Password.Length < 6))
                {
                    results.AddResult(new ValidationResult(string.Format("密码不能为空,长度必须在{0}-{1}个字符之间", 6, config.PasswordMaxLength), this, "", "", null));
                }
                if ((string.IsNullOrEmpty(this.TradePassword) || (this.TradePassword.Length > config.PasswordMaxLength)) || (this.TradePassword.Length < 6))
                {
                    results.AddResult(new ValidationResult(string.Format("交易密码不能为空,长度必须在{0}-{1}个字符之间", 6, config.PasswordMaxLength), this, "", "", null));
                }
            }
            if (!(string.IsNullOrEmpty(this.QQ) || (((this.QQ.Length <= 20) && (this.QQ.Length >= 3)) && Regex.IsMatch(this.QQ, "^[0-9]*$"))))
            {
                results.AddResult(new ValidationResult("QQ号长度限制在3-20个字符之间,只能输入数字", this, "", "", null));
            }
            if (!(string.IsNullOrEmpty(this.Zipcode) || (((this.Zipcode.Length <= 10) && (this.Zipcode.Length >= 3)) && Regex.IsMatch(this.Zipcode, "^[0-9]*$"))))
            {
                results.AddResult(new ValidationResult("邮编长度限制在3-10个字符之间,只能输入数字", this, "", "", null));
            }
            if (!(string.IsNullOrEmpty(this.Wangwang) || ((this.Wangwang.Length <= 20) && (this.Wangwang.Length >= 3))))
            {
                results.AddResult(new ValidationResult("旺旺长度限制在3-20个字符之间", this, "", "", null));
            }
            if (!(string.IsNullOrEmpty(this.MSN) || (((this.MSN.Length <= 0x100) && (this.MSN.Length >= 1)) && Regex.IsMatch(this.MSN, config.EmailRegex))))
            {
                results.AddResult(new ValidationResult("请输入正确MSN帐号,长度在1-256个字符以内", this, "", "", null));
            }
            if (!(string.IsNullOrEmpty(this.CellPhone) || (((this.CellPhone.Length <= 20) && (this.CellPhone.Length >= 3)) && Regex.IsMatch(this.CellPhone, "^[0-9]*$"))))
            {
                results.AddResult(new ValidationResult("手机号码长度限制在3-20个字符之间,只能输入数字", this, "", "", null));
            }
            if (!(string.IsNullOrEmpty(this.TelPhone) || (((this.TelPhone.Length <= 20) && (this.TelPhone.Length >= 3)) && Regex.IsMatch(this.TelPhone, "^[0-9-]*$"))))
            {
                results.AddResult(new ValidationResult("电话号码长度限制在3-20个字符之间,只能输入数字和字符“-”", this, "", "", null));
            }
        }
 private static void AddChildValidationResult(ValidationResults validationResults, PropertyInfo property, ValidationResult childValidationResult)
 {
     validationResults.AddResult(new ValidationResult(childValidationResult.Message, childValidationResult.Target,
                                                      property.Name + ":" + childValidationResult.Key, childValidationResult.Tag, childValidationResult.Validator));
 }
Beispiel #45
0
        protected override void DoValidate(IEnumerable <Fault> objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            Operation operation = currentTarget as Operation;

            if (operation == null)
            {
                return;
            }

            string serviceContractImplementationTech = String.Empty;

            if (operation.ServiceContractModel.ImplementationTechnology == null)
            {
                return;
            }
            else
            {
                serviceContractImplementationTech = operation.ServiceContractModel.ImplementationTechnology.Name;
            }

            SerializerType serviceContractSerializer = operation.ServiceContractModel.SerializerType;

            foreach (Fault item in objectToValidate)
            {
                bool isValid            = true;
                DataContractFault fault = item as DataContractFault;

                if (fault == null || fault.Type == null)
                {
                    continue;
                }

                if (!fault.Type.IsValidReference())
                {
                    validationResults.AddResult(
                        new ValidationResult(
                            String.Format(CultureInfo.CurrentUICulture,
                                          Resources.CannotResolveReference, currentTarget.GetType().Name, fault.Name, fault.Type.GetDisplayName()), fault, key, String.Empty, this));
                    return;
                }

                ModelElement mel = ModelBusReferenceResolver.ResolveAndDispose(fault.Type);
                if (mel == null)
                {
                    return;
                }

                FaultContract dcFault = mel as FaultContract;
                if (dcFault == null ||
                    dcFault.DataContractModel == null ||
                    dcFault.DataContractModel.ImplementationTechnology == null)
                {
                    return;
                }

                if (serviceContractImplementationTech.Equals(ASMXExtension, StringComparison.OrdinalIgnoreCase))
                {
                    if (serviceContractSerializer.Equals(SerializerType.XmlSerializer))
                    {
                        isValid = !(dcFault.DataContractModel.ImplementationTechnology.Name.Equals(WCFExtension, StringComparison.OrdinalIgnoreCase));
                    }
                    else
                    {
                        // Asmx Extension only supports XmlSerializer
                        validationResults.AddResult(
                            new ValidationResult(String.Format(CultureInfo.CurrentUICulture, asmxExtensionInvalidSerializerMessage, fault.Name, operation.Name), objectToValidate, key, String.Empty, this)
                            );
                        return;
                    }
                }
                else if (serviceContractImplementationTech.Equals(WCFExtension, StringComparison.OrdinalIgnoreCase))
                {
                    if (serviceContractSerializer.Equals(SerializerType.DataContractSerializer))
                    {
                        isValid = !(dcFault.DataContractModel.ImplementationTechnology.Name.Equals(ASMXExtension, StringComparison.OrdinalIgnoreCase));
                    }
                    else
                    {
                        if (dcFault.DataContractModel.ImplementationTechnology.Name.Equals(ASMXExtension, StringComparison.OrdinalIgnoreCase))
                        {
                            // Faults cannot be XMLSerializable
                            validationResults.AddResult(
                                new ValidationResult(String.Format(CultureInfo.CurrentUICulture, faultInvalidSerializerMessage, operation.Name, fault.Name), objectToValidate, key, String.Empty, this)
                                );
                            return;
                        }
                    }
                }

                if (!isValid)
                {
                    validationResults.AddResult(
                        new ValidationResult(String.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, fault.Name, operation.Name), objectToValidate, key, String.Empty, this)
                        );
                }
            }
        }