Ejemplo n.º 1
0
 /// <summary>
 /// Kiểm tra và thêm mới PollAnswer
 /// </summary>
 /// <param name="entity">Entity</param>
 /// <returns>Int32: ID của PollAnswer Mới Thêm Vào</returns>
 public static Int32 Add(PollAnswerEntity entity)
 {
     checkLogic(entity);
     checkDuplicate(entity, true);
     checkFK(entity);
     return PollAnswerDAL.Add(entity);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Kiểm tra và chỉnh sửa PollAnswer
 /// </summary>
 /// <param name="entity">PollAnswerEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Edit(PollAnswerEntity entity)
 {
     checkExist(entity);
     checkLogic(entity);
     checkDuplicate(entity, false);
     checkFK(entity);
     return PollAnswerDAL.Edit(entity);
 }
 protected void lbtnRemove_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < lstbAnswer.Items.Count; i++)
     {
         if (lstbAnswer.Items[i].Selected)
         {
             PollAnswerEntity entity = new PollAnswerEntity();
             entity.iAnswerID = Convert.ToInt32(lstbAnswer.Items[i].Value);
             PollAnswerBRL.Remove(entity);
         }
     }
     NapListbox();
 }
 protected void lbtnAdd_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         try
         {
             if (Session["PollID"] != null)
             {
                 PollAnswerEntity entity = new PollAnswerEntity();
                 entity.iCount = 0;
                 entity.iPollID = Convert.ToInt32(Session["PollID"]);
                 entity.sAnswer = txtAdd.Text;
                 PollAnswerBRL.Add(entity);
                 NapListbox();
             }
         }
         catch (Exception ex)
         {
             Response.Write("<script language=\"javascript\">alert('" + ex.Message + "');location='Default.aspx?page=AnswerManager';</script>");
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Kiểm tra logic Entity
 /// </summary>
 /// <param name="entity">PollAnswerEntity: entity</param>
 private static void checkLogic(PollAnswerEntity entity)
 {
     if (String.IsNullOrEmpty(entity.sAnswer))
         throw new Exception(EX_SANSWER_EMPTY);
     if (entity.iCount < 0)
         throw new Exception(EX_ICOUNT_INVALID);
     if (entity.iPollID < 0)
         throw new Exception(EX_IPOLLID_INVALID);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Kiểm tra tồn tại khóa ngoại
 /// </summary>
 /// <param name="entity">PollAnswerEntity:entity</param>
 private static void checkFK(PollAnswerEntity entity)
 {
     PollEntity oPoll = PollDAL.GetOne(entity.iPollID);
     if (oPoll==null)
     {
         throw new Exception("Không tìm thấy bình chọn này");
     }
 }
Ejemplo n.º 7
0
 private static void checkExist(PollAnswerEntity entity)
 {
     PollAnswerEntity oPollAnswer=PollAnswerDAL.GetOne(entity.iAnswerID);
     if(oPollAnswer==null)
         throw new Exception(EX_NOT_EXIST);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Kiểm tra trùng lặp bản ghi
 /// </summary>
 /// <param name="entity">PollAnswerEntity: PollAnswerEntity</param>
 private static void checkDuplicate(PollAnswerEntity entity,bool CheckInsert)
 {
     List<PollAnswerEntity> list = PollAnswerDAL.GetAll();
     if (list.Exists(
         delegate(PollAnswerEntity oldEntity)
         {
             bool result= oldEntity.sAnswer.Equals(entity.sAnswer, StringComparison.OrdinalIgnoreCase) && oldEntity.iPollID==entity.iPollID;
             if (!CheckInsert)
                 result=result && oldEntity.iAnswerID != entity.iAnswerID;
             return result;
         }
     ))
     {
         list.Clear();
         throw new Exception(EX_ANSWER_EXISTED);
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Kiểm tra và xoá PollAnswer
 /// </summary>
 /// <param name="entity">PollAnswerEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Remove(PollAnswerEntity entity)
 {
     checkExist(entity);
     return PollAnswerDAL.Remove(entity.iAnswerID);
 }