protected void btnAdd_Click(object sender, EventArgs e) { try { var dao = DaoFactory.GetAmphoeDao(); var dt = dao.GetAll(); // Here we'll add a blank row to the returned DataTable dt.Insert(0, EntityFactory.CreateAmphoe()); //Creating the first row of GridView to be Editable GridView1.EditIndex = 0; GridView1.DataSource = dt; GridView1.DataBind(); //Delete string text id for row insert GridView1.Rows[0].Cells[1].Text = ""; //Changing the Text for Inserting a New Record ((LinkButton)GridView1.Rows[0].Cells[0].Controls[0]).Text = "Insert"; } catch (Exception ex) { JavaScriptBuilder.Build(new AlertBuilder(ex.Message)); } }
protected override void Page_Load(object sender, EventArgs e) { try { if (IsPostBack) { return; } Load_Init(); if (Mode.New == Mode) { InitNewMode(); } else if (Mode.Edit == Mode) { InitEditMode(); } } catch (Exception ex) { var message = ex.InnerException == null ? ex.Message : ex.InnerException.Message; JavaScriptBuilder.Build(new AlertBuilder(message)); } }
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { try { GridView1.EditIndex = -1; Search(); } catch (Exception ex) { JavaScriptBuilder.Build(new AlertBuilder(ex.Message)); } }
protected virtual void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { Load_Init(); } } catch (Exception ex) { var message = ex.InnerException == null ? ex.Message : ex.InnerException.Message; JavaScriptBuilder.Build(new AlertBuilder(message)); } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { var dao = DaoFactory.GetAmphoeDao(); var id = GridView1.DataKeys[e.RowIndex].Value; var entity = dao.GetById(id, false); if (entity != null) { dao.Delete(entity); } Search(); } catch (Exception ex) { JavaScriptBuilder.Build(new AlertBuilder(ex.Message)); } }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { var dao = DaoFactory.GetUaeProjectManageDao(); if (((LinkButton)GridView1.Rows[0].Cells[0].Controls[0]).Text == "Insert") { var entity = EntityFactory.CreateUaeProjectManage(); entity.ProjCode = ((TextBox)GridView1.Rows[0].Cells[3].Controls[0]).Text; entity.ProjEname = ((TextBox)GridView1.Rows[0].Cells[4].Controls[0]).Text; entity.ProjTname = ((TextBox)GridView1.Rows[0].Cells[5].Controls[0]).Text; dao.Save(entity); } else { var id = GridView1.DataKeys[e.RowIndex].Value; var entity = dao.GetById(id, false); if (entity != null) { entity.ProjCode = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text; entity.ProjEname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text; entity.ProjTname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text; dao.Update(entity); } } GridView1.EditIndex = -1; Search(); } catch (Exception ex) { JavaScriptBuilder.Build(new AlertBuilder(ex.Message)); } }
protected virtual void OnDeleteSucceed() { JavaScriptBuilder.Build(new AlertBuilder(Globals.Delete_succeed)); Search(); }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { var dao = DaoFactory.GetAmphoeDao(); if (((LinkButton)GridView1.Rows[0].Cells[0].Controls[0]).Text == "Insert") { var entity = EntityFactory.CreateAmphoe(); //entity.Id = GridView1.Rows.Count; entity.ThaiName = ((TextBox)GridView1.Rows[0].Cells[3].Controls[0]).Text; entity.EnglishName = ((TextBox)GridView1.Rows[0].Cells[4].Controls[0]).Text; var user = ComponentFactory.CreateUserAccount(); user.UserId = "0402"; SessionAdapter.User = user; #region Create by entity.CreateBy = SessionAdapter.User; var createDatetime = ComponentFactory.CreateDateTime(); createDatetime.Value = DateTime.Now; entity.CreateDate = createDatetime; #endregion dao.Save(entity); } else { var id = GridView1.DataKeys[e.RowIndex].Value; var entity = dao.GetById(id, false); if (entity != null) { entity.ThaiName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text; entity.EnglishName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text; var user = ComponentFactory.CreateUserAccount(); user.UserId = "0402"; SessionAdapter.User = user; #region Update by entity.UpdateBy = SessionAdapter.User; var updateDatetime = ComponentFactory.CreateDateTime(); updateDatetime.Value = DateTime.Now; entity.UpdateDate = updateDatetime; #endregion dao.Update(entity); } } GridView1.EditIndex = -1; Search(); } catch (Exception ex) { JavaScriptBuilder.Build(new AlertBuilder(ex.Message)); } }
protected virtual void OnSaveSucceed() { JavaScriptBuilder.Build(new AlertBuilder(Globals.Save_succeed)); //ClearState(); }
protected virtual void OnUpdateSucceed() { JavaScriptBuilder.Build(new AlertBuilder(Globals.Update_succeed)); }