private void ShowInfo(int id) { Maticsoft.BLL.dafen_jieguo bll = new Maticsoft.BLL.dafen_jieguo(); Maticsoft.Model.dafen_jieguo model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.txtshangke_id.Text = model.shangke_id.ToString(); this.txtfenzu_id.Text = model.fenzu_id.ToString(); this.txtfenshu.Text = model.fenshu.ToString(); this.txtneirong.Text = model.neirong; this.txtdafen_xuhao.Text = model.dafen_xuhao.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.dafen_jieguo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dafen_jieguo set "); strSql.Append("shangke_id=@shangke_id,"); strSql.Append("fenzu_id=@fenzu_id,"); strSql.Append("fenshu=@fenshu,"); strSql.Append("neirong=@neirong,"); strSql.Append("dafen_xuhao=@dafen_xuhao,"); strSql.Append("time=@time,"); strSql.Append("open_id=@open_id,"); strSql.Append("name=@name,"); strSql.Append("beizhu=@beizhu,"); strSql.Append("style=@style"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@shangke_id", SqlDbType.Int, 4), new SqlParameter("@fenzu_id", SqlDbType.Int, 4), new SqlParameter("@fenshu", SqlDbType.Float, 8), new SqlParameter("@neirong", SqlDbType.Text), new SqlParameter("@dafen_xuhao", SqlDbType.Int, 4), new SqlParameter("@time", SqlDbType.DateTime), new SqlParameter("@open_id", SqlDbType.NChar, 50), new SqlParameter("@name", SqlDbType.NChar, 50), new SqlParameter("@beizhu", SqlDbType.NChar, 10), new SqlParameter("@style", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.shangke_id; parameters[1].Value = model.fenzu_id; parameters[2].Value = model.fenshu; parameters[3].Value = model.neirong; parameters[4].Value = model.dafen_xuhao; parameters[5].Value = model.time; parameters[6].Value = model.open_id; parameters[7].Value = model.name; parameters[8].Value = model.beizhu; parameters[9].Value = model.style; parameters[10].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.dafen_jieguo DataRowToModel(DataRow row) { Maticsoft.Model.dafen_jieguo model = new Maticsoft.Model.dafen_jieguo(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["shangke_id"] != null && row["shangke_id"].ToString() != "") { model.shangke_id = int.Parse(row["shangke_id"].ToString()); } if (row["fenzu_id"] != null && row["fenzu_id"].ToString() != "") { model.fenzu_id = int.Parse(row["fenzu_id"].ToString()); } if (row["fenshu"] != null && row["fenshu"].ToString() != "") { model.fenshu = decimal.Parse(row["fenshu"].ToString()); } if (row["neirong"] != null) { model.neirong = row["neirong"].ToString(); } if (row["dafen_xuhao"] != null && row["dafen_xuhao"].ToString() != "") { model.dafen_xuhao = int.Parse(row["dafen_xuhao"].ToString()); } if (row["time"] != null && row["time"].ToString() != "") { model.time = DateTime.Parse(row["time"].ToString()); } if (row["open_id"] != null) { model.open_id = row["open_id"].ToString(); } if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["beizhu"] != null) { model.beizhu = row["beizhu"].ToString(); } if (row["style"] != null && row["style"].ToString() != "") { model.style = int.Parse(row["style"].ToString()); } } return(model); }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtshangke_id.Text)) { strErr += "shangke_id格式错误!\\n"; } if (!PageValidate.IsNumber(txtfenzu_id.Text)) { strErr += "fenzu_id格式错误!\\n"; } if (!PageValidate.IsDecimal(txtfenshu.Text)) { strErr += "fenshu格式错误!\\n"; } if (this.txtneirong.Text.Trim().Length == 0) { strErr += "neirong不能为空!\\n"; } if (!PageValidate.IsNumber(txtdafen_xuhao.Text)) { strErr += "dafen_xuhao格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); int shangke_id = int.Parse(this.txtshangke_id.Text); int fenzu_id = int.Parse(this.txtfenzu_id.Text); decimal fenshu = decimal.Parse(this.txtfenshu.Text); string neirong = this.txtneirong.Text; int dafen_xuhao = int.Parse(this.txtdafen_xuhao.Text); Maticsoft.Model.dafen_jieguo model = new Maticsoft.Model.dafen_jieguo(); model.id = id; model.shangke_id = shangke_id; model.fenzu_id = fenzu_id; model.fenshu = fenshu; model.neirong = neirong; model.dafen_xuhao = dafen_xuhao; Maticsoft.BLL.dafen_jieguo bll = new Maticsoft.BLL.dafen_jieguo(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.dafen_jieguo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dafen_jieguo("); strSql.Append("shangke_id,fenzu_id,fenshu,neirong,dafen_xuhao,time,open_id,name,beizhu,style)"); strSql.Append(" values ("); strSql.Append("@shangke_id,@fenzu_id,@fenshu,@neirong,@dafen_xuhao,@time,@open_id,@name,@beizhu,@style)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@shangke_id", SqlDbType.Int, 4), new SqlParameter("@fenzu_id", SqlDbType.Int, 4), new SqlParameter("@fenshu", SqlDbType.Float, 8), new SqlParameter("@neirong", SqlDbType.Text), new SqlParameter("@dafen_xuhao", SqlDbType.Int, 4), new SqlParameter("@time", SqlDbType.DateTime), new SqlParameter("@open_id", SqlDbType.NChar, 50), new SqlParameter("@name", SqlDbType.NChar, 50), new SqlParameter("@beizhu", SqlDbType.NChar, 10), new SqlParameter("@style", SqlDbType.Int, 4) }; parameters[0].Value = model.shangke_id; parameters[1].Value = model.fenzu_id; parameters[2].Value = model.fenshu; parameters[3].Value = model.neirong; parameters[4].Value = model.dafen_xuhao; parameters[5].Value = model.time; parameters[6].Value = model.open_id; parameters[7].Value = model.name; parameters[8].Value = model.beizhu; parameters[9].Value = model.style; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.dafen_jieguo GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,shangke_id,fenzu_id,fenshu,neirong,dafen_xuhao,time,open_id,name,beizhu,style from dafen_jieguo "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Maticsoft.Model.dafen_jieguo model = new Maticsoft.Model.dafen_jieguo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }