Moved SERV template editing to separate grid within admin region
This commit is contained in:
parent
a1eb65c834
commit
582df11fa7
67
ENI2/Controls/SERVTemplatesControl.xaml
Normal file
67
ENI2/Controls/SERVTemplatesControl.xaml
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<UserControl x:Class="ENI2.Controls.SERVTemplatesControl"
|
||||||
|
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:ENI2.Controls"
|
||||||
|
xmlns:util="clr-namespace:ENI2.Util"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="1000">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="28" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Label Grid.Row="0" Content="SERV_Template" />
|
||||||
|
<GroupBox Header="" Grid.Row="1">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="28" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid Grid.Row="0">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="120" />
|
||||||
|
<ColumnDefinition Width="120" />
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Button x:Name="buttonSave" Grid.Column="0" Margin="2" Content="Save all changes" Click="buttonSave_Click" />
|
||||||
|
<Button x:Name="buttonAdd" Grid.Column="1" Margin="2" Content="Add new" Click="buttonAdd_Click" />
|
||||||
|
</Grid>
|
||||||
|
<local:ENIDataGrid Grid.Row="1" Margin="2,8,2,2" x:Name="dataGridSERVTemplates" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
||||||
|
SelectionMode="Extended" AutoGenerateColumns="False" CanUserAddRows="False"
|
||||||
|
CellEditEnding="dataGridSERVTemplates_CellEditEnding">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="Service name" Width="2*">
|
||||||
|
<DataGridTextColumn.Binding>
|
||||||
|
<Binding Path="ServiceName" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
|
||||||
|
<Binding.ValidationRules>
|
||||||
|
<util:StringValidationRule MaxLength="99" />
|
||||||
|
</Binding.ValidationRules>
|
||||||
|
</Binding>
|
||||||
|
</DataGridTextColumn.Binding>
|
||||||
|
</DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Service beneficiary" Width="2*">
|
||||||
|
<DataGridTextColumn.Binding>
|
||||||
|
<Binding Path="ServiceBeneficiary" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
|
||||||
|
<Binding.ValidationRules>
|
||||||
|
<util:StringValidationRule MaxLength="255" />
|
||||||
|
</Binding.ValidationRules>
|
||||||
|
</Binding>
|
||||||
|
</DataGridTextColumn.Binding>
|
||||||
|
</DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Service invoice recipient" Width="2*">
|
||||||
|
<DataGridTextColumn.Binding>
|
||||||
|
<Binding Path="ServiceInvoiceRecipient" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
|
||||||
|
<Binding.ValidationRules>
|
||||||
|
<util:StringValidationRule MaxLength="255" />
|
||||||
|
</Binding.ValidationRules>
|
||||||
|
</Binding>
|
||||||
|
</DataGridTextColumn.Binding>
|
||||||
|
</DataGridTextColumn>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</local:ENIDataGrid>
|
||||||
|
</Grid>
|
||||||
|
</GroupBox>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
131
ENI2/Controls/SERVTemplatesControl.xaml.cs
Normal file
131
ENI2/Controls/SERVTemplatesControl.xaml.cs
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
using bsmd.database;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
|
namespace ENI2.Controls
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for SERVTemplatesControl.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class SERVTemplatesControl : UserControl
|
||||||
|
{
|
||||||
|
private readonly ObservableCollection<SERV_Template> _templates = new ObservableCollection<SERV_Template>();
|
||||||
|
|
||||||
|
public SERVTemplatesControl()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
this.dataGridSERVTemplates.ItemsSource = _templates;
|
||||||
|
|
||||||
|
var view = CollectionViewSource.GetDefaultView(_templates);
|
||||||
|
view.SortDescriptions.Add(new SortDescription(nameof(SERV_Template.ServiceName), ListSortDirection.Ascending));
|
||||||
|
|
||||||
|
_ = LoadTemplatesAsync();
|
||||||
|
|
||||||
|
this.dataGridSERVTemplates.ContextMenu = new ContextMenu();
|
||||||
|
MenuItem addItem = new MenuItem
|
||||||
|
{
|
||||||
|
Header = Properties.Resources.textAdd,
|
||||||
|
Icon = new System.Windows.Controls.Image { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Resources/add.png")) }
|
||||||
|
};
|
||||||
|
addItem.Click += AddItem_Click;
|
||||||
|
this.dataGridSERVTemplates.ContextMenu.Items.Add(addItem);
|
||||||
|
|
||||||
|
MenuItem delItem = new MenuItem
|
||||||
|
{
|
||||||
|
Header = Properties.Resources.textDelete,
|
||||||
|
Icon = new System.Windows.Controls.Image { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Resources/delete.png")) }
|
||||||
|
};
|
||||||
|
delItem.Click += DelItem_Click;
|
||||||
|
this.dataGridSERVTemplates.ContextMenu.Items.Add(delItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadTemplatesAsync()
|
||||||
|
{
|
||||||
|
List<SERV_Template> items = await DBManagerAsync.GetSERVTemplatesAsync(true);
|
||||||
|
foreach (SERV_Template item in items)
|
||||||
|
{
|
||||||
|
_templates.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSave_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
_ = SaveTemplatesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAdd_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
AddNewTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dataGridSERVTemplates_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Row?.Item is SERV_Template item)
|
||||||
|
{
|
||||||
|
item.IsDirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddItem_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
AddNewTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void DelItem_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (this.dataGridSERVTemplates.SelectedItems.Count > 0)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Are you sure to delete the selected values?", Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) ==
|
||||||
|
MessageBoxResult.Yes)
|
||||||
|
{
|
||||||
|
var selectedItems = new List<SERV_Template>();
|
||||||
|
foreach (SERV_Template item in this.dataGridSERVTemplates.SelectedItems)
|
||||||
|
selectedItems.Add(item);
|
||||||
|
|
||||||
|
foreach (SERV_Template item in selectedItems)
|
||||||
|
{
|
||||||
|
int result = await DBManagerAsync.DeleteAsync(item);
|
||||||
|
if (result == 1 || item.IsNew)
|
||||||
|
{
|
||||||
|
_templates.Remove(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddNewTemplate()
|
||||||
|
{
|
||||||
|
var item = new SERV_Template
|
||||||
|
{
|
||||||
|
IsDirty = true
|
||||||
|
};
|
||||||
|
_templates.Add(item);
|
||||||
|
this.dataGridSERVTemplates.SelectedItem = item;
|
||||||
|
this.dataGridSERVTemplates.ScrollIntoView(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveTemplatesAsync()
|
||||||
|
{
|
||||||
|
int totalSaves = 0;
|
||||||
|
foreach (SERV_Template item in _templates)
|
||||||
|
{
|
||||||
|
if (item.IsNew || item.IsDirty)
|
||||||
|
{
|
||||||
|
totalSaves += await DBManagerAsync.SaveAsync(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalSaves > 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"{totalSaves} SERV templates saved", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -118,23 +118,6 @@
|
|||||||
<Image Source="../Resources/check.png" Margin="0,0,0,0" Height="20" Width="20" />
|
<Image Source="../Resources/check.png" Margin="0,0,0,0" Height="20" Width="20" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button Name="buttonEditTemplate" Grid.Column="4" Grid.Row="0" Margin="2" Click="buttonEditTemplate_Click" BorderThickness="0" Background="Transparent" ToolTip="Edit template">
|
|
||||||
<StackPanel Orientation="Horizontal">
|
|
||||||
<Image Source="../Resources/pencil.png" Margin="0,0,0,0" Height="20" Width="20" />
|
|
||||||
</StackPanel>
|
|
||||||
</Button>
|
|
||||||
<Button Name="buttonNewTemplate" Grid.Column="5" Grid.Row="0" Margin="2" Click="buttonNewTemplate_Click" BorderThickness="0" Background="Transparent" ToolTip="New template">
|
|
||||||
<StackPanel Orientation="Horizontal">
|
|
||||||
<Image Source="../Resources/document_plain_new.png" Margin="0,0,0,0" Height="20" Width="20" />
|
|
||||||
</StackPanel>
|
|
||||||
</Button>
|
|
||||||
<Button Name="buttonDeleteTemplate" Grid.Column="6" Grid.Row="0" Margin="2" Click="buttonDeleteTemplate_Click" BorderThickness="0" Background="Transparent" ToolTip="Delete template" IsEnabled="False">
|
|
||||||
<StackPanel Orientation="Horizontal">
|
|
||||||
<Image Source="../Resources/delete.png" Margin="0,0,0,0" Height="20" Width="20" />
|
|
||||||
</StackPanel>
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
<enictrl:ENIDataGrid Grid.Row="1" x:Name="dataGridSERV" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
<enictrl:ENIDataGrid Grid.Row="1" x:Name="dataGridSERV" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
||||||
AutoGenerateColumns="False" Margin="0,5,0,0">
|
AutoGenerateColumns="False" Margin="0,5,0,0">
|
||||||
|
|||||||
@ -176,11 +176,7 @@ namespace ENI2.DetailViewControls
|
|||||||
Trace.WriteLine($"{_servTemplates.Count} SERV templates loaded");
|
Trace.WriteLine($"{_servTemplates.Count} SERV templates loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.comboBoxGroup.ItemsSource = _servTemplates;
|
this.comboBoxGroup.ItemsSource = _servTemplates;
|
||||||
|
|
||||||
this.buttonDeleteTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
|
|
||||||
this.buttonEditTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
|
|
||||||
this.buttonNewTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -386,8 +382,7 @@ namespace ENI2.DetailViewControls
|
|||||||
private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if(this.comboBoxGroup.SelectedItem is SERV_Template st)
|
if(this.comboBoxGroup.SelectedItem is SERV_Template st)
|
||||||
{
|
{
|
||||||
this.buttonDeleteTemplate.IsEnabled = true;
|
|
||||||
this.buttonSetTemplate.IsEnabled = true;
|
this.buttonSetTemplate.IsEnabled = true;
|
||||||
this._currentTemplate = st;
|
this._currentTemplate = st;
|
||||||
}
|
}
|
||||||
@ -422,56 +417,6 @@ namespace ENI2.DetailViewControls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonNewTemplate_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
SERV_Template newTemplate = new SERV_Template();
|
|
||||||
EditSERVDialog esd = new EditSERVDialog();
|
|
||||||
esd.AddVisible = false;
|
|
||||||
esd.SERV_Template = newTemplate;
|
|
||||||
if(esd.ShowDialog() ?? false)
|
|
||||||
{
|
|
||||||
_ = DBManagerAsync.SaveAsync(esd.SERV_Template);
|
|
||||||
this.comboBoxGroup.ItemsSource = null;
|
|
||||||
_servTemplates.Add(newTemplate);
|
|
||||||
_servTemplates.Sort();
|
|
||||||
this.comboBoxGroup.ItemsSource = _servTemplates;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonEditTemplate_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
if (this.comboBoxGroup.SelectedItem is SERV_Template st)
|
|
||||||
{
|
|
||||||
EditSERVDialog editSERVDialog = new EditSERVDialog();
|
|
||||||
editSERVDialog.AddVisible = false;
|
|
||||||
editSERVDialog.SERV_Template = st;
|
|
||||||
if (editSERVDialog.ShowDialog() ?? false)
|
|
||||||
{
|
|
||||||
_ = DBManagerAsync.SaveAsync(st);
|
|
||||||
this.comboBoxGroup.ItemsSource = null;
|
|
||||||
_servTemplates.Sort();
|
|
||||||
this.comboBoxGroup.ItemsSource = _servTemplates;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonDeleteTemplate_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
if (_currentTemplate != null)
|
|
||||||
{
|
|
||||||
if (MessageBox.Show("Delete this template?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
|
|
||||||
{
|
|
||||||
this.comboBoxGroup.SelectedItem = null;
|
|
||||||
this.comboBoxGroup.ItemsSource = null;
|
|
||||||
_ = DBManagerAsync.DeleteAsync(_currentTemplate);
|
|
||||||
_servTemplates.Remove(_currentTemplate);
|
|
||||||
this.buttonDeleteTemplate.IsEnabled = false;
|
|
||||||
this.comboBoxGroup.ItemsSource = _servTemplates;
|
|
||||||
this.buttonSetTemplate.IsEnabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region other event handler
|
#region other event handler
|
||||||
|
|||||||
@ -331,18 +331,21 @@
|
|||||||
<Compile Include="Controls\ValueMappingsControl.xaml.cs">
|
<Compile Include="Controls\ValueMappingsControl.xaml.cs">
|
||||||
<DependentUpon>ValueMappingsControl.xaml</DependentUpon>
|
<DependentUpon>ValueMappingsControl.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Controls\HazardMaterialControl.xaml.cs">
|
<Compile Include="Controls\HazardMaterialControl.xaml.cs">
|
||||||
<DependentUpon>HazardMaterialControl.xaml</DependentUpon>
|
<DependentUpon>HazardMaterialControl.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Controls\PortAreaControl.xaml.cs">
|
<Compile Include="Controls\PortAreaControl.xaml.cs">
|
||||||
<DependentUpon>PortAreaControl.xaml</DependentUpon>
|
<DependentUpon>PortAreaControl.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Controls\LADG_NST2007Control.xaml.cs">
|
<Compile Include="Controls\LADG_NST2007Control.xaml.cs">
|
||||||
<DependentUpon>LADG_NST2007Control.xaml</DependentUpon>
|
<DependentUpon>LADG_NST2007Control.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Controls\WASExemptionsControl.xaml.cs">
|
<Compile Include="Controls\SERVTemplatesControl.xaml.cs">
|
||||||
<DependentUpon>WASExemptionsControl.xaml</DependentUpon>
|
<DependentUpon>SERVTemplatesControl.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Controls\WASExemptionsControl.xaml.cs">
|
||||||
|
<DependentUpon>WASExemptionsControl.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="EditControls\ChangePasswordDialog.xaml.cs">
|
<Compile Include="EditControls\ChangePasswordDialog.xaml.cs">
|
||||||
<DependentUpon>ChangePasswordDialog.xaml</DependentUpon>
|
<DependentUpon>ChangePasswordDialog.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -662,22 +665,26 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
<Page Include="Controls\HazardMaterialControl.xaml">
|
<Page Include="Controls\HazardMaterialControl.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
<Page Include="Controls\PortAreaControl.xaml">
|
<Page Include="Controls\PortAreaControl.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
<Page Include="Controls\LADG_NST2007Control.xaml">
|
<Page Include="Controls\LADG_NST2007Control.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
<Page Include="Controls\WASExemptionsControl.xaml">
|
<Page Include="Controls\SERVTemplatesControl.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="Controls\WASExemptionsControl.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="ControlTemplates.xaml">
|
<Page Include="ControlTemplates.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
@ -1274,4 +1281,4 @@
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
||||||
@ -118,6 +118,11 @@
|
|||||||
<Image Source="Resources/containership.png" />
|
<Image Source="Resources/containership.png" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
<MenuItem x:Name="menuItemSERVTemplates" Header="SERV_Template" Click="radioButton_Click">
|
||||||
|
<MenuItem.Icon>
|
||||||
|
<Image Source="Resources/document_down.png" />
|
||||||
|
</MenuItem.Icon>
|
||||||
|
</MenuItem>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem x:Name="menuItemMaersk" Header="{x:Static p:Resources.textPOLists}" Click="radioButton_Click" Visibility="Hidden" />
|
<MenuItem x:Name="menuItemMaersk" Header="{x:Static p:Resources.textPOLists}" Click="radioButton_Click" Visibility="Hidden" />
|
||||||
<MenuItem x:Name="menuItemValueMappings" Header="{x:Static p:Resources.textExcelValueMappings}" Click="radioButton_Click" Visibility="Hidden" />
|
<MenuItem x:Name="menuItemValueMappings" Header="{x:Static p:Resources.textExcelValueMappings}" Click="radioButton_Click" Visibility="Hidden" />
|
||||||
|
|||||||
@ -41,9 +41,10 @@ namespace ENI2
|
|||||||
private CompareExcelDialog compareExcelDialog;
|
private CompareExcelDialog compareExcelDialog;
|
||||||
private EasyPeasyControl easyPeasyControl;
|
private EasyPeasyControl easyPeasyControl;
|
||||||
private WASExemptionsControl wasExemptionsControl;
|
private WASExemptionsControl wasExemptionsControl;
|
||||||
private HazardMaterialControl hazardMaterialControl;
|
private HazardMaterialControl hazardMaterialControl;
|
||||||
private PortAreaControl portAreaControl;
|
private PortAreaControl portAreaControl;
|
||||||
private LADG_NST2007Control ladgNst2007Control;
|
private LADG_NST2007Control ladgNst2007Control;
|
||||||
|
private SERVTemplatesControl servTemplatesControl;
|
||||||
|
|
||||||
private bool dbConnected;
|
private bool dbConnected;
|
||||||
private readonly ScaleTransform _transform = new ScaleTransform(1.0, 1.0);
|
private readonly ScaleTransform _transform = new ScaleTransform(1.0, 1.0);
|
||||||
@ -361,15 +362,23 @@ namespace ENI2
|
|||||||
}
|
}
|
||||||
this.rootContainer.Children.Add(this.portAreaControl);
|
this.rootContainer.Children.Add(this.portAreaControl);
|
||||||
}
|
}
|
||||||
else if (sender == this.menuItemLADGNST2007)
|
else if (sender == this.menuItemLADGNST2007)
|
||||||
{
|
{
|
||||||
if (this.ladgNst2007Control == null)
|
if (this.ladgNst2007Control == null)
|
||||||
{
|
{
|
||||||
this.ladgNst2007Control = new LADG_NST2007Control();
|
this.ladgNst2007Control = new LADG_NST2007Control();
|
||||||
}
|
}
|
||||||
this.rootContainer.Children.Add(this.ladgNst2007Control);
|
this.rootContainer.Children.Add(this.ladgNst2007Control);
|
||||||
}
|
}
|
||||||
}
|
else if (sender == this.menuItemSERVTemplates)
|
||||||
|
{
|
||||||
|
if (this.servTemplatesControl == null)
|
||||||
|
{
|
||||||
|
this.servTemplatesControl = new SERVTemplatesControl();
|
||||||
|
}
|
||||||
|
this.rootContainer.Children.Add(this.servTemplatesControl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void buttonCompareSheets_Click(object sender, RoutedEventArgs ev)
|
private void buttonCompareSheets_Click(object sender, RoutedEventArgs ev)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -200,22 +200,6 @@
|
|||||||
<Image Source="../Resources/check.png" Margin="0,0,0,0" Height="20" Width="20" />
|
<Image Source="../Resources/check.png" Margin="0,0,0,0" Height="20" Width="20" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</Button>
|
||||||
<Button Name="buttonEditSERVTemplate" Grid.Column="2" Grid.Row="0" Margin="2" Click="buttonEditSERVTemplate_Click" BorderThickness="0" Background="Transparent" ToolTip="Edit template">
|
|
||||||
<StackPanel Orientation="Horizontal">
|
|
||||||
<Image Source="../Resources/pencil.png" Margin="0,0,0,0" Height="20" Width="20" />
|
|
||||||
</StackPanel>
|
|
||||||
</Button>
|
|
||||||
<Button Name="buttonNewSERVTemplate" Grid.Column="3" Grid.Row="0" Margin="2" Click="buttonNewSERVTemplate_Click" BorderThickness="0" Background="Transparent" ToolTip="New template">
|
|
||||||
<StackPanel Orientation="Horizontal">
|
|
||||||
<Image Source="../Resources/document_plain_new.png" Margin="0,0,0,0" Height="20" Width="20" />
|
|
||||||
</StackPanel>
|
|
||||||
</Button>
|
|
||||||
<Button Name="buttonDeleteSERVTemplate" Grid.Column="4" Grid.Row="0" Margin="2" Click="buttonDeleteSERVTemplate_Click" BorderThickness="0" Background="Transparent" ToolTip="Delete template" IsEnabled="False">
|
|
||||||
<StackPanel Orientation="Horizontal">
|
|
||||||
<Image Source="../Resources/delete.png" Margin="0,0,0,0" Height="20" Width="20" />
|
|
||||||
</StackPanel>
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
<GroupBox Name="servGroupBox" Header="{x:Static p:Resources.textServ}" Grid.Row="16" Grid.Column="0" Grid.ColumnSpan="3">
|
<GroupBox Name="servGroupBox" Header="{x:Static p:Resources.textServ}" Grid.Row="16" Grid.Column="0" Grid.ColumnSpan="3">
|
||||||
<enictrl:ENIDataGrid x:Name="dataGridSERV" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
<enictrl:ENIDataGrid x:Name="dataGridSERV" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
||||||
|
|||||||
@ -215,11 +215,7 @@ namespace ENI2.SheetDisplayControls
|
|||||||
Trace.WriteLine($"{_servTemplates.Count} SERV templates loaded");
|
Trace.WriteLine($"{_servTemplates.Count} SERV templates loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.comboBoxGroup.ItemsSource = _servTemplates;
|
this.comboBoxGroup.ItemsSource = _servTemplates;
|
||||||
|
|
||||||
this.buttonDeleteSERVTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
|
|
||||||
this.buttonEditSERVTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
|
|
||||||
this.buttonNewSERVTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -1070,8 +1066,7 @@ namespace ENI2.SheetDisplayControls
|
|||||||
private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (this.comboBoxGroup.SelectedItem is SERV_Template st)
|
if (this.comboBoxGroup.SelectedItem is SERV_Template st)
|
||||||
{
|
{
|
||||||
this.buttonDeleteSERVTemplate.IsEnabled = true;
|
|
||||||
this.buttonSetSERVTemplate.IsEnabled = true;
|
this.buttonSetSERVTemplate.IsEnabled = true;
|
||||||
this._currentSERVTemplate = st;
|
this._currentSERVTemplate = st;
|
||||||
}
|
}
|
||||||
@ -1104,57 +1099,7 @@ namespace ENI2.SheetDisplayControls
|
|||||||
this.SublistElementChanged(Message.NotificationClass.SERV);
|
this.SublistElementChanged(Message.NotificationClass.SERV);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonEditSERVTemplate_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
if (this.comboBoxGroup.SelectedItem is SERV_Template st)
|
|
||||||
{
|
|
||||||
EditSERVDialog editSERVDialog = new EditSERVDialog();
|
|
||||||
editSERVDialog.AddVisible = false;
|
|
||||||
editSERVDialog.SERV_Template = st;
|
|
||||||
if (editSERVDialog.ShowDialog() ?? false)
|
|
||||||
{
|
|
||||||
_ = DBManagerAsync.SaveAsync(st);
|
|
||||||
this.comboBoxGroup.ItemsSource = null;
|
|
||||||
_servTemplates.Sort();
|
|
||||||
this.comboBoxGroup.ItemsSource = _servTemplates;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonNewSERVTemplate_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
SERV_Template newTemplate = new SERV_Template();
|
|
||||||
EditSERVDialog esd = new EditSERVDialog();
|
|
||||||
esd.AddVisible = false;
|
|
||||||
esd.SERV_Template = newTemplate;
|
|
||||||
if (esd.ShowDialog() ?? false)
|
|
||||||
{
|
|
||||||
_ = DBManagerAsync.SaveAsync(esd.SERV_Template);
|
|
||||||
this.comboBoxGroup.ItemsSource = null;
|
|
||||||
_servTemplates.Add(newTemplate);
|
|
||||||
_servTemplates.Sort();
|
|
||||||
this.comboBoxGroup.ItemsSource = _servTemplates;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonDeleteSERVTemplate_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
if (_currentSERVTemplate != null)
|
|
||||||
{
|
|
||||||
if (MessageBox.Show("Delete this template?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
|
|
||||||
{
|
|
||||||
this.comboBoxGroup.SelectedItem = null;
|
|
||||||
this.comboBoxGroup.ItemsSource = null;
|
|
||||||
_ = DBManagerAsync.DeleteAsync(_currentTemplate);
|
|
||||||
_servTemplates.Remove(_currentSERVTemplate);
|
|
||||||
this.buttonDeleteSERVTemplate.IsEnabled = false;
|
|
||||||
this.comboBoxGroup.ItemsSource = _servTemplates;
|
|
||||||
this.buttonSetSERVTemplate.IsEnabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@ -18,10 +18,12 @@ namespace bsmd.database
|
|||||||
private static readonly ILog _log = LogManager.GetLogger(typeof(DBManagerAsync));
|
private static readonly ILog _log = LogManager.GetLogger(typeof(DBManagerAsync));
|
||||||
private static readonly SemaphoreSlim _portAreaLoadLock = new SemaphoreSlim(1, 1);
|
private static readonly SemaphoreSlim _portAreaLoadLock = new SemaphoreSlim(1, 1);
|
||||||
private static readonly SemaphoreSlim _ladgNst2007LoadLock = new SemaphoreSlim(1, 1);
|
private static readonly SemaphoreSlim _ladgNst2007LoadLock = new SemaphoreSlim(1, 1);
|
||||||
|
private static readonly SemaphoreSlim _servTemplateLoadLock = new SemaphoreSlim(1, 1);
|
||||||
private static List<PortArea> _allPortAreaRows;
|
private static List<PortArea> _allPortAreaRows;
|
||||||
private static Dictionary<string, PortArea> _allPortAreasByCode;
|
private static Dictionary<string, PortArea> _allPortAreasByCode;
|
||||||
private static List<LADG_NST2007> _allLADGNST2007Rows;
|
private static List<LADG_NST2007> _allLADGNST2007Rows;
|
||||||
private static Dictionary<string, LADG_NST2007> _allLADGNST2007ByDescription;
|
private static Dictionary<string, LADG_NST2007> _allLADGNST2007ByDescription;
|
||||||
|
private static List<SERV_Template> _allSERVTemplates;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -43,6 +45,8 @@ namespace bsmd.database
|
|||||||
InvalidatePortAreaCache();
|
InvalidatePortAreaCache();
|
||||||
if ((result == 1) && (entity is LADG_NST2007))
|
if ((result == 1) && (entity is LADG_NST2007))
|
||||||
InvalidateLADGNST2007Cache();
|
InvalidateLADGNST2007Cache();
|
||||||
|
if ((result == 1) && (entity is SERV_Template))
|
||||||
|
InvalidateSERVTemplatesCache();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +62,8 @@ namespace bsmd.database
|
|||||||
InvalidatePortAreaCache();
|
InvalidatePortAreaCache();
|
||||||
if ((result == 1) && (entity is LADG_NST2007))
|
if ((result == 1) && (entity is LADG_NST2007))
|
||||||
InvalidateLADGNST2007Cache();
|
InvalidateLADGNST2007Cache();
|
||||||
|
if ((result == 1) && (entity is SERV_Template))
|
||||||
|
InvalidateSERVTemplatesCache();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,13 +197,15 @@ namespace bsmd.database
|
|||||||
return (await at.LoadListAsync(reader)).ConvertAll(x => (AGNT_Template)x);
|
return (await at.LoadListAsync(reader)).ConvertAll(x => (AGNT_Template)x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<SERV_Template>> GetSERVTemplatesAsync()
|
public static async Task<List<SERV_Template>> GetSERVTemplatesAsync(bool forceReload = false)
|
||||||
{
|
{
|
||||||
SqlCommand cmd = new SqlCommand();
|
await EnsureSERVTemplatesLoadedAsync(forceReload);
|
||||||
SERV_Template st = new SERV_Template();
|
return new List<SERV_Template>(_allSERVTemplates);
|
||||||
st.PrepareLoadCommand(cmd, Message.LoadFilter.ALL);
|
}
|
||||||
SqlDataReader reader = await PerformCommandAsync(cmd);
|
|
||||||
return (await st.LoadListAsync(reader)).ConvertAll(x => (SERV_Template)x);
|
public static void InvalidateSERVTemplatesCache()
|
||||||
|
{
|
||||||
|
_allSERVTemplates = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -306,6 +314,32 @@ namespace bsmd.database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task EnsureSERVTemplatesLoadedAsync(bool forceReload)
|
||||||
|
{
|
||||||
|
if (forceReload)
|
||||||
|
InvalidateSERVTemplatesCache();
|
||||||
|
|
||||||
|
if (_allSERVTemplates != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
await _servTemplateLoadLock.WaitAsync();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_allSERVTemplates != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SqlCommand cmd = new SqlCommand();
|
||||||
|
SERV_Template st = new SERV_Template();
|
||||||
|
st.PrepareLoadCommand(cmd, Message.LoadFilter.ALL);
|
||||||
|
SqlDataReader reader = await PerformCommandAsync(cmd);
|
||||||
|
_allSERVTemplates = (await st.LoadListAsync(reader)).ConvertAll(x => (SERV_Template)x);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_servTemplateLoadLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region async DB access methods
|
#region async DB access methods
|
||||||
|
|||||||
@ -5,9 +5,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace bsmd.database
|
namespace bsmd.database
|
||||||
{
|
{
|
||||||
@ -110,7 +107,6 @@ namespace bsmd.database
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region IComparable implementation
|
#region IComparable implementation
|
||||||
|
|
||||||
public int CompareTo(object obj)
|
public int CompareTo(object obj)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user