106 lines
3.7 KiB
C#
106 lines
3.7 KiB
C#
using BrightIdeasSoftware;
|
|
using DatenDB;
|
|
using Deckungsbeitrag.UserControls;
|
|
using Npgsql;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Deckungsbeitrag.AA_Klassen
|
|
{
|
|
internal class ArtikelNachwaesche
|
|
{
|
|
// 0 1 2 3 4 5 6
|
|
private static string COLUMNS = "nw_artikel_id, artikel_id, datum, nachwaesche, nw_muell, nw_sauber, reklamation";
|
|
private static string TABLE = "kundenverwaltung.nw_artikel";
|
|
|
|
#region Class-Standarts (Properties, Save, reader)
|
|
public ArtikelNachwaesche() { }
|
|
|
|
[OLVColumn(IsVisible = false)]
|
|
public int? NachwaescheID { get; set; }
|
|
[OLVColumn(IsVisible = false)]
|
|
public int? ArtikelID { get; set; }
|
|
[OLVColumn(IsVisible = false)]
|
|
public DateTime Datum { get; set; }
|
|
[OLVColumn(IsVisible = false)]
|
|
public int Nachwaesche { get; set; }
|
|
[OLVColumn("Müll", DisplayIndex = 3)]
|
|
public int Muell { get; set; }
|
|
[OLVColumn("Sauber", DisplayIndex = 2)]
|
|
public int Sauber { get; set; }
|
|
public int Reklamation { get; set; }
|
|
|
|
public int? Save()
|
|
{
|
|
int? result = 0;
|
|
DatenbankConnection.GetConnection().Open();
|
|
|
|
using (NpgsqlCommand command = new NpgsqlCommand())
|
|
{
|
|
command.Connection = DatenbankConnection.GetConnection();
|
|
|
|
if (this.NachwaescheID.HasValue & this.NachwaescheID != 0)
|
|
{
|
|
command.CommandText = $"update {TABLE} set artikel_id = :p1, datum = :p2, nachwaesche = :p3, nw_muell = :p4, nw_sauber = :p5, reklamation = :p6 WHERE nw_artikel_id = :p0";
|
|
}
|
|
else
|
|
{
|
|
command.CommandText = "select nextval('kundenverwaltung.tour_seq')";
|
|
this.NachwaescheID = (int)(long)command.ExecuteScalar();
|
|
command.CommandText = $"insert into {TABLE} ({COLUMNS}) values (:p0, :p1, :p2, :p3, :p4, :p5, :p6)";
|
|
}
|
|
|
|
command.Parameters.AddWithValue("p0", this.NachwaescheID);
|
|
command.Parameters.AddWithValue("p1", this.ArtikelID);
|
|
command.Parameters.AddWithValue("p2", this.Datum);
|
|
command.Parameters.AddWithValue("p3", this.Nachwaesche);
|
|
command.Parameters.AddWithValue("p4", this.Muell);
|
|
command.Parameters.AddWithValue("p5", this.Sauber);
|
|
command.Parameters.AddWithValue("p6", this.Reklamation);
|
|
|
|
|
|
result = command.ExecuteNonQuery();
|
|
DatenbankConnection.GetConnection().Close();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
public ArtikelNachwaesche(NpgsqlDataReader reader)
|
|
{
|
|
this.NachwaescheID = reader.GetInt32(0);
|
|
this.ArtikelID = reader.GetInt32(1);
|
|
this.Datum = reader.GetDateTime(2);
|
|
this.Nachwaesche = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
|
|
this.Muell = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
|
|
this.Sauber = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);
|
|
this.Reklamation = reader.IsDBNull(6) ? 0 : reader.GetInt32(5);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Konstruktors
|
|
internal static ArtikelNachwaesche FindeDatensatz(int? artikelID, DateTime timestamp)
|
|
{
|
|
ArtikelNachwaesche result = new ArtikelNachwaesche();
|
|
DatenbankConnection.GetConnection().Open();
|
|
NpgsqlCommand command = new NpgsqlCommand();
|
|
|
|
command.Connection = DatenbankConnection.GetConnection();
|
|
command.CommandText = $"select {COLUMNS} from {TABLE} where artikel_id = {artikelID} and datum = '{timestamp}'";
|
|
NpgsqlDataReader reader = command.ExecuteReader();
|
|
while (reader.Read()) result = new ArtikelNachwaesche(reader);
|
|
reader.Close();
|
|
DatenbankConnection.GetConnection().Close();
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|