Example #1
0
        public static SelectQuery GroupBy(this SelectQuery query, string tableAlias, string field)
        {
            var groupBy = new GroupByColumn(tableAlias, field);

            query.GroupByColumns.Add(groupBy);
            return(query);
        }
Example #2
0
            public GroupBy(
                SqlQuery sqlQuery,
                QuerySource groupQuery,
                QuerySource originalQuery,
                LambdaInfo keySelector,
                QuerySource elementSource,
                Type groupingType,
                bool isWrapped,
                ISqlExpression[] byExpressions)
                : base(sqlQuery, keySelector, groupQuery)
            {
                ParsingTracer.IncIndentLevel();

                OriginalQuery = originalQuery;
                ElementSource = elementSource;
                GroupingType  = groupingType;
                IsWrapped     = isWrapped;
                ByExpressions = byExpressions;

                var field = new GroupByColumn(this);

                Fields.Add(field);

                Members.Add(groupingType.GetProperty("Key"), field);

                ParsingTracer.DecIndentLevel();
            }
Example #3
0
            public override ICloneableElement Clone(Dictionary <ICloneableElement, ICloneableElement> objectTree, Predicate <ICloneableElement> doClone)
            {
                if (!doClone(this))
                {
                    return(this);
                }

                ICloneableElement clone;

                if (!objectTree.TryGetValue(this, out clone))
                {
                    objectTree.Add(this, clone = new GroupByColumn((QuerySource.GroupBy)GroupBySource.Clone(objectTree, doClone)));
                }

                return(clone);
            }
        /// <summary>
        /// Create an OLVGroup for the given information
        /// </summary>
        /// <param name="key"></param>
        /// <param name="count"></param>
        /// <param name="hasCollapsibleGroups"></param>
        /// <returns></returns>
        public OLVGroup CreateGroup(object key, int count, bool hasCollapsibleGroups)
        {
            string title = GroupByColumn.ConvertGroupKeyToTitle(key);

            if (!String.IsNullOrEmpty(TitleFormat))
            {
                string format = (count == 1 ? TitleSingularFormat : TitleFormat);
                try
                {
                    title = String.Format(format, title, count);
                }
                catch (FormatException)
                {
                    title = "Invalid group format: " + format;
                }
            }
            OLVGroup lvg = new OLVGroup(title);

            lvg.Column      = GroupByColumn;
            lvg.Collapsible = hasCollapsibleGroups;
            lvg.Key         = key;
            lvg.SortValue   = key as IComparable;
            return(lvg);
        }
Example #5
0
        /// <summary>
        /// 对单条数据源的,截取列进行处理,以后可以通过方法的形式扩展
        /// 可以在调用出循环数据源调用
        /// </summary>
        /// <param name="dataEntity">需要做处理的对象</param>
        /// <param name="noSumCol">非聚组列的配置信息</param>
        /// <param name="dAccs">属性访问器</param>
        private void substringOneColumn(ref object dataEntity, GroupByColumn noSumCol,
                                        Dictionary <string, MB.Util.Emit.DynamicPropertyAccessor> dAccs)
        {
            if (!_ColProps.ContainsKey(noSumCol.Name))
            {
                throw new MB.Util.APPException(string.Format(
                                                   "汇总列{0}在ColumnPropertyInfo中没有正确配置,或两边的NAME不一致", noSumCol.Name));
            }

            if (!dAccs.Keys.Contains(noSumCol.Name))
            {
                return;
            }

            if (string.IsNullOrEmpty(noSumCol.SubString))
            {
                return;
            }

            var myReflection = MB.Util.MyReflection.Instance;

            if (!string.IsNullOrEmpty(noSumCol.SubString))
            {
                if (_ColProps[noSumCol.Name].DataType.CompareTo("System.String") != 0)
                {
                    throw new MB.Util.APPException(string.Format("截取列NotSummaryColumnInfo:{0}的类型只能是System.String", noSumCol.Name), Util.APPMessageType.DisplayToUser);
                }
            }
            string[] subStringParas = noSumCol.SubString.Split(',');
            if (subStringParas.Length != 2)
            {
                throw new MB.Util.APPException(string.Format("截取列NotSummaryColumnInfo:{0}SubString设置的不正确,正确格式是 [起始位置,长度]", noSumCol.Name), Util.APPMessageType.DisplayToUser);
            }
            int startPosition = 0;
            int subLength     = 0;

            bool hasStartPosition = Int32.TryParse(subStringParas[0], out startPosition);
            bool hasSubLength     = Int32.TryParse(subStringParas[1], out subLength);

            if (hasStartPosition && hasSubLength)
            {
                string orgValue = dAccs[noSumCol.Name].Get(dataEntity) as string;
                if (string.IsNullOrEmpty(orgValue) || orgValue.Length < subLength)
                {
                    return;
                }

                string subValue = string.Empty;
                if (subLength <= 0)
                {
                    subValue = orgValue.Substring(startPosition);
                }
                else
                {
                    subValue = orgValue.Substring(startPosition, subLength);
                }
                dAccs[noSumCol.Name].Set(dataEntity, subValue);
            }
            else
            {
                throw new MB.Util.APPException(string.Format("截取列NotSummaryColumnInfo:{0}SubString设置的不正确,正确格式是 [起始位置,长度]", noSumCol.Name), Util.APPMessageType.DisplayToUser);
            }
        }