protected void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         ChungchiEntity oChungchi = new ChungchiEntity();
         oChungchi.sTenChungchi = txtChungchi.Text;
         oChungchi.sMota = txtMota.Text;
         if (bAddnew == false && btnOK.CommandName.ToUpper() == "EDIT")
         {
             oChungchi.PK_iChungchiID = Convert.ToInt16(btnOK.CommandArgument);
             ChungchiBRL.Edit(oChungchi);
             lblThongbao.Text = "Cập nhật thành công";
         }
         else if (btnOK.CommandName.ToUpper() == "ADDNEW")
         {
             ChungchiBRL.Add(oChungchi);
             lblThongbao.Text = "Thêm nhóm thành công";
             napGridView();
             pnlEdit.Visible = false;
         }
     }
     catch (Exception ex)
     {
         //lblThongbao.Text = ex.Message;
         Response.Write("<script language=\"javascript\">alert('" + ex.Message + "');location='Default.aspx?page=ChungchiManager';</script>");
     }
 }
 /// <summary>
 /// Kiểm tra và thêm mới Chungchi
 /// </summary>
 /// <param name="entity">Entity</param>
 /// <returns>Int32: ID của Chungchi Mới Thêm Vào</returns>
 public static Int32 Add(ChungchiEntity entity)
 {
     checkLogic(entity);
     checkDuplicate(entity, false);
     checkFK(entity);
     return ChungchiDAL.Add(entity);
 }
 /// <summary>
 /// Kiểm tra và chỉnh sửa Chungchi
 /// </summary>
 /// <param name="entity">ChungchiEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Edit(ChungchiEntity entity)
 {
     checkExist(entity.PK_iChungchiID);
     checkLogic(entity);
     checkDuplicate(entity, true);
     checkFK(entity);
     return ChungchiDAL.Edit(entity);
 }
 /// <summary>
 /// Kiểm tra logic Entity
 /// </summary>
 /// <param name="entity">ChungchiEntity: entity</param>
 private static void checkLogic(ChungchiEntity entity)
 {
     if (String.IsNullOrEmpty(entity.sTenChungchi))
         throw new Exception(EX_STENCHUNGCHI_EMPTY);
     if (String.IsNullOrEmpty(entity.sMota))
         throw new Exception(EX_SMOTA_EMPTY);
 }
 /// <summary>
 /// Kiểm tra tồn tại khóa ngoại
 /// </summary>
 /// <param name="entity">ChungchiEntity:entity</param>
 private static void checkFK(ChungchiEntity entity)
 {
 }
 /// <summary>
 /// Kiểm tra trùng lặp bản ghi
 /// </summary>
 /// <param name="entity">ChungchiEntity: ChungchiEntity</param>
 private static void checkDuplicate(ChungchiEntity entity,bool checkPK)
 {
     /*
     Example
     List<ChungchiEntity> list = ChungchiDAL.GetAll();
     if (list.Exists(
         delegate(ChungchiEntity oldEntity)
         {
             bool result =oldEntity.FIELD.Equals(entity.FIELD, StringComparison.OrdinalIgnoreCase);
             if(checkPK)
                 result=result && oldEntity.PK_iChungchiID != entity.PK_iChungchiID;
             return result;
         }
     ))
     {
         list.Clear();
         throw new Exception(EX_FIELD_EXISTED);
     }
     */
 }