Aktueller Stand FormReader wird eingefroren, da der Service nicht fortgesetzt wird.
This commit is contained in:
parent
c3dd32ed53
commit
de8b7de10d
Binary file not shown.
@ -15,4 +15,15 @@ ALTER TABLE [dbo].[SEC] ADD [AreMatterToReport] bit NULL;
|
||||
|
||||
GO
|
||||
|
||||
-- bis hierhin schon aktualisiert
|
||||
PRINT N'Altering [dbo].[MessageCore]...';
|
||||
|
||||
|
||||
GO
|
||||
ALTER TABLE [dbo].[MessageCore]
|
||||
ADD [CreateExcel] BIT NULL;
|
||||
|
||||
|
||||
GO
|
||||
|
||||
-- bis hierhin schon aktualisiert
|
||||
|
||||
|
||||
@ -74,8 +74,7 @@ namespace bsmd.ExcelReadService
|
||||
nameDict[workbookName.Name].Add(workbookName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
workbooks.Add(aWorkbook);
|
||||
|
||||
103
nsw/Source/bsmd.ExcelReadService/ExcelBase.cs
Normal file
103
nsw/Source/bsmd.ExcelReadService/ExcelBase.cs
Normal file
@ -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<string, Name> _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
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -178,6 +178,22 @@ namespace bsmd.ExcelReadService
|
||||
}
|
||||
}
|
||||
|
||||
#region Phase II - Excel Sheets auf Anforderung erzeugen
|
||||
|
||||
List<MessageCore> 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<Message> messages = DBManager.Instance.GetMessagesForCore(excelCore, DBManager.MessageLoad.ALL);
|
||||
|
||||
// template
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
DBManager.Instance.Disconnect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@ -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<string, Name> _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<string> 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)
|
||||
{
|
||||
|
||||
37
nsw/Source/bsmd.ExcelReadService/ExcelWriter.cs
Normal file
37
nsw/Source/bsmd.ExcelReadService/ExcelWriter.cs
Normal file
@ -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
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
internal class ExcelWriter : ExcelBase
|
||||
{
|
||||
|
||||
public ExcelWriter(CountryMode countryMode)
|
||||
{
|
||||
switch(countryMode)
|
||||
{
|
||||
case CountryMode.DK:
|
||||
|
||||
break;
|
||||
case CountryMode.DE:
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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";
|
||||
|
||||
|
||||
@ -72,6 +72,7 @@
|
||||
<Link>Properties\AssemblyProjectKeyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Confirmation.cs" />
|
||||
<Compile Include="ExcelBase.cs" />
|
||||
<Compile Include="ExcelReader.cs" />
|
||||
<Compile Include="ExcelReadService.cs">
|
||||
<SubType>Component</SubType>
|
||||
@ -79,6 +80,7 @@
|
||||
<Compile Include="ExcelReadService.Designer.cs">
|
||||
<DependentUpon>ExcelReadService.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ExcelWriter.cs" />
|
||||
<Compile Include="LocodeDB.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="ProjectInstaller.cs">
|
||||
|
||||
@ -89,17 +89,22 @@ namespace bsmd.database
|
||||
|
||||
#region public helper funcs
|
||||
|
||||
/*
|
||||
public Dictionary<Guid, MessageCore> GetToSendMessageCoreList()
|
||||
{
|
||||
List<MessageCore> toSendList = this.GetMessageCoresByStatus(MessageCore.BSMDStatus.TOSEND);
|
||||
Dictionary<Guid, MessageCore> result = new Dictionary<Guid, MessageCore>();
|
||||
foreach (MessageCore core in toSendList)
|
||||
result.Add(core.Id.Value, core);
|
||||
return result;
|
||||
}
|
||||
public List<MessageCore> GetMessageCoresForExcelCreate()
|
||||
{
|
||||
MessageCore aMessageCore = new MessageCore();
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
aMessageCore.PrepareLoadCommand(cmd, Message.LoadFilter.CREATE_EXCEL);
|
||||
|
||||
*/
|
||||
SqlDataReader reader = this.PerformCommand(cmd);
|
||||
List<DatabaseEntity> cores = aMessageCore.LoadList(reader);
|
||||
List<MessageCore> result = new List<MessageCore>();
|
||||
foreach (MessageCore core in cores)
|
||||
{
|
||||
this.LoadCustomer(core);
|
||||
result.Add(core);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<MessageCore> GetMessageCoresByStatus(MessageCore.BSMDStatus status)
|
||||
{
|
||||
|
||||
@ -133,7 +133,8 @@ namespace bsmd.database
|
||||
BY_TRANSITID,
|
||||
BY_CORE_ENI,
|
||||
BY_CORE_EXCEL,
|
||||
BY_CORE_HE
|
||||
BY_CORE_HE,
|
||||
CREATE_EXCEL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -117,6 +117,16 @@ namespace bsmd.database
|
||||
|
||||
public DateTime? Created { get { return this.created; } }
|
||||
|
||||
public bool IsDK
|
||||
{
|
||||
get { return this.PoC?.StartsWith("DK") ?? false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flag zeigt an ob ein Excelsheet erzeugt werden soll
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
@ -811,9 +811,10 @@ namespace bsmd.herberg.FormService
|
||||
Dictionary<string, string> 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<string, string> 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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user