Example #1
0
        public AddHostPage(IBusiness business, Frame frame, HostSignInPage host_sign_in_page)
        {
            InitializeComponent();
            Business       = business;
            Frame          = frame;
            HostSignInPage = host_sign_in_page;

            EmailValidator = new EmailValidator(email, email_error);

            Validators = new List <IValidator>()
            {
                new RequiredTextValidator(first_name, first_name_error,
                                          control => Regex.Match(control.Text, @"^[a-z ,.'-]+$", RegexOptions.IgnoreCase).Success ? "" : "Error: Cannot have these symbols in your name."
                                          ),

                new RequiredTextValidator(last_name, last_name_error,
                                          control => Regex.Match(control.Text, @"^[a-z ,.'-]+$", RegexOptions.IgnoreCase).Success ? "" : "Error: Cannot have these symbols in your name."
                                          ),

                EmailValidator,

                new PhoneValidator(phone, phone_error),

                new PasswordValidator(password, password_error),

                new PasswordValidator(repeat_password, repeat_password_error,
                                      control => control.Password != password.Password ? "Error: Passwords do not match." : ""
                                      ),

                new IntValidator(bank_number, bank_number_error, true, 0, null,
                                 control => {
                    try {
                        control.Text = new ID(control.Text, 2);
                        Business.BankBranches().First(branch => branch.BankID == bank_number.Text);
                        return("");
                    } catch (IncorrectDigitsException) {
                        return("Error: Bank number must be at most two digits.");
                    } catch (FormatException) {
                        return("Error: Could not parse the input as a bank number.");
                    } catch (OverflowException) {
                        return("Error: Number is too large to be a bank number.");
                    } catch (InvalidOperationException) {
                        return("Error: No bank with this number was found.");
                    }
                }
                                 ),

                new IntValidator(branch_number, branch_number_error, true, 0, null,
                                 control => {
                    try {
                        control.Text = new ID(control.Text, 3);
                        BankBranch   = Business.BankBranches().First(branch => branch.BankID == bank_number.Text && branch.BranchID == control.Text);
                        return("");
                    } catch (IncorrectDigitsException) {
                        return("Error: Branch number must be at most three digits.");
                    } catch (FormatException) {
                        return("Error: Could not parse the input as a branch number.");
                    } catch (OverflowException) {
                        return("Error: Number is too large to be a branch number.");
                    } catch (InvalidOperationException) {
                        return("Error: No branch with this number was found for bank " + bank_number.Text + '.');
                    }
                }
                                 ),

                new IntValidator(account_number, account_number_error, true, 0, null,
                                 control => {
                    try {
                        control.Text = new ID(control.Text, 6);
                        return("");
                    } catch (IncorrectDigitsException) {
                        return("Error: Account number must be six digits.");
                    } catch (FormatException) {
                        return("Error: Could not parse the input as an account number.");
                    } catch (OverflowException) {
                        return("Error: Number is too large to be an account number.");
                    }
                }
                                 )
            };
        }