Programm_Wirl/AA-Forms/FormAuftragAuswahl.cs

209 lines
6.5 KiB
C#

using DatenDB;
using Deckungsbeitrag.AA_Klassen;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VirtualKeyboard;
using static System.Net.Mime.MediaTypeNames;
namespace Deckungsbeitrag.AA_Forms
{
public partial class FormAuftragAuswahl : Form
{
private ArtikelKategorie Abteilung;
private List<View_Auftrag_Expedit> Auftragliste;
private QwertzKeyboard keyboard;
public Kunde kunde;
public Auftrag auftrag;
private Screen screen = Screen.PrimaryScreen;
private bool _keyboardVisible;
public bool KeyBoardVisible
{
get { return _keyboardVisible; }
set
{
_keyboardVisible = value;
if (KeyBoardVisible)
{
this.Width = screen.WorkingArea.Width;
this.Height = (int)(screen.WorkingArea.Height * 0.55);
this.Location = new Point(0, 0);
this.panelAuswahl.Height = this.Bottom - this.panelSuchen.Bottom - 20;
}
else
{
this.Width = screen.WorkingArea.Width;
this.Height = screen.WorkingArea.Height;
this.Location = new Point(0, 0);
this.panelAuswahl.Height = this.Bottom - this.panelSuchen.Bottom - 20;
}
}
}
public FormAuftragAuswahl()
{
InitializeComponent();
switch (ConfigurationManager.AppSettings["ConnectionString"].Split(';')[0].Split('=')[1])
{
case var t when t.Contains("frottee"): Abteilung = ArtikelKategorie.Frottee; break;
case var t when t.Contains("kleinteile"): Abteilung = ArtikelKategorie.Kleinteile; break;
case var t when t.Contains("grossteile"): Abteilung = ArtikelKategorie.Grossteile; break;
case var t when t.Contains("spannleintuch"): Abteilung = ArtikelKategorie.Spannleintuch; break;
default: break; //TODO: Default Zuweisung löschen bevor in Echtbetrieb.
}
}
private async void FormAuftragAuswahl_Load(object sender, EventArgs e)
{
new TouchScroll(panelAuswahl);
await GetAuftragliste();
Load_PanelAuswahl(this.Auftragliste);
}
private async Task GetAuftragliste()
{
this.Auftragliste = await View_Auftrag_Expedit.GetAuftragExpeditAsync(statusFilter: AuftragStatus.Gewaschen, kategorie: Abteilung);
}
private async void Load_PanelAuswahl(List<View_Auftrag_Expedit> _liste)
{
this.panelAuswahl.Controls.Clear();
_liste = _liste.OrderBy(x => x.KundeName).ToList();
foreach (View_Auftrag_Expedit item in _liste)
{
string name = string.Empty;
if (item.KundeName.Length > 15) name = item.KundeName.Substring(0, 15) + "...";
else name = item.KundeName;
Label lbl = new Label()
{
Text = name,
BackColor = Color.Silver,
BorderStyle = BorderStyle.FixedSingle,
Font = new Font("Microsoft Sans Serif", 20, FontStyle.Bold),
Size = new Size(400, 70),
TextAlign = ContentAlignment.MiddleCenter,
Margin = new Padding(5, 5, 5, 5),
Padding = new Padding(15, 15, 15, 15),
Tag = item
};
lbl.MouseClick += LabelAuftrag_MouseClick;
lbl.MouseEnter += LabelAuftrag_MouseEnter;
lbl.MouseLeave += LabelAuftrag_MouseLeave;
panelAuswahl.Controls.Add(lbl);
}
}
private void LabelAuftrag_MouseLeave(object sender, EventArgs e)
{
Label lbl = sender as Label;
lbl.BackColor = Color.Silver;
}
private void LabelAuftrag_MouseEnter(object sender, EventArgs e)
{
Label lbl = sender as Label;
lbl.BackColor = Color.YellowGreen;
}
private void LabelAuftrag_MouseClick(object sender, MouseEventArgs e)
{
Label lbl = sender as Label;
View_Auftrag_Expedit exAuftrag = (View_Auftrag_Expedit)lbl.Tag;
if (e.Button == MouseButtons.Right)
{
if (MessageBox.Show($"Möchtest du den Auftrag vom Kunde {exAuftrag.KundeName} mit Liefertag {exAuftrag.Liefertag:d} auswählen?", "FRAGE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
}
this.kunde = Kunde.GetKunde(null, exAuftrag.KundeID, null);
this.auftrag = Auftrag.GetAuftrag(exAuftrag.AuftragID);
this.DialogResult = DialogResult.OK;
this.Close();
}
private async void TextBoxKunde_TextChanged(object sender, EventArgs e)
{
TextBox textbox = sender as TextBox;
string text = textbox.Text.Trim().ToLower();
this.Auftragliste = await View_Auftrag_Expedit.GetAuftragExpeditAsync(statusFilter: AuftragStatus.Gewaschen, kategorie: Abteilung, undFertig: true);
if (!string.IsNullOrWhiteSpace(text))
{
var filtered = string.IsNullOrWhiteSpace(text) ? this.Auftragliste : this.Auftragliste.Where(x => x.KundeName != null && x.KundeName.ToLower().Contains(text)).ToList();
Load_PanelAuswahl(filtered);
}
else Load_PanelAuswahl(this.Auftragliste);
}
private void TextBoxKunde_Click(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
tb.Clear();
tb.ForeColor = Color.Black;
keyboard = Funktionen.OpenVirtualKeyboard(sender);
keyboard.KeyBoardShown += KeyBoardShown;
keyboard.KeyBoardClosed += KeyBoardClosed;
this.BeginInvoke(new Action(() =>
{
if (!tb.IsDisposed && tb.CanFocus)
{
tb.Focus();
tb.SelectAll();
}
}));
}
private void KeyBoardClosed(object sender, EventArgs e)
{
KeyBoardVisible = false;
}
private void KeyBoardShown(object sender, EventArgs e)
{
KeyBoardVisible = true;
}
private void FormAuftragAuswahl_Shown(object sender, EventArgs e)
{
this.Width = screen.WorkingArea.Width;
this.Height = screen.WorkingArea.Height;
this.Location = new Point(0, 0);
this.panelAuswahl.Height = this.Bottom - this.panelSuchen.Bottom - 20;
}
private async void buttonAbbrechen_Click(object sender, EventArgs e)
{
this.textBoxKunde.Clear();
this.textBoxKunde.ForeColor = Color.Silver;
this.textBoxKunde.Text = "Kunde suchen";
await GetAuftragliste();
Load_PanelAuswahl(this.Auftragliste);
}
private void FormAuftragAuswahl_FormClosing(object sender, FormClosingEventArgs e)
{
if (this.kunde == null & this.auftrag == null) this.DialogResult = DialogResult.Cancel;
}
}
}