diff --git a/ENI2/DetailRootControl.xaml.cs b/ENI2/DetailRootControl.xaml.cs index 039cd0d5..93c28cde 100644 --- a/ENI2/DetailRootControl.xaml.cs +++ b/ENI2/DetailRootControl.xaml.cs @@ -506,7 +506,7 @@ namespace ENI2 this.DetailControl_RequestReload(this.Core.Id.Value); - System.Action SetTabAction = (int x) => + System.Action SetTabAction = x => { // this hopefully happens *after* the view was completely reloaded if (this.detailView.Children[0] is DetailBaseControl currentNewControl) @@ -590,7 +590,7 @@ namespace ENI2 this.DetailControl_RequestReload(this.Core.Id.Value); - System.Action SetTabAction = (int x) => + Action SetTabAction = x => { // this hopefully happens *after* the view was completely reloaded if (this.detailView.Children[0] is DetailBaseControl currentNewControl) diff --git a/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs b/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs index 02bbea37..e1d4ca77 100644 --- a/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs @@ -21,6 +21,7 @@ using Microsoft.Win32; using System.Diagnostics; using System.ComponentModel; using static bsmd.database.Message; +using PdfSharp.Fonts; namespace ENI2.DetailViewControls { @@ -574,7 +575,13 @@ namespace ENI2.DetailViewControls if (sfd.ShowDialog() ?? false) { Util.UIHelper.SetBusyState(); - ReportManager rm = new ReportManager(); + ReportManager rm = new ReportManager(); + + // TODO!! + // https://docs.pdfsharp.net/PDFsharp/Topics/Fonts/Font-Resolving.html + // https://docs.pdfsharp.net/MigraDoc/DOM/Document/MigraDocSettings.html + GlobalFontSettings.UseWindowsFontsUnderWindows = true; + GlobalFontSettings.UseWindowsFontsUnderWsl2 = true; // create PDF from message classes if (rm.Create(sfd.FileName, this.Core, sicd.SelectedClasses, out string importResultText)) diff --git a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml index 62f1dbc3..66f0794a 100644 --- a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml +++ b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml @@ -28,7 +28,7 @@ - + @@ -36,10 +36,12 @@ - + + + @@ -94,7 +145,7 @@ - + portAreas = null; + private static List _servTemplates = null; + private SERV_Template _currentTemplate; + + #endregion private static readonly string[] shippingAreas = { Properties.Resources.textShippingAreaNORTHBALTIC, @@ -59,7 +68,7 @@ namespace ENI2.DetailViewControls this.dataGridLADG.CellEditEnding += (obj, ev) => { this.OnNotificationClassChanged(Message.NotificationClass.LADG); }; } - public override void Initialize() + public override async void Initialize() { base.Initialize(); @@ -69,6 +78,7 @@ namespace ENI2.DetailViewControls if (aMessage.MessageNotificationClass == Message.NotificationClass.INFO) { this._infoMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.SERV) { this._servMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.LADG) { this._ladgMessage = aMessage; this.ControlMessages.Add(aMessage); } + if(aMessage.MessageNotificationClass == Message.NotificationClass.CREWA) { this._crewaMessage = aMessage;} } #region init NAME @@ -155,16 +165,22 @@ namespace ENI2.DetailViewControls this.dataGridLADG.DeleteRequested += DataGridLADG_DeleteRequested; this.dataGridLADG.CreateRequested += DataGridLADG_CreateRequested; - #endregion + #endregion - #region init helper Maersk / SeaGo Field + #region init SERV templates - if (this.Core.IsFlagSet(MessageCore.CoreFlags.MAERSK_BHV)) this.comboBoxGroup.SelectedIndex = 1; - if (this.Core.IsFlagSet(MessageCore.CoreFlags.SEAGO_BHV)) this.comboBoxGroup.SelectedIndex = 2; - if (this.Core.IsFlagSet(MessageCore.CoreFlags.SEAGO_WHV)) this.comboBoxGroup.SelectedIndex = 3; - if (this.Core.IsFlagSet(MessageCore.CoreFlags.HOEGH)) this.comboBoxGroup.SelectedIndex = 4; - if (this.Core.IsFlagSet(MessageCore.CoreFlags.ELBE_BULK)) this.comboBoxGroup.SelectedIndex = 5; - if (this.Core.IsFlagSet(MessageCore.CoreFlags.FCT_JUNGE)) this.comboBoxGroup.SelectedIndex = 6; + if(_servTemplates == null) + { + _servTemplates = await DBManagerAsync.GetSERVTemplatesAsync(); // initial load + _servTemplates.Sort(); + Trace.WriteLine($"{_servTemplates.Count} SERV templates loaded"); + } + + 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 @@ -365,157 +381,100 @@ namespace ENI2.DetailViewControls #endregion - #region Spezialbalkon für die Gruppenauswahl im Core (Maersk BHV / Seago usw.) + #region SERV template event handler private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e) { - // clear all - this.Core.SetFlag(false, MessageCore.CoreFlags.MAERSK_BHV); - this.Core.SetFlag(false, MessageCore.CoreFlags.SEAGO_BHV); - this.Core.SetFlag(false, MessageCore.CoreFlags.SEAGO_WHV); - this.Core.SetFlag(false, MessageCore.CoreFlags.HOEGH); - this.Core.SetFlag(false, MessageCore.CoreFlags.ELBE_BULK); - this.Core.SetFlag(false, MessageCore.CoreFlags.FCT_JUNGE); - - if (this.comboBoxGroup.SelectedItem == null) - { - this.comboBoxGroup.SelectedIndex = 0; - DBManager.Instance.Save(this.Core); + if(this.comboBoxGroup.SelectedItem is SERV_Template st) + { + this.buttonDeleteTemplate.IsEnabled = true; + this.buttonSetTemplate.IsEnabled = true; + this._currentTemplate = st; } - else + } + + private void buttonSetTemplate_Click(object sender, RoutedEventArgs e) + { + if (this.comboBoxGroup.SelectedItem is SERV_Template st) { - DictionaryEntry selectedItem = (DictionaryEntry)this.comboBoxGroup.SelectedItem; - if (Int32.TryParse((string)selectedItem.Value, out int selectedValue)) + bool found = false; + foreach (SERV serv in _servMessage.Elements.Cast()) { - if (selectedValue == (int)MessageCore.CoreFlags.MAERSK_BHV) CheckServiceEntryMaerskBHV(); - if (selectedValue == (int)MessageCore.CoreFlags.SEAGO_BHV) CheckServiceEntrySeaGoBHV(); - if (selectedValue == (int)MessageCore.CoreFlags.HOEGH) CheckServiceEntryHoegh(); - if (selectedValue == (int)MessageCore.CoreFlags.ELBE_BULK) CheckServiceEntryElbeBulk(); - if (selectedValue == (int)MessageCore.CoreFlags.FCT_JUNGE) CheckServiceEntryFctJunge(); - this.Core.SetFlag(true, (MessageCore.CoreFlags)selectedValue); - DBManager.Instance.Save(this.Core); + if (serv.ServiceName.Equals(st.ServiceName)) + { + found = true; break; + } + } + + if (!found) + { + SERV newServ = new SERV(); + newServ.ServiceName = st.ServiceName; + newServ.ServiceBeneficiary = st.ServiceBeneficiary; + newServ.ServiceInvoiceRecipient = st.ServiceInvoiceRecipient; + + newServ.MessageHeader = this._servMessage; + newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); + this._servMessage.Elements.Add(newServ); + this.dataGridSERV.Items.Refresh(); + this.SublistElementChanged(Message.NotificationClass.SERV); + } + } + } + + 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 - #region special entry ship service check - - private void CheckServiceEntryMaerskBHV() - { - bool found = false; - foreach(SERV serv in _servMessage.Elements.Cast()) - { - if (serv.ServiceBeneficiary.Equals("Maersk A/S, Esplanaden 50, DK-1263 Copenhagen K, VAT-ID: DK53139655")) - found = true; - } - - if(!found) - { - SERV newServ = new SERV(); - newServ.ServiceBeneficiary = "Maersk A/S, Esplanaden 50, DK-1263 Copenhagen K, VAT-ID: DK53139655"; - newServ.ServiceInvoiceRecipient = "Maersk Deutschland A/S & Co.KG, Johanniswall 7, 20095 Hamburg"; - newServ.ServiceName = "Maersk BHV"; - newServ.MessageHeader = this._servMessage; - newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); - this._servMessage.Elements.Add(newServ); - this.dataGridSERV.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.SERV); - } - } - - private void CheckServiceEntrySeaGoBHV() - { - bool found = false; - foreach (SERV serv in _servMessage.Elements.Cast()) - { - if (serv.ServiceBeneficiary.Equals("Sealand Europe A/S, Dampfaergevej 10, 3.tv, DK- 2100 Copenhagen, VAT-ID: DK53139655")) - found = true; - } - - if (!found) - { - SERV newServ = new SERV(); - newServ.ServiceBeneficiary = "Sealand Europe A/S, Dampfaergevej 10, 3.tv, DK- 2100 Copenhagen, VAT-ID: DK53139655"; - newServ.ServiceInvoiceRecipient = "Maersk Deutschland A/S & Co. KG on behalf of Sealand Europe A/S, Johanniswall 7, 20095 Hamburg"; - newServ.ServiceName = "SeaGo BHV"; - newServ.MessageHeader = this._servMessage; - newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); - this._servMessage.Elements.Add(newServ); - this.dataGridSERV.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.SERV); - } - } - - private void CheckServiceEntryHoegh() - { - bool found = false; - foreach (SERV serv in _servMessage.Elements.Cast()) - { - if (serv.ServiceBeneficiary.Equals("Höegh Autoliners AS, Oslo, Norway")) - found = true; - } - - if (!found) - { - SERV newServ = new SERV(); - newServ.ServiceBeneficiary = "Höegh Autoliners AS, Oslo, Norway"; - newServ.ServiceInvoiceRecipient = " PWL Port Services GmbH & Co. KG"; - newServ.ServiceName = "HOEGH BHV"; - newServ.MessageHeader = this._servMessage; - newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); - this._servMessage.Elements.Add(newServ); - this.dataGridSERV.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.SERV); - } - } - - private void CheckServiceEntryFctJunge() - { - bool found = false; - foreach (SERV serv in _servMessage.Elements.Cast()) - { - if (serv.ServiceName.Equals("Fct Junge - Hamburg")) - found = true; - } - - if (!found) - { - SERV newServ = new SERV(); - newServ.ServiceBeneficiary = ""; - newServ.ServiceInvoiceRecipient = " Frachtcontor Junge & Co. GmbH"; - newServ.ServiceName = "Fct Junge - Hamburg"; - newServ.MessageHeader = this._servMessage; - newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); - this._servMessage.Elements.Add(newServ); - this.dataGridSERV.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.SERV); - } - } - - private void CheckServiceEntryElbeBulk() - { - bool found = false; - foreach (SERV serv in _servMessage.Elements.Cast()) - { - if (serv.ServiceName.Equals("Elbe Bulk Schiffe - Hamburg")) - found = true; - } - - if (!found) - { - SERV newServ = new SERV(); - newServ.ServiceBeneficiary = ""; - newServ.ServiceInvoiceRecipient = " Division Elbe Bulk, Frachtcontor Junge & Co. GmbH"; - newServ.ServiceName = "Elbe Bulk Schiffe - Hamburg"; - newServ.MessageHeader = this._servMessage; - newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); - this._servMessage.Elements.Add(newServ); - this.dataGridSERV.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.SERV); - } - } + #region other event handler private void buttonSearchPortArea_Click(object sender, RoutedEventArgs e) { @@ -536,16 +495,28 @@ namespace ENI2.DetailViewControls } } + private void buttonCopyNameFromCREWA_Click(object sender, RoutedEventArgs e) + { + CREW crewA = null; + if (this._crewaMessage.Elements.Count > 0) + { + crewA = this._crewaMessage.Elements[0] as CREW; + } + + SelectCrewMemberDialog scmd = new SelectCrewMemberDialog(); + scmd.CREW = crewA; + scmd.AddVisible = false; + + if (scmd.ShowDialog() ?? false) + { + this.textBox_NameMaster.Text = $"{crewA.CrewMemberFirstName} {crewA.CrewMemberLastName}"; + this.SublistElementChanged(Message.NotificationClass.NAME); + var binding = textBox_NameMaster.GetBindingExpression(TextBox.TextProperty); + binding?.UpdateSource(); + } + } + #endregion - private void MenuItem_Click(object sender, RoutedEventArgs e) - { - - } - - private void contextMenuClearMaersk_Click(object sender, RoutedEventArgs e) - { - - } } } diff --git a/ENI2/ENI2.csproj b/ENI2/ENI2.csproj index 520cf02e..2461208b 100644 --- a/ENI2/ENI2.csproj +++ b/ENI2/ENI2.csproj @@ -18,7 +18,7 @@ - eni2.publish\ + ENI2.publish\ true Web true @@ -36,8 +36,8 @@ 5.4.0.0 true publish.html - 1 - 7.2.8.1 + 2 + 7.2.9.2 false true true @@ -137,60 +137,72 @@ packages\ExcelDataReader.3.7.0\lib\net462\ExcelDataReader.dll - - packages\log4net.3.0.4\lib\net462\log4net.dll + + packages\log4net.3.1.0\lib\net462\log4net.dll - - packages\Microsoft.Bcl.AsyncInterfaces.9.0.4\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + packages\Microsoft.Bcl.AsyncInterfaces.9.0.6\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll - - packages\Microsoft.Extensions.DependencyInjection.9.0.4\lib\net462\Microsoft.Extensions.DependencyInjection.dll + + packages\Microsoft.Bcl.Cryptography.9.0.6\lib\net462\Microsoft.Bcl.Cryptography.dll - - packages\Microsoft.Extensions.DependencyInjection.Abstractions.9.0.4\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + packages\Microsoft.Extensions.DependencyInjection.9.0.6\lib\net462\Microsoft.Extensions.DependencyInjection.dll - - packages\Microsoft.Extensions.Logging.9.0.4\lib\net462\Microsoft.Extensions.Logging.dll + + packages\Microsoft.Extensions.DependencyInjection.Abstractions.9.0.6\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll - - packages\Microsoft.Extensions.Logging.Abstractions.9.0.4\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll + + packages\Microsoft.Extensions.Logging.9.0.6\lib\net462\Microsoft.Extensions.Logging.dll - - packages\Microsoft.Extensions.Options.9.0.4\lib\net462\Microsoft.Extensions.Options.dll + + packages\Microsoft.Extensions.Logging.Abstractions.9.0.6\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll - - packages\Microsoft.Extensions.Primitives.9.0.4\lib\net462\Microsoft.Extensions.Primitives.dll + + packages\Microsoft.Extensions.Options.9.0.6\lib\net462\Microsoft.Extensions.Options.dll + + + packages\Microsoft.Extensions.Primitives.9.0.6\lib\net462\Microsoft.Extensions.Primitives.dll packages\Microsoft.Office.Interop.Excel.15.0.4795.1001\lib\net20\Microsoft.Office.Interop.Excel.dll True - - packages\PDFsharp-MigraDoc.6.1.1\lib\netstandard2.0\MigraDoc.DocumentObjectModel.dll + + packages\PDFsharp-MigraDoc.6.2.0\lib\netstandard2.0\MigraDoc.DocumentObjectModel.dll - - packages\PDFsharp-MigraDoc.6.1.1\lib\netstandard2.0\MigraDoc.Rendering.dll + + packages\PDFsharp-MigraDoc.6.2.0\lib\netstandard2.0\MigraDoc.Rendering.dll - - packages\PDFsharp-MigraDoc.6.1.1\lib\netstandard2.0\MigraDoc.RtfRendering.dll + + packages\PDFsharp-MigraDoc.6.2.0\lib\netstandard2.0\MigraDoc.RtfRendering.dll - - packages\PDFsharp-MigraDoc.6.1.1\lib\netstandard2.0\PdfSharp.dll + + packages\PDFsharp.6.2.0\lib\netstandard2.0\PdfSharp.dll - - packages\PDFsharp-MigraDoc.6.1.1\lib\netstandard2.0\PdfSharp.Charting.dll + + packages\PDFsharp.6.2.0\lib\netstandard2.0\PdfSharp.BarCodes.dll - - packages\PDFsharp-MigraDoc.6.1.1\lib\netstandard2.0\PdfSharp.Quality.dll + + packages\PDFsharp.6.2.0\lib\netstandard2.0\PdfSharp.Charting.dll - - packages\PDFsharp-MigraDoc.6.1.1\lib\netstandard2.0\PdfSharp.Snippets.dll + + packages\PDFsharp.6.2.0\lib\netstandard2.0\PdfSharp.Cryptography.dll - - packages\PDFsharp-MigraDoc.6.1.1\lib\netstandard2.0\PdfSharp.System.dll + + packages\PDFsharp.6.2.0\lib\netstandard2.0\PdfSharp.Quality.dll - - packages\PDFsharp-MigraDoc.6.1.1\lib\netstandard2.0\PdfSharp.WPFonts.dll + + packages\PDFsharp.6.2.0\lib\netstandard2.0\PdfSharp.Shared.dll + + + packages\PDFsharp.6.2.0\lib\netstandard2.0\PdfSharp.Snippets.dll + + + packages\PDFsharp.6.2.0\lib\netstandard2.0\PdfSharp.System.dll + + + packages\PDFsharp.6.2.0\lib\netstandard2.0\PdfSharp.WPFonts.dll @@ -202,10 +214,13 @@ packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\lib\net46\System.Data.SQLite.dll - - packages\System.Diagnostics.DiagnosticSource.9.0.4\lib\net462\System.Diagnostics.DiagnosticSource.dll + + packages\System.Diagnostics.DiagnosticSource.9.0.6\lib\net462\System.Diagnostics.DiagnosticSource.dll + + packages\System.Formats.Asn1.9.0.6\lib\net462\System.Formats.Asn1.dll + packages\System.Memory.4.6.3\lib\net462\System.Memory.dll @@ -218,6 +233,10 @@ packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Security.Cryptography.Pkcs.9.0.6\lib\net462\System.Security.Cryptography.Pkcs.dll + @@ -308,6 +327,9 @@ NewDGItemDialog.xaml + + SelectCrewMemberDialog.xaml + SelectPortAreaDialog.xaml @@ -793,6 +815,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -1021,6 +1047,7 @@ PreserveNewest + Always diff --git a/ENI2/EditControls/EditRulesDialog.xaml b/ENI2/EditControls/EditRulesDialog.xaml index 63859dab..a306db64 100644 --- a/ENI2/EditControls/EditRulesDialog.xaml +++ b/ENI2/EditControls/EditRulesDialog.xaml @@ -9,7 +9,7 @@ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:p="clr-namespace:ENI2.Properties" mc:Ignorable="d" - Title="{x:Static p:Resources.textEditRules}" Height="402" Width="800" WindowStyle="SingleBorderWindow" Background="AliceBlue" Icon="/ENI2;component/Resources/mail_forward.png"> + Title="{x:Static p:Resources.textEditRules}" Height="402" Width="800" WindowStyle="SingleBorderWindow" Background="AliceBlue" Icon="/ENI2;component/Resources/mail_forward.png"> diff --git a/ENI2/EditControls/EditSERVDialog.xaml.cs b/ENI2/EditControls/EditSERVDialog.xaml.cs index c2284d7f..e66f03a5 100644 --- a/ENI2/EditControls/EditSERVDialog.xaml.cs +++ b/ENI2/EditControls/EditSERVDialog.xaml.cs @@ -1,5 +1,5 @@ // Copyright (c) 2017 schick Informatik -// Description: +// Description: Edit SERV and SERV_template entities // using System.Windows; @@ -14,36 +14,78 @@ namespace ENI2.EditControls /// public partial class EditSERVDialog : EditWindowBase { + + #region Construction + public EditSERVDialog() { InitializeComponent(); Loaded += EditSERVDialog_Loaded; } + #endregion + + #region Properties + + public SERV SERV { get; set; } + + public SERV_Template SERV_Template { get; set; } + + #endregion + + #region event handler + private void EditSERVDialog_Loaded(object sender, RoutedEventArgs e) { this.OKClicked += EditSERVDialog_OKClicked; // copy into fields - this.textBoxServiceName.Text = this.SERV.ServiceName; - this.textBoxServiceBeneficiary.Text = this.SERV.ServiceBeneficiary; - this.textBoxServiceInvoiceRecipient.Text = this.SERV.ServiceInvoiceRecipient; - this.AddVisible = true; + if (this.SERV != null) + { + this.textBoxServiceName.Text = this.SERV.ServiceName; + this.textBoxServiceBeneficiary.Text = this.SERV.ServiceBeneficiary; + this.textBoxServiceInvoiceRecipient.Text = this.SERV.ServiceInvoiceRecipient; + this.AddVisible = true; + } + + if (this.SERV_Template != null) + { + this.textBoxServiceName.Text = this.SERV_Template.ServiceName; + this.textBoxServiceBeneficiary.Text = this.SERV_Template.ServiceBeneficiary; + this.textBoxServiceInvoiceRecipient.Text = this.SERV_Template.ServiceInvoiceRecipient; + } } + private void EditSERVDialog_OKClicked() + { + this.CopyValuesToEntity(); + } + + #endregion + + #region public methods public void CopyValuesToEntity() { - // copy back - this.SERV.ServiceName = this.textBoxServiceName.Text.Trim(); - this.SERV.ServiceBeneficiary = this.textBoxServiceBeneficiary.Text.Trim(); - this.SERV.ServiceInvoiceRecipient = this.textBoxServiceInvoiceRecipient.Text.Trim(); + + if (this.SERV != null) + { + // copy back + this.SERV.ServiceName = this.textBoxServiceName.Text.Trim(); + this.SERV.ServiceBeneficiary = this.textBoxServiceBeneficiary.Text.Trim(); + this.SERV.ServiceInvoiceRecipient = this.textBoxServiceInvoiceRecipient.Text.Trim(); + } + + if (this.SERV_Template != null) + { + // copy back + this.SERV_Template.ServiceName = this.textBoxServiceName.Text.Trim(); + this.SERV_Template.ServiceBeneficiary = this.textBoxServiceBeneficiary.Text.Trim(); + this.SERV_Template.ServiceInvoiceRecipient = this.textBoxServiceInvoiceRecipient.Text.Trim(); + } + } - private void EditSERVDialog_OKClicked() - { - this.CopyValuesToEntity(); - } - - public SERV SERV { get; set; } + #endregion + } } diff --git a/ENI2/EditControls/NewDGItemDialog.xaml b/ENI2/EditControls/NewDGItemDialog.xaml index 3a85d0ec..2d10c678 100644 --- a/ENI2/EditControls/NewDGItemDialog.xaml +++ b/ENI2/EditControls/NewDGItemDialog.xaml @@ -8,7 +8,7 @@ xmlns:p="clr-namespace:ENI2.Properties" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" mc:Ignorable="d" - Title="{x:Static p:Resources.textNewDGItem}" Height="350" Width="600" WindowStyle="SingleBorderWindow" Background="AliceBlue" ResizeMode="CanResize" + Title="{x:Static p:Resources.textNewDGItem}" Height="350" Width="600" WindowStyle="SingleBorderWindow" Background="AliceBlue" ResizeMode="CanResize" Icon="/ENI2;component/Resources/bullet_ball_yellow.ico" Loaded="EditWindowBase_Loaded"> diff --git a/ENI2/EditControls/NewWithIdDialog.xaml b/ENI2/EditControls/NewWithIdDialog.xaml index b195c189..0fb1a1fa 100644 --- a/ENI2/EditControls/NewWithIdDialog.xaml +++ b/ENI2/EditControls/NewWithIdDialog.xaml @@ -9,7 +9,7 @@ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" mc:Ignorable="d" Title="{x:Static p:Resources.textNewWithId}" Height="220" Width="350" WindowStyle="SingleBorderWindow" Background="AliceBlue" ResizeMode="NoResize" Icon="/ENI2;component/Resources/id_card_add.ico"> - + diff --git a/ENI2/EditControls/SelectCrewMemberDialog.xaml b/ENI2/EditControls/SelectCrewMemberDialog.xaml new file mode 100644 index 00000000..d57b5165 --- /dev/null +++ b/ENI2/EditControls/SelectCrewMemberDialog.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + diff --git a/ENI2/EditControls/SelectCrewMemberDialog.xaml.cs b/ENI2/EditControls/SelectCrewMemberDialog.xaml.cs new file mode 100644 index 00000000..2583a21c --- /dev/null +++ b/ENI2/EditControls/SelectCrewMemberDialog.xaml.cs @@ -0,0 +1,41 @@ +// Copyright (c) 2017- schick Informatik +// Description: +// + +using bsmd.database; +using ENI2.Controls; +using System.Windows; + +namespace ENI2.EditControls +{ + /// + /// Interaction logic for SelectCrewMemberDialog.xaml + /// + public partial class SelectCrewMemberDialog : EditWindowBase + { + public SelectCrewMemberDialog() + { + InitializeComponent(); + Loaded += SelectCrewMemberDialog_Loaded; + } + + #region Properties + + public CREW CREW { get; set; } + + #endregion + + #region event handler + + private void SelectCrewMemberDialog_Loaded(object sender, RoutedEventArgs e) + { + if (CREW != null) + { + this.DataContext = CREW; + } + } + + #endregion + + } +} diff --git a/ENI2/MainWindow.xaml b/ENI2/MainWindow.xaml index 85d655fb..02ab6d57 100644 --- a/ENI2/MainWindow.xaml +++ b/ENI2/MainWindow.xaml @@ -10,9 +10,9 @@ xmlns:util="clr-namespace:ENI2.Util" xmlns:local="clr-namespace:ENI2" mc:Ignorable="d" - Title="ENI 2" - Height="{util:SettingBinding Height}" Width="{util:SettingBinding Width}" - Icon="Resources/logo_schwarz.ico" Loaded="Window_Loaded" Closing="Window_Closing" + Title="ENI 2" + Height="{util:SettingBinding Height}" Width="{util:SettingBinding Width}" + Icon="Resources/logo_schwarz.ico" Loaded="Window_Loaded" Closing="Window_Closing" SourceInitialized="Window_SourceInitialized"> diff --git a/ENI2/Properties/Resources.Designer.cs b/ENI2/Properties/Resources.Designer.cs index ffaba11f..86c7a834 100644 --- a/ENI2/Properties/Resources.Designer.cs +++ b/ENI2/Properties/Resources.Designer.cs @@ -750,6 +750,16 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + public static System.Drawing.Bitmap pencil { + get { + object obj = ResourceManager.GetObject("pencil", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -2011,7 +2021,7 @@ namespace ENI2.Properties { } /// - /// Looks up a localized string similar to Columns "o" of OBC Code (value 15.19). + /// Looks up a localized string similar to Columns "o" of IBC Code (value 15.19). /// public static string textColumsOfIBC { get { @@ -2253,6 +2263,15 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized string similar to Copy from CREWA. + /// + public static string textCopyFromCREWA { + get { + return ResourceManager.GetString("textCopyFromCREWA", resourceCulture); + } + } + /// /// Looks up a localized string similar to Copy from last 10 port facilities called. /// @@ -5259,6 +5278,15 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized string similar to Select crew member. + /// + public static string textSelectCrewMember { + get { + return ResourceManager.GetString("textSelectCrewMember", resourceCulture); + } + } + /// /// Looks up a localized string similar to Select classes to import. /// @@ -5358,6 +5386,15 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized string similar to SERV-Template. + /// + public static string textSERVTemplate { + get { + return ResourceManager.GetString("textSERVTemplate", resourceCulture); + } + } + /// /// Looks up a localized string similar to Ship-to-ship activity. /// diff --git a/ENI2/Properties/Resources.resx b/ENI2/Properties/Resources.resx index 8f6f801c..89059ac3 100644 --- a/ENI2/Properties/Resources.resx +++ b/ENI2/Properties/Resources.resx @@ -2233,4 +2233,16 @@ SEC simplification available + + Copy from CREWA + + + Select crew member + + + SERV-Template + + + ..\Resources\pencil.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/ENI2/Resources/pencil.png b/ENI2/Resources/pencil.png new file mode 100644 index 00000000..68f35048 Binary files /dev/null and b/ENI2/Resources/pencil.png differ diff --git a/ENI2/SheetDisplayControls/CrewPreArrivalControl.xaml b/ENI2/SheetDisplayControls/CrewPreArrivalControl.xaml index 70d44d8b..b5cb7a33 100644 --- a/ENI2/SheetDisplayControls/CrewPreArrivalControl.xaml +++ b/ENI2/SheetDisplayControls/CrewPreArrivalControl.xaml @@ -30,6 +30,7 @@ diff --git a/ENI2/SheetDisplayControls/PortControl.xaml.cs b/ENI2/SheetDisplayControls/PortControl.xaml.cs index 13491d60..99d6cabc 100644 --- a/ENI2/SheetDisplayControls/PortControl.xaml.cs +++ b/ENI2/SheetDisplayControls/PortControl.xaml.cs @@ -34,7 +34,7 @@ namespace ENI2.SheetDisplayControls private SEC _sec; private WAS _was; private Message _stoMessage; - private Message _crewMessage; + // private Message _crewMessage; private Dictionary portAreas = null; @@ -42,6 +42,9 @@ namespace ENI2.SheetDisplayControls private AGNT_Template _currentTemplate; private AGNT_Template _undoTemplate; + private static List _servTemplates = null; + private SERV_Template _currentSERVTemplate; + private static List _wsdpTemplates = null; private WasteDisposalServiceProvider_Template _currentWSDPTemplate; private string _undoWSDPTemplate; @@ -90,7 +93,7 @@ namespace ENI2.SheetDisplayControls if (aMessage.MessageNotificationClass == Message.NotificationClass.AGNT) { this._agnt = aMessage.Elements[0] as AGNT; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.WAS) { this._was = aMessage.Elements[0] as WAS; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.STO) { this._stoMessage = aMessage; this.ControlMessages.Add(aMessage); } - if (aMessage.MessageNotificationClass == Message.NotificationClass.CREWA) { this._crewMessage = aMessage; this.ControlMessages.Add(aMessage); } + // if (aMessage.MessageNotificationClass == Message.NotificationClass.CREWA) { this._crewMessage = aMessage; this.ControlMessages.Add(aMessage); } } // 2.1 @@ -202,6 +205,23 @@ namespace ENI2.SheetDisplayControls // this.dataGridEffects.Initialize(); // this.dataGridEffects.ItemsSource = _crewMessage.Elements; + #region init SERV templates + + if (_servTemplates == null) + { + _servTemplates = await DBManagerAsync.GetSERVTemplatesAsync(); // initial load + _servTemplates.Sort(); + Trace.WriteLine($"{_servTemplates.Count} SERV templates loaded"); + } + + 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 + } public override int SelectedTabIndex @@ -576,38 +596,7 @@ namespace ENI2.SheetDisplayControls stream.Close(); } - } - - private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - // clear all - this.Core.SetFlag(false, MessageCore.CoreFlags.MAERSK_BHV); - this.Core.SetFlag(false, MessageCore.CoreFlags.SEAGO_BHV); - this.Core.SetFlag(false, MessageCore.CoreFlags.SEAGO_WHV); - this.Core.SetFlag(false, MessageCore.CoreFlags.HOEGH); - this.Core.SetFlag(false, MessageCore.CoreFlags.ELBE_BULK); - this.Core.SetFlag(false, MessageCore.CoreFlags.FCT_JUNGE); - - if (this.comboBoxGroup.SelectedItem == null) - { - this.comboBoxGroup.SelectedIndex = 0; - DBManager.Instance.Save(this.Core); - } - else - { - DictionaryEntry selectedItem = (DictionaryEntry)this.comboBoxGroup.SelectedItem; - if (Int32.TryParse((string)selectedItem.Value, out int selectedValue)) - { - if (selectedValue == (int)MessageCore.CoreFlags.MAERSK_BHV) CheckServiceEntryMaerskBHV(); - if (selectedValue == (int)MessageCore.CoreFlags.SEAGO_BHV) CheckServiceEntrySeaGoBHV(); - if (selectedValue == (int)MessageCore.CoreFlags.HOEGH) CheckServiceEntryHoegh(); - if (selectedValue == (int)MessageCore.CoreFlags.ELBE_BULK) CheckServiceEntryElbeBulk(); - if (selectedValue == (int)MessageCore.CoreFlags.FCT_JUNGE) CheckServiceEntryFctJunge(); - this.Core.SetFlag(true, (MessageCore.CoreFlags)selectedValue); - DBManager.Instance.Save(this.Core); - } - } - } + } #endregion @@ -1148,6 +1137,99 @@ namespace ENI2.SheetDisplayControls } #endregion - + + #region SERV template button event handler + + private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (this.comboBoxGroup.SelectedItem is SERV_Template st) + { + this.buttonDeleteSERVTemplate.IsEnabled = true; + this.buttonSetSERVTemplate.IsEnabled = true; + this._currentSERVTemplate = st; + } + } + + private void buttonSetSERVTemplate_Click(object sender, RoutedEventArgs e) + { + if (this.comboBoxGroup.SelectedItem is SERV_Template st) + { + bool found = false; + foreach (SERV serv in _servMessage.Elements.Cast()) + { + if (serv.ServiceName.Equals(st.ServiceName)) + { + found = true; break; + } + } + + if (!found) + { + SERV newServ = new SERV(); + newServ.ServiceName = st.ServiceName; + newServ.ServiceBeneficiary = st.ServiceBeneficiary; + newServ.ServiceInvoiceRecipient = st.ServiceInvoiceRecipient; + + newServ.MessageHeader = this._servMessage; + newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); + this._servMessage.Elements.Add(newServ); + this.dataGridSERV.Items.Refresh(); + 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 + } } diff --git a/ENI2/packages.config b/ENI2/packages.config index 14b54d2b..a24d5db7 100644 --- a/ENI2/packages.config +++ b/ENI2/packages.config @@ -2,23 +2,27 @@ - - - - - - - - + + + + + + + + + - + + - + + + \ No newline at end of file diff --git a/SQL/SERV_template.sql b/SQL/SERV_template.sql new file mode 100644 index 00000000..2038fa1d --- /dev/null +++ b/SQL/SERV_template.sql @@ -0,0 +1,25 @@ +PRINT N'Creating [dbo].[SERV_template]...'; + +GO +CREATE TABLE [dbo].[SERV_template] ( + [Id] UNIQUEIDENTIFIER NOT NULL, + [ServiceName] NVARCHAR (100) NULL, + [ServiceBeneficiary] NVARCHAR (256) NULL, + [ServiceInvoiceRecipient] NVARCHAR (256) NULL, + [Created] DATETIME NULL DEFAULT CURRENT_TIMESTAMP, + [Changed] DATETIME NULL, + PRIMARY KEY CLUSTERED ([Id] ASC) +); + +GO + +CREATE TRIGGER SERV_template_Trigger_Change_Log +ON + dbo.SERV_template + FOR UPDATE + AS + SET NOCOUNT ON + IF NOT UPDATE([Changed]) + UPDATE SERV_template SET [Changed] = GETDATE() WHERE Id IN (SELECT Id FROM [inserted]) + +GO \ No newline at end of file diff --git a/bsmd.LockingService/bsmd.LockingService.csproj b/bsmd.LockingService/bsmd.LockingService.csproj index 18d2d500..d56c3074 100644 --- a/bsmd.LockingService/bsmd.LockingService.csproj +++ b/bsmd.LockingService/bsmd.LockingService.csproj @@ -46,8 +46,8 @@ 4 - - ..\ENI2\packages\log4net.3.0.4\lib\net462\log4net.dll + + ..\ENI2\packages\log4net.3.1.0\lib\net462\log4net.dll diff --git a/bsmd.LockingService/packages.config b/bsmd.LockingService/packages.config index fbd6f896..362ab867 100644 --- a/bsmd.LockingService/packages.config +++ b/bsmd.LockingService/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/bsmd.Tool/App.config b/bsmd.Tool/App.config index ec50e784..9a2087dd 100644 --- a/bsmd.Tool/App.config +++ b/bsmd.Tool/App.config @@ -1,36 +1,72 @@ - + -
- -
+
+ +
- - + + - - - - - - + + + + + + - + - + - - - - replace me! - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + replace me! + + + + + + 4 + + + C:\temp\hisnord + + + C:\temp\dbh + + + diff --git a/bsmd.Tool/Echolot.cs b/bsmd.Tool/Echolot.cs new file mode 100644 index 00000000..1e3dcf88 --- /dev/null +++ b/bsmd.Tool/Echolot.cs @@ -0,0 +1,224 @@ +// Copyright (c) 2020- schick Informatik +// Description: The purpose of this tool is to evaluate files sent both through HIS-Nord and dbh +// to evaluate how many classes were sent at what time and by whom to the purpose of improved employee +// time planning + + +using ClosedXML.Excel; +using log4net; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace bsmd.Tool +{ + internal static class Echolot + { + + private static readonly ILog _log = LogManager.GetLogger(typeof(Echolot)); + + static readonly HashSet ValidGroupingKeys = new HashSet + { + "VISIT", + "TRANSIT", + "NOA_NOD", + "NOANOD", + "ATA", + "ATD", + "SEC", + "POBA", + "POBD", + "NAME", + "TIEFA", + "TIEFD", + "BKRA", + "BKRD", + "STAT", + "LADG", + "INFO", + "SERV", + "PRE72H", + "MDH", + "WAS", + "CREWA", + "PASA", + "BPOL", + "TOWA", + "TOWD", + "HAZA", + "HAZD", + "AGNT", + "STO", + "CREWD", + "PASD", + "WAS_RCPT" + }; + + static readonly HashSet IgnoreGroupingKeys = new HashSet + { + "VISIT", + "TRANSIT", + "ATA", + "ATD" + }; + + internal static void Evaluate(string outputFolder, int maxThreads) + { + DateTime executionTime = DateTime.Now; + + #region first scan: dbh files + + string inputFolder = Properties.Settings.Default.DBH_Folder; + var files = Directory.GetFiles(inputFolder, "*.xml"); + var results = new ConcurrentBag(); + + Parallel.ForEach(files, new ParallelOptions { MaxDegreeOfParallelism = maxThreads }, file => + { + try + { + var doc = XDocument.Load(file); + + // Look for a valid grouping key at the root level + var groupingElem = doc.Root.Elements() + .FirstOrDefault(x => ValidGroupingKeys.Contains(x.Name.LocalName) && !IgnoreGroupingKeys.Contains(x.Name.LocalName)); + + if (groupingElem == null) + { + _log.InfoFormat("skipping {0}", file); + return; // Skip file + } + + var lastName = doc.Descendants("RPLastName").FirstOrDefault()?.Value?.Trim(); + var firstName = doc.Descendants("RPFirstName").FirstOrDefault()?.Value?.Trim(); + var timestampStr = doc.Descendants("Timestamp").FirstOrDefault()?.Value?.Trim(); + + DateTime timestamp = DateTime.Parse(timestampStr); + + results.Add(new ResultRow + { + FirstName = firstName, + LastName = lastName, + Timestamp = timestamp, + WeekStart = GetWeekStart(timestamp, executionTime.DayOfWeek), + Provider = "DBH" + }); + } + catch (Exception ex) + { + _log.Error(ex.ToString()); + } + }); + + #endregion + + #region second scan: his-nord files + + var inputFolder2 = Properties.Settings.Default.HISNORD_Folder; + var files2 = Directory.GetFiles(inputFolder2, "*.xml"); + + Parallel.ForEach(files2, new ParallelOptions { MaxDegreeOfParallelism = maxThreads }, file => + { + try + { + var doc = XDocument.Load(file); + + var match = Regex.Match(file, @"-([A-Z0-9_]+)\.xml$", RegexOptions.None); + + string key = ""; + if (match.Success) + { + key = match.Groups[1].Value; + } + + if((key.Length == 0) || IgnoreGroupingKeys.Contains(key)) + { + _log.InfoFormat("skipping {0}", file); + return; // Skip file + } + + var username = doc.Descendants("firstname").FirstOrDefault()?.Value?.Trim(); + if(username == null) + { + _log.WarnFormat("Username not found in file {0}", file); + return; + } + var splitname = username.Split(' '); + var lastName = splitname[1].Trim(); + var firstName = splitname[0].Trim(); + + DateTime timestamp = File.GetCreationTime(file); + + results.Add(new ResultRow + { + FirstName = firstName, + LastName = lastName, + Timestamp = timestamp, + WeekStart = GetWeekStart(timestamp, executionTime.DayOfWeek), + Provider = "HIS-NORD" + }); + } + catch (Exception ex) + { + _log.Error(ex.ToString()); + } + }); + + + #endregion + + var grouped = results + .GroupBy(r => r.WeekStart) + .OrderBy(g => g.Key); + + + // Write Excel + string excelFile = Path.Combine(outputFolder, $"echolot_{executionTime:yyyyMMdd_HHmmss}.xlsx"); + using (var workbook = new XLWorkbook()) + { + foreach (var weekGroup in grouped) + { + var ws = workbook.Worksheets.Add(weekGroup.Key.ToString("yyyy-MM-dd")); + ws.Cell(1, 1).Value = "Firstname"; + ws.Cell(1, 2).Value = "Lastname"; + ws.Cell(1, 3).Value = "Count"; + int row = 2; + + var orderedGroups = weekGroup + .GroupBy(x => new { x.FirstName, x.LastName }) + .OrderByDescending(g => g.Count()); // Use OrderBy for ascending + + + foreach (var nameGroup in orderedGroups) + { + ws.Cell(row, 1).Value = nameGroup.Key.FirstName; + ws.Cell(row, 2).Value = nameGroup.Key.LastName; + ws.Cell(row, 3).Value = nameGroup.Count(); + row++; + } + } + workbook.SaveAs(excelFile); + } + } + + static DateTime GetWeekStart(DateTime date, DayOfWeek weekStart) + { + int diff = (7 + (date.DayOfWeek - weekStart)) % 7; + return date.Date.AddDays(-1 * diff); + } + + class ResultRow + { + public string FirstName { get; set; } + public string LastName { get; set; } + public DateTime Timestamp { get; set; } + public DateTime WeekStart { get; set; } + public string Provider { get; set; } + } + + } +} diff --git a/bsmd.Tool/Options.cs b/bsmd.Tool/Options.cs index 026e703c..ae1a507d 100644 --- a/bsmd.Tool/Options.cs +++ b/bsmd.Tool/Options.cs @@ -25,6 +25,18 @@ namespace bsmd.Tool [Option("locodes", HelpText = "use this flag if you want to import locodes")] public bool ImportLocodes { get; set; } + [Option("echolot", HelpText = "use this flag to run the echolot output file evaluation")] + public bool Echolot { get; set; } + + [Option('i', "input_folder", HelpText = "Input folder")] + public string InputFolder { get; set; } + + [Option('o', "output_folder", HelpText = "Output folder")] + public string OutputFolder { get; set; } + + [Option("max_threads", HelpText = "Maximum amount of parallelism for folder parsing")] + public int? MaxThreads { get; set; } + [Option('s', "staledays", Default = 30, HelpText ="Delete files older than X days")] public int StaleDays { get; set; } diff --git a/bsmd.Tool/Program.cs b/bsmd.Tool/Program.cs index 54909cb8..82e2b3ac 100644 --- a/bsmd.Tool/Program.cs +++ b/bsmd.Tool/Program.cs @@ -1,4 +1,5 @@ -using CommandLine; +using bsmd.database; +using CommandLine; using log4net; using System; @@ -40,15 +41,24 @@ namespace bsmd.Tool LocodeSQliteImport.Import(o.LocodeDB, o.LocodeCSV); } } + if(o.Echolot) + { + string outputFolder = Properties.Settings.Default.EcholotOutputFolder; + if (!o.OutputFolder.IsNullOrEmpty()) + outputFolder = o.OutputFolder; + int maxThreads = 2; + if (o.MaxThreads.HasValue) maxThreads = o.MaxThreads.Value; + Echolot.Evaluate(outputFolder, maxThreads); + } }); } catch (Exception ex) { log.Fatal(ex.ToString()); + Console.WriteLine(ex.Message); result = 1; - } - Console.Read(); + } return result; } } diff --git a/bsmd.Tool/Properties/Settings.Designer.cs b/bsmd.Tool/Properties/Settings.Designer.cs index 4d40f00d..a26903d7 100644 --- a/bsmd.Tool/Properties/Settings.Designer.cs +++ b/bsmd.Tool/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace bsmd.Tool.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -23,15 +23,48 @@ namespace bsmd.Tool.Properties { } } - [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("replace me!")] public string ConnectionString { get { return ((string)(this["ConnectionString"])); } - set { - this["ConnectionString"] = value; + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string EcholotOutputFolder { + get { + return ((string)(this["EcholotOutputFolder"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("4")] + public int EcholotMaxThreads { + get { + return ((int)(this["EcholotMaxThreads"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("C:\\temp\\hisnord")] + public string HISNORD_Folder { + get { + return ((string)(this["HISNORD_Folder"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("C:\\temp\\dbh")] + public string DBH_Folder { + get { + return ((string)(this["DBH_Folder"])); } } } diff --git a/bsmd.Tool/Properties/Settings.settings b/bsmd.Tool/Properties/Settings.settings index 07cf4d90..3785f743 100644 --- a/bsmd.Tool/Properties/Settings.settings +++ b/bsmd.Tool/Properties/Settings.settings @@ -2,8 +2,20 @@ - + replace me! + + + + + 4 + + + C:\temp\hisnord + + + C:\temp\dbh + \ No newline at end of file diff --git a/bsmd.Tool/bsmd.Tool.csproj b/bsmd.Tool/bsmd.Tool.csproj index 92d23e99..877acf69 100644 --- a/bsmd.Tool/bsmd.Tool.csproj +++ b/bsmd.Tool/bsmd.Tool.csproj @@ -44,25 +44,62 @@ ..\bsmd.database\bin\Debug\bsmd.database.dll + + ..\packages\ClosedXML.0.105.0\lib\netstandard2.0\ClosedXML.dll + + + ..\packages\ClosedXML.Parser.2.0.0\lib\netstandard2.0\ClosedXML.Parser.dll + ..\packages\CommandLineParser.2.9.1\lib\net461\CommandLine.dll - - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\DocumentFormat.OpenXml.3.1.1\lib\net46\DocumentFormat.OpenXml.dll + + + ..\packages\DocumentFormat.OpenXml.Framework.3.1.1\lib\net46\DocumentFormat.OpenXml.Framework.dll + + + ..\packages\ExcelNumberFormat.1.1.0\lib\net20\ExcelNumberFormat.dll + + + ..\packages\log4net.3.1.0\lib\net462\log4net.dll + + + ..\packages\Microsoft.Bcl.HashCode.1.1.1\lib\net461\Microsoft.Bcl.HashCode.dll + + + ..\packages\RBush.Signed.4.0.0\lib\net47\RBush.dll + + + ..\packages\SixLabors.Fonts.1.0.0\lib\netstandard2.0\SixLabors.Fonts.dll + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + - - ..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.117.0\lib\net46\System.Data.SQLite.dll + + ..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\lib\net46\System.Data.SQLite.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + @@ -76,6 +113,7 @@ + @@ -89,6 +127,7 @@ + SettingsSingleFileGenerator @@ -96,12 +135,12 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/bsmd.Tool/packages.config b/bsmd.Tool/packages.config index 31f24d70..6fb49e25 100644 --- a/bsmd.Tool/packages.config +++ b/bsmd.Tool/packages.config @@ -1,7 +1,19 @@  + + - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/bsmd.database/CREW.cs b/bsmd.database/CREW.cs index f576d7b4..d061f246 100644 --- a/bsmd.database/CREW.cs +++ b/bsmd.database/CREW.cs @@ -137,8 +137,8 @@ namespace bsmd.database } } - [ENI2Validation] - [MaxLength(256)] + //[ENI2Validation] + //[MaxLength(256)] public string Effects { get; set; } [ENI2Validation] diff --git a/bsmd.database/DBManagerAsync.cs b/bsmd.database/DBManagerAsync.cs index 3f5202d2..acd8d9ae 100644 --- a/bsmd.database/DBManagerAsync.cs +++ b/bsmd.database/DBManagerAsync.cs @@ -112,6 +112,16 @@ namespace bsmd.database return (await at.LoadListAsync(reader)).ConvertAll(x => (AGNT_Template)x); } + public static async Task> GetSERVTemplatesAsync() + { + SqlCommand cmd = new SqlCommand(); + SERV_Template st = new SERV_Template(); + st.PrepareLoadCommand(cmd, Message.LoadFilter.ALL); + SqlDataReader reader = await PerformCommandAsync(cmd); + return (await st.LoadListAsync(reader)).ConvertAll(x => (SERV_Template)x); + } + + public static async Task> GetWastDisposalServiceProviderTemplatesAsync() { SqlCommand cmd = new SqlCommand(); diff --git a/bsmd.database/Properties/AssemblyProductInfo.cs b/bsmd.database/Properties/AssemblyProductInfo.cs index 992ffe9a..fddc156f 100644 --- a/bsmd.database/Properties/AssemblyProductInfo.cs +++ b/bsmd.database/Properties/AssemblyProductInfo.cs @@ -2,6 +2,6 @@ [assembly: AssemblyCompany("schick Informatik")] [assembly: AssemblyProduct("BSMD NSW interface")] -[assembly: AssemblyInformationalVersion("7.2.8")] +[assembly: AssemblyInformationalVersion("7.2.9")] [assembly: AssemblyCopyright("Copyright © 2014-2025 schick Informatik")] [assembly: AssemblyTrademark("")] \ No newline at end of file diff --git a/bsmd.database/Properties/AssemblyProjectInfo.cs b/bsmd.database/Properties/AssemblyProjectInfo.cs index cf4fdec9..92c6d524 100644 --- a/bsmd.database/Properties/AssemblyProjectInfo.cs +++ b/bsmd.database/Properties/AssemblyProjectInfo.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("7.2.8.*")] +[assembly: AssemblyVersion("7.2.9.*")] diff --git a/bsmd.database/SERV_Template.cs b/bsmd.database/SERV_Template.cs new file mode 100644 index 00000000..8e47d51a --- /dev/null +++ b/bsmd.database/SERV_Template.cs @@ -0,0 +1,128 @@ +// Copyright (c) 2024-present schick Informatik +// Description: + +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 +{ + public class SERV_Template : DatabaseEntityAsync, IComparable + { + #region Construction + + public SERV_Template() + { + this.tablename = "[dbo].[SERV_template]"; + } + + #endregion + + #region Properties + + [MaxLength(99)] + public string ServiceName { get; set; } + + [MaxLength(255)] + public string ServiceBeneficiary { get; set; } + + [MaxLength(255)] + public string ServiceInvoiceRecipient { get; set; } + + #endregion + + #region DatabaseEntity implementation + + public override void PrepareSave(IDbCommand cmd) + { + SqlCommand scmd = cmd as SqlCommand; + + if (this.ServiceName != null) scmd.Parameters.AddWithValue("@P1", this.ServiceName); + else scmd.Parameters.AddWithValue("@P1", DBNull.Value); + if (this.ServiceBeneficiary != null) scmd.Parameters.AddWithValue(@"P2", this.ServiceBeneficiary); + else scmd.Parameters.AddWithValue("@P2", DBNull.Value); + if (this.ServiceInvoiceRecipient != null) scmd.Parameters.AddWithValue("@P3", this.ServiceInvoiceRecipient); + else scmd.Parameters.AddWithValue("@P3", DBNull.Value); + + if (this.IsNew) + { + this.CreateId(); + cmd.CommandText = string.Format("INSERT INTO {0} (Id, ServiceName, ServiceBeneficiary, ServiceInvoiceRecipient) VALUES " + + "(@ID, @P1, @P2, @P3)", this.Tablename); + } + else + { + cmd.CommandText = string.Format("UPDATE {0} SET ServiceName = @P1, ServiceBeneficiary = @P2, ServiceInvoiceRecipient = @P3 WHERE Id = @ID", this.Tablename); + } + scmd.Parameters.AddWithValue("@ID", this.Id); + } + + public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) + { + string query = string.Format("SELECT Id, ServiceName, ServiceBeneficiary, ServiceInvoiceRecipient FROM {0}", this.Tablename); + + switch (filter) + { + case Message.LoadFilter.ALL: + default: + + break; + } + cmd.CommandText = query; + } + + public override List LoadList(System.Data.IDataReader reader) + { + List result = new List(); + + while (reader.Read()) + { + SERV_Template serv_t = new SERV_Template(); + serv_t.id = reader.GetGuid(0); + if (!reader.IsDBNull(1)) serv_t.ServiceName = reader.GetString(1); + if (!reader.IsDBNull(2)) serv_t.ServiceBeneficiary = reader.GetString(2); + if (!reader.IsDBNull(3)) serv_t.ServiceInvoiceRecipient = reader.GetString(3); + + result.Add(serv_t); + } + reader.Close(); + return result; + } + + protected override DatabaseEntityAsync ReadRowFromReader(IDataReader reader) + { + SERV_Template serv_t = null; + if (reader != null) + { + serv_t = new SERV_Template(); + serv_t.id = reader.GetGuid(0); + if (!reader.IsDBNull(1)) serv_t.ServiceName = reader.GetString(1); + if (!reader.IsDBNull(2)) serv_t.ServiceBeneficiary = reader.GetString(2); + if (!reader.IsDBNull(3)) serv_t.ServiceInvoiceRecipient = reader.GetString(3); + + } + return serv_t; + } + + #endregion + + + #region IComparable implementation + + public int CompareTo(object obj) + { + if (obj is SERV_Template template) + { + return this.ServiceName.CompareTo(template.ServiceName); + } + return 0; + } + + #endregion + + } +} diff --git a/bsmd.database/bsmd.database.csproj b/bsmd.database/bsmd.database.csproj index 2fa7966e..e9cf02a2 100644 --- a/bsmd.database/bsmd.database.csproj +++ b/bsmd.database/bsmd.database.csproj @@ -89,8 +89,8 @@ False - - ..\ENI2\packages\log4net.3.0.4\lib\net462\log4net.dll + + ..\ENI2\packages\log4net.3.1.0\lib\net462\log4net.dll ..\ENI2\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll @@ -173,6 +173,7 @@ + diff --git a/bsmd.database/packages.config b/bsmd.database/packages.config index 21dbfcbd..fbfa0890 100644 --- a/bsmd.database/packages.config +++ b/bsmd.database/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file