/// <summary> /// 得到一个对象实体 /// </summary> public Model.weixin_response_content GetModel(int id) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); Model.weixin_response_content model = new Model.weixin_response_content(); //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); foreach (PropertyInfo p in pros) { str1.Append(p.Name + ",");//拼接字段 } strSql.Append("select top 1 " + str1.ToString().Trim(',')); strSql.Append(" from " + databaseprefix + "weixin_response_content"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; DataTable dt = DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0]; if (dt.Rows.Count > 0) { return(DataRowToModel(dt.Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.weixin_response_content model) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); List <SqlParameter> paras = new List <SqlParameter>(); strSql.Append("update " + databaseprefix + "weixin_response_content set "); foreach (PropertyInfo pi in pros) { //如果不是主键则追加sql字符串 if (!pi.Name.Equals("id")) { //判断属性值是否为空 if (pi.GetValue(model, null) != null && !pi.GetValue(model, null).ToString().Equals("")) { str1.Append(pi.Name + "=@" + pi.Name + ","); //声明参数 paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值 } } } strSql.Append(str1.ToString().Trim(',')); strSql.Append(" where id=@id"); paras.Add(new SqlParameter("@id", model.id)); return(DbHelperSQL.ExecuteSql(strSql.ToString(), paras.ToArray()) > 0); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.weixin_response_content model) { int newId; using (OleDbConnection conn = new OleDbConnection(DbHelperOleDb.connectionString)) { conn.Open(); using (OleDbTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "weixin_response_content("); strSql.Append("account_id,openid,request_type,request_content,response_type,reponse_content,create_time,xml_content,add_time)"); strSql.Append(" values ("); strSql.Append("@account_id,@openid,@request_type,@request_content,@response_type,@reponse_content,@create_time,@xml_content,@add_time)"); OleDbParameter[] parameters = { new OleDbParameter("@account_id", OleDbType.Integer, 4), new OleDbParameter("@openid", OleDbType.VarChar, 100), new OleDbParameter("@request_type", OleDbType.VarChar, 50), new OleDbParameter("@request_content", OleDbType.VarChar, 2000), new OleDbParameter("@response_type", OleDbType.VarChar, 50), new OleDbParameter("@reponse_content", OleDbType.VarChar, 2000), new OleDbParameter("@create_time", OleDbType.VarChar, 50), new OleDbParameter("@xml_content", OleDbType.VarChar, 2000), new OleDbParameter("@add_time", OleDbType.Date) }; parameters[0].Value = model.account_id; parameters[1].Value = model.openid; parameters[2].Value = model.request_type; parameters[3].Value = model.request_content; parameters[4].Value = model.response_type; parameters[5].Value = model.reponse_content; parameters[6].Value = model.create_time; parameters[7].Value = model.xml_content; parameters[8].Value = model.add_time; DbHelperOleDb.ExecuteSql(conn, trans, strSql.ToString(), parameters); //取得新插入的ID newId = GetMaxId(conn, trans); trans.Commit(); } catch { trans.Rollback(); return(-1); } } } return(newId); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.weixin_response_content model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "weixin_response_content set "); strSql.Append("account_id=@account_id,"); strSql.Append("openid=@openid,"); strSql.Append("request_type=@request_type,"); strSql.Append("request_content=@request_content,"); strSql.Append("response_type=@response_type,"); strSql.Append("reponse_content=@reponse_content,"); strSql.Append("create_time=@create_time,"); strSql.Append("xml_content=@xml_content,"); strSql.Append("add_time=@add_time"); strSql.Append(" where id=@id"); OleDbParameter[] parameters = { new OleDbParameter("@account_id", OleDbType.Integer, 4), new OleDbParameter("@openid", OleDbType.VarChar, 100), new OleDbParameter("@request_type", OleDbType.VarChar, 50), new OleDbParameter("@request_content", OleDbType.VarChar, 2000), new OleDbParameter("@response_type", OleDbType.VarChar, 50), new OleDbParameter("@reponse_content", OleDbType.VarChar, 2000), new OleDbParameter("@create_time", OleDbType.VarChar, 50), new OleDbParameter("@xml_content", OleDbType.VarChar, 2000), new OleDbParameter("@add_time", OleDbType.Date), new OleDbParameter("@id", OleDbType.Integer, 4) }; parameters[0].Value = model.account_id; parameters[1].Value = model.openid; parameters[2].Value = model.request_type; parameters[3].Value = model.request_content; parameters[4].Value = model.response_type; parameters[5].Value = model.reponse_content; parameters[6].Value = model.create_time; parameters[7].Value = model.xml_content; parameters[8].Value = model.add_time; parameters[9].Value = model.id; int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.weixin_response_content DataRowToModel(DataRow row) { DTcms.Model.weixin_response_content model = new Model.weixin_response_content(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["account_id"] != null && row["account_id"].ToString() != "") { model.account_id = int.Parse(row["account_id"].ToString()); } if (row["openid"] != null) { model.openid = row["openid"].ToString(); } if (row["request_type"] != null) { model.request_type = row["request_type"].ToString(); } if (row["request_content"] != null) { model.request_content = row["request_content"].ToString(); } if (row["response_type"] != null) { model.response_type = row["response_type"].ToString(); } if (row["reponse_content"] != null) { model.reponse_content = row["reponse_content"].ToString(); } if (row["create_time"] != null) { model.create_time = row["create_time"].ToString(); } if (row["xml_content"] != null) { model.xml_content = row["xml_content"].ToString(); } if (row["add_time"] != null && row["add_time"].ToString() != "") { model.add_time = DateTime.Parse(row["add_time"].ToString()); } } return(model); }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public Model.weixin_response_content DataRowToModel(DataRow row) { DTcms.Model.weixin_response_content model = new Model.weixin_response_content(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["account_id"] != null && row["account_id"].ToString() != "") { model.account_id = int.Parse(row["account_id"].ToString()); } if (row["openid"] != null) { model.openid = row["openid"].ToString(); } if (row["request_type"] != null) { model.request_type = row["request_type"].ToString(); } if (row["request_content"] != null) { model.request_content = row["request_content"].ToString(); } if (row["response_type"] != null) { model.response_type = row["response_type"].ToString(); } if (row["reponse_content"] != null) { model.reponse_content = row["reponse_content"].ToString(); } if (row["create_time"] != null) { model.create_time = row["create_time"].ToString(); } if (row["xml_content"] != null) { model.xml_content = row["xml_content"].ToString(); } if (row["add_time"] != null && row["add_time"].ToString() != "") { model.add_time = DateTime.Parse(row["add_time"].ToString()); } } return model; }
/// <summary> /// 将对象转换实体 /// </summary> public Model.weixin_response_content DataRowToModel(DataRow row) { Model.weixin_response_content model = new Model.weixin_response_content(); if (row != null) { //利用反射获得属性的所有公共属性 Type modelType = model.GetType(); for (int i = 0; i < row.Table.Columns.Count; i++) { //查找实体是否存在列表相同的公共属性 PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName); if (proInfo != null && row[i] != DBNull.Value) { proInfo.SetValue(model, row[i], null);//用索引值设置属性值 } } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.weixin_response_content model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "weixin_response_content("); strSql.Append("account_id,openid,request_type,request_content,response_type,reponse_content,create_time,xml_content,add_time)"); strSql.Append(" values ("); strSql.Append("@account_id,@openid,@request_type,@request_content,@response_type,@reponse_content,@create_time,@xml_content,@add_time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@account_id", SqlDbType.Int, 4), new SqlParameter("@openid", SqlDbType.NVarChar, 100), new SqlParameter("@request_type", SqlDbType.NVarChar, 50), new SqlParameter("@request_content", SqlDbType.NVarChar, 2000), new SqlParameter("@response_type", SqlDbType.NVarChar, 50), new SqlParameter("@reponse_content", SqlDbType.NVarChar, 2000), new SqlParameter("@create_time", SqlDbType.NVarChar, 50), new SqlParameter("@xml_content", SqlDbType.NVarChar, 2000), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.account_id; parameters[1].Value = model.openid; parameters[2].Value = model.request_type; parameters[3].Value = model.request_content; parameters[4].Value = model.response_type; parameters[5].Value = model.reponse_content; parameters[6].Value = model.create_time; parameters[7].Value = model.xml_content; parameters[8].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.weixin_response_content model) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); //数据字段 StringBuilder str2 = new StringBuilder(); //数据参数 //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); List <SqlParameter> paras = new List <SqlParameter>(); strSql.Append("insert into " + databaseprefix + "weixin_response_content("); foreach (PropertyInfo pi in pros) { //如果不是主键则追加sql字符串 if (!pi.Name.Equals("id")) { //判断属性值是否为空 if (pi.GetValue(model, null) != null && !pi.GetValue(model, null).ToString().Equals("")) { str1.Append(pi.Name + ","); //拼接字段 str2.Append("@" + pi.Name + ","); //声明参数 paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值 } } } strSql.Append(str1.ToString().Trim(',')); strSql.Append(") values ("); strSql.Append(str2.ToString().Trim(',')); strSql.Append(") "); strSql.Append(";select @@IDENTITY;"); object obj = DbHelperSQL.GetSingle(strSql.ToString(), paras.ToArray()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 增加一条记录 /// </summary> /// <param name="openid">请求的用户openid</param> /// <param name="request_type">用户请求的类型:文本消息:text 图片消息:image 地理位置消息:location 链接消息:link 事件:event</param> /// <param name="request_content">用户请求的数据内容</param> /// <param name="response_type"> 系统回复的类型:文本消息:text ,图文消息:txtpic ,语音music, 地理位置消息:location 链接消息:link,未取到数据none</param> /// <param name="reponse_content">系统回复的内容</param> /// <param name="ToUserName">由于取不到xml内容,我们将toUserName存入</param> public int Add(string openid, string request_type, string request_content, string response_type, string reponse_content, string xml_content) { int result = 0; try { Model.weixin_response_content model = new Model.weixin_response_content(); model.openid = openid; model.request_type = request_type; model.request_content = request_content; model.response_type = response_type; model.reponse_content = reponse_content; model.xml_content = xml_content; model.add_time = DateTime.Now; result = dal.Add(model); } catch { return(0); } return(result); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.weixin_response_content model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.weixin_response_content model) { return(dal.Add(model)); }
/// <summary> /// 增加一条记录 /// </summary> /// <param name="account_id">公众平台账户ID</param> /// <param name="openid">请求的用户openid</param> /// <param name="request_type">用户请求的类型:文本消息:text 图片消息:image 地理位置消息:location 链接消息:link 事件:event</param> /// <param name="request_content">用户请求的数据内容</param> /// <param name="response_type"> 系统回复的类型:文本消息:text ,图文消息:txtpic ,语音music, 地理位置消息:location 链接消息:link,未取到数据none</param> /// <param name="reponse_content">系统回复的内容</param> /// <param name="ToUserName">由于取不到xml内容,我们将toUserName存入</param> public int Add(int account_id, string openid, string request_type, string request_content, string response_type, string reponse_content, string xml_content) { int result = 0; try { Model.weixin_response_content model = new Model.weixin_response_content(); model.account_id = account_id; model.openid = openid; model.request_type = request_type; model.request_content = request_content; model.response_type = response_type; model.reponse_content = reponse_content; model.xml_content = xml_content; model.add_time = DateTime.Now; result = dal.Add(model); } catch { return 0; } return result; }