コード例 #1
0
        public void AddGroupBy(string columnName)
        {
            GroupByItem groupBy = new GroupByItem {
                Table = "", Name = columnName
            };

            GroupByPart.Add(groupBy);
        }
コード例 #2
0
 public static DataSet getDistinct(DataSet dataSet)
 {
     SelectItem[]  selectItems  = dataSet.getSelectItems();
     GroupByItem[] groupByItems = new GroupByItem[selectItems.Length];
     for (int i = 0; i < groupByItems.Length; i++)
     {
         groupByItems[i] = new GroupByItem(selectItems[i]);
     }
     return(getGrouped(NArrays.AsList(selectItems), dataSet, groupByItems));
 }     // getDistinct()
コード例 #3
0
        /// <summary>
        /// Binds the group by type list
        /// </summary>
        public void BindGroupByObjectTypes()
        {
            var groupByItemTypeObjectType = new GroupByItem {
                Id = GroupByItemType.ObjectType, Description = Resources.GroupByItemTypeObjectType
            };
            var groupByItemTypeCommentType = new GroupByItem {
                Id = GroupByItemType.CommentType, Description = Resources.GroupByItemTypeCommentType
            };
            var groupByItemTypeFlat = new GroupByItem {
                Id = GroupByItemType.Flat, Description = Resources.GroupByItemTypeFlat
            };

            _view.LoadGroupByItems(new[] { groupByItemTypeObjectType, groupByItemTypeCommentType, groupByItemTypeFlat });
        }
コード例 #4
0
        private void CloseGroupByItem(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.OriginalSource is FrameworkElement)
            {
                FrameworkElement element = e.OriginalSource as FrameworkElement;

                if ((element.TemplatedParent != null) && (element.TemplatedParent is GroupByItem))
                {
                    GroupByItem groupByItem = element.TemplatedParent as GroupByItem;

                    if (groupByItem.Content is GroupLevelDescription)
                    {
                        GroupLevelDescription closedGroupDescription = groupByItem.Content as GroupLevelDescription;

                        if (sender is DataGridControl)
                        {
                            DataGridControl grid = sender as DataGridControl;

                            ICollectionView collectionView = DataGridCollectionViewSource.GetDefaultView(grid.ItemsSource);

                            if (collectionView != null)
                            {
                                IEnumerable <DataGridGroupDescription> descriptions = from DataGridGroupDescription groupDescription in collectionView.GroupDescriptions
                                                                                      where groupDescription.PropertyName == closedGroupDescription.FieldName
                                                                                      select groupDescription;

                                if ((descriptions != null) && (descriptions.Count() > 0))
                                {
                                    collectionView.GroupDescriptions.Remove(descriptions.First());
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        private string _buildCount(SqlFilter filter)
        {
            //foreach (string select in filter.Selects)
            //{
            //    SelectMethods[select]();
            //}

            //BuildOrderBy(filter.Orders);

            BuildGroupBy(filter.Groups);

            BuildJoin(filter.Joins);

            string strWhere = "", strFrom = "";


            StringBuilder sql = new StringBuilder();


            sql.Append("select count(*) total");

            if (filter.Limit > 0 && filter.Page == 0)
            {
                sql.Append(" top " + filter.Limit.ToString() + " ");
            }


            //sql.Append(string.Join(",", SelectPart.ToArray()));


            _buildFromAndWhere(filter, out strFrom, out strWhere);


            sql.Append(strFrom).Append(strWhere);


            if (GroupByPart.Count > 0)
            {
                sql.Append(" group by ");

                for (int i = 0; i < GroupByPart.Count; i++)
                {
                    GroupByItem item = GroupByPart[i];

                    if (i > 0)
                    {
                        sql.Append(",");
                    }

                    if (!string.IsNullOrEmpty(item.Table))
                    {
                        sql.Append(item.Table).Append(".").Append(item.Name);
                    }
                    else
                    {
                        sql.Append(item.Name);
                    }
                }
            }


            return(sql.ToString());
        }
コード例 #6
0
        private string _buildHasPage(SqlFilter filter)
        {
            foreach (string select in filter.Selects)
            {
                SelectMethods[select]();
            }

            BuildOrderBy(filter.Orders);

            BuildGroupBy(filter.Groups);

            BuildJoin(filter.Joins);

            string strWhere = "", strFrom = "";


            StringBuilder sql = new StringBuilder();

            sql.Append("select ");


            sql.Append(string.Join(",", SelectPart.ToArray()));


            _buildFromAndWhere(filter, out strFrom, out strWhere);


            sql.Append(strFrom).Append(strWhere);


            if (GroupByPart.Count > 0)
            {
                sql.Append(" group by ");

                for (int i = 0; i < GroupByPart.Count; i++)
                {
                    GroupByItem item = GroupByPart[i];

                    if (i > 0)
                    {
                        sql.Append(",");
                    }

                    if (!string.IsNullOrEmpty(item.Table))
                    {
                        sql.Append(item.Table).Append(".").Append(item.Name);
                    }
                    else
                    {
                        sql.Append(item.Name);
                    }
                }
            }

            if (OrderByPart.Count > 0)
            {
                sql.Append(" order by ");

                for (int i = 0; i < OrderByPart.Count; i++)
                {
                    OrderByItem item = OrderByPart[i];

                    if (i > 0)
                    {
                        sql.Append(",");
                    }

                    switch (item.Type)
                    {
                    case OrderByType.ASC:
                        sql.Append(item.Table).Append(".").Append(item.Name);
                        sql.Append(" asc ");
                        break;

                    case OrderByType.DESC:
                        sql.Append(item.Table).Append(".").Append(item.Name);
                        sql.Append(" desc ");
                        break;

                    case OrderByType.RANDOM:
                        sql.Append(" newid() ");
                        break;
                    }
                }
            }

            if (filter.Page > 0)
            {
                sql.Append(" limit " + filter.PageSize.ToString() + " ");
            }

            sql.Append(" offset ").Append(((filter.Page - 1) * filter.PageSize));

            return(sql.ToString());
        }