Programm_Wirl/AA-Klassen/Funktionen.cs

1233 lines
48 KiB
C#

using AForge.Video.DirectShow;
using BrightIdeasSoftware;
using DatenDB;
using Deckungsbeitrag.AA_Klassen;
using Deckungsbeitrag.Properties;
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.Runtime;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using ZXing;
using Control = System.Windows.Forms.Control;
namespace Deckungsbeitrag
{
public class Funktionen
{
private static readonly Liefertage Arbeitstage = Liefertage.Monday | Liefertage.Tuesday | Liefertage.Wednesday | Liefertage.Thursday | Liefertage.Friday;
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 FormAufleger _aufleger;
public static Auftrag _auftrag;
public static Kunde _adresse;
private int currentPage = 0;
private int totalPages = 0;
int i = 0;
int j = 0;
private bool printOK;
private static bool _nocont;
private static Meldungen meldung = new Meldungen();
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 Get_Font_Size(Font font, string text, float height)
{
Font f = font;
if (!string.IsNullOrEmpty(text))
{
while (height > TextRenderer.MeasureText(text, f).Height)
{
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;
bool ok = false;
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();
ok = true;
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 = 0;
// 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();
artikel[idx - 1] = new Artikel(row, idx - 1);
artikelListe.Add(new Artikel(row, idx - 1));
}
streamReader.Close();
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();
}
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()
{
Kunde knd = new Kunde();
FormListe liste = new FormListe(null, 0);
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();
break;
default:
break;
}
return knd;
}
/// <summary>
/// QR-CODE FÜR ETIKETTEN
/// </summary>
public static Image Get_QR_Code(Kunde kunde, Auftrag auftrag)
{
Image img = null;
BarcodeWriter code = new BarcodeWriter();
code.Format = BarcodeFormat.QR_CODE;
img = code.Write(kunde.KundeNummer.ToString());
//img = code.Write(auftrag.AuftragID + "," + kunde.KundeNummer + "," + auftrag.Liefertag.ToShortDateString());
return img;
}
/// <summary>
/// DRUCKEN VON SCHMUTZWÄSCHESCHEINEN & ETIKETTEN
/// </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 = Get_QR_Code(kunde, auftrag);
Image qrweb = Image.FromFile(ConfigurationManager.AppSettings["QrPfad"]);
qrweb.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(qrweb, 10, 15, 350, 280);
//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);
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;
}
private static void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
if (sender.ToString().Contains("SWS-Schein"))
{
Image img = Funktionen.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(Funktionen.Etikett_Entwurf(null, _auftrag, _nocont), e.PageBounds);
}
/// <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 Columns_Resize(ListView lv)
{
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("BenutzerVW") & !lv.Name.Contains("Auftrag")) lv.Width = lvwWidth;
return lv;
}
public static ListView Columns_Reorder(ListView lv)
{
lv.AllowColumnReorder = true;
return lv;
}
/// <summary>
/// ListView_Load für AufgabenVW und BenutzerVW
/// </summary>
/// <param name="lv"></param>
/// <param name="colname"></param>
/// <param name="objectlist"></param>
/// <returns></returns>
public static ListView ListView_Load(ListView lv, string colname, List<object> objectlist)
{
ColumnHeader ch;
foreach (string s in colname.Split(','))
{
ch = new ColumnHeader();
ch.Name = s.Trim();
if (ch.Name == "vorname") ch.DisplayIndex = 0;
if (ch.Name == "nachname") ch.DisplayIndex = 2;
if (ch.Name == "benutzer_name")
{
ch.DisplayIndex = 3;
ch.Name = "benutzername";
}
if (ch.Name == "rolle") ch.DisplayIndex = 4;
if (ch.Name == "schein") ch.DisplayIndex = 5;
if (ch.Name == "gueltig_bis")
{
ch.DisplayIndex = 6;
ch.Name = "gültig bis";
}
if (ch.Name == "ist_aktiv" || ch.Name == "aktive")
{
ch.DisplayIndex = 7;
ch.Name = "aktiv";
}
if (ch.Name == "bezeichnung") ch.DisplayIndex = 0;
if (ch.Name == "Beschreibung") ch.DisplayIndex = 1;
if (ch.Name == "kategorie") ch.DisplayIndex = 3;
if (ch.Name == "farbe")
{
ch.DisplayIndex = 4;
}
ch.Text = char.ToUpper(ch.Name[0]) + ch.Name.Substring(1);
if (ch.Name != "benutzer_id" && ch.Name != "passwort" && ch.Name != "aufgabe_id" && ch.Name != "rolle") lv.Columns.Add(ch);
}
lv.Items.Clear();
var element = objectlist.FirstOrDefault();
switch (element.GetType().Name)
{
case ("Benutzer"):
foreach (Benutzer ben in objectlist)
{
ListViewItem item;
item = new ListViewItem();
item.Tag = ben;
item.Text = ben.Vorname;
item.SubItems.Add(ben.Nachname);
item.SubItems.Add(ben.BenutzerName);
item.SubItems.Add(ben.Rolle.ToString());
item.SubItems.Add(ben.Schein.ToString());
item.SubItems.Add(ben.GueltigBis.HasValue ? ben.GueltigBis.Value.ToShortDateString() : "");
item.SubItems.Add(ben.Aktiv == true ? "JA" : "NEIN");
lv.Items.Add(item);
}
break;
case ("Aufgabe"):
foreach (Aufgabe auf in objectlist)
{
ListViewItem item = new ListViewItem();
item.UseItemStyleForSubItems = false;
item.Tag = auf;
item.Text = auf.Bezeichnung;
item.SubItems.Add(auf.Beschreibung);
item.SubItems.Add(auf.Kategorie.ToString());
item.SubItems.Add("");
item.SubItems.Add(auf.Aktiv.ToString());
ColorConverter cc = new ColorConverter();
item.SubItems[3].BackColor = (Color)cc.ConvertFromString(auf.Farbe.ToArgb().ToString()); //COLUMN FARBE SUBITEM BACKCOLOR == FARBE.
lv.Items.Add(item);
}
break;
default:
break;
}
//RESIZE COLUMNS
Columns_Resize(lv);
//lv.Width = lv.Width + 22;
lv.AllowColumnReorder = true;
//lv.Height = 150;
foreach (ListViewItem itm in lv.Items)
{
if (itm.Index % 2 == 0) itm.BackColor = Color.LightSteelBlue;
foreach (ListViewItem.ListViewSubItem subItem in itm.SubItems) if (!string.IsNullOrWhiteSpace(subItem.Text)) subItem.BackColor = itm.BackColor;
}//BACKCOLOR FÜR JEDES ZWEITE ANDERE FARBE
return lv;
}
//TODO: Eventuell auch andere ListViews einbinden?
/// <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(Color.FromArgb(1, 53, 101), 2);
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;
}
/// <summary>
/// Bei DataGridView die Größe an Zeilen und Spalten anpassen.
/// </summary>
/// <param name="g"></param>
/// <returns></returns>
public static DataGridView DGV_Size_Anpassen( DataGridView g)
{
int totalWidth = g.RowHeadersVisible ? g.RowHeadersWidth : 0;
foreach (DataGridViewColumn col in g.Columns)
{
if (col.Visible) totalWidth += col.Width;
}
int totalHeight = g.ColumnHeadersVisible ? g.ColumnHeadersHeight : 0;
foreach (DataGridViewRow row in g.Rows)
{
if (row.Visible) totalHeight += row.Height;
}
totalHeight += g.ColumnHeadersHeight;
g.ClientSize = new Size(totalWidth, totalHeight);
return g;
}
public static DateTime GetNextLiefertag(Liefertage rhythmus)
{
DateTime aktDatum = DateTime.Today;
// Starte ab morgen und suche nächsten passenden Arbeitstag
for (int i = 2; 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 = new Title();
title.Text = Kunde.GetKunde(null, artikelDaten[0].KundeID, null).KundeName;
title.Font = new Font("Arial", 12, 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)
var serieGesamt = new Series("Gesamtmenge") { ChartType = SeriesChartType.Bar };
serieGesamt.CustomProperties = "DrawSideBySide=False, PointWidth=0.8";
//chart1.Series.Add(serieGesamt);
// Gestapelte Fehler-Serie (rechts darüber)
var serieFehler = new Series("Fehlmenge")
{
ChartType = SeriesChartType.StackedBar,
Color = Color.Orange
};
var serieReklamation = new Series("Reklamation")
{
ChartType = SeriesChartType.StackedBar,
Color = Color.Red
};
for (int i = 0; i < artikelDaten.Count; i++)
{
var daten = artikelDaten[i];
double index = i; // Gleicher X-Wert für alle Serien
serieGesamt.Points.AddXY(index, daten.Stand);
serieFehler.Points.AddXY(index, daten.Fehlmenge);
serieReklamation.Points.AddXY(index, daten.Reklamation);
// Label setzen (X-Achse zeigt Artikelnamen)
string label = daten.ArtikelName;
if (label.Length > 10)
label = label.Substring(0, 10) + "...";
serieGesamt.Points[i].AxisLabel = label;
}
chart1.Series.Add(serieGesamt);
chart1.Series.Add(serieFehler);
chart1.Series.Add(serieReklamation);
// Legende wird ausgeblendet
chart1.Legends.Clear();
// Für Y-Achse (Mengen) WAAGERECHT
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", 7, 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;
}
}
}