Programm_Wirl/AA-Klassen/Funktionen.cs

1645 lines
67 KiB
C#

using AForge.Video.DirectShow;
using BrightIdeasSoftware;
using DatenDB;
using Deckungsbeitrag.AA_Klassen;
using Deckungsbeitrag.Properties;
using Deckungsbeitrag.UserControls;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Printing;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using ZXing;
using ZXing.QrCode.Internal;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
using Control = System.Windows.Forms.Control;
namespace Deckungsbeitrag
{
public class Funktionen
{
private static FilterInfoCollection videoDevices;
public static Color beladeband = Settings.Default.Beladeband; public static Color waschstr = Settings.Default.Waschstrasse; public static Color presse = Settings.Default.Presse; public static Color trockner = Settings.Default.Trockner;
public static Color entladeband = Settings.Default.Entladeband; public static Color hubband = Settings.Default.Hubband;
public static Auftrag _auftrag;
public static Kunde _adresse;
private static int currentPage = 0;
private static int pagesToPrint = 1;
private static bool _nocont;
private static Meldungen meldung = new Meldungen();
private static List<Auftrag> _auftragliste;
private static Benutzer _fahrer;
private static Benutzer _benutzer;
private static PrintDocument printdoc;
public static bool IsPhysicalPrint = false; // Globaler Schalter
static Dictionary<string, int[]> _dictionary;
public Funktionen()
{
}
public static HeaderFormatStyle GetHeader()
{
HeaderFormatStyle headerFormat = new HeaderFormatStyle();
headerFormat.SetBackColor(Properties.Settings.Default.Wirlblau);
headerFormat.SetForeColor(Color.White);
headerFormat.SetFont(new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold));
headerFormat.Hot.BackColor = Color.SteelBlue;
headerFormat.Pressed.BackColor = Color.DimGray;
return headerFormat;
}
public static Font GetFontSizeByWidth(Font font, string text, float width)
{
Font f = font;
if (!string.IsNullOrEmpty(text))
{
float textwidth = TextRenderer.MeasureText(text, f).Width;
while (width < TextRenderer.MeasureText(text, f).Width)
{
f = new Font(font.FontFamily, f.Size - 1);
}
}
return f;
}
public static Font Get_Label_Font(Font font, string text, Size size)
{
Font f = font;
Size s = size;
if (!string.IsNullOrEmpty(text))
{
while (s.Height > TextRenderer.MeasureText(text, f).Height)
{
f = new Font(font.FontFamily, f.Size + 1);
}
}
return f;
}
public Label[] GetFachLabels(int fach, Maschine maschine, int height, Point loc, int width, string screen)
{
Label[] labels = new Label[5];
Label extra = new Label();
Label lblkunde = new Label();
Label label = new Label();
Label lbltag = new Label();
Label lblpro = new Label();
lblpro.Tag = extra.Tag = label.Tag = lbltag.Tag = lblkunde.Tag = Fach.GetFach(maschine.MaschineID, fach);
lblpro.AutoSize = extra.AutoSize = label.AutoSize = lbltag.AutoSize = lblkunde.AutoSize = false;
lblpro.Height = extra.Height = label.Height = lbltag.Height = lblkunde.Height = height;
lblpro.Font = extra.Font = label.Font = lbltag.Font = lblkunde.Font = new Font("Microsoft Sans Serif", height / 3);
lblkunde.Name = $"Kunde {fach}";
if (Kunde.GetKunde(string.Empty, ((Fach)lblkunde.Tag).KundeID, string.Empty).Suchtext == "?") lblkunde.Text = Auftrag.GetAuftrag(((Fach)lblkunde.Tag).AuftragID).ZusatzInfo;
else lblkunde.Text = Kunde.GetKunde(string.Empty, ((Fach)lblkunde.Tag).KundeID, string.Empty).Suchtext;
if (lblkunde.Text == string.Empty) lblkunde.Text = Kunde.GetKunde(string.Empty, ((Fach)lblkunde.Tag).KundeID, string.Empty).KundeName;
lblkunde.TextAlign = ContentAlignment.MiddleCenter;
if (width < 1500) lblkunde.Width = 400;
else lblkunde.Width = 600;
lbltag.Name = $"Tag {fach}";
if (((Fach)lbltag.Tag).Lieferdatum == null) lbltag.Text = Liefertag.SO.ToString();
else lbltag.Text = ((Liefertag)((DateTime)((Fach)lbltag.Tag).Lieferdatum).DayOfWeek).ToString();
if (lbltag.Text == string.Empty) lbltag.Text = "SO";
lbltag.TextAlign = ContentAlignment.MiddleLeft;
label.Name = $"Fach {fach}";
label.TextAlign = ContentAlignment.MiddleRight;
///SchriftFarben für Fächer zuordnen.
///Unterschied zwischen Waschstrasse 1 & 2.
int i = fach;
if (maschine.Bezeichnung == "Waschstrasse 1")
{
if (i <= 4)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = beladeband;
label.Text = $"F{i}";
} // Beladeband
if (i >= 5 & i <= 13)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = waschstr;
label.Text = $"W{i - 4}";
} // Waschstraße
if (i == 14)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = presse;
label.Text = $"P";
} // Presse
if (i == 15)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = hubband;
label.Text = $"H";
} // Hubband
if(maschine.TrocknerKaputt == false)
{
if (i == 16 || i == 17)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = trockner;
label.Text = $"T";//{i - 15}";
} // Trockner
if (i == 18)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = entladeband;
label.Text = $"S";
} // Entladeband
}
else
{
if (i == 16)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = trockner;
label.Text = $"T"; // {i - 15}";
} // Trockner
if (i == 17)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = entladeband;
label.Text = $"S";
} // Entladeband
}
}
if (maschine.Bezeichnung == "Waschstrasse 2")
{
if (i <= 5)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = beladeband;
label.Text = $"F{i}";
} // Beladeband
if (i >= 6 & i <= 17)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = waschstr;
label.Text = $"W{i - 4}";
} // Waschstraße
if (i == 18)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = presse;
label.Text = $"P";
} // Presse
if (i == 19)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = hubband;
label.Text = $"H";
} // Hubband
if(maschine.TrocknerKaputt == false)
{
if (i == 20 || i == 21)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = trockner;
label.Text = $"T";// {i - 18}";
} // Trockner
if (i == 22)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = entladeband;
label.Text = $"S";
} // Entladeband
}
else
{
if (i == 20)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = trockner;
label.Text = $"T";// {i - 18}";
} // Trockner
if (i == 21)
{
lbltag.ForeColor = label.ForeColor = lblkunde.ForeColor = entladeband;
label.Text = $"S";
} // Entladeband
}
}
if (((Fach)extra.Tag).Extra != null)
{
extra.Text = Aufgabe.GetAufgabe(string.Empty, ((Fach)extra.Tag).Extra).Bezeichnung;
if (extra.Text == "Extra Kunde") lblkunde.Text = "+" + Kunde.GetKunde(string.Empty, ((Fach)extra.Tag).ExtraKundeID, string.Empty).Suchtext;
lblpro.BackColor = lblkunde.BackColor = lbltag.BackColor = label.BackColor = extra.BackColor = Aufgabe.GetAufgabe(string.Empty, ((Fach)extra.Tag).Extra).Farbe;
lblkunde.ForeColor = lbltag.ForeColor = label.ForeColor = lblpro.ForeColor = Color.Black;
extra.Visible = true;
}
else extra.Visible = false;
lblkunde.Font = Get_Label_Font(lblkunde.Font, lblkunde.Text, lblkunde.Size);
lbltag.Font = Get_Label_Font(lbltag.Font, lbltag.Text, lbltag.Size);
label.Font = Get_Label_Font(label.Font, label.Text, label.Size);
extra.Font = Get_Label_Font(extra.Font, extra.Text, extra.Size);
lbltag.Width = TextRenderer.MeasureText(lbltag.Text, lbltag.Font).Width;
label.Width = TextRenderer.MeasureText(label.Text, label.Font).Width;
lblkunde.Location = new Point(loc.X, loc.Y + height * (i - 1));
lbltag.Location = new Point(lblkunde.Right, lblkunde.Location.Y);
label.Location = new Point(lblkunde.Left - label.Width, lblkunde.Location.Y);
extra.Location = new Point(10, lblkunde.Location.Y);
lblpro.Location = new Point(lblkunde.Right + 100, lblkunde.Location.Y);
extra.Name = $"Extra {maschine.MaschineID} {fach}";
if (width < 1500) extra.Width = width - 0;
else extra.Width = width - 100;
extra.ForeColor = Color.White;
extra.TextAlign = ContentAlignment.MiddleRight;
///Waschprogramme bei Beladeband anzeigen.
///Unterscheidung durch Beladebandfächeranzahl.
lblpro.Name = $"PR {fach}";
lblpro.TextAlign = ContentAlignment.MiddleRight;
lblpro.Text = $"WP {((Fach)lblpro.Tag).WProgrammID}";
lblpro.Font = Get_Label_Font(lblpro.Font, lblpro.Text, lblpro.Size);
lblpro.Width = TextRenderer.MeasureText(lblpro.Text, lblpro.Font).Width;
labels[0] = label;
labels[1] = lblkunde;
labels[2] = lbltag;
labels[3] = lblpro;
labels[4] = extra;
return labels;
}
public static Color Get_Color(Maschine maschine, int i)
{
Color color = new Color();
if (maschine.Bezeichnung == "Waschstrasse 1")
{
if (i <= 4) color = beladeband; // Beladeband
if (i >= 5 & i <= 13) color = waschstr; // Waschstraße
if (i == 14) color = presse; // Presse
if (i == 15) color = hubband; // Hubband
if (maschine.TrocknerKaputt == false)
{
if (i == 16 || i == 17) color = trockner; // Trockner
if (i == 18) color = entladeband; // Entladeband
}
else
{
if (i == 16) color = trockner; // Trockner
if (i == 17) color = entladeband; // Entladeband
}
}
if (maschine.Bezeichnung == "Waschstrasse 2")
{
if (i <= 4) color = beladeband; // Beladeband
if (i >= 5 & i <= 16) color = waschstr; // Waschstraße
if (i == 17) color = presse; // Presse
if (i == 18) color = hubband; // Hubband
if (maschine.TrocknerKaputt == false)
{
if (i == 19 || i == 20) color = trockner; // Trockner
if (i == 21) color = entladeband; // Entladeband
}
else
{
if (i == 19) color = trockner; // Trockner
if (i == 20) color = entladeband; // Entladeband
}
}
return color;
}
public static Label Label_Refresh(Label lbl, Maschine maschine, SPSDaten spsdaten, string screen)
{
int fach = 0;
SPSDaten sps = spsdaten;
if (lbl.Name.Contains("Kunde")) fach = int.Parse(lbl.Name.Substring(6));
if (lbl.Name.Contains("Fach")) fach = int.Parse(lbl.Name.Substring(5));
if (lbl.Name.Contains("Tag")) fach = int.Parse(lbl.Name.Substring(4));
if (lbl.Name.Contains("Extra")) fach = int.Parse(lbl.Name.Substring(8));
if (lbl.Name.Contains("PR")) fach = int.Parse(lbl.Name.Substring(3));
if (!lbl.Name.Contains("WP")) lbl.Tag = Fach.GetFach(maschine.MaschineID, fach);
if (!sps.WS_2_Transport)
{
if (maschine.Bezeichnung == "Waschstrasse 2")
{
if (lbl.Name.Contains("17"))
{
if (sps.Presse2_Leer) lbl.Tag = null;
else lbl.Tag = Fach.GetFach(maschine.MaschineID, 17);
}
if (lbl.Name.Contains("18"))
{
if (sps.Hubband2_Leer) lbl.Tag = null;
else lbl.Tag = Fach.GetFach(maschine.MaschineID, 17);
}
if (lbl.Name.Contains("19"))
{
if (sps.Trockner21_Beladen || sps.Trockner22_Beladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 18);
if (sps.Trockner21_Entladen || sps.Trockner22_Entladen) lbl.Tag = null;
}
if (lbl.Name.Contains("20") & !maschine.TrocknerKaputt)
{
if (sps.Trockner21_Beladen || sps.Trockner22_Beladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 19);
if (sps.Trockner21_Entladen || sps.Trockner22_Entladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 19);
}
if (lbl.Name.Contains("21"))
{
if (!maschine.TrocknerKaputt)
{
if (sps.Trockner21_Entladen || sps.Trockner22_Entladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 20);
}
else
{
if (sps.Trockner21_Entladen || sps.Trockner22_Entladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 19);
}
}
}
}
if (!sps.WS_1_Transport)
{
if (maschine.Bezeichnung == "Waschstrasse 1")
{
if (lbl.Name.Contains("14"))
{
if (sps.Presse1_Leer) lbl.Tag = null;
else lbl.Tag = Fach.GetFach(maschine.MaschineID, 14);
}
if (lbl.Name.Contains("15"))
{
if (sps.Hubband1_Leer) lbl.Tag = null;
else lbl.Tag = Fach.GetFach(maschine.MaschineID, 14);
}
if (lbl.Name.Contains("16"))
{
if (sps.Trockner11_Beladen || sps.Trockner12_Beladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 15);
if (sps.Trockner11_Entladen || sps.Trockner12_Entladen) lbl.Tag = null;
}
if (lbl.Name.Contains("17") & !maschine.TrocknerKaputt)
{
if (sps.Trockner11_Beladen || sps.Trockner12_Beladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 16);
if (sps.Trockner11_Entladen || sps.Trockner12_Entladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 16);
}
if (lbl.Name.Contains("18"))
{
if (!maschine.TrocknerKaputt)
{
if (sps.Trockner11_Entladen || sps.Trockner12_Entladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 17);
}
else
{
if (sps.Trockner11_Entladen || sps.Trockner12_Entladen) lbl.Tag = Fach.GetFach(maschine.MaschineID, 16);
}
}
}
}
if (lbl.Tag == null)
{
if (lbl.Name.Contains("Kunde")) lbl.Text = "LEER";
if (lbl.Name.Contains("Tag")) lbl.Text = " ";
if (lbl.Name.Contains("Extra")) lbl.Visible = false;
//BackColor wird wie Hintergrund und Schriftfarbe wird weiß wenn kein TAG (Extra).
lbl.BackColor = Settings.Default.Wirlblau;
lbl.ForeColor = Color.White;
}
else
{
if (lbl.Name.Contains("Kunde"))
{
if (Kunde.GetKunde(string.Empty, ((Fach)lbl.Tag).KundeID, string.Empty).Suchtext == "?") lbl.Text = Auftrag.GetAuftrag(((Fach)lbl.Tag).AuftragID).ZusatzInfo;
else lbl.Text = Kunde.GetKunde(string.Empty, ((Fach)lbl.Tag).KundeID, string.Empty).Suchtext;
if (lbl.Text == string.Empty) lbl.Text = Kunde.GetKunde(string.Empty, ((Fach)lbl.Tag).KundeID, string.Empty).KundeName;
}
if (lbl.Name.Contains("Tag"))
{
if (((Fach)lbl.Tag).Lieferdatum == null) lbl.Text = Liefertag.SO.ToString();
else lbl.Text = ((Liefertag)((DateTime)((Fach)lbl.Tag).Lieferdatum).DayOfWeek).ToString();
if (lbl.Text == string.Empty) lbl.Text = "SO";
lbl.Width = TextRenderer.MeasureText(lbl.Text, lbl.Font).Width;
}
if (lbl.Name.Contains("PR"))
{
lbl.Text = $"WP {((Fach)lbl.Tag).WProgrammID}";
if (fach == 3) sps.Waschprogramm = ((Fach)lbl.Tag).WProgrammID; //WASCHPROGRAMM FÜR ÜBERGABE IN SPS DATEN ÜBERGEBEN
}
if (((Fach)lbl.Tag).Extra != null)
{
Aufgabe extra = Aufgabe.GetAufgabe(string.Empty, ((Fach)lbl.Tag).Extra);
if (lbl.Name.Contains("Extra"))
{
lbl.ForeColor = Color.White;
lbl.Visible = true;
lbl.Font = Get_Label_Font(lbl.Font, lbl.Text, lbl.Size);
}
else lbl.ForeColor = Color.Black;
if (lbl.Name.Contains("Kunde"))
{
if (extra.Bezeichnung == "Extra Kunde") lbl.Text = "+" + Kunde.GetKunde(String.Empty, ((Fach)lbl.Tag).ExtraKundeID, string.Empty).Suchtext;
}
lbl.BackColor = Aufgabe.GetAufgabe(string.Empty, ((Fach)lbl.Tag).Extra).Farbe;
}
else
{
if (lbl.Name.Contains("Extra")) lbl.Visible = false;
else
{
//if (!lbl.Name.Contains("PR"))
lbl.ForeColor = Get_Color(maschine, fach);
lbl.BackColor = Settings.Default.Wirlblau;
}
}
}
return lbl;
}
public static List<Sortiment> SortimentLesen(string s)
{
StreamReader streamReader = null;
try
{
streamReader = new StreamReader(ConfigurationManager.AppSettings["SortimentPfad"], Encoding.GetEncoding("iso-8859-1"));
}
catch (Exception)
{
MessageBox.Show("Keine Sortiment-Datei gefunden, bitte kontrolliere Pfad und Dateiname!");
return null;
}
int nr = 0;
string row = string.Empty;
Sortiment[] sortiment = new Sortiment[0];
List<Sortiment> sortimentListe = new List<Sortiment>();
int idx = 0;
while (!streamReader.EndOfStream)
{
Array.Resize<Sortiment>(ref sortiment, ++idx);
row = streamReader.ReadLine();
sortiment[idx - 1] = new Sortiment(row, nr);
sortimentListe.Add(new Sortiment(row, nr));
++nr;
}
streamReader.Close();
return sortimentListe;
}
public static List<Artikel> Get_ArtikelKurzlisteFromDatei()
{
StreamReader streamReader = null;
string row = string.Empty;
Artikel[] artikel = new Artikel[0];
List<Artikel> artikelListe = new List<Artikel>();
int idx = 1;
// Datei auswählen.
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "CommaSeparatedFiles|*.txt;*.csv";
dialog.InitialDirectory = "N:\\BÜRO\\SOCOM";
if (dialog.ShowDialog() == DialogResult.OK)
{
if (MessageBox.Show($"Möchtest du die Datei {dialog.FileName} wirklich lesen? Hier können nur Artikel upgedated werden.", "Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
// Datei lesen.
streamReader = new StreamReader(dialog.FileName, Encoding.GetEncoding("iso-8859-1"));
while (!streamReader.EndOfStream)
{
Array.Resize<Artikel>(ref artikel, idx);
row = streamReader.ReadLine();
if (row.StartsWith("60") || row.StartsWith("20"))
{
artikel[idx - 1] = new Artikel(row, idx - 1);
idx++;
}
}
streamReader.Close();
artikelListe.AddRange(artikel);
return artikelListe;
}
catch (Exception)
{
MessageBox.Show("Es ist etwas schief gelaufen. Versuche es bitte nochmals.");
return null;
}
}
else return null;
}
else return null;
}
/// <summary>
/// Die Kundenauswahl erfolgt durch Handeingabe oder Scan mit integrierter Kamera.
/// Wenn Kamera vorhanden und trotzdem Handeingabe notwendig, dann Button klicken.
/// </summary>
/// <returns></returns>
public static Kunde KundenAuswahl()
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
// Wenn Kamera Screen nicht verfügbar sein soll, muss videoDevices null sein.
videoDevices = null;
Kunde kunde;
if (videoDevices == null)
{
kunde = Open_List(null);
}
else
{
//if (meldung.HandEingabe()) this.kunde = Funktionen.Open_List();
//else this.kunde = Funktionen.Open_Kamera(videoDevices);
kunde = Open_Kamera(videoDevices);
}
return kunde;
}
/// <summary>
/// Öffnen der Kundenauswahlliste zur händischen Eingabe bzw. Scan des Kunden.
/// </summary>
/// <returns>Kunde</returns>
public static Kunde Open_List(string kndService)
{
Kunde knd = new Kunde();
FormListe liste = new FormListe(null, 0, kndService);
if (liste.ShowDialog() == DialogResult.OK)
{
knd = liste.kunde;
}
else knd = null;
return knd;
}
/// <summary>
/// Öffnen des Kamera Livebildes zur Eingabe des Kunden über die integrierte Kamera.
/// </summary>
/// <param name="videoDevices"> Array der verfügbaren Kameras</param>
/// <returns>Kunde</returns>
public static Kunde Open_Kamera(AForge.Video.DirectShow.FilterInfoCollection videoDevices)
{
Kunde knd = new Kunde();
FormKamera kamera = new FormKamera(videoDevices);
DialogResult result = kamera.ShowDialog();
switch (result)
{
case DialogResult.None:
knd = null;
break;
case DialogResult.OK:
knd = kamera.kunde;
break;
case DialogResult.Cancel:
knd = null;
break;
case DialogResult.Abort:
knd = null;
break;
case DialogResult.Retry:
knd = null;
break;
case DialogResult.Ignore:
knd = null;
break;
case DialogResult.Yes:
knd = kamera.kunde;
break;
case DialogResult.No:
knd = Open_List(null);
break;
default:
break;
}
return knd;
}
/// <summary>
/// QR-Code für SWS-Scheine und KundeDetail
/// </summary>
/// <param name="kunde"></param>
/// <param name="auftrag"></param>
/// <returns>Image des Codes mit der Kundennummer</returns>
public static Image Get_QR_Code(Kunde kunde, Auftrag auftrag)
{
Image img = null;
BarcodeWriter code = new BarcodeWriter();
code.Format = BarcodeFormat.QR_CODE;
if (kunde.KundeNummer == "2320000") img = code.Write(auftrag.ZusatzInfo);
else img = code.Write(kunde.KundeNummer);
return img;
}
/// <summary>
/// QR-Code für Etikett
/// </summary>
/// <param name="kunde">Der Kunde aus dem Auftrag</param>
/// <param name="auftrag">Der gewählte Auftrag</param>
/// <param name="groesse">Die Größe des Codes (Standart=250)</param>
/// <returns>Eine Bitmap mit dem entsprechenden Code inkl. Beschriftung</returns>
private static Bitmap ErstelleQRMitRahmen(Kunde kunde, Auftrag auftrag, int groesse = 250)
{
string obererText = "Abholung notwendig?";
string untererText = "Scan Me!";
string text = $"https://www.wirl.tirol/kontakt?name={kunde.KundeNummer}%20{kunde.KundeName}";
if (kunde.KundeNummer == "2320000") text = $"https://www.wirl.tirol/kontakt?name={kunde.KundeNummer}%20{auftrag.ZusatzInfo}";
else text = $"https://www.wirl.tirol/kontakt?name={kunde.KundeNummer}%20{kunde.KundeName}&address={kunde.Strasse},%20{kunde.PLZ.ToString()}%20{kunde.Ort}&bettenanzahl={kunde.Bettenanzahl.ToString()}&nachricht=Bitte Wäscheabholung organisieren.";
// QR ohne Margin generieren
var hints = new Dictionary<ZXing.EncodeHintType, object>
{
{ ZXing.EncodeHintType.MARGIN, 0 }
};
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.Common.EncodingOptions { Width = groesse, Height = groesse, Margin = 0 }
};
Bitmap qr = writer.Write(text);
// Größeres Bitmap für Rahmen (z.B. +100px Rand)
int rand = 20;
int textHoehe = 20;
Bitmap erweitert = new Bitmap(qr.Width + 2 * rand, qr.Height + 2 * rand + 2 * textHoehe);
using (Graphics g = Graphics.FromImage(erweitert))
{
g.Clear(Color.White);
// Oberen Text (zentriert)
Font font = new Font("Arial", 18, FontStyle.Bold);
SizeF obTextSize = g.MeasureString(obererText, font);
g.DrawString(obererText, font, Brushes.Black,
(erweitert.Width - obTextSize.Width) / 2,
rand - 10);
// QR zentriert unter oberem Text
int qrY = rand + textHoehe;
g.DrawImage(qr, rand, qrY);
// Rahmen um QR (ohne Textbereiche)
using (Pen pen = new Pen(Color.White, 6))
g.DrawRectangle(pen, rand - 3, qrY - 3, qr.Width + 6, qr.Height + 6);
// Unteren Text (zentriert)
SizeF unTextSize = g.MeasureString(untererText, font);
g.DrawString(untererText, font, Brushes.Black,
(erweitert.Width - unTextSize.Width) / 2,
qrY + qr.Height);
}
return erweitert;
}
/// <summary>
/// DRUCKEN VON SCHMUTZWÄSCHESCHEINEN & ETIKETTEN & TOURENLISTEN
/// </summary>
public static Image SWS_Entwurf(Auftrag auftrag, Kunde adresse)
{
int ezl = 50; int handzeile = 33; float textsize = 10; float textsize2 = 20; int idx = 0; int idx1 = 0; int length = 0;
Bitmap bitmap = new Bitmap(790, 1120);
Graphics g = Graphics.FromImage(bitmap);
Point adressblock = new Point(ezl, 50);
Point tabelle = new Point(ezl, 330);
SizeF textSize2 = g.MeasureString("Salzburg, am 26.08.1984", new Font("Arial", textsize, FontStyle.Regular));
SizeF textSize3 = g.MeasureString("MO", new Font("Arial", textsize2, FontStyle.Regular));
SizeF textSizePos = g.MeasureString("Bemerkung", new Font("Arial", textsize, FontStyle.Regular));
int zeile = (int)textSize2.Height + 20; //PIXEL
int posTag = 145;
if (adresse == null) adresse = Kunde.GetKunde(string.Empty, auftrag.KundeID, string.Empty);
Image qrcode = Get_QR_Code(adresse, null);
string sortNr = string.Empty;
//Innsbrucker Soziale Dienste Sortiment immer gleich.
if (adresse.KundeNummer == "010069" | adresse.KundeNummer == "010071") sortNr = "010068";
else sortNr = adresse.KundeNummer;
//result = sortimentListe.Find(Sortiment => Sortiment.KundeNummer == sortNr);
List<Sortiment> resultList = ((List<Sortiment>)SortimentLesen("Liste")).FindAll(Sortiment => Sortiment.KundeNummer == sortNr);
g.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height);
//QR-Code
g.DrawImage(qrcode, bitmap.Width - 150, 50, 120, 120);
//Adressblock
g.DrawString($"{adresse.KundeNummer} {adresse.Suchtext}", new Font("Arial", textsize2, FontStyle.Regular), Brushes.Black, adressblock);
g.DrawString($"{adresse.KundeName}", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, adressblock.X, adressblock.Y + (int)textSize3.Height);
g.DrawString($"{adresse.KundeName2}", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, adressblock.X, adressblock.Y + (int)textSize3.Height + (int)textSize2.Height); //
g.DrawString($"{adresse.Strasse}", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, adressblock.X, adressblock.Y + (int)textSize3.Height + (int)textSize3.Height + (int)textSize2.Height);
g.DrawString($"{adresse.PLZ} {adresse.Ort}", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, adressblock.X, adressblock.Y + (int)textSize3.Height + (int)textSize3.Height + (int)textSize2.Height + (int)textSize2.Height);
//TagAnzeige
g.DrawString("MO", new Font("Arial", textsize2, FontStyle.Regular), Brushes.Black, adressblock.X, adressblock.Y + posTag);
g.DrawString("DI", new Font("Arial", textsize2, FontStyle.Regular), Brushes.Black, adressblock.X + textSize3.Width + 10, adressblock.Y + posTag);
g.DrawString("MI", new Font("Arial", textsize2, FontStyle.Regular), Brushes.Black, adressblock.X + (textSize3.Width + 10) * 2, adressblock.Y + posTag);
g.DrawString("DO", new Font("Arial", textsize2, FontStyle.Regular), Brushes.Black, adressblock.X + (textSize3.Width + 10) * 3, adressblock.Y + posTag);
g.DrawString("FR", new Font("Arial", textsize2, FontStyle.Regular), Brushes.Black, adressblock.X + (textSize3.Width + 10) * 4, adressblock.Y + posTag);
//Datum
g.DrawString("Datum:_______________", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, ezl, adressblock.Y + 200);
if (adresse.Aufgabe != null) g.DrawString($"*{Aufgabe.GetAufgabe(string.Empty, adresse.Aufgabe).Bezeichnung}", new Font("Arial", textsize, FontStyle.Bold), Brushes.Black, tabelle.X + textSizePos.Width + 100, adressblock.Y + 200);
//Tabelle Kopf
g.DrawLine(new Pen(Brushes.Black), new Point(tabelle.X, tabelle.Y - zeile), new Point(bitmap.Width - 50, tabelle.Y - zeile));
g.DrawString("Bemerkung", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, tabelle.X + 5, tabelle.Y - (int)textSize2.Height - 5);
g.DrawString("Stück", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, tabelle.X + textSizePos.Width + 25, tabelle.Y - (int)textSize2.Height - 5);
g.DrawString("Bezeichnung", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, tabelle.X + textSizePos.Width + 100, tabelle.Y - (int)textSize2.Height - 5);
g.DrawString("Art.Nr.", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, tabelle.X + textSizePos.Width + 500, tabelle.Y - (int)textSize2.Height - 5);
g.DrawLine(new Pen(Brushes.Black), tabelle, new Point(bitmap.Width - 50, tabelle.Y));
for (int i = 0; i < 19; i++)
{
++idx;
length = handzeile * idx;
g.DrawLine(new Pen(Brushes.Black), new Point(tabelle.X, tabelle.Y - zeile), new Point(tabelle.X, tabelle.Y + length));
g.DrawLine(new Pen(Brushes.Black), new Point(tabelle.X + (int)textSizePos.Width + 5, tabelle.Y - zeile), new Point(tabelle.X + (int)textSizePos.Width + 5, tabelle.Y + length));
g.DrawLine(new Pen(Brushes.Black), new Point(tabelle.X + (int)textSizePos.Width + 90, tabelle.Y - zeile), new Point(tabelle.X + (int)textSizePos.Width + 90, tabelle.Y + length));
g.DrawLine(new Pen(Brushes.Black), new Point(tabelle.X + (int)textSizePos.Width + 495, tabelle.Y - zeile), new Point(tabelle.X + (int)textSizePos.Width + 495, tabelle.Y + length));
g.DrawLine(new Pen(Brushes.Black), new Point(bitmap.Width - 50, tabelle.Y - zeile), new Point(bitmap.Width - 50, tabelle.Y + length));
g.DrawLine(new Pen(Brushes.Black), new Point(tabelle.X, tabelle.Y + length), new Point(bitmap.Width - 50, tabelle.Y + length));
}
foreach (Sortiment artikel in resultList)
{
++idx1;
length = handzeile * idx1;
g.DrawString($"{artikel.ArtName}", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, tabelle.X + textSizePos.Width + 100, tabelle.Y + length - 20);
g.DrawString($"{artikel.ArtNr}", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, tabelle.X + textSizePos.Width + 500, tabelle.Y + length - 20);
}
//Bemerkung
g.DrawString($"Bemerkung:", new Font("Arial", textsize, FontStyle.Regular), Brushes.Black, ezl + 5, bitmap.Height - 120);
//g.DrawString($"*{Aufgabe.GetAufgabe(string.Empty, adresse.Aufgabe).Bezeichnung}", new Font("Arial", textsize, FontStyle.Bold), Brushes.Black, ezl, bitmap.Height - 130 + handzeile);
g.DrawRectangle(new Pen(Brushes.Black), ezl, bitmap.Height - 120 - textsize, bitmap.Width - 100, 100);
Image img = bitmap;
return img;
}
public static void SWS_Drucken(Auftrag auftrag, Kunde adresse, object sender)
{
if (auftrag != null) _auftrag = auftrag;
if (adresse != null) _adresse = adresse;
PrintDialog dialog = new PrintDialog();
foreach (string printer in PrinterSettings.InstalledPrinters) if (printer.Contains(Properties.Settings.Default.SWS_Drucker)) dialog.PrinterSettings.PrinterName = printer;
dialog.PrinterSettings.Copies = (short)Settings.Default.SWS_Copies;
if (dialog.ShowDialog() == DialogResult.OK)
{
PrintDocument printDocument = new PrintDocument();
printDocument.OriginAtMargins = true;
printDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
printDocument.PrinterSettings = dialog.PrinterSettings;
printDocument.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
if (!sender.ToString().Contains("KundeDaten"))
{
PrintPreviewDialog preview = new PrintPreviewDialog();
preview.StartPosition = FormStartPosition.CenterScreen;
preview.WindowState = FormWindowState.Maximized;
preview.Document = printDocument;
preview.Document.DocumentName = "SWS-Schein";
preview.ShowDialog();
}
else { dialog.Document = printDocument; dialog.Document.DocumentName = "SWS-Schein"; printDocument.Print(); }
}
}
public static Image Etikett_Entwurf(object sender, Auftrag auftrag, bool nocont)
{
Kunde kunde = Kunde.GetKunde(string.Empty, auftrag.KundeID, string.Empty);
if (kunde.Suchtext.StartsWith("?") | kunde.KundeNummer == "2320000") kunde.Suchtext = auftrag.ZusatzInfo;
Image qr = ErstelleQRMitRahmen(kunde, auftrag);
Image qrweb = Image.FromFile(ConfigurationManager.AppSettings["QrPfad"]);
qr.RotateFlip(RotateFlipType.Rotate270FlipNone);
Bitmap bitmap = new Bitmap(1200, 300);
//bitmap.SetResolution(100, 100);
Graphics g = Graphics.FromImage(bitmap);
Font font1 = new Font("Arial", 50, FontStyle.Bold);
Font font2 = new Font("Arial", 30, FontStyle.Bold);
Font font3 = new Font("Arial", 30, FontStyle.Regular);
Font font4 = new Font("Arial", 150, FontStyle.Bold);
float height_font1 = g.MeasureString($"{kunde.Suchtext}", font1).Height;
float height_font2 = g.MeasureString($"{kunde.PLZ} {kunde.Ort})", font2).Height;
SizeF size_container = g.MeasureString($"Container/Pakete:", font3);
SizeF size_Liefertag = new SizeF(g.MeasureString("Liefertag:", font3));
float width_date_font1 = g.MeasureString("25.05.2023", font1).Width;
Point startpoint = new Point(380, 20);
g.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height);
//QR-Code
g.DrawImage(qr, 10, (bitmap.Height - qr.Height) / 2, qr.Width, qr.Height);
//Etikett-Text
g.DrawString($"{kunde.Suchtext}", font1, Brushes.Black, startpoint);
g.DrawString($"{kunde.PLZ} {kunde.Ort}", font2, Brushes.Black, startpoint.X, startpoint.Y + height_font1);
g.DrawString("Liefertag:", font3, Brushes.Black, startpoint.X, startpoint.Y + height_font1 + 5 + height_font2 + 10);
g.DrawString("Container/Pakete:", font3, Brushes.Black, startpoint.X + size_Liefertag.Width + 50, startpoint.Y + height_font1 + 5 + height_font2 + 10);
g.DrawString($"{auftrag.Liefertag.ToString("ddd dd.MM.")}", font1, Brushes.Black, startpoint.X, startpoint.Y + height_font1 + 5 + height_font2 + 2 + size_Liefertag.Height + 2);
if (!nocont) g.DrawString($"{auftrag.ContainerClean}", font4, Brushes.Black, startpoint.X + size_Liefertag.Width + size_container.Width + 10, startpoint.Y + height_font1);
//TODO: Ausprobieren ob die Ausrichtung jetzt richtig ist. Sowohl beim ersten wie auch zweiten Mal.
if (sender == null) bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
Image img = bitmap;
return img;
}
public static DialogResult Etikett_Drucken(Auftrag auftrag, bool nocont)
{
_nocont = nocont;
_auftrag = auftrag;
int x = auftrag.ContainerClean;
PrintDialog dialog = new PrintDialog();
//PrintPreviewDialog preview = new PrintPreviewDialog();
PrintDocument printDocument = new PrintDocument();
foreach (string printer in PrinterSettings.InstalledPrinters) if (printer.Contains(Properties.Settings.Default.Etikett_Drucker)) dialog.PrinterSettings.PrinterName = printer;
dialog.PrinterSettings.Copies = (short)auftrag.ContainerClean;
if (dialog.ShowDialog() == DialogResult.OK)
{
printDocument.PrinterSettings = dialog.PrinterSettings;
printDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
if (!printDocument.PrinterSettings.PrinterName.Contains(Properties.Settings.Default.Etikett_Drucker)) printDocument.DefaultPageSettings.PaperSize = new PaperSize("Etikett-Custom", 29, 90);
//preview.StartPosition = FormStartPosition.CenterScreen;
//preview.WindowState = FormWindowState.Normal;
//preview.Document = printDocument;
//preview.Document.DocumentName = "Etikett";
//preview.ShowDialog();
dialog.Document = printDocument;
dialog.Document.DocumentName = "Etikett";
printDocument.Print();
return DialogResult.OK;
}
return DialogResult.Cancel;
}
public static Image TourenListe_Entwurf(List<Auftrag> auftragliste, Benutzer fahrer, int bottom)
{
DateTime liefertag = auftragliste[0].Liefertag;
int ezl = 50; int lastline = 0; int length = 0;
float fontsize = 15; float fontsize2 = 30; float fontsize3 = 10;
int bitmapHeight = CalculateBitmapHeight(auftragliste);
Bitmap bitmap = new Bitmap(790, bitmapHeight);
Graphics g = Graphics.FromImage(bitmap);
Point adressblock = new Point(ezl, 50);
Point tabelle = new Point(ezl, 330);
SizeF textSize2 = g.MeasureString("Salzburg, am 26.08.1984", new Font("Arial", fontsize, FontStyle.Regular));
SizeF textSize3 = g.MeasureString("MO", new Font("Arial", fontsize2, FontStyle.Regular));
SizeF textSizePos = g.MeasureString("Container Gesamt: ", new Font("Arial", fontsize, FontStyle.Regular));
SizeF textSizePos2 = g.MeasureString("Container: ", new Font("Arial", fontsize, FontStyle.Regular));
SizeF datumSize = g.MeasureString("00.00.0000 - 00:00", new Font("Arial", 10, FontStyle.Regular));
g.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height);
//FAHRER UND LIEFERTAG ZEILE 1 & 2
g.DrawString($"{DateTime.Now.ToString("dd.MM.yyyy - HH:mm")}", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, bitmap.Width - 50 - datumSize.Width, adressblock.Y);
g.DrawString($"{fahrer.Vorname} {fahrer.Nachname}", new Font("Arial", fontsize2, FontStyle.Regular), Brushes.Black, adressblock);
g.DrawString($"{GetWochentagDeutsch(liefertag.DayOfWeek)} {liefertag.ToShortDateString()}", new Font("Arial", fontsize2, FontStyle.Regular), Brushes.Black, adressblock.X, lastline = adressblock.Y + (int)textSize3.Height);
//TOUR START UND ENDE ZEILE 3
g.DrawString($"Tour Start um:", new Font("Arial", fontsize, FontStyle.Regular), Brushes.Black, tabelle.X, lastline = lastline + (int)textSize3.Height + 40);
g.DrawString($"Tour Ende um:", new Font("Arial", fontsize, FontStyle.Regular), Brushes.Black, (bitmap.Width / 2), lastline);
//TOURKOPF ENDLINIE ALLE ÄNDERUNGEN AM TOURKOPF ^^ DARÜBER EINFÜGEN
g.DrawLine(new Pen(Brushes.Black), new Point(tabelle.X, tabelle.Y + 20), new Point(bitmap.Width - 50, lastline = tabelle.Y + 20));
int idx1 = 0;
int gesCont = 0;
int kndanzahl = 0;
int kndnichtfertig = 0;
foreach (Auftrag auftrag in auftragliste)
{
Kunde knd = Kunde.GetKunde(string.Empty, auftrag.KundeID, string.Empty);
string kndName = string.Empty;
gesCont += auftrag.ContainerClean;
if (knd == null) return null;
//Image qrcode = Get_QR_Code(adresse, null);
//QR-Code
//g.DrawImage(qrcode, bitmap.Width - 150, 50, 120, 120);
if (knd.KundeNummer == "2320000") kndName = auftrag.ZusatzInfo;
else kndName = string.IsNullOrWhiteSpace(knd.Suchtext) ? knd.KundeName : knd.Suchtext;
SizeF kundenname = g.MeasureString(kndName, new Font("Arial", fontsize, FontStyle.Regular));
SizeF ortwidth = g.MeasureString(knd.Ort, new Font("Arial", fontsize, FontStyle.Regular));
SizeF adressewidth = g.MeasureString($"{knd.PLZ.ToString()} {knd.Ort}, {knd.Strasse}", new Font("Arial", fontsize3, FontStyle.Regular));
FontStyle style;
if (auftrag.Status < AuftragStatus.Vorbereitet) { style = FontStyle.Bold; kndnichtfertig++; }
else style = FontStyle.Regular;
++idx1;
if (kndanzahl >= 15)
{
if (kndanzahl >= 34)
{
if (kndanzahl >= 54) length = (int)textSize3.Height * idx1 + 420;
else length = (int)textSize3.Height * idx1 + 280;
}
else length = (int)textSize3.Height * idx1 + 140;
}
else length = (int)textSize3.Height * idx1;
//ZEILE 1
g.DrawString($"{auftrag.Status.ToString()}", new Font("Arial", fontsize, style), Brushes.Black, tabelle.X, lastline + 5);
g.DrawString($"{knd.KundeNummer} {kndName}", new Font("Arial", fontsize, style), Brushes.Black, tabelle.X + 130, lastline = lastline + 5);
//CHECKBOX ÜBER 2 ZEILEN
g.DrawRectangle(new Pen(Brushes.Black), ezl + 650, lastline, fontsize + fontsize3 + 10, fontsize3 + fontsize + 10);
if (auftrag.Typ != AuftragTyp.Regelmäßig) g.DrawString($"Container: {auftrag.ContainerClean}", new Font("Arial", fontsize, style), Brushes.Black, tabelle.X + 550 - textSizePos2.Width, lastline);
else
{
int i = 0;
string[] art;
List<AuftragArtikel> liste = AuftragArtikel.GetList(auftrag.AuftragID);
art = new string[liste.Count];
foreach (AuftragArtikel artikel in liste)
{
g.DrawString($"{artikel.Anzahl.ToString()} Stk. {artikel.ArtikelName}", new Font("Arial", fontsize3, style), Brushes.Black, tabelle.X + 550 - textSizePos2.Width, lastline + ((int)datumSize.Height * i));
i++;
}
}
//ZEILE 2
g.DrawString($"{knd.PLZ.ToString()} {knd.Ort}, {knd.Strasse}", new Font("Arial", fontsize3, style), Brushes.Black, tabelle.X, lastline = lastline + (int)textSize2.Height);
//LINIE UNTER ZEILE
g.DrawLine(new Pen(Brushes.Black), new Point(tabelle.X, lastline = lastline + (int)datumSize.Height + 2), new Point(bitmap.Width - 50, lastline));
kndanzahl++;
}
//ANZAHL KUNDEN UND CONTAINER
g.DrawString($"Kunden Gesamt: {kndanzahl.ToString()}", new Font("Arial", fontsize, FontStyle.Bold), Brushes.Black, tabelle.X, lastline + 10);
g.DrawString($"Container Gesamt: {gesCont.ToString()}", new Font("Arial", fontsize , FontStyle.Bold), Brushes.Black, tabelle.X + 550 - textSizePos.Width, lastline = lastline + 10);
if (kndnichtfertig > 0) g.DrawString($"Kunden nicht fertig: {kndnichtfertig.ToString()}", new Font("Arial", fontsize, FontStyle.Bold), Brushes.Black, tabelle.X, lastline = lastline + (int)textSize2.Height + 5);
Image img = bitmap;
return img;
//TODO: Reg.Aufträge einbauen. Besonderheit: Die Artikel sollen ebenfalls erscheinen.
//TODO: Zuweisung zu Fahrer muss geklärt werden.
}
public static void TourenListe_Drucken(List<Auftrag> auftragliste, Benutzer fahrer, object sender, Benutzer benutzer)
{
if (auftragliste != null) _auftragliste = auftragliste;
if (fahrer != null) _fahrer = fahrer;
if (benutzer != null) _benutzer = benutzer;
string dateiName = $"{_auftragliste[0].Liefertag}_{_fahrer.BenutzerName}";
currentPage = 0; // WICHTIG: reset vor jedem Druck
string path = ConfigurationManager.AppSettings["DateiSavePfad"];
string tmpPdf = Path.Combine(path, "Tourenlisten", dateiName);
//string tmpPdf = @"C:\tmp\output2.pdf";
PrintDialog dialog = new PrintDialog();
PrintPreviewDialog preview = new PrintPreviewDialog();
try
{
foreach (string printer in PrinterSettings.InstalledPrinters) if (printer.Contains(Properties.Settings.Default.SWS_Drucker)) dialog.PrinterSettings.PrinterName = printer;
dialog.PrinterSettings.Copies = 1;
if (dialog.ShowDialog() == DialogResult.OK)
{
PrintDocument printDocument = new PrintDocument();
printdoc = new PrintDocument();
printDocument.OriginAtMargins = true;
printDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
printDocument.PrinterSettings = dialog.PrinterSettings;
printDocument.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 50);
//printDocument.BeginPrint += PrintDocument_BeginPrint;
//printDocument.EndPrint += PrintDocument_EndPrint;
if (!sender.ToString().Contains("KundeDaten"))
{
preview.StartPosition = FormStartPosition.CenterScreen;
preview.WindowState = FormWindowState.Maximized;
preview.Document = printdoc = printDocument;
preview.Document.DocumentName = "TourenListe";
// WAITCURSOR + DISABLE Events
printDocument.BeginPrint += (s, args) =>
{
preview.Enabled = false; // Form sperren
preview.UseWaitCursor = true; // Form + Controls
Application.UseWaitCursor = true; // App-weit
Application.DoEvents(); // Cursor sofort updaten
};
printDocument.EndPrint += (s, args) =>
{
IsPhysicalPrint = printDocument.PrintController.IsPreview ? false : true;
preview.Enabled = true; // Form wieder aktiv
preview.UseWaitCursor = false;
Application.UseWaitCursor = false;
System.Windows.Forms.Cursor.Current = Cursors.Default; // Sicherheitsnetz
};
preview.ShowDialog();
}
else { dialog.Document = printDocument; dialog.Document.DocumentName = "TourenListe"; printDocument.Print(); }
}
}
catch (Exception ex)
{
meldung.GetFehler(ex, $"PDF konnte nicht erstellt oder gespeicehrt werden.\nRufe einen Vorgesetzten.\n\nFehler: {ex.Message}");
throw;
}
finally
{
if (IsPhysicalPrint)
{
GeneratePdfFromPrintDocument(tmpPdf);
}
}
}
public static Image SonderEtikett_Entwurf(Auftrag auftrag, Dictionary<string, int[]> dictionary)
{
Kunde kunde = Kunde.GetKunde(string.Empty, auftrag.KundeID, string.Empty);
if (kunde.Suchtext.StartsWith("?") | kunde.KundeNummer == "2320000") kunde.Suchtext = auftrag.ZusatzInfo;
List<AuftragArtikel> artliste = AuftragArtikel.GetList(auftrag.AuftragID);
if (artliste == null || artliste.Count == 0) return null;
Bitmap bitmap = new Bitmap(300, 1200);
Graphics g = Graphics.FromImage(bitmap);
Font font1 = new Font("Arial", 15, FontStyle.Bold);
Font font2 = new Font("Arial", 30, FontStyle.Bold);
Font font3 = new Font("Arial", 30, FontStyle.Regular);
Font font4 = new Font("Arial", 150, FontStyle.Bold);
float height_font1 = g.MeasureString($"{kunde.Suchtext}", font1).Height;
float height_font2 = g.MeasureString($"{kunde.PLZ} {kunde.Ort})", font2).Height;
SizeF size_container = g.MeasureString($"Container/Pakete:", font3);
SizeF size_Liefertag = new SizeF(g.MeasureString("Liefertag:", font3));
float width_date_font1 = g.MeasureString("25.05.2023", font1).Width;
int nextposition = 40;
int einzug = 20;
Point startpoint = new Point(20, 40);
g.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height);
//Etikett-Text
g.DrawString($"{kunde.KundeNummer}", font2, Brushes.Black, startpoint);
nextposition += (int)height_font2;
g.DrawString($"{kunde.Suchtext}", font2, Brushes.Black, einzug, nextposition);
nextposition += (int)height_font2;
g.DrawString($"{auftrag.Liefertag.Date.ToString("dd.MM.yyyy")}", font2, Brushes.Black, einzug, nextposition);
nextposition += (int)height_font2;
g.DrawString("Artikel Rekl/NW/Stand/Inv", font1, Brushes.Black, einzug, nextposition + 20);
nextposition += 20 + (int)height_font1;
foreach (var kvp in dictionary)
{
string artikelKey = kvp.Key; // z.B. "ART1"
int[] artbestand = kvp.Value; // z.B. [3, 0, 5]
string shortName = Artikel.GetShort(null, artikelKey);
g.DrawString($"{shortName}", font1, Brushes.Black, einzug, nextposition);
if (artbestand[2] < 0) g.DrawString($"{artbestand[0].ToString()}/{artbestand[1].ToString()}/({artbestand[2].ToString()})/{artbestand[3].ToString()}", font1, Brushes.Black, einzug + g.MeasureString(shortName, font1).Width + 10, nextposition);
else g.DrawString($"{artbestand[0].ToString()}/{artbestand[1].ToString()}/{artbestand[2].ToString()}/{artbestand[3].ToString()}", font1, Brushes.Black, einzug + g.MeasureString(shortName, font1).Width + 10, nextposition);
nextposition += (int)height_font1;
}
Image img = bitmap;
return img;
}
public static DialogResult SonderEtikett_Drucken(Auftrag auftrag, Dictionary<string, int[]> dictionary)
{
_auftrag = auftrag;
_dictionary = dictionary;
int x = auftrag.ContainerClean;
PrintDialog dialog = new PrintDialog();
PrintPreviewDialog preview = new PrintPreviewDialog();
PrintDocument printDocument = new PrintDocument();
foreach (string printer in PrinterSettings.InstalledPrinters) if (printer.Contains(Properties.Settings.Default.Etikett_Drucker)) dialog.PrinterSettings.PrinterName = printer;
dialog.PrinterSettings.Copies = 2;
if (dialog.ShowDialog() == DialogResult.OK)
{
printDocument.PrinterSettings = dialog.PrinterSettings;
printDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
if (!printDocument.PrinterSettings.PrinterName.Contains(Properties.Settings.Default.Etikett_Drucker)) printDocument.DefaultPageSettings.PaperSize = new PaperSize("Etikett-Custom", 29, 90);
preview.StartPosition = FormStartPosition.CenterScreen;
preview.WindowState = FormWindowState.Normal;
preview.Document = printDocument;
preview.Document.DocumentName = "SonderEtikett";
preview.ShowDialog();
//dialog.Document = printDocument;
//dialog.Document.DocumentName = "Etikett";
//printDocument.Print();
return DialogResult.OK;
}
return DialogResult.Cancel;
}
private static void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
if (sender.ToString().Contains("SWS-Schein"))
{
Image img = SWS_Entwurf(_auftrag, _adresse);
// Verfügbare Druckfläche innerhalb der Seitenränder
Rectangle printArea = e.MarginBounds;
// Skalierungsfaktor berechnen, um Bild proportional einzupassen
float scale = Math.Min((float)printArea.Width / img.Width, (float)printArea.Height / img.Height);
// Berechnete Bildgröße
int scaledWidth = (int)(img.Width * scale);
int scaledHeight = (int)(img.Height * scale);
// Zentrierte Position im Druckbereich
int posX = printArea.Left + (printArea.Width - scaledWidth) / 2;
int posY = printArea.Top + (printArea.Height - scaledHeight) / 2;
e.Graphics.DrawImage(img, posX, posY, scaledWidth, scaledHeight);
//e.Graphics.DrawImage(img, 0, 0, scaledWidth, scaledHeight);
// Event abschließen (keine weiteren Seiten)
e.HasMorePages = false;
}
if (sender.ToString().Contains("Etikett")) e.Graphics.DrawImage(Etikett_Entwurf(null, _auftrag, _nocont), e.PageBounds);
if (sender.ToString().Contains("Sonder")) e.Graphics.DrawImage(SonderEtikett_Entwurf(_auftrag, _dictionary), e.PageBounds);
if (sender.ToString().Contains("TourenListe"))
{
if (pagesToPrint == currentPage) currentPage = 0;
int bottom = e.MarginBounds.Bottom - e.MarginBounds.Size.Height;
Image img = TourenListe_Entwurf(_auftragliste, _fahrer, bottom);
if (img == null) return;
pagesToPrint = img.Height / 1119;
Rectangle printArea = e.MarginBounds;
// Feste Höhe pro Seite (Pixel der Bitmap)
int pageHeight = printArea.Height;
int startY = currentPage * pageHeight; // Offset für diese Seite
// Ausschnitt: Originalgröße, nur vertikal verschoben
Rectangle sourceRect = new Rectangle(
0, // X=0 (kein horizontaler Ausschnitt)
startY, // Y dieser Seite
img.Width, // volle Breite
pageHeight // nur diese Seitenhöhe
);
// Ziel: Vollbild ohne Skalierung
Rectangle destRect = new Rectangle(
printArea.X, printArea.Y,
img.Width, pageHeight
);
// 1:1 ohne Skalierung zeichnen
e.Graphics.DrawImage(img, destRect, sourceRect, GraphicsUnit.Pixel);
// Nächste Seite?
currentPage++;
e.HasMorePages = (startY + pageHeight) < img.Height;
}
}
private static int CalculateBitmapHeight(List<Auftrag> auftragliste)
{
int firstPageItems = 15; // Erste Seite: 15 Aufträge
int otherPagesItems = 19; // Weitere Seiten: 20 Aufträge
if (auftragliste.Count <= firstPageItems)
return 1119; // Nur 1 Seite
int remainingItems = auftragliste.Count - firstPageItems;
int additionalPages = (int)Math.Ceiling((double)remainingItems / otherPagesItems);
return 1119 * (1 + additionalPages); // 1. Seite + weitere Seiten
}
private static void GeneratePdfFromPrintDocument(string pdfPath)
{
printdoc.PrinterSettings.PrinterName = "Microsoft Print to PDF";
printdoc.PrinterSettings.PrintToFile = true;
printdoc.PrinterSettings.PrintFileName = pdfPath;
//printDoc.PrintController = new StandardPrintController(); // Unterdrückt Vorschau-Dialog
printdoc.Print();
printdoc.Dispose();
}
private static bool WaitForFileReady(string filePath, int maxWaitMs = 5000)
{
int timeout = 0;
while (timeout < maxWaitMs)
{
if (File.Exists(filePath))
{
try
{
// Prüfe ob Datei lesbar (nicht gelockt)
using (var fs = File.OpenRead(filePath))
{
fs.ReadByte(); // Test-Lesezugriff
return true;
}
}
catch
{
// Noch gelockt → weiter warten
}
}
Thread.Sleep(100);
timeout += 100;
}
return false;
}
/// <summary>
/// HIDE AND SHOW CONTROLS WÄHREND LADEVORGANG
/// </summary>
public static Control.ControlCollection HideControls(Control.ControlCollection controls)
{
Control.ControlCollection cc = controls;
foreach (Control c in cc) { c.Hide(); }
return cc;
}
public static Control.ControlCollection ShowControls(Control.ControlCollection controls)
{
Control.ControlCollection cc = controls;
foreach (Control c in cc) { c.Show(); }
return cc;
}
/// <summary>
/// RadioButtons für Liefertag erzeugen
/// </summary>
/// <param name="sender">ParentControl der Radiobuttons</param>
public static void Get_RadioButtons(object sender)
{
GroupBox groupBox = sender as GroupBox;
FormNeuerAuftrag form = sender as FormNeuerAuftrag;
if (groupBox == null && form == null) return;
Control ctr = groupBox ?? (Control)form;
var liefertagMapping = new Dictionary<string, Liefertag>
{
["MO"] = Liefertag.MO,
["Di"] = Liefertag.DI,
["MI"] = Liefertag.MI,
["DO"] = Liefertag.DO,
["FR"] = Liefertag.FR
};
foreach (RadioButton rb in ctr.Controls.OfType<RadioButton>())
{
foreach (var kvp in liefertagMapping)
{
if (rb.Name.Contains(kvp.Key))
{
rb.Tag = kvp.Value;
break;
}
}
rb.Enabled = true;
}
}
/// <summary>
/// LISTVIEW COLUMNSBREITE WIRD ANGEPASST UND DAS UMREIHEN ERMÖGLICHT
/// </summary>
public static (ListView lv, ObjectListView olv) Columns_Resize(ListView lv, ObjectListView olv)
{
if (olv == null)
{
int realwidth = lv.Width;
int lvwWidth = 0;
lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
ListView.ColumnHeaderCollection cc = lv.Columns;
for (int i = 0; i < cc.Count; i++)
{
int colWidth = TextRenderer.MeasureText(cc[i].Text, lv.Font).Width + 30;
if (colWidth > cc[i].Width)
{
lvwWidth += cc[i].Width = colWidth;
}
else lvwWidth += cc[i].Width;
}//COLUMNS BREITE CONTENT ODER HEADER SIZE
//BREITE DER LISTVIEW UNVERÄNDERT BEI NAMEN MIT...
if (!lv.Name.Contains("Lieferungen") & !lv.Name.Contains("STH") & !lv.Name.Contains("Artikel") & !lv.Name.Contains("AufgabeVW") & !lv.Name.Contains("Auftrag")) lv.Width = lvwWidth;
return (lv, null);
}
else
{
int realwidth = olv.Width;
int lvwWidth = 10;
olv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
ObjectListView.ColumnHeaderCollection cc = olv.Columns;
for (int i = 0; i < cc.Count; i++)
{
cc[i].Width += 10;
int colWidth = TextRenderer.MeasureText(cc[i].Text, olv.Font).Width + 30;
if (colWidth > cc[i].Width)
{
lvwWidth += cc[i].Width = colWidth;
}
else lvwWidth += cc[i].Width;
}//COLUMNS BREITE CONTENT ODER HEADER SIZE
//BREITE DER LISTVIEW UNVERÄNDERT BEI NAMEN MIT...
if (!olv.Name.Contains("Lieferungen") & !olv.Name.Contains("STH") & !olv.Name.Contains("AufgabeVW") & !olv.Name.Contains("Auftrag")) olv.Width = lvwWidth;
return (null, olv);
}
}
/// <summary>
/// Rahmen um die GroupBox erstellen.
/// base.OnPaint(e) muss im GroupBox_Paint Event vor dem Aufruf der Funktionen stehen.
/// </summary>
/// <param name="gb"></param>
/// <param name="e"></param>
/// <returns>GroupBox gb</returns>
public static GroupBox GetGroupBoxBoarder(GroupBox gb, PaintEventArgs e)
{
string text = gb.Text;
Font font = gb.Font;
Size textSize = TextRenderer.MeasureText(text, font);
Pen pen = new Pen(Program.Wirlblau, 3);
int textWidth = textSize.Width;
int textHeight = textSize.Height;
if (gb.Parent.Name == "FormExpedit") pen = new Pen(Color.Red, 3);
int offset = 9; // Abstand von links zum Text
// Rechteck für äußeren Rahmen
Rectangle rect = new Rectangle(1, textHeight / 2, gb.Width - 3, gb.Height - textHeight / 2 - 2);
// Obere linke Linie (links bis zum linken Rand des Textes)
e.Graphics.DrawLine(pen, rect.Left - 1, rect.Top, offset, rect.Top);
// Obere rechte Linie (rechts vom Text bis zum rechten Rand)
e.Graphics.DrawLine(pen, offset + textWidth - 5, rect.Top, rect.Right + 2, rect.Top);
// Linke vertikale Linie
e.Graphics.DrawLine(pen, rect.Left, rect.Top, rect.Left, rect.Bottom);
// Rechte vertikale Linie
e.Graphics.DrawLine(pen, rect.Right, rect.Top, rect.Right, rect.Bottom);
// Untere Linie
e.Graphics.DrawLine(pen, rect.Left - 1, rect.Bottom, rect.Right + 2, rect.Bottom);
return gb;
}
public static DateTime GetNextLiefertag(Liefertage rhythmus)
{
DateTime aktDatum = DateTime.Today;
// Starte ab morgen und suche nächsten passenden Arbeitstag
for (int i = 1; i <= 7; i++)
{
DateTime testDatum = aktDatum.AddDays(i);
DayOfWeek dow = testDatum.DayOfWeek;
Liefertage liefertag;
// Klassischer switch statement (C# 7.3 kompatibel)
switch (dow)
{
case DayOfWeek.Monday:
liefertag = Liefertage.Monday;
break;
case DayOfWeek.Tuesday:
liefertag = Liefertage.Tuesday;
break;
case DayOfWeek.Wednesday:
liefertag = Liefertage.Wednesday;
break;
case DayOfWeek.Thursday:
liefertag = Liefertage.Thursday;
break;
case DayOfWeek.Friday:
liefertag = Liefertage.Friday;
break;
default: // Sa/So
continue;
}
if (rhythmus.HasFlag(liefertag))
return testDatum;
}
return aktDatum.AddDays(7);
}
public static Chart Load_FehlmengeChart(List<KundeArtikel> artikelDaten, Chart chart1)
{
chart1.Series.Clear();
Title title = chart1.Titles[0];
title.Text = Kunde.GetKunde(null, artikelDaten[0].KundeID, null).Suchtext == null ? Kunde.GetKunde(null, artikelDaten[0].KundeID, null).KundeName : Kunde.GetKunde(null, artikelDaten[0].KundeID, null).Suchtext;
title.Font = new Font("Arial", 16, FontStyle.Bold);
title.ForeColor = Color.White;
title.BackColor = Color.Transparent;
title.Position = new ElementPosition(0, 0, 100, 8); // X,Y,Breite,Höhe (Prozent)
title.Alignment = ContentAlignment.TopCenter;
title.Docking = Docking.Top;
title.DockingOffset = 0;
chart1.Titles.Clear();
chart1.Titles.Add(title);
chart1.ChartAreas[0].Position = new ElementPosition(0, 8, 100, 92);
// Gesamtmenge als einzelne Säule (links oder transparent)
//TODO: Gesamt soll immer 100% sein.
var serieGesamt = new Series("Gesamtmenge")
{
ChartType = SeriesChartType.StackedBar100,
Color = Color.LightBlue,
CustomProperties = "DrawSideBySide=False, PointWidth=0.8",
LabelFormat = "{0:P0}",
};
// Gestapelte Fehler-Serie (rechts darüber)
var serieFehler = new Series("Fehlmenge")
{
ChartType = SeriesChartType.StackedBar100,
Color = Color.Orange,
LabelFormat = "{0:P0}%"
};
var serieReklamation = new Series("Reklamation")
{
ChartType = SeriesChartType.StackedBar100,
Color = Color.OrangeRed,
LabelFormat = "{0:P0}%"
};
for (int i = 0; i < artikelDaten.Count; i++)
{
var daten = artikelDaten[i];
double index = i; // Gleicher X-Wert für alle Serien
if (daten.Stand > 0)
{
serieGesamt.Points.AddXY(index, 1.0 - (((double)daten.Fehlmenge + (double)daten.Reklamation) / (double)daten.Stand));
//serieGesamt.Points[i].Label = daten.Stand.ToString("N0");
serieFehler.Points.AddXY(index, ((double)daten.Fehlmenge / (double)daten.Stand));
if (daten.Fehlmenge > 0) serieFehler.Points[i].Label = daten.Fehlmenge.ToString("N0");
else serieFehler.Points[i].Label = " ";
serieReklamation.Points.AddXY(index, ((double)daten.Reklamation / (double)daten.Stand));
if (daten.Reklamation > 0) serieReklamation.Points[i].Label = daten.Reklamation.ToString("N0");
else serieReklamation.Points[i].Label = " ";
}
else
{
serieGesamt.Points.AddXY(index, 1.0d);
serieGesamt.Label = " ";
serieFehler.Points.AddXY(index, daten.Fehlmenge);
if (daten.Fehlmenge > 0) serieFehler.Points[i].Label = daten.Fehlmenge.ToString();
else serieFehler.Points[i].Label = " ";
serieReklamation.Points.AddXY(index, daten.Reklamation);
if (daten.Reklamation > 0) serieReklamation.Points[i].Label = daten.Reklamation.ToString();
else serieReklamation.Points[i].Label = " ";
}
// Label setzen (X-Achse zeigt Artikelnamen)
string label = Artikel.GetShort(daten.ArtikelID, null);
//if (label.Length > 10)
// label = label.Substring(0, 10) + "...";
serieGesamt.Points[i].AxisLabel = label;
}
chart1.Series.Add(serieFehler);
chart1.Series.Add(serieReklamation);
chart1.Series.Add(serieGesamt);
// Legende wird ausgeblendet
chart1.Legends.Clear();
// Für Y-Achse (Mengen) WAAGERECHT
chart1.ChartAreas[0].AxisY.Maximum = 100;
chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
chart1.ChartAreas[0].AxisY.TitleForeColor = Color.White;
chart1.ChartAreas[0].AxisY.LabelStyle.Font = new Font("Arial", 9, FontStyle.Bold);
// Für X-Achse (Mengen) SENKRECHT
chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
chart1.ChartAreas[0].AxisX.TitleForeColor = Color.White;
chart1.ChartAreas[0].AxisX.LabelStyle.Font = new Font("Arial", 10, FontStyle.Regular);
//chart1.ChartAreas[0].AxisX.LabelStyle.Angle = -45; // Schräg für mehr Platz
// Gitterlinien (optional)
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray;
return chart1;
}
public static string GetWochentagDeutsch(DayOfWeek day)
{
switch (day)
{
case DayOfWeek.Monday:
return "Montag";
case DayOfWeek.Tuesday:
return "Dienstag";
case DayOfWeek.Wednesday:
return "Mittwoch";
case DayOfWeek.Thursday:
return "Donnerstag";
case DayOfWeek.Friday:
return "Freitag";
case DayOfWeek.Saturday:
return "Samstag";
case DayOfWeek.Sunday:
return "Sonntag";
default:
return "Unbekannt";
}
}
//public static void UpdateOrSaveTour(int? tourid, Auftrag auftrag)
//{
// int? arbeiterID = null;
// DateTime? liefertag = null;
// int? tourID = tourid;
// Tour tour = null;
// if (auftrag != null)
// {
// arbeiterID = auftrag.ArbeiterID;
// liefertag = auftrag.Liefertag;
// tourID = auftrag.TourID;
// }
// if (tourID != null) tour = Tour.GetTour(tourID);
// if (tour == null)
// {
// tour = new Tour();
// tour.TourID = null;
// tour.BenutzerID = auftrag.ArbeiterID;
// tour.Liefertag = auftrag.Liefertag;
// tour.SaisonID = Saison.GetAktivSaison().SaisonId;
// }
// tour.Kundenanzahl++;
// tour.ContainerDirt += auftrag.Container;
// tour.ContainerClean += auftrag.ContainerClean;
// if (tour.Save() == 0) meldung.GetFehler(null, "Speichern oder Updaten der Tour war nicht möglich.\nBitte informiere deinen Vorgesetzten.");
//}
internal static Priority GetPriority(Benutzer user)
{
string vorname;
if (user == null) vorname = string.Empty;
else vorname = user.Vorname;
switch (vorname)
{
case var n when n == "Gerald": return Priority.First;
case var n when n == "Jochen": return Priority.Second;
case var n when n == "Thomas": return Priority.Third;
case var n when n == "Alil": return Priority.Fourth;
default: return Priority.None;
}
}
}
}