示例#1
0
        static void SetHalfhoursColumnsForXamDataGrid(XamDataGrid dataGrid, DataTableEx userTable,
                                                      enumTimeDiscreteType discreteType, enumTypeInformation typeInformation, string format, bool isCumulateDrums
                                                      , bool isDateTimeGroupingGridControlXam, bool useBindedConverter)
        {
            //var nameStyle = dataGrid.FindResource("TIChanelName") as Style;

            ////Style labelStyle = null;

            try
            {
                var labelStyle = dataGrid.FindResource("LabelObjectStyle") as Style;
                dataGrid.FieldSettings.LabelPresenterStyle = labelStyle;
            }
            catch
            {
            }

            //var vTemplate = dataGrid.FindResource("FValueTemplate") as DataTemplate;
            var fValueNoBindMeasureStyle = dataGrid.FindResource("FValueNoBindMeasureStyle") as Style;

            var vFreeHierarchyObjectTemplate = Application.Current.FindResource("FreeHierarchyObjectTemlate") as DataTemplate;
            var fValueStyle = useBindedConverter ?  dataGrid.FindResource("FValueStyle") as Style : fValueNoBindMeasureStyle;

            var widthValue    = new FieldLength(105);
            var widthFreeHier = new FieldLength(270);

            var comparer = new IFValueComparer();

            var measure = dataGrid.FindParent <IMeasure>();

            dataGrid.Resources["IMeasure"] = measure;

            //var fConverter = new FValueConverter
            //{
            //    FParameter = new FValueParameter
            //    {
            //        Measure = measure,
            //    }
            //};

            var fieldLayout = dataGrid.FieldLayouts[0];
            var fields      = fieldLayout.Fields;

            try
            {
                fields.BeginUpdate();
                //fieldLayout.SortedFields.BeginUpdate();

                var dtCol = userTable.Columns["EventDateTime"];

                var dtField = new TemplateField
                {
                    Name          = dtCol.ColumnName,
                    DataType      = dtCol.DataType,
                    Label         = dtCol.Caption,
                    Width         = new FieldLength(95),
                    AllowFixing   = AllowFieldFixing.Default,
                    FixedLocation = FixedFieldLocation.FixedToNearEdge,
                    Settings      =
                    {
                        LabelPresenterStyle = dataGrid.FindResource("TimeStyle") as Style
                    }
                };

                fields.Add(dtField);

                if (isCumulateDrums)
                {
                    //dtField.Settings.CellValuePresenterStyle =
                    //    XamDataGridHelper.DataTemplateToCellValuePresenterStyle(ConstantHelper.DateTimeTemplateName);
                    dtField.DisplayTemplate = Application.Current.Resources[ConstantHelper.DateTimeTemplateName] as DataTemplate;
                }
                else
                {
                    string dataTemplateToCellValuePresenterStyleName;
                    //-------------------------------
                    switch (discreteType)
                    {
                    case enumTimeDiscreteType.DBHalfHours:
                        dataTemplateToCellValuePresenterStyleName = ConstantHelper.HalfHourstoRangeTimeTemplateName;
                        break;

                    case enumTimeDiscreteType.DBHours:
                        dataTemplateToCellValuePresenterStyleName = ConstantHelper.HourstoRangeTimeTemplateName;
                        break;

                    case enumTimeDiscreteType.DB24Hour:
                        dataTemplateToCellValuePresenterStyleName = ConstantHelper.DateTemplateName;
                        break;

                    case enumTimeDiscreteType.DBMonth:
                        dataTemplateToCellValuePresenterStyleName = ConstantHelper.MonthName;
                        break;

                    default:
                        dataTemplateToCellValuePresenterStyleName = ConstantHelper.DateTimeTemplateName;
                        break;
                    }

                    dtField.Tag             = dataTemplateToCellValuePresenterStyleName; //Это нужно для форматирования при выгрузке в Excel
                    dtField.DisplayTemplate = Application.Current.Resources[dataTemplateToCellValuePresenterStyleName] as DataTemplate;

                    //dtField.Settings.CellValuePresenterStyle =
                    //    XamDataGridHelper.DataTemplateToCellValuePresenterStyle(
                    //        dataTemplateToCellValuePresenterStyleName);
                }

                dtField.Label = "Время";

                if (discreteType == enumTimeDiscreteType.DB24Hour)
                {
                    dtField.Settings.GroupByMode = FieldGroupByMode.Month;
                    dtField.Settings.GroupByRecordPresenterStyle =
                        Application.Current.FindResource("MonthYearXamDataGridStyle") as Style;
                }
                else
                {
                    dtField.Settings.GroupByMode = FieldGroupByMode.Date;
                }


                SummaryCalculator statType;
                string            prefix;
                if (typeInformation == enumTypeInformation.Power)
                {
                    statType = new FValueAvgCalculator(format);
                    prefix   = "Сред:";
                }
                else
                {
                    statType = new FValueSumCalculator(format);
                    prefix   = "Сум:";
                }

                var stringFormat = prefix + " {0:" + format + "}";

                var dfc = new DetailFieldInfoEqualityComparer();

                //FieldGroup fieldGroupByObject = null;
                //FieldGroup fieldGroupByMeasureCategory = null;
                //EnumMeasureUnitCategory? previousMeasureCategory = null; //Для определения групповать или нет по категории

                foreach (var colGroupByObject in userTable.Columns
                         .Cast <DataColumn>()
                         .Where(c => c.ColumnName != "EventDateTime")
                         .Select(c =>
                {
                    DetailFieldInfo fieldInfo;
                    userTable.TryGetIndexByItemName(c.ColumnName, out fieldInfo);

                    return(new Tuple <DetailFieldInfo, DataColumn>(fieldInfo, c));
                })
                         .GroupBy(c => c.Item1, dfc))
                {
                    if (colGroupByObject.Key == null || (colGroupByObject.Key.ChannelType == 0 && colGroupByObject.Key.ColumnType == EnumColumnType.None))
                    {
                        //Группировать не нужно
                        foreach (var colByObject in colGroupByObject)
                        {
                            DetailFieldInfo fieldInfo;
                            userTable.ItemsIndexesDict.TryGetValue(colByObject.Item2.ColumnName, out fieldInfo);

                            SummaryDefinition summaryDefinition;
                            var fld = AddFieldAndSummary(colByObject.Item2, widthValue, comparer, fieldInfo != null && fieldInfo.UseMeasureModule,
                                                         isCumulateDrums, statType, stringFormat, out summaryDefinition, fValueStyle);

                            fld.Label = fieldInfo == null ? colByObject.Item2.Caption : (object)colByObject.Item1;
                            fields.Add(fld);
                            if (summaryDefinition != null)
                            {
                                fieldLayout.SummaryDefinitions.Add(summaryDefinition);
                            }
                        }
                    }
                    //else if ()
                    //{
                    //    //Группируем по типу
                    //    foreach (var colByObjectByColumnType in colGroupByObject.GroupBy(c => c.Item1.ColumnType))
                    //    {
                    //        foreach (var colByObject in colByObjectByColumnType)
                    //        {
                    //            DetailFieldInfo fieldInfo;
                    //            if (!userTable.ItemsIndexesDict.TryGetValue(colByObject.Item2.ColumnName, out fieldInfo)) continue;

                    //            FValueSummaryDefinition summaryDefinition;
                    //            var fld = AddFieldAndSummary(colByObject.Item2, widthValue, comparer, fieldInfo != null && fieldInfo.UseMeasureModule,
                    //                isCumulateDrums, statType, stringFormat, out summaryDefinition, fValueStyle);

                    //            fld.Label = fieldInfo == null ? colByObject.Item2.Caption : (object)colByObject.Item1;
                    //            fields.Add(fld);
                    //            if (summaryDefinition != null)
                    //            {
                    //                fieldLayout.SummaryDefinitions.Add(summaryDefinition);
                    //            }
                    //        }
                    //    }
                    //}
                    else
                    {
                        var fieldInfo          = colGroupByObject.Key;
                        var fieldGroupByObject = new FieldGroup
                        {
                            Label = fieldInfo.Id,
                        };

                        fieldLayout.FieldItems.Add(fieldGroupByObject);

                        //Группируем по ед.измерения
                        foreach (var colGroupByMeasureCategory in colGroupByObject.GroupBy(c => c.Item1.MeasureUnitUn.SubstringQuantityUn()))
                        {
                            var colGroupByMeasureCategoryList = colGroupByMeasureCategory.ToList();

                            if (!string.IsNullOrEmpty(colGroupByMeasureCategory.Key) && colGroupByMeasureCategoryList.Count > 1)
                            {
                                //Есть категории ед. измерения и их несколько
                                var fieldGroupByMeasureCategory = new FieldGroup
                                {
                                    Label = new LabelMeasureQuantity
                                    {
                                        MeasureQuantityType_UN = colGroupByMeasureCategory.Key,
                                    },
                                };

                                fieldGroupByObject.Children.Add(fieldGroupByMeasureCategory);

                                foreach (var colByMeasure in colGroupByMeasureCategoryList)
                                {
                                    SummaryDefinition summaryDefinition;
                                    var fld = AddFieldAndSummary(colByMeasure.Item2, widthValue, comparer, fieldInfo.UseMeasureModule,
                                                                 isCumulateDrums, statType, stringFormat, out summaryDefinition, fValueStyle);

                                    fld.Label = colByMeasure.Item1;
                                    fieldGroupByMeasureCategory.Children.Add(fld);
                                    if (summaryDefinition != null)
                                    {
                                        fieldLayout.SummaryDefinitions.Add(summaryDefinition);
                                    }
                                }
                            }
                            else
                            {
                                var fielgGroupByReplacedTiDict = new Dictionary <string, FieldGroup>();

                                //Нет категорий, или она одна
                                foreach (var colByMeasure in colGroupByMeasureCategoryList)
                                {
                                    if (colByMeasure.Item2.ColumnName.StartsWith("ovInfo"))
                                    {
                                        var hoc = new HierObjectsConverterComparer();

                                        //var fld = AddField(colByMeasure.Item2, widthFreeHier, hoc, fieldInfo.UseMeasureModule,
                                        //    vFreeHierarchyObjectTemplate,
                                        //    vFreeHierarchyObjectTemplate, new HierObjectsConverter(), null);

                                        var fld = new TemplateField
                                        {
                                            Name            = colByMeasure.Item2.ColumnName,
                                            DataType        = colByMeasure.Item2.DataType,
                                            Width           = widthFreeHier,
                                            AllowFixing     = AllowFieldFixing.No,
                                            DisplayTemplate = vFreeHierarchyObjectTemplate,
                                            Settings        =
                                            {
                                                AutoSizeOptions      = FieldAutoSizeOptions.None,
                                                Width                = widthFreeHier,
                                                SummaryUIType        = SummaryUIType.MultiSelect,
                                                FilterComparer       = hoc,
                                                FilterOperandUIType  = FilterOperandUIType.Combo,
                                                AllowRecordFiltering = true,
                                            },
                                            HorizontalContentAlignment = HorizontalAlignment.Stretch,
                                            VerticalContentAlignment   = VerticalAlignment.Stretch,
                                        };

                                        fld.Label = "Замещаемые ТИ";
                                        fld.Settings.FilterOperandUIType         = FilterOperandUIType.DropDownList;
                                        fld.Settings.FilterLabelIconDropDownType = FilterLabelIconDropDownType.MultiSelectExcelStyle;
                                        fld.Settings.GroupByComparer             = hoc;

                                        //fld.ValueToTextConverter = new HierObjectsConverter();
                                        fld.Settings.FilterComparer = new HierObjectsConverterComparer();
                                        fieldGroupByObject.Children.Add(fld);
                                    }
                                    else
                                    {
                                        FieldGroup fielgGroupByReplacedTi = null;

                                        //Группируем по замещаемой ТИ
                                        if (colByMeasure.Item2.ColumnName.StartsWith("ovValue") &&
                                            !fielgGroupByReplacedTiDict.TryGetValue(
                                                colByMeasure.Item1.GroupByReplacedTiName, out fielgGroupByReplacedTi))
                                        {
                                            fielgGroupByReplacedTi = new FieldGroup
                                            {
                                                Label = colByMeasure.Item1.ReplacedId,
                                            };

                                            fielgGroupByReplacedTiDict[colByMeasure.Item1.GroupByReplacedTiName] =
                                                fielgGroupByReplacedTi;
                                        }

                                        SummaryDefinition summaryDefinition;
                                        Field             fld;

                                        if (!string.IsNullOrEmpty(colByMeasure.Item1.MeasureUnitUn) && colByMeasure.Item1.MeasureUnitUn.IndexOf("RatioUnit") > -1)
                                        {
                                            //Это %, нужно усреднять
                                            fld = AddFieldAndSummary(colByMeasure.Item2, widthValue, comparer, colByMeasure.Item1.UseMeasureModule,
                                                                     isCumulateDrums, new FValueAvgCalculator(format), "Сред: {0:" + format + "}", out summaryDefinition, fValueNoBindMeasureStyle);
                                        }
                                        else
                                        {
                                            fld = AddFieldAndSummary(colByMeasure.Item2, widthValue, comparer, useBindedConverter && colByMeasure.Item1.UseMeasureModule,
                                                                     isCumulateDrums, statType, stringFormat, out summaryDefinition, fValueStyle);
                                        }

                                        fld.Label = colByMeasure.Item1;

                                        if (fielgGroupByReplacedTi != null)
                                        {
                                            fielgGroupByReplacedTi.Children.Add(fld);
                                        }
                                        else
                                        {
                                            fieldGroupByObject.Children.Add(fld);
                                        }

                                        if (summaryDefinition != null)
                                        {
                                            fieldLayout.SummaryDefinitions.Add(summaryDefinition);
                                        }

                                        if (colByMeasure.Item1.IsOv)
                                        {
                                            //Если это ОВ, добавляем суммарную информацию о неразнесенных значениях
                                            var unWritedOvs = new FValueSummaryDefinition
                                            {
                                                SourceFieldName  = colByMeasure.Item2.ColumnName,
                                                Calculator       = new FValueSumUnreplacedCalculator(format),
                                                StringFormat     = stringFormat,
                                                UseMeasureModule = fieldInfo.UseMeasureModule,
                                            };

                                            fieldLayout.SummaryDefinitions.Add(unWritedOvs);
                                        }
                                    }
                                }

                                if (fielgGroupByReplacedTiDict.Count > 0)
                                {
                                    fieldGroupByObject.Children.AddRange(fielgGroupByReplacedTiDict.Values);
                                }
                            }
                        }
                    }
                }

                if (isDateTimeGroupingGridControlXam)
                {
                    //dtField.Settings.AllowSummaries = false;
                    dtField.Settings.AllowGroupBy = true;


                    fieldLayout.SortedFields.Add(new FieldSortDescription("EventDateTime", ListSortDirection.Ascending,
                                                                          true));
                }
                else if (discreteType != enumTimeDiscreteType.DBMonth && discreteType != enumTimeDiscreteType.DB24Hour)
                {
                    dtField.DisplayTemplate = Application.Current.Resources[ConstantHelper.DateTimeTemplateName] as DataTemplate;
                }

                //var consumptionScheduleField = fields.FirstOrDefault(ff => ff.Name == "ConsumptionSchedule");
                //if (consumptionScheduleField != null)
                //{
                //    consumptionScheduleField.Label = "Тип. потр.";
                //}

                //var consumptionSchedulePercentField = fields.FirstOrDefault(ff => ff.Name == "ConsumptionSchedulePercent");
                //if (consumptionSchedulePercentField != null)
                //{
                //    consumptionSchedulePercentField.Label = "Тип. потр. %";
                //}
            }
            finally
            {
                // fieldLayout.SortedFields.EndUpdate();
                fields.EndUpdate();
            }

            //XamDataGridHelper.ConfigureGrid(dataGrid, true, false, true, true, true);
            dataGrid.FieldLayoutSettings.FixedFieldUIType = FixedFieldUIType.Splitter;

            dataGrid.FieldSettings.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;

            if (userTable.Columns.Count < 20)
            {
                //из-за того что тормоза ограничиваем
                //dataGrid.FieldSettings.SummaryDisplayArea = dataGrid.FieldSettings.SummaryDisplayArea | SummaryDisplayAreas.InGroupByRecords;
            }

            if (userTable.Columns.Count < 1000)
            {
                dataGrid.RecordsInViewChanged += ExpandFirstRecord;
            }
        }
        static void SetHalfhoursColumnsForXamDataGrid(XamGrid dataGrid, DataTableEx userTable,
                                                      enumTimeDiscreteType discreteType, enumTypeInformation typeInformation, string format, bool isCumulateDrums, bool isDateTimeGroupingGridControlXam)
        {
            //var nameStyle = dataGrid.FindResource("TIChanelName") as Style;

            Style labelStyle = null;

            //try
            //{
            //    labelStyle = dataGrid.FindResource("LabelObjectStyle") as Style;
            //    dataGrid.FieldSettings.LabelPresenterStyle = labelStyle;
            //}
            //catch
            //{
            //}

            var groupLabelTemplate     = dataGrid.FindResource("GroupLabelObjectTemplate") as DataTemplate;
            var channelLabelTemplate   = dataGrid.FindResource("ChannelLabelObjectTemplate") as DataTemplate;
            var unchannelLabelTemplate = dataGrid.FindResource("LabelUnchannelTemplate") as DataTemplate;

            var vTemplate = dataGrid.FindResource("FValueTemplate") as DataTemplate;
            var vTemplateNoBindMeasure = Application.Current.FindResource("FValueTemplateNoBindMeasureFormTemplate") as DataTemplate;

            var vFreeHierarchyObjectTemplate = Application.Current.FindResource("FreeHierarchyObjectTemlate") as DataTemplate;

            var columnWidth = new ColumnWidth(105, false);

            //var widthValue = new FieldLength(105);
            //var widthFreeHier = new FieldLength(270);

            var comparer          = new IFValueComparer();
            var dtConverter       = new DateTimeConverter();
            var dtToolTiptemplate = Application.Current.Resources[ConstantHelper.DateTimeTemplateName] as DataTemplate;

            var measure = dataGrid.FindParent <IMeasure>();

            dataGrid.Resources["IMeasure"] = measure;

            //var fieldLayout = dataGrid.ColumnLayouts[0];

            //TemplateField dtField;

            try
            {
                //fieldLayout.Fields.BeginUpdate();
                //fieldLayout.SortedFields.BeginUpdate();

                var dtCol = userTable.Columns["EventDateTime"];

                var dtField = new TextColumn
                {
                    Key        = dtCol.ColumnName,
                    IsReadOnly = true,
                    //DataType = dtCol.DataType,
                    HeaderText = dtCol.Caption,
                    //Width = new FieldLength(95),
                    Width                      = new ColumnWidth(90, false),
                    ValueConverter             = dtConverter,
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                    AllowToolTips              = AllowToolTips.Always,
                    ToolTipContentTemplate     = dtToolTiptemplate,
                    DataViewType               = typeof(DateTime),
                    IsSortable                 = true,
                    IsSorted                   = SortDirection.Ascending,
                    GroupByComparer            = new ByDayComparer(),
                    //Settings = { LabelPresenterStyle = dataGrid.FindResource("TimeStyle") as Style }
                };

                dataGrid.Columns.Add(dtField);

                if (isCumulateDrums)
                {
                    //dtField.Settings.CellValuePresenterStyle =
                    //    XamDataGridHelper.DataTemplateToCellValuePresenterStyle(ConstantHelper.DateTimeTemplateName);


                    dtConverter.Parametr = ConstantHelper.DateTimeTemplateName;

                    //dtField.ItemTemplate = Application.Current.Resources[ConstantHelper.DateTimeTemplateName] as DataTemplate;
                }
                else
                {
                    string dataTemplateToCellValuePresenterStyleName;
                    //-------------------------------
                    switch (discreteType)
                    {
                    case enumTimeDiscreteType.DB24Hour:
                        dataTemplateToCellValuePresenterStyleName = ConstantHelper.DateTemplateName;
                        break;

                    case enumTimeDiscreteType.DBMonth:
                        dataTemplateToCellValuePresenterStyleName = ConstantHelper.MonthName;
                        break;

                    default:
                        dataTemplateToCellValuePresenterStyleName = ConstantHelper.DateTimeTemplateName;
                        break;
                    }

                    dtConverter.Parametr = dataTemplateToCellValuePresenterStyleName;
                }

                dtField.HeaderText = "Время";

                //dataGrid.GroupBySettings.GroupByColumns.Add(dtField);

                //if (discreteType == enumTimeDiscreteType.DB24Hour)
                //{
                //dtField.Settings.GroupByMode = FieldGroupByMode.Month;
                //dtField.Settings.GroupByRecordPresenterStyle =
                //Application.Current.FindResource("MonthYearXamDataGridStyle") as Style;
                //}
                //else
                //{
                //dtField.Settings.GroupByMode = FieldGroupByMode.Date;
                //}


                //SummaryCalculator statType;
                //string prefix;
                //if (typeInformation == enumTypeInformation.Power)
                //{
                //    statType = new FValueAvgCalculator(format);
                //    prefix = "Сред:";
                //}
                //else
                //{
                //    statType = new FValueSumCalculator(format);
                //    prefix = "Сум:";
                //}

                //var stringFormat = prefix + " {0:" + format + "}";
                var stringFormat = " {0:" + format + "}";

                var dfc = new DetailFieldInfoEqualityComparer();

                //FieldGroup fieldGroupByObject = null;
                //FieldGroup fieldGroupByMeasureCategory = null;
                //EnumMeasureUnitCategory? previousMeasureCategory = null; //Для определения групповать или нет по категории

                foreach (var colGroupByObject in userTable.Columns
                         .Cast <DataColumn>()
                         .Where(c => c.ColumnName != "EventDateTime")
                         .Select(c =>
                {
                    DetailFieldInfo fieldInfo;
                    userTable.TryGetIndexByItemName(c.ColumnName, out fieldInfo);

                    return(new Tuple <DetailFieldInfo, DataColumn>(fieldInfo, c));
                })
                         .GroupBy(c => c.Item1, dfc))
                {
                    var fieldInfo = colGroupByObject.Key;
                    if (fieldInfo == null || fieldInfo.ChannelType == 0)
                    {
                        //Группировать не нужно
                        foreach (var colByObject in colGroupByObject)
                        {
                            FValueSummaryDefinition summaryDefinition;
                            var fld = AddFieldAndSummary(colByObject.Item2, comparer,
                                                         fieldInfo != null && fieldInfo.UseMeasureModule, vTemplate, vTemplateNoBindMeasure, columnWidth);

                            if (fieldInfo != null && fieldInfo.Id != null)
                            {
                                fld.HeaderTemplate = groupLabelTemplate;
                                fld.Label          = colByObject.Item1.Id;
                            }
                            else
                            {
                                fld.HeaderText = colByObject.Item2.Caption;
                            }

                            //fld.HeaderText = (fieldInfo == null ? colByObject.Item2.Caption : (object)colByObject.Item1).ToString();
                            dataGrid.Columns.Add(fld);
                            //if (summaryDefinition != null)
                            //{
                            //    fieldLayout.SummaryDefinitions.Add(summaryDefinition);
                            //}
                        }
                    }
                    else
                    {
                        var fieldGroupByObject = new GroupColumn
                        {
                            //Label = fieldInfo.Id,
                            Key   = fieldInfo.ColumnName + "___",
                            Label = fieldInfo.Id,
                            //HeaderText = fieldInfo.Id.ToString(),
                            HeaderTemplate = groupLabelTemplate,
                        };

                        dataGrid.Columns.Add(fieldGroupByObject);

                        //Группируем по объектам
                        foreach (var colGroupByMeasureCategory in colGroupByObject.GroupBy(c => c.Item1.MeasureUnitUn.SubstringQuantityUn()))
                        {
                            var colGroupByMeasureCategoryList = colGroupByMeasureCategory.ToList();

                            if (!string.IsNullOrEmpty(colGroupByMeasureCategory.Key) && colGroupByMeasureCategoryList.Count > 1)
                            {
                                //Есть категории ед. измерения и их несколько
                                var fieldGroupByMeasureCategory = new GroupColumn
                                {
                                    Label = new LabelMeasureQuantity
                                    {
                                        MeasureQuantityType_UN = colGroupByMeasureCategory.Key,
                                    },
                                    Key = fieldInfo.Id + "_" + colGroupByMeasureCategory.Key,
                                };

                                fieldGroupByObject.Columns.Add(fieldGroupByMeasureCategory);

                                foreach (var colByMeasure in colGroupByMeasureCategoryList)
                                {
                                    FValueSummaryDefinition summaryDefinition;
                                    var fld = AddFieldAndSummary(colByMeasure.Item2, comparer, fieldInfo.UseMeasureModule,
                                                                 vTemplate,
                                                                 vTemplateNoBindMeasure,
                                                                 columnWidth);
                                    //isCumulateDrums, statType, stringFormat, fieldLayout, out summaryDefinition);

                                    //fld.Label = colByMeasure.Item1;

                                    fld.HeaderTemplate = colByMeasure.Item1.ChannelType == 0 ? unchannelLabelTemplate : channelLabelTemplate;
                                    fld.Label          = colByMeasure.Item1;

                                    fieldGroupByMeasureCategory.Columns.Add(fld);
                                    //if (summaryDefinition != null)
                                    //{
                                    //    fieldLayout.SummaryDefinitions.Add(summaryDefinition);
                                    //}
                                }
                            }
                            else
                            {
                                //Нет категорий, или она одна
                                var fielgGroupByReplacedTiDict = new Dictionary <string, GroupColumn>();
                                foreach (var colByMeasure in colGroupByMeasureCategoryList)
                                {
                                    if (colByMeasure.Item2.ColumnName.StartsWith("ovInfo"))
                                    {
                                        //Это информация об ОВ
                                        //var hoc = new HierObjectsConverterComparer();

                                        var fld = AddField(colByMeasure.Item2, fieldInfo.UseMeasureModule,
                                                           vFreeHierarchyObjectTemplate,
                                                           vFreeHierarchyObjectTemplate, columnWidth);

                                        //widthFreeHier

                                        fld.Label = "Замещаемые ТИ";
                                        //fld.Settings.FilterOperandUIType = FilterOperandUIType.DropDownList;
                                        //fld.Settings.FilterLabelIconDropDownType = FilterLabelIconDropDownType.MultiSelectExcelStyle;
                                        //fld.Settings.GroupByComparer = hoc;

                                        //fld.ValueToTextConverter = new HierObjectsConverter();
                                        //fld.Settings.FilterComparer = new HierObjectsConverterComparer();
                                        fieldGroupByObject.Columns.Add(fld);
                                    }
                                    else
                                    {
                                        GroupColumn fielgGroupByReplacedTi = null;

                                        //Группируем по замещаемой ТИ
                                        if (colByMeasure.Item2.ColumnName.StartsWith("ovValue") &&
                                            !fielgGroupByReplacedTiDict.TryGetValue(
                                                colByMeasure.Item1.GroupByReplacedTiName, out fielgGroupByReplacedTi))
                                        {
                                            fielgGroupByReplacedTi = new GroupColumn
                                            {
                                                Label      = colByMeasure.Item1.ReplacedId,
                                                Key        = colByMeasure.Item1.ColumnName + "_",
                                                HeaderText = colByMeasure.Item1.ReplacedId.ToString(),
                                            };

                                            fielgGroupByReplacedTiDict[colByMeasure.Item1.GroupByReplacedTiName] =
                                                fielgGroupByReplacedTi;
                                        }

                                        //FValueSummaryDefinition summaryDefinition;
                                        var fld = AddFieldAndSummary(colByMeasure.Item2, comparer, fieldInfo.UseMeasureModule,
                                                                     vTemplate,
                                                                     vTemplateNoBindMeasure,
                                                                     columnWidth);
                                        //isCumulateDrums, statType, stringFormat, fieldLayout, out summaryDefinition);

                                        fld.Label          = colByMeasure.Item1;
                                        fld.HeaderTemplate = colByMeasure.Item1.ChannelType == 0 ? unchannelLabelTemplate : channelLabelTemplate;

                                        if (fielgGroupByReplacedTi != null)
                                        {
                                            fielgGroupByReplacedTi.Columns.Add(fld);
                                        }
                                        else
                                        {
                                            fieldGroupByObject.Columns.Add(fld);
                                        }

                                        //if (summaryDefinition != null)
                                        //{
                                        //    fieldLayout.SummaryDefinitions.Add(summaryDefinition);
                                        //}

                                        //if (colByMeasure.Item1.IsOv)
                                        //{
                                        //    //Если это ОВ, добавляем суммарную информацию о неразнесенных значениях
                                        //    var unWritedOvs = new FValueSummaryDefinition
                                        //    {
                                        //        SourceFieldName = colByMeasure.Item2.ColumnName,
                                        //        Calculator = new FValueSumUnreplacedCalculator(format),
                                        //        StringFormat = stringFormat,
                                        //        UseMeasureModule = fieldInfo.UseMeasureModule,
                                        //    };

                                        //    fieldLayout.SummaryDefinitions.Add(unWritedOvs);
                                        //}
                                    }
                                }

                                if (fielgGroupByReplacedTiDict.Count > 0)
                                {
                                    foreach (var c in fielgGroupByReplacedTiDict.Values)
                                    {
                                        fieldGroupByObject.Columns.Add(c);
                                    }
                                }
                            }
                        }
                    }
                }



                //if (isDateTimeGroupingGridControlXam &&
                //    (discreteType == enumTimeDiscreteType.DBHalfHours || discreteType == enumTimeDiscreteType.DBHours ||
                //     discreteType == enumTimeDiscreteType.DB24Hour))
                //{
                //    //dtField.Settings.AllowSummaries = false;
                //    dtField.Settings.AllowGroupBy = true;


                //    fieldLayout.SortedFields.Add(new FieldSortDescription("EventDateTime", ListSortDirection.Ascending,
                //        true));
                //}
                //else
                //{
                //    dtField.DisplayTemplate = Application.Current.Resources[ConstantHelper.DateTimeTemplateName] as DataTemplate;

                //    //dtField.Settings.CellValuePresenterStyle =
                //    //    XamDataGridHelper.DataTemplateToCellValuePresenterStyle(ConstantHelper.DateTimeTemplateName);
                //}

                //var consumptionScheduleField = fieldLayout.Fields.FirstOrDefault(ff => ff.Name == "ConsumptionSchedule");
                //if (consumptionScheduleField != null)
                //{
                //    consumptionScheduleField.Label = "Тип. потр.";
                //}

                //var consumptionSchedulePercentField = fieldLayout.Fields.FirstOrDefault(ff => ff.Name == "ConsumptionSchedulePercent");
                //if (consumptionSchedulePercentField != null)
                //{
                //    consumptionSchedulePercentField.Label = "Тип. потр. %";
                //}
            }
            finally
            {
                // fieldLayout.SortedFields.EndUpdate();
                //fieldLayout.Fields.EndUpdate();
            }

            //dataGrid.FieldLayoutSettings.FixedFieldUIType = FixedFieldUIType.Splitter;
            //dataGrid.FieldSettings.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;

            if (userTable.Columns.Count < 20)
            {
                //из-за того что тормоза ограничиваем
                //dataGrid.FieldSettings.SummaryDisplayArea = dataGrid.FieldSettings.SummaryDisplayArea | SummaryDisplayAreas.InGroupByRecords;
            }

            //if (userTable.Columns.Count < 1000)
            //{
            //    dataGrid.RecordsInViewChanged += ExpandFirstRecord;
            //}
        }