using BrightIdeasSoftware; using DatenDB; 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 dictionary = new Dictionary(); private Dictionary auftragDictionary = new Dictionary(); public Auftrag auftrag; public Benutzer benutzer; public List artikelList; public Meldungen meldung = new Meldungen(); private UCInventur uci; private UCFeedback fb; public Kunde kunde; private int diff = 0; int[] bestand; // Reklamation/Fehlmenge/Standveränderung/Inventurausgleich bool etikettgedruckt = false; //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; 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; } 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; 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; 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; if (this.auftrag.Typ != AuftragTyp.Inventur || (this.auftrag.Typ == AuftragTyp.Inventur & this.auftrag.Status == AuftragStatus.Herrichten)) Load_OLV(); else { if (this.auftrag.Status == AuftragStatus.Warten) buttonFertig.Visible = false; Load_UCInventur(this.auftrag); } this.ClientSize = new Size(this.oLVArtikel.Right + 10, this.ClientSize.Height); //WENN STATUS VORBEREITET BUTTON FERTIG ENABLEN if (auftrag.Status == AuftragStatus.Vorbereitet) { buttonFertig.Enabled = true; buttonFertig.BackColor = Color.FromArgb(0, 192, 0); Toclose = true; } } 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); uci = new UCInventur(lines, this.benutzer, this); uci.Visible = false; uci.SizeChangedForParent += () => { DoResize(); }; this.Controls.Add(uci); } private void DoResize() { if (uci != null) { uci.Location = this.oLVArtikel.Location = new Point(this.oLVArtikel.Location.X, fb.Bottom + 2); uci.Visible = true; this.ClientSize = new Size(uci.Right, uci.Bottom + buttonAbbrechen.Height + 25); } else { this.oLVArtikel.Height = this.textBoxZusatz.Bottom - this.oLVArtikel.Top; this.ClientSize = new Size(oLVArtikel.Right + 10, oLVArtikel.Bottom + buttonAbbrechen.Height + 25); } if (fb != null) fb.Location = new Point(this.ClientSize.Width - fb.Width - 7, 0); } 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 LadeComboBoxen() { this.comboBoxFahrer.SelectedValueChanged -= ComboBox_SelectedValueChanged; this.comboBoxPriority.SelectedValueChanged -= ComboBox_SelectedValueChanged; List 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.Priority = this.comboBoxPriority.SelectedIndex == -1 ? Priority.None : ((Priority)this.comboBoxPriority.SelectedItem); auftrag.ZusatzInfo = this.textBoxZusatz.Text; auftrag.Save(); if (auftrag.Typ <= AuftragTyp.Regelmäßig && (auftrag.Typ >= AuftragTyp.Inventur) && auftrag.Status == AuftragStatus.Herrichten) { 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; aufart.Save(); } if (auftrag.Typ == AuftragTyp.Inventur) { foreach (var kvp in dictionary) { KundeArtikel kndart = KundeArtikel.GetItem(kvp.Key); if (kndart.Reklamation != kvp.Value[0]) { kndart.Reklamation = kvp.Value[0]; kndart.ReklamationBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString(); } if (kndart.Fehlmenge != kvp.Value[1]) { kndart.Fehlmenge = kvp.Value[1]; kndart.FehlmengeBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString(); } if (kndart.Stand != kvp.Value[2]) { kndart.Stand = kvp.Value[2]; kndart.StandBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString(); } if (kndart.Korrektur != kvp.Value[3]) { kndart.Korrektur = kvp.Value[3]; kndart.KorrekturBearbeitet = this.benutzer.BenutzerName + " am " + DateTime.Now.ToString(); } kndart.Save(); } WriteToCSV(dictionary); } } 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) { EtikettDrucken(); if (Tosave && etikettgedruckt) 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: 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; 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 { auftrag.Erledigt = DateTime.Now; auftrag.ErledigtVon = (int)benutzer.BenutzerID; 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.Close(); } #endregion /// /// TOCLOSE /// 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; } /// /// SonderAuftrag in CSV-Liste eintragen. Jede Änderung wird in eine Zeile eingetragen. Rek./NW/Rest /// /// private void WriteToCSV(Dictionary dictionary) { Kunde _knd = Kunde.GetKunde(null, auftrag.KundeID, null); Benutzer _user = this.benutzer; List _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(); if (uci != null) { uci.Location = this.oLVArtikel.Location = new Point(this.oLVArtikel.Location.X, fb.Bottom + 2); uci.Visible = true; this.ClientSize = new Size(uci.Right, uci.Bottom + buttonAbbrechen.Height + 25); } else { this.oLVArtikel.Height = this.textBoxZusatz.Bottom - this.oLVArtikel.Top; this.ClientSize = new Size(oLVArtikel.Right + 10, oLVArtikel.Bottom + buttonAbbrechen.Height + 25); } 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, AuftragArtikel auftragArtikel) { if (this.auftrag.Typ == AuftragTyp.SOLL_Verminderung) if (newValue > 0) newValue *= -1; diff = oldvalue - (newValue); if (diff != 0) Tosave = true; 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); 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; } private void OLVArtikel_CellEditFinished(object sender, CellEditEventArgs e) { this.Cursor = Cursors.WaitCursor; this.SuspendLayout(); ObjectListView olv = (ObjectListView)sender; 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) { MessageBox.Show("Eine SOLL-Verminderung kann keine positiven Zahlen haben. Bitte korrigiere die Zahlen.", "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Stop ); return; } 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; } 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; } } } } } //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.