diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index 2fbd48ab..4c566228 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/SQL/Update_3.5.1_To_4.0.sql b/nsw/Source/SQL/Update_3.5.1_To_4.0.sql index 520ec4a5..5f4b00d4 100644 --- a/nsw/Source/SQL/Update_3.5.1_To_4.0.sql +++ b/nsw/Source/SQL/Update_3.5.1_To_4.0.sql @@ -15,4 +15,15 @@ ALTER TABLE [dbo].[SEC] ADD [AreMatterToReport] bit NULL; GO --- bis hierhin schon aktualisiert \ No newline at end of file +PRINT N'Altering [dbo].[MessageCore]...'; + + +GO +ALTER TABLE [dbo].[MessageCore] + ADD [CreateExcel] BIT NULL; + + +GO + +-- bis hierhin schon aktualisiert + diff --git a/nsw/Source/bsmd.ExcelReadService/Confirmation.cs b/nsw/Source/bsmd.ExcelReadService/Confirmation.cs index 02722ad2..5d8f6358 100644 --- a/nsw/Source/bsmd.ExcelReadService/Confirmation.cs +++ b/nsw/Source/bsmd.ExcelReadService/Confirmation.cs @@ -74,8 +74,7 @@ namespace bsmd.ExcelReadService nameDict[workbookName.Name].Add(workbookName); } - } - + } workbooks.Add(aWorkbook); diff --git a/nsw/Source/bsmd.ExcelReadService/ExcelBase.cs b/nsw/Source/bsmd.ExcelReadService/ExcelBase.cs new file mode 100644 index 00000000..a7039db0 --- /dev/null +++ b/nsw/Source/bsmd.ExcelReadService/ExcelBase.cs @@ -0,0 +1,103 @@ +// Copyright (c) 2017 Informatikbüro Daniel Schick +// + + +using System; +using System.Collections.Generic; +using Microsoft.Office.Interop.Excel; +using System.Runtime.InteropServices; +using log4net; + +namespace bsmd.ExcelReadService +{ + internal class ExcelBase : IDisposable + { + + #region Fields + + internal enum CountryMode { NONE, DE, DK }; + + protected CountryMode _countryMode = CountryMode.NONE; + + protected Workbooks _excelWorkbooks; + protected Workbook _portcall; + protected Application _excelApp; + protected Dictionary _nameDict; + protected ILog _log; + + #endregion + + #region Properties + + internal CountryMode Mode { get { return _countryMode; } } + + #endregion + + #region Saving + + internal bool Save(string filePath) + { + bool result = true; + if (this._excelApp == null) return false; + try + { + this._excelApp.SaveWorkspace(filePath); + } + catch (Exception ex) + { + _log.WarnFormat("cannot save workspace: {0}", ex.Message); + result = false; + } + return result; + } + + internal bool SaveCopy(string filePath) + { + bool result = true; + if (this._excelApp == null) return false; + try + { + this._portcall.Saved = true; + this._portcall.SaveCopyAs(filePath); + } + catch (Exception ex) + { + _log.WarnFormat("cannot save copy of workbook: {0}", ex.Message); + result = false; + } + return result; + } + + #endregion + + #region Dispose + + public void Dispose() + { + if (this._portcall != null) + { + this._portcall.Close(0); + _log.Debug("Close Worksheet"); + Marshal.ReleaseComObject(this._portcall); + } + + if (this._excelWorkbooks != null) + { + this._excelWorkbooks.Close(); + _log.Debug("Close Workbooks"); + Marshal.ReleaseComObject(this._excelWorkbooks); + // this._excelWorkbooks.Close(); + } + if (this._excelApp != null) + { + _log.Debug("Quit Excel"); + this._excelApp.Quit(); + Marshal.ReleaseComObject(this._excelApp); + } + } + + #endregion + + + } +} diff --git a/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs b/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs index 5bfe70c2..9301d8e2 100644 --- a/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs +++ b/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs @@ -178,6 +178,22 @@ namespace bsmd.ExcelReadService } } + #region Phase II - Excel Sheets auf Anforderung erzeugen + + List excelMessageCoreList = DBManager.Instance.GetMessageCoresForExcelCreate(); + if(excelMessageCoreList.Count > 0) + _log.InfoFormat("{0} excel sheets to create from database", excelMessageCoreList.Count); + foreach(MessageCore excelCore in excelMessageCoreList) + { + // load messages + List messages = DBManager.Instance.GetMessagesForCore(excelCore, DBManager.MessageLoad.ALL); + + // template + + } + + #endregion + DBManager.Instance.Disconnect(); } catch (Exception ex) diff --git a/nsw/Source/bsmd.ExcelReadService/ExcelReader.cs b/nsw/Source/bsmd.ExcelReadService/ExcelReader.cs index 35d07040..e23fccfd 100644 --- a/nsw/Source/bsmd.ExcelReadService/ExcelReader.cs +++ b/nsw/Source/bsmd.ExcelReadService/ExcelReader.cs @@ -12,7 +12,6 @@ using Microsoft.Office.Interop.Excel; using System; using System.Collections.Generic; using System.Data; -using System.IO; using System.Globalization; using System.Linq; @@ -21,22 +20,15 @@ using bsmd.database; namespace bsmd.ExcelReadService { - public class ExcelReader : IDisposable - { - private ILog _log = LogManager.GetLogger(typeof(ExcelReader)); - private Workbooks _excelWorkbooks; - private Workbook _portcall; - private Application _excelApp; - private Dictionary _nameDict; + internal class ExcelReader : ExcelBase + { - internal enum ReadState { NONE, OK, WARN, FAIL }; - internal enum CountryMode { NONE, DE, DK }; - - private CountryMode _countryMode = CountryMode.NONE; - + internal enum ReadState { NONE, OK, WARN, FAIL }; public ExcelReader(string filePath) { + _log = LogManager.GetLogger(typeof(ExcelReader)); + this._excelApp = new Application(); this._excelApp.DisplayAlerts = false; this._excelWorkbooks = _excelApp.Workbooks; @@ -50,9 +42,7 @@ namespace bsmd.ExcelReadService } - internal Confirmation Conf { get; set; } - - internal CountryMode Mode { get { return _countryMode; } } + internal Confirmation Conf { get; set; } internal void SetConfirmation(System.Collections.Specialized.StringCollection templatePaths) { @@ -60,40 +50,7 @@ namespace bsmd.ExcelReadService if (templatePaths == Properties.Settings.Default.ConfirmationDK) _countryMode = CountryMode.DK; this.Conf = new Confirmation(templatePaths, _excelApp); - } - - internal bool Save(string filePath) - { - bool result = true; - if (this._excelApp == null) return false; - try - { - this._excelApp.SaveWorkspace(filePath); - } - catch(Exception ex) - { - _log.WarnFormat("cannot save workspace: {0}", ex.Message); - result = false; - } - return result; - } - - internal bool SaveCopy(string filePath) - { - bool result = true; - if (this._excelApp == null) return false; - try - { - this._portcall.Saved = true; - this._portcall.SaveCopyAs(filePath); - } - catch (Exception ex) - { - _log.WarnFormat("cannot save copy of workbook: {0}", ex.Message); - result = false; - } - return result; - } + } internal List SaveConfirmationSheets(string attachmentLocalPath) { @@ -353,31 +310,7 @@ namespace bsmd.ExcelReadService this.Conf.ConfirmText(lookup, val, ReadState.FAIL); } return result; - } - - public void Dispose() - { - if(this._portcall != null) - { - this._portcall.Close(0); - _log.Debug("Close Worksheet"); - Marshal.ReleaseComObject(this._portcall); - } - - if (this._excelWorkbooks != null) - { - this._excelWorkbooks.Close(); - _log.Debug("Close Workbooks"); - Marshal.ReleaseComObject(this._excelWorkbooks); - // this._excelWorkbooks.Close(); - } - if (this._excelApp != null) - { - _log.Debug("Quit Excel"); - this._excelApp.Quit(); - Marshal.ReleaseComObject(this._excelApp); - } - } + } internal DateTime? ReadBirthDate(string lookup) { diff --git a/nsw/Source/bsmd.ExcelReadService/ExcelWriter.cs b/nsw/Source/bsmd.ExcelReadService/ExcelWriter.cs new file mode 100644 index 00000000..51044947 --- /dev/null +++ b/nsw/Source/bsmd.ExcelReadService/ExcelWriter.cs @@ -0,0 +1,37 @@ +// Copyright (c) 2017 Informatikbüro Daniel Schick +// + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bsmd.ExcelReadService +{ + + /// + /// Diese Klasse generiert aus einer Anmeldung ein Excel-Sheet, die Vorlage ist dabei landesabhängig (PoC) + /// Das ist notwendig bei Anmeldungen die nicht als Excel kommen (EU-NOAD) und aber in ein Excel-Upload Portal + /// gespeist werden müssen (z.B. Dänemark) + /// + internal class ExcelWriter : ExcelBase + { + + public ExcelWriter(CountryMode countryMode) + { + switch(countryMode) + { + case CountryMode.DK: + + break; + case CountryMode.DE: + default: + + break; + } + } + + } +} diff --git a/nsw/Source/bsmd.ExcelReadService/Util.cs b/nsw/Source/bsmd.ExcelReadService/Util.cs index 6dd32e2e..dd393ba9 100644 --- a/nsw/Source/bsmd.ExcelReadService/Util.cs +++ b/nsw/Source/bsmd.ExcelReadService/Util.cs @@ -20,7 +20,7 @@ namespace bsmd.ExcelReadService { private static ILog _log = LogManager.GetLogger(typeof(Util)); - public static bool ProcessSheet(ExcelReader reader, out string readMessage, out MessageCore messageCore) + internal static bool ProcessSheet(ExcelReader reader, out string readMessage, out MessageCore messageCore) { readMessage = "ok"; diff --git a/nsw/Source/bsmd.ExcelReadService/bsmd.ExcelReadService.csproj b/nsw/Source/bsmd.ExcelReadService/bsmd.ExcelReadService.csproj index db906d2b..eb076f52 100644 --- a/nsw/Source/bsmd.ExcelReadService/bsmd.ExcelReadService.csproj +++ b/nsw/Source/bsmd.ExcelReadService/bsmd.ExcelReadService.csproj @@ -72,6 +72,7 @@ Properties\AssemblyProjectKeyInfo.cs + Component @@ -79,6 +80,7 @@ ExcelReadService.cs + diff --git a/nsw/Source/bsmd.database/DBManager.cs b/nsw/Source/bsmd.database/DBManager.cs index f67d1c4d..3a42b829 100644 --- a/nsw/Source/bsmd.database/DBManager.cs +++ b/nsw/Source/bsmd.database/DBManager.cs @@ -89,17 +89,22 @@ namespace bsmd.database #region public helper funcs - /* - public Dictionary GetToSendMessageCoreList() - { - List toSendList = this.GetMessageCoresByStatus(MessageCore.BSMDStatus.TOSEND); - Dictionary result = new Dictionary(); - foreach (MessageCore core in toSendList) - result.Add(core.Id.Value, core); - return result; - } + public List GetMessageCoresForExcelCreate() + { + MessageCore aMessageCore = new MessageCore(); + SqlCommand cmd = new SqlCommand(); + aMessageCore.PrepareLoadCommand(cmd, Message.LoadFilter.CREATE_EXCEL); - */ + SqlDataReader reader = this.PerformCommand(cmd); + List cores = aMessageCore.LoadList(reader); + List result = new List(); + foreach (MessageCore core in cores) + { + this.LoadCustomer(core); + result.Add(core); + } + return result; + } public List GetMessageCoresByStatus(MessageCore.BSMDStatus status) { diff --git a/nsw/Source/bsmd.database/Message.cs b/nsw/Source/bsmd.database/Message.cs index cbce0cf1..2a5f693f 100644 --- a/nsw/Source/bsmd.database/Message.cs +++ b/nsw/Source/bsmd.database/Message.cs @@ -133,7 +133,8 @@ namespace bsmd.database BY_TRANSITID, BY_CORE_ENI, BY_CORE_EXCEL, - BY_CORE_HE + BY_CORE_HE, + CREATE_EXCEL } /// diff --git a/nsw/Source/bsmd.database/MessageCore.cs b/nsw/Source/bsmd.database/MessageCore.cs index 6c7e6c3b..d3ecc565 100644 --- a/nsw/Source/bsmd.database/MessageCore.cs +++ b/nsw/Source/bsmd.database/MessageCore.cs @@ -117,6 +117,16 @@ namespace bsmd.database public DateTime? Created { get { return this.created; } } + public bool IsDK + { + get { return this.PoC?.StartsWith("DK") ?? false; } + } + + /// + /// Flag zeigt an ob ein Excelsheet erzeugt werden soll + /// + public bool CreateExcel { get; set; } + #endregion #region DatabaseEntity implementation @@ -161,6 +171,7 @@ namespace bsmd.database scmd.Parameters.AddWithNullableValue("@P23", this.SietasSheetVersion); scmd.Parameters.AddWithValue("@P24", this.Incoming ? 1 : 0); scmd.Parameters.AddWithNullableValue("@P25", this.DefaultReportingPartyId); + scmd.Parameters.AddWithValue("@P26", this.CreateExcel ? 1 : 0); if (this.IsNew) { @@ -169,9 +180,9 @@ namespace bsmd.database string query = string.Format("INSERT INTO {0} (Id, VisitId, TransitId, IMO, ENI, PoC, Portname, ETA, CustomerId, " + "Previous, Next, IsTransit, Wetris_zz_56_datensatz_id, BSMDStatus, InitialHIS, HerbergFormGuid, " + "HerbergFormTemplateGuid, HerbergReportType, HerbergEmailcontactReportingVessel, HerbergEmail24HrsContact, " + - "ETAKielCanal, HerbergRevDate, ReportStatus, SietasSheetVersion, Incoming, DefaultReportingPartyId) VALUES " + + "ETAKielCanal, HerbergRevDate, ReportStatus, SietasSheetVersion, Incoming, DefaultReportingPartyId, CreateExcel) VALUES " + "(@ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, @P12, @P13, @P14, @P15, @P16, @P17, " + - "@P18, @P19, @P20, @P21, @P22, @P23, @P24, @P25)", + "@P18, @P19, @P20, @P21, @P22, @P23, @P24, @P25, @P26)", this.Tablename); scmd.CommandText = query; } @@ -183,7 +194,7 @@ namespace bsmd.database "Wetris_zz_56_datensatz_id = @P12, BSMDStatus = @P13, InitialHIS = @P14, HerbergFormGuid = @P15, " + "HerbergFormTemplateGuid = @P16, HerbergReportType = @P17, HerbergEmailContactReportingVessel = @P18, " + "HerbergEmail24HrsContact = @P19, ETAKielCanal = @P20, HerbergRevDate = @P21, ReportStatus = @P22, " + - "SietasSheetVersion = @P23, Incoming = @P24, DefaultReportingPartyId = @P25 WHERE Id = @ID", this.Tablename); + "SietasSheetVersion = @P23, Incoming = @P24, DefaultReportingPartyId = @P25, CreateExcel = @P26 WHERE Id = @ID", this.Tablename); scmd.CommandText = query; } } @@ -194,7 +205,7 @@ namespace bsmd.database "ETA, CustomerId, Previous, Next, IsTransit, Wetris_zz_56_datensatz_id, BSMDStatus, InitialHIS, " + "HerbergFormGuid, HerbergFormTemplateGuid, HerbergReportType, HerbergEmailContactReportingVessel, " + "HerbergEmail24HrsContact, ETAKielCanal, HerbergRevDate, ReportStatus, SietasSheetVersion, Incoming, " + - "DefaultReportingPartyId, Created, Changed FROM {0} ", + "DefaultReportingPartyId, Created, Changed, CreateExcel FROM {0} ", this.Tablename); switch (filter) @@ -249,6 +260,11 @@ namespace bsmd.database ((SqlCommand)cmd).Parameters.AddWithValue("@TRANSITID", criteria[0]); break; } + case Message.LoadFilter.CREATE_EXCEL: + { + query += "WHERE CreateExcel = 1"; + break; + } case Message.LoadFilter.ALL: default: break; @@ -291,6 +307,7 @@ namespace bsmd.database if (!reader.IsDBNull(25)) core.DefaultReportingPartyId = reader.GetGuid(25); if (!reader.IsDBNull(26)) core.created = reader.GetDateTime(26); if (!reader.IsDBNull(27)) core.changed = reader.GetDateTime(27); + if (!reader.IsDBNull(28)) core.CreateExcel = reader.GetBoolean(28); result.Add(core); } diff --git a/nsw/Source/bsmd.herberg.FormService/Util.cs b/nsw/Source/bsmd.herberg.FormService/Util.cs index 0c3c47a9..ef190dcb 100644 --- a/nsw/Source/bsmd.herberg.FormService/Util.cs +++ b/nsw/Source/bsmd.herberg.FormService/Util.cs @@ -811,9 +811,10 @@ namespace bsmd.herberg.FormService Dictionary pDict = nDict[key]; keysInMessage.Add(key.ToString(), key.ToString()); CREW crew = theMessage.GetSublistElementWithIdentifier(key.ToString()) as CREW; - if (crew == null) - { + if (crew == null || (!crew.IsDeparture && isDeparture && aMessageCore.IsDK)) // für DK wird bei Abfahrt ein neuer Datensatz (=CREWD) angelegt + { crew = new CREW(); + crew.IsDeparture = isDeparture; crew.MessageHeader = theMessage; crew.Identifier = key.ToString(); theMessage.MessageNotificationClass = Message.NotificationClass.CREW; @@ -1072,9 +1073,10 @@ namespace bsmd.herberg.FormService Dictionary pDict = nDict[key]; keysInMessage.Add(key.ToString(), key.ToString()); PAS pas = theMessage.GetSublistElementWithIdentifier(key.ToString()) as PAS; - if (pas == null) + if ((pas == null) || (!pas.IsDeparture && isDeparture && aMessageCore.IsDK)) { pas = new PAS(); + pas.IsDeparture = isDeparture; pas.MessageHeader = theMessage; pas.Identifier = key.ToString(); theMessage.MessageNotificationClass = Message.NotificationClass.PAS;