/// <summary> /// 更新一条数据 /// </summary> public bool Update(CHSS.Model.CCommunityAgency model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CCommunityAgency set "); strSql.Append("CommDescription=@CommDescription,"); strSql.Append("CommAddDate=@CommAddDate,"); strSql.Append("CommName=@CommName,"); strSql.Append("UID=@UID"); strSql.Append(" where CID=@CID"); SqlParameter[] parameters = { new SqlParameter("@CommDescription", SqlDbType.NVarChar, 200), new SqlParameter("@CommAddDate", SqlDbType.NVarChar, 20), new SqlParameter("@CommName", SqlDbType.NVarChar, 20), new SqlParameter("@UID", SqlDbType.Int, 4), new SqlParameter("@CID", SqlDbType.Int, 4) }; parameters[0].Value = model.CommDescription; parameters[1].Value = model.CommAddDate; parameters[2].Value = model.CommName; parameters[3].Value = model.UID; parameters[4].Value = model.CID; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(CHSS.Model.CCommunityAgency model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CCommunityAgency("); strSql.Append("CommDescription,CommAddDate,CommName,UID)"); strSql.Append(" values ("); strSql.Append("@CommDescription,@CommAddDate,@CommName,@UID)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CommDescription", SqlDbType.NVarChar, 200), new SqlParameter("@CommAddDate", SqlDbType.NVarChar, 20), new SqlParameter("@CommName", SqlDbType.NVarChar, 20), new SqlParameter("@UID", SqlDbType.Int, 4) }; parameters[0].Value = model.CommDescription; parameters[1].Value = model.CommAddDate; parameters[2].Value = model.CommName; parameters[3].Value = model.UID; object obj = DBHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CHSS.Model.CCommunityAgency DataRowToModel(DataRow row) { CHSS.Model.CCommunityAgency model = new CHSS.Model.CCommunityAgency(); if (row != null) { if (row["CID"] != null && row["CID"].ToString() != "") { model.CID = int.Parse(row["CID"].ToString()); } if (row["CommDescription"] != null) { model.CommDescription = row["CommDescription"].ToString(); } if (row["CommAddDate"] != null) { model.CommAddDate = row["CommAddDate"].ToString(); } if (row["CommName"] != null) { model.CommName = row["CommName"].ToString(); } if (row["UID"] != null && row["UID"].ToString() != "") { model.UID = int.Parse(row["UID"].ToString()); } } return(model); }
private void ShowInfo(int CID) { CHSS.BLL.CCommunityAgency bll = new CHSS.BLL.CCommunityAgency(); CHSS.Model.CCommunityAgency model = bll.GetModel(CID); this.txtCID.Text = model.CID.ToString(); this.txtCommDescription.Text = model.CommDescription; this.txtCommAddDate.Text = model.CommAddDate; this.txtCommName.Text = model.CommName; }
protected void btnSave_Click(object sender, EventArgs e) { string CommDescription = this.txtCommDescription.Text; string CommAddDate = this.txtCommAddDate.Text; string CommName = this.txtCommName.Text; int UID = int.Parse(Session["UID"].ToString()); CHSS.Model.CCommunityAgency model = new CHSS.Model.CCommunityAgency(); model.CommDescription = CommDescription; model.CommAddDate = CommAddDate; model.CommName = CommName; model.UID = UID; CHSS.BLL.CCommunityAgency bll = new CHSS.BLL.CCommunityAgency(); bll.Add(model); Response.Redirect("Show.aspx?id=" + (bll.GetMaxId() - 1)); }
public void btnSave_Click(object sender, EventArgs e) { int CID = int.Parse(this.txtCID.Text); string CommDescription = this.txtCommDescription.Text; string CommAddDate = this.txtCommAddDate.Text; string CommName = this.txtCommName.Text; int UID = int.Parse(Session["UID"].ToString()); CHSS.Model.CCommunityAgency model = new CHSS.Model.CCommunityAgency(); model.CID = CID; model.CommDescription = CommDescription; model.CommAddDate = CommAddDate; model.CommName = CommName; model.UID = UID; CHSS.BLL.CCommunityAgency bll = new CHSS.BLL.CCommunityAgency(); bll.Update(model); Response.Redirect("Show.aspx?id=" + CID); }
/// <summary> /// 得到一个对象实体 /// </summary> public CHSS.Model.CCommunityAgency GetModel(int CID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CID,CommDescription,CommAddDate,CommName,UID from CCommunityAgency "); strSql.Append(" where CID=@CID"); SqlParameter[] parameters = { new SqlParameter("@CID", SqlDbType.Int, 4) }; parameters[0].Value = CID; CHSS.Model.CCommunityAgency model = new CHSS.Model.CCommunityAgency(); DataSet ds = DBHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }