/// <summary> /// 增加一条数据 /// </summary> public int Add(WechatBuilder.Model.wx_message_setting model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wx_message_setting("); strSql.Append("wid,title,adminOpenid,picUrl,needSH)"); strSql.Append(" values ("); strSql.Append("@wid,@title,@adminOpenid,@picUrl,@needSH)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@wid", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.VarChar, 200), new SqlParameter("@adminOpenid", SqlDbType.VarChar, 100), new SqlParameter("@picUrl", SqlDbType.VarChar, 800), new SqlParameter("@needSH", SqlDbType.Bit, 1) }; parameters[0].Value = model.wid; parameters[1].Value = model.title; parameters[2].Value = model.adminOpenid; parameters[3].Value = model.picUrl; parameters[4].Value = model.needSH; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WechatBuilder.Model.wx_message_setting DataRowToModel(DataRow row) { WechatBuilder.Model.wx_message_setting model = new WechatBuilder.Model.wx_message_setting(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["wid"] != null && row["wid"].ToString() != "") { model.wid = int.Parse(row["wid"].ToString()); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["adminOpenid"] != null) { model.adminOpenid = row["adminOpenid"].ToString(); } if (row["picUrl"] != null) { model.picUrl = row["picUrl"].ToString(); } if (row["needSH"] != null && row["needSH"].ToString() != "") { if ((row["needSH"].ToString() == "1") || (row["needSH"].ToString().ToLower() == "true")) { model.needSH = true; } else { model.needSH = false; } } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WechatBuilder.Model.wx_message_setting model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wx_message_setting set "); strSql.Append("wid=@wid,"); strSql.Append("title=@title,"); strSql.Append("adminOpenid=@adminOpenid,"); strSql.Append("picUrl=@picUrl,"); strSql.Append("needSH=@needSH"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@wid", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.VarChar, 200), new SqlParameter("@adminOpenid", SqlDbType.VarChar, 100), new SqlParameter("@picUrl", SqlDbType.VarChar, 800), new SqlParameter("@needSH", SqlDbType.Bit, 1), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.wid; parameters[1].Value = model.title; parameters[2].Value = model.adminOpenid; parameters[3].Value = model.picUrl; parameters[4].Value = model.needSH; 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_message_setting GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,wid,title,adminOpenid,picUrl,needSH from wx_message_setting "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; WechatBuilder.Model.wx_message_setting model = new WechatBuilder.Model.wx_message_setting(); 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_message_setting DataRowToModel(DataRow row) { WechatBuilder.Model.wx_message_setting model=new WechatBuilder.Model.wx_message_setting(); if (row != null) { if(row["id"]!=null && row["id"].ToString()!="") { model.id=int.Parse(row["id"].ToString()); } if(row["wid"]!=null && row["wid"].ToString()!="") { model.wid=int.Parse(row["wid"].ToString()); } if(row["title"]!=null) { model.title=row["title"].ToString(); } if(row["adminOpenid"]!=null) { model.adminOpenid=row["adminOpenid"].ToString(); } if(row["picUrl"]!=null) { model.picUrl=row["picUrl"].ToString(); } if(row["needSH"]!=null && row["needSH"].ToString()!="") { if((row["needSH"].ToString()=="1")||(row["needSH"].ToString().ToLower()=="true")) { model.needSH=true; } else { model.needSH=false; } } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public WechatBuilder.Model.wx_message_setting GetModel(int id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 id,wid,title,adminOpenid,picUrl,needSH from wx_message_setting "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; WechatBuilder.Model.wx_message_setting model=new WechatBuilder.Model.wx_message_setting(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }