82 lines
3.0 KiB
C#
82 lines
3.0 KiB
C#
using Npgsql;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DatenDB
|
|
{
|
|
public class FahrerAuftrag
|
|
{
|
|
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
private const string COLUMNS = "auftrag_id, fahrer_id, wann, zusatz, kndnr, kndname, aufgabe, beschreibung, gedruckt, gedruckt_von, erledigt, erledigt_von, erstellt, erstellt_von";
|
|
private const string TABLE = "kundenverwaltung.fahrer_auftrag";
|
|
public const string ASPECTS = "AuftragID,Fahrer,Wann,KundeNummer,Kunde,Aufgabe,Zusatz,Beschreibung,Gedruckt,Erledigt,Erstellt,Am";
|
|
|
|
public FahrerAuftrag()
|
|
{
|
|
}
|
|
public static List<FahrerAuftrag> GetAuftragList()
|
|
{
|
|
DatenbankConnection.GetConnection().Open();
|
|
List<FahrerAuftrag> resultList = new List<FahrerAuftrag>();
|
|
NpgsqlCommand command = new NpgsqlCommand();
|
|
command.Connection = DatenbankConnection.GetConnection();
|
|
|
|
command.CommandText = $"select {COLUMNS} from {TABLE}";
|
|
|
|
NpgsqlDataReader reader = command.ExecuteReader();
|
|
while (reader.Read()) resultList.Add(new FahrerAuftrag(reader));
|
|
reader.Close();
|
|
DatenbankConnection.GetConnection().Close();
|
|
|
|
foreach(FahrerAuftrag fahrerAuftrag in resultList)
|
|
{
|
|
fahrerAuftrag.Fahrer = get_fahrer(fahrerAuftrag.FahrerID);
|
|
}
|
|
return resultList;
|
|
}
|
|
|
|
public FahrerAuftrag(NpgsqlDataReader reader)
|
|
{
|
|
this.AuftragID = reader.GetInt32(0);
|
|
this.FahrerID = reader.IsDBNull(1) ? null : (int?)reader.GetInt32(1);
|
|
this.Wann = reader.GetDateTime(2);
|
|
this.Zusatz = reader.IsDBNull(3) ? string.Empty : reader.GetString(3);
|
|
this.KundeNummer = reader.GetString(4);
|
|
this.Kunde = reader.GetString(5);
|
|
this.Aufgabe = reader.GetString(6);
|
|
this.Beschreibung = reader.GetString(7);
|
|
this.Gedruckt = reader.IsDBNull(8) ? null : (DateTime?)reader.GetDateTime(8);
|
|
this.GedrucktVon = reader.IsDBNull(9) ? null : (int?)reader.GetInt32(9);
|
|
this.Erledigt = reader.IsDBNull(10) ? null : (DateTime?)reader.GetDateTime(10);
|
|
this.ErledigtVon = reader.IsDBNull(11) ? null : (int?)reader.GetInt32(11);
|
|
this.Erstellt = reader.IsDBNull(12) ? null : (DateTime?)reader.GetDateTime(12);
|
|
this.ErstelltVon = reader.GetInt32(13);
|
|
|
|
}
|
|
public int AuftragID { get; set; }
|
|
public string Fahrer { get; set; }
|
|
public int? FahrerID { get; set; }
|
|
public string KundeNummer { get; set; }
|
|
public string Kunde { get; set; }
|
|
public string Aufgabe { get; set; }
|
|
public string Beschreibung { get; set; }
|
|
public DateTime Wann { get; set; }
|
|
public string Zusatz { get; set; }
|
|
public DateTime? Gedruckt { get; set; }
|
|
public int? GedrucktVon { get; set; }
|
|
public DateTime? Erledigt { get; set; }
|
|
public int? ErledigtVon { get; set; }
|
|
public DateTime? Erstellt { get; set; }
|
|
public int ErstelltVon { get; set; }
|
|
private static string get_fahrer(int? fahrerid)
|
|
{
|
|
string fahrer = Benutzer.GetBenutzer(null, fahrerid).Vorname + " " + Benutzer.GetBenutzer(null, fahrerid).Nachname;
|
|
|
|
return fahrer;
|
|
}
|
|
}
|
|
}
|