Esempio n. 1
0
        public static void ConfigureGrid(XamDataGrid dataGrid, DataTableEx userTable, enumTimeDiscreteType discreteType, enumTypeInformation typeInformation,
                                         string format, bool isHalfhours, bool isCumulateDrums = false, bool isDateTimeGroupingGridControlXam = true, bool useBindedConverter = true)
        {
            if (dataGrid == null || userTable == null)
            {
                return;
            }

            var view = userTable.DefaultView;

            try
            {
                dataGrid.BeginInit();
                dataGrid.FieldSettings.AllowEdit = false;

                view.AllowDelete = view.AllowEdit = view.AllowNew = false;

                //var style = new Style(typeof(XamNumericEditor));
                //style.Setters.Add(new Setter(ValueEditor.FormatProperty, format));

                if (isHalfhours)
                {
                    SetHalfhoursColumnsForXamDataGrid(dataGrid, userTable, discreteType, typeInformation, format, isCumulateDrums, isDateTimeGroupingGridControlXam, useBindedConverter);
                }
                else
                {
                    SetValidateColumnsForXamDataGrid(dataGrid, userTable);
                }

                //view.Table = null;
            }
            finally
            {
                dataGrid.DataSource = view;
                dataGrid.EndInit();
            }

            //dataGrid.Dispatcher.BeginInvoke((System.Action) (() =>
            //{

            //}), DispatcherPriority.Background);
        }
        public static void ConfigureGridDailyIntegrals(XamDataGrid dataGrid, DataTableEx userTable, bool useLossesCoefficient)
        {
            if (dataGrid == null || userTable == null)
            {
                return;
            }

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

            var view = userTable.DefaultView;

#if DEBUG
            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
#endif

            try
            {
                var hierObjectStyle   = dataGrid.FindResource("HierObjectStyle") as Style;
                var chTemplate        = dataGrid.FindResource("ChannelTemplate") as DataTemplate;
                var fValueStyle       = dataGrid.FindResource("FValueStyle") as Style;
                var fValueNoFlagStyle = dataGrid.FindResource("FValueNoFlagStyle") as Style;
                var widthValue        = new FieldLength(105);

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

                try
                {
                    fields.BeginUpdate();

                    #region Создаем основные колонки

                    var comparer = new IFreeHierarchyObjectComparer();

                    fields.Add(new Field
                    {
                        Name        = "Parent",
                        DataType    = typeof(IFreeHierarchyObject),
                        Label       = "Объект",
                        Width       = new FieldLength(160),
                        AllowFixing = AllowFieldFixing.Near,
                        //FixedLocation = FixedFieldLocation.FixedToNearEdge,
                        Settings =
                        {
                            //GroupByMode = FieldGroupByMode.Value,
                            AllowGroupBy              = true,
                            GroupByComparer           = comparer,
                            SortComparer              = comparer,
                            FilterComparer            = comparer,
                            CellVisibilityWhenGrouped = Visibility.Collapsed,
                            FilterOperandUIType       = FilterOperandUIType.DropDownList,
                            AllowFixing             = AllowFieldFixing.Near,
                            AllowEdit               = false,
                            EditorStyle             = null,
                            AllowRecordFiltering    = true,
                            CellValuePresenterStyle = hierObjectStyle,
                        },
                        HorizontalContentAlignment = HorizontalAlignment.Left,
                        VerticalContentAlignment   = VerticalAlignment.Center,
                    });

                    fields.Add(new Field
                    {
                        Name        = "NameTI",
                        DataType    = typeof(IFreeHierarchyObject),
                        Label       = "ТИ",
                        Width       = new FieldLength(200),
                        AllowFixing = AllowFieldFixing.Near,
                        //FixedLocation = FixedFieldLocation.FixedToNearEdge,
                        Settings =
                        {
                            AllowGroupBy              = true,
                            GroupByComparer           = comparer,
                            SortComparer              = comparer,
                            FilterComparer            = comparer,
                            CellVisibilityWhenGrouped = Visibility.Collapsed,
                            FilterOperandUIType       = FilterOperandUIType.DropDownList,
                            AllowFixing             = AllowFieldFixing.Near,
                            AllowEdit               = false,
                            EditorStyle             = null,
                            AllowRecordFiltering    = true,
                            CellValuePresenterStyle = hierObjectStyle,
                        },
                        HorizontalContentAlignment = HorizontalAlignment.Left,
                        VerticalContentAlignment   = VerticalAlignment.Center,
                    });

                    fields.Add(new TemplateField
                    {
                        Name            = "Channel",
                        Label           = "К",
                        DataType        = typeof(object),
                        DisplayTemplate = chTemplate,
                        Width           = new FieldLength(40),
                        AllowFixing     = AllowFieldFixing.Near,
                        //FixedLocation = FixedFieldLocation.FixedToNearEdge,
                        Settings =
                        {
                            AllowGroupBy         = true,
                            FilterOperandUIType  = FilterOperandUIType.DropDownList,
                            AllowFixing          = AllowFieldFixing.Near,
                            AllowEdit            = false,
                            EditorStyle          = null,
                            AllowRecordFiltering = true,
                        },
                    });

                    fieldLayout.Fields.Add(new Field
                    {
                        Name        = "DataSource",
                        Label       = "Источник данных",
                        Width       = new FieldLength(100),
                        AllowFixing = AllowFieldFixing.Near,
                        Settings    =
                        {
                            AllowGroupBy         = true,
                            FilterOperandUIType  = FilterOperandUIType.DropDownList,
                            AllowFixing          = AllowFieldFixing.Near,
                            AllowEdit            = false,
                            EditorStyle          = null,
                            AllowRecordFiltering = true,
                        },
                    });

                    fields.Add(new Field
                    {
                        Name        = "Coeff",
                        DataType    = typeof(double),
                        Width       = widthValue,
                        Label       = "Коэфф. тр.",
                        Format      = "#0",
                        AllowFixing = AllowFieldFixing.Near,
                        Settings    =
                        {
                            AllowGroupBy         = true,
                            AutoSizeOptions      = FieldAutoSizeOptions.None,
                            Width                = widthValue,
                            SummaryUIType        = SummaryUIType.MultiSelect,
                            AllowEdit            = false,
                            EditorStyle          = null,
                            FilterOperandUIType  = FilterOperandUIType.Combo,
                            AllowRecordFiltering = true,
                        },
                        HorizontalContentAlignment = HorizontalAlignment.Right,
                        VerticalContentAlignment   = VerticalAlignment.Center,
                    });

                    if (useLossesCoefficient)
                    {
                        fields.Add(new Field
                        {
                            Name        = "CoeffLosses",
                            DataType    = typeof(double),
                            Width       = widthValue,
                            Label       = "Коэфф. потерь",
                            Format      = "#0.###",
                            AllowFixing = AllowFieldFixing.Near,
                            Settings    =
                            {
                                AllowGroupBy         = true,
                                AutoSizeOptions      = FieldAutoSizeOptions.None,
                                Width                = widthValue,
                                SummaryUIType        = SummaryUIType.MultiSelect,
                                AllowEdit            = false,
                                EditorStyle          = null,
                                FilterOperandUIType  = FilterOperandUIType.Combo,
                                AllowRecordFiltering = true,
                            },
                            HorizontalContentAlignment = HorizontalAlignment.Right,
                            VerticalContentAlignment   = VerticalAlignment.Center,
                        });
                    }

                    #endregion

                    #region Посуточные колонки
                    var        counter    = 0;
                    FieldGroup fieldGroup = null;

                    foreach (var col in userTable.Columns.OfType <DataColumnEx>())
                    {
                        if (col == null)
                        {
                            continue;
                        }

                        if (counter == 0)
                        {
                            fieldGroup = new FieldGroup
                            {
                                Label = col.GroupName,
                            };

                            fieldLayout.FieldItems.Add(fieldGroup);
                        }

                        var fld = AddFValueField(col.ColumnName, col.DataType, widthValue, col.IsFValue ? fValueStyle : fValueNoFlagStyle, null);
                        fld.Label = col.Caption;

                        //if (!col.IsFValue)
                        //{
                        //    fld.Format = "##0.######";
                        //}

                        fieldGroup.Children.Add(fld);

                        if (++counter == 3)
                        {
                            counter = 0;
                        }
                    }

                    #endregion
                }
                finally
                {
                    fieldLayout.Fields.EndUpdate();
                }

                dataGrid.RecordsInViewChanged += ExpandFirstRecord;
            }
            finally
            {
                dataGrid.DataSource = view;
                dataGrid.EndInit();
            }

#if DEBUG
            sw.Stop();
            Console.WriteLine("ConfigureGridDailyIntegrals - > {0} млс", sw.ElapsedMilliseconds);
#endif
        }