/// <summary> /// Kiểm tra và thêm mới Adv /// </summary> /// <param name="entity">Entity</param> /// <returns>Int32: ID của Adv Mới Thêm Vào</returns> public static Int32 Add(AdvEntity entity) { checkLogic(entity); //checkDuplicate(entity, true); checkFK(entity); return AdvDAL.Add(entity); }
protected void lbtnDelete_Click(object sender, EventArgs e) { if (Page.IsValid) { try { foreach (GridViewRow row in grvAdv.Rows) { CheckBox chkDelete = row.FindControl("chkDelete") as CheckBox; if (chkDelete != null && chkDelete.Checked) { int advID = Convert.ToInt32(grvAdv.DataKeys[row.RowIndex].Values["iAdvID"]); AdvEntity oAdv = new AdvEntity(); oAdv.iAdvID = advID; AdvBRL.Remove(oAdv); } } //Nap lai du lieu Response.Redirect(Request.Url.ToString()); } catch (Exception ex) { Response.Write("<script language=\"javascript\">alert('" + ex.Message + "');location='Default.aspx?page=Adv';</script>"); } } }
/// <summary> /// Kiểm tra và chỉnh sửa Adv /// </summary> /// <param name="entity">AdvEntity</param> /// <returns>bool:kết quả thực hiện</returns> public static bool Edit(AdvEntity entity) { checkExist(entity); checkLogic(entity); //checkDuplicate(entity, false); checkFK(entity); return AdvDAL.Edit(entity); }
/// <summary> /// Kiểm tra logic Entity /// </summary> /// <param name="entity">AdvEntity: entity</param> private static void checkLogic(AdvEntity entity) { if (String.IsNullOrEmpty(entity.sTitle)) throw new Exception(EX_STITLE_EMPTY); if (String.IsNullOrEmpty(entity.sLink)) throw new Exception(EX_SLINK_EMPTY); if (String.IsNullOrEmpty(entity.sMedia)) throw new Exception(EX_SMEDIA_EMPTY); if (entity.iType < 0) throw new Exception(EX_ITYPE_INVALID); if (entity.iOrder < 0) throw new Exception(EX_IORDER_INVALID); if (entity.iPositionID < 0) throw new Exception(EX_IPOSITIONID_INVALID); if (entity.iWidth < 0) throw new Exception(EX_IWIDTH_INVALID); if (entity.iHeight < 0) throw new Exception(EX_IHEIGHT_INVALID); }
/// <summary> /// Kiểm tra tồn tại khóa ngoại /// </summary> /// <param name="entity">AdvEntity:entity</param> private static void checkFK(AdvEntity entity) { PositionEntity oPosition = PositionDAL.GetOne(entity.iPositionID); if (oPosition==null) { throw new Exception("Không tìm thấy vị trí này"); } }
private static void checkExist(AdvEntity entity) { AdvEntity oAdv=AdvDAL.GetOne(entity.iAdvID); if(oAdv==null) throw new Exception(EX_NOT_EXIST); }
/// <summary> /// Kiểm tra trùng lặp bản ghi /// </summary> /// <param name="entity">AdvEntity: AdvEntity</param> private static void checkDuplicate(AdvEntity entity,bool CheckInsert) { List<AdvEntity> list = AdvDAL.GetAll(); if (list.Exists( delegate(AdvEntity oldEntity) { bool result =oldEntity.sTitle.Equals(entity.sTitle, StringComparison.OrdinalIgnoreCase); if(!CheckInsert) result=result && oldEntity.iAdvID != entity.iAdvID; return result; } )) { list.Clear(); throw new Exception(EX_ADV_EXISTED); } }
/// <summary> /// Kiểm tra và xoá Adv /// </summary> /// <param name="entity">AdvEntity</param> /// <returns>bool:kết quả thực hiện</returns> public static bool Remove(AdvEntity entity) { checkExist(entity); //checkFK(entity); return AdvDAL.Remove(entity.iAdvID); }
protected void btnOK_Click(object sender, EventArgs e) { Page.Validate("vgQuangcao"); if (Page.IsValid) { int Result = 0; try { AdvEntity oAdv = new AdvEntity(); oAdv.sTitle = txtTitle.Text; oAdv.sMedia = txtMedia.Text; oAdv.sLink = txtLink.Text; oAdv.sDesc = txtAdvDesc.Text; oAdv.iOrder = Byte.Parse(txtOrder.Text); oAdv.iType = Byte.Parse(cboType.SelectedValue); oAdv.iWidth = Convert.ToInt16(txtWidth.Text); oAdv.iHeight = Convert.ToInt16(txtHeight.Text); oAdv.iPositionID = Convert.ToInt32(ddlPosition.SelectedValue); if (btnOK.CommandName == "Edit") { oAdv.iAdvID = Convert.ToInt32(btnOK.CommandArgument); bool resultEdit = AdvBRL.Edit(oAdv); //Cập nhật trong AdvCategory foreach (ListItem item in lstbNhomtin.Items) { try { int categoryID = Convert.ToInt32(item.Value); if (!item.Selected) { AdvCategoryBRL.RemoveByiCategoryID(categoryID); } else { AdvCategoryEntity oAdvCat = new AdvCategoryEntity(); oAdvCat.iAdvID = oAdv.iAdvID; oAdvCat.iCategoryID = categoryID; AdvCategoryBRL.Add(oAdvCat); } } catch { } } if (resultEdit) lblThongbao.Text = Resources.language.capnhapthanhcong; } else { Result = AdvBRL.Add(oAdv); //Thêm bản ghi vào tblAdvCategory if (Result > 0) { foreach (ListItem item in lstbNhomtin.Items) { if (item.Selected) { AdvCategoryEntity oAdvCat = new AdvCategoryEntity(); oAdvCat.iAdvID = Result; oAdvCat.iCategoryID = Convert.ToInt32(item.Value); AdvCategoryBRL.Add(oAdvCat); } } } } if (Result > 0) lblThongbao.Text = Resources.language.quangcaodaduocthietlap; Response.Redirect(Request.Url.ToString()); } catch (Exception ex) { lblThongbao.Text = ex.Message; } } }