예제 #1
0
        private void submitBtn_Click(object sender, EventArgs e)
        {
            currentCustomer = null;
            try
            {
                customers = SqliteDataAccess.LoadCustomers();
            }catch (Exception ex)
            {
                MessageBox.Show("Немає зареєстрованих користувачів");
            }

            if (mode) // registration
            {
                bool flag = false;

                foreach (CustomerModel customer in customers)
                {
                    if (customer.Login.Equals(login2TextBox.Text))
                    {
                        flag = true;
                        break;
                    }
                }

                if (!flag)
                {
                    SqliteDataAccess.SaveCustomer(new CustomerModel(nameTextBox.Text, login2TextBox.Text, emailTextBox.Text, pass2TextBox.Text));
                    MessageBox.Show("Новий користувач зареєстрований");

                    nameTextBox.Text   = "";
                    login2TextBox.Text = "";
                    emailTextBox.Text  = "";
                    pass2TextBox.Text  = "";
                }
                else
                {
                    login2TextBox.Text     = "";
                    attentionLabel.Visible = true;
                    attentionLabel.Text    = "Користувач з таким логіном уже присутній";
                }
            }
            else
            {
                foreach (CustomerModel c in customers)
                {
                    if (c.Login.Equals(loginTextBox.Text) && c.Password.Equals(passTextBox.Text))
                    {
                        currentCustomer = c;
                        break;
                    }
                }
                if (currentCustomer == null)
                {
                    MessageBox.Show("Невірно введений логін або пароль");
                }
                else
                {
                    loginTextBox.Text  = "";
                    passTextBox.Text   = "";
                    form1.currCustomer = currentCustomer;
                    form1.ReloadData();
                    this.Hide();
                }
            }
        }