Beispiel #1
0
        //Session session = new Session();
        private void btnDoiMK_Click(object sender, EventArgs e)
        {
            Debug.WriteLine("constructor firedsss " + Session.SessionMaNV);
            if (String.Compare(txtNhapLai.Text, txtMKmoi.Text) == 0)
            {
                using (SqlConnection cnn = new SqlConnection(constr))
                {
                    using (SqlCommand cmd = cnn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "sp_kiemTraMK";
                        cmd.Parameters.AddWithValue("@id", Session.SessionMaNV);
                        cmd.Parameters.AddWithValue("@mk", maHoa.GetMD5(txtMKcu.Text));
                        cnn.Open();
                        SqlDataAdapter dap  = new SqlDataAdapter(cmd);
                        DataTable      data = new DataTable();
                        dap.Fill(data);

                        if (data.Rows.Count > 0)
                        {
                            using (SqlCommand cmd1 = cnn.CreateCommand())
                            {
                                cmd1.CommandType = CommandType.StoredProcedure;
                                cmd1.CommandText = "sp_DoiMatKhau";
                                cmd1.Parameters.AddWithValue("@id", Session.SessionMaNV);
                                cmd1.Parameters.AddWithValue("@mk", maHoa.GetMD5(txtMKmoi.Text));
                                int i = cmd1.ExecuteNonQuery();
                                if (i > 0)
                                {
                                    MessageBox.Show("Đổi Thành Công.", "Thông Báo");
                                    this.Hide();
                                }
                                else
                                {
                                    MessageBox.Show("Đổi không Thành Công.", "Thông Báo");
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Mật Khẩu Cũ Không Đúng.", "Thông Báo");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Mật Khẩu Mới Không Giống Nhau.", "Thông Báo");
            }
        }
 private void btnThem_Click(object sender, EventArgs e)
 {
     if (txtDiaChi.Text.Length != 0 && txtMK.Text.Length != 0 && txtUserNam.Text.Length != 0 && txtTenNV.Text.Length != 0 && txtSDT.Text.Length != 0)
     {
         using (SqlConnection cnn = new SqlConnection(constr))
         {
             using (SqlCommand cmd1 = cnn.CreateCommand())
             {
                 cmd1.CommandType = CommandType.StoredProcedure;
                 cmd1.CommandText = "sp_ktraTen";
                 cmd1.Parameters.AddWithValue("@userName", txtUserNam.Text);
                 cnn.Open();
                 int i = (int)cmd1.ExecuteScalar();
                 Debug.WriteLine("constructor fired " + i);
                 if (i == 0)
                 {
                     using (SqlCommand cmd = cnn.CreateCommand())
                     {
                         cmd.CommandType = CommandType.StoredProcedure;
                         cmd.CommandText = "sp_themNhanVien";
                         cmd.Parameters.AddWithValue("@tenTK", txtUserNam.Text);
                         cmd.Parameters.AddWithValue("@mk", maHoa.GetMD5(txtMK.Text));
                         cmd.Parameters.AddWithValue("@tenNV", txtTenNV.Text);
                         cmd.Parameters.AddWithValue("@sdt", txtSDT.Text);
                         cmd.Parameters.AddWithValue("@diachi", txtDiaChi.Text);
                         if (rdNhanVien.Checked == true)
                         {
                             cmd.Parameters.AddWithValue("@quyen", 1);
                         }
                         else
                         {
                             cmd.Parameters.AddWithValue("@quyen", 2);
                         }
                         // cnn.Open();
                         int i_ = cmd.ExecuteNonQuery();
                         if (i_ > 0)
                         {
                             load_grid();
                             xoaTrang();
                             MessageBox.Show("Thêm Nhân Viên Thành Công", "Thông Báo");
                         }
                     }
                 }
                 else
                 {
                     MessageBox.Show("Tên Đăng Nhập Đã Trùng", "Thông Báo");
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("Phải Điền Đủ Dữ Liệu", "Thông Báo");
     }
 }
Beispiel #3
0
        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            String constr = ConfigurationManager.ConnectionStrings["db_qltbnb"].ConnectionString;

            using (SqlConnection cnn = new SqlConnection(constr))
            {
                using (SqlCommand cmd = cnn.CreateCommand())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "sp_kiemTraDangNhap";
                    cmd.Parameters.AddWithValue("@tenTK", txtTenDN.Text);
                    cmd.Parameters.AddWithValue("@mk", maHoa.GetMD5(txtMK.Text));
                    cnn.Open();
                    SqlDataAdapter dap  = new SqlDataAdapter(cmd);
                    DataTable      data = new DataTable();
                    dap.Fill(data);
                    //Debug.WriteLine("constructor fired " + i);
                    if (data.Rows.Count > 0)
                    {
                        cnn.Close();

                        Session.SessionMaNV  = data.Rows[0]["iMaNhanVien"].ToString();
                        Session.SessionQuyen = Convert.ToInt32(data.Rows[0]["iQuyen"].ToString());
                        this.Hide();
                        mainQuanLy main = new mainQuanLy();

                        main.ShowDialog();
                        this.Show();
                        Debug.WriteLine("constructor fired sesion " + Session.SessionMaNV);
                    }
                    else
                    {
                        MessageBox.Show("TK Hoặc MK Không Chính Xác", "Thông Báo");
                    }
                }
            }
        }