using DatenDB; 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.Text; using System.Threading.Tasks; using System.Web.Caching; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; using static System.Net.Mime.MediaTypeNames; namespace Deckungsbeitrag { public partial class FormNeuerAuftrag : Form { public Fehlermeldungen meldung = new Fehlermeldungen(); public Kunde kunde; //public Kunde extrakunde; //public List kundenliste; //public List fahrerliste; public Auftrag Auftrag; public Auftrag extraAuftrag; public Fach fach; public AuftragArtikel AuftragArtikel; private Benutzer benutzer; private Maschine maschine; bool extra; List sortimentListe; public FormNeuerAuftrag() { InitializeComponent(); } public FormNeuerAuftrag(Benutzer benutzer, Maschine maschine, bool extra, Auftrag auftrag, Fach fach) : this() { this.benutzer = benutzer; this.maschine = maschine; this.extra = extra; this.fach = fach; if (auftrag == null) this.extraAuftrag = auftrag; else this.Auftrag = auftrag; } private void FormNeuerAuftrag_Load(object sender, EventArgs e) { Load_Controls(); this.label1.Text = this.textBoxZusatz.Text.Length.ToString() + "/" + this.textBoxZusatz.MaxLength.ToString(); sortimentListe = (List)Funktionen.SortimentLesen("Liste"); //TODO: Funktion versuchen was diese bewirkt. this.dGArtikel.ForeColor = Color.Black; //Unterscheidung zwischen BenutzerRollen. Verschiedene Controls werden gesperrt, angezeigt oder verändert if (this.benutzer.Rolle == BenutzerRolle.Verwaltung || this.benutzer.Rolle == BenutzerRolle.Admin || this.benutzer.Rolle == BenutzerRolle.Master) { this.comboBoxTyp.Enabled = true; this.buttonExtraKunde.Enabled = false; this.buttonExtraKunde.BackColor = Color.Gray; this.comboBoxTyp.SelectedIndex = 2; } else { this.comboBoxTyp.Enabled = false; foreach(Control c in this.groupBoxSonder.Controls) { if(c.GetType() != typeof(Label)) c.Enabled = false; } this.dGArtikel.Enabled = this.dGArtikel.Visible = false; this.pictureBoxWalli.Visible = true; this.comboBoxTyp.SelectedIndex = 1; } } private void Load_Controls() { Get_RadioButtons(); comboBox_Load(); if (Auftrag == null) { this.dTPLiefertag.Value = DateTime.Today; this.comboBoxAufgabe.SelectedIndex = -1; this.comboBoxBenutzer.SelectedIndex = -1; } else { kunde = Kunde.GetKunde(string.Empty, Auftrag.KundeID, string.Empty); this.textBoxKndNr.Text = kunde.KundeNummer; this.textBoxKundeName.Text = kunde.Suchtext; this.textBoxKundeName.Enabled = false; this.dTPLiefertag.Value = Auftrag.Liefertag; this.labelContainer.Text = Auftrag.Container.ToString(); this.textBoxZusatz.Text = Auftrag.ZusatzInfo; dTPLiefertag_Leave(this.dTPLiefertag, EventArgs.Empty); labelContainer_TextChanged(this.labelContainer, EventArgs.Empty); if (Auftrag.ArbeiterID != null) { foreach (Benutzer b in comboBoxBenutzer.Items) if (b.BenutzerID == Auftrag.ArbeiterID) this.comboBoxBenutzer.SelectedItem = b; } if (Auftrag.Typ == AuftragTyp.Sonder) { foreach (Aufgabe auf in comboBoxAufgabe.Items) { if (auf.AufgabeID == Auftrag.AufgabeID) { this.comboBoxAufgabe.SelectedItem = auf; if (auf.Bezeichnung == "STH" || auf.Bezeichnung == "STV" || auf.Bezeichnung == "STA") Load_Gridview(kunde.KundeNummer.ToString()); } } } } } private void Get_RadioButtons() { foreach (RadioButton rb in this.Controls.OfType()) { if (rb.Name.Contains("MO")) rb.Tag = Liefertag.MO; if (rb.Name.Contains("Di")) rb.Tag = Liefertag.DI; if (rb.Name.Contains("MI")) rb.Tag = Liefertag.MI; if (rb.Name.Contains("DO")) rb.Tag = Liefertag.DO; if (rb.Name.Contains("FR")) rb.Tag = Liefertag.FR; } } private void comboBox_Load() { List aufgabenlist = Aufgabe.GetList(2); foreach (Aufgabe aufgabe in aufgabenlist) this.comboBoxAufgabe.AutoCompleteCustomSource.Add(aufgabe.Bezeichnung); this.comboBoxAufgabe.DataSource = aufgabenlist; this.comboBoxAufgabe.DisplayMember = "Bezeichnung"; List benutzerlist = Benutzer.GetArbeiterList(); foreach (Benutzer benutzer in benutzerlist) this.comboBoxBenutzer.AutoCompleteCustomSource.Add(benutzer.Vorname); this.comboBoxBenutzer.DataSource = benutzerlist; this.comboBoxBenutzer.DisplayMember = "Vorname"; this.comboBoxTyp.DataSource = Enum.GetValues(typeof(AuftragTyp)); } private void Load_Gridview(string kundeNr) { List resultList = null; resultList = sortimentListe.FindAll(Sortiment => Sortiment.KundeNummer == kundeNr); //if(this.benutzer.BenutzerID == this.Auftrag.ArbeiterID) //{ // DataGridViewCheckBoxColumn boolColumn = new DataGridViewCheckBoxColumn(); // boolColumn.HeaderText = "Erledigt"; // boolColumn.Name = "CheckColumn"; // this.dGArtikel.Columns.Add(boolColumn); //} this.dGArtikel.DataSource = resultList; this.dGArtikel.Columns[0].Visible = false; this.dGArtikel.Columns[2].HeaderText = "Bezeichnung"; this.dGArtikel.Columns.Add("Anzahl", "Anzahl"); this.dGArtikel.ClearSelection(); this.dGArtikel.CurrentCell = this.dGArtikel.Rows[0].Cells[3]; } private void buttonAbbrechen_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } private void buttonSpeichern_Click(object sender, EventArgs e) { int[] save; if(kunde == null) { MessageBox.Show("Auftrag kann nicht gespeichert werden. Kein Kunde vorhanden.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.textBoxKndNr.Focus(); return; } //Bei Auftrag BEARBEITEN ist AUFTRAG nicht null. Wenn NEUER AUFTRAG dann AUFTRAG erzeugen. if (Auftrag == null) { Auftrag = new Auftrag(); //Wenn Kundename händisch eingegeben dann wird DIV ZIELKUNDE genommen und KUNDENAME in ZUSATZINFO. if (kunde.Suchtext == this.textBoxKundeName.Text) { Auftrag.ZusatzInfo = kunde.Suchtext; } } //AUFTRAG DATEN ÜBERGEBEN Auftrag.KundeID = (int)kunde.KundeID; Auftrag.Liefertag = this.dTPLiefertag.Value; Auftrag.Container = int.Parse(this.labelContainer.Text); Auftrag.ErstelltVon = (int)this.benutzer.BenutzerID; Auftrag.Erstellt = DateTime.Now; Auftrag.Container = int.Parse(this.labelContainer.Text); Auftrag.Typ = (AuftragTyp)comboBoxTyp.SelectedItem; if (maschine != null) Auftrag.MaschineID = (int)maschine.MaschineID; else Auftrag.MaschineID = 0; //BEI BENUTZER WASCHSTRASSE DEAKTIVIERT if(benutzer.Rolle != BenutzerRolle.Waschstrasse) { if (!string.IsNullOrWhiteSpace(this.comboBoxAufgabe.Text)) Auftrag.AufgabeID = Aufgabe.GetAufgabeID(this.comboBoxAufgabe.Text); else if (meldung.NoAufgabe() == DialogResult.OK) { this.comboBoxAufgabe.Focus(); return; } if (!string.IsNullOrWhiteSpace(textBoxZusatz.Text)) Auftrag.ZusatzInfo = this.textBoxZusatz.Text; if (!string.IsNullOrWhiteSpace(this.comboBoxBenutzer.Text)) Auftrag.ArbeiterID = this.comboBoxBenutzer.SelectedItem != null ? (int?)((Benutzer)this.comboBoxBenutzer.SelectedItem).BenutzerID : null; } if (benutzer.Rolle == BenutzerRolle.Verwaltung || benutzer.Rolle == BenutzerRolle.Admin) Auftrag.Status = AuftragStatus.Herrichten; else Auftrag.Status = AuftragStatus.Aufgelegt; //Wenn SONDERAUFTRAG(STH,STV,INV) dann ARTIKEL speichern. if (Auftrag.Typ == AuftragTyp.Sonder) { foreach (DataGridViewRow artikel in this.dGArtikel.Rows) { if (artikel.Cells[0].Value != null) { AuftragArtikel = new AuftragArtikel(); AuftragArtikel.AuftragID = Auftrag.AuftragID; AuftragArtikel.ArtikelNR = (int)artikel.Cells[2].Value; AuftragArtikel.ArtikelName = artikel.Cells[3].Value.ToString(); AuftragArtikel.Anzahl = int.Parse(artikel.Cells[0].Value.ToString()); AuftragArtikel.Erledigt = false; AuftragArtikel.Save(); } } //Speichern von AUFTRAG save = Auftrag.Save(); } else { if (!extra) { this.fach.KundeID = Auftrag.KundeID; this.fach.Lieferdatum = Auftrag.Liefertag; this.fach.Liefertag = (Liefertag)Auftrag.Liefertag.DayOfWeek; if (extraAuftrag == null) { this.fach.ExtraAuftragID = null; this.fach.ExtraKundeID = null; } else { this.fach.ExtraAuftragID = extraAuftrag.AuftragID; this.fach.ExtraKundeID = extraAuftrag.KundeID; } this.fach.Gewaschen = (DateTime)Auftrag.Erstellt; FormFachBearbeiten fachbearb = new FormFachBearbeiten(this.Auftrag ,this.fach); if (fachbearb.ShowDialog() == DialogResult.OK) { this.fach = fachbearb.fach; //Speichern von AUFTRAG save = Auftrag.Save(); } this.fach.AuftragID = Auftrag.AuftragID; } else save = Auftrag.Save(); } this.DialogResult = DialogResult.OK; this.Close(); } private void textBoxZusatz_TextChanged(object sender, EventArgs e) { this.label1.Text = this.textBoxZusatz.Text.Length.ToString() + "/" + this.textBoxZusatz.MaxLength.ToString(); } private void Container_Click(object sender, EventArgs e) { PictureBox pb = (PictureBox)sender; int 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(); } private void labelContainer_TextChanged(object sender, EventArgs e) { if (this.labelContainer.Text == "0") { this.pictureBoxMinus.Enabled = false; this.pictureBoxMinus.BackColor = Color.Gray; } else { this.pictureBoxMinus.Enabled = true; this.pictureBoxMinus.BackColor = Color.Red; } } //Liefertag oder Lieferdatum Funktionen. private void dTPLiefertag_Leave(object sender, EventArgs e) { foreach (RadioButton liefertag in this.Controls.OfType()) { 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()) { 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 textBoxKndNr_Click(object sender, EventArgs e) { this.textBoxKndNr.Clear(); //Process.Start("C:\\Windows\\WinSxS\\amd64_microsoft-windows-osk_31bf3856ad364e35_10.0.22621.3672_none_8a93c823d58f9d77\\osk.exe"); } //Wenn die Textbox verlassen wird, wir die Eingabe überprüft und weiter Schritte eingeleitet private void textBoxKndNr_Leave(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(textBoxKndNr.Text)) { //kunde = Kunde.GetKunde(textBoxKndNr.Text, null, null); if (Kunde.GetKunde(textBoxKndNr.Text, null, null) == null) { if (MessageBox.Show($"Kunde konnte nicht gefunden werden. Möchtest du in der Liste suchen?", "Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { FormListe liste = new FormListe(null, true); if (liste.ShowDialog() == DialogResult.OK) { kunde = liste.kunde; } } else { this.textBoxKndNr.Clear(); this.textBoxKndNr.Focus(); return; } } else this.kunde = Kunde.GetKunde(textBoxKndNr.Text, null, null); textBoxKndNr.Text = kunde.KundeNummer; textBoxKundeName.Text = kunde.Suchtext; textBoxKundeName.Enabled = false; string sortNr = kunde.KundeNummer; Load_Gridview(sortNr); } else { if (textBoxKndNr.Focused) { if (MessageBox.Show($"Möchtest du den Kunden händisch eingeben?", "Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.textBoxKundeName.Focus(); kunde = null; } } } } //Wird verwendet wenn ein zusätzlicher Auftrag(Kunde) in ein Fach gelegt wird private void buttonExtraKunde_Click(object sender, EventArgs e) { FormNeuerAuftrag nauftrag = new FormNeuerAuftrag(benutzer, maschine, true, this.extraAuftrag, null); if (nauftrag.ShowDialog() == DialogResult.OK) { this.extraAuftrag = nauftrag.Auftrag; } } //Wenn der Kunde nicht gefunden wird und händisch eingegeben wird, wird beim verlassen der Textbox der Kunde als DIV ZIELKUNDE erstellt. //Der individuelle Kundename wird als KUNDE.SUCHTEXT eingetragen aber nicht gespeichert. private void textBoxKundeName_Leave(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(textBoxKundeName.Text)) { kunde = Kunde.GetKunde("2300000", null, null); kunde.Suchtext = this.textBoxKundeName.Text; } } //Wenn mit TAB aus Textbox gesprungen wird, wird Focus auf TEXTBOX KUNDENAME gelegt. (Dadurch wird Fehlermeldung aktiviert) private void textBoxKndNr_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyValue == 9) textBoxKundeName.Focus(); } } }