Exemplo n.º 1
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            //validacion: todos los campos deben estar llenos
            if (userTextbox.Text == "" || passwordTextbox.Text == "")
            {
                MessageBox.Show("Favor de llenar todos los campos");
            }
            else
            {
                //abre conexion a la db
                Connection.OpenConnection();
                //busco el nombre y la contraseña en la db
                MySqlCommand    command = new MySqlCommand(String.Format("SELECT * from Employee WHERE FirstName = '{0}' AND Password = '******' AND Active  = true", userTextbox.Text, passwordTextbox.Text), Connection.myConnection);
                MySqlDataReader reader  = command.ExecuteReader();

                if (reader.Read())
                {
                    //el reader lo ponemos de la forma de employee
                    Class.Employee myEmployee = new Class.Employee(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5), reader.GetString(6), reader.GetInt32(7), reader.GetBoolean(8));

                    //si coinciden los campos con la informacion del gerente entra aqui
                    if (myEmployee.EmployeeType == 0)
                    {
                        Connection.CloseConnection();
                        MessageBox.Show("Sesion iniciada como admin");

                        //se inicializa el menu del gerente
                        this.Hide();
                        //obtengo el id del empleado y lo mando
                        ManagerMenu ManagerWindow = new ManagerMenu(Connection, myEmployee.IdEmployee);
                        ManagerWindow.ShowDialog();
                        this.Close();
                    }
                    else if (myEmployee.EmployeeType == 1)
                    {
                        //si coinciden los datos con la informacion del cajero entra aqui
                        MessageBox.Show("Sesion iniciada como cajero");
                        Connection.CloseConnection();
                        CashierMenu CashierWIndow = new CashierMenu(Connection, myEmployee.IdEmployee);
                        this.Hide();
                        CashierWIndow.ShowDialog();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("ID o Contraseña Incorrectos", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                Connection.CloseConnection();
            }
        }
Exemplo n.º 2
0
        private void Login_btn_Click(object sender, EventArgs e)
        {
            if (LoginUser_txt.Text == "" || LoginPw_txt.Text == "")
            {
                username_wrn.Text = "*Tài khoản không được để trống";
                pass_wrn.Text     = "*Mật khẩu không được để trống";
                username_wrn.Show();
                pass_wrn.Show();
                Cafe.Close();
            }
            else
            {
                username_wrn.Visible = false;
                pass_wrn.Visible     = false;
                Cafe.Open();
                SqlDataAdapter loginAdapter = new SqlDataAdapter
                                                  ("select * from [dbo].[TAI_KHOAN_HE_THONG] where TAI_KHOAN='" + LoginUser_txt.Text + "' and MAT_KHAU='" + LoginPw_txt.Text + "' ", Cafe);
                DataTable result = new DataTable();
                loginAdapter.Fill(result);
                try
                {
                    if (result.Rows.Count == 1)
                    {
                        if (LoginUser_txt.Text == result.Rows[0]["TAI_KHOAN"].ToString() && LoginPw_txt.Text == result.Rows[0]["MAT_KHAU"].ToString())
                        {
                            login_role = result.Rows[0]["LOAI_TK"].ToString();
                            switch (login_role)
                            {
                            case "Admin":
                            {
                                AdminMenu AdminMenu = new AdminMenu();
                                MessageBox.Show("Đăng nhập thành công\n Xin chào Admin");
                                AdminMenu.Login_Main_Data(login_role);
                                this.Hide();
                                AdminMenu.Show();
                                break;
                            }

                            case "Thu ngân":
                            {
                                CashierMenu CashierMenu = new CashierMenu();
                                MessageBox.Show("Đăng nhập thành công\n Xin chào Thu ngân");
                                CashierMenu.Login_Main_Data(login_role);
                                this.Hide();
                                CashierMenu.Show();
                                break;
                            }

                            case "Khách hàng":
                            {
                                MessageBox.Show("Tính năng đang trong quá trình phát triển");
                                break;
                            }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Đăng nhập thất bại\n Vui lòng kiểm tra tài khoản và mật khẩu");
                            Cafe.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "ERROR", MessageBoxButtons.OK);
                    Cafe.Close();
                }
            }
        }