private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txttenkh.Text.Trim().Length == 0)
            {
                MessageBox.Show("Vui lòng nhập thông tin đầy đủ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            KhachHangobj khObj = new KhachHangobj();

            addData(khObj);
            if (flagLuu == 0)
            {
                if (khCtr.AddData(khObj))
                {
                    MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Thêm không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (khCtr.UpdData(khObj))
                {
                    MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Sửa không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            KhachHang_Load(sender, e);
        }
 private void addData(KhachHangobj kh)
 {
     kh.Ma = txtMaKH.Text.Trim();
     if (cbbGioiTinh.SelectedIndex == 0)
     {
         kh.Gioitinh = "Nam";
     }
     else
     {
         kh.Gioitinh = "Nữ";
     }
     kh.Diachi = txtdiachi.Text.Trim();
     kh.Tenkh  = txttenkh.Text.Trim();
     kh.Sdt    = txtsdt.Text.Trim();
 }
 public bool UpdData(KhachHangobj khObj)
 {
     cmd.CommandText = "Update KhachHang set TenKH =  N'" + khObj.Tenkh + "', GioiTinh = N'" + khObj.Gioitinh + "', DiaChi= N'" + khObj.Diachi + "', SoDT = '" + khObj.Sdt + "' Where MaKH = '" + khObj.Ma + "'";
     cmd.CommandType = CommandType.Text;
     cmd.Connection  = con.Connection;
     try
     {
         con.OpenConn();
         cmd.ExecuteNonQuery();
         con.CloseConn();
         return(true);
     }
     catch (Exception ex)
     {
         string mex = ex.Message;
         cmd.Dispose();
         con.CloseConn();
     }
     return(false);
 }
 public bool AddData(KhachHangobj khObj)
 {
     cmd.CommandText = "Insert into KhachHang values ('" + khObj.Ma + "',N'" + khObj.Tenkh + "',N'" + khObj.Gioitinh + "',N'" + khObj.Diachi + "','" + khObj.Sdt + "')";
     cmd.CommandType = CommandType.Text;
     cmd.Connection  = con.Connection;
     try
     {
         con.OpenConn();
         cmd.ExecuteNonQuery();
         con.CloseConn();
         return(true);
     }
     catch (Exception ex)
     {
         string mex = ex.Message;
         cmd.Dispose();
         con.CloseConn();
     }
     return(false);
 }
 public bool UpdData(KhachHangobj khObj)
 {
     return(khMod.UpdData(khObj));
 }