示例#1
0
 /// <summary>
 /// Logging functionality 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void SignInButton_Click(object sender, RoutedEventArgs e)
 {
     LoginVM login = new LoginVM();
     bool result = ValidatorExtensions.IsValidEmailAddress(txt_box1.Text);
     if (txt_box1.Text == null || pass.Password.ToString() == null ||
          string.IsNullOrWhiteSpace(txt_box1.Text) ||
         string.IsNullOrWhiteSpace(pass.Password.ToString()))
     {
         MessageBox.Show("All rows must be fill in!");
     }
     else
     {
         if (result == false) { MessageBox.Show("Incorrect Email validation!"); }
         else
         {
             login.Action1(txt_box1.Text, pass.Password.ToString());
             if (App.currentUser != null)
             {
                 this.NavigationService.Navigate(new Uri("View/LoadingPage.xaml", UriKind.Relative));
             }
             else
             {
                 MessageBox.Show("Account doesn`t exist!");
             }
         }
     }
 }
示例#2
0
        private void Tb_email_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                var bc = new BrushConverter();

                if (!tb_email.Text.Equals(""))
                {
                    if (!ValidatorExtensions.IsValid(tb_email.Text))
                    {
                        p_errorEmail.Visibility = Visibility.Visible;
                        tt_errorEmail.Content   = MainWindow.resourcemanager.GetString("trErrorEmailToolTip");
                        tb_email.Background     = (Brush)bc.ConvertFrom("#15FF0000");
                    }
                    else
                    {
                        p_errorEmail.Visibility = Visibility.Collapsed;
                        tb_email.Background     = (Brush)bc.ConvertFrom("#f8f8f8");
                    }
                }
            }
            catch (Exception ex)
            {
                SectionData.ExceptionMessage(ex, this);
            }
        }
示例#3
0
        /// <summary>
        /// Realization of registering process
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void SignUpButton_Click(object sender, RoutedEventArgs e)
        {
            RegisterVM register = new RegisterVM();
            bool       result   = ValidatorExtensions.IsValidEmailAddress(txt2.Text);

            if (txt1.Text == null || txt2.Text == null ||
                pass2.Password.ToString() == null || string.IsNullOrWhiteSpace(txt1.Text) ||
                string.IsNullOrWhiteSpace(txt2.Text) || string.IsNullOrWhiteSpace(pass2.Password.ToString()))
            {
                MessageBox.Show("All rows must be fill in!");
            }
            else
            {
                if (result == false)
                {
                    MessageBox.Show("Incorrect Email validation!");
                }
                else
                {
                    register.Action1(txt1.Text, txt2.Text, pass2.Password.ToString());
                    if (App.currentUser != null)
                    {
                        this.NavigationService.Navigate(new Uri("View/LoadingPage.xaml", UriKind.Relative));
                    }
                    else
                    {
                        MessageBox.Show("Account already exists!");
                    }
                }
            }
        }
示例#4
0
        private void EmailTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            bool result = ValidatorExtensions.IsValidEmailAddress(EmailTextBox.Text);

            if (!result)
            {
                emailError.Text = "Please Enter Valid Email";
            }
        }
            public void When_ValidParameters_Then_ReturnDate()
            {
                var result = ValidatorExtensions.ConstructDate("01", "02", "2021");

                result.Should().NotBeNull();
                result.Should().HaveValue();
                result.Should().HaveDay(1);
                result.Should().HaveMonth(2);
                result.Should().HaveYear(2021);
            }
        public ValidatableObject <Address> Validate(Address address)
        {
            var add = ValidatorExtensions.AsValidatableObject(address);

            _ = add.ForField <ValidatableObject <Address>, string>(nameof(address.Country)).Required().Length(2, 50);
            _ = add.ForField <ValidatableObject <Address>, string>(nameof(address.Region)).Required().Length(2, 50).Match(Consts.ExpRegion);
            _ = add.ForField <ValidatableObject <Address>, string>(nameof(address.Locality)).Required().Length(2, 50).Match(Consts.ExpLocality);
            _ = add.ForField <ValidatableObject <Address>, string>(nameof(address.Street)).Required().Length(2, 50).Match(Consts.ExpStreet);

            //_ = add.ForField<ValidatableObject<Address>, ushort>(nameof(address.House)).Custom(CheckHouseForTen);

            _ = add.ForField <ValidatableObject <Address>, ushort>(nameof(address.House)).If(HouseIsThousand).SliceForHundred().Else(AddThousand);

            return(add);
        }
示例#7
0
        public UserValidator()
        {
            // First set the cascade mode
            CascadeMode = CascadeMode.StopOnFirstFailure;

            RuleFor(user => user.Id).GreaterThanOrEqualTo(0);
            RuleFor(user => user.Fullname).NotEmpty();
            RuleFor(user => user.Username).NotEmpty();
            RuleFor(user => user.Company).NotNull().SetValidator(new CompanyValidator());
            //RuleFor(user => user.Properties).Must(HaveValidIds).When(user => user.Properties.Count > 0);

            RuleSet("NoPassword", () => ValidatorExtensions.IsNull <User, string>(RuleFor(user => user.Password)));

            RuleSet("Password", () => RuleFor(user => user.Password).NotEmpty());
        }
        public SetSecondaryEpaoEffectiveToDateViewModelValidator()
        {
            RuleFor(vm => vm).Custom((vm, context) =>
            {
                if (vm.Day == null && vm.Month == null && vm.Year == null)
                {
                    context.AddFailure("Date", "Enter an Effective to date");
                }
                else
                {
                    int.TryParse(vm.Day, out var day);
                    int.TryParse(vm.Month, out var month);
                    int.TryParse(vm.Year, out var year);

                    if (day == 0)
                    {
                        context.AddFailure("Day", "Effective to date must include a day");
                    }

                    if (month == 0)
                    {
                        context.AddFailure("Month", "Effective to date must include a month");
                    }

                    if (year == 0)
                    {
                        context.AddFailure("Year", "Effective to date must include a year");
                    }

                    if (day != 0 && month != 0 && year != 0)
                    {
                        var date = ValidatorExtensions.ConstructDate(vm.Day, vm.Month, vm.Year);

                        if (date == null)
                        {
                            context.AddFailure("Date", "Effective to date must be a real date");
                        }
                        else if (date < DateTime.Now.Date)
                        {
                            context.AddFailure("Date", "Effective to date must be in the future");
                        }
                    }
                }
            });
        }
        public RegisterEditOrganisationStandardViewModelValidator(IOrganisationsApiClient apiClient,
                                                                  IRegisterValidator registerValidator)
        {
            _apiClient         = apiClient;
            _registerValidator = registerValidator;
            var errorInEffectiveFrom = false;

            RuleFor(vm => vm).Custom((vm, context) =>
            {
                var validationResultEffectiveFrom = registerValidator.CheckDateIsEmptyOrValid(vm.EffectiveFromDay,
                                                                                              vm.EffectiveFromMonth,
                                                                                              vm.EffectiveFromYear, "EffectiveFromDay",
                                                                                              "EffectiveFromMonth", "EffectiveFromYear", "EffectiveFrom", "Effective From");

                errorInEffectiveFrom = validationResultEffectiveFrom.Errors.Count > 0;

                var validationResultEffectiveTo = registerValidator.CheckDateIsEmptyOrValid(vm.EffectiveToDay,
                                                                                            vm.EffectiveToMonth,
                                                                                            vm.EffectiveToYear, "EffectiveToDay",
                                                                                            "EffectiveToMonth", "EffectiveToYear", "EffectiveTo", "Effective To");

                vm.EffectiveFrom = ValidatorExtensions.ConstructDate(vm.EffectiveFromDay, vm.EffectiveFromMonth, vm.EffectiveFromYear);
                vm.EffectiveTo   = ValidatorExtensions.ConstructDate(vm.EffectiveToDay, vm.EffectiveToMonth, vm.EffectiveToYear);

                CreateFailuresInContext(validationResultEffectiveFrom.Errors, context);
                CreateFailuresInContext(validationResultEffectiveTo.Errors, context);

                var deliveryAreas             = vm.DeliveryAreas ?? new List <int>();
                var validationResultExternals = _apiClient
                                                .ValidateUpdateOrganisationStandard(vm.OrganisationId, vm.OrganisationStandardId, vm.StandardId, vm.EffectiveFrom,
                                                                                    vm.EffectiveTo, vm.ContactId, deliveryAreas, vm.ActionChoice, vm.Status, vm.OrganisationStatus).Result;
                if (validationResultExternals.IsValid)
                {
                    return;
                }
                foreach (var error in validationResultExternals.Errors)
                {
                    if (errorInEffectiveFrom == false || error.Field != "EffectiveFrom")
                    {
                        context.AddFailure(error.Field, error.ErrorMessage);
                    }
                }
            });
        }
示例#10
0
        private bool validateEmail(TextBox tb, System.Windows.Shapes.Path p_error, ToolTip tt_error)
        {
            bool isValid = true;

            if (!tb.Text.Equals(""))
            {
                if (!ValidatorExtensions.IsValid(tb.Text))
                {
                    p_error.Visibility = Visibility.Visible;
                    tt_error.Content   = ("Email address is not valid");
                    tb.Background      = (SolidColorBrush)(new BrushConverter().ConvertFrom("#15FF0000"));
                    isValid            = false;
                }
                else
                {
                    p_error.Visibility = Visibility.Collapsed;
                    tb.Background      = (SolidColorBrush)(new BrushConverter().ConvertFrom("#f8f8f8"));
                    isValid            = true;
                }
            }
            return(isValid);
        }
示例#11
0
        private void txtEmail_TextChanged(object sender, TextChangedEventArgs e)
        {
            bool result = false;
            var  email  = (sender as TextBox).Text;

            if (string.IsNullOrEmpty(email))
            {
                result = true;
            }
            else if (ValidatorExtensions.IsValidEmailAddress(email))
            {
                result = true;
            }

            if (result)
            {
                errEmail.Visibility = Visibility.Collapsed;
            }
            else
            {
                errEmail.Visibility = Visibility.Visible;
            }
        }
示例#12
0
        private async void Btn_save_Click(object sender, RoutedEventArgs e)
        {//save
            try
            {
                if (sender != null)
                {
                    SectionData.StartAwait(grid_main);
                }
                //chk empty name
                SectionData.validateEmptyTextBox(tb_name, p_errorName, tt_errorName, "trEmptyNameToolTip");
                //chk empty mobile
                SectionData.validateEmptyTextBox(tb_mobile, p_errorMobile, tt_errorMobile, "trEmptyMobileToolTip");
                //validate email
                SectionData.validateEmail(tb_email, p_errorEmail, tt_errorEmail);

                string phoneStr = "";
                if (!tb_phone.Text.Equals(""))
                {
                    phoneStr = cb_areaPhone.Text + "-" + cb_areaPhoneLocal.Text + "-" + tb_phone.Text;
                }
                string faxStr = "";
                if (!tb_fax.Text.Equals(""))
                {
                    faxStr = cb_areaFax.Text + "-" + cb_areaFaxLocal.Text + "-" + tb_fax.Text;
                }
                bool emailError = false;
                if (!tb_email.Text.Equals(""))
                {
                    if (!ValidatorExtensions.IsValid(tb_email.Text))
                    {
                        emailError = true;
                    }
                }

                //decimal maxDeserveValue = 0;

                if ((!tb_name.Text.Equals("")) && (!tb_mobile.Text.Equals("")))
                {
                    if (emailError)
                    {
                        Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trErrorEmailToolTip"), animation: ToasterAnimation.FadeIn);
                    }
                    else
                    {
                        //SectionData.genRandomCode(type);
                        if (agent.agentId == 0)
                        {
                            tb_code.Text = await agentModel.generateCodeNumber(type);

                            agent.type     = type;
                            agent.accType  = "";
                            agent.balance  = 0;
                            agent.isActive = 1;
                        }
                        if (type == "c")
                        {
                            agent.isLimited = (bool)tgl_hasCredit.IsChecked;
                            decimal maxDeserveValue = 0;
                            if (!tb_upperLimit.Text.Equals(""))
                            {
                                maxDeserveValue = decimal.Parse(tb_upperLimit.Text);
                            }
                            agent.maxDeserve = maxDeserveValue;
                        }
                        else
                        {
                            agent.maxDeserve = 0;
                            agent.isLimited  = false;
                        }
                        agent.name    = tb_name.Text;
                        agent.code    = tb_code.Text;
                        agent.company = tb_company.Text;
                        agent.address = tb_address.Text;
                        agent.email   = tb_email.Text;
                        agent.phone   = phoneStr;
                        agent.mobile  = cb_areaMobile.Text + "-" + tb_mobile.Text;
                        agent.image   = "";

                        agent.createUserId = MainWindow.userID;
                        agent.updateUserId = MainWindow.userID;
                        agent.notes        = tb_notes.Text;
                        agent.fax          = faxStr;

                        int s = await agentModel.save(agent);

                        if (s > 0)
                        {
                            //Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopSave"), animation: ToasterAnimation.FadeIn);
                            isOk = true;
                            this.Close();
                        }
                        //else
                        //Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn);


                        if (isImgPressed)
                        {
                            int    agentId = s;
                            string b       = await agentModel.uploadImage(imgFileName, Md5Encription.MD5Hash("Inc-m" + agentId.ToString()), agentId);

                            agent.image  = b;
                            isImgPressed = false;
                            //if (b.Equals(""))
                            //Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trThereWasAnErrorLoadingTheImage"), animation: ToasterAnimation.FadeIn);
                        }
                    }
                }
                if (sender != null)
                {
                    SectionData.EndAwait(grid_main);
                }
            }
            catch (Exception ex)
            {
                if (sender != null)
                {
                    SectionData.EndAwait(grid_main);
                }
                SectionData.ExceptionMessage(ex, this);
            }
        }
            public void When_InvalidParameters_Then_ReturnFalse()
            {
                var result = ValidatorExtensions.IsValidDate(2021, 2, 31);

                result.Should().BeFalse();
            }
            public void When_ValidParameters_Then_ReturnTrue()
            {
                var result = ValidatorExtensions.IsValidDate(2021, 2, 1);

                result.Should().BeTrue();
            }
示例#15
0
        private async void Btn_save_Click(object sender, RoutedEventArgs e)
        {//save
            try
            {
                if (sender != null)
                {
                    SectionData.StartAwait(grid_main);
                }

                #region validate
                bool emailError = false;
                if (!isFirstTime)
                {
                    //chk empty name
                    SectionData.validateEmptyTextBox(tb_name, p_errorName, tt_errorName, "trEmptyNameToolTip");
                    //validate email
                    SectionData.validateEmail(tb_email, p_errorEmail, tt_errorEmail);
                    if (!tb_email.Text.Equals(""))
                    {
                        if (!ValidatorExtensions.IsValid(tb_email.Text))
                        {
                            emailError = true;
                        }
                    }
                    //chk empty mobile
                    SectionData.validateEmptyTextBox(tb_mobile, p_errorMobile, tt_errorMobile, "trEmptyMobileToolTip");
                }
                else
                {
                    //chk empty name
                    validateEmptyTextBox(tb_name, p_errorName, tt_errorName, "Name cann't be empty");
                    //validate email
                    validateEmail(tb_email, p_errorEmail, tt_errorEmail);
                    if (!tb_email.Text.Equals(""))
                    {
                        if (!ValidatorExtensions.IsValid(tb_email.Text))
                        {
                            emailError = true;
                        }
                    }
                    //chk empty mobile
                    validateEmptyTextBox(tb_mobile, p_errorMobile, tt_errorMobile, "Mobile number cann't be empty");
                }
                #endregion

                #region save
                if ((!tb_name.Text.Equals("")) && (!tb_mobile.Text.Equals("")) && !emailError)
                {
                    //save name
                    if (!tb_name.Text.Equals(""))
                    {
                        setVName.value     = tb_name.Text;
                        setVName.isSystem  = 1;
                        setVName.isDefault = 1;
                        setVName.settingId = nameId;
                        // string sName = await valueModel.Save(setVName);
                        int sName = await valueModel.Save(setVName);

                        if (!sName.Equals(0))
                        {
                            MainWindow.companyName = tb_name.Text;
                        }
                    }
                    //save address
                    if (!tb_address.Text.Equals(""))
                    {
                        setVAddress.value     = tb_address.Text;
                        setVAddress.isSystem  = 1;
                        setVAddress.isDefault = 1;
                        setVAddress.settingId = addressId;
                        int sAddress = await valueModel.Save(setVAddress);

                        //   string sAddress = await valueModel.Save(setVAddress);
                        if (!sAddress.Equals(0))
                        {
                            MainWindow.Address = tb_address.Text;
                        }
                    }
                    //save email
                    if ((!tb_email.Text.Equals("")) && (!emailError))
                    {
                        setVEmail.value     = tb_email.Text;
                        setVEmail.isSystem  = 1;
                        setVEmail.settingId = emailId;
                        setVEmail.isDefault = 1;
                        //  string sEmail = await valueModel.Save(setVEmail);
                        int sEmail = await valueModel.Save(setVEmail);

                        if (!sEmail.Equals(0))
                        {
                            MainWindow.Email = tb_email.Text;
                        }
                    }
                    //save mobile
                    if (!tb_mobile.Text.Equals(""))
                    {
                        setVMobile.value     = cb_areaMobile.Text + "-" + tb_mobile.Text;
                        setVMobile.isSystem  = 1;
                        setVMobile.isDefault = 1;
                        setVMobile.settingId = mobileId;
                        int sMobile = await valueModel.Save(setVMobile);

                        if (!sMobile.Equals(0))
                        {
                            MainWindow.Mobile = cb_areaMobile.Text + tb_mobile.Text;
                        }
                    }
                    //save phone
                    if (!tb_phone.Text.Equals(""))
                    {
                        setVPhone.value     = cb_areaPhone.Text + "-" + cb_areaPhoneLocal.Text + "-" + tb_phone.Text;
                        setVPhone.isSystem  = 1;
                        setVPhone.isDefault = 1;
                        setVPhone.settingId = phoneId;
                        int sPhone = await valueModel.Save(setVPhone);

                        if (!sPhone.Equals(0))
                        {
                            MainWindow.Phone = cb_areaPhone.Text + cb_areaPhoneLocal.Text + tb_phone.Text;
                        }
                    }
                    //save fax
                    if (!tb_fax.Text.Equals(""))
                    {
                        setVFax.value     = cb_areaFax.Text + "-" + cb_areaFaxLocal.Text + "-" + tb_fax.Text;
                        setVFax.isSystem  = 1;
                        setVFax.isDefault = 1;
                        setVFax.settingId = faxId;
                        int sFax = await valueModel.Save(setVFax);

                        if (!sFax.Equals(0))
                        {
                            MainWindow.Fax = cb_areaFax.Text + cb_areaFaxLocal.Text + tb_fax.Text;
                        }
                    }
                    //  save logo
                    // image
                    //  string sLogo = "";
                    int sLogo = 0;
                    if (isImgPressed)
                    {
                        isImgPressed = false;

                        setVLogo.value     = sLogo.ToString();
                        setVLogo.isSystem  = 1;
                        setVLogo.isDefault = 1;
                        setVLogo.settingId = logoId;
                        sLogo = await valueModel.Save(setVLogo);

                        if (!sLogo.Equals(0))
                        {
                            MainWindow.logoImage = setVLogo.value;
                            string b = await setVLogo.uploadImage(imgFileName, Md5Encription.MD5Hash("Inc-m" + sLogo), sLogo);

                            setVLogo.value       = b;
                            MainWindow.logoImage = b;
                            sLogo = await valueModel.Save(setVLogo);

                            await valueModel.getImg(setVLogo.value);
                        }
                    }

                    #endregion
                    if (!isFirstTime)
                    {
                        Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopSave"), animation: ToasterAnimation.FadeIn);
                        await Task.Delay(1500);
                    }
                    this.Close();
                }
                if (sender != null)
                {
                    SectionData.EndAwait(grid_main);
                }
            }
            catch (Exception ex)
            {
                if (sender != null)
                {
                    SectionData.EndAwait(grid_main);
                }
                SectionData.ExceptionMessage(ex, this);
            }
        }
            public void When_InvalidParameters_Then_ReturnNull()
            {
                var result = ValidatorExtensions.ConstructDate("31", "02", "2021");

                result.Should().BeNull();
            }
        public void ExtendabilityTest04()
        {
            int value = 1;

            ValidatorExtensions.IsGreaterOrEqual(Condition.Requires(value, "value"), 0);
        }
示例#18
0
 private bool IsFormValid()
 {
     return(!String.IsNullOrWhiteSpace(Login) && !String.IsNullOrWhiteSpace(Password) && !String.IsNullOrWhiteSpace(LastName) && !String.IsNullOrWhiteSpace(FirstName) && ValidatorExtensions.IsValidEmailAddress(Email));
 }