Esempio n. 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.weixin_request_rule GetModel(int account_id, int request_type)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder();

            Model.weixin_request_rule model = new Model.weixin_request_rule();
            //利用反射获得属性的所有公共属性
            PropertyInfo[] pros = model.GetType().GetProperties();
            foreach (PropertyInfo p in pros)
            {
                //拼接字段,忽略List<T>
                if (!p.Name.Equals("values") && !p.Name.Equals("contents"))
                {
                    str1.Append(p.Name + ",");
                }
            }
            strSql.Append("select top 1 " + str1.ToString().Trim(','));
            strSql.Append(" from " + databaseprefix + "weixin_request_rule");
            strSql.AppendFormat(" where account_id={0} and request_type='{1}'", account_id, request_type);

            DataSet ds = WriteDataBase.QueryFillDataSet(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataTable GetImagesList(int article_id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id,article_id,thumb_path,original_path,sort_id,remark,add_time,channel_id ");
            strSql.Append(" FROM " + databaseprefix + "article_albums ");
            strSql.Append(" where article_id=" + article_id);
            strSql.Append(" order by sort_id asc, id asc");
            DataSet ds = WriteDataBase.QueryFillDataSet(strSql.ToString());

            return(ds.Tables[0]);
        }
Esempio n. 3
0
        /// <summary>
        /// 将对象转换实体
        /// </summary>
        public Model.weixin_request_rule DataRowToModel(DataRow row)
        {
            Model.weixin_request_rule model = new Model.weixin_request_rule();
            if (row != null)
            {
                #region 主表信息======================
                //利用反射获得属性的所有公共属性
                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);//用索引值设置属性值
                    }
                }
                #endregion

                #region 子表信息======================
                StringBuilder strSql1 = new StringBuilder();
                strSql1.Append("select * from " + databaseprefix + "weixin_request_content");
                strSql1.Append(" where rule_id=" + model.id);
                DataTable dt1 = WriteDataBase.QueryFillDataSet(strSql1.ToString()).Tables[0];

                if (dt1.Rows.Count > 0)
                {
                    int rowsCount = dt1.Rows.Count;
                    List <Model.weixin_request_content> models = new List <Model.weixin_request_content>();
                    Model.weixin_request_content        modelt;
                    for (int n = 0; n < rowsCount; n++)
                    {
                        modelt = new Model.weixin_request_content();
                        Type modeltType = modelt.GetType();
                        for (int i = 0; i < dt1.Rows[n].Table.Columns.Count; i++)
                        {
                            PropertyInfo proInfo = modeltType.GetProperty(dt1.Rows[n].Table.Columns[i].ColumnName);
                            if (proInfo != null && dt1.Rows[n][i] != DBNull.Value)
                            {
                                proInfo.SetValue(modelt, dt1.Rows[n][i], null);
                            }
                        }
                        models.Add(modelt);
                    }
                    model.contents = models;
                }
                #endregion
            }
            return(model);
        }
Esempio n. 4
0
        /// <summary>
        /// 得到关健字查询的规则ID及回复类型(如需提高效率可使用存储过程)
        /// </summary>
        public int GetKeywordsRuleId(int account_id, string keywords, out int response_type)
        {
            int rule_id = 0;
            //精确匹配
            StringBuilder strSql3 = new StringBuilder();

            strSql3.Append("select top 1 id,response_type from " + databaseprefix + "weixin_request_rule");
            strSql3.Append(" where account_id=" + account_id + " and request_type=1");
            strSql3.Append(" and(keywords like '" + keywords + "|%' or keywords='%|" + keywords + "' or keywords like '%|" + keywords + "|%' or keywords='" + keywords + "')");
            strSql3.Append(" order by sort_id asc,add_time desc");
            DataSet ds3 = WriteDataBase.QueryFillDataSet(strSql3.ToString());

            if (ds3.Tables[0].Rows.Count > 0)
            {
                rule_id       = int.Parse(ds3.Tables[0].Rows[0][0].ToString());
                response_type = int.Parse(ds3.Tables[0].Rows[0][1].ToString());
                return(rule_id);
            }
            //模糊匹配
            StringBuilder strSql2 = new StringBuilder();

            strSql2.Append("select top 1 id,response_type from " + databaseprefix + "weixin_request_rule");
            strSql2.Append(" where account_id=" + account_id + " and request_type=1 and keywords like '%" + keywords + "%'");
            strSql2.Append(" order by sort_id asc,add_time desc");
            DataSet ds2 = WriteDataBase.QueryFillDataSet(strSql2.ToString());

            if (ds2.Tables[0].Rows.Count > 0)
            {
                rule_id       = int.Parse(ds2.Tables[0].Rows[0][0].ToString());
                response_type = int.Parse(ds2.Tables[0].Rows[0][1].ToString());
                return(rule_id);
            }
            //默认回复
            StringBuilder strSql1 = new StringBuilder();

            strSql1.Append("select top 1 id,response_type from " + databaseprefix + "weixin_request_rule");
            strSql1.Append(" where account_id=" + account_id + " and request_type=0");
            strSql1.Append(" order by sort_id asc,add_time desc");
            DataSet ds1 = WriteDataBase.QueryFillDataSet(strSql1.ToString());

            if (ds1.Tables[0].Rows.Count > 0)
            {
                rule_id       = int.Parse(ds1.Tables[0].Rows[0][0].ToString());
                response_type = int.Parse(ds1.Tables[0].Rows[0][1].ToString());
                return(rule_id);
            }
            response_type = 0;
            return(rule_id);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取站点未添加数据
        /// </summary>
        public DataSet GetList(int site_id, int oauth_id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * FROM  " + databaseprefix + "oauth_app");
            strSql.Append(" where is_lock=0 and id not in(");
            strSql.Append("select oauth_id from " + databaseprefix + "site_oauth where site_id=" + site_id);
            if (oauth_id > 0)
            {
                strSql.Append(" and oauth_id<>" + oauth_id);
            }
            strSql.Append(")");
            strSql.Append(" order by sort_id asc,id desc");
            return(WriteDataBase.QueryFillDataSet(strSql.ToString()));
        }
Esempio n. 6
0
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(string channel_name, int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" * ");
            strSql.Append(" FROM " + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + channel_name);
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return(WriteDataBase.QueryFillDataSet(strSql.ToString()));
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public override Model.article_attribute_field GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder();

            Model.article_attribute_field model = new Model.article_attribute_field();
            //利用反射获得属性的所有公共属性
            Type modelType = model.GetType();

            PropertyInfo[] pros = modelType.GetProperties();
            foreach (PropertyInfo p in pros)
            {
                str1.Append(p.Name + ",");//拼接字段
            }
            strSql.Append("select top 1 " + str1.ToString().Trim(','));
            strSql.Append(" from " + databaseprefix + "article_attribute_field");
            strSql.Append(" where id=" + id);
            DataTable dt = WriteDataBase.QueryFillDataSet(strSql.ToString()).Tables[0];

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows[0].Table.Columns.Count; i++)
                {
                    //查找实体是否存在列表相同的公共属性
                    PropertyInfo proInfo = modelType.GetProperty(dt.Rows[0].Table.Columns[i].ColumnName);
                    if (proInfo != null && dt.Rows[0][i] != DBNull.Value)
                    {
                        proInfo.SetValue(model, dt.Rows[0][i], null);//用索引值设置属性值
                    }
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }