protected void btnOK_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            try
            {
                LoaivanbanEntity entity = new LoaivanbanEntity();
                entity.sTenloai = txtTenLoai.Text;

                if (btnOK.CommandName == "Edit")
                {
                    entity.PK_iLoaivanbanID = Convert.ToInt32(btnOK.CommandArgument);
                    LoaivanbanBRL.Edit(entity);
                }
                else
                    LoaivanbanBRL.Add(entity);
                lblThongbao.Text = "Cập nhật thành công";
                //Nạp lại dữ liệu
                Response.Redirect(Request.Url.ToString());
            }
            catch (Exception ex)
            {
                Response.Write("<script language=\"javascript\">alert('" + ex.Message + "');location='Default.aspx?page=DocumentCategoryUpdate';</script>");
            }
        }
    }
 /// <summary>
 /// Kiểm tra và thêm mới Loaivanban
 /// </summary>
 /// <param name="entity">Entity</param>
 /// <returns>Int32: ID của Loaivanban Mới Thêm Vào</returns>
 public static Int32 Add(LoaivanbanEntity entity)
 {
     checkLogic(entity);
     checkDuplicate(entity, false);
     checkFK(entity);
     return LoaivanbanDAL.Add(entity);
 }
 /// <summary>
 /// Kiểm tra và chỉnh sửa Loaivanban
 /// </summary>
 /// <param name="entity">LoaivanbanEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Edit(LoaivanbanEntity entity)
 {
     checkExist(entity.PK_iLoaivanbanID);
     checkLogic(entity);
     checkDuplicate(entity, true);
     checkFK(entity);
     return LoaivanbanDAL.Edit(entity);
 }
 /// <summary>
 /// Kiểm tra trùng lặp bản ghi
 /// </summary>
 /// <param name="entity">LoaivanbanEntity: LoaivanbanEntity</param>
 private static void checkDuplicate(LoaivanbanEntity entity,bool checkPK)
 {
     /*
     Example
     List<LoaivanbanEntity> list = LoaivanbanDAL.GetAll();
     if (list.Exists(
         delegate(LoaivanbanEntity oldEntity)
         {
             bool result =oldEntity.FIELD.Equals(entity.FIELD, StringComparison.OrdinalIgnoreCase);
             if(checkPK)
                 result=result && oldEntity.PK_iLoaivanbanID != entity.PK_iLoaivanbanID;
             return result;
         }
     ))
     {
         list.Clear();
         throw new Exception(EX_FIELD_EXISTED);
     }
     */
 }
 /// <summary>
 /// Kiểm tra logic Entity
 /// </summary>
 /// <param name="entity">LoaivanbanEntity: entity</param>
 private static void checkLogic(LoaivanbanEntity entity)
 {
     if (String.IsNullOrEmpty(entity.sTenloai))
         throw new Exception(EX_STENLOAI_EMPTY);
 }
 /// <summary>
 /// Kiểm tra tồn tại khóa ngoại
 /// </summary>
 /// <param name="entity">LoaivanbanEntity:entity</param>
 private static void checkFK(LoaivanbanEntity entity)
 {
 }