From 2490a78dca2e69d83f2747e7b33e7ee23ae7d68f Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 26 Apr 2017 16:31:37 +0000 Subject: [PATCH] neue ENI2 Version, mit Locode Control und Grid RootControls etc pp --- ENI-2/ENI2/ENI2/Controls/ENIDataGrid.cs | 122 ++++++++++++++ ENI-2/ENI2/ENI2/Controls/LocodeControl.xaml | 22 +++ .../ENI2/ENI2/Controls/LocodeControl.xaml.cs | 158 ++++++++++++++++++ ENI-2/ENI2/ENI2/DetailBaseControl.cs | 2 + .../OverViewDetailControl.xaml | 5 +- .../OverViewDetailControl.xaml.cs | 5 +- .../PortCallDetailControl.xaml | 104 +++++++++++- .../PortCallDetailControl.xaml.cs | 52 ++++++ ENI-2/ENI2/ENI2/ENI2.csproj | 19 ++- .../ENI2/Properties/Resources.Designer.cs | 30 ++++ ENI-2/ENI2/ENI2/Properties/Resources.resx | 9 + ENI-2/ENI2/ENI2/Resources/add.png | Bin 0 -> 763 bytes ENI-2/ENI2/ENI2/Resources/delete.png | Bin 0 -> 1279 bytes ENI-2/ENI2/ENI2/Resources/edit.png | Bin 0 -> 1629 bytes ENI-2/ENI2/ENI2/SucheControl.xaml | 13 +- ENI-2/ENI2/ENI2/SucheControl.xaml.cs | 16 +- ENI-2/ENI2/ENI2/Themes/Generic.xaml | 20 +++ Stundensheet.xlsx | Bin 29606 -> 29672 bytes nsw/Source/bsmd.ExcelReadService/Util.cs | 20 ++- nsw/Source/bsmd.database/Extensions.cs | 9 +- nsw/Source/bsmd.database/MessageCore.cs | 10 +- .../Properties/AssemblyProductInfo.cs | 2 +- .../Properties/AssemblyProjectInfo.cs | 2 +- 23 files changed, 593 insertions(+), 27 deletions(-) create mode 100644 ENI-2/ENI2/ENI2/Controls/ENIDataGrid.cs create mode 100644 ENI-2/ENI2/ENI2/Controls/LocodeControl.xaml create mode 100644 ENI-2/ENI2/ENI2/Controls/LocodeControl.xaml.cs create mode 100644 ENI-2/ENI2/ENI2/Resources/add.png create mode 100644 ENI-2/ENI2/ENI2/Resources/delete.png create mode 100644 ENI-2/ENI2/ENI2/Resources/edit.png create mode 100644 ENI-2/ENI2/ENI2/Themes/Generic.xaml diff --git a/ENI-2/ENI2/ENI2/Controls/ENIDataGrid.cs b/ENI-2/ENI2/ENI2/Controls/ENIDataGrid.cs new file mode 100644 index 00000000..a58d347d --- /dev/null +++ b/ENI-2/ENI2/ENI2/Controls/ENIDataGrid.cs @@ -0,0 +1,122 @@ +// Copyright (c) 2017 schick Informatik +// Description: DataGrid mit etwas "verbesserten" Funktionen +// + +using System; +using System.Collections.Generic; +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 +{ + /// + /// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file. + /// + /// Step 1a) Using this custom control in a XAML file that exists in the current project. + /// Add this XmlNamespace attribute to the root element of the markup file where it is + /// to be used: + /// + /// xmlns:enictrl="clr-namespace:ENI2.Controls" + /// + /// + /// Step 1b) Using this custom control in a XAML file that exists in a different project. + /// Add this XmlNamespace attribute to the root element of the markup file where it is + /// to be used: + /// + /// xmlns:enictrl="clr-namespace:ENI2.Controls;assembly=ENI2.Controls" + /// + /// You will also need to add a project reference from the project where the XAML file lives + /// to this project and Rebuild to avoid compilation errors: + /// + /// Right click on the target project in the Solution Explorer and + /// "Add Reference"->"Projects"->[Browse to and select this project] + /// + /// + /// Step 2) + /// Go ahead and use your control in the XAML file. + /// + /// + /// + /// + public class ENIDataGrid : DataGrid + { + /* + static ENIDataGrid() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(ENIDataGrid), new FrameworkPropertyMetadata(typeof(ENIDataGrid))); + } + */ + + public event Action EditRequested; + public event Action DeleteRequested; + public event Action CreateRequested; + + public void Initialize() + { + this.ContextMenu = new ContextMenu(); + + MenuItem addItem = new MenuItem(); + addItem.Header = "_Add"; + addItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/add.png")) }; + addItem.Click += new RoutedEventHandler(this.addItem); + this.ContextMenu.Items.Add(addItem); + + MenuItem deleteItem = new MenuItem(); + deleteItem.Header = "_Delete"; + deleteItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/delete.png")) }; + deleteItem.Click += this.deleteItem; + this.ContextMenu.Items.Add(deleteItem); + + MenuItem editItem = new MenuItem(); + editItem.Header = "_Edit"; + editItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/edit.png")) }; + editItem.Click += this.editItem; + this.ContextMenu.Items.Add(editItem); + + } + + protected void addItem(object sender, RoutedEventArgs e) + { + this.CreateRequested?.Invoke(); + } + + protected void deleteItem(object sender, RoutedEventArgs e) + { + if((this.SelectedItems != null) && (this.SelectedItems.Count > 0)) + { + // TODO: ask confirmation message box + + foreach(object deleteItem in this.SelectedItems) + { + if (deleteItem is DatabaseEntity) { + this.DeleteRequested?.Invoke(deleteItem as DatabaseEntity); + } + } + } + } + + protected void editItem(object sender, RoutedEventArgs e) + { + if((this.SelectedItems != null) && (this.SelectedItems.Count == 1)) + { + DatabaseEntity selectedEntity = this.SelectedItems[0] as DatabaseEntity; + if (selectedEntity != null) + this.EditRequested?.Invoke(selectedEntity); + } + } + + } +} diff --git a/ENI-2/ENI2/ENI2/Controls/LocodeControl.xaml b/ENI-2/ENI2/ENI2/Controls/LocodeControl.xaml new file mode 100644 index 00000000..45676795 --- /dev/null +++ b/ENI-2/ENI2/ENI2/Controls/LocodeControl.xaml @@ -0,0 +1,22 @@ + + + + + + + + + + + + diff --git a/ENI-2/ENI2/ENI2/Controls/LocodeControl.xaml.cs b/ENI-2/ENI2/ENI2/Controls/LocodeControl.xaml.cs new file mode 100644 index 00000000..522ab672 --- /dev/null +++ b/ENI-2/ENI2/ENI2/Controls/LocodeControl.xaml.cs @@ -0,0 +1,158 @@ +// Copyright (c) 2017 schick Informatik +// Description: Kapselt den Locode - Lookup +// + +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media.Imaging; + +using bsmd.database; +using bsmd.ExcelReadService; +using System.ComponentModel; + +namespace ENI2.Controls +{ + /// + /// Interaction logic for LocodeControl.xaml + /// + public partial class LocodeControl : UserControl, INotifyPropertyChanged + { + private List _locodeList = new List(); + // private string _selectedLocode; + public event PropertyChangedEventHandler PropertyChanged; + + public LocodeControl() + { + InitializeComponent(); + } + + protected enum LocodeState + { + UNKNOWN, + INVALID, + OK, + AMBIGUOUS + } + + /// + /// used internally to load up drop down + /// + public List LocodeList + { + get { return this._locodeList; } + set { this._locodeList = value; } + } + + public static readonly DependencyProperty LocodeValueProperty = DependencyProperty.Register("LocodeValue", typeof(string), typeof(LocodeControl), + new UIPropertyMetadata(LocodeValueChangedHandler)); + //new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + + + public static void LocodeValueChangedHandler(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + // Get instance of current control from sender + // and property value from e.NewValue + + // Set public property on TaregtCatalogControl, e.g. + if(e.NewValue != null) + ((LocodeControl)sender).SelectedItem = e.NewValue.ToString(); + } + + + public string SelectedItem + { + get { return this.comboBoxLocode.SelectedItem as string; } + set { + this._locodeList.Clear(); + this._locodeList.Add(value); + this.comboBoxLocode.ItemsSource = this.LocodeList; + LocodeState locodeState = LocodeDB.PortNameFromLocode(value).IsNullOrEmpty() ? LocodeState.INVALID : LocodeState.OK; + this.SetLocodeStateImage(this.imageLocodeState, locodeState); + this.comboBoxLocode.SelectedItem = value; + } + } + + + + /// + /// Actual value for DataBinding + /// + public string LocodeValue + { + get { return (string)GetValue(LocodeValueProperty); } + set { SetValue(LocodeValueProperty, value); } + } + + #region event handler + + private void ComboBox_TextChanged(object sender, RoutedEventArgs e) + { + if (this.comboBoxLocode.Text.Length > 3) + { + // check if actual locode + bool isLocode = !LocodeDB.PortNameFromLocode(this.comboBoxLocode.Text).IsNullOrEmpty(); + if (isLocode) + { + this.SetLocodeStateImage(this.imageLocodeState, LocodeState.OK); + return; + } + + // assume this is a harbour name typed out.. + this.LocodeList = LocodeDB.AllLocodesForCityName(this.comboBoxLocode.Text + "%"); + + if (this.LocodeList.Count == 1) + { + this.comboBoxLocode.SelectedItem = this.LocodeList[0]; + this.SetLocodeStateImage(this.imageLocodeState, LocodeState.OK); + } + else if (this.LocodeList.Count == 0) + { + this.SetLocodeStateImage(this.imageLocodeState, LocodeState.INVALID); + } + else + { + this.SetLocodeStateImage(this.imageLocodeState, LocodeState.AMBIGUOUS); + } + + this.comboBoxLocode.ItemsSource = this.LocodeList; + + } + + this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LocodeList")); + } + + private void comboBoxLocode_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + this.LocodeValue = this.SelectedItem; + } + + #endregion + + #region private/protected methods + + protected void SetLocodeStateImage(Image stateImage, LocodeState state) + { + switch (state) + { + case LocodeState.AMBIGUOUS: + stateImage.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/bullet_ball_yellow.png")); + break; + case LocodeState.INVALID: + stateImage.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/bullet_ball_red.png")); + break; + case LocodeState.OK: + stateImage.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/bullet_ball_green.png")); + break; + case LocodeState.UNKNOWN: + default: + stateImage.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/bullet_ball_grey.png")); + break; + } + } + + #endregion + + } +} diff --git a/ENI-2/ENI2/ENI2/DetailBaseControl.cs b/ENI-2/ENI2/ENI2/DetailBaseControl.cs index fb503abb..e77c22c0 100644 --- a/ENI-2/ENI2/ENI2/DetailBaseControl.cs +++ b/ENI-2/ENI2/ENI2/DetailBaseControl.cs @@ -17,6 +17,8 @@ namespace ENI2 public class DetailBaseControl : UserControl { + protected bool _initialized = false; + protected enum LocodeState { UNKNOWN, diff --git a/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml b/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml index 76c9d6a0..bf2a8a15 100644 --- a/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml +++ b/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml @@ -32,7 +32,6 @@ -