438 lines
14 KiB
C#
438 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Printing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Windows.Forms;
|
|
using BrightIdeasSoftware;
|
|
using DatenDB;
|
|
using Deckungsbeitrag.UserControls;
|
|
|
|
namespace Deckungsbeitrag
|
|
{
|
|
public partial class FormAuftragDetail : Form
|
|
{
|
|
public Auftrag auftrag;
|
|
public Benutzer benutzer;
|
|
public List<AuftragArtikel> artikelList;
|
|
public Meldungen meldung = new Meldungen();
|
|
public Kunde kunde;
|
|
private int diff = 0;
|
|
int[] bestand = new int[3]; // Reklamation/Fehlmenge/Standveränderung
|
|
|
|
|
|
//WENN AUFTRAG SPEICHERN
|
|
private bool _tosave = false;
|
|
public bool tosave
|
|
{
|
|
get { return _tosave; }
|
|
set
|
|
{
|
|
_tosave = value;
|
|
if (_tosave)
|
|
{
|
|
buttonSpeichern.Enabled = true;
|
|
buttonSpeichern.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);
|
|
|
|
//SPEICHERN UND ABSCHLIESSEN BUTTONS WERDEN FUNKTIONSLOS UND GRAU
|
|
buttonSpeichern.Enabled = buttonFertig.Enabled = false;
|
|
buttonSpeichern.BackColor = buttonFertig.BackColor = Color.Gray;
|
|
|
|
}
|
|
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;
|
|
|
|
Load_OLV();
|
|
|
|
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_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;
|
|
}
|
|
|
|
private void LadeComboBoxen()
|
|
{
|
|
this.comboBoxFahrer.SelectedValueChanged -= comboBox_SelectedValueChanged;
|
|
this.comboBoxPriority.SelectedValueChanged -= comboBox_SelectedValueChanged;
|
|
|
|
List<Benutzer> benutzerliste = Benutzer.GetFahrerList();
|
|
this.comboBoxFahrer.DataSource = benutzerliste;
|
|
this.comboBoxFahrer.ValueMember = "BenutzerName";
|
|
|
|
this.comboBoxPriority.DataSource = Enum.GetValues(typeof(AuftragPriority));
|
|
}
|
|
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; }
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// TOSAVE
|
|
/// </summary>
|
|
|
|
//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; }
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// TOCLOSE
|
|
/// </summary>
|
|
private void oLVArtikel_ItemChecked(object sender, ItemCheckedEventArgs e)
|
|
{
|
|
ObjectListView olv = (ObjectListView)sender;
|
|
if (olv.Items.Count == olv.CheckedItems.Count) toclose = true;
|
|
foreach(OLVListItem item in olv.CheckedItems)
|
|
{
|
|
AuftragArtikel auftragArtikel = (AuftragArtikel)item.RowObject;
|
|
auftragArtikel.Erledigt = true;
|
|
auftragArtikel.Save();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// BUTTONS
|
|
/// </summary>
|
|
|
|
//ÄNDERUNGEN SPEICHERN
|
|
private void buttonSpeichern_Click(object sender, EventArgs e)
|
|
{
|
|
if (tosave)
|
|
{
|
|
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 ? AuftragPriority.None : ((AuftragPriority)this.comboBoxPriority.SelectedItem);
|
|
auftrag.ZusatzInfo = this.textBoxZusatz.Text;
|
|
auftrag.Save();
|
|
|
|
if (auftrag.Typ == AuftragTyp.Regelmäßig)
|
|
{
|
|
foreach (OLVListItem item in this.oLVArtikel.Items)
|
|
{
|
|
AuftragArtikel art = (AuftragArtikel)item.Tag;
|
|
if (item.Checked) art.Erledigt = true;
|
|
else art.Erledigt = false;
|
|
|
|
art.Save();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
|
|
}
|
|
|
|
//AUFTRAG ABBRECHEN
|
|
private void buttonAbbrechen_Click(object sender, EventArgs e)
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
this.Close();
|
|
}
|
|
|
|
//AUFTRAG ABSCHLIESSEN
|
|
private void buttonFertig_Click(object sender, EventArgs e)
|
|
{
|
|
if (toclose)
|
|
{
|
|
if (auftrag.Typ < AuftragTyp.Standerhöhung || auftrag.Typ > AuftragTyp.Regelmäßig)
|
|
if (int.Parse(this.labelContainer.Text) == 0) if (meldung.NoCleanContainer() == DialogResult.OK) return;
|
|
|
|
if (int.Parse(this.labelContainer.Text) != auftrag.ContainerClean)
|
|
{
|
|
switch (meldung.DifferentCleanContainer())
|
|
{
|
|
case DialogResult.Cancel:
|
|
break;
|
|
case DialogResult.Yes:
|
|
{
|
|
auftrag.ContainerClean = int.Parse(this.labelContainer.Text);
|
|
auftrag.Liefertag = dTPLiefertag.Value;
|
|
//WENN BEARBEITET UND AUSGEDRUCKT WIRD GEDRUCKT VERÄNDERT UND ERSTELLT IST URSPRUNGSDATUM
|
|
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;
|
|
|
|
DialogResult result = Funktionen.Etikett_Drucken(auftrag, nocont);
|
|
if (result == DialogResult.OK)
|
|
{
|
|
this.auftrag.Save();
|
|
this.Close();
|
|
}
|
|
}
|
|
break;
|
|
case DialogResult.No:
|
|
{
|
|
auftrag.ContainerClean = int.Parse(this.labelContainer.Text);
|
|
auftrag.Liefertag = dTPLiefertag.Value;
|
|
//WENN BEARBEITET UND NICHT GEDRUCKT WIRD ERSTELLT VERÄNDERT UND GEDRUCKT IST URSPRUNGSDATUM
|
|
auftrag.Erstellt = DateTime.Now;
|
|
auftrag.ErstelltVon = (int)benutzer.BenutzerID;
|
|
auftrag.Status = AuftragStatus.Fertig;
|
|
|
|
this.auftrag.Save();
|
|
this.Close();
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
auftrag.Erledigt = DateTime.Now;
|
|
auftrag.ErledigtVon = (int)benutzer.BenutzerID;
|
|
auftrag.Status = AuftragStatus.Fertig;
|
|
auftrag.Save();
|
|
}
|
|
}
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
|
|
}
|
|
|
|
//SCHMUTZWÄSCHESCHEIN DRUCKEN
|
|
private void buttonSWS_Click(object sender, EventArgs e)
|
|
{
|
|
//TODO: Bestand von allen Artikeln speichern und für Druck vorbereiten.
|
|
//TODO: Eventuell die Zahlen in CSV speichern und von dort für Druck verwenden?!
|
|
//TODO: Erstellen von SonderAuftrag und Drucken von Etikett testen.
|
|
if (MessageBox.Show("Möchtest du Etiketten für die Änderung drucken?", "FRAGE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
Funktionen.SonderEtikett_Drucken(this.auftrag, bestand);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// UNUSED THINGS
|
|
/// </summary>
|
|
|
|
//RAHMEN UM FORM ZEICHNEN
|
|
private void FormAuftragDetail_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
Graphics surface = CreateGraphics();
|
|
Pen pen1 = new Pen(Color.White, 5);
|
|
|
|
surface.DrawLine(pen1, 10, 215, this.buttonAbbrechen.Right + 15, 215);
|
|
surface.DrawRectangle(pen1, 10, 10, this.buttonAbbrechen.Right + 5, this.buttonAbbrechen.Bottom + 5);
|
|
|
|
}
|
|
//PRINT PAGE FÜR DRUCK
|
|
private void FormAuftragDetail_Shown(object sender, EventArgs e)
|
|
{
|
|
UCFeedback fb = new UCFeedback(benutzer);
|
|
Button btn = fb.Controls[0] as Button;
|
|
if (fb != null) fb.Location = new Point(this.ClientSize.Width - fb.Width - 7, 0);
|
|
btn.BackColor = Program.Wirlblau;
|
|
btn.ForeColor = Color.White;
|
|
btn.FlatAppearance.BorderColor = Color.White;
|
|
this.Controls.Add(fb);
|
|
fb.BringToFront();
|
|
this.oLVArtikel.Location = new Point(this.oLVArtikel.Location.X, fb.Bottom + 2);
|
|
this.oLVArtikel.Height = this.textBoxZusatz.Bottom - this.oLVArtikel.Top;
|
|
}
|
|
|
|
private void oLVArtikel_CellEditStarting(object sender, CellEditEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void oLVArtikel_CellEditFinished(object sender, CellEditEventArgs e)
|
|
{
|
|
this.Cursor = Cursors.WaitCursor;
|
|
this.SuspendLayout();
|
|
|
|
ObjectListView olv = (ObjectListView)sender;
|
|
AuftragArtikel auftragArtikel = (AuftragArtikel)e.RowObject;
|
|
if (e.Column.Text == "Anzahl") diff = ((int)e.Value - ((int)e.NewValue));
|
|
|
|
auftragArtikel.Anzahl = (int)e.NewValue;
|
|
auftragArtikel.Save();
|
|
|
|
KundeArtikel kndart = KundeArtikel.GetKundeArtikelVonArtikelID(this.kunde.KundeID, auftragArtikel.ArtikelID);
|
|
|
|
int reklamation = kndart.Reklamation;
|
|
int fehlmenge = kndart.Fehlmenge;
|
|
int stand = kndart.Stand;
|
|
KorrigiereBestand(diff, ref reklamation, ref fehlmenge, ref stand);
|
|
kndart.Reklamation = reklamation;
|
|
kndart.Fehlmenge = fehlmenge;
|
|
kndart.Stand = stand;
|
|
|
|
|
|
kndart.Save();
|
|
this.ResumeLayout();
|
|
this.Cursor = Cursors.Default;
|
|
|
|
}
|
|
//TODO: Standerhöhung funktioniert soweit Standverringerung soll nur auf Stand gehen
|
|
public void KorrigiereBestand(int diff, ref int reklamation, ref int fehlmenge, ref int stand)
|
|
{
|
|
|
|
if (diff == 0)
|
|
return;
|
|
|
|
if (diff < 0) { bestand[2] = diff; stand += diff; return; }
|
|
|
|
int rest = diff * 1;
|
|
|
|
// 1) Reklamation nur korrigieren, wenn sie <= diff ist
|
|
if (reklamation > 0 && reklamation <= rest)
|
|
{
|
|
rest -= reklamation;
|
|
bestand[0] = reklamation;
|
|
reklamation = 0;
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
|
|
private void oLVArtikel_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
|
|
{
|
|
tosave = true;
|
|
}
|
|
}
|
|
}
|
|
//TODO: Standverminderung und Standerhöhung mit einem Aufruf (Standveränderung?) Bei Verminderung -Zahlen sonst Plus.
|
|
//TODO: Korrigiere Bestand: Wenn -Zahl dann Stand - Zahl.
|
|
//TODO: Speichern etc. durchgehen und adaptieren
|
|
//TODO: Liste vorher/nachher durchdenken
|
|
//DONE: Feedback Button hinzufügen
|
|
//DONE: ComboBox Fahrer und Priorität implementieren
|
|
//DONE: Container schmutzig bearbeitbar machen |