Beispiel #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("Нужно ввести логин и пароль! ");
                return;
            }
            Логин usr = db.Users.Find(textBox1.Text);

            if ((usr != null) && (usr.psw == textBox2.Text))
            {
                USER = usr;

                FORMA = this;

                if (usr.role == "Директор")
                {
                    Form2 frm = new Form2();
                    frm.Show();
                    this.Hide();
                }
                else if (usr.role == "Менеджер")
                {
                    Form3 frm = new Form3();
                    frm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show($"Роли {usr.role} в системе нет!");
                    return;
                }
            }
            else
            {
                MessageBox.Show($"Пользователь с таким логином и паролем нет!");
                return;
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
            {
                MessageBox.Show("Нужно задать все данные!");
                return;
            }
            if (textBox2.Text != textBox3.Text)
            {
                MessageBox.Show("Пароль не совподают!");
                return;
            }
            Логин usr = db.Users.Find();

            if (usr != null)
            {
                MessageBox.Show("Пользователь с таким логином уже есть!");
                return;
            }
            usr       = new Логин();
            usr.Login = textBox1.Text;
            usr.psw   = textBox2.Text;
            usr.role  = textBox3.Text;
            usr.name  = textBox5.Text;
            db.Users.Add(usr);
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            MessageBox.Show("Пользователь " + usr.Login + " Зарегистрирован!");
            Form1.FORMA.Show();
            this.Close();
            return;
        }