Tabs statt ersetzte Windows, MainFrame bereinigt, Lösung für lokalisierte Lookups in der SQLite Datenbank gefunden!

This commit is contained in:
Daniel Schick 2017-05-07 11:37:08 +00:00
parent 1f6bdb11c8
commit 344b511ae1
18 changed files with 302 additions and 23 deletions

View File

@ -1,9 +1,12 @@
// Copyright (c) 2017 Informatibüro Daniel Schick
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Markup;
using bsmd.database;
namespace ENI2
{
/// <summary>
@ -17,10 +20,25 @@ namespace ENI2
this.Dispatcher.UnhandledException += Dispatcher_UnhandledException;
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// initialize static / localized lookups from sqlite database
string langKey = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
Dictionary<int, string> cargoHandlingDict = LocalizedLookup.getLADGCargoHandlingStrings(langKey);
foreach (int key in cargoHandlingDict.Keys)
LADG.CargoHandlingDict.Add(key, cargoHandlingDict[key]);
}
private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
string errorMessage = string.Format("An unhandled exception occurred: {0}\r\n{1}", e.Exception.Message, e.Exception.StackTrace);

View File

@ -0,0 +1,91 @@
// Copyright (c) 2017 schick Informatik
// Description: Custom tab item
//
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace ENI2.Controls
{
/// <summary>
/// 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:MyNamespace="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:MyNamespace="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.
///
/// <MyNamespace:ClosableTabItem/>
///
/// </summary>
public class ClosableTabItem : TabItem
{
/*
static ClosableTabItem()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ClosableTabItem), new FrameworkPropertyMetadata(typeof(ClosableTabItem)));
}
*/
public void SetHeaderText(string headerText)
{
// Container for header controls
var dockPanel = new DockPanel();
var header = new TextBlock { Text = headerText };
dockPanel.Children.Add(header);
// Close button to remove the tab
var closeButton = new Button();
closeButton.Content = "X";
closeButton.Margin = new Thickness(5, 0, 0, 0);
closeButton.Foreground = Brushes.Red;
closeButton.Height = 18;
closeButton.Width = 15;
closeButton.Opacity = 0.2;
closeButton.FontSize = 8;
closeButton.FontWeight = FontWeights.Bold;
closeButton.MouseEnter += (sender, e) => {
DoubleAnimation animation = new DoubleAnimation(0.2, 1.0, new TimeSpan(0, 0, 0, 0, 500));
closeButton.BeginAnimation(Button.OpacityProperty, animation);
};
closeButton.MouseLeave += (sender, e) => {
DoubleAnimation animation = new DoubleAnimation(1.0, 0.2, new TimeSpan(0, 0, 0, 0, 500));
closeButton.BeginAnimation(Button.OpacityProperty, animation);
};
closeButton.Click +=
(sender, e) =>
{
var tabControl = Parent as ItemsControl;
tabControl.Items.Remove(this);
};
dockPanel.Children.Add(closeButton);
// Set the header
Header = dockPanel;
}
}
}

View File

@ -80,7 +80,7 @@
<enictrl:ENIDataGrid x:Name="dataGridLADG" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
SelectionMode="Single" AutoGenerateColumns="False" Margin="0,5,0,0">
<DataGrid.Columns>
<DataGridTextColumn Header="{x:Static p:Resources.textCargoHandlingType}" Binding="{Binding CargoHandlingType, Mode=TwoWay}" IsReadOnly="True" Width="0.15*" />
<DataGridTextColumn Header="{x:Static p:Resources.textCargoHandlingType}" Binding="{Binding CargoHandlingTypeDisplay}" IsReadOnly="True" Width="0.15*" />
<DataGridTextColumn Header="{x:Static p:Resources.textLACodes}" Binding="{Binding CargoLACode, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textCargoCodeNST}" Binding="{Binding CargoCodeNST, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textCargoCodeNST3}" Binding="{Binding CargoCodeNST_3, Mode=TwoWay}" IsReadOnly="True" Width="0.15*" />

View File

@ -159,6 +159,7 @@
<Compile Include="..\..\..\nsw\Source\bsmd.ExcelReadService\LocodeDB.cs">
<Link>Locode\LocodeDB.cs</Link>
</Compile>
<Compile Include="Controls\ClosableTabItem.cs" />
<Compile Include="Controls\EditWindowBase.cs" />
<Compile Include="Controls\ENIDataGrid.cs" />
<Compile Include="Controls\LocodeControl.xaml.cs">
@ -217,6 +218,7 @@
<Compile Include="EditControls\EditSERVDialog.xaml.cs">
<DependentUpon>EditSERVDialog.xaml</DependentUpon>
</Compile>
<Compile Include="LocalizedLookup.cs" />
<Compile Include="SucheControl.xaml.cs">
<DependentUpon>SucheControl.xaml</DependentUpon>
</Compile>

View File

@ -0,0 +1,44 @@
// Copyright (c) 2017 schick Informatik
// Description: Alle Lookup-Tabellen für das Display statisch aus der SQLite Datenbank initialisieren
//
using System.Data;
using System.Data.SQLite;
using System.Collections.Generic;
namespace ENI2
{
static class LocalizedLookup
{
private static SQLiteConnection _con;
private const string _locode_DB_NAME = "db.sqlite";
static LocalizedLookup()
{
_con = new SQLiteConnection(string.Format("data source={0}; Version=3;", _locode_DB_NAME));
_con.Open();
}
public static Dictionary<int, string> getLADGCargoHandlingStrings(string languageCode)
{
Dictionary<int, string> result = new Dictionary<int, string>();
string query = string.Format("SELECT key, text FROM LADG_CargoHandlingCodes WHERE langKey = '{0}'", languageCode);
SQLiteCommand cmd = new SQLiteCommand(query, _con);
IDataReader reader = cmd.ExecuteReader();
int key;
string text;
while (reader.Read())
{
key = reader.GetInt32(0);
text = reader.GetString(1);
result[key] = text;
}
reader.Close();
return result;
}
}
}

View File

@ -16,9 +16,10 @@
<DockPanel>
<Grid DockPanel.Dock="Top" Height="80" Background="#FFE8F6FF">
<Image x:Name="logoImage" HorizontalAlignment="Left" Height="80" Width="80" Source="Resources/EUREPORT.png" Stretch="Fill" MouseUp="logoImage_MouseUp"/>
<Button x:Name="buttonAnmeldungen" Content="{x:Static p:Resources.textDeclarations}" HorizontalAlignment="Left" Margin="101,25,0,0" VerticalAlignment="Top" Width="95" Height="23" Click="buttonAnmeldungen_Click" Background="Transparent" />
<Button x:Name="buttonVorgaenge" Content="{x:Static p:Resources.textOperations}" HorizontalAlignment="Left" Margin="201,25,0,0" VerticalAlignment="Top" Width="95" Height="23" Click="buttonVorgaenge_Click" Background="Transparent" />
<Button x:Name="buttonSuche" Content="{x:Static p:Resources.textSearch}" HorizontalAlignment="Left" Margin="301,25,0,0" VerticalAlignment="Top" Width="95" Height="23" Click="buttonSuche_Click" Background="Transparent" />
<Button x:Name="buttonNewId" Content="{x:Static p:Resources.textNewVisitTransitId}" HorizontalAlignment="Left" Margin="101,25,0,0" VerticalAlignment="Top" Width="110" Height="23" Click="buttonNewTransitIdClick" Background="Transparent" />
<!--Button x:Name="buttonAnmeldungen" Content="{x:Static p:Resources.textDeclarations}" HorizontalAlignment="Left" Margin="101,25,0,0" VerticalAlignment="Top" Width="95" Height="23" Click="buttonAnmeldungen_Click" Background="Transparent" /-->
<!--Button x:Name="buttonVorgaenge" Content="{x:Static p:Resources.textOperations}" HorizontalAlignment="Left" Margin="201,25,0,0" VerticalAlignment="Top" Width="95" Height="23" Click="buttonVorgaenge_Click" Background="Transparent" / -->
<!-- Button x:Name="buttonSuche" Content="{x:Static p:Resources.textSearch}" HorizontalAlignment="Left" Margin="301,25,0,0" VerticalAlignment="Top" Width="95" Height="23" Click="buttonSuche_Click" Background="Transparent" /-->
</Grid>
<Grid DockPanel.Dock="Bottom" Height="20" Background="#FFE8F6FF">
@ -57,8 +58,10 @@
</StatusBarItem>
</StatusBar>
</Grid>
<Grid Margin="10" Background="#FFE8F6FF" Name="mainFrame">
</Grid>
<TabControl Margin="10" Name="mainFrame">
<TabItem Header="{x:Static p:Resources.textSearch}" Name="tabSearch">
</TabItem>
</TabControl>
</DockPanel>
</Window>

View File

@ -10,6 +10,8 @@ using System.Windows.Input;
using System.Windows.Media.Imaging;
using bsmd.database;
using System.Windows.Controls;
using ENI2.Controls;
namespace ENI2
{
@ -19,8 +21,8 @@ namespace ENI2
public partial class MainWindow : Window
{
private bool dbConnected;
private VorgaengeControl vorgaengeControl;
private AnmeldungenControl anmeldungenControl;
//private VorgaengeControl vorgaengeControl;
//private AnmeldungenControl anmeldungenControl;
private SucheControl sucheControl;
private List<MessageCore> anmeldungen = new List<MessageCore>();
private bool efMode = false;
@ -29,11 +31,12 @@ namespace ENI2
{
InitializeComponent();
this.vorgaengeControl = new VorgaengeControl();
this.anmeldungenControl = new AnmeldungenControl();
//this.vorgaengeControl = new VorgaengeControl();
//this.anmeldungenControl = new AnmeldungenControl();
this.sucheControl = new SucheControl();
this.anmeldungenControl.MessageCoreSelected += AnmeldungenControl_MessageCoreSelected;
this.tabSearch.Content = this.sucheControl;
this.sucheControl.buttonSuche.IsDefault = true;
//this.anmeldungenControl.MessageCoreSelected += AnmeldungenControl_MessageCoreSelected;
this.sucheControl.MessageCoreSelected += AnmeldungenControl_MessageCoreSelected;
}
@ -42,9 +45,11 @@ namespace ENI2
{
if(aMessageCore != null)
{
mainFrame.Children.Clear();
ClosableTabItem searchResultItem = new ClosableTabItem();
searchResultItem.SetHeaderText(aMessageCore.Shipname);
DetailRootControl drc = new DetailRootControl(aMessageCore);
mainFrame.Children.Add(drc);
searchResultItem.Content = drc;
this.mainFrame.Items.Add(searchResultItem);
}
}
@ -52,7 +57,7 @@ namespace ENI2
private void buttonAnmeldungen_Click(object sender, RoutedEventArgs e)
{
mainFrame.Children.Clear();
if (dbConnected)
{
this.anmeldungen = DBManager.Instance.GetMessageCoresByStatus(MessageCore.BSMDStatus.PREPARE);
@ -67,24 +72,28 @@ namespace ENI2
}
*/
}
anmeldungenControl.dataGrid.ItemsSource = this.anmeldungen;
//anmeldungenControl.dataGrid.ItemsSource = this.anmeldungen;
mainFrame.Children.Add(this.anmeldungenControl);
//mainFrame.Children.Add(this.anmeldungenControl);
}
/*
private void buttonVorgaenge_Click(object sender, RoutedEventArgs e)
{
mainFrame.Children.Clear();
mainFrame.Children.Add(this.vorgaengeControl);
}
*/
/*
private void buttonSuche_Click(object sender, RoutedEventArgs e)
{
mainFrame.Children.Clear();
mainFrame.Children.Add(this.sucheControl);
this.sucheControl.buttonSuche.IsDefault = true;
}
*/
private void logoImage_MouseUp(object sender, MouseButtonEventArgs e)
{
@ -145,6 +154,21 @@ namespace ENI2
e.CanExecute = true;
}
private void buttonNewTransitIdClick(object sender, RoutedEventArgs e)
{
// TODO
}
private void closeButton_Click(object sender, RoutedEventArgs e)
{
// close particular tab
TabItem tabitem = e.Source as TabItem;
if(tabitem != null)
{
this.mainFrame.Items.Remove(tabitem);
}
}
#endregion

View File

@ -825,6 +825,15 @@ namespace ENI2.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to New Visit/Transit Id.
/// </summary>
public static string textNewVisitTransitId {
get {
return ResourceManager.GetString("textNewVisitTransitId", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Next Port.
/// </summary>

View File

@ -132,4 +132,7 @@
<data name="textCaptionDeleteConfirm" xml:space="preserve">
<value>Löschen bestätigen</value>
</data>
<data name="textNewVisitTransitId" xml:space="preserve">
<value>Neue Visit/Transit Id</value>
</data>
</root>

View File

@ -466,4 +466,7 @@
<data name="textTransit" xml:space="preserve">
<value>Transit</value>
</data>
<data name="textNewVisitTransitId" xml:space="preserve">
<value>New Visit/Transit Id</value>
</data>
</root>

View File

@ -52,6 +52,7 @@ namespace ENI2
dateTimePickerETAFrom.Text = string.Empty;
dateTimePickerETATo.Text = string.Empty;
this.dataGrid.ItemsSource = null;
this.searchResultLabel.Content = "";
}
private void buttonSuche_Click(object sender, RoutedEventArgs e)

View File

@ -45,4 +45,19 @@
</Setter>
</Style>
<Style TargetType="{x:Type enictrl:ClosableTabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type enictrl:ClosableTabItem}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

Binary file not shown.

View File

@ -35,10 +35,54 @@ namespace bsmd.ExcelReadService
this._portcall = _excelWorkbooks.Open(filePath, 0, true, 5, "", "", false, XlPlatform.xlWindows, "", false, false, 0, false, false, false);
_nameDict = new Dictionary<string, Name>();
int bookCnt = 0;
foreach(Name name in _portcall.Names)
{
_nameDict[name.Name] = name;
}
string theValue = name.Value;
// Namensbezug: =SheetZelle. Leere Referenzen überspringen (kommt immer mal wieder vor!)
string nameKey = name.Name;
try
{
if (nameKey.Contains("!"))
nameKey = nameKey.Substring(nameKey.IndexOf('!') + 1);
}
catch(Exception)
{
_log.DebugFormat("Strange name in Sheet: {0}", nameKey);
continue;
}
if ((theValue != "=#REF!#REF!") && (theValue != "=#BEZUG!#BEZUG!"))
{
_nameDict[nameKey] = name;
bookCnt++;
}
}
_log.DebugFormat("{0} named ranges found at Workbook level", bookCnt);
/*
foreach(Worksheet ws in _portcall.Worksheets)
{
int wsCnt = 0;
foreach(Name name in ws.Names)
{
string theValue = name.Value;
// Namensbezug: =SheetZelle. Leere Referenzen überspringen (kommt immer mal wieder vor!)
if (!_nameDict.ContainsKey(name.Name))
{
if ((theValue != "=#REF!#REF!") && (theValue != "=#BEZUG!#BEZUG!"))
{
_nameDict[name.Name] = name;
wsCnt++;
}
}
}
if (wsCnt > 0)
_log.DebugFormat("{0} named ranges found in Worksheet {1}", wsCnt, ws.Name);
}
*/
}

View File

@ -17,7 +17,7 @@ namespace bsmd.database
public class LADG : DatabaseEntity, ISublistElement
{
#region LACodes static definition
#region static definition
private static Lazy<Dictionary<int, string>> laCodes =
new Lazy<Dictionary<int, string>>(() => new Dictionary<int, string>
@ -43,6 +43,8 @@ namespace bsmd.database
{ 67, "Reisezugwagen und Triebwagen" }
});
private static Dictionary<int, string> _cargoHandlingDict = new Dictionary<int, string>();
#endregion
public LADG()
@ -56,6 +58,21 @@ namespace bsmd.database
[Validation(ValidationCode.NOT_NULL)]
public byte? CargoHandlingType { get; set; }
/// <summary>
/// ENI-2 display value
/// </summary>
public string CargoHandlingTypeDisplay {
get {
if(this.CargoHandlingType.HasValue)
{
if (_cargoHandlingDict.ContainsKey(this.CargoHandlingType.Value))
return _cargoHandlingDict[this.CargoHandlingType.Value];
return string.Empty;
}
return string.Empty;
}
}
[ShowReport]
[Validation(ValidationCode.TWO_DIGIT)]
[MaxLength(5)]
@ -93,6 +110,11 @@ namespace bsmd.database
}
}
public static Dictionary<int, string> CargoHandlingDict
{
get { return _cargoHandlingDict; }
}
#endregion
#region DatabaseEntity implementation

View File

@ -2,6 +2,6 @@
[assembly: AssemblyCompany("Informatikbüro Daniel Schick")]
[assembly: AssemblyProduct("BSMD NSW interface")]
[assembly: AssemblyInformationalVersion("3.5.6")]
[assembly: AssemblyInformationalVersion("3.5.7")]
[assembly: AssemblyCopyright("Copyright © 2014-2017 Informatikbüro Daniel Schick. All rights reserved.")]
[assembly: AssemblyTrademark("")]

View File

@ -1,4 +1,4 @@
using System.Reflection;
[assembly: AssemblyVersion("3.5.6.*")]
[assembly: AssemblyVersion("3.5.7.*")]

Binary file not shown.