コード例 #1
0
        private void Set_ObjectCountInfoLabel()
        {
            AccountsRepository accounts = new AccountsRepository();

            objectCountInfoLabel.Text = "Объектов создано: " + accounts.GetAccountsLength();
        }
コード例 #2
0
        private void CreateAccountButton_Click(object sender, EventArgs e)
        {
            // подключение репозиторию с данными
            AccountsRepository accountsRepository = new AccountsRepository();

            string   accountNumber = (accountsRepository.GetAccountsLength() + 1) + "k";
            string   accountType   = this.AccountTypeButton.Text;
            DateTime openingDate   = this.OpeningDateButton.Value;
            // Owner
            string   name         = this.userNameField.Text;
            string   lastName     = this.userLastNameField.Text;
            string   middleName   = this.userMiddleNameField.Text;
            DateTime birthday     = this.BirthdayButton.Value;
            string   passportData = this.passportDataField.Text;

            bool InternetBunking = false;

            if (this.InternetBankingButtonYes.Checked)
            {
                InternetBunking = true;
            }
            else if (this.InternetBankingButtonNo.Checked)
            {
                InternetBunking = false;
            }

            bool Alert = false;

            if (this.AlertYesButton.Checked)
            {
                Alert = true;
            }
            else if (this.AlertNoButton.Checked)
            {
                Alert = false;
            }

            Account account = new Account(
                accountNumber,
                accountType,
                0,
                openingDate,
                InternetBunking,
                Alert,
                new Owner(
                    name,
                    lastName,
                    middleName,
                    birthday,
                    passportData
                    )
                );

            var results        = new List <ValidationResult>();
            var contextAccount = new ValidationContext(account);
            var contextOwner   = new ValidationContext(account.owner);

            bool res1 = tryValidateObject(account, contextAccount, results);
            bool res2 = tryValidateObject(account.owner, contextOwner, results);

            if (res1 && res2)
            {
                accountsRepository.AddAccount(account);

                this.Hide();
                SuccessForm successForm = new SuccessForm();
                successForm.Show();
            }
        }