aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs
blob: 2847c508e564793136ed5f9168e638cf35224bb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Tango.BL.Entities;
using Tango.Core;
using System.Data.Entity;

namespace Tango.BL
{
    public partial class ObservablesStaticCollections : ExtendedObject
    {
        private bool _initialized;
        private ObservablesContext db;

        private static ObservablesStaticCollections _instance;
        /// <summary>
        /// Gets the singleton instance.
        /// </summary>
        public static ObservablesStaticCollections Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new ObservablesStaticCollections();
                }
                return _instance;
            }
        }

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        public void Initialize()
        {
            if (!_initialized)
            {
                db = ObservablesContext.CreateDefault();

                WindingMethods = db.WindingMethods.ToObservableCollection();
                ColorSpaces = db.ColorSpaces.ToObservableCollection();
                SpoolTypes = db.SpoolTypes.ToObservableCollection();

                ActionTypes = db.ActionTypes.ToObservableCollection();
                EventTypes = db.EventTypes.ToObservableCollection();
                EventTypesActions = db.EventTypesActions.ToObservableCollection();
                EventTypesCategories = db.EventTypesCategories.ToObservableCollection();
                EventTypesGroups = db.EventTypesGroups.ToObservableCollection();

                HardwareBlowerTypes = db.HardwareBlowerTypes.ToObservableCollection();
                HardwareBlowers = db.HardwareBlowers.ToObservableCollection();

                HardwareBreakSensorTypes = db.HardwareBreakSensorTypes.ToObservableCollection();
                HardwareBreakSensors = db.HardwareBreakSensors.ToObservableCollection();

                HardwareDancerTypes = db.HardwareDancerTypes.ToObservableCollection();
                HardwareDancers = db.HardwareDancers.ToObservableCollection();

                HardwareMotorTypes = db.HardwareMotorTypes.ToObservableCollection();
                HardwareMotors = db.HardwareMotors.ToObservableCollection();

                HardwarePidControlTypes = db.HardwarePidControlTypes.ToObservableCollection();
                HardwarePidControls = db.HardwarePidControls.ToObservableCollection();

                HardwareSpeedSensorTypes = db.HardwareSpeedSensorTypes.ToObservableCollection();
                HardwareSpeedSensors = db.HardwareSpeedSensors.ToObservableCollection();

                HardwareWinderTypes = db.HardwareWinderTypes.ToObservableCollection();
                HardwareWinders = db.HardwareWinders.ToObservableCollection();

                TechControllers = db.TechControllers.ToObservableCollection();
                TechDispensers = db.TechDispensers.ToObservableCollection();
                TechIos = db.TechIos.ToObservableCollection();
                TechMonitors = db.TechMonitors.ToObservableCollection();
                TechValves = db.TechValves.ToObservableCollection();
                TechHeaters = db.TechHeaters.ToObservableCollection();
                TechValves = db.TechValves.ToObservableCollection();

                Machines = db.Machines.Include(x => x.Organization).ToObservableCollection();

                Users = db.Users.Include(x => x.Contact).ToObservableCollection();

                MachineVersions = db.MachineVersions.ToObservableCollection();


                //Load later...
                Task.Factory.StartNew(() =>
                {
                    LiquidTypes = db.LiquidTypes.ToObservableCollection();
                    DispenserTypes = db.DispenserTypes.ToObservableCollection();
                    MidTankTypes = db.MidTankTypes.ToObservableCollection();
                    CartridgeTypes = db.CartridgeTypes.ToObservableCollection();
                    IdsPackFormulas = db.IdsPackFormulas.ToObservableCollection();


                    Rmls = db.Rmls.ToObservableCollection();
                    LiquidTypesRmls = db.LiquidTypesRmls.ToObservableCollection();

                    foreach (var machine in Machines)
                    {
                        ObservablesContextAdapter adapter = new ObservablesContextAdapter(db);

                        adapter.GetConfiguration(x => x.Guid == machine.ConfigurationGuid);
                    }
                });

                _initialized = true;
            }

            //InitCollectionSources();
        }

        /// <summary>
        /// Creates a collection view from the specified observable collection.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection">The collection.</param>
        /// <returns></returns>
        private ICollectionView CreateCollectionView<T>(ObservableCollection<T> collection)
        {
            var view = CollectionViewSource.GetDefaultView(collection);
            return view;
        }
    }
}
ader="RELATED OBJECT NAME" Binding="{Binding RelatedObjectName}" Width="Auto" /> <DataGridTextColumn Header="RELATED OBJECT ID" Binding="{Binding RelatedObjectGuid}" Width="Auto" > <DataGridTextColumn.CellStyle> <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}" > <Setter Property="BorderThickness" Value="0"/> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="VerticalContentAlignment" Value="Center"></Setter> <Setter Property="Tag" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=DataContext}"/> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu DataContext="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource Self}}" Padding="0" Margin="0" > <MenuItem Header="Copy (Ctrl+C)" Command="{Binding CopyRelateObjectIDCommand}" FontSize="12" Background="{StaticResource MainWindow.Background}"> <MenuItem.Icon> <materialDesign:PackIcon Width="16" Height="16" Kind="ContentCopy" VerticalAlignment="Center" Foreground="{StaticResource MainWindow.Foreground}"/> </MenuItem.Icon> <MenuItem.ItemContainerStyle> <Style TargetType="MenuItem" BasedOn="{StaticResource MaterialDesignMenuItem}"> <Setter Property="Background" Value="Transparent"></Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Transparent"></Setter> </Trigger> </Style.Triggers> </Style> </MenuItem.ItemContainerStyle> </MenuItem> <ContextMenu.Style> <Style TargetType="{x:Type ContextMenu}" BasedOn="{StaticResource MaterialDesignMenu}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate > <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}"> <Border Background="{StaticResource MainWindow.Background}" Effect="{DynamicResource MaterialDesignShadowDepth1}" Margin="3" CornerRadius="2"> <Grid RenderOptions.ClearTypeHint="Enabled" Margin="0"> <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/> </Grid> </Border> </AdornerDecorator> </ControlTemplate> </Setter.Value> </Setter> </Style> </ContextMenu.Style> </ContextMenu> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="Transparent"></Setter> <Setter Property="Foreground" Value="{StaticResource AccentColorBrush}" /> </Trigger> </Style.Triggers> </Style> </DataGridTextColumn.CellStyle> </DataGridTextColumn> <DataGridTextColumn Header="MESSAGE" Binding="{Binding Message}" Width="1*" /> </DataGrid.Columns> </DataGrid> </Grid> <Grid Grid.Row="1" Grid.Column="0" Visibility="{Binding IsLoading,Converter={StaticResource BooleanToVisibilityConverter}}"> <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center"> <mahapps:ProgressRing Margin="20 60 20 40" Width="80" Height="80" IsActive="{Binding IsLoading}"></mahapps:ProgressRing> <TextBlock Text="Loading..." HorizontalAlignment="Center" FontSize="20" FontStyle="Italic" VerticalAlignment="Center" Margin="0 20 0 0"></TextBlock> </StackPanel> </Grid> <Grid Grid.Row="0" Grid.Column="1" Margin="40 0 10 0"> <Border Padding="14 14 12 14" BorderBrush="DimGray" BorderThickness="0" Background="{StaticResource Logging.Background}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="2"> <Border.Effect> <DropShadowEffect ShadowDepth="4" BlurRadius="10" Opacity="0.5"/> </Border.Effect> <DockPanel> <TextBlock DockPanel.Dock="Left" Margin="10 0 0 0" Foreground="{StaticResource DimGrayBrush}" FontSize="16" VerticalAlignment="Center" Width="150">Object Changes</TextBlock> <Button Width="Auto" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Right" DockPanel.Dock="Right" Command="{Binding CopyToClipBoardCommand}" > <StackPanel Orientation="Horizontal" > <materialDesign:PackIcon Width="16" Height="16" Kind="ContentCopy" VerticalAlignment="Center" Margin="-5 0 10 0"/> <TextBlock Text="Copy to Clipboard" VerticalAlignment="Center"></TextBlock> </StackPanel> </Button> </DockPanel> </Border> </Grid> <Border Grid.Row="1" Grid.Column="1" Margin="40 0 10 10" IsEnabled="{Binding IsFree}" BorderThickness="1 0 1 1 " BorderBrush="{StaticResource LightGrayBrush100}" Background="{StaticResource TransparentBackgroundBrush}"> <DockPanel > <TextBlock DockPanel.Dock="Top" Height="40" Text="{Binding DifferenceObject.Name, Mode=OneWay}" VerticalAlignment="Center" Padding="5" FontSize="18" HorizontalAlignment="Center" ></TextBlock> <TreeView x:Name="treeView" ItemsSource="{Binding DifferenceObject.Children, Mode=OneWay}" > <TreeView.ItemContainerStyle> <Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TreeViewItem}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition MinWidth="19" Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition/> </Grid.RowDefinitions> <ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource MaterialDesignExpandCollapseToggleStyle}" Foreground="{TemplateBinding Foreground}" Margin="8 0 8 0" VerticalAlignment="Center" /> <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="1" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"> <ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Border> <ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="1"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsExpanded" Value="false"> <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/> </Trigger> <Trigger Property="HasItems" Value="false"> <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="IsSelectionActive" Value="false"/> </MultiTrigger.Conditions> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}}"/> </MultiTrigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="IsExpanded" Value="True" /> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Transparent"></Setter> </Trigger> <Trigger Property="IsFocused" Value="True"> <Setter Property="Background" Value="Transparent"></Setter> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="Transparent"></Setter> </Trigger> </Style.Triggers> </Style> </TreeView.ItemContainerStyle> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type diff:ActionLogDifference}" ItemsSource="{Binding Children}"> <TextBlock Text="{Binding Name}" Margin="5 0 0 0" Foreground ="{StaticResource MainWindow.Foreground}"/> </HierarchicalDataTemplate> <DataTemplate DataType="{x:Type diff:ActionLogDifferenceValue}"> <TextBlock Margin="5 0 0 0" Foreground ="{StaticResource MainWindow.Foreground}"> <Run Text="{Binding Name}"/> <Run>: </Run> <Run Text="{Binding Before,Mode=OneWay}" Foreground="{StaticResource DimGrayBrush}"/> <Run> | </Run> <Run Text="{Binding After,Mode=OneWay}" Foreground="{StaticResource RedBrush100}"/> </TextBlock> </DataTemplate> </TreeView.Resources> </TreeView> </DockPanel> </Border> <mahapps:ProgressRing Grid.Row="1" Grid.Column="1" Margin="20 0 20 40" Width="80" Height="80" IsActive="{Binding IsLoadingDifferences}"></mahapps:ProgressRing> </Grid> </Grid> </UserControl>