using BrightIdeasSoftware; using Deckungsbeitrag; using HarfBuzzSharp; using Npgsql; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace DatenDB { #region Enums /// /// Enum AuftragStatus /// public enum AuftragStatus { Abgeholt = 0, Aufgelegt = 1, Gewaschen = 2, Herrichten = 3, Vorbereitet = 4, Fertig = 6, Geladen = 7, Ausgeliefert = 8, AufAbruf = 9 } /// /// Enum AuftragTyp Wenn Geschäft dann Container = Pakete. /// public enum AuftragTyp { Geschäft = 0, Standart = 1, Inventur = 2, Standerhöhung = 3, Standverminderung = 4 } [Flags] public enum AbteilungsStatus { Keine = 0, // Bit 0-1: Frottee (Status) FrotteeBegonnen = 1 << 0, // 1 = begonnen FrotteeBeendet = 1 << 1, // 2 = beendet (Zwischenstatus) // Bit 2-3: Kleinteile (Status) KleinteileBegonnen = 1 << 2, // 4 = begonnen KleinteileBeendet = 1 << 3, // 8 = beendet // Bit 4-5: Großteile (Status) GrossteileBegonnen = 1 << 4, // 16 = begonnen GrossteileBeendet = 1 << 5, // 32 = beendet } #endregion public class Auftrag { // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 public const string COLUMNS = "auftrag_id, benutzer_id, aufgabe_id, kunde_id, zusatz, liefertag, gedruckt, gedruckt_von, erledigt, erledigt_von, erstellt, erstellt_von, status, tour_id, container_dirt, maschine_id, container_clean, typ, aufgabe_erledigt, abteilungen_status"; public const string ACOLUMNS = "a.auftrag_id, a.benutzer_id, a.aufgabe_id, a.kunde_id, a.zusatz, a.liefertag, a.gedruckt, a.gedruckt_von, a.erledigt, a.erledigt_von, a.erstellt, a.erstellt_von, a.status, a.tour_id, a.container_dirt, a.maschine_id, a.container_clean, a.typ, a.aufgabe_erledigt, a.abteilungen_status"; private const string TABLE = "kundenverwaltung.auftrag"; public const string ASPECTS = "FahrerID,AufgabeID,KundeID,ZusatzInfo,Wann,Gedruckt,Erledigt,Erstellt von,Erstellt Am"; static bool isExpedit = false; public Auftrag() { } #region async Tasks public static async Task> GetAuftragListTodayAsync(DateTime produktion, NpgsqlConnection conn, AuftragTyp typ, int? abtstatus) { List resultList = new List(); isExpedit = true; using (var command = new NpgsqlCommand()) { command.Connection = conn; if (abtstatus != null) command.CommandText = $"SELECT {ACOLUMNS}, k.name1 as kunde_name, k.suchtext as suchtext, u.benutzer_name as fahrer FROM {TABLE} a left join kundenverwaltung.kunde k on a.kunde_id = k.kunde_id left join kundenverwaltung.benutzer u on a.benutzer_id = u.benutzer_id WHERE typ = {(int)typ} AND erstellt::date = @produktion AND (a.abteilungen_status & 2) = 0 OR typ = {(int)typ} AND status < {(int)AuftragStatus.Fertig} AND (a.abteilungen_status & 2) = 0 ORDER BY liefertag ASC"; else command.CommandText = $"SELECT {ACOLUMNS}, k.name1 as kunde_name, k.suchtext as suchtext, u.benutzer_name as fahrer FROM {TABLE} a left join kundenverwaltung.kunde k on a.kunde_id = k.kunde_id left join kundenverwaltung.benutzer u on a.benutzer_id = u.benutzer_id WHERE typ = {(int)typ} AND erstellt::date = @produktion OR typ = {(int)typ} AND status < {(int)AuftragStatus.Fertig} ORDER BY liefertag ASC"; //Status kleiner FERTIG command.Parameters.AddWithValue("@produktion", produktion.Date); using (var reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) resultList.Add(new Auftrag(reader)); } } isExpedit = false; return resultList; } public static async Task> GetExpeditListsAsync(int? typ, NpgsqlConnection conn, int? abtstatus) { List resultList = new List(); isExpedit = true; using (var command = new NpgsqlCommand()) { command.Connection = conn; if (abtstatus != null) command.CommandText = $"SELECT {ACOLUMNS}, k.name1 as kunde_name, k.suchtext as suchtext, u.benutzer_name as fahrer FROM {TABLE} a left join Kundenverwaltung.kunde k on a.kunde_id = k.kunde_id left join kundenverwaltung.benutzer u on a.benutzer_id = u.benutzer_id WHERE typ >= @typ AND status < {(int)AuftragStatus.Fertig} AND a.abteilungen_status <= {abtstatus} ORDER BY status DESC, liefertag ASC"; else command.CommandText = $"SELECT {ACOLUMNS}, k.name1 as kunde_name, k.suchtext as suchtext, u.benutzer_name as fahrer FROM {TABLE} a left join Kundenverwaltung.kunde k on a.kunde_id = k.kunde_id left join kundenverwaltung.benutzer u on a.benutzer_id = u.benutzer_id WHERE typ >= @typ AND status < {(int)AuftragStatus.Fertig} ORDER BY status DESC, liefertag ASC"; command.Parameters.AddWithValue("@typ", typ ?? 0); // Parameterized + Null-Handling using (var reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) resultList.Add(new Auftrag(reader)); } } isExpedit = false; return resultList; } public static async Task> GetStatusListAsync(int? status, NpgsqlConnection conn) { List resultList = new List(); isExpedit = true; using (var command = new NpgsqlCommand()) { command.Connection = conn; if (status == null) command.CommandText = $"SELECT {ACOLUMNS}, k.name1 as kunde_name, k.suchtext as suchtext, u.benutzer_name as fahrer FROM {TABLE} a left join kundenverwaltung.kunde k on a.kunde_id = k.kunde_id left join kundenverwaltung.benutzer u on a.benutzer_id = u.benutzer_id WHERE status <= {(int)AuftragStatus.Fertig} ORDER BY status DESC, liefertag ASC"; else command.CommandText = $"SELECT {ACOLUMNS}, k.name1 as kunde_name, k.suchtext as suchtext, u.benutzer_name as fahrer FROM {TABLE} a left join kundenverwaltung.kunde k on a.kunde_id = k.kunde_id left join kundenverwaltung.benutzer u on a.benutzer_id = u.benutzer_id WHERE status = {status} ORDER BY status DESC, liefertag ASC"; using (var reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) resultList.Add(new Auftrag(reader)); } } isExpedit = false; return resultList; } public static async Task>> GetAuftraegeProLiefertagAsync(NpgsqlConnection conn, AuftragTyp standart, AuftragStatus aufgelegt) { // ✅ 5 FIXED Keys mit Sonntags-Check var result = new Dictionary> { [DateTime.Today.Date] = new List(), }; using (var command = new NpgsqlCommand()) { command.Connection = conn; command.CommandText = $"SELECT {COLUMNS} from {TABLE} where typ <= {(int)standart} and status <= {(int)aufgelegt} and liefertag >= CURRENT_DATE order by liefertag"; using (var reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { Auftrag auftrag = new Auftrag(reader); var tag = auftrag.Liefertag.Date; // Nur Datum if (result.Count == 5) tag = result.Keys.Last(); if (!result.ContainsKey(tag)) result[tag] = new List(); result[tag].Add(auftrag); } } } return result; } #endregion public static List GetFinishingList() { DatenbankConnection.GetConnection().Open(); List resultList = new List(); NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = DatenbankConnection.GetConnection(); cmd.CommandText = $"select {COLUMNS} from {TABLE} where status = 2 order by liefertag asc"; NpgsqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) resultList.Add(new Auftrag(reader)); reader.Close(); DatenbankConnection.GetConnection().Close(); return resultList; } public static List GetRampeAuftragList() { DatenbankConnection.GetConnection().Open(); List resultList = new List(); NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = DatenbankConnection.GetConnection(); cmd.CommandText = $"select {COLUMNS} from {TABLE} where status = 0 order by liefertag asc"; NpgsqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) resultList.Add(new Auftrag(reader)); reader.Close(); DatenbankConnection.GetConnection().Close(); return resultList; } public static List GetAuftragList(string s, Auftrag auftrag) { int? aID = null; int? mID = null; //Get MaschineID und AuftragID für Aufträge vor und nach Auftrag if (auftrag != null) { mID = auftrag.MaschineID; aID = auftrag.AuftragID; } //Get AufgabeID für Anzeige von Standerhöhungen if (s == "STH") aID = (int)Aufgabe.GetAufgabe(s, null).AufgabeID; DatenbankConnection.GetConnection().Open(); List resultList = new List(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = DatenbankConnection.GetConnection(); if (s == "Expedit") command.CommandText = $"select {COLUMNS} from {TABLE} where status = 3 order by liefertag asc"; if (s == string.Empty) command.CommandText = $"select {COLUMNS} from {TABLE} where gedruckt is null and erledigt is null"; if (s == "davor") command.CommandText = $"select {COLUMNS} from {TABLE} where maschine_id = {mID} and auftrag_id < {aID} order by liefertag asc limit 3"; if (s == "danach") command.CommandText = $"select {COLUMNS} from {TABLE} where maschine_id = {mID} and auftrag_id > {aID} order by liefertag asc limit 3"; if (s == "STH") command.CommandText = $"select {COLUMNS} from {TABLE} where status = 3 and aufgabe_id = {aID} order by liefertag"; NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) resultList.Add(new Auftrag(reader)); reader.Close(); DatenbankConnection.GetConnection().Close(); return resultList; } public static List GetAuftragStatsListToday(DateTime produktion) { DatenbankConnection.GetConnection().Open(); List resultList = new List(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = DatenbankConnection.GetConnection(); command.CommandText = $"select {COLUMNS} from {TABLE} where typ = 1 and erstellt::date = '{produktion.Date}' order by liefertag asc"; NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) resultList.Add(new Auftrag(reader)); reader.Close(); DatenbankConnection.GetConnection().Close(); return resultList; } public static List GetTourenListe(Benutzer fahrer) { DateTime dateTime = NaechsterLiefertag(); DatenbankConnection.GetConnection().Open(); List resultList = new List(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = DatenbankConnection.GetConnection(); command.CommandText = $"select {ACOLUMNS} from {TABLE} a join kundenverwaltung.kunde k on a.kunde_id = k.kunde_id where typ = 1 and a.liefertag = '{dateTime}' and a.benutzer_id = {fahrer.BenutzerID} and a.status >= {(int)AuftragStatus.Vorbereitet} and a.status <= {(int)AuftragStatus.Fertig} order by k.region, k.bezeichnung"; NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) resultList.Add(new Auftrag(reader)); reader.Close(); DatenbankConnection.GetConnection().Close(); return resultList; } public static Auftrag GetAuftrag(int? auftragID) { DatenbankConnection.GetConnection().Open(); Auftrag result = new Auftrag(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = DatenbankConnection.GetConnection(); command.CommandText = $"select {COLUMNS} from {TABLE} where auftrag_id = {auftragID}"; NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) result = new Auftrag(reader); reader.Close(); DatenbankConnection.GetConnection().Close(); return result; } public static Auftrag GetLastAuftrag(int? benutzerID) { DatenbankConnection.GetConnection().Open(); Auftrag result = new Auftrag(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = DatenbankConnection.GetConnection(); command.CommandText = $"select {COLUMNS} from {TABLE} where erstellt_von = {benutzerID} order by erstellt desc limit 1"; NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) result = new Auftrag(reader); reader.Close(); DatenbankConnection.GetConnection().Close(); return result; } public static List FindeAuftragVonKunde(Kunde kunde, string zusatz) { List result = new List(); DatenbankConnection.GetConnection().Open(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = DatenbankConnection.GetConnection(); if (string.IsNullOrWhiteSpace(zusatz)) command.CommandText = $"select {COLUMNS} from {TABLE} where kunde_id = {kunde.KundeID} and status = {(int)AuftragStatus.Abgeholt}"; else command.CommandText = $"select {COLUMNS} from {TABLE} where kunde_id = {kunde.KundeID} and status = {(int)AuftragStatus.Abgeholt} and zusatz ~* '{zusatz}'"; NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) result.Add(new Auftrag(reader)); reader.Close(); DatenbankConnection.GetConnection().Close(); return result; } public (bool Gefunden, int auftragID) FindeAuftrag(bool exakt) { int result = 0; DatenbankConnection.GetConnection().Open(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = DatenbankConnection.GetConnection(); if (exakt) command.CommandText = $"select auftrag_id from {TABLE} where kunde_id = {this.KundeID} and erstellt::date = '{this.Erstellt.Value.Date}' and liefertag = '{this.Liefertag}'"; else command.CommandText = $"select auftrag_id from {TABLE} where kunde_id = {this.KundeID} and liefertag = '{this.Liefertag}' and status = {(int)AuftragStatus.Abgeholt}"; NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) result = reader.GetInt16(0); reader.Close(); DatenbankConnection.GetConnection().Close(); if(result > 0) return (true, result); else return (false, result); } public static int[] GetContainerAnzahlen(int? kundeId) { const string sql = @" SELECT COALESCE(MAX(container_clean), 0) as max_clean, COALESCE(ROUND(AVG(container_clean)), 0) as avg_clean, COALESCE(MIN(container_clean), 0) as min_clean FROM {0} WHERE (@kundeId IS NULL OR kunde_id = @kundeId)"; NpgsqlConnection connection = null; NpgsqlCommand command = null; NpgsqlDataReader reader = null; try { connection = DatenbankConnection.GetConnection(); connection.Open(); command = new NpgsqlCommand(string.Format(sql, TABLE), connection); command.Parameters.AddWithValue("kundeId", kundeId ?? (object)DBNull.Value); reader = command.ExecuteReader(); if (reader.Read()) { return new[] { reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2) }; } return new[] { 0, 0, 0 }; } finally { reader?.Close(); command?.Dispose(); connection?.Close(); } } public static int[] GetContaineranzahl(int? kundeId) { int[] result = { 0, 0, 0 }; int i = 0; DatenbankConnection.GetConnection().Open(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = DatenbankConnection.GetConnection(); command.CommandText = $"select max(container_clean), avg(container_clean), min(container_clean) from {TABLE} where kunde_id = {kundeId}"; NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { result[i] = reader.IsDBNull(i) ? 0 : reader.GetInt16(i); i++; } reader.Close(); DatenbankConnection.GetConnection().Close(); return result; } public Auftrag(NpgsqlDataReader reader) { this.AuftragID = reader.GetInt32(0); this.ArbeiterID = reader.IsDBNull(1) ? null : (int?)reader.GetInt32(1); this.AufgabeID = reader.IsDBNull(2) ? null : (int?)reader.GetInt32(2); this.KundeID = reader.GetInt32(3); this.ZusatzInfo = reader.IsDBNull(4) ? string.Empty : reader.GetString(4); this.Liefertag = reader.GetDateTime(5); this.Gedruckt = reader.IsDBNull(6) ? null : (DateTime?)reader.GetDateTime(6); this.GedrucktVon = reader.IsDBNull(7) ? null : (int?)reader.GetInt32(7); this.Erledigt = reader.IsDBNull(8) ? null : (DateTime?)reader.GetDateTime(8); this.ErledigtVon = reader.IsDBNull(9) ? null : (int?)reader.GetInt32(9); this.Erstellt = reader.IsDBNull(10) ? null : (DateTime?)reader.GetDateTime(10); this.ErstelltVon = reader.GetInt32(11); this.Status = (AuftragStatus)reader.GetInt32(12); this.TourID = reader.IsDBNull(13) ? null : (int?)reader.GetInt32(13); this.Container = reader.IsDBNull(14) ? 0 : reader.GetInt32(14); this.MaschineID = reader.IsDBNull(15) ? null : (int?)reader.GetInt32(15); this.ContainerClean = reader.IsDBNull(16) ? 0 : reader.GetInt32(16); this.Typ = reader.IsDBNull(17) ? AuftragTyp.Standart : (AuftragTyp)reader.GetInt32(17); this.AufgabeErledigt = reader.IsDBNull(18) ? false : reader.GetBoolean(18); this.Abteilungen = reader.IsDBNull(19) ? AbteilungsStatus.Keine : (AbteilungsStatus)reader.GetInt16(19); if (isExpedit) { this.Kundename = reader.GetString(20); this.Kundename = reader.IsDBNull(21) ? this.Kundename : reader.GetString(21); if (this.Kundename == "BAR DIVERSE") this.Kundename = this.ZusatzInfo; this.Fahrer = reader.IsDBNull(22) ? string.Empty : reader.GetString(22); } } #region Properties /// /// SPALTE 1 - Der Kundename wird angezeigt /// [OLVColumn("Kunde", DisplayIndex = 0)] public string Kundename { get; set; } /// /// SPALTE 2 - CheckBoxen zur Auftragsauswahl als erste Spalte. /// [OLVColumn("Auswählen", CheckBoxes = true, DisplayIndex = 1)] public bool IsChecked { get; set; } /// /// SPALTE 3 - Liefertag mit ausgeschriebenen Tag als zweite Spalte. /// [OLVColumn("Liefertag", DisplayIndex = 2)] public DateTime Liefertag { get; set; } /// /// SPALTE 4 - Containeranzahl schmutzig /// [OLVColumn("schmutzig", DisplayIndex = 3, TextAlign = System.Windows.Forms.HorizontalAlignment.Center)] public int Container { get; set; } /// /// SPALTE 5 - Containeranzahl sauber /// [OLVColumn("sauber", DisplayIndex = 4, TextAlign = System.Windows.Forms.HorizontalAlignment.Center)] public int ContainerClean { get; set; } /// /// SPALTE 6 - Der Status wird angezeigt. /// [OLVColumn("Status", DisplayIndex = 5)] public AuftragStatus Status { get; set; } /// /// SPALTE 7 - Der Auftragtyp wird angezeigt. /// [OLVColumn("Typ", IsVisible = true, DisplayIndex = 6)] public AuftragTyp Typ { get; set; } /// /// SPALTE 8 - Die "Erstellt von" Spalte mit Datum wird erstellt /// private string _auftragerstellt; [OLVColumn("Erstellt")] public string AuftragErstellt { get { if (this.Erstellt != null) return _auftragerstellt = Benutzer.GetBenutzer(null, this.ErstelltVon).BenutzerName + " von " + this.Erstellt.ToString(); else return null; } } /// /// SPALTE 9 - Die "Gedruckt von" Spalte mit Datum wird erstellt /// private string _auftraggedruckt; [OLVColumn("Gedruckt")] public string AuftragGedruckt { get { if(this.Gedruckt != null) return _auftraggedruckt = Benutzer.GetBenutzer(null, this.GedrucktVon).BenutzerName + " von " + this.Gedruckt.ToString(); else return null; } } /// /// SPALTE 10 - Die "Erledigt von" Spalte mit Datum wird erstellt /// private string _auftragerledigt; [OLVColumn("Erledigt")] public string AuftragErledigt { get { if (this.Erledigt != null) return _auftragerledigt = Benutzer.GetBenutzer(null, this.ErledigtVon).BenutzerName + " von " + this.Erledigt.ToString(); else return null; } } /// /// SPALTE 11 - Die Aufgabe (STV, STH, INV) wird angezeigt wenn vorhanden. /// private string _auftragaufgabe; [OLVColumn("Aufgabe", DisplayIndex = 10, TextAlign = System.Windows.Forms.HorizontalAlignment.Center)] public string AuftragAufgabe { get { if (this.AufgabeID != null) return _auftragaufgabe = Aufgabe.GetAufgabe(null, this.AufgabeID).Bezeichnung; else return null; } } /// /// SPALTE 12 - Button Etikett Drucken wird angezeigt. /// private string _etikett; [OLVColumn("Etikett", DisplayIndex = 11, TextAlign = System.Windows.Forms.HorizontalAlignment.Center)] public string Etikett { get { if (Typ >= AuftragTyp.Inventur) { if (Status >= AuftragStatus.Vorbereitet) return _fertig = string.Empty; else return _fertig = "🖨"; } else { if (Status <= AuftragStatus.Herrichten) return _fertig = "🖨"; else { if (Status == AuftragStatus.Vorbereitet) return _fertig = "🖨"; else return _fertig = string.Empty; } } } } /// /// SPALTE 13 - Button Abschließenvon Aufträgen wird angezeigt. /// private string _fertig; [OLVColumn("Abschließen", DisplayIndex = 12, TextAlign = System.Windows.Forms.HorizontalAlignment.Center)] public string Fertig { get { if(Typ >= AuftragTyp.Inventur) { if (Status >= AuftragStatus.Fertig) return _fertig = string.Empty; else return _fertig = "✅"; } else { if (Status == AuftragStatus.Vorbereitet || Status == AuftragStatus.Herrichten || Status == AuftragStatus.Gewaschen) return _fertig = "✅"; else { return _fertig = string.Empty; } } } } [OLVColumn("Fahrer", DisplayIndex = 13)] public string Fahrer { get; set; } /// /// Zusatz und Typ Properties werden ausgeblendet. /// [OLVColumn("Zusatz", IsVisible = false)] public string ZusatzInfo { get; set; } /// /// Properties von ObjectListView ignoriert. /// [OLVIgnore] public int? AuftragID { get; set; } [OLVIgnore] public int? GedrucktVon { get; set; } [OLVIgnore] public DateTime? Gedruckt { get; set; } [OLVIgnore] public DateTime? Erledigt { get; set; } [OLVIgnore] public int? ErledigtVon { get; set; } [OLVIgnore] public DateTime? Erstellt { get; set; } [OLVIgnore] public int ErstelltVon { get; set; } [OLVIgnore] public int? MaschineID { get; set; } [OLVIgnore] public int KundeID { get; set; } [OLVIgnore] public int? TourID { get; set; } /// /// BenutzerID des ausführenden Users /// [OLVIgnore] public int? ArbeiterID { get; set; } [OLVIgnore] public int? AufgabeID { get; set; } [OLVIgnore] public bool AufgabeErledigt { get; set; } = false; [OLVIgnore] public AbteilungsStatus Abteilungen { get; set; } #endregion public int[] Save() { DatenbankConnection.GetConnection().Open(); int[] result = new int[2]; NpgsqlCommand command = new NpgsqlCommand(); command.Connection = DatenbankConnection.GetConnection(); if (this.AuftragID.HasValue & this.AuftragID != 0) { command.CommandText = $"update {TABLE} set benutzer_id = :p1, aufgabe_id = :p2, kunde_id = :p3, zusatz = :p4, liefertag = :p5, gedruckt = :p6, gedruckt_von = :p7, erledigt = :p8, erledigt_von = :p9, erstellt = :p10, erstellt_von = :p11, status = :p12, tour_id = :p13, container_dirt = :p14, maschine_id = :p15, container_clean = :p16, typ = :p17, aufgabe_erledigt = :p18, abteilungen_status = :p19 WHERE auftrag_id = :p0"; } else { command.CommandText = "select nextval('kundenverwaltung.auftrag_seq')"; this.AuftragID = result[1] = (int)(long)command.ExecuteScalar(); command.CommandText = $"insert into {TABLE} ({COLUMNS}) values (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19)"; } command.Parameters.AddWithValue("p0", this.AuftragID); command.Parameters.AddWithValue("p1", this.ArbeiterID.HasValue ? this.ArbeiterID.Value : (object)DBNull.Value); command.Parameters.AddWithValue("p2", this.AufgabeID.HasValue ? this.AufgabeID.Value : (object)DBNull.Value); command.Parameters.AddWithValue("p3", this.KundeID); command.Parameters.AddWithValue("p4", string.IsNullOrEmpty(this.ZusatzInfo) ? (object)DBNull.Value : this.ZusatzInfo); command.Parameters.AddWithValue("p5", this.Liefertag); command.Parameters.AddWithValue("p6", this.Gedruckt.HasValue ? this.Gedruckt.Value : (object)DBNull.Value); command.Parameters.AddWithValue("p7", this.GedrucktVon.HasValue ? this.GedrucktVon.Value : (object)DBNull.Value); command.Parameters.AddWithValue("p8", this.Erledigt.HasValue ? this.Erledigt.Value : (object)DBNull.Value); command.Parameters.AddWithValue("p9", this.ErledigtVon.HasValue ? this.ErledigtVon.Value : (object)DBNull.Value); command.Parameters.AddWithValue("p10", this.Erstellt); command.Parameters.AddWithValue("p11", this.ErstelltVon); command.Parameters.AddWithValue("p12", (int)this.Status); command.Parameters.AddWithValue("p13", this.TourID.HasValue ? this.TourID.Value : (object)DBNull.Value); command.Parameters.AddWithValue("p14", this.Container); command.Parameters.AddWithValue("p15", this.MaschineID.HasValue ? this.MaschineID.Value : 0); command.Parameters.AddWithValue("p16", this.ContainerClean); command.Parameters.AddWithValue("p17", (int)this.Typ); command.Parameters.AddWithValue("p18", this.AufgabeErledigt); command.Parameters.AddWithValue("p19", (int)this.Abteilungen); result[0] = command.ExecuteNonQuery(); DatenbankConnection.GetConnection().Close(); return result; } public static DateTime NaechsterLiefertag() { DateTime heute = DateTime.Today; DateTime kandidat = heute.AddDays(1); // Wochenende überspringen while (kandidat.DayOfWeek == DayOfWeek.Saturday || kandidat.DayOfWeek == DayOfWeek.Sunday) kandidat = kandidat.AddDays(1); return kandidat; } } } //INSTALL-REMINDER: Change Status in DB-Auftrag von 7 auf 6