using DatenDB; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Deckungsbeitrag { public partial class FormFachBearbeiten : Form { Point formcenter; public Kunde kunde = null; public Kunde extrakunde = null; public Fach fach = null; Benutzer benutzer; Maschine maschine; public Fehlermeldungen fm; private Auftrag auftrag; public FormFachBearbeiten() { InitializeComponent(); formcenter = new Point(this.Width / 2, this.Height / 2); fm = new Fehlermeldungen(); Load_comboBoxes(); } public FormFachBearbeiten(Label btn, Benutzer person, Maschine maschine) : this() { this.benutzer = person; this.maschine = maschine; this.fach = (Fach)btn.Tag; this.kunde = Kunde.GetKunde(string.Empty, fach.KundeID, string.Empty); //this.Location = new Point(btn.Parent.Location.X + formcenter.X, btn.Parent.Location.Y + formcenter.Y); this.Text = btn.Name + " bearbeiten"; } public FormFachBearbeiten(Auftrag auftrag, Fach fach) : this() { this.auftrag = auftrag; this.fach = fach; } private void FormFachBearbeiten_Load(object sender, EventArgs e) { //WIRD DURCH NEUE REGEL ERSETZT siehe unten //if (Kunde.GetKunde(string.Empty, fach.KundeID, string.Empty).Suchtext == "?") this.labelFach.Text = Auftrag.GetAuftrag(fach.AuftragID).ZusatzInfo; //else this.labelFach.Text = Kunde.GetKunde(string.Empty, fach.KundeID, string.Empty).Suchtext; if (this.fach.ExtraKundeID != null) { this.labelFach.Text = Auftrag.GetAuftrag(fach.ExtraAuftragID).ZusatzInfo; this.comboBoxExtra.SelectedIndex = this.comboBoxExtra.FindString("Extra Kunde"); this.comboBoxExtra.Enabled = this.buttonExtraEnt.Enabled = false; this.buttonExtraEnt.BackColor = Color.Gray; } else this.labelFach.Text = Kunde.GetKunde(string.Empty, fach.KundeID, string.Empty).Suchtext; this.labelLT.Text = fach.Liefertag.ToString(); foreach (WProgramm prog in comboBoxPrNr.Items) { if (prog.WprogrammID == fach.WProgrammID) this.comboBoxPrNr.SelectedItem = prog; this.textBoxPrBez.Text = prog.Bezeichnung; } foreach (Aufgabe auf in comboBoxExtra.Items) if (auf.AufgabeID == fach.Extra) this.comboBoxExtra.SelectedItem = auf; } private void buttonSpeichern_Click(object sender, EventArgs e) { this.fach.Extra = comboBoxExtra.SelectedIndex == -1 ? (int?)null : ((Aufgabe)comboBoxExtra.SelectedItem).AufgabeID; if (this.fach.Extra != null) { if (((Aufgabe)comboBoxExtra.SelectedItem).Bezeichnung == "Extra Kunde") { //FormListe liste = new FormListe(null, true); //if (liste.ShowDialog() == DialogResult.OK) { extrakunde = liste.kunde; } //this.fach.ExtraKundeID = extrakunde.KundeID; //FormNeuerAuftrag liste = new FormNeuerAuftrag(benutzer, maschine, true, null); //if (liste.ShowDialog() == DialogResult.OK) //{ // this.fach.ExtraKundeID = liste.kunde.KundeID; // this.fach.ExtraAuftragID = liste.Auftrag.AuftragID; // this.fach.Lieferdatum = liste.Auftrag.Liefertag; //} } } this.fach.WProgrammID = (int)((WProgramm)comboBoxPrNr.SelectedItem).WprogrammID; this.fach.Save(); this.DialogResult = DialogResult.OK; this.Close(); } //AUSPROGRAMMIEREN private void buttonExtraEnt_Click(object sender, EventArgs e) { this.comboBoxExtra.SelectedIndex = -1; } private void buttonAbbrechen_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } private void comboBoxExtra_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxExtra.SelectedIndex == -1) comboBoxExtra.Text = "EXTRA"; else if (((Aufgabe)comboBoxExtra.SelectedItem).Bezeichnung == "Extra Kunde") { MessageBox.Show(fm.NoExtraKunde(), "ACHTUNG", MessageBoxButtons.OK, MessageBoxIcon.Error); this.comboBoxExtra.SelectedIndex = -1; } //this.Focus(); } //AUSPROGRAMMIEREN private void Load_comboBoxes() { List aufgabenlist1 = Aufgabe.GetList(3); List programmlist = WProgramm.GetList(); this.comboBoxExtra.DataSource = aufgabenlist1; this.comboBoxExtra.DisplayMember = "Bezeichnung"; this.comboBoxExtra.SelectedIndex = -1; this.comboBoxExtra.Text = "EXTRA"; this.comboBoxPrNr.DataSource = programmlist; this.comboBoxPrNr.DisplayMember = "Nummer"; this.comboBoxPrNr.SelectedIndex = -1; } private void Extra_comboBox_Leave(object sender, EventArgs e) { ComboBox cb = (ComboBox)sender; if (cb.SelectedItem != null && cb.SelectedItem.GetType() == typeof(Aufgabe)) { Aufgabe aufg = (Aufgabe)cb.SelectedItem; if (aufg.Bezeichnung == "Extra Kunde") { MessageBox.Show(fm.NoExtraKunde()); //FormNeuerAuftrag liste = new FormNeuerAuftrag(benutzer, maschine, true, null); //if (liste.ShowDialog() == DialogResult.OK) //{ // extrakunde = liste.kunde; //} } } } //Wenn die ComboBox verlassen wird und "Extra Kunde" gewählt ist. Öffnet sich Kundenliste um Extra Kunde zu wählen. private void FormFachBearbeiten_KeyUp(object sender, KeyEventArgs e) { if (e.Shift) { switch (e.KeyCode) { case Keys.F10: break; case Keys.F5: FormListe liste = new FormListe(null, 0); if (liste.ShowDialog() == DialogResult.OK) { kunde = liste.kunde; FormFachBearbeiten_Load(this, null); } break; case Keys.E: int last = comboBoxExtra.Items.Count - 1; if (comboBoxExtra.SelectedIndex < last) comboBoxExtra.SelectedIndex++; else comboBoxExtra.SelectedIndex = 0; break; case Keys.T: break; case Keys.D: break; case Keys.P: int lastpr = comboBoxPrNr.Items.Count - 1; if (comboBoxPrNr.SelectedIndex < lastpr) comboBoxPrNr.SelectedIndex++; else comboBoxPrNr.SelectedIndex = 0; break; case Keys.Delete: buttonExtraEnt_Click(this, null); break; default: break; } } } private void comboBox_MouseClick(object sender, MouseEventArgs e) { ComboBox cb = (ComboBox)sender; cb.DroppedDown = true; } } }