aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ThreadCharacteristicsView.xaml
blob: aeedcb6dfcbc3b401ddf8814bbce3d3a3b3653c0 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<UserControl x:Class="Tango.MachineStudio.ThreadExtensions.Views.ThreadCharacteristicsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Tango.MachineStudio.ThreadExtensions.Views"
             xmlns:vm="clr-namespace:Tango.MachineStudio.ThreadExtensions.ViewModels"
             xmlns:global="clr-namespace:Tango.MachineStudio.ThreadExtensions"
             xmlns:shapes="clr-namespace:Tango.SharedUI.Shapes;assembly=Tango.SharedUI"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI"
             xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI"
             xmlns:enumerations="clr-namespace:Tango.BL.Enumerations;assembly=Tango.BL"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
             mc:Ignorable="d" 
             FontSize="16"
             d:DesignHeight="850" d:DesignWidth="1200" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}">

    <UserControl.Resources>
        <converters:EnumToDescriptionConverter x:Key="EnumToDescriptionConverter"/>

        <ObjectDataProvider x:Key="TwistDirections" ObjectType="{x:Type sys:Enum}" MethodName="GetValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="enumerations:TwistDirections"/>
        </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider x:Key="Plies" ObjectType="{x:Type sys:Enum}" MethodName="GetValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="enumerations:Plies"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        
    </UserControl.Resources>

    <Grid IsEnabled="{Binding CanEdit}">
        <materialDesign:Card Background="{DynamicResource MaterialDesignBackground}" VerticalAlignment="Stretch" Padding="40">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <UniformGrid Columns="4" Grid.Row="0">

                    <Grid Margin="10">
                        <materialDesign:Card Background="{DynamicResource MaterialDesignBackground}" VerticalAlignment="Stretch" >
                            <Grid Margin="20">
                                <DockPanel>
                                    <TextBlock DockPanel.Dock="Top" Margin="20 10 0 10" FontSize="20" FontWeight="DemiBold">Yarn Source</TextBlock>
                                    <controls:TableGrid RowHeight="60" Margin="0 20 0 0" MakeFirstColumnVerticalAlignmentBottom="False"  >
                                        <controls:TableGrid.Resources>
                                            <Style TargetType="TextBlock">
                                                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                                                <Setter Property="Margin" Value="0 3 0 0"></Setter>
                                            </Style>
                                        </controls:TableGrid.Resources>
                                        <TextBlock Text="Manufacturer:"  VerticalAlignment="Center" FontSize="16" Margin="0 3 0 0"></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding Manufacturers}" SelectedItem="{Binding ActiveRML.Manufacturer,Mode=TwoWay}" AddCommand="{Binding AddManufacturerItemCommand}" EditCommand="{Binding EditManufacturerItemCommand}"/>
                                        
                                        <TextBlock Text="Brand:" VerticalAlignment="Center" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding Brands}" SelectedItem="{Binding ActiveRMLExtension.YarnBrand,Mode=TwoWay}" DisplayMemberPath="Name"  AddCommand="{Binding AddBrandItemCommand}" EditCommand="{Binding EditBrandItemCommand}"/>
                                        
                                        <TextBlock Text="Country:" ></TextBlock>
                                        <TextBox Text="{Binding  ActiveRMLExtension.Country,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center"></TextBox>

                                        <TextBlock Text="End Use:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding EndUse}" SelectedItem="{Binding ActiveRML.MediaPurpose,Mode=TwoWay}" DisplayMemberPath="Name"  AddCommand="{Binding AddEndUseItemCommand}" EditCommand="{Binding EditEndUseItemCommand}"/>

                                        <TextBlock Text="Applications:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding Applications}" SelectedItem="{Binding ActiveRMLExtension.YarnApplication,Mode=TwoWay}" DisplayMemberPath="Name"  AddCommand="{Binding AddApplicationItemCommand}" EditCommand="{Binding EditApplicationItemCommand}"/>

                                        <TextBlock Text="Industry Sector:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding IndustrySector}" SelectedItem="{Binding ActiveRMLExtension.YarnIndustrysector}" DisplayMemberPath="Name"  AddCommand="{Binding AddIndustrySectorItemCommand}" EditCommand="{Binding EditIndustrySectorItemCommand}"/>

                                    </controls:TableGrid>
                                </DockPanel>
                            </Grid>
                        </materialDesign:Card>
                    </Grid>

                    <Grid Margin="10">
                        <materialDesign:Card Background="{DynamicResource MaterialDesignBackground}" VerticalAlignment="Stretch" >
                            <Grid Margin="20">
                                <DockPanel>
                                    <TextBlock DockPanel.Dock="Top"  FontSize="20" FontWeight="DemiBold">Yarn Source</TextBlock>
                                    <controls:TableGrid RowHeight="55" Margin="0 20 0 0" MakeFirstColumnVerticalAlignmentBottom="False" >
                                        <controls:TableGrid.Resources>
                                            <Style TargetType="TextBlock">
                                                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                                                <Setter Property="Margin" Value="0 3 0 0"></Setter>
                                            </Style>
                                        </controls:TableGrid.Resources>
                                        <TextBlock Text="Material:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding Materials}" SelectedItem="{Binding ActiveRML.MediaMaterial}" DisplayMemberPath="Name"  AddCommand="{Binding AddMaterialItemCommand}" EditCommand="{Binding EditMaterialItemCommand}"/>
                                        
                                        <TextBlock Text="Type:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding YarnTypes}" SelectedItem="{Binding ActiveRMLExtension.YarnType}" DisplayMemberPath="Name"  AddCommand="{Binding AddYarnTypeItemCommand}" EditCommand="{Binding EditYarnTypeItemCommand}"/>
                                        
                                        <TextBlock Text="Sub family:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding SubFamilies}" SelectedItem="{Binding ActiveRMLExtension.YarnSubFamily}" DisplayMemberPath="Name" AddCommand="{Binding AddSubFamilyItemCommand}" EditCommand="{Binding EditSubFamilyItemCommand}"/>
                                        
                                        <TextBlock Text="Family:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding Family}" SelectedItem="{Binding ActiveRMLExtension.YarnFamily}" DisplayMemberPath="Name" AddCommand="{Binding AddFamilyItemCommand}" EditCommand="{Binding EditFamilyItemCommand}"/>
                                        
                                        <TextBlock Text="Group:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding Group}" SelectedItem="{Binding ActiveRMLExtension.YarnGroup}" DisplayMemberPath="Name"  AddCommand="{Binding AddGroupItemCommand}" EditCommand="{Binding EditGroupItemCommand}"/>
                                        
                                        <TextBlock Text="Texturing:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding Texturing}" SelectedItem="{Binding ActiveRMLExtension.YarnTexturing}" DisplayMemberPath="Name"  AddCommand="{Binding AddTexturingItemCommand}" EditCommand="{Binding EditTexturingItemCommand}"/>
                                        
                                        <TextBlock Text="Geometry:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding Geometry}" SelectedItem="{Binding ActiveRML.FiberShape}" DisplayMemberPath="Name"  AddCommand="{Binding AddGeometryItemCommand}" EditCommand="{Binding EditGeometryItemCommand}"/>
                                        
                                        <TextBlock Text="Thread Shade:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding YarnWhiteShade}" SelectedItem="{Binding ActiveRMLExtension.YarnWhiteShade}" DisplayMemberPath="Name"  AddCommand="{Binding AddYarnWhiteShadeItemCommand}" EditCommand="{Binding EditYarnWhiteShadeItemCommand}"/>
                                        
                                        <TextBlock Text="Gloss level:" ></TextBlock>
                                        <local:ComboboxEditable ItemsSource="{Binding GlossLevel}" SelectedItem="{Binding ActiveRMLExtension.YarnGlossLevel}" DisplayMemberPath="Name"  AddCommand="{Binding AddGlossLevelItemCommand}" EditCommand="{Binding EditGlossLevelItemCommand}"/>
                                       
                                    </controls:TableGrid>
                                </DockPanel>
                            </Grid>
                        </materialDesign:Card>
                    </Grid>
                    <Grid Margin="10">
                        <materialDesign:Card Background="{DynamicResource MaterialDesignBackground}" VerticalAlignment="Stretch" >
                            <Grid Margin="20">
                                <DockPanel>
                                    <TextBlock DockPanel.Dock="Top"  FontSize="20" FontWeight="DemiBold">Yarn Data</TextBlock>
                                    <controls:TableGrid RowHeight="55" Margin="0 20 0 0" MakeFirstColumnVerticalAlignmentBottom="False" >
                                        <controls:TableGrid.Resources>
                                            <Style TargetType="TextBlock">
                                                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                                                <Setter Property="Margin" Value="0 3 0 0"></Setter>
                                            </Style>
                                        </controls:TableGrid.Resources>

                                        <TextBlock Text="Linear Density:" ></TextBlock>
                                        <mahapps:NumericUpDown Minimum="0" Maximum="9999" InterceptArrowKeys="True" Background="Transparent" BorderThickness="0" InterceptMouseWheel="True" HasDecimals="False" HorizontalContentAlignment="Left" Value="{Binding ActiveRML.FiberSize,Mode=TwoWay}" FontSize="16"></mahapps:NumericUpDown>

                                        <TextBlock Text="Unit:" ></TextBlock>
                                        <ComboBox ItemsSource="{Binding Units}" SelectedItem="{Binding ActiveRML.LinearMassDensityUnit}" DisplayMemberPath="Name"></ComboBox>

                                        <TextBlock Text="Plies:" ></TextBlock>
                                        <ComboBox ItemsSource="{Binding Source={StaticResource Plies}}" SelectedItem="{Binding ActiveRML.RMLPlies,  Mode=TwoWay}" >
                                            <ComboBox.ItemTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Converter={StaticResource EnumToDescriptionConverter}}"></TextBlock>
                                                </DataTemplate>
                                            </ComboBox.ItemTemplate>
                                        </ComboBox>

                                        <TextBlock Text="Filament count per plies:" ></TextBlock>
                                        <mahapps:NumericUpDown Minimum="0" Maximum="500" InterceptArrowKeys="True" Background="Transparent" BorderThickness="0" InterceptMouseWheel="True" HasDecimals="False" HorizontalContentAlignment="Left" Value="{Binding ActiveRML.PliesPerFiber,Mode=TwoWay}" FontSize="16"></mahapps:NumericUpDown>

                                        <TextBlock Text="Count (den)" ></TextBlock>
                                        <TextBlock Text="{Binding ActiveRML.DencityCount}" Foreground="Blue" ></TextBlock>

                                        <TextBlock Text="Fiber count " ></TextBlock>
                                        <TextBlock Text="{Binding ActiveRML.FiberCount}" Foreground="Blue" ></TextBlock>

                                        <TextBlock Text="Twist(tpm):" ></TextBlock>
                                        <mahapps:NumericUpDown Minimum="0" Maximum="9999" InterceptArrowKeys="True" Background="Transparent" BorderThickness="0" InterceptMouseWheel="True" HasDecimals="False" HorizontalContentAlignment="Left" Value="{Binding ActiveRMLExtension.TwistTpm,Mode=TwoWay}" FontSize="16"></mahapps:NumericUpDown>

                                        <TextBlock Text="Twist direction:" ></TextBlock>
                                        <ComboBox  ItemsSource="{Binding  Source={StaticResource TwistDirections}}" SelectedItem="{Binding ActiveRMLExtension.YarnTwistDirections,Mode=TwoWay}" >
                                            <ComboBox.ItemContainerStyle>
                                                <Style TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
                                                    <Setter Property="Background" Value="{StaticResource WhiteBrush100}"></Setter>
                                                </Style>
                                            </ComboBox.ItemContainerStyle>
                                            <ComboBox.ItemTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Converter={StaticResource EnumToDescriptionConverter}}"></TextBlock>
                                                </DataTemplate>
                                            </ComboBox.ItemTemplate>
                                        </ComboBox>
                                    </controls:TableGrid>
                                </DockPanel>
                            </Grid>
                        </materialDesign:Card>
                    </Grid>
                    <Grid Margin="10">
                        <materialDesign:Card Background="{DynamicResource MaterialDesignBackground}" VerticalAlignment="Stretch" >
                            <Grid Margin="20">
                                <DockPanel>
                                    <TextBlock DockPanel.Dock="Top"  FontSize="20" FontWeight="DemiBold">Yarn Properties from datasheet</TextBlock>
                                    <controls:TableGrid RowHeight="55" Margin="0 20 0 0" MakeFirstColumnVerticalAlignmentBottom="False" >
                                        <controls:TableGrid.Resources>
                                            <Style TargetType="TextBlock">
                                                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                                                <Setter Property="Margin" Value="0 3 0 0"></Setter>
                                            </Style>
                                            <Style TargetType="{x:Type mahapps:NumericUpDown}">
                                                <Setter Property="BorderThickness" Value="0 0 0 0.5"></Setter>
                                                <Setter Property="FontSize" Value="16"/>
                                            </Style>
                                        </controls:TableGrid.Resources>
                                        <TextBlock Text="Max Force (N):" ></TextBlock>
                                        <StackPanel Orientation="Horizontal">
                                            <mahapps:NumericUpDown HasDecimals="True" Minimum="0" Maximum="100" InterceptArrowKeys="True" HideUpDownButtons="True" Value="{Binding ActiveRMLExtension.MinMaxForceN}" HorizontalContentAlignment="Left" BorderBrush="{StaticResource MainWindow.Foreground}" Foreground="{StaticResource MainWindow.Foreground}" />
                                            <mahapps:NumericUpDown HasDecimals="True" Minimum="0" Maximum="100" InterceptArrowKeys="True" HideUpDownButtons="True" Value="{Binding ActiveRMLExtension.MaxMaxForceN}" HorizontalContentAlignment="Left" BorderBrush="{StaticResource MainWindow.Foreground}" Foreground="{StaticResource MainWindow.Foreground}" Margin="10 0 0 0"/>
                                        </StackPanel>

                                        <TextBlock Text="Elasticity (%)" ></TextBlock>
                                        <StackPanel Orientation="Horizontal">
                                            <mahapps:NumericUpDown HasDecimals="True" Minimum="0" Maximum="100" InterceptArrowKeys="True" HideUpDownButtons="True" Value="{Binding ActiveRMLExtension.MinElasticity}" HorizontalContentAlignment="Left" BorderBrush="{StaticResource MainWindow.Foreground}" Foreground="{StaticResource MainWindow.Foreground}" />
                                            <mahapps:NumericUpDown HasDecimals="True" Minimum="0" Maximum="100" InterceptArrowKeys="True" HideUpDownButtons="True" Value="{Binding ActiveRMLExtension.MaxElasticity}" HorizontalContentAlignment="Left" BorderBrush="{StaticResource MainWindow.Foreground}" Foreground="{StaticResource MainWindow.Foreground}" Margin="10 0 0 0"/>
                                        </StackPanel>

                                        <TextBlock Text="Tenacity (%)" ></TextBlock>
                                        <StackPanel Orientation="Horizontal">
                                            <mahapps:NumericUpDown HasDecimals="True" Minimum="0" Maximum="100" InterceptArrowKeys="True" HideUpDownButtons="True" Value="{Binding ActiveRMLExtension.MinTenacity}" HorizontalContentAlignment="Left" BorderBrush="{StaticResource MainWindow.Foreground}" Foreground="{StaticResource MainWindow.Foreground}" />
                                            <mahapps:NumericUpDown HasDecimals="True" Minimum="0" Maximum="100" InterceptArrowKeys="True" HideUpDownButtons="True" Value="{Binding ActiveRMLExtension.MaxTenacity}" HorizontalContentAlignment="Left" BorderBrush="{StaticResource MainWindow.Foreground}" Foreground="{StaticResource MainWindow.Foreground}" Margin="10 0 0 0"/>
                                        </StackPanel>

                                        <TextBlock Text="Finishing:" VerticalAlignment="Bottom" Margin=" 0 20 0 0"></TextBlock>
                                        <TextBox Text="{Binding ActiveRMLExtension.Finishing}" ></TextBox>

                                    </controls:TableGrid>
                                </DockPanel>
                            </Grid>
                        </materialDesign:Card>
                    </Grid>

                </UniformGrid>
                <Button Grid.Row="1"  HorizontalAlignment="Right" Width="170" Height="45" Margin="0 0 20 0" VerticalAlignment="Center" Command="{Binding SaveCommand}">
                    <StackPanel Orientation="Horizontal">
                        <materialDesign:PackIcon Kind="ContentSaveAll" Width="24" Height="24" />
                        <TextBlock VerticalAlignment="Center" Margin="10 0 0 0">SAVE</TextBlock>
                    </StackPanel>
                </Button>
            </Grid>
        </materialDesign:Card>
    </Grid>
</UserControl>
class="w"> public ObservableCollection<Configuration> History { get { return _history; } set { _history = value; RaisePropertyChangedAuto(); } } private Configuration _selectedHistoryConfiguration; /// <summary> /// Gets or sets the machine selected configuration from history. /// </summary> public Configuration SelectedHistoryConfiguration { get { return _selectedHistoryConfiguration; } set { _selectedHistoryConfiguration = value; RaisePropertyChangedAuto(); OnHistoryConfigurationSelected(); } } private String _filter; /// <summary> /// Gets or sets the configuration components filter. /// </summary> public String Filter { get { return _filter; } set { _filter = value; RaisePropertyChangedAuto(); OnFilterChanged(); } } #endregion #region Commands /// <summary> /// Gets or sets the save command. /// </summary> public RelayCommand SaveCommand { get; set; } /// <summary> /// Gets or sets the add ids command. /// </summary> public RelayCommand AddIdsCommand { get; set; } /// <summary> /// Gets or sets the remove ids command. /// </summary> public RelayCommand RemoveIdsCommand { get; set; } /// <summary> /// Gets or sets the set version configuration command. /// </summary> public RelayCommand SetVersionConfigurationCommand { get; set; } /// <summary> /// Gets or sets the set as default command. /// </summary> public RelayCommand SetAsDefaultCommand { get; set; } #endregion #region Constructors public MainViewVM() { } /// <summary> /// Initializes a new instance of the <see cref="MainViewVM"/> class. /// </summary> public MainViewVM(INotificationProvider notification) { _notification = notification; Adapter = ObservablesEntitiesAdapter.Instance; Configuration = new Configuration(); Configuration.Name = "Untitled"; Machine = new Machine(); Machine.Configuration = Configuration; SaveCommand = new RelayCommand(Save, (x) => !_isSaving); AddIdsCommand = new RelayCommand(AddIds, (x) => !_isSaving && Configuration.IdsPacks.Count < 8); RemoveIdsCommand = new RelayCommand(RemoveIds, (x) => !_isSaving && SelectedIds != null); SetVersionConfigurationCommand = new RelayCommand(SetVersionConfiguration, (x) => !_isSaving); SetAsDefaultCommand = new RelayCommand(SetAsDefaultConfiguration, (x) => !_isSaving); } #endregion #region Virtual Methods /// <summary> /// Called when the selected machine has changed. /// </summary> protected virtual void OnSelectedMachineChanged() { if (SelectedMachine != null) { Machine = SelectedMachine.CloneEntity(); Configuration = Machine.Configuration.CloneConfiguration(); History = SelectedMachine.MachinesConfigurations.Select(x => x.Configuration).ToObservableCollection(); } else { History = new ObservableCollection<Configuration>(); } } /// <summary> /// Called when the history configuration has been selected /// </summary> protected virtual void OnHistoryConfigurationSelected() { if (SelectedHistoryConfiguration != null) { Configuration = SelectedHistoryConfiguration.CloneConfiguration(); } } /// <summary> /// Called when the filter has changed /// </summary> protected virtual void OnFilterChanged() { List<ICollectionView> collections = new List<ICollectionView>(); collections.Add(Adapter.ApplicationDisplayPanelVersionsViewSource); collections.Add(Adapter.ApplicationVersionsViewSource); collections.Add(Adapter.EmbeddedSoftwareVersionsViewSource); collections.Add(Adapter.EmbeddedFirmwareVersionsViewSource); collections.Add(Adapter.ApplicationOsVersionsViewSource); collections.Add(Adapter.ApplicationVersionsViewSource); collections.Add(Adapter.DispenserTypesViewSource); collections.Add(Adapter.CartridgeTypesViewSource); collections.Add(Adapter.LiquidTypesViewSource); collections.Add(Adapter.MidTankTypesViewSource); collections.Add(Adapter.HardwareVersionsViewSource); foreach (var collection in collections) { collection.Filter = (x) => { foreach (var prop in x.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(y => y.PropertyType == typeof(String))) { String value = prop.GetValue(x).ToStringSafe(); if (value != null) { if (value.ToLower().Contains(Filter.ToLower())) { return true; } } } return false; }; } } #endregion #region Drag Drop Handlers /// <summary> /// Drops the ids pack. /// </summary> /// <param name="idsPack1">The ids pack1.</param> /// <param name="idsPack2">The ids pack2.</param> public void DropIdsPack(IdsPack idsPack1, IdsPack idsPack2) { Configuration.IdsPacks.Swap(idsPack1, idsPack2); } /// <summary> /// Drops the touch panel. /// </summary> /// <param name="applicationDisplayPanelVersion">The application display panel version.</param> public void DropTouchPanel(ApplicationDisplayPanelVersion applicationDisplayPanelVersion) { Configuration.ApplicationDisplayPanelVersion = applicationDisplayPanelVersion; Configuration.ApplicationDisplayPanelVersionGuid = applicationDisplayPanelVersion.Guid; } /// <summary> /// Drops the application firmware version. /// </summary> /// <param name="applicationFirmwareVersion">The application firmware version.</param> public void DropApplicationFirmwareVersion(ApplicationFirmwareVersion applicationFirmwareVersion) { Configuration.ApplicationFirmwareVersion = applicationFirmwareVersion; Configuration.ApplicationFirmwareVersionGuid = applicationFirmwareVersion.Guid; } /// <summary> /// Drops the application version. /// </summary> /// <param name="applicationVersion">The application version.</param> public void DropApplicationVersion(ApplicationVersion applicationVersion) { Configuration.ApplicationVersion = applicationVersion; Configuration.ApplicationVersionGuid = applicationVersion.Guid; } /// <summary> /// Drops the hardware version. /// </summary> /// <param name="hardwareVersion">The hardware version.</param> public void DropHardwareVersion(HardwareVersion hardwareVersion) { Configuration.HardwareVersion = hardwareVersion; Configuration.HardwareVersionGuid = hardwareVersion.Guid; } /// <summary> /// Drops the embedded firmware. /// </summary> /// <param name="embeddedFirmwareVersion">The embedded firmware version.</param> public void DropEmbeddedFirmware(EmbeddedFirmwareVersion embeddedFirmwareVersion) { Configuration.EmbeddedFirmwareVersion = embeddedFirmwareVersion; Configuration.EmbeddedFirmwareVersionGuid = embeddedFirmwareVersion.Guid; } /// <summary> /// Drops the embedded software. /// </summary> /// <param name="embeddedSoftwareVersion">The embedded software version.</param> public void DropEmbeddedSoftware(EmbeddedSoftwareVersion embeddedSoftwareVersion) { Configuration.EmbeddedSoftwareVersion = embeddedSoftwareVersion; Configuration.EmbeddedSoftwareVersionGuid = embeddedSoftwareVersion.Guid; } /// <summary> /// Drops the application os version. /// </summary> /// <param name="applicationOsVersion">The application os version.</param> public void DropApplicationOsVersion(ApplicationOsVersion applicationOsVersion) { Configuration.ApplicationOsVersion = applicationOsVersion; Configuration.ApplicationVersionGuid = applicationOsVersion.Guid; } /// <summary> /// Drops the type of the cartridge. /// </summary> /// <param name="cartridgeType">Type of the cartridge.</param> /// <param name="idsPack">The ids pack.</param> public void DropCartridgeType(CartridgeType cartridgeType, IdsPack idsPack) { idsPack.CartridgeType = cartridgeType; idsPack.CartridgeTypeGuid = cartridgeType.Guid; } /// <summary> /// Drops the dispenser. /// </summary> /// <param name="dispenserType">The dispenser.</param> /// <param name="idsPack">The ids pack.</param> public void DropDispenserType(DispenserType dispenserType, IdsPack idsPack) { idsPack.DispenserType = dispenserType; idsPack.DispenserTypeGuid = dispenserType.Guid; } /// <summary> /// Drops the type of the mid tank. /// </summary> /// <param name="midTankType">Type of the mid tank.</param> /// <param name="idsPack">The ids pack.</param> public void DropMidTankType(MidTankType midTankType, IdsPack idsPack) { idsPack.MidTankType = midTankType; idsPack.MidTankTypeGuid = midTankType.Guid; } /// <summary> /// Drops the type of the liquid. /// </summary> /// <param name="liquidType">Type of the liquid.</param> /// <param name="idsPack">The ids pack.</param> public void DropLiquidType(LiquidType liquidType, IdsPack idsPack) { idsPack.LiquidType = liquidType; idsPack.LiquidTypeGuid = liquidType.Guid; } /// <summary> /// Drops the ids formula. /// </summary> /// <param name="idsPackFormula">The ids pack formula.</param> /// <param name="idsPack">The ids pack.</param> /// <exception cref="NotImplementedException"></exception> public void DropIdsFormula(IdsPackFormula idsPackFormula, IdsPack idsPack) { idsPack.IdsPackFormula = idsPackFormula; idsPack.IdsPackFormulaGuid = idsPackFormula.Guid; } #endregion #region Private Methods /// <summary> /// Removes the selected IDS pack. /// </summary> private void RemoveIds() { Configuration.IdsPacks.Remove(SelectedIds); SelectedIds = null; } /// <summary> /// Adds a new IDS pack. /// </summary> private void AddIds() { Configuration.IdsPacks.Add(new IdsPack() { Configuration = Configuration }); InvalidateRelayCommands(); } /// <summary> /// Saves the current machine configuration. /// </summary> private async void Save() { foreach (var ids in Configuration.IdsPacks) { ids.PackIndex = Configuration.IdsPacks.IndexOf(ids); ids.Configuration = Configuration; ids.ConfigurationGuid = Configuration.Guid; } //Validate List<String> errors = new List<string>(); if (Machine.MachineVersion == null) { errors.Add("Machine version is required."); } if (Machine.Name.IsNullOrWhiteSpace()) { errors.Add("Machine name is required."); } if (Machine.Organization == null) { errors.Add("Machine organization is required."); } if (Machine.SerialNumber.IsNullOrWhiteSpace()) { errors.Add("Machine serial number is required."); } if (Configuration.Name.IsNullOrWhiteSpace()) { errors.Add("Configuration name is required."); } if (Configuration.ApplicationDisplayPanelVersion == null) { errors.Add("Touch Panel is required."); } if (Configuration.ApplicationFirmwareVersion == null) { errors.Add("Application firmware is required."); } if (Configuration.ApplicationOsVersion == null) { errors.Add("Application operation system is required."); } if (Configuration.ApplicationVersion == null) { errors.Add("Application version is required."); } if (Configuration.EmbeddedFirmwareVersion == null) { errors.Add("Embedded firmware is required."); } if (Configuration.EmbeddedSoftwareVersion == null) { errors.Add("Embedded software is required."); } if (Configuration.HardwareVersion == null) { errors.Add("Hardware version is required."); } foreach (var pack in Configuration.IdsPacks) { if (pack.LiquidType != null || pack.CartridgeType != null || pack.DispenserType != null || pack.IdsPackFormula != null || pack.MidTankType != null) { if (pack.Name.IsNullOrWhiteSpace()) { errors.Add(String.Format("Name is required on IDS pack number '{0}'.", Configuration.IdsPacks.IndexOf(pack) + 1)); continue; } if (pack.CartridgeType == null) { errors.Add(String.Format("Cartridge type is required on IDS pack '{0}'.", pack.Name)); } if (pack.DispenserType == null) { errors.Add(String.Format("Dispenser type is required on IDS pack '{0}'.", pack.Name)); } if (pack.LiquidType == null) { errors.Add(String.Format("Liquid type is required on IDS pack '{0}'.", pack.Name)); } if (pack.MidTankType == null) { errors.Add(String.Format("Mid Tank type is required on IDS pack '{0}'.", pack.Name)); } if (pack.IdsPackFormula == null) { errors.Add(String.Format("Formula type is required on IDS pack '{0}'.", pack.Name)); } } else { pack.IsEmpty = true; pack.Name = String.Empty; } } if (errors.Count > 0) { String errorsString = "Please fix the following validation errors before trying to save." + Environment.NewLine + Environment.NewLine; errorsString += String.Join(Environment.NewLine, errors); _notification.ShowError(errorsString); return; } //Validate _isSaving = true; InvalidateRelayCommands(); try { using (_notification.PushTaskItem("Saving Machine Configuration...")) { if (!Adapter.Machines.ToList().Exists(x => x.SerialNumber.ToLower() == Machine.SerialNumber.ToLower())) { if (!_notification.ShowQuestion("The specified machine serial number does not exist. Do you wish to create a new machine?")) { return; } else { Machine.Configuration = Configuration; Configuration.CreationDate = DateTime.UtcNow; Machine.ProductionDate = DateTime.UtcNow; Machine.MachinesConfigurations.Add(new MachinesConfiguration() { Configuration = Configuration, Machine = Machine, }); await Machine.SaveAsync(Adapter.Context); Machine = Adapter.Machines.SingleOrDefault(x => x.Guid == Machine.Guid); Configuration = Machine.Configuration.CloneConfiguration(); } } else { var machine = Adapter.Machines.Single(x => x.SerialNumber.ToLower() == Machine.SerialNumber.ToLower()); //Set 'Real machine' parameters... bool add_history = History.Count == 0 || History.First().Name != Configuration.Name; machine.Name = Machine.Name; machine.SerialNumber = Machine.SerialNumber; machine.Organization = Machine.Organization; if (add_history) { machine.MachinesConfigurations.Add(new MachinesConfiguration() { Configuration = Configuration, Machine = machine }); } else { machine.Configuration.DefferedDelete(Adapter.Context); } machine.Configuration = Configuration; await machine.SaveAsync(Adapter.Context); Machine = Adapter.Machines.SingleOrDefault(x => x.Guid == machine.Guid); Configuration = Machine.Configuration.CloneConfiguration(); } SetHistory(Machine); Machine = Machine.CloneEntity(); } } catch (Exception ex) { _notification.ShowError("An error occurred while trying to save the configuration" + Environment.NewLine + ex.Message); } finally { _isSaving = false; InvalidateRelayCommands(); } } /// <summary> /// Sets the specified machine history. /// </summary> /// <param name="machine">The machine.</param> private void SetHistory(Machine machine) { History = machine.MachinesConfigurations.Select(x => x.Configuration).ToObservableCollection(); History.Insert(0, machine.Configuration); } /// <summary> /// Sets the current configuration to the selected machine version default configuration. /// </summary> private void SetVersionConfiguration() { if (Machine.MachineVersion != null) { Configuration = Machine.MachineVersion.DefaultConfiguration.CloneConfiguration(); } else { _notification.ShowError("No machine version selected."); } } /// <summary> /// Sets the current configuration as a default machine version configuration. /// </summary> private void SetAsDefaultConfiguration() { _notification.ShowModalDialog<MachineVersionDialogVM>(async (vm) => { try { using (_notification.PushTaskItem("Saving Default Configuration...")) { if (vm.SelectedVersion != null) { vm.SelectedVersion.DefaultConfiguration = Configuration.CloneConfiguration(); vm.SelectedVersion.DefaultConfigurationGuid = vm.SelectedVersion.DefaultConfiguration.Guid; await vm.SelectedVersion.SaveAsync(Adapter.Context); } else { MachineVersion newVersion = new MachineVersion(); newVersion.Version = vm.Version; newVersion.Name = vm.VersionName; newVersion.DefaultConfiguration = Configuration.CloneConfiguration(); newVersion.DefaultConfigurationGuid = newVersion.DefaultConfiguration.Guid; await newVersion.SaveAsync(Adapter.Context); } } } catch (Exception ex) { _notification.ShowError(ex.Message); } }, () => { }); } #endregion #region IStudioModuleVM public override void OnModuleRequest(params object[] args) { SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == (args[0] as Machine).Guid); } #endregion } }