public bool UpdateNhomHang(NhomHangDTO dtoNhomHang)
 {
     string strQuery = "Update NHOMHANG Set ";
     strQuery += "TENNHOMHANG = N'" + dtoNhomHang.TenNhomHang + "',";
     strQuery += "GHICHU = N'" + dtoNhomHang.GhiChu + "' ";
     strQuery += "Where MANHOMHANG = N'" + dtoNhomHang.MaNH + "'";
     return dp.ExecuteNonQuery(strQuery);
 }
 public bool InsertNhomHang(NhomHangDTO dtoNhomHang)
 {
     string strQuery = "Insert Into NHOMHANG Values(";
     strQuery += "N'" + dtoNhomHang.MaNH + "',";
     strQuery += "N'" + dtoNhomHang.TenNhomHang + "',";
     strQuery += "N'" + dtoNhomHang.GhiChu + "', 1)";
     return dp.ExecuteNonQuery(strQuery);
 }
 public string UpdateNhomHang(NhomHangDTO dtoNhomHang)
 {
     string strError = "";
     if (dtoNhomHang.TenNhomHang.Trim().Equals("") == true)
     {
         strError = "Tên nhóm hàng không được rỗng.";
     }
     if (strError == "")
     {
         bool boolResult = dalNhomHang.UpdateNhomHang(dtoNhomHang);
         return "ok";
     }
     else
     {
         return strError;
     }
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                NhomHangDTO dtoNhomHang = new NhomHangDTO();
                string strAction = btnOK.Tag.ToString();
                if (strAction == "add")
                {
                    dtoNhomHang.MaNH = txtMaNhom.Text;
                    dtoNhomHang.TenNhomHang = txtTenNhom.Text;
                    dtoNhomHang.GhiChu = txtGhiChu.Text;
                    string strResult = bllNhomHang.InsertNhomHang(dtoNhomHang);
                    if (strResult == "ok")
                    {
                        MessageBox.Show("Thêm Thành Công!", "Thêm Nhóm Hàng", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(strResult, "Thêm Nhóm Hàng", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                }
                else
                {
                    dtoNhomHang.MaNH = txtMaNhom.Text;
                    dtoNhomHang.TenNhomHang = txtTenNhom.Text;
                    dtoNhomHang.GhiChu = txtGhiChu.Text;
                    string strResult = bllNhomHang.UpdateNhomHang(dtoNhomHang);
                    if (strResult == "ok")
                    {
                        MessageBox.Show("Cập Nhật Thành Công!", "Cập Nhật Nhóm Hàng", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(strResult, "Cập Nhật Nhóm Hàng", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch { }
        }