protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string idValue = Request.Params["id"]; if (idValue != null) { int id = Convert.ToInt32(idValue); LMessageSortBB messageSortBB = new LMessageSortBB(); try { LMessageSortData messageSortData = new LMessageSortData(); messageSortData = messageSortBB.GetModel(id); //����й��������˴�Ҫ��֤�Ƿ�����ɾ�� messageSortBB.DeleteRecord(id); this.ClientScript.RegisterStartupScript(this.GetType(), "CloseSubmit", "CloseSubmit()", true); } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3)", true); return; } finally { messageSortBB.Dispose(); } } } }
/// <summary> /// ���ݱ��� /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { LMessageSortData model = new LMessageSortData(); LMessageSortBB messageSortBB = new LMessageSortBB(); try { if (this.State == "1") { this.SetModel(ref model); this.IdValue = messageSortBB.AddRecord(model); } else if (this.State == "2") { model = messageSortBB.GetModel(this.IdValue); this.SetModel(ref model); messageSortBB.ModifyRecord(model); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { messageSortBB.Dispose(); } Response.Redirect("LMessageSortList.aspx?itemNo=" + this.itemNo + "&pTypeNo=main", false); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LMessageSortData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into LMessageSort("); strSql.Append(@"sortNm)"); strSql.Append(" values ("); strSql.Append(@"@sortNm)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@sortNm", SqlDbType.NVarChar,20) }; parameters[0].Value = model.sortNm; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
/// <summary> /// չʾ���� /// </summary> /// <param name="id">��¼Id</param> private void ShowInfo(int id) { LMessageSortBB messageSortBB = new LMessageSortBB(); LMessageSortData model = new LMessageSortData(); try { model = messageSortBB.GetModel(id); this.sortNm.Text = model.sortNm; } finally { messageSortBB.Dispose(); } }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LMessageSortData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update LMessageSort set "); strSql.Append("sortNm=@sortNm"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@sortNm", SqlDbType.NVarChar,20) }; parameters[0].Value = model.id; parameters[1].Value = model.sortNm; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
/// <summary> /// 得到一个model /// </summary> /// <param name="id">主键值</param> /// <returns>model</returns> public LMessageSortData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select id,sortNm from LMessageSort"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; LMessageSortData model = new LMessageSortData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["id"] != DBNull.Value) { model.id = Convert.ToInt32(row["id"]); } if (row["sortNm"] != DBNull.Value) { model.sortNm = Convert.ToString(row["sortNm"]); } return model; } else { return null; } }
/// <summary> /// ʵ���ำֵ /// </summary> /// <param name="model">ʵ����ʵ��</param> private void SetModel(ref LMessageSortData model) { model.sortNm = this.sortNm.Text; }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LMessageSortData model) { return this.messageSortDB.ModifyRecord(model); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LMessageSortData model) { return this.messageSortDB.AddRecord(model); }