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