Programm_Wirl/AA-Forms/FormAusschlager.cs

296 lines
9.9 KiB
C#

using DatenDB;
using Deckungsbeitrag.AA_Klassen;
using Deckungsbeitrag.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.Xml.Serialization;
namespace Deckungsbeitrag
{
public partial class FormAusschlager : Form
{
private Fehlermeldungen meldung = new Fehlermeldungen();
private Auftrag auftrag;
public Maschine maschine;
public List<Fach> fachliste;
bool maximised = false;
int height;
Point loc;
public bool ws1transport = false;
public bool ws2transport = false;
private string Userid { get; }
public FormAusschlager()
{
InitializeComponent();
}
public FormAusschlager(string userid) : this()
{
this.Userid = userid;
if (userid.Contains("01")) this.maschine = Maschine.GetMaschine(null, "Waschstrasse 1");
if (userid.Contains("02")) this.maschine = Maschine.GetMaschine(null, "Waschstrasse 2");
}
private void FormAusschlager_Load(object sender, EventArgs e)
{
// WaitCursor und Controls ausblenden.
this.Cursor = Cursors.WaitCursor;
Funktionen.HideControls(this.Controls);
this.BackColor = Properties.Settings.Default.Wirlblau;
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
if (maschine.TrocknerKaputt) this.tableLayoutPanelWS.RowCount = maschine.Faecher - 1;
else this.tableLayoutPanelWS.RowCount = maschine.Faecher;
this.tableLayoutPanelWS.ColumnCount = 4;
Get_TableLayoutPanel(this.tableLayoutPanelWS);
Load_TableLayoutPanel(this.tableLayoutPanelWS);
//DefaultCursor und Controls einblenden.
Funktionen.ShowControls(this.Controls);
this.Cursor = Cursors.Default;
}
private void Load_TableLayoutPanel(TableLayoutPanel tlp)
{
// Fachliste für Maschine holen.
List<WSFach> fachliste = WSFach.GetFachliste(this.maschine);
if (fachliste.Count > 0)
{
// Alle Zellen einer Spalte durchlaufen
int columnIndex = 1;
for (int row = 0; row < tlp.RowCount; row++)
{
Control cellControl = tlp.GetControlFromPosition(columnIndex, row);
if (cellControl != null && cellControl is Label lbl)
{
// Label in Zelle (col=2, row) bearbeiten
lbl.BackColor = Color.LightBlue;
lbl.Text = $"Col {columnIndex} Row {row}";
}
}
}
else { meldung.MaschineIstLeer(null); }
}
/// <summary>
/// Label in jede Zelle des Panels einfügen und mit Schriftfarben aus den Settings versehen. Fach Label hat auch Text erhalten.
/// </summary>
/// <param name="tlp"></param>
private void Get_TableLayoutPanel(TableLayoutPanel tlp)
{
int rows = tlp.RowCount;
int cols = tlp.ColumnCount;
// Alle Spalten und Zeilen Styles entfernen.
tlp.ColumnStyles.Clear();
tlp.RowStyles.Clear();
// Labels in jeder Zelle erstellen
for (int row = 0; row < rows; row++)
{
// Reihen gleichmäßig am Screen verteilen.
tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 100F / rows));
for (int col = 0; col < cols; col++)
{
tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute));
Label lbl = new Label();
lbl.Name = $"Zeile {row}, Spalte {col}";
lbl.Dock = DockStyle.Fill;
lbl.Tag = Tuple.Create(row, col);
lbl.BackColor = Color.Transparent;
// Content Alignment pro Spalte festlegen.
switch (col)
{
case 0:
lbl.TextAlign = ContentAlignment.MiddleRight;
lbl.Text = "Fach";
break;
case 1:
lbl.TextAlign = ContentAlignment.MiddleCenter;
lbl.Text = "Kunde";
break;
case 2:
lbl.TextAlign = ContentAlignment.MiddleLeft;
lbl.Text = "Liefertag";
break;
case 3:
lbl.TextAlign = ContentAlignment.MiddleLeft;
lbl.Text = "Aufgabe";
break;
default:
break;
}
// Schriftfarbe nach Fachzahl zuordnen.
if(this.maschine.Bezeichnung == "Waschstrasse 1")
{
switch (row)
{
case int n when (n <= 4):
lbl.ForeColor = Config.FarbenConfig.Farben["Beladeband"];
if (lbl.Text == "Fach") lbl.Text = $"F";
break;
case int n when (n >= 5 && n <= 13):
lbl.ForeColor = Config.FarbenConfig.Farben["Waschstrasse"];
if (lbl.Text == "Fach") lbl.Text = $"W";
break;
case int n when (n == 14):
lbl.ForeColor = Config.FarbenConfig.Farben["Presse"];
if (lbl.Text == "Fach") lbl.Text = $"P";
break;
case int n when (n == 15):
lbl.ForeColor = Config.FarbenConfig.Farben["Hubband"];
if (lbl.Text == "Fach") lbl.Text = $"H";
break;
case int n when (n == 16):
lbl.ForeColor = Config.FarbenConfig.Farben["Trockner"];
if (lbl.Text == "Fach") lbl.Text = $"T";
break;
case int n when (n == 17):
if (maschine.TrocknerKaputt) { lbl.ForeColor = Config.FarbenConfig.Farben["Entladeband"]; if (lbl.Text == "Fach") lbl.Text = $"E"; }
else { lbl.ForeColor = Config.FarbenConfig.Farben["Trockner"]; if (lbl.Text == "Fach") lbl.Text = $"T"; }
break;
case int n when (n == 18):
lbl.ForeColor = Config.FarbenConfig.Farben["Entladeband"];
if (lbl.Text == "Fach") lbl.Text = $"E";
break;
default:
break;
}
}
if(this.maschine.Bezeichnung == "Waschstrasse 2")
{
switch (row)
{
case int n when (n <= 5):
lbl.ForeColor = Config.FarbenConfig.Farben["Beladeband"];
if (lbl.Text == "Fach") lbl.Text = $"F";
break;
case int n when (n >= 6 && n <= 17):
lbl.ForeColor = Config.FarbenConfig.Farben["Waschstrasse"];
if (lbl.Text == "Fach") lbl.Text = $"W";
break;
case int n when (n == 18):
lbl.ForeColor = Config.FarbenConfig.Farben["Presse"];
if (lbl.Text == "Fach") lbl.Text = $"P";
break;
case int n when (n == 19):
lbl.ForeColor = Config.FarbenConfig.Farben["Hubband"];
if (lbl.Text == "Fach") lbl.Text = $"H";
break;
case int n when (n == 20):
lbl.ForeColor = Config.FarbenConfig.Farben["Trockner"];
if (lbl.Text == "Fach") lbl.Text = $"T";
break;
case int n when (n == 21):
if (maschine.TrocknerKaputt) { lbl.ForeColor = Config.FarbenConfig.Farben["Entladeband"]; if (lbl.Text == "Fach") lbl.Text = $"E"; }
else { lbl.ForeColor = Config.FarbenConfig.Farben["Trockner"]; if (lbl.Text == "Fach") lbl.Text = $"T"; }
break;
case int n when (n == 22):
lbl.ForeColor = Config.FarbenConfig.Farben["Entladeband"];
if (lbl.Text == "Fach") lbl.Text = $"E";
break;
default:
break;
}
}
// Schriftgröße an Zellenhöhe anpassen.
lbl.Font = Funktionen.Get_Label_Font(lbl.Font, lbl.Text, GetCellSizeInPixels(tlp, cols, rows));
tlp.Controls.Add(lbl, col, row);
}
}
}
public void Form_Refresh(Maschine ms, SPSDaten spsdaten)
{
}
private void FormAusschlager_SizeChanged(object sender, EventArgs e)
{
}
private void FormAusschlager_ResizeEnd(object sender, EventArgs e)
{
}
/// <summary>
/// Umrechnen der Prozentgröße der Zeile in Pixelhöhe (int).
/// </summary>
/// <param name="tlp"></param>
/// <param name="column"></param>
/// <param name="row"></param>
/// <returns></returns>
public static Size GetCellSizeInPixels(TableLayoutPanel tlp, int column, int row)
{
float colPercent = 0;
float rowPercent = tlp.RowStyles[0].Height;
int pixelWidth = colPercent == 0 ? 0 : (int)(tlp.Width * (colPercent / 100f));
int pixelHeight = rowPercent == 0 ? 0 : (int)(tlp.Height * (rowPercent / 100f));
return new Size(pixelWidth, pixelHeight);
}
/// <summary>
/// KEIN VERWEIS NOTWENDIG
/// Wenn ESC gedrückt wird schließt sich das Fenster.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected override bool ProcessDialogKey(Keys keyData)
{
if (Form.ModifierKeys == Keys.None && keyData == Keys.Escape)
{
this.Close();
return true;
}
if (Form.ModifierKeys == Keys.None && keyData == Keys.Insert)
{
Open_NeuerAuftrag();
return true;
}
return base.ProcessDialogKey(keyData);
}
private void Open_NeuerAuftrag()
{
FormNeuerAuftrag neuerAuftrag = new FormNeuerAuftrag(this.Userid);
if (neuerAuftrag.ShowDialog() == DialogResult.OK)
{
this.auftrag = neuerAuftrag.Auftrag;
}
}
//TODO: Wenn NeuerAuftrag gewählt wie gehts weiter?
//TODO: Bei Transport wir ein Fach mit Aktuellem Auftrag erstellt. Das Alte wird bei Transport gespeichert.
//TODO: Wenn NeuerAuftrag gewählt Fach ändern nicht vergessen.
//TODO: Eventuell einen "Nächsten Auftrag" erstellen damit im Vorraus erstellt werden kann?
}
}