Beispiel #1
0
        /// <summary>
        /// 设置指定的查询语句并返回当前语句
        /// </summary>
        /// <param name="command">相关语句</param>
        /// <param name="ids">逗号分隔的实体ID</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="userName">用户名</param>
        /// <param name="languageType">提交语言</param>
        /// <param name="resultType">提交结果</param>
        /// <param name="startDate">开始时间</param>
        /// <param name="endDate">结束时间</param>
        /// <returns>当前语句</returns>
        internal static T Where <T>(this T command, String ids, Int32 cid, Int32 pid, String userName, LanguageType languageType, ResultType?resultType, DateTime?startDate, DateTime?endDate) where T : AbstractSqlCommandWithWhere
        {
            SqlConditionBuilder  c         = command.ConditionBuilder;
            AbstractSqlCondition condition = command.WhereCondition as AbstractSqlCondition;
            AbstractSqlCondition temp      = null;

            //提交ID
            if (!String.IsNullOrEmpty(ids))
            {
                temp      = c.InInt32(SolutionRepository.SOLUTIONID, ids, ',');
                condition = (condition == null ? temp : condition & temp);
            }

            //竞赛ID
            if (cid >= 0)
            {
                temp      = c.Equal(SolutionRepository.CONTESTID, cid);
                condition = (condition == null ? temp : condition & temp);
            }

            //题目ID
            if (pid >= 0)
            {
                temp      = c.Equal(SolutionRepository.PROBLEMID, pid);
                condition = (condition == null ? temp : condition & temp);
            }

            //用户名
            if (!String.IsNullOrEmpty(userName))
            {
                temp      = c.Equal(SolutionRepository.USERNAME, userName);
                condition = (condition == null ? temp : condition & temp);
            }

            //提交程序语言
            if (!LanguageType.IsNull(languageType))
            {
                temp      = c.Equal(SolutionRepository.LANGUAGE, languageType.ID);
                condition = (condition == null ? temp : condition & temp);
            }

            //提交结果
            if (resultType.HasValue)
            {
                temp      = c.Equal(SolutionRepository.RESULT, (Byte)resultType.Value);
                condition = (condition == null ? temp : condition & temp);
            }

            //开始时间
            if (startDate.HasValue || endDate.HasValue)
            {
                temp      = c.BetweenNullable <DateTime>(SolutionRepository.SUBMITTIME, startDate, endDate);
                condition = (condition == null ? temp : condition & temp);
            }

            command.Where(condition);

            return(command);
        }
        public void CreateInConditionTest()
        {
            AbstractDatabase fakeDb          = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            SelectCommand    expectedCommand = fakeDb.CreateSelectCommand("");
            SelectCommand    actualCommand   = fakeDb.CreateSelectCommand("");

            SqlConditionBuilder expectedConditionBuilder = expectedCommand.ConditionBuilder;
            SqlConditionBuilder actualConditionBuilder   = actualCommand.ConditionBuilder;

            SqlInsideParametersCondition expectedCondition = expectedConditionBuilder.InThese("TestColumn2", 1, 2, 3, 4, 5);
            SqlInsideParametersCondition actualCondition   = actualConditionBuilder.InInt32("TestColumn2", "1, 2, 3, 4, 5", ',');

            Assert.AreEqual(expectedCondition, actualCondition);
        }
        /// <summary>
        /// 设置指定的查询语句并返回当前语句
        /// </summary>
        /// <param name="command">选择语句</param>
        /// <param name="fpids">帖子ID列表</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="userName">发帖用户名</param>
        /// <param name="title">帖子标题</param>
        /// <param name="content">帖子内容</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <param name="postip">发帖IP</param>
        /// <returns>当前语句</returns>
        internal static SelectCommand Where(this SelectCommand command, String fpids, String ftids, String userName, String title, String content, Boolean?isHide, DateTime?startDate, DateTime?endDate, String postip)
        {
            SqlConditionBuilder  c         = command.ConditionBuilder;
            AbstractSqlCondition condition = command.WhereCondition as AbstractSqlCondition;
            AbstractSqlCondition temp      = null;

            //帖子ID
            if (!String.IsNullOrEmpty(fpids))
            {
                temp      = c.InInt32(ForumPostRepository.POSTID, fpids, ',');
                condition = (condition == null ? temp : condition & temp);
            }

            //主题ID
            if (!String.IsNullOrEmpty(ftids))
            {
                temp      = c.InInt32(ForumPostRepository.TOPICID, ftids, ',');
                condition = (condition == null ? temp : condition & temp);
            }

            //用户名
            if (!String.IsNullOrEmpty(userName))
            {
                temp      = c.LikeAll(ForumPostRepository.USERNAME, userName);
                condition = (condition == null ? temp : condition & temp);
            }

            //帖子标题
            if (!String.IsNullOrEmpty(title))
            {
                temp      = c.LikeAll(ForumPostRepository.TITLE, title);
                condition = (condition == null ? temp : condition & temp);
            }

            //帖子内容
            if (!String.IsNullOrEmpty(content))
            {
                temp      = c.LikeAll(ForumPostRepository.CONTENT, content);
                condition = (condition == null ? temp : condition & temp);
            }

            //是否隐藏
            if (isHide.HasValue)
            {
                temp      = c.Equal(ForumPostRepository.ISHIDE, isHide.Value);
                condition = (condition == null ? temp : condition & temp);
            }

            //发布日期范围
            if (startDate.HasValue || endDate.HasValue)
            {
                temp      = c.BetweenNullable <DateTime>(ForumPostRepository.POSTDATE, startDate, endDate);
                condition = (condition == null ? temp : condition & temp);
            }

            //发布IP
            if (!String.IsNullOrEmpty(postip))
            {
                temp      = c.LikeAll(ForumPostRepository.POSTIP, postip);
                condition = (condition == null ? temp : condition & temp);
            }

            return(command.Where(condition));
        }
Beispiel #4
0
        /// <summary>
        /// 设置指定的查询语句并返回当前语句
        /// </summary>
        /// <param name="command">选择语句</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="userName">发帖人</param>
        /// <param name="title">主题标题</param>
        /// <param name="type">主题类型</param>
        /// <param name="relativeID">相关ID</param>
        /// <param name="isLocked">是否锁定</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <returns>当前语句</returns>
        internal static SelectCommand Where(this SelectCommand command, String ftids, String userName, String title, ForumTopicType?type, Int32 relativeID, Boolean?isLocked, Boolean?isHide, DateTime?startDate, DateTime?endDate)
        {
            SqlConditionBuilder  c         = command.ConditionBuilder;
            AbstractSqlCondition condition = command.WhereCondition as AbstractSqlCondition;
            AbstractSqlCondition temp      = null;

            //主题ID
            if (!String.IsNullOrEmpty(ftids))
            {
                temp      = c.InInt32(ForumTopicRepository.TOPICID, ftids, ',');
                condition = (condition == null ? temp : condition & temp);
            }

            //用户名
            if (!String.IsNullOrEmpty(userName))
            {
                temp      = c.LikeAll(ForumTopicRepository.USERNAME, userName);
                condition = (condition == null ? temp : condition & temp);
            }

            //主题标题
            if (!String.IsNullOrEmpty(title))
            {
                temp      = c.LikeAll(ForumTopicRepository.TITLE, title);
                condition = (condition == null ? temp : condition & temp);
            }

            //主题类型
            if (type.HasValue)
            {
                temp      = c.Equal(ForumTopicRepository.TYPE, (Byte)type.Value);
                condition = (condition == null ? temp : condition & temp);
            }

            //相关ID
            if (relativeID >= 0)
            {
                temp      = c.Equal(ForumTopicRepository.RELATIVEID, relativeID);
                condition = (condition == null ? temp : condition & temp);
            }

            //是否锁定
            if (isLocked.HasValue)
            {
                temp      = c.Equal(ForumTopicRepository.ISLOCKED, isLocked.Value);
                condition = (condition == null ? temp : condition & temp);
            }

            //是否隐藏
            if (isHide.HasValue)
            {
                temp      = c.Equal(ForumTopicRepository.ISHIDE, isHide.Value);
                condition = (condition == null ? temp : condition & temp);
            }

            //发布日期范围
            if (startDate.HasValue || endDate.HasValue)
            {
                temp      = c.BetweenNullable <DateTime>(ForumTopicRepository.LASTDATE, startDate, endDate);
                condition = (condition == null ? temp : condition & temp);
            }

            return(command.Where(condition));
        }