using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bsmd.database
{
///
/// Basisklasse aller Nachrichtentypen, zentrale Klasse für die NSW App
///
public class Message : IDatabaseEntity
{
private Guid messageHeaderId;
private MessageCore messageCore;
private ReportingParty reportingParty;
#region Enumerations
public enum NotificationClass
{
VISIT, TRANSIT, NOA_NOD, ATA, ATD, SEC, POBA, POBD, NAME, TIEFA, TIEFD,
BKRA, BKRD, STAT, LADG, INFO, SERV, PRE72H, MDH, WAS, CREW, PAS, BPOL, TOWA, TOWD, HAZA, HAZD
}
public enum MessageStatus
{ ACCEPTED, REJECTED }
#endregion
#region Properties
///
/// Primärschlüssel
///
public Guid MessageHeaderId { get { return this.messageHeaderId; } }
///
/// Dieser Wert wird vom NSW / HIS vergeben
///
public string ClientRequestId { set; get; }
///
/// Referenz zur eigentlichen Schiffankunft
///
public MessageCore MessageCore { get { return this.messageCore; } }
public Guid? MessageId { get; set; }
public DateTime? SentAt { get; set; }
public DateTime? ReceivedAt { get; set; }
public DateTime? RequestedAt { get; set; }
public bool Reset { get; set; }
public bool Cancel { get; set; }
public MessageStatus? Status { get; set; }
///
/// Nachrichtentyp der abgeleiteten Meldeklassen
///
public NotificationClass MessageNotificationClass { get; set; }
///
/// Der Meldende
///
public ReportingParty ReportingParty { get { return this.reportingParty; } }
#endregion
#region public virtual methods
#endregion
#region IDatabaseEntity implementation
public bool IsNew
{
get { throw new NotImplementedException(); }
}
public void Save(System.Data.IDbConnection connection)
{
SqlConnection sqlCon = connection as SqlConnection;
if (sqlCon == null) return;
if (this.IsNew)
{
string query = "INSERT INTO MessageHeader (ClientRequestId, MessageCoreId, MessageId, SentAt, ReceivedAt, RequestedAt, NotificationClass, Reset, Cancel, Status, ReportingPartyId) " +
"VALUES (@CLIENTREQUESTID, @MESSAGECOREID, @MESSAGEID, @SENTAT, @RECEIVEDAT, @REQUESTEDAT, @NOTIFICATIONCLASS, @RESET, @CANCEL, @STATUS, @REPORTINGPARTYID)";
SqlCommand cmd = new SqlCommand(query, sqlCon);
if (this.ClientRequestId != null)
cmd.Parameters.AddWithValue("@CLIENTREQUESTID", this.ClientRequestId);
else
cmd.Parameters.AddWithValue("@CLIENTREQUESTID", DBNull.Value);
cmd.Parameters.AddWithValue("@MESSAGECOREID", this.MessageCore.Id);
if (this.MessageId.HasValue)
cmd.Parameters.AddWithValue("@MESSAGEID", this.MessageId.Value);
else
cmd.Parameters.AddWithValue("@MESSAGEID", DBNull.Value);
if (this.SentAt.HasValue)
cmd.Parameters.AddWithValue("@SENTAT", this.SentAt.Value);
else
cmd.Parameters.AddWithValue("@SENTAT", DBNull.Value);
if (this.ReceivedAt.HasValue)
cmd.Parameters.AddWithValue("@RECEIVEDAT", this.ReceivedAt.Value);
else
cmd.Parameters.AddWithValue("@RECEIVEDAT", DBNull.Value);
if (this.RequestedAt.HasValue)
cmd.Parameters.AddWithValue("@REQUESTEDAT", this.RequestedAt.Value);
else
cmd.Parameters.AddWithValue("@REQUESTEDAT", DBNull.Value);
cmd.Parameters.AddWithValue("@NOTIFICATIONCLASS", (int) this.MessageNotificationClass);
cmd.Parameters.AddWithValue("@RESET", this.Reset);
cmd.Parameters.AddWithValue("@CANCEL", this.Cancel);
if (this.Status.HasValue)
cmd.Parameters.AddWithValue("@STATUS", (int)this.Status.Value);
else
cmd.Parameters.AddWithValue("@STATUS", DBNull.Value);
cmd.Parameters.AddWithValue("@REPORTINGPARTYID", this.ReportingParty.Id);
}
}
public void Delete(System.Data.IDbConnection connection)
{
throw new NotImplementedException();
}
#endregion
}
}