777 lines
31 KiB
C#
777 lines
31 KiB
C#
using BrightIdeasSoftware;
|
|
using DatenDB;
|
|
using Deckungsbeitrag.AA_Forms;
|
|
using Deckungsbeitrag.AA_Klassen;
|
|
using Deckungsbeitrag.UserControls;
|
|
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.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Caching;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Forms.VisualStyles;
|
|
|
|
|
|
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 readonly Benutzer benutzer;
|
|
List<Sortiment> sortimentListe;
|
|
public DateTime? letzterLiefertag;
|
|
public DataGridViewCell aktivCell;
|
|
private readonly string userid;
|
|
private readonly AuftragTyp? auftragtyp = AuftragTyp.Standart;
|
|
private string eingabe = string.Empty;
|
|
private readonly OnboardingSchritt onBoardingArt = OnboardingSchritt.NeuerAuftrag;
|
|
string[] touren;
|
|
private Tour tour;
|
|
string kundeName = string.Empty;
|
|
|
|
#endregion
|
|
|
|
#region Form-Konstruktor
|
|
public FormNeuerAuftrag()
|
|
{
|
|
InitializeComponent();
|
|
this.Text += " Version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
|
|
}
|
|
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)
|
|
{
|
|
// SortimentListe holen
|
|
sortimentListe = Funktionen.SortimentLesen("Liste");
|
|
|
|
string kndService = string.Empty;
|
|
if (this.auftragtyp == AuftragTyp.Regelmäßig) {kndService = "Geschäft"; labelLiefertag.Text = "Erster Liefertag:"; }
|
|
if (this.benutzer.Rolle == BenutzerRolle.Fahrer) kndService = "Geschäft";
|
|
|
|
if (this.auftragtyp == null || this.auftragtyp == AuftragTyp.Geschäft) SonderDatenLaden(kndService);
|
|
else DatenLaden(kndService);
|
|
}
|
|
private async void FormNeuerAuftrag_HelpButtonClicked(object sender, CancelEventArgs e)
|
|
{
|
|
this.benutzer.OnboardingStatus = this.benutzer.ClearOnboardingFlag(onBoardingArt); // OnBoarding zurücksetzen
|
|
await this.benutzer.UpdateOnBoardingAsync(); // Update OnBoardingStatus
|
|
ZeigeOnboarding();
|
|
|
|
}
|
|
private void SonderDatenLaden(string kndService)
|
|
{
|
|
// Kunde laden
|
|
if (!GetKunde(kndService)) { CloseForm(DialogResult.Cancel); return; }
|
|
|
|
// ComboBox Typ & Fahrer wird mit Items geladen
|
|
ComboBoxTyp_Load();
|
|
ComboBoxFahrer_Load();
|
|
}
|
|
private void DatenLaden(string kndService)
|
|
{
|
|
this.SuspendLayout();
|
|
|
|
// Kunde laden
|
|
if (!GetKunde(kndService)) { CloseForm(DialogResult.Cancel); return; }
|
|
|
|
// Containeranzahl laden
|
|
CustomMessageBox messageBox = new CustomMessageBox($"Wieviel Container hast du beim Kunde {kundeName} abgeholt?", "CONTAINERANZAHL", "Containeranzahl", "isNumeric");
|
|
if (messageBox.ShowDialog() == DialogResult.OK)
|
|
{
|
|
this.textBoxCont.Text = messageBox.text.ToString();
|
|
}
|
|
else { CloseForm(DialogResult.Cancel); return; }
|
|
|
|
// NextLiefertag laden
|
|
GetNextLiefertag();
|
|
|
|
// ComboBox Typ & Fahrer wird mit Items geladen
|
|
ComboBoxTyp_Load();
|
|
ComboBoxFahrer_Load();
|
|
|
|
this.ResumeLayout();
|
|
}
|
|
private bool GetKunde(string kndService)
|
|
{
|
|
this.kunde = Funktionen.Open_List(kndService);
|
|
if (this.kunde == null) { CloseForm(DialogResult.Cancel); return false; }
|
|
|
|
this.textBoxKndNr.Text = kunde.KundeNummer;
|
|
this.kundeName = this.textBoxKundeName.Text = this.kunde.Suchtext ?? this.kunde.KundeName;
|
|
|
|
// Textboxen mit Kundedaten füllen
|
|
this.textBoxKundeName.Enabled = false;
|
|
this.textBoxKndNr.Enabled = false;
|
|
return true;
|
|
}
|
|
private void GetNextLiefertag()
|
|
{
|
|
DateTime nextLiefertag = DateTime.Today;
|
|
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);
|
|
// Wenn aktive Saison ist Zwischensaison, wird der Tourenplan angezeigt und die Auswahl von Liefertag(Datum) & Tour(Fahrer) übernommen.
|
|
if (Saison.Bezeichnung == "Zwischensaison")
|
|
{
|
|
var data = ShowTourenplan();
|
|
// Wenn ShowTourenplan null retour gibt, wird das Schließen der Form abgefragt.
|
|
if (data.datum == null)
|
|
{
|
|
if (MessageBox.Show("Möchtest du die Eingabe von Aufträgen beenden?", "FRAGE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
{
|
|
// Wenn trotzdem nicht geschlossen werden soll, wir die Info angezeigt, dass der Liefertag falsch sein kann.
|
|
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;
|
|
}
|
|
else
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
this.Close();
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Wenn ShowTourenplan Daten retour gibt, werden diese geladen.
|
|
nextLiefertag = (DateTime)data.datum;
|
|
tour = Tour.GetTour(Saison.SaisonId, data.tour);
|
|
}
|
|
}
|
|
|
|
if (this.auftragtyp == AuftragTyp.Regelmäßig) nextLiefertag = DateTime.Today.AddDays(1);
|
|
this.dTPLiefertag.Value = nextLiefertag;
|
|
|
|
// Die Wochentag RadioButtons werden geladen. Wichtig wenn der Tag null ist vor DTPLiefertag_Leave durchführen.
|
|
if (this.rBMO.Tag == null) Funktionen.Get_RadioButtons(this);
|
|
|
|
// Der Richtige RadioButton wird als aktiv markiert.
|
|
DTPLiefertag_Leave(this.dTPLiefertag, EventArgs.Empty);
|
|
}
|
|
private (DateTime? datum, string[] touren, string tour) ShowTourenplan()
|
|
{
|
|
FormShowUserControl showUserControl = new FormShowUserControl("Tourenplan", this.benutzer, this.kunde);
|
|
if (showUserControl.ShowDialog() == DialogResult.OK)
|
|
{
|
|
var data = showUserControl.lieferDaten;
|
|
return (data.datum, data.touren, data.text);
|
|
}
|
|
return (null, null, null);
|
|
}
|
|
|
|
#region ComboBox-Events
|
|
private void ComboBoxTyp_Load()
|
|
{
|
|
try
|
|
{
|
|
this.SuspendLayout();
|
|
this.comboBoxTyp.SelectedValueChanged -= ComboBoxTyp_SelectedValueChanged;
|
|
// Items werden von AuftragTyp geladen.
|
|
this.comboBoxTyp.DataSource = Enum.GetValues(typeof(AuftragTyp));
|
|
this.comboBoxTyp.DropDownWidth = GetDropDownWidth(this.comboBoxTyp);
|
|
// 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 (this.auftragtyp == null) this.comboBoxTyp.SelectedIndex = -1;
|
|
else
|
|
{
|
|
this.comboBoxTyp.SelectedItem = auftragtyp;
|
|
}
|
|
|
|
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()
|
|
{
|
|
Saison saison = Saison.GetAktivSaison();
|
|
this.comboBoxFahrer.Validating -= ComboBoxFahrer_Validating;
|
|
List<Tour> tourliste = Tour.GetSaisonListe(saison);
|
|
this.comboBoxFahrer.DataSource = tourliste;
|
|
this.comboBoxFahrer.DisplayMember = "Bezeichnung";
|
|
this.comboBoxFahrer.ValueMember = "TourID";
|
|
this.comboBoxFahrer.DropDownWidth = GetDropDownWidth(this.comboBoxFahrer);
|
|
// ComboBox-Auswahl vordefinieren.
|
|
if (this.benutzer.Rolle == BenutzerRolle.Fahrer)
|
|
{
|
|
this.comboBoxFahrer.SelectedValue = tour.TourID;
|
|
}
|
|
else this.comboBoxFahrer.SelectedIndex = -1;
|
|
this.comboBoxFahrer.Validating += ComboBoxFahrer_Validating;
|
|
}
|
|
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 Standard oder AufAbruf.");
|
|
this.comboBoxTyp.SelectedItem = AuftragTyp.Standart;
|
|
return;
|
|
}
|
|
}
|
|
if (comboBoxTyp.SelectedValue != null)
|
|
{
|
|
switch ((AuftragTyp)comboBoxTyp.SelectedValue)
|
|
{
|
|
case AuftragTyp.Geschäft: // Wird derzeit wenig verwendet da die Auswahl in DatenLaden nach KundenService erfolgt.
|
|
this.pictureBoxPlus.Enabled = this.pictureBoxMinus.Enabled = this.textBoxCont.Enabled = true;
|
|
this.Width = textBoxKundeName.Right + 30;
|
|
this.Height = 470;
|
|
break;
|
|
case AuftragTyp.Standart:
|
|
this.pictureBoxPlus.Enabled = this.pictureBoxMinus.Enabled = this.textBoxCont.Enabled = true;
|
|
this.Width = textBoxKundeName.Right + 30;
|
|
this.Height = 470;
|
|
break;
|
|
case AuftragTyp.Inventur:
|
|
this.textBoxText.Visible = false;
|
|
this.DialogResult = DialogResult.Abort;
|
|
this.Close();
|
|
break;
|
|
case AuftragTyp.SOLL_Erhoehung:
|
|
if (this.kunde == null) return;
|
|
this.textBoxText.Visible = false;
|
|
this.panelRegAuftrag.Enabled = this.panelRegAuftrag.Visible = true;
|
|
this.pictureBoxPlus.Enabled = this.pictureBoxMinus.Enabled = this.textBoxCont.Enabled = false;
|
|
this.labelText.Text = "Rhythmus:";
|
|
this.Width = this.panelRegAuftrag.Right + 25;
|
|
this.Height = 470;
|
|
break;
|
|
case AuftragTyp.SOLL_Verminderung:
|
|
if (this.kunde == null) return;
|
|
this.textBoxText.Visible = false;
|
|
this.panelRegAuftrag.Enabled = this.panelRegAuftrag.Visible = true;
|
|
this.pictureBoxPlus.Enabled = this.pictureBoxMinus.Enabled = this.textBoxCont.Enabled = false;
|
|
this.labelText.Text = "Rhythmus:";
|
|
this.Width = this.panelRegAuftrag.Right + 25;
|
|
this.Height = 470;
|
|
break;
|
|
case AuftragTyp.Regelmäßig:
|
|
this.textBoxText.Visible = false;
|
|
this.panelRegAuftrag.Enabled = this.panelRegAuftrag.Visible = true;
|
|
this.pictureBoxPlus.Enabled = this.pictureBoxMinus.Enabled = this.textBoxCont.Enabled = false;
|
|
this.labelText.Text = "Rhythmus:";
|
|
this.Width = this.panelRegAuftrag.Right + 25;
|
|
this.Height = 470;
|
|
break;
|
|
case AuftragTyp.AufAbruf:
|
|
this.pictureBoxPlus.Enabled = this.pictureBoxMinus.Enabled = this.textBoxCont.Enabled = true;
|
|
this.Width = textBoxKundeName.Right + 30;
|
|
this.Height = 470;
|
|
break;
|
|
case AuftragTyp.Laufzettel:
|
|
this.panelRegAuftrag.Enabled = this.panelRegAuftrag.Visible = true;
|
|
this.textBoxText.Visible = true;
|
|
this.pictureBoxPlus.Enabled = this.pictureBoxMinus.Enabled = this.textBoxCont.Enabled = false;
|
|
this.labelText.Text = "Laufzetteltext:";
|
|
this.Width = this.panelRegAuftrag.Right + 25;
|
|
this.Height = 470;
|
|
this.textBoxText.BringToFront();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
PanelRegAuftrag_EnabledChanged(this.panelRegAuftrag, null);
|
|
}
|
|
else
|
|
{
|
|
this.Width = textBoxKundeName.Right + 30;
|
|
this.Height = 470;
|
|
}
|
|
}
|
|
private void ComboBoxArtikel_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
int index = 0;
|
|
int artAnzahl = 1;
|
|
string anzahl = string.Empty;
|
|
UCArtikel uca;
|
|
var art = this.comboBoxArtikel.SelectedItem;
|
|
do
|
|
{
|
|
if (index > 0) if (MessageBox.Show("Bitte nur ganze Zahlen eingeben.", "ACHTUNG", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return;
|
|
anzahl = Interaction.InputBox($"Wieviel Stück sollen geliefert oder eingezogen werden?\n\nStück:", "Artikelanzahl", "");
|
|
index++;
|
|
} while (!int.TryParse(anzahl, out artAnzahl));
|
|
|
|
if (art is Artikel artikel) uca = new UCArtikel(artikel, artAnzahl);
|
|
else uca = new UCArtikel((KundeArtikel)art, artAnzahl);
|
|
uca.Width = fLPArtikel.Width - 25;
|
|
uca.DeleteClicked += Uca_DeleteClicked;
|
|
this.fLPArtikel.Controls.Add(uca);
|
|
}
|
|
private void ComboBoxFahrer_Validating(object sender, CancelEventArgs e)
|
|
{
|
|
ComboBox cb = sender as ComboBox;
|
|
if (cb.SelectedIndex == -1) return;
|
|
if (tour != null && (cb.SelectedItem is Tour selected && selected.TourID == tour.TourID)) return;
|
|
if (this.benutzer.Rolle == BenutzerRolle.Verwaltung || this.benutzer.Rolle == BenutzerRolle.Admin || this.benutzer.Rolle == BenutzerRolle.Expedit) return;
|
|
if (meldung.GetFrage(this, "Möchtest du den Auftrag wirklich einer anderen Tour 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", "");
|
|
if (string.IsNullOrWhiteSpace(eingabe)) e.Cancel = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ComboBox Artikel & Rhythmus wird geladen.
|
|
/// Je nach AuftragTyp werden verschiedene Items in die ComboBoxen geladen.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void PanelRegAuftrag_EnabledChanged(object sender, EventArgs e)
|
|
{
|
|
comboBoxArtikel.SelectedIndexChanged -= ComboBoxArtikel_SelectedIndexChanged;
|
|
|
|
Panel panel = sender as Panel;
|
|
int dropdownWidth = comboBoxArtikel.DropDownWidth;
|
|
if (panel.Enabled)
|
|
{
|
|
if ((AuftragTyp)comboBoxTyp.SelectedValue == AuftragTyp.Regelmäßig)
|
|
{
|
|
List<Artikel> artikelListe;
|
|
if ((AuftragTyp)comboBoxTyp.SelectedValue == AuftragTyp.Regelmäßig) artikelListe = Artikel.GetRegArtikelList();
|
|
else artikelListe = Artikel.GetArtikelList("Alle");
|
|
if (artikelListe.Count == 0)
|
|
{
|
|
MessageBox.Show("Auswahl für den gewählten Kunden nicht verfügbar.", "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
this.comboBoxTyp.SelectedIndex = -1;
|
|
return;
|
|
}
|
|
|
|
comboBoxArtikel.DataSource = artikelListe;
|
|
comboBoxArtikel.DisplayMember = "ComboBoxAnzeige";
|
|
comboBoxArtikel.DropDownWidth = GetDropDownWidth(comboBoxArtikel);
|
|
comboBoxArtikel.SelectedIndex = -1;
|
|
|
|
comboBoxRhythmus.DataSource = Enum.GetValues(typeof(RegRhythmen));
|
|
comboBoxRhythmus.SelectedIndex = -1;
|
|
comboBoxRhythmus.Enabled = true;
|
|
}
|
|
if ((AuftragTyp)comboBoxTyp.SelectedValue == AuftragTyp.SOLL_Erhoehung || (AuftragTyp)comboBoxTyp.SelectedValue == AuftragTyp.SOLL_Verminderung || (AuftragTyp)comboBoxTyp.SelectedValue == AuftragTyp.IST_Erhoehung)
|
|
{
|
|
List<KundeArtikel> kndartikel = KundeArtikel.GetList(this.kunde.KundeID.ToString());
|
|
if (kndartikel.Count == 0)
|
|
{
|
|
MessageBox.Show("Auswahl für den gewählten Kunden nicht verfügbar.", "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
this.comboBoxTyp.SelectedIndex = -1;
|
|
return;
|
|
}
|
|
comboBoxArtikel.DataSource = kndartikel;
|
|
comboBoxArtikel.DisplayMember = "ComboBoxAnzeige";
|
|
comboBoxArtikel.DropDownWidth = GetDropDownWidth(comboBoxArtikel);
|
|
comboBoxArtikel.SelectedIndex = -1;
|
|
|
|
comboBoxRhythmus.Enabled = false;
|
|
}
|
|
}
|
|
|
|
comboBoxArtikel.SelectedIndexChanged += ComboBoxArtikel_SelectedIndexChanged;
|
|
}
|
|
private int GetDropDownWidth(ComboBox cb)
|
|
{
|
|
int maxLenght = 0;
|
|
foreach (object item in cb.Items)
|
|
{
|
|
int bezWidth = TextRenderer.MeasureText(cb.GetItemText(item), cb.Font).Width;
|
|
if (maxLenght < bezWidth) maxLenght = bezWidth;
|
|
}
|
|
return maxLenght;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Click Events
|
|
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;
|
|
|
|
if(this.kunde == null)
|
|
{
|
|
MessageBox.Show("Auftrag kann nicht gespeichert werden. Kein Kunde vorhanden.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
this.textBoxKndNr.Focus();
|
|
return;
|
|
}
|
|
|
|
this.Auftrag = Aktualisieren(kunde);
|
|
|
|
// Wenn Fahrer den Auftrag speichert
|
|
if (this.benutzer.Rolle == BenutzerRolle.Fahrer) { FahrerAuftraegeSpeichern(this.Auftrag); return; }
|
|
|
|
// Wenn Expedit/Waschstrasse/Verwaltung/Admin den Auftrag speichert
|
|
switch ((AuftragTyp)comboBoxTyp.SelectedItem)
|
|
{
|
|
case AuftragTyp.SOLL_Erhoehung: SpezialAuftragSpeichern(Auftrag);
|
|
return;
|
|
case AuftragTyp.SOLL_Verminderung: SpezialAuftragSpeichern(Auftrag);
|
|
return;
|
|
case AuftragTyp.Regelmäßig: SpezialAuftragSpeichern(Auftrag);
|
|
return;
|
|
case AuftragTyp.IST_Erhoehung: SpezialAuftragSpeichern(Auftrag);
|
|
return;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
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;
|
|
}
|
|
else { this.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;
|
|
}
|
|
|
|
Auftrag.Save();
|
|
}
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
private void ButtonEinstellung_Click(object sender, EventArgs e)
|
|
{
|
|
FormKundeVW kundeVW = new FormKundeVW(this.kunde);
|
|
kundeVW.ShowDialog();
|
|
}
|
|
private void Uca_DeleteClicked(object sender, EventArgs e)
|
|
{
|
|
this.fLPArtikel.Controls.Remove((UCArtikel)sender);
|
|
}
|
|
private void PictureBoxAddArtikel_Click(object sender, EventArgs e)
|
|
{
|
|
int index = 0;
|
|
int artAnzahl = 1;
|
|
string artname = string.Empty;
|
|
string anzahl = string.Empty;
|
|
UCArtikel uca;
|
|
|
|
artname = Interaction.InputBox($"Möchtest du einen individuellen Artikel eingeben?\n\nArtikelname:", "ARTIKELNAME WÄHLEN", "");
|
|
if (!string.IsNullOrWhiteSpace(artname))
|
|
{
|
|
do
|
|
{
|
|
if (index > 0) if (MessageBox.Show("Bitte nur ganze Zahlen eingeben.", "ACHTUNG", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return;
|
|
anzahl = Interaction.InputBox($"Wieviel Stück sollen geliefert werden?\n\nStück:", "Artikelanzahl", "");
|
|
index++;
|
|
} while (!int.TryParse(anzahl, out artAnzahl));
|
|
}
|
|
|
|
var art = new Artikel()
|
|
{
|
|
Bezeichnung = artname,
|
|
Nummer = 0000
|
|
};
|
|
|
|
uca = new UCArtikel(art, artAnzahl)
|
|
{
|
|
Width = fLPArtikel.Width - 25
|
|
};
|
|
uca.DeleteClicked += Uca_DeleteClicked;
|
|
this.fLPArtikel.Controls.Add(uca);
|
|
}
|
|
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();
|
|
}
|
|
#endregion
|
|
|
|
private Auftrag Aktualisieren(Kunde knd)
|
|
{
|
|
DateTime liefertag;
|
|
string zusatz = string.Empty;
|
|
|
|
// ZusatzInfo wird geladen.
|
|
// Wenn textBoxText wurde eingetragen (Auftrag Laufzettel)
|
|
if (!string.IsNullOrWhiteSpace(textBoxText.Text)) zusatz = textBoxText.Text;
|
|
// Wenn Kundennummer ist Div.Barzahler(in FormListe wenn mit ? am Anfang) wird individueller Kundename eingetrage
|
|
// Wenn Fahrerwechsel durchgeführt wird Grund eingetragen
|
|
if (knd.KundeNummer == "2320000") zusatz += string.IsNullOrWhiteSpace(knd.Suchtext) ? "Kunde: " + knd.KundeName : "Kunde: " + knd.Suchtext;
|
|
else if (!string.IsNullOrWhiteSpace(eingabe)) zusatz += "Fahrerwechsel: " + eingabe;
|
|
|
|
Tour selectedTour = this.comboBoxFahrer.SelectedIndex == -1 ? null : (Tour)this.comboBoxFahrer.SelectedItem;
|
|
|
|
Auftrag _auftrag = new Auftrag
|
|
{
|
|
AuftragID = this.Auftrag?.AuftragID,
|
|
KundeID = (int)knd.KundeID,
|
|
AufgabeID = knd.Aufgabe != null ? knd.Aufgabe : null,
|
|
Liefertag = liefertag = this.dTPLiefertag.Value,
|
|
Container = int.TryParse(this.textBoxCont.Text, out int i) ? i : 0,
|
|
ErstelltVon = (int)this.benutzer.BenutzerID,
|
|
Erstellt = DateTime.Now,
|
|
Typ = (AuftragTyp)comboBoxTyp.SelectedItem,
|
|
Abteilungen = AbteilungsStatus.Keine,
|
|
Status = this.benutzer.Rolle == BenutzerRolle.Fahrer ? AuftragStatus.Abgeholt : AuftragStatus.Herrichten, // Wenn Fahrer Auftrag erstellt dann abgeholt sonst Herrichten.
|
|
Rhythmus = this.comboBoxRhythmus.Enabled ? (RegRhythmen)this.comboBoxRhythmus.SelectedItem : RegRhythmen.Unbekannt, // Wenn Rhythmus ist nicht Enabled dann RegRhythmus Unbekannt.
|
|
TourID = selectedTour?.TourID, // Wenn Tour hinterlegt dann TourID speichern.
|
|
ArbeiterID = selectedTour?.BenutzerID, // Wenn Tour hinterlegt dann BenutzerID der Tour speichern. KANN AUCH null SEIN!!
|
|
Priority = selectedTour == null ? Priority.None : selectedTour.Priority, // Wenn Tour hinterlegt dann Priority der Tour speichern.
|
|
ZusatzInfo = zusatz,
|
|
};
|
|
|
|
return _auftrag;
|
|
}
|
|
//private int? GetTour(int? arbeiterID, DateTime liefertag)
|
|
//{
|
|
// Tour tour;
|
|
// do
|
|
// {
|
|
// tour = Tour.FindeTour(null, arbeiterID, liefertag);
|
|
// if (tour == null) Funktionen.UpdateOrSaveTour(Auftrag.TourID, Auftrag);
|
|
|
|
// } while (tour == null);
|
|
|
|
// return tour.TourID;
|
|
//}
|
|
private void SpezialAuftragSpeichern(Auftrag Auftrag)
|
|
{
|
|
if (Auftrag.FindeAuftrag(true).Gefunden)
|
|
{
|
|
int aufID = Auftrag.FindeAuftrag(false).auftragID;
|
|
Auftrag auf = Auftrag.GetAuftrag(aufID);
|
|
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:d}\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)
|
|
{
|
|
int? id;
|
|
string artname;
|
|
if (uca.Tag != null)
|
|
{
|
|
if (uca.Tag is Artikel artikel)
|
|
{
|
|
id = artikel.ArtikelID;
|
|
artname = artikel.Nummer + artikel.Bezeichnung;
|
|
}
|
|
else
|
|
{
|
|
id = ((KundeArtikel)uca.Tag).ArtikelID;
|
|
artname = ((KundeArtikel)uca.Tag).ArtikelNR + ((KundeArtikel)uca.Tag).ArtikelName;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
id = null;
|
|
artname = uca.ArtikelName.ToString();
|
|
}
|
|
AuftragArtikel aufart = new AuftragArtikel()
|
|
{
|
|
AuftragID = Auftrag.AuftragID,
|
|
ArtikelID = id,
|
|
ArtikelName = artname,
|
|
Anzahl = uca.Anzahl,
|
|
Erledigt = false,
|
|
Gesamt = uca.Anzahl,
|
|
};
|
|
aufart.Save();
|
|
}
|
|
}
|
|
this.Close();
|
|
}
|
|
private void FahrerAuftraegeSpeichern(Auftrag Auftrag)
|
|
{
|
|
if (Auftrag.FindeAuftrag(false).Gefunden)
|
|
{
|
|
if (meldung.GetFrage(this, $"Der Auftrag {Kunde.GetKunde(null, Auftrag.KundeID, null).Suchtext} Liefertag {Auftrag.Liefertag:d} 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:d} 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;
|
|
DatenLaden(string.Empty);
|
|
}
|
|
}
|
|
|
|
/// <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; }
|
|
}
|
|
|
|
#region GetLiefertag etc.
|
|
/// <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);
|
|
}
|
|
#endregion
|
|
private async void ZeigeOnboarding()
|
|
{
|
|
if (this.benutzer.IstGesehen(onBoardingArt)) return; // Bereits fertig
|
|
|
|
if (Program.ShowOnBoarding(this.benutzer.Rolle.ToString(), onBoardingArt) == DialogResult.OK)
|
|
{
|
|
// Nächster Schritt → Flag setzen
|
|
this.benutzer.OnboardingStatus = this.benutzer.SetOnboardingFlag(onBoardingArt);
|
|
await this.benutzer.UpdateOnBoardingAsync(); // Deine Update-Methode
|
|
//this.Close(); // Onboarding beendet
|
|
}
|
|
}
|
|
private void TextBoxText_VisibleChanged(object sender, EventArgs e)
|
|
{
|
|
if (textBoxText.Visible)
|
|
{
|
|
foreach (Control ctr in this.panelRegAuftrag.Controls) if (!ctr.Name.Contains("Text")) ctr.Enabled = false;
|
|
}
|
|
else foreach (Control ctr in this.panelRegAuftrag.Controls) if (!ctr.Name.Contains("Text")) ctr.Enabled = true;
|
|
}
|
|
private void CloseForm(DialogResult result)
|
|
{
|
|
this.DialogResult = result;
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|
|
//CHANGES: Es kann ab jetzt Morgen als Liefertag gewählt werden.
|
|
//CHANGES: Auftrag LAUFZETTEL (ehem. Einmalig) läuft als Sonderauftrag also Tab-Sonderaufträge.
|
|
//CHANGES: Der Text des LAUFZETTELS wird bei Expedit im InfoFeld angezeigt.
|
|
//CHANGES: DropDownWidth wird an das größte Item angepasst. |