/// <summary> /// 增加一条数据 /// </summary> public int Add(WeiXinPF.Model.wx_wq_chexing model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wx_wq_chexing("); strSql.Append("xid,dwNum,Name,niankuan,sort_id,zdPrice,jxsPrice,pic,qjid,pailiang,biansuxiang,createdate,wid,pid)"); strSql.Append(" values ("); strSql.Append("@xid,@dwNum,@Name,@niankuan,@sort_id,@zdPrice,@jxsPrice,@pic,@qjid,@pailiang,@biansuxiang,@createdate,@wid,@pid)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@xid", SqlDbType.Int, 4), new SqlParameter("@dwNum", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.VarChar, 300), new SqlParameter("@niankuan", SqlDbType.VarChar, 300), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@zdPrice", SqlDbType.NVarChar, 100), new SqlParameter("@jxsPrice", SqlDbType.NVarChar, 100), new SqlParameter("@pic", SqlDbType.VarChar, 500), new SqlParameter("@qjid", SqlDbType.Int, 4), new SqlParameter("@pailiang", SqlDbType.VarChar, 300), new SqlParameter("@biansuxiang", SqlDbType.VarChar, 300), new SqlParameter("@createdate", SqlDbType.DateTime), new SqlParameter("@wid", SqlDbType.Int, 4), new SqlParameter("@pid", SqlDbType.Int, 4) }; parameters[0].Value = model.xid; parameters[1].Value = model.dwNum; parameters[2].Value = model.Name; parameters[3].Value = model.niankuan; parameters[4].Value = model.sort_id; parameters[5].Value = model.zdPrice; parameters[6].Value = model.jxsPrice; parameters[7].Value = model.pic; parameters[8].Value = model.qjid; parameters[9].Value = model.pailiang; parameters[10].Value = model.biansuxiang; parameters[11].Value = model.createdate; parameters[12].Value = model.wid; parameters[13].Value = model.pid; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WeiXinPF.Model.wx_wq_chexing GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,xid,dwNum,Name,niankuan,sort_id,zdPrice,jxsPrice,pic,qjid,pailiang,biansuxiang,createdate,wid,pid from wx_wq_chexing "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; WeiXinPF.Model.wx_wq_chexing model = new WeiXinPF.Model.wx_wq_chexing(); 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 WeiXinPF.Model.wx_wq_chexing DataRowToModel(DataRow row) { WeiXinPF.Model.wx_wq_chexing model = new WeiXinPF.Model.wx_wq_chexing(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["xid"] != null && row["xid"].ToString() != "") { model.xid = int.Parse(row["xid"].ToString()); } if (row["dwNum"] != null && row["dwNum"].ToString() != "") { model.dwNum = int.Parse(row["dwNum"].ToString()); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["niankuan"] != null) { model.niankuan = row["niankuan"].ToString(); } if (row["sort_id"] != null && row["sort_id"].ToString() != "") { model.sort_id = int.Parse(row["sort_id"].ToString()); } if (row["zdPrice"] != null) { model.zdPrice = row["zdPrice"].ToString(); } if (row["jxsPrice"] != null) { model.jxsPrice = row["jxsPrice"].ToString(); } if (row["pic"] != null) { model.pic = row["pic"].ToString(); } if (row["qjid"] != null && row["qjid"].ToString() != "") { model.qjid = int.Parse(row["qjid"].ToString()); } if (row["pailiang"] != null) { model.pailiang = row["pailiang"].ToString(); } if (row["biansuxiang"] != null) { model.biansuxiang = row["biansuxiang"].ToString(); } if (row["createdate"] != null && row["createdate"].ToString() != "") { model.createdate = DateTime.Parse(row["createdate"].ToString()); } if (row["wid"] != null && row["wid"].ToString() != "") { model.wid = int.Parse(row["wid"].ToString()); } if (row["pid"] != null && row["pid"].ToString() != "") { model.pid = int.Parse(row["pid"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WeiXinPF.Model.wx_wq_chexing model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wx_wq_chexing set "); strSql.Append("xid=@xid,"); strSql.Append("dwNum=@dwNum,"); strSql.Append("Name=@Name,"); strSql.Append("niankuan=@niankuan,"); strSql.Append("sort_id=@sort_id,"); strSql.Append("zdPrice=@zdPrice,"); strSql.Append("jxsPrice=@jxsPrice,"); strSql.Append("pic=@pic,"); strSql.Append("qjid=@qjid,"); strSql.Append("pailiang=@pailiang,"); strSql.Append("biansuxiang=@biansuxiang,"); strSql.Append("createdate=@createdate,"); strSql.Append("wid=@wid,"); strSql.Append("pid=@pid"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@xid", SqlDbType.Int, 4), new SqlParameter("@dwNum", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.VarChar, 300), new SqlParameter("@niankuan", SqlDbType.VarChar, 300), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@zdPrice", SqlDbType.NVarChar, 100), new SqlParameter("@jxsPrice", SqlDbType.NVarChar, 100), new SqlParameter("@pic", SqlDbType.VarChar, 500), new SqlParameter("@qjid", SqlDbType.Int, 4), new SqlParameter("@pailiang", SqlDbType.VarChar, 300), new SqlParameter("@biansuxiang", SqlDbType.VarChar, 300), new SqlParameter("@createdate", SqlDbType.DateTime), new SqlParameter("@wid", SqlDbType.Int, 4), new SqlParameter("@pid", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.xid; parameters[1].Value = model.dwNum; parameters[2].Value = model.Name; parameters[3].Value = model.niankuan; parameters[4].Value = model.sort_id; parameters[5].Value = model.zdPrice; parameters[6].Value = model.jxsPrice; parameters[7].Value = model.pic; parameters[8].Value = model.qjid; parameters[9].Value = model.pailiang; parameters[10].Value = model.biansuxiang; parameters[11].Value = model.createdate; parameters[12].Value = model.wid; parameters[13].Value = model.pid; parameters[14].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }