909 lines
33 KiB
C#
909 lines
33 KiB
C#
using BrightIdeasSoftware;
|
||
using DatenDB;
|
||
using Deckungsbeitrag.AA_Klassen;
|
||
using Deckungsbeitrag.UserControls;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Configuration;
|
||
using System.Data;
|
||
using System.Diagnostics.Eventing.Reader;
|
||
using System.Drawing;
|
||
using System.Drawing.Printing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Web;
|
||
using System.Windows.Forms;
|
||
using ZXing;
|
||
|
||
namespace Deckungsbeitrag
|
||
{
|
||
public partial class FormAuftragDetail : Form
|
||
{
|
||
private Dictionary<int, int[]> dictionary = new Dictionary<int, int[]>();
|
||
private Dictionary<int, int> auftragDictionary = new Dictionary<int, int>();
|
||
public Auftrag auftrag;
|
||
public Benutzer benutzer;
|
||
public List<AuftragArtikel> artikelList;
|
||
public Meldungen meldung = new Meldungen();
|
||
private UCFeedback fb;
|
||
public Kunde kunde;
|
||
private int diff = 0;
|
||
int[] bestand; // Reklamation/Fehlmenge/Standveränderung/Inventurausgleich
|
||
bool etikettgedruckt = false;
|
||
bool zahlenChanged = false;
|
||
bool infoOpen = false;
|
||
private Saison saison = Saison.GetAktivSaison();
|
||
|
||
|
||
//WENN AUFTRAG SPEICHERN
|
||
private bool _tosave = false;
|
||
public bool Tosave
|
||
{
|
||
get { return _tosave; }
|
||
set
|
||
{
|
||
_tosave = value;
|
||
if (_tosave)
|
||
{
|
||
buttonFertig.Enabled = true;
|
||
buttonFertig.BackColor = Color.FromArgb(0,192,0);
|
||
}
|
||
}
|
||
}
|
||
|
||
//WENN AUFTRAG ABZUSCHLIESSEN
|
||
private bool _toclose = false;
|
||
private List<KundeArtikel> kndartListe;
|
||
|
||
public bool Toclose
|
||
{
|
||
get { return _toclose; }
|
||
set
|
||
{
|
||
_toclose = value;
|
||
if (_toclose)
|
||
{
|
||
buttonFertig.Enabled = true;
|
||
buttonFertig.BackColor = Color.FromArgb(0, 192, 0);
|
||
}
|
||
}
|
||
}
|
||
|
||
public FormAuftragDetail()
|
||
{
|
||
InitializeComponent();
|
||
//this.BackColor = Properties.Settings.Default.Wirlblau;
|
||
LabelContainer_TextChanged(this.labelContainer, EventArgs.Empty);
|
||
|
||
}
|
||
public FormAuftragDetail(Auftrag auftrag, Benutzer benutzer) : this()
|
||
{
|
||
this.auftrag = auftrag;
|
||
this.benutzer = benutzer;
|
||
}
|
||
public FormAuftragDetail(Auftrag auftrag, Benutzer benutzer, List<KundeArtikel> kndartListe) : this(auftrag, benutzer)
|
||
{
|
||
this.kndartListe = kndartListe;
|
||
}
|
||
|
||
private void FormAuftragDetail_Load(object sender, EventArgs e)
|
||
{
|
||
LadeComboBoxen();
|
||
this.Text = this.auftrag.Typ.ToString() + "-Auftrag";
|
||
this.kunde = Kunde.GetKunde(string.Empty, auftrag.KundeID, string.Empty);
|
||
|
||
this.dTPLiefertag.Value = auftrag.Liefertag < DateTime.Today ? DateTime.Today.Date.AddDays(1) : auftrag.Liefertag;
|
||
this.labelKundeName.Text = string.IsNullOrWhiteSpace(this.kunde.Suchtext) ? this.kunde.KundeName : this.kunde.Suchtext;
|
||
this.labelRegion.Text = this.kunde.Region;
|
||
this.labelContainer.Text = auftrag.ContainerClean.ToString();
|
||
this.labelContDirt.Text = auftrag.Container.ToString();
|
||
this.textBoxZusatz.Text = $"{auftrag.ZusatzInfo}\n{this.kunde.Anmerkung}\n{Aufgabe.GetAufgabe(null, this.kunde.Aufgabe).Bezeichnung}";
|
||
//if (auftrag.Fahrer == null) this.comboBoxFahrer.SelectedIndex = -1;
|
||
//else this.comboBoxFahrer.SelectedValue = auftrag.Fahrer;
|
||
if (auftrag.TourID == null) this.comboBoxFahrer.SelectedIndex = -1;
|
||
else this.comboBoxFahrer.SelectedValue = auftrag.TourID;
|
||
this.comboBoxPriority.SelectedItem = auftrag.Priority;
|
||
|
||
// Events nach dem Laden der Daten wieder den ComboBoxen zuweisen.
|
||
this.comboBoxPriority.SelectedValueChanged += ComboBox_SelectedValueChanged;
|
||
this.comboBoxFahrer.SelectedValueChanged += ComboBox_SelectedValueChanged;
|
||
|
||
switch (this.auftrag.Typ)
|
||
{
|
||
case AuftragTyp.Inventur:
|
||
{
|
||
Load_OLV();
|
||
//if (this.auftrag.Status == AuftragStatus.Herrichten) Load_OLV();
|
||
//else
|
||
//{
|
||
// if (this.auftrag.Status == AuftragStatus.Warten)
|
||
// {
|
||
// buttonFertig.Visible = false; //TODO: Speichern der Inventur prüfen wenn Button nicht Visible ist.
|
||
// Load_UCInventur(this.auftrag);
|
||
// }
|
||
//}
|
||
}
|
||
break;
|
||
case AuftragTyp.SOLL_Erhoehung: Load_OLV();
|
||
break;
|
||
case AuftragTyp.IST_Erhoehung:
|
||
{
|
||
if (this.kndartListe == null) Load_OLV();
|
||
else Load_NWAusgleich();
|
||
}
|
||
break;
|
||
case AuftragTyp.SOLL_Verminderung: Load_OLV();
|
||
break;
|
||
case AuftragTyp.Regelmäßig: Load_OLV();
|
||
break;
|
||
case AuftragTyp.Laufzettel: Load_Laufzettel();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
|
||
if (this.oLVArtikel.Visible)
|
||
{
|
||
if (this.oLVArtikel.Items.Count == this.oLVArtikel.CheckedItems.Count) Toclose = true;
|
||
this.ClientSize = new Size(this.oLVArtikel.Right + 10, this.ClientSize.Height);
|
||
}
|
||
else this.ClientSize = new Size(this.textBoxZusatz.Right + 10, this.ClientSize.Height);
|
||
}
|
||
|
||
private void Load_NWAusgleich()
|
||
{
|
||
Generator.GenerateColumns(this.oLVArtikel, typeof(KundeArtikel), true);
|
||
this.oLVArtikel.SetObjects(kndartListe);
|
||
|
||
foreach (OLVColumn column in this.oLVArtikel.AllColumns)
|
||
{
|
||
switch (column.AspectName)
|
||
{
|
||
case var t when t == "Korrektur":
|
||
column.IsEditable = true;
|
||
break;
|
||
case var t when t == "Reihung":
|
||
this.oLVArtikel.Sort(column);
|
||
break;
|
||
default:
|
||
column.IsEditable = false;
|
||
break;
|
||
}
|
||
}
|
||
this.oLVArtikel.ShowGroups = false;
|
||
this.oLVArtikel = Funktionen.Columns_Resize(null, this.oLVArtikel).olv;
|
||
}
|
||
|
||
private void Load_UCInventur(Auftrag _auftrag)
|
||
{
|
||
Point loc = this.oLVArtikel.Location;
|
||
this.oLVArtikel.Visible = false;
|
||
string loadPath = Path.Combine(ConfigurationManager.AppSettings["DateiSavePfad"], "Listen\\Inventuren") ?? "Inventuren";
|
||
if (ConfigurationManager.AppSettings["ConnectionString"].Split(';')[4].Split('=')[1] == "Test_Wirl") loadPath = Path.Combine(ConfigurationManager.AppSettings["DateiSavePfad"], "Test\\Inventuren") ?? "Inventuren";
|
||
|
||
|
||
// Alle "Herrichten" Inventur Files auflisten.
|
||
string[] invFiles = Directory.GetFiles(loadPath, $"Warten-{_auftrag.AuftragID.ToString()}*.csv");
|
||
if (invFiles.Length == 0) return;
|
||
if (invFiles.Length > 1) { MessageBox.Show("Es wurden mehr Inventuren gefunden. Besprich das mit deinem Vorgesetzten.", "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
|
||
string[] lines = File.ReadAllLines(Path.Combine(loadPath, invFiles[0]), Encoding.UTF8);
|
||
}
|
||
private void Load_OLV()
|
||
{
|
||
Generator.GenerateColumns(this.oLVArtikel, typeof(AuftragArtikel), true);
|
||
|
||
this.artikelList = AuftragArtikel.GetList(auftrag.AuftragID);
|
||
|
||
this.oLVArtikel.SetObjects(this.artikelList);
|
||
this.oLVArtikel = Funktionen.Columns_Resize(null, this.oLVArtikel).olv;
|
||
|
||
// Wenn alle Artikel Checked sind TOCLOSE auslösen.
|
||
OLVArtikel_ItemChecked(this.oLVArtikel, null);
|
||
}
|
||
private void Load_Laufzettel()
|
||
{
|
||
this.oLVArtikel.Visible = false;
|
||
this.label1.Location = this.oLVArtikel.Location;
|
||
this.textBoxZusatz.Location = new Point(this.label1.Left, this.label1.Bottom);
|
||
this.textBoxZusatz.Size = new Size(this.oLVArtikel.Width, this.oLVArtikel.Height - 20);
|
||
}
|
||
private void LadeComboBoxen()
|
||
{
|
||
this.comboBoxFahrer.SelectedValueChanged -= ComboBox_SelectedValueChanged;
|
||
this.comboBoxPriority.SelectedValueChanged -= ComboBox_SelectedValueChanged;
|
||
|
||
List<Tour> liste = Tour.GetSaisonListe(saison);
|
||
this.comboBoxFahrer.DataSource = liste;
|
||
this.comboBoxFahrer.DisplayMember = "Bezeichnung";
|
||
this.comboBoxFahrer.ValueMember = "TourID";
|
||
|
||
//List<Benutzer> benutzerliste = Benutzer.GetFahrerList();
|
||
//this.comboBoxFahrer.DataSource = benutzerliste;
|
||
//this.comboBoxFahrer.ValueMember = "BenutzerName";
|
||
|
||
this.comboBoxPriority.DataSource = Enum.GetValues(typeof(Priority));
|
||
}
|
||
private void ComboBox_SelectedValueChanged(object sender, EventArgs e)
|
||
{
|
||
Tosave = true;
|
||
}
|
||
private void LabelContainer_TextChanged(object sender, EventArgs e)
|
||
{
|
||
if (this.labelContainer.Text == "0") { this.pictureBoxMinus.Enabled = this.pictureBoxDirtMinus.Enabled = false; this.pictureBoxMinus.BackColor = this.pictureBoxDirtMinus.BackColor = Color.Gray; }
|
||
else { this.pictureBoxMinus.Enabled = this.pictureBoxDirtMinus.Enabled = true; this.pictureBoxMinus.BackColor = this.pictureBoxDirtMinus.BackColor = Color.Red; }
|
||
|
||
}
|
||
//ÄNDERUNGEN SPEICHERN
|
||
private void AuftragSpeichern()
|
||
{
|
||
auftrag.Liefertag = dTPLiefertag.Value;
|
||
auftrag.ContainerClean = int.Parse(this.labelContainer.Text);
|
||
auftrag.Container = int.Parse(this.labelContDirt.Text);
|
||
//auftrag.ArbeiterID = this.comboBoxFahrer.SelectedIndex == -1 ? null : ((Benutzer)this.comboBoxFahrer.SelectedItem).BenutzerID;
|
||
auftrag.TourID = this.comboBoxFahrer.SelectedIndex == -1 ? null : (int?)this.comboBoxFahrer.SelectedValue;
|
||
auftrag.Priority = this.comboBoxPriority.SelectedIndex == -1 ? Priority.None : ((Priority)this.comboBoxPriority.SelectedItem);
|
||
auftrag.ZusatzInfo = this.textBoxZusatz.Text;
|
||
|
||
if (auftrag.Status == AuftragStatus.Herrichten)
|
||
{
|
||
switch (auftrag.Typ)
|
||
{
|
||
case AuftragTyp.Geschäft:
|
||
break;
|
||
case AuftragTyp.Standart:
|
||
break;
|
||
case AuftragTyp.Inventur:
|
||
{
|
||
foreach (var kvp in dictionary)
|
||
{
|
||
KundeArtikel kndart = KundeArtikel.GetItem(kvp.Key);
|
||
|
||
if (kndart.Korrektur > 0)
|
||
{
|
||
kndart.Korrektur -= kvp.Value[3];
|
||
kndart.KorrekturBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
||
}
|
||
kndart.Save();
|
||
}
|
||
goto default;
|
||
}
|
||
case AuftragTyp.SOLL_Verminderung:
|
||
{
|
||
foreach (var kvp in dictionary)
|
||
{
|
||
KundeArtikel kndart = KundeArtikel.GetItem(kvp.Key);
|
||
|
||
if (kndart.Stand > 0 & kvp.Value[2] < 0)
|
||
{
|
||
kndart.Stand += kvp.Value[2];
|
||
kndart.StandBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
||
}
|
||
kndart.Save();
|
||
}
|
||
goto default;
|
||
}
|
||
case AuftragTyp.SOLL_Erhoehung:
|
||
{
|
||
foreach (var kvp in dictionary)
|
||
{
|
||
KundeArtikel kndart = KundeArtikel.GetItem(kvp.Key);
|
||
|
||
if (kndart.Stand > 0 & kvp.Value[2] > 0)
|
||
{
|
||
kndart.Stand += kvp.Value[2];
|
||
kndart.StandBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
||
}
|
||
kndart.Save();
|
||
}
|
||
goto default;
|
||
}
|
||
case AuftragTyp.IST_Erhoehung:
|
||
{
|
||
foreach (var kvp in dictionary)
|
||
{
|
||
KundeArtikel kndart = KundeArtikel.GetItem(kvp.Key);
|
||
if (kndart.Reklamation > 0 & kvp.Value[0] > 0)
|
||
{
|
||
kndart.Reklamation -= kvp.Value[0];
|
||
kndart.ReklamationBearbeitet = Program.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
||
|
||
}
|
||
if (kndart.Fehlmenge > 0 & kvp.Value[1] > 0)
|
||
{
|
||
kndart.Fehlmenge -= kvp.Value[1];
|
||
kndart.FehlmengeBearbeitet = Program.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
||
}
|
||
if (kndart.Stand > 0 & kvp.Value[2] > 0)
|
||
{
|
||
kndart.Stand += kvp.Value[2];
|
||
kndart.StandBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString();
|
||
}
|
||
kndart.Save();
|
||
}
|
||
goto default;
|
||
}
|
||
default:
|
||
{
|
||
if (auftragDictionary.Count > 0)
|
||
{
|
||
foreach (var kvp in auftragDictionary)
|
||
{
|
||
AuftragArtikel aufart = AuftragArtikel.GetArtikel(kvp.Key);
|
||
aufart.Anzahl = (int)kvp.Value;
|
||
if (aufart.Anzahl == 0) aufart.Erledigt = true;
|
||
else { aufart.Erledigt = false; Toclose = false; }
|
||
aufart.Save();
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
if (this.oLVArtikel.CheckedItems.Count == this.oLVArtikel.Items.Count) { auftrag.Erledigt = DateTime.Now; auftrag.ErledigtVon = this.benutzer.BenutzerID; }
|
||
}
|
||
|
||
auftrag.Save();
|
||
Tosave = false;
|
||
}
|
||
//SCHMUTZWÄSCHESCHEIN DRUCKEN
|
||
private void EtikettDrucken()
|
||
{
|
||
if (MessageBox.Show("Möchtest du JETZT Etiketten für die erfolgten Änderung drucken?", "FRAGE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||
{
|
||
if (Funktionen.SonderEtikett_Drucken(this.auftrag.KundeID, dictionary) == DialogResult.OK)
|
||
{
|
||
etikettgedruckt = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
#region ToSave
|
||
|
||
//BEI CLICK AUF CONTAINER +/- SPEICHERN WIRD AKITV
|
||
private void Container_Click(object sender, EventArgs e)
|
||
{
|
||
PictureBox pb = (PictureBox)sender;
|
||
int cont = 0;
|
||
if (pb.Name.Contains("Dirt"))
|
||
{
|
||
cont = int.Parse(this.labelContDirt.Text);
|
||
if (pb.Name.ToString().Contains("Plus")) cont++;
|
||
if (pb.Name.ToString().Contains("Minus")) cont--;
|
||
this.labelContDirt.Text = cont.ToString();
|
||
}
|
||
else
|
||
{
|
||
cont = int.Parse(this.labelContainer.Text);
|
||
if (pb.Name.ToString().Contains("Plus")) cont++;
|
||
if (pb.Name.ToString().Contains("Minus")) cont--;
|
||
this.labelContainer.Text = cont.ToString();
|
||
}
|
||
Tosave = true;
|
||
}
|
||
|
||
//BEI CLICK AUF DATUM SPEICHERN WIRD AKTIV
|
||
private void FormAuftragDetail_MouseClick(object sender, MouseEventArgs e)
|
||
{
|
||
Control ctr = this.GetChildAtPoint(e.Location);
|
||
if (ctr != null)
|
||
{
|
||
if (ctr.Name.Contains("dTP"))
|
||
{
|
||
ctr.Enabled = true;
|
||
Tosave = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
//WENN LISTVIEW NICHT FOCUSED (FORM.LOAD) TOSAVE BLEIBT FALSE
|
||
private void OLVArtikel_ItemCheck(object sender, ItemCheckEventArgs e)
|
||
{
|
||
ObjectListView olv = (ObjectListView)sender;
|
||
if (e.NewValue != e.CurrentValue) { Tosave = true; }
|
||
}
|
||
#endregion
|
||
|
||
#region Button-Click
|
||
//AUFTRAG ABBRECHEN
|
||
private void ButtonAbbrechen_Click(object sender, EventArgs e)
|
||
{
|
||
//if (_tosave)
|
||
//{
|
||
// if (MessageBox.Show("Möchtest du die Änderungen wirklich verwerfen?", "ÄNDERUNGEN VERWERFEN", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||
// {
|
||
// this.DialogResult = DialogResult.Cancel;
|
||
// this.Close();
|
||
// }
|
||
// else return;
|
||
//}
|
||
//else
|
||
//{
|
||
// this.DialogResult = DialogResult.Cancel;
|
||
// this.Close();
|
||
//}
|
||
|
||
this.DialogResult = DialogResult.Cancel;
|
||
this.Close();
|
||
}
|
||
|
||
//AUFTRAG ABSCHLIESSEN
|
||
private void ButtonFertig_Click(object sender, EventArgs e)
|
||
{
|
||
if (!this.dTPLiefertag.Checked)
|
||
{
|
||
MessageBox.Show("Liefertag muss ausgewählt und angehakt werden.", "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
if (this.kndartListe != null)
|
||
{
|
||
foreach (OLVListItem item in this.oLVArtikel.Items)
|
||
{
|
||
KundeArtikel kndart = (KundeArtikel)item.RowObject;
|
||
if (kndart.Korrektur == 0) continue;
|
||
int oldValue = kndart.Korrektur;
|
||
int newValue = 0;
|
||
|
||
ChangeAnzahl(newValue, oldValue, kndart);
|
||
}
|
||
}
|
||
if (zahlenChanged) EtikettDrucken();
|
||
if (Tosave && etikettgedruckt || Tosave && !zahlenChanged) AuftragSpeichern();
|
||
else Toclose = false;
|
||
if (Toclose)
|
||
{
|
||
if (int.Parse(this.labelContainer.Text) == 0)
|
||
{
|
||
switch (auftrag.Typ)
|
||
{
|
||
case AuftragTyp.Geschäft:
|
||
meldung.NoCleanContainer();
|
||
return;
|
||
case AuftragTyp.Standart:
|
||
meldung.NoCleanContainer();
|
||
return;
|
||
case AuftragTyp.Inventur:
|
||
Program.InventurFertig(this.auftrag);
|
||
break;
|
||
case AuftragTyp.SOLL_Erhoehung:
|
||
break;
|
||
case AuftragTyp.SOLL_Verminderung:
|
||
break;
|
||
case AuftragTyp.Regelmäßig:
|
||
break;
|
||
case AuftragTyp.AufAbruf:
|
||
meldung.NoCleanContainer();
|
||
return;
|
||
case AuftragTyp.Laufzettel:
|
||
break;
|
||
case AuftragTyp.IST_Erhoehung:
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (int.Parse(this.labelContainer.Text) != auftrag.ContainerClean)
|
||
{
|
||
switch (meldung.DifferentCleanContainer())
|
||
{
|
||
case DialogResult.Cancel:
|
||
return;
|
||
case DialogResult.Yes:
|
||
{
|
||
auftrag.ContainerClean = int.Parse(this.labelContainer.Text);
|
||
auftrag.Gedruckt = DateTime.Now;
|
||
auftrag.GedrucktVon = benutzer.BenutzerID;
|
||
auftrag.Status = AuftragStatus.Fertig;
|
||
|
||
bool nocont = false;
|
||
if (MessageBox.Show("Möchtest du die Containeranzahl am Etikett anzeigen?", "FRAGE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||
{
|
||
nocont = true;
|
||
}
|
||
else nocont = false;
|
||
|
||
Funktionen.Etikett_Drucken(auftrag, nocont);
|
||
}
|
||
break;
|
||
case DialogResult.No:
|
||
{
|
||
auftrag.ContainerClean = int.Parse(this.labelContainer.Text);
|
||
auftrag.Erstellt = DateTime.Now;
|
||
auftrag.ErstelltVon = (int)benutzer.BenutzerID;
|
||
auftrag.Status = AuftragStatus.Fertig;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//TODO: NICHT AUFTRAG FERTIG WENN NICHT ALLE ZAHLEN 0
|
||
auftrag.Status = AuftragStatus.Fertig;
|
||
}
|
||
auftrag.Save();
|
||
|
||
// Wenn Inventur wird Fertig-File erstellt.
|
||
if (auftrag.Typ == AuftragTyp.Inventur)
|
||
{
|
||
string loadPath = Path.Combine(ConfigurationManager.AppSettings["DateiSavePfad"], "Listen\\Inventuren") ?? "Inventuren";
|
||
// Inventur File des aktuellen Auftrags auflisten.
|
||
string[] invFiles = Directory.GetFiles(loadPath, $"Herrichten-{auftrag.AuftragID.ToString()}-{kunde.KundeNummer}.csv");
|
||
if (invFiles.Length == 1)
|
||
{
|
||
string ausgeliefertFile = $"Fertig-{auftrag.AuftragID.ToString()}-{kunde.KundeNummer}.csv";
|
||
File.Copy(Path.Combine(loadPath, invFiles[0]), Path.Combine(loadPath, ausgeliefertFile));
|
||
File.Delete(Path.Combine(loadPath, invFiles[0]));
|
||
}
|
||
}
|
||
Toclose = Tosave = false;
|
||
this.DialogResult = DialogResult.OK;
|
||
this.Close();
|
||
}
|
||
else
|
||
{
|
||
this.DialogResult = DialogResult.OK;
|
||
this.Close();
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// TOCLOSE
|
||
/// </summary>
|
||
private void OLVArtikel_ItemChecked(object sender, ItemCheckedEventArgs e)
|
||
{
|
||
ObjectListView olv = (ObjectListView)sender;
|
||
if (e == null) return;
|
||
OLVListItem item = e.Item as OLVListItem;
|
||
AuftragArtikel auftragArtikel = (AuftragArtikel)item.RowObject;
|
||
if (item.Checked)
|
||
{
|
||
auftragArtikel.Erledigt = true;
|
||
int oldValue = auftragArtikel.Anzahl;
|
||
int newValue = 0;
|
||
ChangeAnzahl(newValue, oldValue, auftragArtikel);
|
||
}
|
||
else auftragArtikel.Erledigt = false;
|
||
|
||
if (olv.Items.Count == olv.CheckedItems.Count) Toclose = true;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// SonderAuftrag in CSV-Liste eintragen. Jede Änderung wird in eine Zeile eingetragen. Rek./NW/Rest
|
||
/// </summary>
|
||
/// <param name="kndart"></param>
|
||
private void WriteToCSV(Dictionary<int, int[]> dictionary)
|
||
{
|
||
Kunde _knd = Kunde.GetKunde(null, auftrag.KundeID, null);
|
||
Benutzer _user = this.benutzer;
|
||
List<KundeArtikel> _artikelliste = KundeArtikel.GetList(_knd.KundeID.ToString());
|
||
|
||
string artikel = string.Empty;
|
||
string artikelStand = string.Empty;
|
||
string[] bestandNamen = new string[4] { "Rek.", "NW", "Rest", "INV" };
|
||
string fileName = $"{_knd.KundeNummer}_{_knd.Suchtext}.csv"; // Immer gleiche Datei!
|
||
string savePath = ConfigurationManager.AppSettings["DateiSavePfad"];
|
||
string inventurOrdner = Path.Combine(savePath, "Listen\\Kundenstand") ?? "Kundenstand";
|
||
string csvPath = Path.Combine(inventurOrdner, fileName);
|
||
|
||
// Prüfen ob Header schon existiert
|
||
bool headerExists = File.Exists(csvPath);
|
||
|
||
// Artikelbezeichnungen in string convertieren
|
||
foreach (KundeArtikel art in _artikelliste) { artikel += ";" + art.ArtikelName; artikelStand += ";" + art.Stand.ToString(); }
|
||
|
||
// Nur Header bei NEUER Datei
|
||
if (!headerExists)
|
||
{
|
||
var csv = new StringBuilder();
|
||
csv.AppendLine("=== STANDVERÄNDERUNG ===");
|
||
csv.AppendLine($"KundeNr: {_knd.KundeNummer}");
|
||
csv.AppendLine($"Kunde: {_knd.KundeName}");
|
||
csv.AppendLine(new string('=', 30));
|
||
csv.AppendLine();
|
||
csv.AppendLine($"Erstellt am;Erstellt von;Hergerichtet am;Veränderung;{artikel}");
|
||
File.WriteAllText(csvPath, csv.ToString(), Encoding.UTF8);
|
||
}
|
||
|
||
// NEUE Artikel ANHÄNGEN (ohne Header)
|
||
var appendCsv = new StringBuilder();
|
||
string difftrennzeichen = string.Empty;
|
||
|
||
var artikelArray = artikel.Split(';');
|
||
|
||
foreach (var kvp in dictionary)
|
||
{
|
||
KundeArtikel kndart = KundeArtikel.GetItem(kvp.Key);
|
||
Artikel _artikel = Artikel.GetArtikel(null, kndart.ArtikelID);
|
||
string artikelKey = _artikel.Bezeichnung; // z.B. "ART1"
|
||
int[] artbestand = kvp.Value; // z.B. [3, 0, 5]
|
||
|
||
int artikelIndex = Array.IndexOf(artikelArray, artikelKey);
|
||
if (artikelIndex < 0) continue;
|
||
|
||
for (int idxInBestand = 0; idxInBestand < artbestand.Length; idxInBestand++)
|
||
{
|
||
int art = artbestand[idxInBestand];
|
||
if (art == 0) continue;
|
||
|
||
// Spalten: Datum, User, Heute, Bestandsname, dann alle Artikel‑Spalten
|
||
int totalColumns = 4 + artikelArray.Length;
|
||
var line = new string[totalColumns];
|
||
|
||
line[0] = auftrag.Erstellt.Value.Date.ToString("yyyy-MM-dd");
|
||
line[1] = _user.Vorname + " " + _user.Nachname;
|
||
line[2] = DateTime.Today.ToString("yyyy-MM-dd");
|
||
line[3] = bestandNamen[idxInBestand]; // z.B. "Lager A"
|
||
|
||
// Wert in der richtigen Artikel‑Spalte
|
||
line[4 + artikelIndex] = art.ToString();
|
||
|
||
appendCsv.AppendLine(string.Join(";", line));
|
||
}
|
||
}
|
||
appendCsv.AppendLine($"{DateTime.Today.Date.ToString("yyyy-MM-dd")};;;Stand;{artikelStand}{difftrennzeichen}");
|
||
// ANHÄNGEN statt überschreiben
|
||
File.AppendAllText(csvPath, appendCsv.ToString(), Encoding.UTF8);
|
||
}
|
||
|
||
|
||
private void FormAuftragDetail_Shown(object sender, EventArgs e)
|
||
{
|
||
fb = new UCFeedback(benutzer);
|
||
Button btn = fb.Controls[0] as Button;
|
||
btn.BackColor = Program.Wirlblau;
|
||
btn.ForeColor = Color.White;
|
||
btn.FlatAppearance.BorderColor = Color.White;
|
||
this.Controls.Add(fb);
|
||
fb.BringToFront();
|
||
|
||
int width = 0;
|
||
foreach (OLVColumn col in this.oLVArtikel.Columns) width += col.Width;
|
||
if (this.oLVArtikel.Scrollable) width += Program.scrollBar;
|
||
this.oLVArtikel.Width = width;
|
||
this.oLVArtikel.Height = textBoxZusatz.Bottom;
|
||
//AdjustHeightToFitAll(this.oLVArtikel);
|
||
this.buttonAbbrechen.Location = new Point(this.buttonAbbrechen.Left, this.oLVArtikel.Bottom + 15);
|
||
this.buttonFertig.Location = new Point(this.buttonFertig.Left, this.oLVArtikel.Bottom + 15);
|
||
this.buttonKundeInfo.Location = new Point(20, this.buttonAbbrechen.Top);
|
||
if (this.oLVArtikel.Visible) this.ClientSize = new Size(oLVArtikel.Right + 10, buttonAbbrechen.Bottom + 10);
|
||
else this.ClientSize = new Size(textBoxZusatz.Right + 10, pictureBoxDirtPlus.Bottom + 10 + buttonAbbrechen.Height + 20);
|
||
|
||
if (fb != null) fb.Location = new Point(this.ClientSize.Width - fb.Width - 7, 0);
|
||
|
||
while (this.Right > Screen.PrimaryScreen.WorkingArea.Width)
|
||
{
|
||
this.Width--;
|
||
}
|
||
//if (oLVArtikel != null) this.ClientSize = new Size(oLVArtikel.Right + 10, oLVArtikel.Bottom + buttonAbbrechen.Height + 25);
|
||
}
|
||
private void ChangeAnzahl(int newValue, int oldvalue, object _artikel)
|
||
{
|
||
KundeArtikel kndart;
|
||
if (this.auftrag.Typ == AuftragTyp.SOLL_Verminderung) if (newValue > 0) newValue *= -1;
|
||
diff = oldvalue - (newValue);
|
||
if (diff != 0) Tosave = true;
|
||
|
||
if (_artikel is AuftragArtikel auftragArtikel)
|
||
{
|
||
if (auftragDictionary.TryGetValue((int)auftragArtikel.AuftragArtikelID, out int val))
|
||
{
|
||
auftragDictionary[(int)auftragArtikel.AuftragArtikelID] = newValue;
|
||
//if (newValue == 0) e.ListViewItem.Checked = true;
|
||
}
|
||
else auftragDictionary.Add((int)auftragArtikel.AuftragArtikelID, newValue);
|
||
|
||
kndart = KundeArtikel.GetKundeArtikelVonArtikelID(this.kunde.KundeID, auftragArtikel.ArtikelID);
|
||
}
|
||
else kndart = (KundeArtikel)_artikel;
|
||
|
||
int reklamation = kndart.Reklamation;
|
||
int fehlmenge = kndart.Fehlmenge;
|
||
int stand = kndart.Stand;
|
||
int korrektur = kndart.Korrektur;
|
||
KorrigiereBestand(diff, ref reklamation, ref fehlmenge, ref stand, ref korrektur);
|
||
|
||
if (dictionary.TryGetValue((int)kndart.KundeArtikelID, out int[] value))
|
||
{
|
||
for (int i = 0; i < value.Length; i++)
|
||
{
|
||
value[i] += bestand[i];
|
||
}
|
||
}
|
||
else dictionary.Add((int)kndart.KundeArtikelID, bestand);
|
||
|
||
zahlenChanged = true;
|
||
|
||
//WriteToCSV(kndart);
|
||
this.ResumeLayout();
|
||
this.Cursor = Cursors.Default;
|
||
|
||
}
|
||
private void OLVArtikel_CellEditFinished(object sender, CellEditEventArgs e)
|
||
{
|
||
this.Cursor = Cursors.WaitCursor;
|
||
this.SuspendLayout();
|
||
|
||
ObjectListView olv = (ObjectListView)sender;
|
||
if (e.RowObject is KundeArtikel)
|
||
{
|
||
if (e.Value != e.NewValue) zahlenChanged = true;
|
||
this.ResumeLayout();
|
||
this.Cursor = Cursors.Default;
|
||
return;
|
||
}
|
||
AuftragArtikel auftragArtikel = (AuftragArtikel)e.RowObject;
|
||
int newValue = (int)e.NewValue;
|
||
int oldValue = (int)e.Value;
|
||
|
||
ChangeAnzahl(newValue, oldValue, auftragArtikel);
|
||
|
||
//if (this.auftrag.Typ == AuftragTyp.SOLL_Verminderung) if (newValue > 0) newValue = newValue * -1;
|
||
//if (e.Column.Text == "Anzahl") diff = (int)e.Value - (newValue);
|
||
//if (diff != 0) Tosave = true;
|
||
|
||
//if (auftragDictionary.TryGetValue((int)auftragArtikel.AuftragArtikelID, out int val))
|
||
//{
|
||
// val = newValue;
|
||
// if (newValue == 0) e.ListViewItem.Checked = true;
|
||
//}
|
||
//else auftragDictionary.Add((int)auftragArtikel.AuftragArtikelID, newValue);
|
||
|
||
//KundeArtikel kndart = KundeArtikel.GetKundeArtikelVonArtikelID(this.kunde.KundeID, auftragArtikel.ArtikelID);
|
||
|
||
//int reklamation = kndart.Reklamation;
|
||
//int fehlmenge = kndart.Fehlmenge;
|
||
//int stand = kndart.Stand;
|
||
//int korrektur = kndart.Korrektur;
|
||
//KorrigiereBestand(diff, ref reklamation, ref fehlmenge, ref stand, ref korrektur);
|
||
|
||
//if (dictionary.TryGetValue((int)kndart.KundeArtikelID, out int[] value))
|
||
//{
|
||
// for (int i = 0; i < value.Length; i++)
|
||
// {
|
||
// value[i] += bestand[i];
|
||
// }
|
||
//}
|
||
//else dictionary.Add((int)kndart.KundeArtikelID, bestand);
|
||
////WriteToCSV(kndart);
|
||
this.ResumeLayout();
|
||
this.Cursor = Cursors.Default;
|
||
|
||
}
|
||
public void KorrigiereBestand(int diff, ref int reklamation, ref int fehlmenge, ref int stand, ref int korrektur)
|
||
{
|
||
bestand = new int[4];
|
||
if (diff == 0)
|
||
return;
|
||
|
||
switch (this.auftrag.Typ)
|
||
{
|
||
case AuftragTyp.Inventur:
|
||
{
|
||
if (diff < 0) // Diff ist negativ
|
||
{
|
||
int korr = diff;
|
||
bestand[3] = korr;
|
||
korrektur -= korr;
|
||
}
|
||
else // Diff ist positiv
|
||
{
|
||
int korr = diff;
|
||
bestand[3] = korr;
|
||
korrektur -= korr;
|
||
}
|
||
}
|
||
break;
|
||
case AuftragTyp.SOLL_Erhoehung:
|
||
{
|
||
if (diff < 0) { MessageBox.Show("Eine SOLL-Erhöhung kann keine negative Zahl haben. Bitte korrigiere die Zahlen.", "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; }
|
||
bestand[2] = diff;
|
||
stand += diff;
|
||
}
|
||
break;
|
||
case AuftragTyp.IST_Erhoehung:
|
||
{
|
||
if (diff < 0) { MessageBox.Show("Eine IST-Erhöhung kann keine negative Zahl haben. Bitte korrigiere die Zahlen.", "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; }
|
||
goto default;
|
||
}
|
||
case AuftragTyp.SOLL_Verminderung:
|
||
{
|
||
if (diff > 0) { diff *= -1; }
|
||
bestand[2] = diff;
|
||
stand += diff;
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
int rest = diff;
|
||
// 1) Reklamation nur korrigieren, wenn sie <= diff ist
|
||
if (reklamation > 0)
|
||
{
|
||
int reduktion = Math.Min(reklamation, rest);
|
||
bestand[0] = reduktion;
|
||
reklamation -= reduktion;
|
||
rest -= reduktion;
|
||
}
|
||
// 2) Fehlmenge korrigieren
|
||
if (fehlmenge > 0)
|
||
{
|
||
int abbau = Math.Min(fehlmenge, rest);
|
||
bestand[1] = abbau;
|
||
fehlmenge -= abbau;
|
||
rest -= abbau;
|
||
}
|
||
// 3) Rest auf Stand buchen
|
||
if (rest > 0)
|
||
stand += rest;
|
||
bestand[2] = rest;
|
||
// 4) Wenn kein Rest dann Korrektur auf null
|
||
if (rest == 0) korrektur = bestand[3] = rest;
|
||
}
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
private void OLVArtikel_SizeChanged(object sender, EventArgs e)
|
||
{
|
||
this.ClientSize = new Size(oLVArtikel.Right + 10, oLVArtikel.Bottom + buttonAbbrechen.Height + 25);
|
||
}
|
||
|
||
private void FormAuftragDetail_FormClosing(object sender, FormClosingEventArgs e)
|
||
{
|
||
if (Tosave)
|
||
{
|
||
if (MessageBox.Show("Möchtest du die Änderungen wirklich verwerfen?", "ÄNDERUNGEN VERWERFEN", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||
{
|
||
e.Cancel = true;
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void ButtonKundeInfo_CLick(object sender, EventArgs e)
|
||
{
|
||
FormKundeVW kundeVW = new FormKundeVW(this.kunde);
|
||
kundeVW.ShowDialog();
|
||
}
|
||
|
||
private void FormAuftragDetail_HelpButtonClicked(object sender, CancelEventArgs e)
|
||
{
|
||
Control[] ctr = this.Controls.Find("info", false);
|
||
if (ctr.Length == 1) this.Controls.Remove(ctr[0]); infoOpen = false;
|
||
if (ctr.Length > 1) foreach (Control control in ctr) this.Controls.Remove(control);
|
||
if (ctr.Length == 0)
|
||
{
|
||
UCAuftragInfo info = new UCAuftragInfo(this.auftrag);
|
||
info.Name = "info";
|
||
this.Controls.Add(info);
|
||
info.Location = new Point(20, 20);
|
||
info.BringToFront();
|
||
}
|
||
e.Cancel = true;
|
||
}
|
||
|
||
private void ComboBoxFahrer_Leave(object sender, EventArgs e)
|
||
{
|
||
if (this.comboBoxFahrer.SelectedIndex == -1) return;
|
||
Tour tour = Tour.FindeTour((int?)this.comboBoxFahrer.SelectedValue, null, null);
|
||
this.comboBoxPriority.SelectedItem = tour.Priority;
|
||
}
|
||
}
|
||
}
|
||
//CHANGES: 1. Es wird ab sofort nur ein Button zum Speichern und Abschließen bereitgestellt. System entscheidet was getan wird.
|
||
//CHANGES: 2. Änderungen werden nur gespeichert wenn ein Etikett gedruckt wurde.
|
||
//CHANGES: 3. Abschließen nur möglich wenn alle Artikel auf 0 sind (Checked) und gespeichert wurde.
|
||
//CHANGES: Bei Druckabbruch wird die geänderte Zahl NICHT zurückgesetzt. (Das muss händisch erfolgen)
|
||
//CHANGES: Wenn die Zahlen zurückgesetzt werden sollen, muss AuftragDetail geschlossen werden.
|
||
//CHANGES: Wenn die reduzierte Anzahl bei SOLL-Verminderung nicht negativ ist, wird diese negativ gemacht. So wird ein möglicher Fehler ausgebessert.
|
||
//CHANGES: Beim Speichern ohne Abschließen schließt sich das Fenster nach dem Speichern.
|
||
//CHANGES: Wenn ein Artikel vollständig hergerichtet wird, muss er nur abgehackt werden. Den Rest macht der Computer. |