Example #1
0
        /// <summary>
        /// 随机出题
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="kpointId"></param>
        /// <param name="cpointId"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static int[] GetQuesIds(int courseId, int kpointId, int cpointId, int count)
        {
            List <int>            model = null;
            string                sql   = "select id from T_Questions where courseid = @courseId and pid = 0 ";
            List <MySqlParameter> pl    = new List <MySqlParameter>();

            pl.Add(new MySqlParameter("@courseid", courseId));

            if (kpointId != 0)
            {
                sql += "and kpoints like '%\"" + kpointId + "\"%'";
            }

            if (cpointId != 0)
            {
                int[] s = B_QuesBase.GetSimilarCatalogs(courseId, cpointId);
                if (s != null)
                {
                    sql += "and (";
                    var str = "";
                    foreach (var c in s)
                    {
                        str += " or cpoints like '%\"" + c + "\"%'";
                    }
                    sql += str.Substring(3) + ")";
                }
                else
                {
                    sql += "and cpoints like '%\"" + cpointId + "\"%'";
                }
            }

            sql += " order by usagetimes desc";

            using (MySqlDataReader dr = MySqlHelper.ExecuteReader(Util.GetConnectString(QuesConnString), sql, pl.ToArray()))
            {
                if (dr != null && dr.HasRows)
                {
                    model = new List <int>();
                    while (dr.Read())
                    {
                        model.Add(int.Parse(dr[0].ToString()));
                    }
                }
            }
            return(model == null ? null : model.ToArray());
        }
Example #2
0
        /// <summary>
        /// 根据查询条件返回符合条件的试题Id数组
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="kpointId"></param>
        /// <param name="cpointId"></param>
        /// <param name="typeId"></param>
        /// <param name="diffType"></param>
        /// <param name="paperYear"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public static int[] GetQuesIds(int courseId, int kpointId, int cpointId, int typeId, int diffType, int paperYear, int pageIndex, int pageSize, out int totalCount)
        {
            int[] cpointIds = null;
            if (cpointId != 0)
            {
                int[] s = B_QuesBase.GetSimilarCatalogs(courseId, cpointId);
                if (s == null)
                {
                    s = new int[1] {
                        cpointId
                    };
                }
                cpointIds = s;
            }

            return(SolrHelper.QueryQuesIds(courseId, kpointId, cpointIds, typeId, diffType, paperYear, pageIndex, pageSize, out totalCount));
        }
Example #3
0
        /// <summary>
        /// 根据查询条件返回符合条件的试题Id数组
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="kpointId"></param>
        /// <param name="cpointId"></param>
        /// <param name="typeId"></param>
        /// <param name="diffType"></param>
        /// <param name="paperYear"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public static int[] GetQuesIds(int courseId, int kpointId, int cpointId, int typeId, int diffType, int paperYear, int pageIndex, int pageSize, out int totalCount)
        {
            List <int>            model    = null;
            string                wherestr = "T_Questions where courseid = @courseId ";
            string                orderstr = "usagetimes desc";
            List <MySqlParameter> pl       = new List <MySqlParameter>();

            pl.Add(new MySqlParameter("@courseid", courseId));

            if (typeId != 0)
            {
                wherestr += "and btypeid=@btypeid ";
                pl.Add(new MySqlParameter("@btypeid", typeId));
            }

            if (diffType != 0)
            {
                wherestr += "and difftype=@difftype ";
                pl.Add(new MySqlParameter("@difftype", diffType));
            }

            if (paperYear > 0)
            {
                wherestr += "and paperyear = @paperyear ";
                pl.Add(new MySqlParameter("@paperyear", paperYear));
            }
            else if (paperYear < 0)
            {
                wherestr += "and paperyear <= @paperyear ";
                pl.Add(new MySqlParameter("@paperyear", paperYear * -1));
            }

            if (kpointId != 0)
            {
                wherestr += "and kpoints like '%\"" + kpointId + "\"%'";
            }

            if (cpointId != 0)
            {
                int[] s = B_QuesBase.GetSimilarCatalogs(courseId, cpointId);
                if (s != null)
                {
                    wherestr += "and (";
                    var str = "";
                    foreach (var c in s)
                    {
                        str += " or cpoints like '%\"" + c + "\"%'";
                    }
                    wherestr += str.Substring(3) + ")";
                }
                else
                {
                    wherestr += "and cpoints like '%\"" + cpointId + "\"%'";
                }
            }

            using (MySqlDataReader dr = MySqlDBHelper.GetPageReader(Util.GetConnectString(QuesConnString),
                                                                    "id",
                                                                    wherestr,
                                                                    orderstr,
                                                                    pageSize,
                                                                    pageIndex,
                                                                    out totalCount,
                                                                    pl.ToArray()))
            {
                if (dr != null && dr.HasRows)
                {
                    model = new List <int>();
                    while (dr.Read())
                    {
                        model.Add(int.Parse(dr[0].ToString()));
                    }
                }
            }
            return(model == null ? null : model.ToArray());
        }