Esempio n. 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Controls.Add(menu        = new Menu());
            adminPanel               = new AdminPanel();
            adminPanel.OnBackToMenu += OnBackToMenu;

            adminPanel.OnTopicClick += (topic, words) =>
            {
                Controls.Clear();
                Controls.Add(new Edit(topic, words));
            };

            menu.OnEnterAction += (login, password) =>
            {
                if (login == "admin" && password == "111")
                {
                    Controls.Clear();
                    Controls.Add(adminPanel);
                }
                else
                {
                    MessageBox.Show("Неверный логин или пароль.");
                }
            };

            menu.OnStartGameAction += () =>
            {
                Controls.Clear();
                Controls.Add(new UserControls.GameMode());
            };
        }
Esempio n. 2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string email      = txtLoginEmail.Text.Trim();
            string password   = txtLoginPassword.Text.Trim();
            User   ExistEmail = _db.Users.FirstOrDefault(u => u.Email == email);

            if (email == "" || password == "")
            {
                MessageBox.Show("All fields must be filled", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (!IsValid(ExistEmail, password))
            {
                return;
            }

            if (ExistEmail.IsAdmin)
            {
                AdminPanel admin = new AdminPanel(this);
                admin.Show();
                return;
            }
            UsersPage userPage = new UsersPage();

            userPage.Show();
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;
            bool   asAdmin  = chkAdmin.Checked;

            if (asAdmin)
            {
                Admin adm = db.Admins.FirstOrDefault(a => a.Username == username);

                if (adm != null)
                {
                    if (Extension.CheckPassword(password, adm.Password))
                    {
                        AdminPanel admForm = new AdminPanel();
                        admForm.Show();
                        this.Hide();

                        admForm.FormClosed += (sender2, e2) => this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Username or password is wrong");
                    }
                }
                else
                {
                    MessageBox.Show("Username or password is wrong");
                }
            }
            else
            {
                Waiter waiter = db.Waiters.FirstOrDefault(s => s.Username == username);

                if (waiter != null && Extension.CheckPassword(password, waiter.Password))
                {
                    WaiterPanel WaiterForm = new WaiterPanel();
                    WaiterForm.Show();
                    this.Hide();

                    WaiterForm.FormClosed += (sender2, e2) => this.Close();
                }
                else
                {
                    MessageBox.Show("Username or password is wrong");
                }
            }
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //Добавим подключение к БД
                using (SqlConnection connect = new SqlConnection(Program.conString))
                {
                    connect.Open();

                    if (textBoxLogin.Text == "" && textBoxPsw.Text == "")
                    {
                        MessageBox.Show("Вы не заполнили поле!");
                    }
                    login = textBoxLogin.Text;

                    string        sqlExp = string.Format("SELECT*FROM USERS WHERE login='******' ", login);
                    SqlCommand    cmd    = new SqlCommand(sqlExp, connect);
                    SqlDataReader reader = cmd.ExecuteReader();

                    //

                    if (reader.HasRows) // проверка есть ли данные
                    {
                        reader.Read();  // читаем строку
                        if ((string)reader["password"] == textBoxPsw.Text)
                        {
                            role = (string)reader["role"];
                            // сравниваем введенный пароль с паролем в бд и если он совпадает, то смотрим на значение
                            //поля роль и в зависимости от него открываем нужную форму
                            switch ((string)reader["role"])
                            {
                            case "Customer":
                                UserPanel usrP = new UserPanel(Login, Role);
                                usrP.Show(); break;

                            case "Manager":
                                ManagerPanel mngP = new ManagerPanel(Login, Role);
                                mngP.Show(); break;

                            case "Admin":
                                AdminPanel admP = new AdminPanel(Login, Role);
                                admP.Show(); break;

                            default: MessageBox.Show("Ошибка роли"); break;
                            }
                        }

                        else
                        {
                            MessageBox.Show("Неверный пароль");
                            textBoxLogin.Text = "";
                            textBoxPsw.Text   = "";
                        }
                    }
                    else
                    {
                        MessageBox.Show("Нет такого пользователя");
                        textBoxLogin.Text = "";
                        textBoxPsw.Text   = "";
                    }
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); return; }
        }
Esempio n. 5
0
        private void adminToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminPanel a = new AdminPanel();

            a.Show();
        }