예제 #1
0
 public AttributeEditDlg(string fieldName, double maxValue)
 {
     this.InitializeComponent();
     this.dxValidationProvider1.ValidationMode = ValidationMode.Manual;
     this.dxValidationProvider1.SetIconAlignment(this.spinEdit, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
     this.dxValidationProvider1.SetIconAlignment(this.cmdEdit, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
     this._fieldName = fieldName;
     this._role      = new CustomValidationRule(fieldName);
     if (fieldName == "FlyTime")
     {
         this.layoutSpin.Visibility        = LayoutVisibility.Always;
         this.spinEdit.Properties.MinValue = 0m;
         this.spinEdit.Properties.MaxValue = (decimal)maxValue;
         this.dxValidationProvider1.SetValidationRule(this.spinEdit, this._role);
         return;
     }
     if (fieldName == "FlyMode")
     {
         this.layoucombox.Visibility = LayoutVisibility.Always;
         this.cmdEdit.Properties.Items.Add("Smooth");
         this.cmdEdit.Properties.Items.Add("Bounce");
         this.cmdEdit.Properties.Items.Add("Linear");
         this.cmdEdit.Properties.CycleOnDblClick = true;
         this.cmdEdit.SelectedItem = "Smooth";
         this.cmdEdit.DoubleClick += new EventHandler(this.cmdEdit_DoubleClick);
         this.dxValidationProvider1.SetValidationRule(this.cmdEdit, this._role);
     }
 }
예제 #2
0
        public UserEditFm(Utils.Operation operation, UsersDTO model)
        {
            InitializeComponent();

            usersService = Program.kernel.Get <IUsersService>();

            this.operation     = operation;
            usersBS.DataSource = Item = model;

            fioTBox.DataBindings.Add("EditValue", usersBS, "Fio");
            loginTBox.DataBindings.Add("EditValue", usersBS, "Login");
            passwordTBox.DataBindings.Add("EditValue", usersBS, "Password");

            roleEdit.DataBindings.Add("EditValue", usersBS, "UserRoleId");
            roleEdit.Properties.DataSource    = usersService.GetUserRoles();
            roleEdit.Properties.ValueMember   = "RoleId";
            roleEdit.Properties.DisplayMember = "RoleName";

            if (operation == Utils.Operation.Add)
            {
                roleEdit.EditValue = 0;
            }

            CustomValidationRule customValidationRule = new CustomValidationRule();

            customValidationRule.ErrorText = "Поле пароль обязательное для заполнения, длинной не более 20 символов";
            customValidationRule.ErrorType = ErrorType.Critical;

            userValidationProvider.SetValidationRule(passwordTBox, customValidationRule);

            userValidationProvider.Validate();
        }
예제 #3
0
        /// <summary>
        /// Add a new rule to the validator
        /// </summary>
        /// <param name="condition">The condition to check</param>
        /// <param name="message">The message that is returned in case of an error</param>
        /// <returns>The validator</returns>
        public Validator <T> AddRule(Func <T, bool> condition, string message)
        {
            var rule = new CustomValidationRule <T>(message)
                       .AddCondition(new Conditions.CustomEntityCondition <T>(condition));

            AddRule(rule);

            return(this);
        }
        public void Validation_Integration_CustomValidationRule_Message_CustomPrpertCondition_Test()
        {
            var rule = new CustomValidationRule <TestClass>()
                       .AddCondition(new CustomPropertyCondition <TestClass, int>(inst => inst.Index, (t, p) => p > 10));

            var result = rule.Validate(new TestClass {
                Index = 5
            });

            Assert.AreEqual("The Property Index caused a validation error", result.Message);
        }
        public void Validation_Integration_CustomValidationRule_CustomPropertyCondition_Valid_Test()
        {
            var rule = new CustomValidationRule <TestClass>()
                       .AddCondition(new CustomPropertyCondition <TestClass, int>(inst => inst.Index, (t, p) => p < 10));

            var result = rule.Validate(new TestClass {
                Index = 5
            });

            Assert.IsNull(result);
        }
        public void Validation_Integration_CustomValidationRule_Message_CustomEntityCondition_Test()
        {
            var rule = new CustomValidationRule <TestClass>("The validation failed")
                       .AddCondition(new CustomEntityCondition <TestClass>(inst => inst.Index > 10));

            var result = rule.Validate(new TestClass {
                Index = 5
            });

            Assert.AreEqual("The validation failed", result.Message);
        }
        public void Validation_Integration_CustomValidationRule_CustomEntityCondition_Valid_Test()
        {
            var rule = new CustomValidationRule <TestClass>("The validation failed")
                       .AddCondition(new CustomEntityCondition <TestClass>(inst => inst.Index < 10));

            var result = rule.Validate(new TestClass {
                Index = 5
            });

            Assert.IsNull(result);
        }
        public void Validation_Integration_CustomValidationRule_CustomMessage_CustomPrpertCondition_WithExternalValue_Test()
        {
            const string Name = "test";
            var          rule = new CustomValidationRule <TestClass>()
                                .AddCondition(new CustomPropertyCondition <TestClass, string>(inst => inst.Name, (t, p) => p == Name))
                                .SetMessage("The validation failed");

            var result = rule.Validate(new TestClass {
                Index = 5, Name = "test 2"
            });

            Assert.AreEqual("The validation failed", result.Message);
        }
예제 #9
0
        public void Validation_Integration_Validator_Add_CustomValidationRule_WrongRuleType_Test()
        {
            var validator = new Validator <TestClass>();
            var rule      = new CustomValidationRule <TestClass>("The validation failed")
                            .AddCondition(new GreaterThanCondition <TestClass, int>(t => t.Index, 4));

            validator.AddRule(rule);
            var summary = validator.Validate(new TestClass {
                Index = 5
            });

            Assert.IsTrue(summary.IsValid);
        }
예제 #10
0
        public void Validation_Integration_Validator_Add_CustomValidationRule_Test()
        {
            var validator = new Validator <TestClass>();
            var rule      = new CustomValidationRule <TestClass>("The validation failed")
                            .AddCondition(new CustomEntityCondition <TestClass>(tc => tc.Name != null));

            validator.AddRule(rule);

            var summary = validator.Validate(new TestClass());

            Assert.IsTrue(summary.ValidationResults.Any());
            Assert.IsFalse(summary.IsValid);
        }