protected void btnSave_Click(object sender, EventArgs e) { foreach (GridViewRow row in myManageGridView.Rows) { string strId = ((Label)row.FindControl(STR_LABEL_ID)).Text; TextBox updRoleName = (TextBox)row.FindControl("txtUptRoleName"); TextBox uptDescription = (TextBox)row.FindControl("txtUptDescription"); //check title if (!CheckInputEmptyAndLength(updRoleName, "E01501", "E01502", false)) return; if (!CheckInputLength(uptDescription, "E01502", false)) return; //update Johnny.CMS.OM.Access.Role model = new Johnny.CMS.OM.Access.Role(); model.RoleId = DataConvert.GetInt32(strId); model.RoleName = updRoleName.Text; model.Description = uptDescription.Text; Johnny.CMS.BLL.Access.Role bll = new Johnny.CMS.BLL.Access.Role(); bll.Update(model); } SetMessage(GetMessage("C00003")); //update grid getData(); }
protected override void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e); if (!this.IsPostBack) { litPageTitle.Text = GetLabelText("Role_Title"); litRoleName.Text = GetLabelText("Role_RoleName"); txtRoleName.ToolTip = GetLabelText("Role_RoleName"); litDescription.Text = GetLabelText("Role_Description"); txtDescription.ToolTip = GetLabelText("Role_Description"); if (Request.QueryString["action"] == "modify") { //get RoleId int RoleId = Convert.ToInt32(Request.QueryString["id"]); //Role entity Johnny.CMS.BLL.Access.Role bll = new Johnny.CMS.BLL.Access.Role(); //bind data Johnny.CMS.OM.Access.Role model = new Johnny.CMS.OM.Access.Role(); model = bll.GetModel(RoleId); txtRoleName.Text = model.RoleName; txtDescription.Text = model.Description; btnAdd.ButtonType = Johnny.Controls.Web.Button.Button.EnumButtonType.Save; // btnAdd.Text = CONST_BUTTONTEXT_SAVE; } //RFVldtRoleName.ErrorMessage = GetMessage("E01501", txtRoleName.MaxLength.ToString()); } }
/// <summary> /// Add one record /// </summary> public int Add(Johnny.CMS.OM.Access.Role model) { StringBuilder strSql = new StringBuilder(); strSql.Append("DECLARE @Sequence int"); strSql.Append(" SELECT @Sequence=(max(Sequence)+1) FROM [cms_role]"); strSql.Append(" if @Sequence is NULL"); strSql.Append(" Set @Sequence=1"); strSql.Append("INSERT INTO [cms_role]("); strSql.Append("[RoleName],[Description],[Sequence]"); strSql.Append(")"); strSql.Append(" VALUES ("); strSql.Append("@rolename,@description,@Sequence"); strSql.Append(")"); strSql.Append(";SELECT @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@rolename", SqlDbType.NVarChar, 50), new SqlParameter("@description", SqlDbType.NVarChar, 200) }; parameters[0].Value = model.RoleName; parameters[1].Value = model.Description; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
protected void btnSave_Click(object sender, EventArgs e) { foreach (GridViewRow row in myManageGridView.Rows) { string strId = ((Label)row.FindControl(STR_LABEL_ID)).Text; TextBox updRoleName = (TextBox)row.FindControl("txtUptRoleName"); TextBox uptDescription = (TextBox)row.FindControl("txtUptDescription"); //check title if (!CheckInputEmptyAndLength(updRoleName, "E01501", "E01502", false)) { return; } if (!CheckInputLength(uptDescription, "E01502", false)) { return; } //update Johnny.CMS.OM.Access.Role model = new Johnny.CMS.OM.Access.Role(); model.RoleId = DataConvert.GetInt32(strId); model.RoleName = updRoleName.Text; model.Description = uptDescription.Text; Johnny.CMS.BLL.Access.Role bll = new Johnny.CMS.BLL.Access.Role(); bll.Update(model); } SetMessage(GetMessage("C00003")); //update grid getData(); }
/// <summary> /// Method to get one record by primary key /// </summary> public Johnny.CMS.OM.Access.Role GetModel(int roleid) { //Set up a return value Johnny.CMS.OM.Access.Role model = null; StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT [RoleId], [RoleName], [Description], [Sequence] "); strSql.Append(" FROM [cms_role] "); strSql.Append(" WHERE [RoleId]=@roleid"); SqlParameter[] parameters = { new SqlParameter("@roleid", SqlDbType.Int, 4) }; parameters[0].Value = roleid; using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters)) { if (sdr.Read()) { model = new Johnny.CMS.OM.Access.Role(sdr.GetInt32(0), sdr.GetString(1), sdr.GetString(2), sdr.GetInt32(3)); } else { model = new Johnny.CMS.OM.Access.Role(); } } return(model); }
protected override void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e); Johnny.CMS.OM.Access.Role model = new Johnny.CMS.OM.Access.Role(); base.ManageTable = model.TableName; base.ManageKey = model.PrimaryKey; base.IsDesc = model.IsDesc; if (!IsPostBack) { myManageGridView.Columns[2].HeaderText = GetLabelText("Role_RoleName"); myManageGridView.Columns[3].HeaderText = GetLabelText("Role_Description"); getData(); } }
/// <summary> /// Method to get records with condition /// </summary> public IList<Johnny.CMS.OM.Access.Role> GetList() { IList<Johnny.CMS.OM.Access.Role> list = new List<Johnny.CMS.OM.Access.Role>(); StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT [RoleId], [RoleName], [Description], [Sequence] "); strSql.Append(" FROM [cms_role] "); strSql.Append(" ORDER BY [Sequence]"); using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString())) { while (sdr.Read()) { Johnny.CMS.OM.Access.Role item = new Johnny.CMS.OM.Access.Role(sdr.GetInt32(0), sdr.GetString(1), sdr.GetString(2), sdr.GetInt32(3)); list.Add(item); } } return list; }
protected void btnAdd_Click(object sender, System.EventArgs e) { //validation if (!CheckInputEmptyAndLength(txtRoleName, "E01501", "E01502", false)) { return; } if (!CheckInputLength(txtDescription, "E01502", false)) { return; } Johnny.CMS.BLL.Access.Role bll = new Johnny.CMS.BLL.Access.Role(); Johnny.CMS.OM.Access.Role model = new Johnny.CMS.OM.Access.Role(); if (Request.QueryString["action"] == "modify") { //update model.RoleId = Convert.ToInt32(Request.QueryString["id"]); model.RoleName = txtRoleName.Text; model.Description = txtDescription.Text; bll.Update(model); SetMessage(GetMessage("C00003")); } else { //insert model.RoleName = txtRoleName.Text; model.Description = txtDescription.Text; if (bll.Add(model) > 0) { SetMessage(GetMessage("C00001")); txtRoleName.Text = ""; txtDescription.Text = ""; } else { SetMessage(GetMessage("C00002")); } } }
/// <summary> /// Method to get records with condition /// </summary> public IList <Johnny.CMS.OM.Access.Role> GetList() { IList <Johnny.CMS.OM.Access.Role> list = new List <Johnny.CMS.OM.Access.Role>(); StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT [RoleId], [RoleName], [Description], [Sequence] "); strSql.Append(" FROM [cms_role] "); strSql.Append(" ORDER BY [Sequence]"); using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString())) { while (sdr.Read()) { Johnny.CMS.OM.Access.Role item = new Johnny.CMS.OM.Access.Role(sdr.GetInt32(0), sdr.GetString(1), sdr.GetString(2), sdr.GetInt32(3)); list.Add(item); } } return(list); }
/// <summary> /// Update one record /// </summary> public void Update(Johnny.CMS.OM.Access.Role model) { StringBuilder strSql = new StringBuilder(); strSql.Append("UPDATE [cms_role] SET "); strSql.Append("[RoleName]=@rolename,"); strSql.Append("[Description]=@description"); strSql.Append(" WHERE [RoleId]=@roleid "); SqlParameter[] parameters = { new SqlParameter("@roleid", SqlDbType.Int, 4), new SqlParameter("@rolename", SqlDbType.NVarChar, 50), new SqlParameter("@description", SqlDbType.NVarChar, 200) }; parameters[0].Value = model.RoleId; parameters[1].Value = model.RoleName; parameters[2].Value = model.Description; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// Method to get one record by primary key /// </summary> public Johnny.CMS.OM.Access.Role GetModel(int roleid) { //Set up a return value Johnny.CMS.OM.Access.Role model = null; StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT [RoleId], [RoleName], [Description], [Sequence] "); strSql.Append(" FROM [cms_role] "); strSql.Append(" WHERE [RoleId]=@roleid"); SqlParameter[] parameters = { new SqlParameter("@roleid", SqlDbType.Int,4)}; parameters[0].Value = roleid; using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters)) { if (sdr.Read()) model = new Johnny.CMS.OM.Access.Role(sdr.GetInt32(0), sdr.GetString(1), sdr.GetString(2), sdr.GetInt32(3)); else model = new Johnny.CMS.OM.Access.Role(); } return model; }
protected void btnAdd_Click(object sender, System.EventArgs e) { //validation if (!CheckInputEmptyAndLength(txtRoleName, "E01501", "E01502", false)) return; if (!CheckInputLength(txtDescription, "E01502", false)) return; Johnny.CMS.BLL.Access.Role bll = new Johnny.CMS.BLL.Access.Role(); Johnny.CMS.OM.Access.Role model = new Johnny.CMS.OM.Access.Role(); if (Request.QueryString["action"] == "modify") { //update model.RoleId = Convert.ToInt32(Request.QueryString["id"]); model.RoleName = txtRoleName.Text; model.Description = txtDescription.Text; bll.Update(model); SetMessage(GetMessage("C00003")); } else { //insert model.RoleName = txtRoleName.Text; model.Description = txtDescription.Text; if (bll.Add(model) > 0) { SetMessage(GetMessage("C00001")); txtRoleName.Text = ""; txtDescription.Text = ""; } else SetMessage(GetMessage("C00002")); } }
/// <summary> /// Update one record /// </summary> public void Update(Johnny.CMS.OM.Access.Role model) { dal.Update(model); }
/// <summary> /// Add one record /// </summary> public int Add(Johnny.CMS.OM.Access.Role model) { return(dal.Add(model)); }