858 lines
39 KiB
C#
858 lines
39 KiB
C#
// Copyright (c) 2015-2017 schick Informatik
|
|
// Description: Kopfdaten Schiffsanmeldungen
|
|
|
|
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using log4net;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class MessageCore : DatabaseEntity, IComparable, IEquatable<MessageCore>
|
|
{
|
|
|
|
#region (backing) Fields
|
|
|
|
private Guid? previous;
|
|
private Guid? next;
|
|
private DateTime? created;
|
|
private DateTime? changed;
|
|
private int? wetris_zz_56_datensatz_id;
|
|
private static readonly ILog _log = LogManager.GetLogger("MessageCore");
|
|
|
|
private string _visitId;
|
|
private string _transitId;
|
|
private Message.NSWProvider _initialHIS;
|
|
|
|
#endregion
|
|
|
|
#region selection delegate definition
|
|
|
|
public delegate void MessageCoreSelectedHandler(MessageCore aMessageCore);
|
|
|
|
#endregion
|
|
|
|
#region Construction
|
|
|
|
public MessageCore()
|
|
{
|
|
this.tablename = "MessageCore";
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Enum
|
|
|
|
/// <summary>
|
|
/// "globaler" Status des Schiffsanlaufs
|
|
/// </summary>
|
|
public enum BSMDStatus
|
|
{
|
|
UNDEFINED = 0,
|
|
PREPARE,
|
|
TOSEND,
|
|
SENT,
|
|
RESPONDED,
|
|
FAILURE,
|
|
REPORTREQUESTED,
|
|
ARCHIVED,
|
|
HIS_FAILURE_DBH,
|
|
INVALID
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dieses Enum dient zur Steuerung des ReportGenerator Service
|
|
/// </summary>
|
|
public enum ReportStatusEnum
|
|
{
|
|
NONE = 0, // keine Aktion
|
|
COMPLETE, // Report mit vollst. Ausgabe aller Felder
|
|
HE_REVISION, // eine neue EU-NOAD Rev. wurde empfangen (TBD)
|
|
HE_REPORTTYPE, // ein neuer EU-NOAD ReportType wurde empfangen (TBD)
|
|
RECEIPT, // einfache Empfangsbestätigung (TBD)
|
|
SINGLE // Report nur für einzelne Meldeklasse erstellen
|
|
}
|
|
|
|
|
|
public enum SearchFilterType
|
|
{
|
|
FILTER_ID,
|
|
FILTER_PORT,
|
|
FILTER_IMO,
|
|
FILTER_SHIPNAME,
|
|
FILTER_ETA,
|
|
FILTER_TICKETNO,
|
|
FILTER_LATESTIDS,
|
|
FILTER_CREATEDBY,
|
|
FILTER_FLAG_EQ,
|
|
FILTER_FLAG_NEQ
|
|
}
|
|
|
|
[Flags]
|
|
public enum CoreFlags
|
|
{
|
|
NONE = 0,
|
|
MAERSK_BHV = 1,
|
|
SEAGO_BHV = 2,
|
|
SEAGO_WHV = 4,
|
|
HOEGH = 8
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
[MaxLength(25)]
|
|
[ENI2Validation]
|
|
public string VisitId
|
|
{
|
|
get { return this._visitId; }
|
|
set {
|
|
if(value.IsNullOrEmpty() && !this._visitId.IsNullOrEmpty())
|
|
{
|
|
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
|
|
_log.WarnFormat("Someones resetting the VISIT Id at {0}", st.ToString());
|
|
}
|
|
else
|
|
{
|
|
this._visitId = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
[MaxLength(25)]
|
|
[ENI2Validation]
|
|
public string TransitId
|
|
{
|
|
get { return this._transitId; }
|
|
set
|
|
{
|
|
if (value.IsNullOrEmpty() && !this._transitId.IsNullOrEmpty())
|
|
{
|
|
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
|
|
_log.WarnFormat("Someones resetting the TRANSIT Id at {0}", st.ToString());
|
|
}
|
|
else
|
|
{
|
|
this._transitId = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Display Property für ENI-2
|
|
/// </summary>
|
|
public string DisplayId
|
|
{
|
|
get
|
|
{
|
|
if (!VisitId.IsNullOrEmpty()) return VisitId;
|
|
if (!TransitId.IsNullOrEmpty()) return TransitId;
|
|
return "";
|
|
}
|
|
}
|
|
|
|
[MaxLength(7)]
|
|
[ENI2Validation]
|
|
public string IMO { get; set; }
|
|
|
|
[MaxLength(8)]
|
|
[ENI2Validation]
|
|
public string ENI { get; set; }
|
|
|
|
/// <summary>
|
|
/// ENI-2 helper field
|
|
/// </summary>
|
|
public string IMOENIDisplay
|
|
{
|
|
get
|
|
{
|
|
if (this.IMO.IsNullOrEmpty())
|
|
return this.ENI;
|
|
else
|
|
return this.IMO;
|
|
}
|
|
}
|
|
|
|
[MaxLength(5)]
|
|
[ENI2Validation]
|
|
public string PoC { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string Portname { get; set; }
|
|
|
|
[ENI2Validation]
|
|
public DateTime? ETA { get; set; }
|
|
|
|
[ENI2Validation]
|
|
public DateTime? ETAKielCanal { get; set; }
|
|
|
|
public DateTime? ETADisplay
|
|
{
|
|
get { return this.IsTransit ? this.ETAKielCanal : this.ETA; }
|
|
}
|
|
|
|
public string PortnameDisplay
|
|
{
|
|
get { return this.IsTransit ? "NOK" : this.Portname; }
|
|
}
|
|
|
|
[ENI2Validation]
|
|
public bool IsTransit { get; set; }
|
|
|
|
[ENI2Validation]
|
|
public bool Incoming { get; set; } // tbd: für HIS-NORD, mal sehen ob das so bleibt
|
|
|
|
[ENI2Validation]
|
|
public BSMDStatus BSMDStatusInternal { get; set; }
|
|
|
|
[ENI2Validation]
|
|
public Message.NSWProvider InitialHIS
|
|
{
|
|
get
|
|
{
|
|
return _initialHIS;
|
|
}
|
|
set
|
|
{
|
|
_initialHIS = value;
|
|
}
|
|
}
|
|
|
|
public Guid? HerbergFormGuid { get; set; }
|
|
|
|
public Guid? HerbergFormTemplateGuid { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
public string HerbergReportType { get; set; }
|
|
|
|
[MaxLength(255)]
|
|
public string HerbergEmailContactReportingVessel { get; set; }
|
|
|
|
[MaxLength(255)]
|
|
public string HerbergEmail24HrsContact { get; set; }
|
|
|
|
public DateTime? HerbergRevDate { get; set; }
|
|
|
|
public Customer Customer { get; set; }
|
|
|
|
public Guid? CustomerId { get; set; }
|
|
|
|
public ReportStatusEnum ReportStatus { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
public string SietasSheetVersion { get; set; }
|
|
|
|
public Guid? DefaultReportingPartyId { get; set; }
|
|
|
|
public DateTime? Changed { get { return this.changed; } }
|
|
|
|
public DateTime? Created { get { return this.created; } }
|
|
|
|
public bool IsDK
|
|
{
|
|
get { return this.PoC?.StartsWith("DK") ?? false; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// ENI-2
|
|
/// </summary>
|
|
public string EditedBy { get; set; }
|
|
|
|
/// <summary>
|
|
/// ENI-2 display prop
|
|
/// </summary>
|
|
public string Shipname { get; set; }
|
|
|
|
/// <summary>
|
|
/// ENI-2 display prop
|
|
/// </summary>
|
|
public DateTime? ETA_NOA_NOD { get; set; }
|
|
|
|
/// <summary>
|
|
/// ENI-2 display prop
|
|
/// </summary>
|
|
public DateTime? ETD_NOA_NOD { get; set; }
|
|
|
|
/// <summary>
|
|
/// ENI-2 display prop
|
|
/// </summary>
|
|
public DateTime? ATA { get; set; }
|
|
|
|
/// <summary>
|
|
/// ENI-2 display prop
|
|
/// </summary>
|
|
public DateTime? ATD { get; set; }
|
|
|
|
/// <summary>
|
|
/// Helper display prop to highlight cores with unsent ATA/ATD
|
|
/// </summary>
|
|
public bool? UnsentATAATD { get; set; }
|
|
|
|
/// <summary>
|
|
/// Validation flag (set from STAT, GrossTonnage < 500)
|
|
/// </summary>
|
|
public bool IsSmallShip { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Flag zeigt an ob ein Excelsheet erzeugt werden soll
|
|
/// </summary>
|
|
public bool CreateExcel { get; set; }
|
|
|
|
/// <summary>
|
|
/// Feld um die OTRS Ticketnummer zu speichern
|
|
/// </summary>
|
|
[MaxLength(50)]
|
|
public string TicketNo { get; set; }
|
|
|
|
/// <summary>
|
|
/// Property um in ENI-2 den "gelockten" Zustand zu speichern (wird nicht persistiert), "threeway":
|
|
/// null: nicht in Verwendung, true: vom Anwender gelockt, false: von jmd. anderem gelocked
|
|
/// </summary>
|
|
public bool? Locked { get; set; }
|
|
|
|
/// <summary>
|
|
/// Flag wird vom ExcelImportTool beim ersten Einlesen gesetzt. Weitere Einlesevorgänge werden nur in der
|
|
/// Update Tabelle gespeichert, um Änderungen durch den Mitarbeiter im ENI-2 nicht zu überschreiben
|
|
/// </summary>
|
|
public bool? ExcelImportComplete { get; set; }
|
|
|
|
/// <summary>
|
|
/// Diese Nummer wird bei Schiffen von Maersk/SeaGo für die Identifikation bei der Fakturierung benutzt. Das Feld ist funktional
|
|
/// für den NSW Betrieb so nicht erforderlich. (nur Ausgabe / POService)
|
|
/// </summary>
|
|
public string PONumber { get; set; }
|
|
|
|
/// <summary>
|
|
/// Dieses Datumsfeld wird verwendet wenn ein ATA (das nicht über das ENI eingegeben wurde) im PO Nummer Dialog eingegeben werden
|
|
/// soll, damit es anschließend im exportierten Sheet und auf der Rechnung auftaucht
|
|
/// </summary>
|
|
public DateTime? POATA { get; set; }
|
|
|
|
/// <summary>
|
|
/// generic multipurpose flag field
|
|
/// </summary>
|
|
public int Flags { get; set; }
|
|
|
|
#region Flag properties not backed by field
|
|
|
|
/// <summary>
|
|
/// ENI helper to mark this Core in Overview (tabheader)
|
|
/// </summary>
|
|
public bool IsHighlighted { get; set; }
|
|
|
|
public int NumberSent { get; set; }
|
|
|
|
/// <summary>
|
|
/// ENI helper, # of notif. classes already sent vs total number (e.g. 18/27)
|
|
/// </summary>
|
|
public string NumberSentDisplay { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Felder um NSW Statusinformationen zu speichern (abgefragte Daten!)
|
|
|
|
public bool? Cancelled { get; set; }
|
|
|
|
public bool? VisitIdOrTransitIdCancellable { get; set; }
|
|
|
|
/// <summary>
|
|
/// als string serialisierte Enumeration - Liste
|
|
/// </summary>
|
|
public string BlockedNotificationClasses { get; set; }
|
|
|
|
public string OwnNotificationClasses { get; set; }
|
|
|
|
public string FreeNotificationClasses { get; set; }
|
|
|
|
public string StatusCheckErrorCode { get; set; }
|
|
|
|
public string StatusCheckErrorMessage { get; set; }
|
|
|
|
public bool? QueryNSWStatus { get; set; }
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override void PrepareSave(IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithNullableValue("@P1", this.VisitId);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.TransitId);
|
|
if (this.IMO != null) scmd.Parameters.AddWithValue("@P3", this.IMO);
|
|
else scmd.Parameters.AddWithValue("@P3", DBNull.Value);
|
|
if (this.ENI != null) scmd.Parameters.AddWithValue("@P4", this.ENI);
|
|
else scmd.Parameters.AddWithValue("@P4", DBNull.Value);
|
|
if (this.PoC != null) scmd.Parameters.AddWithValue("@P5", this.PoC);
|
|
else scmd.Parameters.AddWithValue("@P5", DBNull.Value);
|
|
if (this.Portname != null) scmd.Parameters.AddWithValue("@P6", this.Portname);
|
|
else scmd.Parameters.AddWithValue("@P6", DBNull.Value);
|
|
if (this.ETA.HasValue) scmd.Parameters.AddWithValue("@P7", this.ETA);
|
|
else scmd.Parameters.AddWithValue("@P7", DBNull.Value);
|
|
if (this.CustomerId.HasValue) scmd.Parameters.AddWithValue("@P8", this.CustomerId);
|
|
else scmd.Parameters.AddWithValue("@P8", DBNull.Value);
|
|
if (this.previous.HasValue) scmd.Parameters.AddWithValue("@P9", this.previous);
|
|
else scmd.Parameters.AddWithValue("@P9", DBNull.Value);
|
|
if (this.next.HasValue) scmd.Parameters.AddWithValue("@P10", this.next);
|
|
else scmd.Parameters.AddWithValue("@P10", DBNull.Value);
|
|
scmd.Parameters.AddWithValue("@P11", this.IsTransit ? 1 : 0);
|
|
if (this.wetris_zz_56_datensatz_id.HasValue) scmd.Parameters.AddWithValue("@P12", this.wetris_zz_56_datensatz_id);
|
|
else scmd.Parameters.AddWithValue("@P12", DBNull.Value);
|
|
scmd.Parameters.AddWithValue("@P13", this.BSMDStatusInternal);
|
|
scmd.Parameters.AddWithValue("@P14", this.InitialHIS);
|
|
scmd.Parameters.AddWithNullableValue("@P15", this.HerbergFormGuid);
|
|
scmd.Parameters.AddWithNullableValue("@P16", this.HerbergFormTemplateGuid);
|
|
scmd.Parameters.AddWithNullableValue("@P17", this.HerbergReportType);
|
|
scmd.Parameters.AddWithNullableValue("@P18", this.HerbergEmailContactReportingVessel);
|
|
scmd.Parameters.AddWithNullableValue("@P19", this.HerbergEmail24HrsContact);
|
|
scmd.Parameters.AddWithNullableValue("@P20", this.ETAKielCanal);
|
|
scmd.Parameters.AddWithNullableValue("@P21", this.HerbergRevDate);
|
|
scmd.Parameters.AddWithValue("@P22", this.ReportStatus);
|
|
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);
|
|
scmd.Parameters.AddWithNullableValue("@P27", this.EditedBy);
|
|
scmd.Parameters.AddWithNullableValue("@P28", this.TicketNo);
|
|
scmd.Parameters.AddWithNullableValue("@P29", this.Cancelled);
|
|
scmd.Parameters.AddWithNullableValue("@P30", this.VisitIdOrTransitIdCancellable);
|
|
scmd.Parameters.AddWithNullableValue("@P31", this.BlockedNotificationClasses);
|
|
scmd.Parameters.AddWithNullableValue("@P32", this.FreeNotificationClasses);
|
|
scmd.Parameters.AddWithNullableValue("@P33", this.OwnNotificationClasses);
|
|
scmd.Parameters.AddWithNullableValue("@P34", this.StatusCheckErrorCode);
|
|
scmd.Parameters.AddWithNullableValue("@P35", this.StatusCheckErrorMessage);
|
|
scmd.Parameters.AddWithNullableValue("@P36", this.QueryNSWStatus);
|
|
scmd.Parameters.AddWithNullableValue("@P37", this.ExcelImportComplete);
|
|
scmd.Parameters.AddWithNullableValue("@P38", this.PONumber);
|
|
scmd.Parameters.AddWithValue("@P39", this.Flags);
|
|
scmd.Parameters.AddWithNullableValue("@P40", this.POATA);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
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, CreateExcel, " +
|
|
"EditedBy, TicketNo, Cancelled, VisitIdOrTransitIdCancellable, BlockedNotificationClasses, FreeNotificationClasses, " +
|
|
"OwnNotificationClasses, StatusCheckErrorCode, StatusCheckErrorMessage, QueryNSWStatus, ExcelImportComplete, PONumber, Flags, POATA) 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, @P26, @P27, @P28, @P29, @P30, @P31, @P32, @P33, @P34, @P35, @P36, @P37, @P38, @P39, @P40)",
|
|
this.Tablename);
|
|
scmd.CommandText = query;
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
string query = string.Format("UPDATE {0} SET VisitId = @P1, TransitId = @P2, IMO = @P3, ENI = @P4, Poc = @P5, " +
|
|
"Portname = @P6, ETA = @P7, CustomerId = @P8, Previous = @P9, Next = @P10, IsTransit = @P11, " +
|
|
"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, CreateExcel = @P26, EditedBy = @P27, " +
|
|
"TicketNo = @P28, Cancelled = @P29, VisitIdOrTransitIdCancellable = @P30, BlockedNotificationClasses = @P31, " +
|
|
"FreeNotificationClasses = @P32, OwnNotificationClasses = @P33, StatusCheckErrorCode = @P34, StatusCheckErrorMessage = @P35, " +
|
|
"QueryNSWStatus = @P36, ExcelImportComplete = @P37, PONumber = @P38, Flags = @P39, POATA = @P40 WHERE Id = @ID", this.Tablename);
|
|
scmd.CommandText = query;
|
|
}
|
|
}
|
|
|
|
public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
StringBuilder sb = new StringBuilder("SELECT ");
|
|
if (this.ResultLimit > 0)
|
|
{
|
|
sb.AppendFormat("TOP {0} ", this.ResultLimit);
|
|
}
|
|
|
|
sb.AppendFormat("[{0}].[Id], [{0}].[VisitId], [{0}].[TransitId], [{0}].[IMO], [{0}].[ENI], [{0}].[PoC], [{0}].[Portname], " +
|
|
"[{0}].[ETA], [{0}].[CustomerId], [{0}].[Previous], [{0}].[Next], [{0}].[IsTransit], [{0}].[Wetris_zz_56_datensatz_id], [{0}].[BSMDStatus], " +
|
|
"[{0}].[InitialHIS], [{0}].[HerbergFormGuid], [{0}].[HerbergFormTemplateGuid], [{0}].[HerbergReportType], [{0}].[HerbergEmailContactReportingVessel], " +
|
|
"[{0}].[HerbergEmail24HrsContact], [{0}].[ETAKielCanal], [{0}].[HerbergRevDate], [{0}].[ReportStatus], [{0}].[SietasSheetVersion], [{0}].[Incoming], " +
|
|
"[{0}].[DefaultReportingPartyId], [{0}].[Created], [{0}].[Changed], [{0}].[CreateExcel], [{0}].[EditedBy], [{0}].[TicketNo], " +
|
|
"[{0}].[Cancelled], [{0}].[VisitIdOrTransitIdCancellable], [{0}].[BlockedNotificationClasses], [{0}].[FreeNotificationClasses], " +
|
|
"[{0}].[OwnNotificationClasses], [{0}].[StatusCheckErrorCode], [{0}].[StatusCheckErrorMessage], [{0}].[QueryNSWStatus], " +
|
|
"[{0}].[ExcelImportComplete], [{0}].[PONumber], [{0}].Flags, [{0}].POATA",
|
|
this.Tablename);
|
|
|
|
if(filter == Message.LoadFilter.SEARCH_CORE_FILTERS)
|
|
{
|
|
if (criteria[0] is Dictionary<SearchFilterType, string> searchDict && (searchDict.Count > 0))
|
|
{
|
|
if (searchDict.ContainsKey(SearchFilterType.FILTER_ETA))
|
|
sb.Append(", NOA_NOD.ETAToPortOfCall, NOA_NOD.ETAToKielCanal");
|
|
}
|
|
}
|
|
|
|
sb.AppendFormat(" FROM {0} ", this.Tablename);
|
|
|
|
this.SetFilters(sb, cmd, filter, criteria);
|
|
bool latestIdSearch = false;
|
|
if(filter == Message.LoadFilter.SEARCH_CORE_FILTERS)
|
|
{
|
|
latestIdSearch = (criteria[0] is Dictionary<SearchFilterType, string> searchDict && searchDict.ContainsKey(SearchFilterType.FILTER_LATESTIDS));
|
|
}
|
|
|
|
if (latestIdSearch)
|
|
{
|
|
sb.AppendFormat(" ORDER BY [{0}].Changed DESC", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
sb.Append(" ORDER BY COALESCE(ETA, ETAKielCanal) DESC");
|
|
}
|
|
|
|
cmd.CommandText = sb.ToString();
|
|
}
|
|
|
|
public override void PrepareCountCmd(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
StringBuilder sb = new StringBuilder("SELECT COUNT(*) FROM ");
|
|
sb.Append(this.Tablename);
|
|
sb.Append(" ");
|
|
|
|
this.SetFilters(sb, cmd, filter, criteria);
|
|
|
|
cmd.CommandText = sb.ToString();
|
|
}
|
|
|
|
private void SetFilters(StringBuilder sb, IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.WETRIS_SHIP_ID:
|
|
{
|
|
sb.Append("WHERE Wetris_zz_56_datensatz_id = @WETRIS");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@WETRIS", criteria[0]);
|
|
break;
|
|
}
|
|
case Message.LoadFilter.HERBERG_FORMGUID:
|
|
{
|
|
sb.Append("WHERE HerbergFormGuid = @HFG");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@HFG", criteria[0]);
|
|
break;
|
|
}
|
|
case Message.LoadFilter.BSMDSTATUS:
|
|
{
|
|
sb.Append("WHERE BSMDStatus = @STATUS");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@STATUS", criteria[0]);
|
|
break;
|
|
}
|
|
case Message.LoadFilter.REPORTSTATUS:
|
|
{
|
|
sb.Append("WHERE ReportStatus = @REPORTSTATUS");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@REPORTSTATUS", criteria[0]);
|
|
break;
|
|
}
|
|
case Message.LoadFilter.BY_ID:
|
|
{
|
|
sb.Append("WHERE Id = @ID");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@ID", criteria[0]);
|
|
break;
|
|
}
|
|
case Message.LoadFilter.IMO_ETA_POC:
|
|
{
|
|
sb.Append("WHERE (IMO = @IMO AND ETA = @ETA AND PoC = @POC)");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@IMO", criteria[0]);
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@ETA", criteria[1]);
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@POC", criteria[2]);
|
|
break;
|
|
}
|
|
case Message.LoadFilter.BY_VISITID:
|
|
{
|
|
sb.Append("WHERE VisitId = @VISITID");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@VISITID", criteria[0]);
|
|
break;
|
|
}
|
|
case Message.LoadFilter.BY_TRANSITID:
|
|
{
|
|
sb.Append("WHERE TransitId = @TRANSITID");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@TRANSITID", criteria[0]);
|
|
break;
|
|
}
|
|
case Message.LoadFilter.CREATE_EXCEL:
|
|
{
|
|
sb.Append("WHERE CreateExcel = 1");
|
|
break;
|
|
}
|
|
case Message.LoadFilter.QUERY_NSW_STATUS:
|
|
{
|
|
sb.Append("WHERE QueryNSWStatus = 1");
|
|
break;
|
|
}
|
|
case Message.LoadFilter.BY_AGE:
|
|
{
|
|
sb.AppendFormat("WHERE Created < DATEADD(month, -{0}, GETDATE())", criteria[0]);
|
|
break;
|
|
}
|
|
case Message.LoadFilter.SEARCH_CORE_FILTERS:
|
|
{
|
|
// object ist jetzt ein dict aus filtertyp und filterparameter
|
|
bool moreThanOne = false;
|
|
|
|
if (criteria[0] is Dictionary<SearchFilterType, string> searchDict && (searchDict.Count > 0))
|
|
{
|
|
if (searchDict.ContainsKey(SearchFilterType.FILTER_SHIPNAME))
|
|
{
|
|
// perform STAT join
|
|
sb.Append(" JOIN MessageHeader mh ON MessageCore.Id = mh.MessageCoreId JOIN STAT ON mh.Id = STAT.MessageHeaderId");
|
|
}
|
|
|
|
if (searchDict.ContainsKey(SearchFilterType.FILTER_ETA))
|
|
{
|
|
// perform NOA_NOD join
|
|
sb.Append(" LEFT JOIN MessageHeader mh2 ON mh2.MessageCoreId = MessageCore.Id AND mh2.NotificationClass = 2 LEFT JOIN NOA_NOD ON NOA_NOD.MessageHeaderId = mh2.Id");
|
|
}
|
|
|
|
sb.Append(" WHERE ");
|
|
foreach (SearchFilterType key in searchDict.Keys)
|
|
{
|
|
if (moreThanOne) sb.Append(" AND ");
|
|
switch (key)
|
|
{
|
|
case SearchFilterType.FILTER_ETA:
|
|
uint? from = null, to = null;
|
|
string[] elems = searchDict[key].Split(':');
|
|
if (!elems[0].IsNullOrEmpty()) from = UInt32.Parse(elems[0]);
|
|
if (!elems[1].IsNullOrEmpty()) to = UInt32.Parse(elems[1]);
|
|
|
|
// SQL Logik für die Zeitfilterung: Wenn es bereits eine Tabelle NOA_NOD mit einem Eintrag für ETAToPortOfCall / ETAToKielCanal gibt
|
|
// soll dieser Wert als Vergleich herangezogen werden, sonst ETA / ETAKielCanal aus MessageCore
|
|
// Das *sollte* so funktionieren: CASE WHEN ETAToPortOfCall IS NULL THEN ETA ELSE ETAToPortOfCall END
|
|
|
|
if (from.HasValue && !to.HasValue)
|
|
{
|
|
sb.Append(" ((CASE WHEN ETAToPortOfCall IS NULL THEN ETA ELSE ETAToPortOfCall END > @SEARCHFROM) OR (CASE WHEN ETAToKielCanal IS NULL THEN ETAKielCanal ELSE ETAToKielCanal END > @SEARCHFROM)) ");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@SEARCHFROM", from.Value.FromUnixTimeStamp());
|
|
}
|
|
if (to.HasValue && !from.HasValue)
|
|
{
|
|
sb.Append(" ((CASE WHEN ETAToPortOfCall IS NULL THEN ETA ELSE ETAToPortOfCall END < @SEARCHTO) OR (CASE WHEN ETAToKielCanal IS NULL THEN ETAKielCanal ELSE ETAToKielCanal END < @SEARCHTO)) ");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@SEARCHTO", to.Value.FromUnixTimeStamp());
|
|
|
|
}
|
|
if (from.HasValue && to.HasValue)
|
|
{
|
|
sb.Append(" ((CASE WHEN ETAToPortOfCall IS NULL THEN ETA ELSE ETAToPortOfCall END > @SEARCHFROM AND CASE WHEN ETAToPortOfCall IS NULL THEN ETA ELSE ETAToPortOfCall END < @SEARCHTO) OR (CASE WHEN ETAToKielCanal IS NULL THEN ETAKielCanal ELSE ETAToKielCanal END > @SEARCHFROM AND CASE WHEN ETAToKielCanal IS NULL THEN ETAKielCanal ELSE ETAToKielCanal END < @SEARCHTO)) ");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@SEARCHFROM", from.Value.FromUnixTimeStamp());
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@SEARCHTO", to.Value.FromUnixTimeStamp());
|
|
}
|
|
|
|
break;
|
|
case SearchFilterType.FILTER_ID:
|
|
sb.Append(" (VisitId LIKE @SEARCH_ID OR TransitId LIKE @SEARCH_ID) ");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@SEARCH_ID", string.Format("%{0}%", searchDict[key]));
|
|
break;
|
|
case SearchFilterType.FILTER_IMO:
|
|
sb.Append(" (IMO = @SEARCH_IMO OR ENI = @SEARCH_IMO) ");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@SEARCH_IMO", searchDict[key]);
|
|
break;
|
|
case SearchFilterType.FILTER_PORT:
|
|
{
|
|
sb.Append("( ");
|
|
int paramCnt = 0;
|
|
foreach (string param in searchDict[key].SimpleSplit())
|
|
{
|
|
string paramName = string.Format("@SEARCH_PORT{0}", paramCnt);
|
|
if (paramCnt > 0) sb.Append(" OR ");
|
|
sb.AppendFormat(" Portname LIKE {0} OR PoC LIKE {0} ", paramName);
|
|
((SqlCommand)cmd).Parameters.AddWithValue(paramName, string.Format("%{0}%", param));
|
|
paramCnt++;
|
|
|
|
}
|
|
sb.Append(") ");
|
|
}
|
|
break;
|
|
case SearchFilterType.FILTER_SHIPNAME:
|
|
{
|
|
sb.Append(" [STAT].[ShipName] LIKE @SHIPNAME ");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@SHIPNAME", string.Format("%{0}%", searchDict[key]));
|
|
}
|
|
break;
|
|
case SearchFilterType.FILTER_TICKETNO:
|
|
{
|
|
sb.Append(" TicketNo like @TICKETNO ");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@TICKETNO", searchDict[key]);
|
|
break;
|
|
}
|
|
case SearchFilterType.FILTER_LATESTIDS:
|
|
{
|
|
sb.Append(" ((DATALENGTH(VisitId) > 0) OR (DATALENGTH(TransitId) > 0)) ");
|
|
break;
|
|
}
|
|
case SearchFilterType.FILTER_CREATEDBY:
|
|
{
|
|
sb.Append(" DefaultReportingPartyId = @DRPID ");
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@DRPID", searchDict[key]);
|
|
break;
|
|
}
|
|
case SearchFilterType.FILTER_FLAG_EQ:
|
|
{
|
|
sb.Append(" MessageCore.Flags = @FLAG ");
|
|
int flag = 0;
|
|
int.TryParse(searchDict[key], out flag);
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@FLAG", flag);
|
|
break;
|
|
}
|
|
case SearchFilterType.FILTER_FLAG_NEQ:
|
|
{
|
|
sb.Append(" MessageCore.Flags <> @FLAG ");
|
|
int flag = 0;
|
|
int.TryParse(searchDict[key], out flag);
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@FLAG", flag);
|
|
break;
|
|
}
|
|
}
|
|
if (!moreThanOne) moreThanOne = true;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case Message.LoadFilter.ALL:
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
while(reader.Read())
|
|
{
|
|
MessageCore core = new MessageCore();
|
|
core.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) core.VisitId = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) core.TransitId = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) core.IMO = reader.GetString(3);
|
|
if (!reader.IsDBNull(4)) core.ENI = reader.GetString(4);
|
|
if (!reader.IsDBNull(5)) core.PoC = reader.GetString(5);
|
|
if (!reader.IsDBNull(6)) core.Portname = reader.GetString(6);
|
|
if (!reader.IsDBNull(7)) core.ETA = reader.GetDateTime(7);
|
|
if (!reader.IsDBNull(8)) core.CustomerId = reader.GetGuid(8);
|
|
if (!reader.IsDBNull(9)) core.previous = reader.GetGuid(9);
|
|
if (!reader.IsDBNull(10)) core.next = reader.GetGuid(10);
|
|
core.IsTransit = reader.GetBoolean(11);
|
|
if (!reader.IsDBNull(12)) core.wetris_zz_56_datensatz_id = reader.GetInt32(12);
|
|
core.BSMDStatusInternal = (BSMDStatus) Enum.ToObject(typeof(BSMDStatus), reader.GetByte(13));
|
|
core.InitialHIS = (Message.NSWProvider) Enum.ToObject(typeof(Message.NSWProvider), reader.GetByte(14));
|
|
if (!reader.IsDBNull(15)) core.HerbergFormGuid = reader.GetGuid(15);
|
|
if (!reader.IsDBNull(16)) core.HerbergFormTemplateGuid = reader.GetGuid(16);
|
|
if (!reader.IsDBNull(17)) core.HerbergReportType = reader.GetString(17);
|
|
if (!reader.IsDBNull(18)) core.HerbergEmailContactReportingVessel = reader.GetString(18);
|
|
if (!reader.IsDBNull(19)) core.HerbergEmail24HrsContact = reader.GetString(19);
|
|
if (!reader.IsDBNull(20)) core.ETAKielCanal = reader.GetDateTime(20);
|
|
if (!reader.IsDBNull(21)) core.HerbergRevDate = reader.GetDateTime(21);
|
|
if (!reader.IsDBNull(22)) core.ReportStatus = (ReportStatusEnum) Enum.ToObject(typeof(ReportStatusEnum), reader.GetByte(22));
|
|
if (!reader.IsDBNull(23)) core.SietasSheetVersion = reader.GetString(23);
|
|
if (!reader.IsDBNull(24)) core.Incoming = reader.GetBoolean(24);
|
|
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);
|
|
if (!reader.IsDBNull(29)) core.EditedBy = reader.GetString(29);
|
|
if (!reader.IsDBNull(30)) core.TicketNo = reader.GetString(30);
|
|
if (!reader.IsDBNull(31)) core.Cancelled = reader.GetBoolean(31);
|
|
if (!reader.IsDBNull(32)) core.VisitIdOrTransitIdCancellable = reader.GetBoolean(32);
|
|
if (!reader.IsDBNull(33)) core.BlockedNotificationClasses = reader.GetString(33);
|
|
if (!reader.IsDBNull(34)) core.FreeNotificationClasses = reader.GetString(34);
|
|
if (!reader.IsDBNull(35)) core.OwnNotificationClasses = reader.GetString(35);
|
|
if (!reader.IsDBNull(36)) core.StatusCheckErrorCode = reader.GetString(36);
|
|
if (!reader.IsDBNull(37)) core.StatusCheckErrorMessage = reader.GetString(37);
|
|
if (!reader.IsDBNull(38)) core.QueryNSWStatus = reader.GetBoolean(38);
|
|
if (!reader.IsDBNull(39)) core.ExcelImportComplete = reader.GetBoolean(39);
|
|
if (!reader.IsDBNull(40)) core.PONumber = reader.GetString(40);
|
|
if (!reader.IsDBNull(41)) core.Flags = reader.GetInt32(41);
|
|
if (!reader.IsDBNull(42)) core.POATA = reader.GetDateTime(42);
|
|
|
|
result.Add(core);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region public methods
|
|
|
|
public Message CreateMessage(Message.NotificationClass notificationClass)
|
|
{
|
|
// hier wird keine Validierung gemacht, ob die Messageklasse schon vorhanden ist!!
|
|
Message result = new Message();
|
|
result.MessageNotificationClass = notificationClass;
|
|
result.MessageCoreId = this.Id;
|
|
result.MessageCore = this;
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Definition: Eine Liste von Meldeklassen enthält dann Daten, wenn für irgendeine Meldeklasse außer
|
|
/// VISIT/TRANSIT ein Element vorhanden ist
|
|
/// </summary>
|
|
public static bool HasMessageData(List<Message> messages)
|
|
{
|
|
foreach(Message message in messages)
|
|
{
|
|
if ((message.MessageNotificationClass != Message.NotificationClass.VISIT) &&
|
|
(message.MessageNotificationClass != Message.NotificationClass.TRANSIT))
|
|
if (message.Elements.Count > 0)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool IsFlagSet(CoreFlags flag)
|
|
{
|
|
return (this.Flags & (int)flag) != 0;
|
|
}
|
|
|
|
public void SetFlag(bool value, CoreFlags flag)
|
|
{
|
|
if (value) this.Flags |= (int)flag;
|
|
else this.Flags &= (int)~flag;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region display override
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("{0} - {1}", this.IMO, this.ETA);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IComparable implementation
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if(obj is MessageCore messageCore)
|
|
{
|
|
return Nullable.Compare((messageCore).ETA_NOA_NOD, this.ETA_NOA_NOD);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IEquatable<T> implementation
|
|
|
|
public bool Equals(MessageCore other)
|
|
{
|
|
return other != null && Id == other.Id;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|