850 lines
33 KiB
C#
850 lines
33 KiB
C#
using DatenDB;
|
|
using Deckungsbeitrag.AA_Klassen;
|
|
using Microsoft.VisualBasic;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Caching;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Forms.VisualStyles;
|
|
using System.Text.Json;
|
|
using System.Reflection;
|
|
using Deckungsbeitrag.UserControls;
|
|
|
|
|
|
namespace Deckungsbeitrag
|
|
{
|
|
public partial class FormNeuerAuftrag : Form
|
|
{
|
|
#region Properties
|
|
public Meldungen meldung = new Meldungen();
|
|
public Kunde kunde;
|
|
public Auftrag Auftrag;
|
|
public Auftrag extraAuftrag;
|
|
public Fach fach;
|
|
public AuftragArtikel AuftragArtikel;
|
|
private Benutzer benutzer;
|
|
private Maschine maschine;
|
|
bool extra;
|
|
List<Sortiment> sortimentListe;
|
|
public DateTime? letzterLiefertag;
|
|
private Kunde knd;
|
|
public DataGridViewCell aktivCell;
|
|
private string userid;
|
|
private AuftragTyp auftragtyp = AuftragTyp.Standart;
|
|
private string eingabe = string.Empty;
|
|
private DateTime nextLiefertag = DateTime.Today;
|
|
#endregion
|
|
|
|
#region Form-Konstruktor
|
|
public FormNeuerAuftrag()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public FormNeuerAuftrag(Benutzer benutzer) : this()
|
|
{
|
|
this.benutzer = benutzer;
|
|
|
|
}
|
|
public FormNeuerAuftrag(Benutzer benutzer, AuftragTyp auftragTyp) : this(benutzer)
|
|
{
|
|
this.auftragtyp = auftragTyp;
|
|
}
|
|
public FormNeuerAuftrag(Benutzer benutzer, DateTime? letzterLiefertag, AuftragTyp auftragTyp) : this(benutzer, auftragTyp)
|
|
{
|
|
this.letzterLiefertag = letzterLiefertag;
|
|
}
|
|
public FormNeuerAuftrag(string userid) : this()
|
|
{
|
|
this.userid = userid;
|
|
if (userid.Contains("wstrasse01")) this.benutzer = Benutzer.GetBenutzer("ws1", null);
|
|
if (userid.Contains("wstrasse02")) this.benutzer = Benutzer.GetBenutzer("ws2", null);
|
|
}
|
|
#endregion
|
|
private void FormNeuerAuftrag_Load(object sender, EventArgs e)
|
|
{
|
|
string kndService = string.Empty;
|
|
|
|
this.Text += " Version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
// SortimentListe holen
|
|
sortimentListe = Funktionen.SortimentLesen("Liste");
|
|
|
|
// Kunde holen
|
|
|
|
if (auftragtyp == AuftragTyp.Regelmäßig) kndService = "Geschäft";
|
|
this.kunde = Funktionen.Open_List(kndService);
|
|
|
|
// ComboBox AuftragTyp wird geladen und richtiges Item selected.
|
|
// Falls KundenAuswahl null liefert wird Form geschlossen oder wenn Waschstrasse neu geladen.
|
|
if (this.kunde != null)
|
|
{
|
|
if (this.auftragtyp != AuftragTyp.Regelmäßig)
|
|
{
|
|
Saison Saison = Saison.GetAktivSaison();
|
|
if (Saison.Bezeichnung == "Sommer") nextLiefertag = Funktionen.GetNextLiefertag((Liefertage)this.kunde.SommerLieferRhythmus);
|
|
if (Saison.Bezeichnung == "Winter") nextLiefertag = Funktionen.GetNextLiefertag((Liefertage)this.kunde.WinterLieferRhythmus);
|
|
if (Saison.Bezeichnung == "Zwischensaison")
|
|
{
|
|
meldung.GetInfo(this, "Achtung Liefertag kann falsch sein, da Zwischensaison ist.", false);
|
|
DateTime datum = DateTime.Today;
|
|
int tage = 2;
|
|
while (tage > 0)
|
|
{
|
|
datum = datum.AddDays(1);
|
|
if (datum.DayOfWeek != DayOfWeek.Saturday && datum.DayOfWeek != DayOfWeek.Sunday)
|
|
{
|
|
tage--;
|
|
}
|
|
}
|
|
nextLiefertag = datum;
|
|
|
|
}
|
|
}
|
|
comboBoxTyp_Load();
|
|
comboBoxFahrer_Load();
|
|
DatenLaden();
|
|
}
|
|
else
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
this.Close();
|
|
}
|
|
|
|
this.dGArtikel.ForeColor = Color.Black;
|
|
this.textBoxKundeName.Enabled = false;
|
|
this.textBoxKndNr.Enabled = false;
|
|
|
|
// RadioButtons und ComboBoxen laden.
|
|
if(this.kunde != null) Funktionen.Get_RadioButtons(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Kundendaten Liefertag werden eingefügt.
|
|
/// </summary>
|
|
private void DatenLaden()
|
|
{
|
|
this.textBoxKndNr.Text = kunde.KundeNummer;
|
|
if (string.IsNullOrWhiteSpace(kunde.Suchtext)) this.textBoxKundeName.Text = kunde.KundeName;
|
|
else this.textBoxKundeName.Text = kunde.Suchtext;
|
|
this.dTPLiefertag.Value = nextLiefertag;
|
|
this.textBoxCont.Text = "0";
|
|
|
|
dTPLiefertag_Leave(this.dTPLiefertag, EventArgs.Empty);
|
|
//textBoxCont_TextChanged(this.textBoxCont, EventArgs.Empty);
|
|
}
|
|
private void comboBoxTyp_Load()
|
|
{
|
|
try
|
|
{
|
|
this.SuspendLayout();
|
|
this.comboBoxTyp.SelectedValueChanged -= comboBoxTyp_SelectedValueChanged;
|
|
// Items werden von AuftragTyp geladen.
|
|
this.comboBoxTyp.DataSource = Enum.GetValues(typeof(AuftragTyp));
|
|
// Wenn der Kunde ein Geschäftskunde ist, wird AuftragTyp.Geschäft ausgewählt. Andernfalls wird der AuftragTyp aus dem Konstruktor gewählt.
|
|
|
|
this.comboBoxTyp.SelectedValueChanged += comboBoxTyp_SelectedValueChanged;
|
|
|
|
if (kunde.Service == "Geschäft") this.comboBoxTyp.SelectedItem = AuftragTyp.Geschäft;
|
|
else this.comboBoxTyp.SelectedItem = auftragtyp;
|
|
|
|
if (this.benutzer.Rolle == BenutzerRolle.Fahrer)
|
|
{
|
|
this.comboBoxTyp.Enabled = true;
|
|
}
|
|
else this.comboBoxTyp.Enabled = false;
|
|
this.ResumeLayout(false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
Program.AddFehler(this.benutzer, ex.Message, ex.StackTrace, null);
|
|
throw;
|
|
}
|
|
}
|
|
private void comboBoxFahrer_Load()
|
|
{
|
|
List<Benutzer> benutzerliste = Benutzer.GetFahrerList();
|
|
this.comboBoxFahrer.DataSource = benutzerliste;
|
|
this.comboBoxFahrer.DisplayMember = "BenutzerName";
|
|
|
|
if (this.benutzer.Rolle == BenutzerRolle.Fahrer) this.comboBoxFahrer.SelectedItem = this.benutzer;
|
|
else this.comboBoxFahrer.SelectedIndex = -1;
|
|
}
|
|
private void Load_Gridview(string kundeid, AuftragTyp auftragTyp)
|
|
{
|
|
|
|
List<KundeArtikel> artikelListe = KundeArtikel.GetList(kundeid);
|
|
|
|
//List<Sortiment> resultList = null;
|
|
//resultList = sortimentListe.FindAll(Sortiment => Sortiment.KundeNummer == kundeNr);
|
|
|
|
if (artikelListe.Count != 0)
|
|
{
|
|
this.dGArtikel.AutoGenerateColumns = false;
|
|
foreach (DataGridViewColumn col in this.dGArtikel.Columns)
|
|
{
|
|
col.DataPropertyName = col.Name;
|
|
|
|
if (col.Name.Contains("Bearbeitet")) col.Visible = false;
|
|
if (col.Name == "Fehlmenge")
|
|
{
|
|
if (auftragTyp == AuftragTyp.Inventur) col.Visible = true;
|
|
else col.Visible = false;
|
|
}
|
|
if (col.Name == "Korrektur")
|
|
{
|
|
if (auftragTyp >= AuftragTyp.Standerhöhung & auftragTyp <= AuftragTyp.Standverminderung) col.Visible = true;
|
|
else
|
|
{
|
|
if (auftragTyp == AuftragTyp.Inventur)
|
|
{
|
|
col.Visible = true;
|
|
col.Name = "Inventurausgleich";
|
|
}
|
|
else col.Visible = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// DataGridView mit ArtikelStand Liste verbinden und Columns automatisch generieren.
|
|
this.dGArtikel.DataSource = artikelListe;
|
|
|
|
this.dGArtikel.ClearSelection();
|
|
//this.dGArtikel.CurrentCell = this.dGArtikel.Rows[0].Cells[3];
|
|
|
|
// Alle Spaltenbreiten an den Zellinhalt anpassen
|
|
this.dGArtikel.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
|
this.dGArtikel.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
|
|
// Alle Zeilenhöhen an Zellinhalt anpassen
|
|
this.dGArtikel.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
|
|
this.dGArtikel.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCells);
|
|
|
|
int totalWidth = dGArtikel.RowHeadersVisible ? dGArtikel.RowHeadersWidth : 0;
|
|
foreach (DataGridViewColumn col in dGArtikel.Columns)
|
|
{
|
|
if (col.Visible) totalWidth += col.Width;
|
|
}
|
|
|
|
int totalHeight = dGArtikel.ColumnHeadersVisible ? dGArtikel.ColumnHeadersHeight : 0;
|
|
foreach (DataGridViewRow row in dGArtikel.Rows)
|
|
{
|
|
if (row.Visible) totalHeight += row.Height;
|
|
}
|
|
totalHeight += dGArtikel.ColumnHeadersHeight;
|
|
|
|
dGArtikel.ClientSize = new Size(totalWidth, totalHeight);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Button Click Events.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void buttonAbbrechen_Click(object sender, EventArgs e)
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
this.Close();
|
|
}
|
|
private void buttonSpeichern_Click(object sender, EventArgs e)
|
|
{
|
|
if (!this.ValidateChildren(ValidationConstraints.Enabled)) return;
|
|
|
|
int[] save;
|
|
if(kunde == null)
|
|
{
|
|
MessageBox.Show("Auftrag kann nicht gespeichert werden. Kein Kunde vorhanden.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
this.textBoxKndNr.Focus();
|
|
return;
|
|
}
|
|
else Auftrag = new Auftrag();
|
|
|
|
if (this.benutzer.Rolle == BenutzerRolle.Fahrer) { AuftragSpeichern(); return; }
|
|
if ((AuftragTyp)comboBoxTyp.SelectedItem == AuftragTyp.Regelmäßig) { RegAuftragSpeichern(); return; }
|
|
|
|
//AUFTRAG DATEN ÜBERGEBEN
|
|
Auftrag.KundeID = (int)kunde.KundeID;
|
|
|
|
// Wenn Kundennummer ist Div.Barzahler(in FormListe wenn mit ? am Anfang) wird individueller Kundename als Zusatzinfo gespeichert.
|
|
if (kunde.KundeNummer == "2320000") Auftrag.ZusatzInfo = string.IsNullOrWhiteSpace(kunde.Suchtext) ? kunde.KundeName : kunde.Suchtext;
|
|
else if (!string.IsNullOrWhiteSpace(eingabe)) Auftrag.ZusatzInfo = eingabe;
|
|
|
|
if (Auftrag.AufgabeID == null) { if (kunde.Aufgabe != null) Auftrag.AufgabeID = kunde.Aufgabe; }
|
|
Auftrag.Liefertag = this.dTPLiefertag.Value;
|
|
Auftrag.Container = int.Parse(this.textBoxCont.Text);
|
|
Auftrag.ErstelltVon = (int)this.benutzer.BenutzerID;
|
|
Auftrag.Erstellt = DateTime.Now;
|
|
Auftrag.Container = int.Parse(this.textBoxCont.Text);
|
|
Auftrag.Typ = (AuftragTyp)comboBoxTyp.SelectedItem;
|
|
Auftrag.ArbeiterID = this.comboBoxFahrer.SelectedIndex == -1 ? null : ((Benutzer)this.comboBoxFahrer.SelectedItem).BenutzerID;
|
|
if (maschine != null) Auftrag.MaschineID = (int)maschine.MaschineID;
|
|
else Auftrag.MaschineID = null;
|
|
|
|
if (Auftrag.FindeAuftrag(true).Gefunden) //TODO: Aufträge zusammenführen wenn gleicher Kunde und Liefertag.
|
|
{
|
|
if (meldung.AuftragVorhanden(Auftrag) == DialogResult.Yes)
|
|
{
|
|
|
|
if (benutzer.Rolle == BenutzerRolle.Verwaltung || benutzer.Rolle == BenutzerRolle.Admin) Auftrag.Status = AuftragStatus.Herrichten;
|
|
else Auftrag.Status = AuftragStatus.Abgeholt;
|
|
|
|
//Wenn SONDERAUFTRAG(STH,STV,STA) dann ARTIKEL speichern.
|
|
if (Auftrag.Typ >= AuftragTyp.Inventur & Auftrag.Typ <= AuftragTyp.Standverminderung)
|
|
{
|
|
int tosave = 0;
|
|
int saved = 0;
|
|
bool negieren = false;
|
|
foreach (DataGridViewRow artikel in this.dGArtikel.Rows)
|
|
{
|
|
tosave++;
|
|
KundeArtikel stand;
|
|
if (artikel.Cells[0].Value != null)
|
|
{
|
|
stand = KundeArtikel.GetItem(int.Parse(artikel.Cells[0].Value.ToString()));
|
|
if (artikel.Cells[5].Visible == true)
|
|
{
|
|
stand.Fehlmenge = int.Parse(artikel.Cells[5].Value.ToString());
|
|
stand.FehlmengeBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
|
}
|
|
if (artikel.Cells[6].Visible == true)
|
|
{
|
|
if (int.TryParse(artikel.Cells[6].Value.ToString(), out int result))
|
|
{
|
|
if (Auftrag.Typ == AuftragTyp.Standverminderung) negieren = true;
|
|
stand.Korrektur = (negieren && stand.Korrektur > 0) ? -result : result;
|
|
stand.KorrekturBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
|
}
|
|
else { meldung.Eingabefehler(); return; }
|
|
}
|
|
if (stand.Save() == 1) saved++;
|
|
}
|
|
}
|
|
//Kontrolle ob alle Artikel gespeichert wurden.
|
|
if (saved != tosave) meldung.Speicherfehler();
|
|
else
|
|
{
|
|
//Speichern von AUFTRAG
|
|
save = Auftrag.Save();
|
|
GetInventurCSV();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!extra)
|
|
{
|
|
if (Auftrag.Save()[1] == 1) this.Close();
|
|
}
|
|
else save = Auftrag.Save();
|
|
}
|
|
}
|
|
else { Auftrag = new Auftrag(); FormNeuerAuftrag_Load(this, e); return; }
|
|
}
|
|
else
|
|
{
|
|
switch (benutzer.Rolle)
|
|
{
|
|
case BenutzerRolle.Verwaltung:
|
|
Auftrag.Status = AuftragStatus.Herrichten;
|
|
break;
|
|
case BenutzerRolle.Fahrer:
|
|
Auftrag.Status = AuftragStatus.Abgeholt;
|
|
if (Auftrag.ArbeiterID == null) Auftrag.ArbeiterID = benutzer.BenutzerID;
|
|
break;
|
|
case BenutzerRolle.Admin:
|
|
Auftrag.Status = AuftragStatus.Herrichten;
|
|
break;
|
|
case BenutzerRolle.Waschstrasse:
|
|
Auftrag.Status = AuftragStatus.Aufgelegt;
|
|
break;
|
|
case BenutzerRolle.Master:
|
|
break;
|
|
case BenutzerRolle.Expedit:
|
|
Auftrag.Status = AuftragStatus.Gewaschen;
|
|
break;
|
|
case BenutzerRolle.Frottee:
|
|
break;
|
|
case BenutzerRolle.Flach:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
//Wenn SONDERAUFTRAG(STH,STV,STA) dann ARTIKEL speichern.
|
|
if (Auftrag.Typ >= AuftragTyp.Inventur & Auftrag.Typ <= AuftragTyp.Standverminderung)
|
|
{
|
|
int tosave = 0;
|
|
int saved = 0;
|
|
bool negieren = false;
|
|
foreach (DataGridViewRow artikel in this.dGArtikel.Rows)
|
|
{
|
|
tosave++;
|
|
KundeArtikel stand;
|
|
if (artikel.Cells[0].Value != null)
|
|
{
|
|
stand = KundeArtikel.GetItem(int.Parse(artikel.Cells[0].Value.ToString()));
|
|
if (artikel.Cells[5].Visible == true)
|
|
{
|
|
stand.Fehlmenge = int.Parse(artikel.Cells[5].Value.ToString());
|
|
stand.FehlmengeBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
|
}
|
|
if (artikel.Cells[6].Visible == true)
|
|
{
|
|
if (int.TryParse(artikel.Cells[6].Value.ToString(), out int result))
|
|
{
|
|
if (Auftrag.Typ == AuftragTyp.Standverminderung) negieren = true;
|
|
stand.Korrektur = (negieren && stand.Korrektur > 0) ? -result : result;
|
|
stand.KorrekturBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
|
}
|
|
else { meldung.Eingabefehler(); return; }
|
|
}
|
|
if (stand.Save() == 1) saved++;
|
|
}
|
|
}
|
|
//Kontrolle ob alle Artikel gespeichert wurden.
|
|
if (saved != tosave) meldung.Speicherfehler();
|
|
else
|
|
{
|
|
//Speichern von AUFTRAG
|
|
save = Auftrag.Save();
|
|
GetInventurCSV();
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!extra)
|
|
{
|
|
//this.fach.KundeID = Auftrag.KundeID;
|
|
//this.fach.Lieferdatum = Auftrag.Liefertag;
|
|
//this.fach.Liefertag = (Liefertag)Auftrag.Liefertag.DayOfWeek;
|
|
//if (extraAuftrag == null) { this.fach.ExtraAuftragID = null; this.fach.ExtraKundeID = null; }
|
|
//else { this.fach.ExtraAuftragID = extraAuftrag.AuftragID; this.fach.ExtraKundeID = extraAuftrag.KundeID; }
|
|
//this.fach.Gewaschen = (DateTime)Auftrag.Erstellt;
|
|
|
|
//FormFachBearbeiten fachbearb = new FormFachBearbeiten(this.Auftrag ,this.fach);
|
|
//if (fachbearb.ShowDialog() == DialogResult.OK)
|
|
//{
|
|
// this.fach = fachbearb.fach;
|
|
// //Speichern von AUFTRAG
|
|
// save = Auftrag.Save();
|
|
//}
|
|
//this.fach.AuftragID = Auftrag.AuftragID;
|
|
if (Auftrag.Save()[1] == 1) this.Close();
|
|
|
|
}
|
|
else save = Auftrag.Save();
|
|
}
|
|
}
|
|
|
|
if (this.benutzer.Rolle == BenutzerRolle.Fahrer)
|
|
{
|
|
this.Auftrag = null;
|
|
this.kunde = Funktionen.KundenAuswahl();
|
|
if (this.kunde != null) { DatenLaden(); return; }
|
|
}
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
|
|
}
|
|
|
|
private void AuftragUpdate()
|
|
{
|
|
//AUFTRAG DATEN ÜBERGEBEN
|
|
Auftrag.KundeID = (int)kunde.KundeID;
|
|
|
|
if (Auftrag.AufgabeID == null) { if (kunde.Aufgabe != null) Auftrag.AufgabeID = kunde.Aufgabe; }
|
|
Auftrag.Liefertag = this.dTPLiefertag.Value;
|
|
Auftrag.Container = int.Parse(this.textBoxCont.Text);
|
|
Auftrag.ErstelltVon = (int)this.benutzer.BenutzerID;
|
|
Auftrag.Erstellt = DateTime.Now;
|
|
if (!this.textBoxCont.Enabled) Auftrag.Container = int.Parse(this.textBoxCont.Text);
|
|
Auftrag.Typ = (AuftragTyp)comboBoxTyp.SelectedItem;
|
|
Auftrag.ArbeiterID = this.comboBoxFahrer.SelectedIndex == -1 ? null : ((Benutzer)this.comboBoxFahrer.SelectedItem).BenutzerID;
|
|
|
|
}
|
|
private void RegAuftragSpeichern()
|
|
{
|
|
//TODO: ArbeiterID muss gefunden werden. Eventuell suche Aufträge mit Kunden am selben Liefertag und Region.
|
|
AuftragUpdate();
|
|
Auftrag.ArbeiterID = Auftrag.FindeFahrerIDZuAuftrag(kunde, Auftrag.Liefertag);
|
|
Auftrag.Status = AuftragStatus.Herrichten;
|
|
Lieferrhythmen.Rhythmus = (RegRhythmen)this.comboBoxRhythmus.SelectedItem;
|
|
|
|
if (Auftrag.FindeAuftrag(false).Gefunden)
|
|
{
|
|
Auftrag auf = Auftrag.GetAuftrag(Auftrag.FindeAuftrag(false).auftragID);
|
|
List<AuftragArtikel> liste = AuftragArtikel.GetList(auf.AuftragID);
|
|
string output = string.Join(Environment.NewLine, liste.Select(a => $"{a.ArtikelName,-20} {a.Anzahl,4} Stk."));
|
|
if (MessageBox.Show($"Es wurde ein Auftrag von {kunde.Suchtext ?? kunde.KundeName} für {auf.Liefertag.ToShortDateString()}\nmit folgenden Artikeln gefunden:\n\n{output}\nGeplanter Rhythmus: {Lieferrhythmen.Rhythmus}\n\nMöchtest du den Auftrag als erledigt markieren?", "AUFTRAG GEFUNDEN", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
auf.Status = AuftragStatus.Erledigt;
|
|
|
|
foreach (AuftragArtikel art in liste) { art.Erledigt = true; art.Save(); }
|
|
if (auf.Save()[0] != 1) meldung.Speicherfehler();
|
|
}
|
|
else return;
|
|
}
|
|
|
|
if (Auftrag.Save()[0] != 1) meldung.Speicherfehler();
|
|
else
|
|
{
|
|
foreach (UCArtikel uca in this.fLPArtikel.Controls)
|
|
{
|
|
AuftragArtikel aufart = new AuftragArtikel()
|
|
{
|
|
AuftragID = Auftrag.AuftragID,
|
|
ArtikelID = ((Artikel)uca.Tag).ArtikelID,
|
|
Anzahl = uca.Anzahl,
|
|
Erledigt = false,
|
|
};
|
|
aufart.Save();
|
|
}
|
|
}
|
|
this.Close();
|
|
}
|
|
|
|
private void AuftragSpeichern()
|
|
{
|
|
//AUFTRAG DATEN ÜBERGEBEN
|
|
Auftrag.KundeID = (int)kunde.KundeID;
|
|
|
|
if (Auftrag.AufgabeID == null) { if (kunde.Aufgabe != null) Auftrag.AufgabeID = kunde.Aufgabe; }
|
|
Auftrag.Liefertag = this.dTPLiefertag.Value;
|
|
Auftrag.Container = int.Parse(this.textBoxCont.Text);
|
|
Auftrag.ErstelltVon = (int)this.benutzer.BenutzerID;
|
|
Auftrag.Erstellt = DateTime.Now;
|
|
Auftrag.Container = int.Parse(this.textBoxCont.Text);
|
|
Auftrag.Typ = (AuftragTyp)comboBoxTyp.SelectedItem;
|
|
Auftrag.ArbeiterID = this.comboBoxFahrer.SelectedIndex == -1 ? null : ((Benutzer)this.comboBoxFahrer.SelectedItem).BenutzerID;
|
|
Auftrag.Status = AuftragStatus.Abgeholt;
|
|
|
|
Tour tour = null;
|
|
do
|
|
{
|
|
tour = Tour.FindeTour(null, Auftrag.ArbeiterID, Auftrag.Liefertag);
|
|
if (tour == null) Funktionen.UpdateOrSaveTour(Auftrag.TourID, Auftrag);
|
|
|
|
} while (tour == null);
|
|
|
|
Auftrag.TourID = tour.TourID;
|
|
|
|
if (Auftrag.FindeAuftrag(false).Gefunden)
|
|
{
|
|
if (meldung.GetFrage(this, $"Der Auftrag {Kunde.GetKunde(null, Auftrag.KundeID, null).Suchtext} Liefertag {Auftrag.Liefertag.ToShortDateString()} ist bereits vorhanden.\nMöchtest du diesen bearbeiten?\n\n[JA] => Auftrag bearbeiten\n[NEIN] => Neuen Auftrag erstellen", false) == DialogResult.Yes)
|
|
{
|
|
Auftrag = Auftrag.GetAuftrag(Auftrag.FindeAuftrag(false).auftragID);
|
|
Auftrag.Container += int.Parse(this.textBoxCont.Text);
|
|
if (Auftrag.Save()[0] != 1) meldung.Speicherfehler();
|
|
else meldung.GetInfo(this, $"Der Auftrag wurde bearbeitet.\nBitte suche den Auftrag von {Kunde.GetKunde(null, Auftrag.KundeID, null).Suchtext} mit Liefertag {Auftrag.Liefertag.ToShortDateString()} und stelle deine Container dazu.\nVergiss nicht die Containeranzahl auf der Karte auszubessern.", false);
|
|
}
|
|
else
|
|
{
|
|
Auftrag.ZusatzInfo += " Auftrag 2";
|
|
if (Auftrag.Save()[0] != 1) meldung.Speicherfehler();
|
|
else meldung.GetInfo(this, "Der Auftrag wurde als neuer Auftrag gespeichert.\nBitte vermerke auf der Containerkarte, dass dieser Auftrag 'Auftrag 2' ist.\n\nSollte das nicht richtig sein, melde es deinem Vorgesetzten.", false);
|
|
}
|
|
}
|
|
else if (Auftrag.Save()[0] != 1) meldung.Speicherfehler();
|
|
|
|
if (this.benutzer.Rolle == BenutzerRolle.Fahrer)
|
|
{
|
|
this.Auftrag = null;
|
|
this.kunde = Funktionen.KundenAuswahl();
|
|
if (this.kunde != null) { DatenLaden(); return; }
|
|
else this.Close();
|
|
}
|
|
|
|
}
|
|
|
|
private void Container_Click(object sender, EventArgs e)
|
|
{
|
|
PictureBox pb = (PictureBox)sender;
|
|
int cont = int.Parse(this.textBoxCont.Text);
|
|
if (pb.Name.ToString().Contains("Plus")) cont++;
|
|
if (pb.Name.ToString().Contains("Minus")) cont--;
|
|
this.textBoxCont.Text = cont.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// CSV-Liste für Inventur erstellen.
|
|
/// Wenn Liste vorhanden werden Inventuren unten angehängt sonst wird Datei erstellt.
|
|
/// </summary>
|
|
private void GetInventurCSV()
|
|
{
|
|
Kunde _knd = Kunde.GetKunde(null, Auftrag.KundeID, null);
|
|
Benutzer _user = Benutzer.GetBenutzer(null, Auftrag.ErstelltVon);
|
|
|
|
string fileName = $"{_knd.KundeNummer}.csv"; // Immer gleiche Datei!
|
|
string inventurOrdner = ConfigurationManager.AppSettings["InventurPfad"] ?? "Inventur";
|
|
string csvPath = Path.Combine(Application.StartupPath, inventurOrdner, fileName);
|
|
|
|
// Prüfen ob Header schon existiert
|
|
bool headerExists = File.Exists(csvPath);
|
|
|
|
// Nur Header bei NEUER Datei
|
|
if (!headerExists)
|
|
{
|
|
var csv = new StringBuilder();
|
|
csv.AppendLine("=== INVENTUR INFO ===");
|
|
csv.AppendLine($"KundeNr: {_knd.KundeNummer}");
|
|
csv.AppendLine($"Kunde: {_knd.KundeName}");
|
|
csv.AppendLine(new string('=', 30));
|
|
csv.AppendLine();
|
|
csv.AppendLine("Erstellt am;Erstellt von;Liefertag;ArtikelNr;Bezeichnung;Stand;Fehlmenge;Korrektur;InventurDatum");
|
|
File.WriteAllText(csvPath, csv.ToString(), Encoding.UTF8);
|
|
}
|
|
|
|
// NEUE Artikel ANHÄNGEN (ohne Header)
|
|
var appendCsv = new StringBuilder();
|
|
|
|
foreach (DataGridViewRow row in this.dGArtikel.Rows.Cast<DataGridViewRow>()
|
|
.Where(row => row.Cells[0].Value != null))
|
|
{
|
|
appendCsv.AppendLine(string.Join(";", new object[]
|
|
{
|
|
Auftrag.Erstellt.Value.Date.ToString("yyyy-MM-dd"),
|
|
_user.Vorname + " " + _user.Nachname,
|
|
Auftrag.Liefertag.Date.ToString("yyyy-MM-dd"),
|
|
row.Cells[2].Value?.ToString().Replace(";", " ") ?? "",
|
|
row.Cells[3].Value?.ToString().Replace(";", " ") ?? "",
|
|
row.Cells[4].Value?.ToString() ?? "0",
|
|
row.Cells[5].Visible ? (row.Cells[5].Value?.ToString() ?? "0") : "",
|
|
row.Cells[6].Visible ? (row.Cells[6].Value?.ToString() ?? "0") : "",
|
|
}));
|
|
}
|
|
|
|
// ANHÄNGEN statt überschreiben
|
|
File.AppendAllText(csvPath, appendCsv.ToString(), Encoding.UTF8);
|
|
}
|
|
|
|
/// <summary>
|
|
/// TextBox Events
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void textBoxCont_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (this.textBoxCont.Text == "0") { this.pictureBoxMinus.Enabled = false; this.pictureBoxMinus.BackColor = Color.Gray; }
|
|
else { this.pictureBoxMinus.Enabled = true; this.pictureBoxMinus.BackColor = Color.Red; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Liefertag mit automatischer Berechnung des nächsten Datums bzw. des Wochentages des Datums.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void dTPLiefertag_Leave(object sender, EventArgs e)
|
|
{
|
|
foreach (RadioButton liefertag in this.Controls.OfType<RadioButton>())
|
|
{
|
|
if (liefertag.Name.Contains(((Liefertag)dTPLiefertag.Value.DayOfWeek).ToString())) liefertag.Checked = true;
|
|
}
|
|
}
|
|
private void Liefertag_rB_Checked(object sender, EventArgs e)
|
|
{
|
|
foreach (RadioButton radioButton in this.Controls.OfType<RadioButton>())
|
|
{
|
|
if (radioButton.Checked) radioButton.BackColor = Color.Yellow;
|
|
else { radioButton.BackColor = Color.Gray; }
|
|
}
|
|
}
|
|
private void Liefertag_rB_Click(object sender, EventArgs e)
|
|
{
|
|
RadioButton radioButton = (RadioButton)sender;
|
|
foreach(Liefertag tag in Enum.GetValues(typeof(Liefertag)))
|
|
{
|
|
if (radioButton.Name.Contains(tag.ToString())) this.dTPLiefertag.Value = Berechnungen.GetNextWeekday((int)tag);
|
|
}
|
|
//this.dTPLiefertag.Enabled = false;
|
|
}
|
|
private void dTPLiefertag_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
dTPLiefertag_Leave(sender, e);
|
|
}
|
|
|
|
private void textBoxKndNr_Click(object sender, EventArgs e)
|
|
{
|
|
this.textBoxKndNr.Clear();
|
|
//Process.Start("C:\\Windows\\WinSxS\\amd64_microsoft-windows-osk_31bf3856ad364e35_10.0.22621.3672_none_8a93c823d58f9d77\\osk.exe");
|
|
}
|
|
|
|
//Wenn der Kunde nicht gefunden wird und händisch eingegeben wird, wird beim verlassen der Textbox der Kunde als DIV ZIELKUNDE erstellt.
|
|
//Der individuelle Kundename wird als KUNDE.SUCHTEXT eingetragen aber nicht gespeichert.
|
|
private void textBoxKundeName_Leave(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(textBoxKundeName.Text))
|
|
{
|
|
kunde = Kunde.GetKunde("2300000", null, null);
|
|
kunde.Suchtext = this.textBoxKundeName.Text;
|
|
}
|
|
}
|
|
|
|
//Wenn mit TAB aus Textbox gesprungen wird, wird Focus auf TEXTBOX KUNDENAME gelegt. (Dadurch wird Fehlermeldung aktiviert)
|
|
private void textBoxKndNr_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
|
{
|
|
if (e.KeyValue == 9) textBoxKundeName.Focus();
|
|
}
|
|
|
|
private void DataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Überprüfen ob die Eingabe eine Zahl ist. Es wird sonst eine Meldung angezeigt und das weiterspringen wird verhindert.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void dGArtikel_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
|
|
{
|
|
if (e.ColumnIndex >= 5)
|
|
{
|
|
DataGridView dgv = (DataGridView)sender;
|
|
DataGridViewCell dgc = dgv.CurrentCell;
|
|
if (!int.TryParse(dgc.EditedFormattedValue.ToString(), out int i))
|
|
{
|
|
meldung.Eingabefehler();
|
|
e.Cancel = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void comboBoxTyp_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
if (this.benutzer.Rolle == BenutzerRolle.Fahrer)
|
|
{
|
|
if ((AuftragTyp)comboBoxTyp.SelectedValue != AuftragTyp.Standart & (AuftragTyp)comboBoxTyp.SelectedValue != AuftragTyp.AufAbruf)
|
|
{
|
|
meldung.GetFehler(this, "Unerlaubter AuftragTyp. Bitte wähle Standart oder AufAbruf.");
|
|
return;
|
|
}
|
|
}
|
|
switch ((AuftragTyp)comboBoxTyp.SelectedValue)
|
|
{
|
|
case AuftragTyp.Geschäft: // Wird derzeit wenig verwendet da die Auswahl in DatenLaden nach KundenService erfolgt.
|
|
this.dGArtikel.Enabled = this.dGArtikel.Visible = false;
|
|
this.Width = textBoxKundeName.Right + 30;
|
|
this.Height = 470;
|
|
break;
|
|
case AuftragTyp.Standart:
|
|
this.dGArtikel.Enabled = this.dGArtikel.Visible = false;
|
|
this.Width = textBoxKundeName.Right + 30;
|
|
this.Height = 470;
|
|
break;
|
|
case AuftragTyp.Inventur:
|
|
if (this.kunde != null) Load_Gridview(this.kunde.KundeID.ToString(), (AuftragTyp)comboBoxTyp.SelectedValue);
|
|
this.dGArtikel.Enabled = this.dGArtikel.Visible = true;
|
|
this.Width = this.dGArtikel.Right + 25;
|
|
this.Height = this.dGArtikel.Bottom + this.buttonSpeichern.Height + 60;
|
|
break;
|
|
case AuftragTyp.Standerhöhung:
|
|
if (this.kunde != null) Load_Gridview(this.kunde.KundeID.ToString(), (AuftragTyp)comboBoxTyp.SelectedValue);
|
|
this.dGArtikel.Enabled = this.dGArtikel.Visible = true;
|
|
this.Width = this.dGArtikel.Right + 25;
|
|
this.Height = this.dGArtikel.Bottom + this.buttonSpeichern.Height + 60;
|
|
break;
|
|
case AuftragTyp.Standverminderung:
|
|
if (this.kunde != null) Load_Gridview(this.kunde.KundeID.ToString(), (AuftragTyp)comboBoxTyp.SelectedValue);
|
|
this.dGArtikel.Enabled = this.dGArtikel.Visible = true;
|
|
this.Width = this.dGArtikel.Right + 25;
|
|
this.Height = this.dGArtikel.Bottom + this.buttonSpeichern.Height + 60;
|
|
break;
|
|
case AuftragTyp.Regelmäßig:
|
|
this.dGArtikel.Enabled = this.dGArtikel.Visible = false;
|
|
this.panelRegAuftrag.Enabled = this.panelRegAuftrag.Visible = true;
|
|
this.pictureBoxPlus.Enabled = this.pictureBoxMinus.Enabled = this.textBoxCont.Enabled = false;
|
|
this.Width = this.panelRegAuftrag.Right + 25;
|
|
this.Height = 470;
|
|
break;
|
|
case AuftragTyp.AufAbruf:
|
|
this.dGArtikel.Enabled = this.dGArtikel.Visible = false;
|
|
this.Width = textBoxKundeName.Right + 30;
|
|
this.Height = 470;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void comboBoxFahrer_Validating(object sender, CancelEventArgs e)
|
|
{
|
|
if (((ComboBox)sender).SelectedIndex == -1) return;
|
|
if (((Benutzer)((ComboBox)sender).SelectedItem).BenutzerID == this.benutzer.BenutzerID) return;
|
|
if (meldung.GetFrage(this, "Möchtest du den Auftrag wirklich einem anderen Fahrer zuteilen?", false) == DialogResult.No) { ((ComboBox)sender).SelectedIndex = -1; e.Cancel = true; }
|
|
else
|
|
{
|
|
eingabe = Interaction.InputBox("Warum möchtest du den Auftrag einem anderen Fahrer zuteilen?\n\nGrund:", "Sonderzuteilung", "");
|
|
eingabe += " / ";
|
|
}
|
|
}
|
|
|
|
private void buttonEinstellung_Click(object sender, EventArgs e)
|
|
{
|
|
FormKundeVW kundeVW = new FormKundeVW(this.kunde);
|
|
kundeVW.ShowDialog();
|
|
}
|
|
|
|
private void pictureBoxAddArtikel_Click(object sender, EventArgs e)
|
|
{
|
|
int index = 0;
|
|
int artAnzahl = 1;
|
|
string anzahl = string.Empty;
|
|
Artikel art = (Artikel)this.comboBoxArtikel.SelectedItem;
|
|
do
|
|
{
|
|
if (index > 0) MessageBox.Show("Bitte nur ganze Zahlen eingeben.", "ACHTUNG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
anzahl = Interaction.InputBox($"Wieviel Stück {art.Bezeichnung} sollen geliefert werden?\n\nStück:", "Artikelanzahl", "");
|
|
index++;
|
|
} while (!int.TryParse(anzahl, out artAnzahl));
|
|
|
|
|
|
UCArtikel uca = new UCArtikel(art, artAnzahl);
|
|
uca.Width = fLPArtikel.Width - 25;
|
|
uca.DeleteClicked += Uca_DeleteClicked;
|
|
this.fLPArtikel.Controls.Add(uca);
|
|
}
|
|
|
|
private void Uca_DeleteClicked(object sender, EventArgs e)
|
|
{
|
|
this.fLPArtikel.Controls.Remove((UCArtikel)sender);
|
|
}
|
|
|
|
private void panelRegAuftrag_EnabledChanged(object sender, EventArgs e)
|
|
{
|
|
Panel panel = sender as Panel;
|
|
int dropdownWidth = comboBoxArtikel.DropDownWidth;
|
|
if (panel.Enabled)
|
|
{
|
|
List<Artikel> artikelListe = Artikel.GetRegArtikelList();
|
|
comboBoxArtikel.DataSource = artikelListe;
|
|
comboBoxArtikel.DisplayMember = "Bezeichnung";
|
|
foreach (Artikel art in artikelListe)
|
|
{
|
|
int bezWidth = TextRenderer.MeasureText(art.Bezeichnung, comboBoxArtikel.Font).Width;
|
|
if (dropdownWidth < bezWidth) dropdownWidth = bezWidth;
|
|
}
|
|
comboBoxArtikel.DropDownWidth = dropdownWidth;
|
|
comboBoxArtikel.SelectedIndex = -1;
|
|
|
|
comboBoxRhythmus.DataSource = Enum.GetValues(typeof(RegRhythmen));
|
|
comboBoxRhythmus.SelectedIndex = -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//TODO: Form AuftragDetail muss überarbeitet werden.
|
|
//TODO: TourenListe Entwurf muss überarbeitet werden.
|
|
//TODO: Grund immer abfragen oder nur wenn Fahrer die Zuteilung ändert? |