/// <summary> /// 得到一个对象实体 /// </summary> public MxWeiXinPF.Model.wx_hb_imggroup DataRowToModel(DataRow row) { MxWeiXinPF.Model.wx_hb_imggroup model = new MxWeiXinPF.Model.wx_hb_imggroup(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["hid"] != null && row["hid"].ToString() != "") { model.hid = int.Parse(row["hid"].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["igName"] != null) { model.igName = row["igName"].ToString(); } if (row["cratedate"] != null && row["cratedate"].ToString() != "") { model.cratedate = DateTime.Parse(row["cratedate"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(MxWeiXinPF.Model.wx_hb_imggroup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wx_hb_imggroup("); strSql.Append("hid,imgurl,sort_id,igName,cratedate)"); strSql.Append(" values ("); strSql.Append("@hid,@imgurl,@sort_id,@igName,@cratedate)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@hid", SqlDbType.Int, 4), new SqlParameter("@imgurl", SqlDbType.VarChar, 800), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@igName", SqlDbType.VarChar, 500), new SqlParameter("@cratedate", SqlDbType.DateTime) }; parameters[0].Value = model.hid; parameters[1].Value = model.imgurl; parameters[2].Value = model.sort_id; parameters[3].Value = model.igName; parameters[4].Value = model.cratedate; 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_imggroup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wx_hb_imggroup set "); strSql.Append("hid=@hid,"); strSql.Append("imgurl=@imgurl,"); strSql.Append("sort_id=@sort_id,"); strSql.Append("igName=@igName,"); strSql.Append("cratedate=@cratedate"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@hid", SqlDbType.Int, 4), new SqlParameter("@imgurl", SqlDbType.VarChar, 800), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@igName", SqlDbType.VarChar, 500), new SqlParameter("@cratedate", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.hid; parameters[1].Value = model.imgurl; parameters[2].Value = model.sort_id; parameters[3].Value = model.igName; parameters[4].Value = model.cratedate; 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_imggroup GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,hid,imgurl,sort_id,igName,cratedate from wx_hb_imggroup "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; MxWeiXinPF.Model.wx_hb_imggroup model = new MxWeiXinPF.Model.wx_hb_imggroup(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }