/// <summary> /// 增加一条数据 /// </summary> public int Add(zs.Model.Tbl_Guide model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Tbl_Guide("); strSql.Append("pid,name,url,sortid,type)"); strSql.Append(" values ("); strSql.Append("@pid,@name,@url,@sortid,@type)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@pid", SqlDbType.Int, 4), new SqlParameter("@name", SqlDbType.VarChar, 50), new SqlParameter("@url", SqlDbType.VarChar, 150), new SqlParameter("@sortid", SqlDbType.Int, 4), new SqlParameter("@type", SqlDbType.VarChar, 50) }; parameters[0].Value = model.pid; parameters[1].Value = model.name; parameters[2].Value = model.url; parameters[3].Value = model.sortid; parameters[4].Value = model.type; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void ShowInfo(int id) { zs.BLL.Tbl_Guide bll = new zs.BLL.Tbl_Guide(); zs.Model.Tbl_Guide model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.lblpid.Text = model.pid.ToString(); this.lblname.Text = model.name; this.lblurl.Text = model.url; this.lblsortid.Text = model.sortid.ToString(); this.lbltype.Text = model.type; }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtpid.Text)) { strErr += "pid格式错误!\\n"; } if (this.txtname.Text.Trim().Length == 0) { strErr += "name不能为空!\\n"; } if (this.txturl.Text.Trim().Length == 0) { strErr += "url不能为空!\\n"; } if (!PageValidate.IsNumber(txtsortid.Text)) { strErr += "sortid格式错误!\\n"; } if (this.txttype.Text.Trim().Length == 0) { strErr += "type不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); int pid = int.Parse(this.txtpid.Text); string name = this.txtname.Text; string url = this.txturl.Text; int sortid = int.Parse(this.txtsortid.Text); string type = this.txttype.Text; zs.Model.Tbl_Guide model = new zs.Model.Tbl_Guide(); model.id = id; model.pid = pid; model.name = name; model.url = url; model.sortid = sortid; model.type = type; zs.BLL.Tbl_Guide bll = new zs.BLL.Tbl_Guide(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public zs.Model.Tbl_Guide GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,pid,name,url,sortid,type from Tbl_Guide "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; zs.Model.Tbl_Guide model = new zs.Model.Tbl_Guide(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["pid"] != null && ds.Tables[0].Rows[0]["pid"].ToString() != "") { model.pid = int.Parse(ds.Tables[0].Rows[0]["pid"].ToString()); } if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "") { model.name = ds.Tables[0].Rows[0]["name"].ToString(); } if (ds.Tables[0].Rows[0]["url"] != null && ds.Tables[0].Rows[0]["url"].ToString() != "") { model.url = ds.Tables[0].Rows[0]["url"].ToString(); } if (ds.Tables[0].Rows[0]["sortid"] != null && ds.Tables[0].Rows[0]["sortid"].ToString() != "") { model.sortid = int.Parse(ds.Tables[0].Rows[0]["sortid"].ToString()); } if (ds.Tables[0].Rows[0]["type"] != null && ds.Tables[0].Rows[0]["type"].ToString() != "") { model.type = ds.Tables[0].Rows[0]["type"].ToString(); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(zs.Model.Tbl_Guide model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Tbl_Guide set "); strSql.Append("pid=@pid,"); strSql.Append("name=@name,"); strSql.Append("url=@url,"); strSql.Append("sortid=@sortid,"); strSql.Append("type=@type"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@pid", SqlDbType.Int, 4), new SqlParameter("@name", SqlDbType.VarChar, 50), new SqlParameter("@url", SqlDbType.VarChar, 150), new SqlParameter("@sortid", SqlDbType.Int, 4), new SqlParameter("@type", SqlDbType.VarChar, 50), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.pid; parameters[1].Value = model.name; parameters[2].Value = model.url; parameters[3].Value = model.sortid; parameters[4].Value = model.type; parameters[5].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }