600 lines
23 KiB
C#
600 lines
23 KiB
C#
using BrightIdeasSoftware;
|
|
using Deckungsbeitrag;
|
|
using Npgsql;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DatenDB
|
|
{
|
|
#region Enums
|
|
/// <summary>
|
|
/// Enum AuftragStatus
|
|
/// </summary>
|
|
public enum AuftragStatus
|
|
{
|
|
Abgeholt = 0,
|
|
Aufgelegt = 1,
|
|
Gewaschen = 2,
|
|
Herrichten = 3,
|
|
Vorbereitet = 4,
|
|
Fertig = 7,
|
|
Ausgeliefert = 8,
|
|
AufAbruf = 9
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enum AuftragTyp Wenn Geschäft dann Container = Pakete.
|
|
/// </summary>
|
|
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<List<Auftrag>> GetAuftragListTodayAsync(DateTime produktion, NpgsqlConnection conn, AuftragTyp typ, int? abtstatus)
|
|
{
|
|
List<Auftrag> resultList = new List<Auftrag>();
|
|
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 < 7 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 < 7 ORDER BY liefertag ASC";
|
|
command.Parameters.AddWithValue("@produktion", produktion.Date);
|
|
|
|
using (var reader = await command.ExecuteReaderAsync())
|
|
{
|
|
while (await reader.ReadAsync())
|
|
resultList.Add(new Auftrag(reader));
|
|
}
|
|
}
|
|
|
|
return resultList;
|
|
}
|
|
public static async Task<List<Auftrag>> GetExpeditListsAsync(int? typ, NpgsqlConnection conn, int? abtstatus)
|
|
{
|
|
List<Auftrag> resultList = new List<Auftrag>();
|
|
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 < 7 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 < 7 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));
|
|
}
|
|
}
|
|
|
|
return resultList;
|
|
}
|
|
public static async Task<List<Auftrag>> GetStatusListAsync(int? status, NpgsqlConnection conn)
|
|
{
|
|
List<Auftrag> resultList = new List<Auftrag>();
|
|
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 <= 7 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));
|
|
}
|
|
}
|
|
|
|
return resultList;
|
|
}
|
|
#endregion
|
|
|
|
public static List<Auftrag> GetFinishingList()
|
|
{
|
|
DatenbankConnection.GetConnection().Open();
|
|
List<Auftrag> resultList = new List<Auftrag>();
|
|
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<Auftrag> GetRampeAuftragList()
|
|
{
|
|
DatenbankConnection.GetConnection().Open();
|
|
List<Auftrag> resultList = new List<Auftrag>();
|
|
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<Auftrag> 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<Auftrag> resultList = new List<Auftrag>();
|
|
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<Auftrag> GetAuftragStatsListToday(DateTime produktion)
|
|
{
|
|
DatenbankConnection.GetConnection().Open();
|
|
List<Auftrag> resultList = new List<Auftrag>();
|
|
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 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 bool FindeAuftrag(Auftrag auftrag)
|
|
{
|
|
int result = 0;
|
|
DatenbankConnection.GetConnection().Open();
|
|
NpgsqlCommand command = new NpgsqlCommand();
|
|
|
|
command.Connection = DatenbankConnection.GetConnection();
|
|
command.CommandText = $"select auftrag_id from {TABLE} where kunde_id = {auftrag.KundeID} and erstellt::date = '{auftrag.Erstellt.Value.Date}' and liefertag = '{auftrag.Liefertag}'";
|
|
|
|
NpgsqlDataReader reader = command.ExecuteReader();
|
|
while (reader.Read()) result = reader.GetInt16(0);
|
|
reader.Close();
|
|
DatenbankConnection.GetConnection().Close();
|
|
|
|
|
|
if(result > 0) return true;
|
|
else return false;
|
|
}
|
|
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
|
|
/// <summary>
|
|
/// SPALTE 1 - Der Kundename wird angezeigt
|
|
/// </summary>
|
|
[OLVColumn("Kunde", DisplayIndex = 0)]
|
|
public string Kundename { get; set; }
|
|
|
|
/// <summary>
|
|
/// SPALTE 2 - CheckBoxen zur Auftragsauswahl als erste Spalte.
|
|
/// </summary>
|
|
[OLVColumn("Auswählen", CheckBoxes = true, DisplayIndex = 1)]
|
|
public bool IsChecked { get; set; }
|
|
|
|
/// <summary>
|
|
/// SPALTE 3 - Liefertag mit ausgeschriebenen Tag als zweite Spalte.
|
|
/// </summary>
|
|
[OLVColumn("Liefertag", DisplayIndex = 2)]
|
|
public DateTime Liefertag { get; set; }
|
|
|
|
/// <summary>
|
|
/// SPALTE 4 - Containeranzahl schmutzig
|
|
/// </summary>
|
|
[OLVColumn("schmutzig", DisplayIndex = 3, TextAlign = System.Windows.Forms.HorizontalAlignment.Center)]
|
|
public int Container { get; set; }
|
|
|
|
/// <summary>
|
|
/// SPALTE 5 - Containeranzahl sauber
|
|
/// </summary>
|
|
[OLVColumn("sauber", DisplayIndex = 4, TextAlign = System.Windows.Forms.HorizontalAlignment.Center)]
|
|
public int ContainerClean { get; set; }
|
|
|
|
/// <summary>
|
|
/// SPALTE 6 - Der Status wird angezeigt.
|
|
/// </summary>
|
|
[OLVColumn("Status", DisplayIndex = 5)]
|
|
public AuftragStatus Status { get; set; }
|
|
|
|
/// <summary>
|
|
/// SPALTE 7 - Der Auftragtyp wird angezeigt.
|
|
/// </summary>
|
|
[OLVColumn("Typ", IsVisible = true, DisplayIndex = 6)]
|
|
public AuftragTyp Typ { get; set; }
|
|
|
|
/// <summary>
|
|
/// SPALTE 8 - Die "Erstellt von" Spalte mit Datum wird erstellt
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// SPALTE 9 - Die "Gedruckt von" Spalte mit Datum wird erstellt
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// SPALTE 10 - Die "Erledigt von" Spalte mit Datum wird erstellt
|
|
/// </summary>
|
|
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;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// SPALTE 11 - Die Aufgabe (STV, STH, INV) wird angezeigt wenn vorhanden.
|
|
/// </summary>
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// SPALTE 12 - Button Etikett Drucken wird angezeigt.
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// SPALTE 13 - Button Abschließenvon Aufträgen wird angezeigt.
|
|
/// </summary>
|
|
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; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Zusatz und Typ Properties werden ausgeblendet.
|
|
/// </summary>
|
|
[OLVColumn("Zusatz", IsVisible = false)]
|
|
public string ZusatzInfo { get; set; }
|
|
|
|
/// <summary>
|
|
/// Properties von ObjectListView ignoriert.
|
|
/// </summary>
|
|
[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; }
|
|
/// <summary>
|
|
/// BenutzerID des ausführenden Users
|
|
/// </summary>
|
|
[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;
|
|
}
|
|
|
|
}
|
|
} |