/// <summary> /// 增加一条数据 /// </summary> public int Add(WechatBuilder.Model.wx_diancai_dingdan_caiping model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wx_diancai_dingdan_caiping("); strSql.Append("dingId,caiId,num,price,totpric)"); strSql.Append(" values ("); strSql.Append("@dingId,@caiId,@num,@price,@totpric)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@dingId", SqlDbType.Int, 4), new SqlParameter("@caiId", SqlDbType.Int, 4), new SqlParameter("@num", SqlDbType.Int, 4), new SqlParameter("@price", SqlDbType.Float, 8), new SqlParameter("@totpric", SqlDbType.Float, 8) }; parameters[0].Value = model.dingId; parameters[1].Value = model.caiId; parameters[2].Value = model.num; parameters[3].Value = model.price; parameters[4].Value = model.totpric; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WechatBuilder.Model.wx_diancai_dingdan_caiping DataRowToModel(DataRow row) { WechatBuilder.Model.wx_diancai_dingdan_caiping model = new WechatBuilder.Model.wx_diancai_dingdan_caiping(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["dingId"] != null && row["dingId"].ToString() != "") { model.dingId = int.Parse(row["dingId"].ToString()); } if (row["caiId"] != null && row["caiId"].ToString() != "") { model.caiId = int.Parse(row["caiId"].ToString()); } if (row["num"] != null && row["num"].ToString() != "") { model.num = int.Parse(row["num"].ToString()); } if (row["price"] != null && row["price"].ToString() != "") { model.price = decimal.Parse(row["price"].ToString()); } if (row["totpric"] != null && row["totpric"].ToString() != "") { model.totpric = decimal.Parse(row["totpric"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WechatBuilder.Model.wx_diancai_dingdan_caiping model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wx_diancai_dingdan_caiping set "); strSql.Append("dingId=@dingId,"); strSql.Append("caiId=@caiId,"); strSql.Append("num=@num,"); strSql.Append("price=@price,"); strSql.Append("totpric=@totpric"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@dingId", SqlDbType.Int, 4), new SqlParameter("@caiId", SqlDbType.Int, 4), new SqlParameter("@num", SqlDbType.Int, 4), new SqlParameter("@price", SqlDbType.Float, 8), new SqlParameter("@totpric", SqlDbType.Float, 8), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.dingId; parameters[1].Value = model.caiId; parameters[2].Value = model.num; parameters[3].Value = model.price; parameters[4].Value = model.totpric; parameters[5].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WechatBuilder.Model.wx_diancai_dingdan_caiping GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,dingId,caiId,num,price,totpric from wx_diancai_dingdan_caiping "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; WechatBuilder.Model.wx_diancai_dingdan_caiping model = new WechatBuilder.Model.wx_diancai_dingdan_caiping(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WechatBuilder.Model.wx_diancai_dingdan_caiping DataRowToModel(DataRow row) { WechatBuilder.Model.wx_diancai_dingdan_caiping model = new WechatBuilder.Model.wx_diancai_dingdan_caiping(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["dingId"] != null && row["dingId"].ToString() != "") { model.dingId = int.Parse(row["dingId"].ToString()); } if (row["caiId"] != null && row["caiId"].ToString() != "") { model.caiId = int.Parse(row["caiId"].ToString()); } if (row["num"] != null && row["num"].ToString() != "") { model.num = int.Parse(row["num"].ToString()); } if (row["price"] != null && row["price"].ToString() != "") { model.price = decimal.Parse(row["price"].ToString()); } if (row["totpric"] != null && row["totpric"].ToString() != "") { model.totpric = decimal.Parse(row["totpric"].ToString()); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public WechatBuilder.Model.wx_diancai_dingdan_caiping GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,dingId,caiId,num,price,totpric from wx_diancai_dingdan_caiping "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; WechatBuilder.Model.wx_diancai_dingdan_caiping model = new WechatBuilder.Model.wx_diancai_dingdan_caiping(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }