78 lines
2.3 KiB
C#
78 lines
2.3 KiB
C#
//
|
|
// Class: IDatabaseEntity
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 3/2/2015 9:08:47 PM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Collections.Generic;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
|
|
public abstract class DatabaseEntity
|
|
{
|
|
protected Guid? id;
|
|
protected string tablename;
|
|
|
|
/// <summary>
|
|
/// Nachrichtentyp der abgeleiteten Meldeklassen
|
|
/// </summary>
|
|
public Message.NotificationClass MessageNotificationClass { get; set; }
|
|
|
|
/// <summary>
|
|
/// Referenz zur eigentlichen Schiffankunft
|
|
/// </summary>
|
|
public MessageCore MessageCore { get; set; }
|
|
|
|
/// <summary>
|
|
/// gemeinschaftliche Daten
|
|
/// </summary>
|
|
public Message MessageHeader { get; set; }
|
|
|
|
/// <summary>
|
|
/// Status für Services
|
|
/// </summary>
|
|
public Message.BSMDStatus InternalStatus { get; set; }
|
|
|
|
/// <summary>
|
|
/// SQL Table name to construct queries
|
|
/// </summary>
|
|
public string Tablename { get { return this.tablename; } }
|
|
|
|
/// <summary>
|
|
/// primary key
|
|
/// </summary>
|
|
public Guid? Id { get { return this.id; } }
|
|
|
|
/// <summary>
|
|
/// IsNew Flag
|
|
/// </summary>
|
|
public bool IsNew { get { return !this.id.HasValue; } }
|
|
|
|
/// <summary>
|
|
/// when it's time (during save), create id
|
|
/// </summary>
|
|
public void CreateId() { this.id = Guid.NewGuid(); }
|
|
|
|
public abstract void PrepareSave(IDbCommand cmd);
|
|
|
|
public virtual void PrepareDelete(IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
scmd.CommandText = string.Format("DELETE FROM {0} WHERE Id = @ID", Tablename);
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
}
|
|
|
|
public abstract void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria);
|
|
|
|
public abstract List<DatabaseEntity> LoadList(IDataReader reader);
|
|
|
|
}
|
|
}
|