コード例 #1
0
 /// <summary>
 /// Kiểm tra và thêm mới Poll
 /// </summary>
 /// <param name="entity">Entity</param>
 /// <returns>Int32: ID của Poll Mới Thêm Vào</returns>
 public static Int32 Add(PollEntity entity)
 {
     checkLogic(entity);
     checkDuplicate(entity, true);
     //checkFK(entity);
     return PollDAL.Add(entity);
 }
コード例 #2
0
 /// <summary>
 /// Kiểm tra và chỉnh sửa Poll
 /// </summary>
 /// <param name="entity">PollEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Edit(PollEntity entity)
 {
     checkExist(entity);
     checkLogic(entity);
     checkDuplicate(entity, false);
     //checkFK(entity);
     return PollDAL.Edit(entity);
 }
コード例 #3
0
 protected void lbtnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         foreach (GridViewRow row in grvPoll.Rows)
         {
             CheckBox chkDelete = row.FindControl("chkDelete") as CheckBox;
             int pollID = Convert.ToInt32(grvPoll.DataKeys[row.RowIndex].Values["iPollID"]);
             if (chkDelete != null && chkDelete.Checked)
             {
                 //Remove Answer
                 PollAnswerBRL.RemoveByPollID(pollID);
                 //Remove Poll
                 PollEntity oPoll = new PollEntity();
                 oPoll.iPollID = pollID;
                 PollBRL.Remove(oPoll);
             }
         }
         //Nap lai du lieu
         Response.Redirect(Request.Url.ToString());
     }
     catch (Exception ex)
     {
         lblThongbao.Text = ex.Message;
     }
 }
コード例 #4
0
 protected void btnOK_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         try
         {
             PollEntity oPoll = new PollEntity();
             oPoll.sQuestion = txtQuestion.Text;
             oPoll.tDate = DateTime.ParseExact(txtDate.Text, "dd/MM/yyyy", null);
             oPoll.iOrder = Convert.ToByte(txtOrder.Text);
             oPoll.bHomepage = chkHomepage.Checked;
             if (Session["NewsID"] != null)
             {
                 int newsID;
                 bool result = Int32.TryParse(Session["NewsID"].ToString(), out newsID);
                 if (result) oPoll.iNewsID = newsID;
             }
             if (btnOK.CommandName == "Edit")
             {
                 oPoll.iPollID = Convert.ToInt32(btnOK.CommandArgument);
                 PollBRL.Edit(oPoll);
                 //Cập nhật trong PollCategory
                 foreach (ListItem item in lstbNhomtin.Items)
                 {
                     try
                     {
                         int categoryID = Convert.ToInt32(item.Value);
                         if (!item.Selected)
                         {
                             PollCategoryBRL.RemoveByiCategoryID(categoryID);
                         }
                         else
                         {
                             PollCategoryEntity oPollCat = new PollCategoryEntity();
                             oPollCat.iPollID = oPoll.iPollID;
                             oPollCat.iCategoryID = categoryID;
                             PollCategoryBRL.Add(oPollCat);
                         }
                     }
                     catch { }
                 }
             }
             else
             {
                 int pollID = PollBRL.Add(oPoll);
                 //Thêm bản ghi vào tblAdvCategory
                 if (pollID > 0)
                 {
                     foreach (ListItem item in lstbNhomtin.Items)
                     {
                         if (item.Selected)
                         {
                             PollCategoryEntity oPollCat = new PollCategoryEntity();
                             oPollCat.iPollID = pollID;
                             oPollCat.iCategoryID = Convert.ToInt32(item.Value);
                             PollCategoryBRL.Add(oPollCat);
                         }
                     }
                 }
             }
             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=PollManager';</script>");
         }
     }
 }
コード例 #5
0
 /// <summary>
 /// Kiểm tra logic Entity
 /// </summary>
 /// <param name="entity">PollEntity: entity</param>
 private static void checkLogic(PollEntity entity)
 {
     if (String.IsNullOrEmpty(entity.sQuestion))
         throw new Exception(EX_SQUESTION_EMPTY);
     if (entity.iNewsID < 0)
         throw new Exception(EX_INEWSID_INVALID);
 }
コード例 #6
0
 /// <summary>
 /// Kiểm tra tồn tại khóa ngoại
 /// </summary>
 /// <param name="entity">PollEntity:entity</param>
 private static void checkFK(PollEntity entity)
 {
     NewsEntity oNews = NewsDAL.GetOne(entity.iNewsID);
     if (oNews==null)
     {
         throw new Exception("Không tìm thấy tin tức này");
     }
 }
コード例 #7
0
 private static void checkExist(PollEntity entity)
 {
     PollEntity oPoll=PollDAL.GetOne(entity.iPollID);
     if(oPoll==null)
         throw new Exception(EX_NOT_EXIST);
 }
コード例 #8
0
 /// <summary>
 /// Kiểm tra trùng lặp bản ghi
 /// </summary>
 /// <param name="entity">PollEntity: PollEntity</param>
 private static void checkDuplicate(PollEntity entity,bool CheckInsert)
 {
     List<PollEntity> list = PollDAL.GetAll();
     if (list.Exists(
         delegate(PollEntity oldEntity)
         {
             bool result= oldEntity.sQuestion.Equals(entity.sQuestion, StringComparison.OrdinalIgnoreCase);
             if (!CheckInsert)
                 result = result && oldEntity.iPollID != entity.iPollID;
             return result;
         }
     ))
     {
         list.Clear();
         throw new Exception(EX_POLL_EXISTED);
     }
 }
コード例 #9
0
 /// <summary>
 /// Kiểm tra và xoá Poll
 /// </summary>
 /// <param name="entity">PollEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Remove(PollEntity entity)
 {
     checkExist(entity);
     //checkFK(entity);
     return PollDAL.Remove(entity.iPollID);
 }