Example #1
0
        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));
            }
        }