예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            button1.ForeColor = Color.White;
            button2.ForeColor = Color.FromArgb(89, 121, 254);
            MoveIndicator((Control)sender);
            frmmau frm = new frmmau();

            frm.ShowDialog();
        }
예제 #2
0
        private void btn_login_Click_1(object sender, EventArgs e)
        {
            MY_DB db = new MY_DB();

            try
            {
                if (txt_user.Text == "" || txt_pass.Text == "")
                {
                    MessageBox.Show("không được để trống");
                }
                else
                {
                    SqlCommand command = new SqlCommand("SELECT MaNV,Role from NhanVien WHERE NhanVien.UserName=@user AND Password=@pass", db.GetConnection);
                    command.Parameters.Add("@user", SqlDbType.NVarChar).Value = txt_user.Text;
                    command.Parameters.Add("@pass", SqlDbType.NVarChar).Value = txt_pass.Text;
                    //MessageBox.Show(HashPasswordUsingMD5(txt_pass.Text));
                    SqlDataAdapter adapter = new SqlDataAdapter(command);
                    DataTable      table   = new DataTable();
                    adapter.Fill(table);

                    // MessageBox.Show(table.Rows.Count.ToString());
                    int count = table.Rows.Count;
                    if (count == 0)
                    {
                        MessageBox.Show("ban da nhap sai ten tai khoan hoac mat khau");
                    }
                    for (int i = 0; i < count; i++)
                    {
                        if (table.Rows[i].ItemArray[0] != null)
                        {
                            string a = table.Rows[i].ItemArray[1].ToString();
                            Globals.Setusername(txt_user.Text);
                            Globals.Setpass(txt_pass.Text);
                            if (a == "employee")
                            {
                                Globals.SetNV(Convert.ToInt32(table.Rows[i].ItemArray[0]));
                                Globals.SetRole("employee");
                                //MessageBox.Show(Globals.role);
                                frmmaunhanvien frm = new frmmaunhanvien();
                                frm.ShowDialog();
                            }
                            else
                            {
                                Globals.SetNV(Convert.ToInt32(table.Rows[i].ItemArray[0]));
                                Globals.SetRole("manager");
                                frmmau frm = new frmmau();
                                frm.ShowDialog();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }