protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { List <Su_LinhVuc> lstLinhVuc = logic.getAll(); dgvApprover.DataSource = lstLinhVuc; dgvApprover.DataBind(); if (Session[LinhVucLogic.LINH_VUC_LOGIC_SEC_ID] != null) { sec = logic.findById(Int32.Parse(Session[LinhVucLogic.LINH_VUC_LOGIC_SEC_ID].ToString())); txtCode.ReadOnly = true; txtCode.Text = sec.Code; tbxName.Text = sec.Name; tbxDescription.Text = sec.Description; btAddApprover.Text = "Cập nhật"; } else { sec = new Su_LinhVuc(); txtCode.ReadOnly = false; txtCode.Text = ""; tbxName.Text = ""; tbxDescription.Text = ""; btAddApprover.Text = "Thêm mới"; } } else { if (Session[LinhVucLogic.LINH_VUC_LOGIC_SEC_ID] != null) { sec = logic.findById(Int32.Parse(Session[LinhVucLogic.LINH_VUC_LOGIC_SEC_ID].ToString())); txtCode.ReadOnly = true; sec.Name = tbxName.Text; sec.Description = tbxDescription.Text; } else { sec = new Su_LinhVuc(); sec.Code = txtCode.Text; sec.Name = tbxName.Text; sec.Description = tbxDescription.Text; sec.Active = 1; } } } catch (Exception ex) { logger.Error("editApprover_Click error: ", ex); Response.Redirect("~/ThongBaoLoi.aspx", false); } }
public int insert(Su_LinhVuc sec) { try { dataContext.Su_LinhVucs.InsertOnSubmit(sec); dataContext.SubmitChanges(); } catch (Exception ex) { logger.Error("insert error: ", ex); } return(sec.ID); }
public Su_LinhVuc findById(int id) { Su_LinhVuc rs = null; try { rs = dataContext.Su_LinhVucs.Where(p => ((p.Active > 0 || p.Active == null) && p.ID == id)).First(); } catch (Exception ex) { logger.Error("getAll error: ", ex); } return(rs); }
protected void dgvOnDataBind(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { stt++; Su_LinhVuc item = (Su_LinhVuc)e.Row.DataItem; if (item != null) { Label lblSTT = (Label)e.Row.FindControl("lblSTT"); if (lblSTT != null) { lblSTT.Text = stt.ToString(); } } } }
public bool delete(int id) { bool rs = false; try { Su_LinhVuc attachObj = dataContext.Su_LinhVucs.Where(p => p.ID == id).First(); attachObj.Active = 0; dataContext.SubmitChanges(); rs = true; } catch (Exception ex) { logger.Error("update error: ", ex); } return(rs); }
public bool update(Su_LinhVuc sec) { bool rs = false; try { Su_LinhVuc attachObj = dataContext.Su_LinhVucs.Where(p => p.ID == sec.ID).First(); attachObj.Name = sec.Name; attachObj.Description = sec.Description; dataContext.SubmitChanges(); rs = true; } catch (Exception ex) { logger.Error("update error: ", ex); } return(rs); }
public bool validateUpdate(Su_LinhVuc sec) { bool rt = true; try { List <Su_LinhVuc> rs = dataContext.Su_LinhVucs.Where(p => (p.ID != sec.ID && p.Name.ToUpper().Equals(sec.Name.ToUpper())) && p.Active > 0).ToList(); if (rs != null && rs.Count > 0) { rt = false; } } catch (Exception ex) { logger.Error("validateUpdate error: ", ex); } return(rt); }