using BrightIdeasSoftware; using DatenDB; using Spire.Barcode; using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.Drawing.Printing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ZXing; using System.Windows.Forms.DataVisualization.Charting; using System.Data.SqlClient; using System.Web; namespace Deckungsbeitrag { public partial class KundeDaten : Form { List sortimentListe = null; List resultList = null; Sortiment result = null; Kunde adresse = null; Bitmap bitmap = null; Image qrcode = null; public KundeDaten() { InitializeComponent(); sortimentListe = (List)Funktionen.SortimentLesen("Liste"); foreach (Control ctr in this.Controls) if (ctr is TextBox) if (!ctr.Name.Contains("KndNr") && !ctr.Name.Contains("Suchtext")) ctr.Enabled = false; this.buttonProgramm.Enabled = false; this.buttonBewertung.Enabled = false; this.tSBDrucken.Enabled = false; this.tSBNext.Enabled = false; List aufgabenlist1 = Aufgabe.GetList(2); this.comboBoxAufgabe.DataSource = aufgabenlist1; this.comboBoxAufgabe.DisplayMember = "Bezeichnung"; this.comboBoxAufgabe.SelectedIndex = -1; this.comboBoxAufgabe.Enabled = false; this.buttonAufgEnt.Enabled = false; } public KundeDaten(Kunde kunde) :this() { this.adresse = kunde; //Funktionen.SortimentLesen("Liste"); this.textBoxKndNr.Text = kunde.KundeNummer; TextBoxKndNr_Leave(this, null); //OLV_Load(); //Chart_Load(); } //private bool SortimentLesen() //{ // bool ok = false; // 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 ok; // } // int nr = 0; // string row = string.Empty; // Sortiment[] sortiment = new Sortiment[0]; // sortimentListe = new List(); // int idx = 0; // while (!streamReader.EndOfStream) // { // Array.Resize(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 ok; //} private void DatenLesen() { foreach (Control ctr in this.Controls) if (ctr is TextBox) ctr.Enabled = false; this.comboBoxAufgabe.Enabled = true; 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); resultList = sortimentListe.FindAll(Sortiment => Sortiment.KundeNummer == sortNr); BarcodeWriter code = new BarcodeWriter(); code.Format = BarcodeFormat.QR_CODE; qrcode = code.Write(adresse.KundeNummer); if (resultList != null) //KONTROLLE OB SORTIMENT VORHANDEN MIT RESULT...WERT VON resultList WENN KUNDE HAT KEIN SORTIMENT?????? { Entwurf_Erstellen(); this.pictureBoxEntwurf.Visible = true; this.pictureBoxEntwurf.Image = bitmap; } else MessageBox.Show("Der gesuchte Kunde hat kein Sortiment."); tSSLabelArtikelAnz.Text = resultList.Count.ToString(); this.textBoxKndNr.Text = adresse.KundeNummer; this.textBoxKundeName.Text = adresse.KundeName; this.textBoxKndName2.Text = adresse.KundeName2; this.textBoxStraße.Text = adresse.Strasse; this.textBoxPLZ.Text = adresse.PLZ.ToString(); this.textBoxOrt.Text = adresse.Ort; this.textBoxSuchtext.Text = adresse.Suchtext; foreach (Aufgabe auf in comboBoxAufgabe.Items) if (auf.AufgabeID == adresse.Aufgabe) this.comboBoxAufgabe.SelectedItem = auf; if (this.comboBoxAufgabe.SelectedItem != null) this.buttonAufgEnt.Enabled = true; this.pictureBoxQRCode.Image = qrcode; this.pictureBoxQRCode.SizeMode = PictureBoxSizeMode.Zoom; this.buttonProgramm.Text = "WP 01"; //AUS DATENBANK STANDART-WASCHPROGRAMM EINFÜGEN. this.buttonProgramm.Enabled = true; this.buttonBewertung.Enabled = true; this.tSBDrucken.Enabled = true; this.tSBNext.Enabled = true; OLV_Load(); Chart_Load(); } private void Entwurf_Erstellen() { int ezl = 50; int handzeile = 33; float textsize = 10; float textsize2 = 20; int idx = 0; int idx1 = 0; int length = 0; 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; int qr = (int)textSize3.Height * 2 + (int)textSize2.Height * 3; g.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height); //QR-Code g.DrawImage(qrcode, bitmap.Width - 50 - qr, 50, qr, qr); //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, 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, bitmap.Height - 130); //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 - 130 - textsize, bitmap.Width - 100, 100); } private void TSBBeenden_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } private void OLV_Load() { foreach(ObjectListView olv in this.Controls.OfType()) { olv.HeaderFormatStyle = Funktionen.GetHeader(); olv.OwnerDraw = true; Generator.GenerateColumns(olv, typeof(OLVKundenumsatz), true); if (olv.Name.Contains("Jahresumsatz")) { foreach (OLVColumn c in olv.Columns) if (c.Name == "Zeitraum") c.Text = "Jahr"; olv.SetObjects(OLVKundenumsatz.GetJahresumsatz(adresse.KundeID)); } if (olv.Name.Contains("Quartalsumsatz")) { foreach (OLVColumn c in olv.Columns) if (c.Name == "Zeitraum") c.Text = "Quartal"; olv.SetObjects(OLVKundenumsatz.GetQuartalsumsatz(adresse.KundeID)); } if (olv.Name.Contains("Monatsumsatz")) { foreach (OLVColumn c in olv.Columns) if (c.Name == "Zeitraum") c.Text = "Monat"; olv.SetObjects(OLVKundenumsatz.GetMonatsumsatz(adresse.KundeID)); } } } private void Chart_Load() { foreach (Chart chart in this.Controls.OfType()) chart.Visible = true; //IMPLEMENTIEREN ClassChart ch = ClassChart.FillChart(adresse.KundeID); //Chart Jahresumsatz List olv = OLVKundenumsatz.GetJahresumsatz(adresse.KundeID); string[] x = new string[olv.Count()]; double[] y = new double[olv.Count()]; for (int i = 0; i < y.Length; i++) { y[i] = olv[i].Umsatz; x[i] = olv[i].Zeitraum; } this.chartJahresumsatz.Series[0].LegendText = "Umsatz"; this.chartJahresumsatz.Series[0].ChartType = SeriesChartType.Column; this.chartJahresumsatz.Series[0].IsValueShownAsLabel = true; this.chartJahresumsatz.Series[0].Points.DataBindXY(x, y); //Chart Quartalsumsatz List olvq = OLVKundenumsatz.GetQuartalsumsatz(adresse.KundeID); string[] xq = new string[olvq.Count()]; double[] yq = new double[olvq.Count()]; for (int i = 0; i < olvq.Count(); i++) { yq[i] = olvq[i].Umsatz; xq[i] = olvq[i].Zeitraum; } this.chartQuartalsumsatz.Series[0].LegendText = "Umsatz"; this.chartQuartalsumsatz.Series[0].ChartType = SeriesChartType.Bar; this.chartQuartalsumsatz.Series[0].IsValueShownAsLabel = true; this.chartQuartalsumsatz.Series[0].Points.DataBindXY(xq, yq); } private void TextBoxKndNr_Leave(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(textBoxKndNr.Text)) { this.textBoxSuchtext.Enabled = false; adresse = Kunde.GetKunde(textBoxKndNr.Text, null, null); if (adresse == null) { MessageBox.Show("Kunden Nummer nicht vorhanden!!"); this.textBoxSuchtext.Enabled = true; this.textBoxKndNr.Clear(); this.textBoxKndNr.Focus(); return; } else DatenLesen(); } else { this.textBoxSuchtext.Enabled = true; return; } } private void ButtonDrucken_Click(object sender, EventArgs e) { //PrintDialog dialog = new PrintDialog(); //foreach(string printer in PrinterSettings.InstalledPrinters) if (printer.Contains(ConfigurationManager.AppSettings["PrinterName"])) dialog.PrinterSettings.PrinterName = printer; // dialog.PrinterSettings.Copies = 10; // if (dialog.ShowDialog() == DialogResult.OK) //{ // PrintDocument printDocument = new PrintDocument(); // printDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage); // printDocument.PrinterSettings = dialog.PrinterSettings; // printDocument.Print(); //} Funktionen.SWS_Drucken(null, adresse); } private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(bitmap, e.PageBounds); //e.Graphics.DrawImage(bitmap, 0, 0, 790, 900); } private void TSBNext_Click(object sender, EventArgs e) { foreach (Control ctr in this.Controls) { if (ctr is TextBox) { ctr.Text = ""; if (!ctr.Name.Contains("KndNr") && !ctr.Name.Contains("Suchtext")) ctr.Enabled = false; else ctr.Enabled = true; } this.textBoxKndNr.Focus(); } this.pictureBoxEntwurf.Image = null; this.pictureBoxQRCode.Image = null; this.buttonProgramm.Enabled = false; this.buttonBewertung.Enabled = false; this.comboBoxAufgabe.Enabled = false; this.buttonAufgEnt.Enabled = false; this.tSBNext.Enabled = false; this.tSBDrucken.Enabled = false; foreach (ObjectListView olv in this.Controls.OfType()) olv.Clear(); foreach (Chart chart in this.Controls.OfType()) chart.Visible = false; } private void ButtonProgramm_Click(object sender, EventArgs e) { FormProgrammauswahl auswahl = new FormProgrammauswahl(); if (auswahl.ShowDialog() == DialogResult.OK) { DatenLesen(); } } private void textBoxSuchtext_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(textBoxSuchtext.Text)) { this.textBoxSuchtext.AutoCompleteCustomSource = Kunde.GetSuchtext(textBoxSuchtext.Text); } } private void TextBoxSuchtext_Leave(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(textBoxSuchtext.Text)) { if (Kunde.GetKunde(textBoxSuchtext.Text, null, string.Empty) != null) adresse = Kunde.GetKunde(textBoxSuchtext.Text.ToUpper(), null, string.Empty); else { MessageBox.Show($"Kunde mit {textBoxSuchtext.Text} als Suchtext ist nicht vorhanden!!"); this.textBoxSuchtext.Clear(); this.textBoxSuchtext.Focus(); return; } DatenLesen(); } } private void textBoxSuchtext_KeyDown(object sender, KeyEventArgs e) { TextBox tb = (TextBox)sender; if (e.KeyData == Keys.Enter || e.KeyData == Keys.Tab) { if (tb.Name.Contains("KndNr")) TextBoxKndNr_Leave(this, null); if (tb.Name.Contains("Suchtext")) TextBoxSuchtext_Leave(this, null); e.Handled = true; } } private void comboBoxAufgabe_DropDownClosed(object sender, EventArgs e) { if (MessageBox.Show("Möchtest du die Aufgabe speichern?", "Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (this.comboBoxAufgabe.SelectedItem == null) adresse.Aufgabe = null; else adresse.Aufgabe = ((Aufgabe)this.comboBoxAufgabe.SelectedItem).AufgabeID; adresse.Save(); } } private void buttonAufgEnt_Click(object sender, EventArgs e) { if (MessageBox.Show("Möchtest du die Aufgabe wirklich löschen?", "Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.comboBoxAufgabe.SelectedIndex = -1; adresse.Aufgabe = null; adresse.Save(); } } private void KundeDaten_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.End) TSBNext_Click(this, e); } private void nextToolStripMenuItem_Click(object sender, EventArgs e) { TSBNext_Click(this, e); } private void nächsterKundeToolStripMenuItem_Click(object sender, EventArgs e) { TSBNext_Click(this, e); } } }