Exemple #1
0
        /// <summary>
        /// Handles clicking the Sign Up button.
        /// </summary>
        private void SignUpButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(FullNameTextBox.Text))
            {
                MessageBox.Show(Messages.EmptyFullNameText, Messages.EmptyFullNameCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!IsPhoneCorrect(PhoneNumberTextBox.Text))
            {
                MessageBox.Show(Messages.IncorrectPhoneText, Messages.IncorrectPhoneCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrWhiteSpace(AddressTextBox.Text))
            {
                MessageBox.Show(Messages.EmptyAddressText, Messages.EmptyAddressCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrWhiteSpace(EmailTextBox.Text))
            {
                MessageBox.Show(Messages.EmptyEmailText, Messages.EmptyEmailCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!IsPasswordValid(PasswordTextBox.Text))
            {
                MessageBox.Show(Messages.InvalidPasswordText, Messages.InvalidPasswordCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                ClientDatabase.Register(new Customer(FullNameTextBox.Text,
                                                     PhoneNumberTextBox.Text, AddressTextBox.Text, EmailTextBox.Text,
                                                     PasswordTextBox.Text));
                AuthorisationForm.SerializeCustomers();
                Close();
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, Messages.SignUpFailedCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        /// <summary>
        /// Handles clicking the Log In button: checks the validity of the user's e-mail and
        /// password, and opens a WarehouseViewer form.
        /// </summary>
        private void LogInButton_Click(object sender, EventArgs e)
        {
            if (ClientDatabase.Authorize(EmailTextBox.Text, PasswordTextBox.Text))
            {
                Client client = ClientDatabase.GetClient(EmailTextBox.Text);

                this.Hide();
                WarehouseViewer form = new WarehouseViewer(client);
                form.Closed += (s, args) => this.Close();
                form.ShowDialog();
            }
            else
            {
                MessageBox.Show(Messages.LoginFailedText, Messages.LoginFailedCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }