Esempio n. 1
0
        private void ButtonLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBoxLogin.Text) || string.IsNullOrWhiteSpace(textBoxPass.Text))
            {
                if (string.IsNullOrWhiteSpace(textBoxLogin.Text))
                {
                    textBoxLogin.BackColor = Color.Red;
                }
                if (string.IsNullOrWhiteSpace(textBoxPass.Text))
                {
                    textBoxPass.BackColor = Color.Red;
                }

                MessageBox.Show("Fill in the blank space, please");
                textBoxLogin.BackColor = Color.White;
                textBoxPass.BackColor  = Color.White;
            }
            else if (textBoxLogin.Text.Length <= 2 || textBoxLogin.Text.Length >= 10)
            {
                textBoxLogin.BackColor = Color.Red;
                MessageBox.Show("Name has inappropriate length, try again");
                textBoxLogin.BackColor = Color.White;
                textBoxLogin.Text      = string.Empty;
            }
            else if (textBoxPass.Text.Length <= 4 || textBoxPass.Text.Length >= 10)
            {
                textBoxPass.BackColor = Color.Red;
                MessageBox.Show("Password has inappropriate length, try again");
                textBoxPass.BackColor = Color.White;
                textBoxPass.Text      = string.Empty;
            }
            //filled and long enough
            else
            {
                string login    = textBoxLogin.Text;
                string password = (textBoxPass.Text);
                // uniwue users
                if (lombard.Clients.FirstOrDefault(u => u.Name.ToLower() == login.ToLower() && u.Password == password) != null)
                {
                    Form main = new ClientMain(ref lombard, lombard.Clients.FirstOrDefault(u => u.Name == login && u.Password == password));
                    main.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Sorry, such Client doesn`t exist...Try again or Register");
                    textBoxLogin.Text = string.Empty;
                    textBoxPass.Text  = string.Empty;
                }
            }
        }
Esempio n. 2
0
        private void ButtonRegister_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(RegName.Text) || string.IsNullOrWhiteSpace(RegPassword.Text) || string.IsNullOrWhiteSpace(IDbox.Text))
            {
                if (string.IsNullOrWhiteSpace(RegName.Text))
                {
                    RegName.BackColor = Color.Red;
                }
                if (string.IsNullOrWhiteSpace(RegPassword.Text))
                {
                    RegPassword.BackColor = Color.Red;
                }
                if (string.IsNullOrWhiteSpace(IDbox.Text))
                {
                    RegPassword.BackColor = Color.Red;
                }
                MessageBox.Show("Fill in the blank space, please");
                RegName.BackColor     = Color.White;
                RegPassword.BackColor = Color.White;
                IDbox.BackColor       = Color.White;
            }
            else if (RegName.Text.Length <= 2 || RegName.Text.Length >= 10)
            {
                RegName.BackColor = Color.Red;
                MessageBox.Show("Name has inappropriate length, try again");
                RegName.BackColor = Color.White;
                RegName.Text      = string.Empty;
            }
            else if (RegPassword.Text.Length <= 4 || RegPassword.Text.Length >= 10)
            {
                RegPassword.BackColor    = Color.Red;
                RegPassReenter.BackColor = Color.Red;
                MessageBox.Show("Password has inappropriate length, try again");
                RegPassword.BackColor    = Color.White;
                RegPassword.Text         = string.Empty;
                RegPassReenter.BackColor = Color.White;
                RegPassReenter.Text      = string.Empty;
            }
            else if (RegPassReenter.Text != RegPassword.Text)
            {
                RegPassword.BackColor    = Color.Red;
                RegPassReenter.BackColor = Color.Red;
                MessageBox.Show("Passwords don't match, try again");
                RegPassword.BackColor    = Color.White;
                RegPassword.Text         = string.Empty;
                RegPassReenter.BackColor = Color.White;
                RegPassReenter.Text      = string.Empty;
            }
            else if (IDbox.Text.Length != 9)
            {
                IDbox.BackColor = Color.Red;
                MessageBox.Show("id has inappropriate length, try again");
                IDbox.BackColor = Color.White;
                IDbox.Text      = string.Empty;
            }
            //filled and long enough
            else
            {
                string login    = RegName.Text;
                string password = (RegPassword.Text);
                int    iD       = Convert.ToInt32(IDbox.Text);
                // unique users
                if (lombard.Clients.FirstOrDefault(u => u.Name.ToLower() == login.ToLower() && u.ID == iD) != null)
                {
                    MessageBox.Show("Sorry, such Client already exist...Change your login");
                    RegName.Text     = string.Empty;
                    RegPassword.Text = string.Empty;
                }
                else
                {
                    Client user = new Client(iD, login, password);
                    lombard.Clients.Add(user);
                    MessageBox.Show("We are glad to hear you joined us!");
                    lombard.Save();
                    Form main = new ClientMain(ref lombard, user);
                    main.Show();

                    this.Close();
                }
            }
        }