Ejemplo n.º 1
0
        /// <summary>
        /// 设置指定的查询语句并返回当前语句
        /// </summary>
        /// <param name="command">选择语句</param>
        /// <param name="type">主题类型</param>
        /// <param name="relativeID">相关ID</param>
        /// <param name="includeHide">是否包含隐藏主题</param>
        /// <returns>当前语句</returns>
        internal static SelectCommand Where(this SelectCommand command, ForumTopicType type, Int32 relativeID, Boolean includeHide)
        {
            SqlConditionBuilder  c         = command.ConditionBuilder;
            AbstractSqlCondition condition = command.WhereCondition as AbstractSqlCondition;
            AbstractSqlCondition temp      = null;

            //不包含隐藏
            if (!includeHide)
            {
                temp      = c.Equal(ForumTopicRepository.ISHIDE, false);
                condition = (condition == null ? temp : condition & temp);
            }

            if (type == ForumTopicType.Default)                                                  //普通讨论板中包括题目专属讨论板的帖子
            {
                temp      = c.LessThan(ForumTopicRepository.TYPE, (Byte)ForumTopicType.Contest); //普通0,题目1,竞赛2
                condition = (condition == null ? temp : condition & temp);
            }
            else//竞赛或题目专属讨论板只有专属帖子
            {
                temp      = c.Equal(ForumTopicRepository.TYPE, (Byte)type) & c.Equal(ForumTopicRepository.RELATIVEID, relativeID);
                condition = (condition == null ? temp : condition & temp);
            }

            return(command.Where(condition));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 设置指定的查询语句并返回当前语句
        /// </summary>
        /// <param name="command">选择语句</param>
        /// <param name="topics">主题列表</param>
        /// <param name="includeHide">是否包含隐藏主题</param>
        /// <returns>当前语句</returns>
        internal static SelectCommand Where(this SelectCommand command, IList <ForumTopicEntity> topics, Boolean includeHide)
        {
            SqlConditionBuilder  c         = command.ConditionBuilder;
            AbstractSqlCondition condition = command.WhereCondition as AbstractSqlCondition;
            AbstractSqlCondition temp      = null;

            if (!includeHide)
            {
                temp      = c.Equal(ForumPostRepository.ISHIDE, false);
                condition = (condition == null ? temp : condition & temp);
            }

            if (topics != null)
            {
                temp = c.In <Int32>(ForumPostRepository.TOPICID, () =>
                {
                    List <Int32> ids = new List <Int32>();

                    for (Int32 i = 0; i < topics.Count; i++)
                    {
                        ids.Add(topics[i].TopicID);
                    }

                    return(ids);
                });

                condition = (condition == null ? temp : condition & temp);
            }

            return(command.Where(condition));
        }
Ejemplo n.º 3
0
        private static AbstractSqlCondition ParseBetweenCallExpression(AbstractSqlCommandWithWhere sourceCommand, MethodCallExpression expr, Boolean isNot)
        {
            MemberExpression        left       = ExpressionHelper.GetMemberExpression(expr.Arguments[0]);
            DatabaseColumnAttribute columnAttr = ExpressionHelper.GetColumnAttributeWithDataType(sourceCommand, left);
            Object start = ExpressionHelper.GetExpressionValue(expr.Arguments[1]) as Object;
            Object end   = ExpressionHelper.GetExpressionValue(expr.Arguments[2]) as Object;

            if (columnAttr == null)
            {
                throw new NullAttributeException();
            }

            AbstractSqlCondition condition = null;

            if (isNot)
            {
                condition = sourceCommand.ConditionBuilder.NotBetweenNullable(columnAttr.ColumnName, columnAttr.DataType.Value, start, end);
            }
            else
            {
                condition = sourceCommand.ConditionBuilder.BetweenNullable(columnAttr.ColumnName, columnAttr.DataType.Value, start, end);
            }

            return(condition);
        }
Ejemplo n.º 4
0
        public void CreateNullableConditionTest()
        {
            AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;

            SelectCommand       baseCommand      = fakeDb.CreateSelectCommand("");
            SqlConditionBuilder conditionBuilder = baseCommand.ConditionBuilder;

            AbstractSqlCondition baseCondition = conditionBuilder.Equal("TestColumn2", 1);

            AbstractSqlCondition expectedCondition = baseCondition & null;
            AbstractSqlCondition actualCondition   = baseCondition;

            Assert.AreEqual(expectedCondition, actualCondition);

            AbstractSqlCondition expectedCondition2 = null & baseCondition;
            AbstractSqlCondition actualCondition2   = baseCondition;

            Assert.AreEqual(expectedCondition2, actualCondition2);

            AbstractSqlCondition expectedCondition3 = baseCondition | null;
            AbstractSqlCondition actualCondition3   = baseCondition;

            Assert.AreEqual(expectedCondition3, actualCondition3);

            AbstractSqlCondition expectedCondition4 = null | baseCondition;
            AbstractSqlCondition actualCondition4   = baseCondition;

            Assert.AreEqual(expectedCondition4, actualCondition4);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取最早提交等待评测的一个实体
        /// </summary>
        /// <param name="count">获取个数</param>
        /// <param name="getErrorTime">获取异常提交时间</param>
        /// <param name="languageSupport">支持语言</param>
        /// <returns>对象实体</returns>
        public List <SolutionEntity> GetPendingEntities(Int32 count, Int32 getErrorTime, LanguageType[] languageSupport)
        {
            return(this.UsingTransaction <List <SolutionEntity> >(trans =>
            {
                List <SolutionEntity> list = this.Select()
                                             .Top(count)
                                             .Querys(SOLUTIONID, PROBLEMID, USERNAME, SOURCECODE, LANGUAGE, CODELENGTH, SUBMITTIME)
                                             .Where(c =>
                {
                    AbstractSqlCondition condition = c.LessThanOrEqual(RESULT, (Byte)ResultType.RejudgePending);
                    AbstractSqlCondition temp = null;

                    if (getErrorTime > 0)
                    {
                        temp = c.Equal(RESULT, (Byte)ResultType.Judging) & c.LessThanOrEqual(JUDGETIME, DateTime.Now.AddSeconds(-getErrorTime));
                        condition = (condition == null ? temp : condition | temp);
                    }

                    if (languageSupport.Length > 0 & languageSupport.Length < LanguageManager.LanguageSupportedCount)    //没有和全部时不设定条件
                    {
                        temp = c.In(LANGUAGE, () =>
                        {
                            Byte[] langIds = new Byte[languageSupport.Length];

                            for (Int32 i = 0; i < langIds.Length; i++)
                            {
                                langIds[i] = languageSupport[i].ID;
                            }

                            return langIds;
                        });
                        condition = (condition == null ? temp : condition & temp);
                    }

                    return condition;
                })
                                             .OrderByAsc(SOLUTIONID)
                                             .ToEntityList(this, trans);

                //提交获取到的题目状态为Juding且评测时间为当前
                if (list != null && list.Count > 0)
                {
                    Int32 updated = 0;

                    for (Int32 i = 0; i < list.Count; i++)
                    {
                        updated += this.InternalGetUpdateSolutionResultCommand(list[i].SolutionID, ResultType.Judging, DateTime.Now)
                                   .Result(trans);
                    }
                }

                trans.Commit();

                return list;
            }));
        }
Ejemplo n.º 7
0
        private static AbstractSqlCondition ParseInTheseCallExpression(AbstractSqlCommandWithWhere sourceCommand, MethodCallExpression expr, Boolean isNot)
        {
            MemberExpression        left       = ExpressionHelper.GetMemberExpression(expr.Arguments[0]);
            DatabaseColumnAttribute columnAttr = ExpressionHelper.GetColumnAttributeWithDataType(sourceCommand, left);
            Array array = ExpressionHelper.GetExpressionValue(expr.Arguments[1]) as Array;

            if (columnAttr == null)
            {
                throw new NullAttributeException();
            }

            AbstractSqlCondition condition = SqlInsideParametersCondition.InternalCreate(sourceCommand, columnAttr.ColumnName, isNot, columnAttr.DataType.Value, array);

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

            SqlConditionBuilder expectedConditionBuilder = expectedCommand.ConditionBuilder;

            AbstractSqlCondition expectedCondition = expectedConditionBuilder.GreaterThanOrEqual("TestColumn2", 123) & expectedConditionBuilder.LessThan("TestColumn2", 456);
            AbstractSqlCondition actualCondition   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2 >= 123 && c.Test2 < 456) as SqlConditionList;

            Assert.AreEqual(expectedCondition, actualCondition);

            AbstractSqlCondition expectedCondition2 = expectedConditionBuilder.GreaterThanOrEqual("TestColumn2", 123) | (expectedConditionBuilder.GreaterThan("TestColumn4", DateTime.Now) & expectedConditionBuilder.LessThan("TestColumn7", DateTime.Now.AddDays(7)));
            AbstractSqlCondition actualCondition2   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2 >= 123 || (c.Test4 > DateTime.Now && c.Test7 < DateTime.Now.AddDays(7))) as SqlConditionList;

            Assert.AreEqual(expectedCondition2, actualCondition2);
        }
Ejemplo n.º 9
0
        private static AbstractSqlCondition ParseInCallExpression(AbstractSqlCommandWithWhere sourceCommand, MethodCallExpression expr, Boolean isNot)
        {
            MemberExpression        left       = ExpressionHelper.GetMemberExpression(expr.Arguments[0]);
            DatabaseColumnAttribute columnAttr = ExpressionHelper.GetColumnAttributeWithDataType(sourceCommand, left);
            Action <SelectCommand>  action     = ExpressionHelper.GetExpressionValue(expr.Arguments[1]) as Action <SelectCommand>;

            if (columnAttr == null)
            {
                throw new NullAttributeException();
            }

            Type   entityType       = expr.Method.GetGenericArguments()[0];
            String anotherTableName = EntityHelper.InternalGetTableName(entityType);

            AbstractSqlCondition condition = SqlInsideCommandCondition.InternalCreate(sourceCommand, columnAttr.ColumnName, isNot, anotherTableName, action);

            return(condition);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 设置指定的查询语句并返回当前语句
        /// </summary>
        /// <param name="command">相关语句</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="userName">用户名</param>
        /// <param name="languageType">提交语言</param>
        /// <param name="resultType">提交结果</param>
        /// <returns>当前语句</returns>
        internal static SelectCommand Where(this SelectCommand command, Int32 cid, Int32 pid, String userName, LanguageType languageType, ResultType?resultType)
        {
            SqlConditionBuilder  c         = command.ConditionBuilder;
            AbstractSqlCondition condition = command.WhereCondition as AbstractSqlCondition;
            AbstractSqlCondition temp      = null;

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

            //题目ID,如果为竞赛从竞赛题目顺序查找,否则从题目ID查找
            if (pid >= 0)
            {
                temp      = c.Equal((cid >= 0 ? SolutionRepository.CONTESTPROBLEMID : 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);
            }

            return(command.Where(condition));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 根据用户名和小于提交结果获取题目ID列表
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="contestID">竞赛ID</param>
        /// <param name="resultType">提交结果</param>
        /// <returns>题目ID列表</returns>
        public List <Int32> GetEntityIDsByUserAndLessResultType(String userName, Int32 contestID, ResultType resultType)
        {
            String problemIDColumn = (contestID < 0 ? PROBLEMID : CONTESTPROBLEMID);

            return(this.Select()
                   .Query(problemIDColumn)
                   .Distinct()
                   .Where(c =>
            {
                AbstractSqlCondition condition = c.Equal(USERNAME, userName) & c.LessThan(RESULT, (Byte)resultType);

                if (contestID >= 0)
                {
                    condition = condition & c.Equal(CONTESTID, contestID);
                }

                return condition;
            })
                   .OrderByAsc(problemIDColumn)
                   .ToDataTable()
                   .EachToList <Int32>((list, args) => list.Add((Int32)args.Row[problemIDColumn])));
        }
Ejemplo n.º 12
0
        private static AbstractSqlCondition ParseNullExpression(AbstractSqlCommandWithWhere sourceCommand, MethodCallExpression expr, Boolean isNot)
        {
            MemberExpression        left       = ExpressionHelper.GetMemberExpression(expr.Arguments[0]);
            DatabaseColumnAttribute columnAttr = ExpressionHelper.GetColumnAttributeWithDataType(sourceCommand, left);

            if (columnAttr == null)
            {
                throw new NullAttributeException();
            }

            AbstractSqlCondition condition = null;

            if (isNot)
            {
                condition = sourceCommand.ConditionBuilder.IsNotNull(columnAttr.ColumnName);
            }
            else
            {
                condition = sourceCommand.ConditionBuilder.IsNull(columnAttr.ColumnName);
            }

            return(condition);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 获取提交统计信息
        /// </summary>
        /// <param name="dtStart">开始日期</param>
        /// <param name="dtEnd">结束日期</param>
        /// <param name="acceptedOnly">是否仅有AC题目</param>
        /// <returns>提交统计信息</returns>
        public IDictionary <Int32, Int32> GetSubmitStatus(DateTime dtStart, DateTime dtEnd, Boolean acceptedOnly)
        {
            //SELECT COUNT(*) AS SOLU_COUNT, #DatePart(SOLU_SUBMITTIME)# AS SOLU_SUBMITDATE
            //FROM SDNUOJ_SOLUTION
            //WHERE CONDITION
            //GROUP BY #DatePart(SOLU_SUBMITTIME)#

            SortedDictionary <Int32, Int32> submits = new SortedDictionary <Int32, Int32>();

            return(this.Select()
                   .Query(SqlAggregateFunction.Count, SOLUTIONID, "SOLU_COUNT")
                   .Query(this.Functions.DatePart(SUBMITTIME, SqlDatePartType.DayOfMonth), "SOLU_SUBMITDATE")
                   .Where(c =>
            {
                AbstractSqlCondition condition = c.Between(SUBMITTIME, dtStart, dtEnd);

                if (acceptedOnly)
                {
                    condition = condition & c.Equal(RESULT, (Byte)ResultType.Accepted);
                }

                return condition;
            })
                   .GroupBy(this.Functions.DatePart(SUBMITTIME, SqlDatePartType.DayOfMonth))
                   .ToDataTable()
                   .Each(args =>
            {
                if (!DbConvert.IsDBNull(args.Row["SOLU_SUBMITDATE"]))
                {
                    Int32 dayOfMonth = this.LoadInt32(args, "SOLU_SUBMITDATE");
                    Int32 count = this.LoadInt32(args, "SOLU_COUNT");

                    submits[dayOfMonth] = count;
                }
            })
                   .Done(submits));
        }
Ejemplo n.º 14
0
        private static AbstractSqlCondition ParseLikeCallExpression(AbstractSqlCommandWithWhere sourceCommand, MethodCallExpression expr, String format, Boolean isNot)
        {
            MemberExpression        left       = ExpressionHelper.GetMemberExpression(expr.Arguments[0]);
            DatabaseColumnAttribute columnAttr = ExpressionHelper.GetColumnAttributeWithDataType(sourceCommand, left);
            String value = ExpressionHelper.GetExpressionValue(expr.Arguments[1]) as String;

            if (columnAttr == null)
            {
                throw new NullAttributeException();
            }

            AbstractSqlCondition condition = null;

            if (isNot)
            {
                condition = sourceCommand.ConditionBuilder.NotLike(columnAttr.ColumnName, columnAttr.DataType.Value, String.Format(format, value));;
            }
            else
            {
                condition = sourceCommand.ConditionBuilder.Like(columnAttr.ColumnName, columnAttr.DataType.Value, String.Format(format, value));;
            }

            return(condition);
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
0
        /// <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));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 设置指定的查询语句并返回当前语句
        /// </summary>
        /// <param name="command">选择语句</param>
        /// <param name="names">用户名包含</param>
        /// <param name="nickname">昵称包含</param>
        /// <param name="email">邮箱包含</param>
        /// <param name="school">学校包含</param>
        /// <param name="lastIP">最后登录IP</param>
        /// <param name="islocked">是否锁定</param>
        /// <param name="regStartDate">注册日期开始</param>
        /// <param name="regEndDate">注册日期结束</param>
        /// <param name="loginStartDate">最后登录日期开始</param>
        /// <param name="loginEndDate">最后登录日期结束</param>
        /// <returns>当前语句</returns>
        internal static SelectCommand Where(this SelectCommand command, String names, String nickname, String email, String school, String lastIP, Boolean?islocked, DateTime?regStartDate, DateTime?regEndDate, DateTime?loginStartDate, DateTime?loginEndDate)
        {
            SqlConditionBuilder  c         = command.ConditionBuilder;
            AbstractSqlCondition condition = command.WhereCondition as AbstractSqlCondition;
            AbstractSqlCondition temp      = null;

            //用户名列表模糊
            if (!String.IsNullOrEmpty(names))
            {
                String[]             arrnames  = names.Split(',');
                AbstractSqlCondition innertemp = null;
                temp = null;

                for (Int32 i = 0; i < arrnames.Length; i++)
                {
                    if (!String.IsNullOrEmpty(arrnames[i]))
                    {
                        innertemp = c.LikeAll(UserRepository.USERNAME, arrnames[i]);
                        temp      = (temp == null ? innertemp : innertemp | temp);
                    }
                }

                condition = (condition == null ? temp : condition & temp);
            }

            //昵称模糊
            if (!String.IsNullOrEmpty(nickname))
            {
                temp      = c.LikeAll(UserRepository.NICKNAME, nickname);
                condition = (condition == null ? temp : condition & temp);
            }

            //邮箱模糊
            if (!String.IsNullOrEmpty(email))
            {
                temp      = c.LikeAll(UserRepository.EMAIL, email);
                condition = (condition == null ? temp : condition & temp);
            }

            //学校模糊
            if (!String.IsNullOrEmpty(school))
            {
                temp      = c.LikeAll(UserRepository.SCHOOL, school);
                condition = (condition == null ? temp : condition & temp);
            }

            //最后登录IP模糊
            if (!String.IsNullOrEmpty(lastIP))
            {
                temp      = c.LikeAll(UserRepository.LASTIP, lastIP);
                condition = (condition == null ? temp : condition & temp);
            }

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

            //注册日期范围
            if (regStartDate.HasValue || regEndDate.HasValue)
            {
                temp      = c.BetweenNullable <DateTime>(UserRepository.CREATEDATE, regStartDate, regEndDate);
                condition = (condition == null ? temp : condition & temp);
            }

            //登陆日期范围
            if (loginStartDate.HasValue || loginEndDate.HasValue)
            {
                temp      = c.BetweenNullable <DateTime>(UserRepository.LASTDATE, loginStartDate, loginEndDate);
                condition = (condition == null ? temp : condition & temp);
            }

            return(command.Where(condition));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 获取题目统计信息
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <returns>题目统计信息实体</returns>
        public ProblemStatistic GetProblemStatistic(Int32 cid, Int32 pid)
        {
            return(this.UsingConnection <ProblemStatistic>(conn =>
            {
                ProblemStatistic entity = new ProblemStatistic();
                entity.ProblemID = pid;
                entity.SolvedCount = this.Select("T1", from =>
                {
                    from.Querys(USERNAME)
                    .Distinct()
                    .Where(c =>
                    {
                        AbstractSqlCondition condition = c.Equal((cid > 0 ? CONTESTPROBLEMID : PROBLEMID), pid) & c.Equal(RESULT, (Byte)ResultType.Accepted);

                        if (cid >= 0)        //竞赛ID,非竞赛为0
                        {
                            condition = condition & c.Equal(CONTESTID, cid);
                        }

                        return condition;
                    });
                })
                                     .Count(conn);//计算AC的用户数

                return this.Select()
                .Query(SqlAggregateFunction.Count, SOLUTIONID, "SOLU_COUNT")
                .Query(RESULT)
                .Where(c =>
                {
                    AbstractSqlCondition condition = c.Equal((cid >= 0 ? CONTESTPROBLEMID : PROBLEMID), pid);

                    if (cid >= 0)    //竞赛ID,非竞赛为0
                    {
                        condition = condition & c.Equal(CONTESTID, cid);
                    }

                    return condition;
                })
                .GroupBy(RESULT)
                .ToDataTable(conn)
                .Each(args =>
                {
                    Int32 count = this.LoadInt32(args, "SOLU_COUNT");
                    ResultType type = (ResultType)this.LoadByte(args, RESULT);

                    entity.SubmitCount += count;

                    switch (type)
                    {
                    case ResultType.Pending: entity.PendingCount = count; break;

                    case ResultType.RejudgePending: entity.RejudgePendingCount = count; break;

                    case ResultType.Judging: entity.JudgingCount = count; break;

                    case ResultType.CompileError: entity.CompileErrorCount = count; break;

                    case ResultType.RuntimeError: entity.RuntimeErrorCount = count; break;

                    case ResultType.TimeLimitExceeded: entity.TimeLimitExceededCount = count; break;

                    case ResultType.MemoryLimitExceeded: entity.MemoryLimitExceededCount = count; break;

                    case ResultType.OutputLimitExceeded: entity.OutputLimitExceededCount = count; break;

                    case ResultType.WrongAnswer: entity.WrongAnswerCount = count; break;

                    case ResultType.PresentationError: entity.PresentationErrorCount = count; break;

                    case ResultType.Accepted: entity.AcceptedCount = count; break;
                    }
                })
                .Done(entity);
            }));
        }