Grid Control für ValueMappings mit allerlei FUntkionen. tut noch nicht alles
This commit is contained in:
parent
1f7ada5c58
commit
07215858fe
58
ENI2/Controls/ValueMappingsControl.xaml
Normal file
58
ENI2/Controls/ValueMappingsControl.xaml
Normal file
@ -0,0 +1,58 @@
|
||||
<UserControl x:Class="ENI2.Controls.ValueMappingsControl"
|
||||
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:p="clr-namespace:ENI2.Properties"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800" Loaded="UserControl_Loaded">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Label Grid.Row="0" Content="{x:Static p:Resources.textExcelValueMappings}" />
|
||||
<GroupBox Name="groupBoxRP" Header="" Grid.Row="1">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="40" />
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="40" />
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="50" />
|
||||
<ColumnDefinition Width="30" />
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition Width="80" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Content="Type" Grid.Column="0" />
|
||||
<ComboBox Margin="2" Grid.Column="1" x:Name="comboBoxType" SelectionChanged="comboBoxType_SelectionChanged" />
|
||||
|
||||
<local:BusyControl x:Name="busyControl" Grid.Column="2" />
|
||||
<Button x:Name="buttonSave" Grid.Column="6" Margin="2" Content="Save all changes" Click="buttonSave_Click" />
|
||||
<Button x:Name="buttonImport" Grid.Column="9" Margin="2" Content="Import" Click="buttonImport_Click" IsEnabled="False" />
|
||||
<Button x:Name="buttonExport" Grid.Column="10" Margin="2" Content="Export" Click="buttonExport_Click" IsEnabled="False" />
|
||||
|
||||
</Grid>
|
||||
<local:ENIDataGrid Grid.Row="1" Margin="2,8,2,2" x:Name="dataGridValueMappings" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
||||
SelectionMode="Extended" AutoGenerateColumns="False" CellEditEnding="dataGridValueMappings_CellEditEnding" CanUserAddRows="True"
|
||||
MouseDoubleClick="dataGridValueMappings_MouseDoubleClick" BeginningEdit="dataGridValueMappings_BeginningEdit">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn x:Name="columnKey" Header="Key" Binding="{Binding Key, Mode=TwoWay}" IsReadOnly="False" />
|
||||
<DataGridTextColumn x:Name="columnValue" Header="Value" Binding="{Binding Value, Mode=TwoWay}" IsReadOnly="False" />
|
||||
<DataGridTextColumn Header="Created" Binding="{Binding Created}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Changed" Binding="{Binding Changed}" IsReadOnly="True" />
|
||||
</DataGrid.Columns>
|
||||
</local:ENIDataGrid>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
143
ENI2/Controls/ValueMappingsControl.xaml.cs
Normal file
143
ENI2/Controls/ValueMappingsControl.xaml.cs
Normal file
@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
using bsmd.database;
|
||||
|
||||
namespace ENI2.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ValueMappingsControl.xaml
|
||||
/// </summary>
|
||||
public partial class ValueMappingsControl : UserControl
|
||||
{
|
||||
private ObservableCollection<ValueMapping> _mappings = new ObservableCollection<ValueMapping>();
|
||||
private DataGridCellInfo activeCellAtEdit;
|
||||
|
||||
public ValueMappingsControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.comboBoxType.ItemsSource = Enum.GetValues(typeof(ValueMapping.MappingType)).Cast<ValueMapping.MappingType>();
|
||||
this.dataGridValueMappings.ItemsSource = _mappings;
|
||||
|
||||
this.dataGridValueMappings.ContextMenu = new ContextMenu();
|
||||
MenuItem addItem = new MenuItem
|
||||
{
|
||||
Header = Properties.Resources.textAdd,
|
||||
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/add.png")) }
|
||||
};
|
||||
|
||||
addItem.Click += AddItem_Click;
|
||||
this.dataGridValueMappings.ContextMenu.Items.Add(addItem);
|
||||
|
||||
MenuItem delItem = new MenuItem
|
||||
{
|
||||
Header = Properties.Resources.textAdd,
|
||||
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/delete.png")) }
|
||||
};
|
||||
|
||||
delItem.Click += DelItem_Click;
|
||||
this.dataGridValueMappings.ContextMenu.Items.Add(delItem);
|
||||
}
|
||||
|
||||
private async void DelItem_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ValueMapping vm = this.dataGridValueMappings.SelectedItem as ValueMapping;
|
||||
if(vm != null)
|
||||
{
|
||||
if(MessageBox.Show($"Are you sure to delete {vm.Key} -> {vm.Value}?", Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) ==
|
||||
MessageBoxResult.Yes)
|
||||
{
|
||||
int result = await DBManagerAsync.DeleteAsync(vm);
|
||||
if(result == 1)
|
||||
{
|
||||
_mappings.Remove(vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddItem_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ValueMapping vm = new ValueMapping();
|
||||
_mappings.Add(vm);
|
||||
}
|
||||
|
||||
private void dataGridValueMappings_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
|
||||
{
|
||||
// we need to check that there are no keys entered twice or changed into something that is already here
|
||||
if(e.Column == columnKey)
|
||||
{
|
||||
TextBox t = e.EditingElement as TextBox;
|
||||
string editedCellValue = t.Text;
|
||||
ValueMapping editedMapping = e.Row.Item as ValueMapping;
|
||||
editedMapping.IsDirty = true;
|
||||
foreach(ValueMapping vm in _mappings)
|
||||
{
|
||||
if (vm.Key == editedCellValue)
|
||||
e.Cancel = true; // hopefully this avoids writing back to the model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dataGridValueMappings_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void buttonImport_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void buttonExport_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private async void comboBoxType_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
this._mappings.Clear();
|
||||
|
||||
if(this.comboBoxType.SelectedItem != null)
|
||||
{
|
||||
ValueMapping.MappingType mappingType = (ValueMapping.MappingType)this.comboBoxType.SelectedItem;
|
||||
List<ValueMapping> mappings = await DBManagerAsync.LoadValuesForType(mappingType);
|
||||
foreach (ValueMapping vm in mappings)
|
||||
_mappings.Add(vm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void dataGridValueMappings_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
|
||||
{
|
||||
this.activeCellAtEdit = this.dataGridValueMappings.CurrentCell;
|
||||
}
|
||||
|
||||
private async void buttonSave_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
foreach(ValueMapping vm in _mappings)
|
||||
{
|
||||
if (vm.Key.IsNullOrEmpty()) continue;
|
||||
if (vm.IsNew || vm.IsDirty)
|
||||
await DBManagerAsync.SaveAsync(vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -234,6 +234,9 @@
|
||||
<Compile Include="Controls\MaerskOverviewControl.xaml.cs">
|
||||
<DependentUpon>MaerskOverviewControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\ValueMappingsControl.xaml.cs">
|
||||
<DependentUpon>ValueMappingsControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="EditControls\CompareExcelDialog.xaml.cs">
|
||||
<DependentUpon>CompareExcelDialog.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@ -494,6 +497,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Controls\ValueMappingsControl.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="ControlTemplates.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@ -92,6 +92,7 @@
|
||||
<MenuItem x:Name="menuItemStatus" Header="{x:Static p:Resources.textServerStatus}" Click="radioButton_Click" />
|
||||
<MenuItem x:Name="menuItemUserAdministration" Header="{x:Static p:Resources.textUserAdministration}" 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="labelStatusId" />
|
||||
<MenuItem Header="Help" HorizontalAlignment="Right">
|
||||
<MenuItem Header="About" Click="buttonAbout_Click">
|
||||
|
||||
@ -35,6 +35,7 @@ namespace ENI2
|
||||
|
||||
private ReportingPartyControl rpControl;
|
||||
private MaerskOverviewControl moControl;
|
||||
private ValueMappingsControl vmControl;
|
||||
private ServerStatusControl statusControl;
|
||||
private readonly SucheControl sucheControl;
|
||||
private CompareExcelDialog compareExcelDialog;
|
||||
@ -304,6 +305,14 @@ namespace ENI2
|
||||
}
|
||||
this.rootContainer.Children.Add(this.statusControl);
|
||||
}
|
||||
else if(sender == this.menuItemValueMappings)
|
||||
{
|
||||
if(this.vmControl == null)
|
||||
{
|
||||
this.vmControl = new ValueMappingsControl();
|
||||
}
|
||||
this.rootContainer.Children.Add(this.vmControl);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCompareSheets_Click(object sender, RoutedEventArgs ev)
|
||||
@ -663,7 +672,7 @@ namespace ENI2
|
||||
App.UserId = this.userEntity.Id;
|
||||
ReportingParty.CurrentReportingParty = this.userEntity;
|
||||
this.menuItemMaersk.Visibility = Visibility.Visible;
|
||||
|
||||
this.menuItemValueMappings.Visibility = Visibility.Visible;
|
||||
if (this.userEntity.IsAdmin)
|
||||
{
|
||||
this.menuItemUserAdministration.Visibility = Visibility.Visible;
|
||||
|
||||
11
ENI2/Properties/Resources.Designer.cs
generated
11
ENI2/Properties/Resources.Designer.cs
generated
@ -38,7 +38,7 @@ namespace ENI2.Properties {
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (ReferenceEquals(resourceMan, null)) {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ENI2.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
@ -2297,6 +2297,15 @@ namespace ENI2.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Excel import value mappings.
|
||||
/// </summary>
|
||||
public static string textExcelValueMappings {
|
||||
get {
|
||||
return ResourceManager.GetString("textExcelValueMappings", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Excepted quantities.
|
||||
/// </summary>
|
||||
|
||||
@ -1879,4 +1879,7 @@
|
||||
<data name="textCopyIMO" xml:space="preserve">
|
||||
<value>Copy IMO to clipboard</value>
|
||||
</data>
|
||||
<data name="textExcelValueMappings" xml:space="preserve">
|
||||
<value>Excel import value mappings</value>
|
||||
</data>
|
||||
</root>
|
||||
@ -5,8 +5,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bsmd.database
|
||||
@ -42,6 +40,5 @@ namespace bsmd.database
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,17 +15,23 @@ namespace bsmd.database
|
||||
public class ValueMapping : DatabaseEntityAsync
|
||||
{
|
||||
|
||||
#region Construction
|
||||
public ValueMapping()
|
||||
{
|
||||
this.tablename = "[dbo].[ValueMapping]";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region enums
|
||||
|
||||
public enum MappingType
|
||||
{
|
||||
UNKNOWN,
|
||||
COUNTRY,
|
||||
GENDER,
|
||||
DOCUMENT_TYPE,
|
||||
LOCODE,
|
||||
INVALID
|
||||
};
|
||||
LOCODE
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -44,9 +50,9 @@ namespace bsmd.database
|
||||
|
||||
public MappingType EntryType { get; private set; }
|
||||
|
||||
public string Key { get; private set; }
|
||||
public string Key { get; set; }
|
||||
|
||||
public string Value { get; private set; }
|
||||
public string Value { get; set; }
|
||||
|
||||
public DateTime? Created { get; private set; }
|
||||
|
||||
@ -139,6 +145,8 @@ namespace bsmd.database
|
||||
default:
|
||||
break;
|
||||
}
|
||||
query += " ORDER BY MappingKey";
|
||||
cmd.CommandText = query;
|
||||
}
|
||||
|
||||
protected override DatabaseEntityAsync ReadRowFromReader(System.Data.IDataReader reader)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user