using DatenDB; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Collections; namespace Deckungsbeitrag { public partial class FormDeckungsbeitrag : Form { private ListViewColumnSorter lvwColumnSorter = new ListViewColumnSorter(true); public Kunde kunde = new Kunde(); public List umsatzliste = new List(); double fixlohnkosten; double variablekosten; double fixmietkosten; double gesamtumsatz; double filterumsatz; double filterumsatzVP; int? id = null; int year = 2019; int itemsinlistview; int Mietbetten; int Gesamtbetten; bool filter = false; int[] months = null; string order = "asc"; string[] selection = null; public FormDeckungsbeitrag() { InitializeComponent(); this.dTPJahr.Checked = true; dTPJahr_ValueChanged(this, null); this.dTPVergleich.Checked = true; Mietbetten = Kunde.GetBettenAnzahl("Miete"); Gesamtbetten = Kunde.GetBettenAnzahl("Lohn"); this.listViewDeckungsbeitrag.ListViewItemSorter = lvwColumnSorter; buttonOK_Click(this, null); } private void FormDeckungsbeitrag_Load(object sender, EventArgs e) { Lade_ListView(); } private void Lade_ListView() { listViewDeckungsbeitrag.SuspendLayout(); listViewDeckungsbeitrag.BeginUpdate(); listViewDeckungsbeitrag.Items.Clear(); itemsinlistview = 0; filterumsatz = 0; filterumsatzVP = 0; double leer = 0; //ERST KUNDENLISTE VON KUNDENLISTE DANN UMSÄTZE!! foreach (Umsatz ums in umsatzliste) { kunde = Kunde.GetKunde(null, ums.KundeID, null); ListViewItem item = new ListViewItem(); item.UseItemStyleForSubItems = false; item.Tag = kunde; item.Text = kunde.KundeNummer; item.SubItems.Add(kunde.KundeName); item.SubItems.Add(kunde.Region); item.SubItems.Add(kunde.Waescheart); item.SubItems.Add(kunde.Service); item.SubItems.Add(kunde.Bettenanzahl.ToString()); item.SubItems.Add(Umsatz.GetUmsatz(ums.KundeID, dTPVergleich.Value.Year, ums.Year, months).ToString("C2", CultureInfo.CurrentCulture));//UMSATZ VORPERIODE item.SubItems.Add(ums.Betrag.ToString("C2", CultureInfo.CurrentCulture));//UMSATZ WUNSCHPERIODE //ANFANG //UMSATZDIFFERENZ BERECHNEN IN EUR UND % if (Differenz_berechnen(ums.Betrag, Umsatz.GetUmsatz(ums.KundeID, dTPVergleich.Value.Year, ums.Year, months))[0] > 0) item.SubItems.Add(Differenz_berechnen(ums.Betrag, Umsatz.GetUmsatz(ums.KundeID, dTPVergleich.Value.Year, ums.Year, months))[0].ToString("C2", CultureInfo.CurrentCulture), Color.Green, item.BackColor, item.Font);//DIFFERENZ IN EUR else item.SubItems.Add(Differenz_berechnen(ums.Betrag, Umsatz.GetUmsatz(ums.KundeID, dTPVergleich.Value.Year, ums.Year, months))[0].ToString("C2", CultureInfo.CurrentCulture), Color.Green, item.BackColor, item.Font); if (Differenz_berechnen(ums.Betrag, Umsatz.GetUmsatz(ums.KundeID, dTPVergleich.Value.Year, ums.Year, months))[1] > 0) item.SubItems.Add("+" + Differenz_berechnen(ums.Betrag, Umsatz.GetUmsatz(ums.KundeID, dTPVergleich.Value.Year, ums.Year, months))[1].ToString("P2"), Color.Green, item.BackColor, item.Font);//DIFFERENZ IN % else item.SubItems.Add(Differenz_berechnen(ums.Betrag, Umsatz.GetUmsatz(ums.KundeID, dTPVergleich.Value.Year, ums.Year, months))[1].ToString("P2"), Color.Red, item.BackColor, item.Font); //ENDE //UMSATZDIFFERENZ BERECHNEN IN EUR UND % if (kunde.Bettenanzahl > 0) { item.SubItems.Add(GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[0].ToString("P2"));//UMSATZANTEIL item.SubItems.Add(GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[1].ToString("C2", CultureInfo.CurrentCulture));//KOSTENANTEIL item.SubItems.Add(GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[2].ToString("C2", CultureInfo.CurrentCulture));//UMSATZ/GAST item.SubItems.Add(GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[3].ToString("C2", CultureInfo.CurrentCulture));//BEWERTUNG IN EURO }//BEWERTUNG IN ZAHLEN else { item.SubItems.Add(leer.ToString("P2")); item.SubItems.Add(leer.ToString("C2", CultureInfo.CurrentCulture)); item.SubItems.Add(leer.ToString("C2", CultureInfo.CurrentCulture)); item.SubItems.Add(leer.ToString("C2", CultureInfo.CurrentCulture)); item.SubItems.Add("Z"); } if(kunde.Waescheart.Contains("Miet") && kunde.Waescheart != null) { if (GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[3] < Kosten_Pro_Gast()[2] * -1) item.SubItems.Add("C"); if (GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[3] < Kosten_Pro_Gast()[2] * -1 * 2) item.SubItems.Add("B"); if (GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[3] > Kosten_Pro_Gast()[2] * -1 * 2) item.SubItems.Add("A"); }//BEWERTUNG IN WORTEN else { if (GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[3] < Kosten_Pro_Gast()[1] * -1) item.SubItems.Add("C"); if (GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[3] < Kosten_Pro_Gast()[1] * -1 * 2) item.SubItems.Add("B"); if (GetBewertung((double)ums.Betrag, (int)kunde.Bettenanzahl)[3] > Kosten_Pro_Gast()[1] * -1 * 2) item.SubItems.Add("A"); } if (ums.Betrag != 0) { this.listViewDeckungsbeitrag.Items.Add(item); filterumsatz += ums.Betrag; ++itemsinlistview; } else if (!checkBox0ausblenden.Checked) { this.listViewDeckungsbeitrag.Items.Add(item); ++itemsinlistview; }//ERGEBNIS 0 AUSBLENDEN VIA CHECKBOX filterumsatz += Umsatz.GetUmsatz(ums.KundeID, dTPVergleich.Value.Year, ums.Year, null); } this.listViewDeckungsbeitrag.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); ListView.ColumnHeaderCollection cc = listViewDeckungsbeitrag.Columns; for (int i = 0; i < cc.Count; i++) { int colWidth = TextRenderer.MeasureText(cc[i].Text, listViewDeckungsbeitrag.Font).Width + 10; if (colWidth > cc[i].Width) { cc[i].Width = colWidth; } }//COLUMNS BREITE CONTENT ODER HEADER SIZE this.listViewDeckungsbeitrag.AllowColumnReorder = true; //ANFANG //STATUSSTRIP UND KOSTEN/GAST ANZEIGE this.labelAbschGast.Text = (Kosten_Pro_Gast()[0] * -1).ToString("C2"); this.labelFixGastEW.Text = (Kosten_Pro_Gast()[1] * -1).ToString("C2"); this.labelFixGastMW.Text = (Kosten_Pro_Gast()[2] * -1).ToString("C2"); this.toolStripStatusLabelKundegef.Text = itemsinlistview.ToString(); this.toolStripStatusLabelGesamtbetten.Text = Gesamtbetten.ToString(); this.toolStripStatusLabelMietbetten.Text = Mietbetten.ToString(); this.toolStripStatusLabelGesamtumsatz.Text = gesamtumsatz.ToString("C2"); this.toolStripStatusLabelFilterumsatz.Text = filterumsatz.ToString("C2"); this.toolStripStatusLabelFilterumsatzVP.Text = filterumsatzVP.ToString("C2"); this.toolStripStatusLabelSteigerung.Text = ((filterumsatz - filterumsatzVP) / filterumsatz).ToString("P2"); //ENDE //STATUSSTRIP UND KOSTEN/GAST ANZEIGE ListView_Design(); listViewDeckungsbeitrag.EndUpdate(); listViewDeckungsbeitrag.ResumeLayout(); } private void ListView_Design() { foreach (ListViewItem item in this.listViewDeckungsbeitrag.Items) { if (item.Index % 2 == 0) item.BackColor = Color.LightSteelBlue; else item.BackColor = Color.White;//BACKCOLOR FÜR JEDES ZWEITE AUF BLAU for (int i = 0; i < item.SubItems.Count; i++) { if (item.SubItems[i].Text.Equals("C")) item.SubItems[i].BackColor = Color.Red; else { if (item.SubItems[i].Text.Equals("B")) item.SubItems[i].BackColor = Color.Yellow; else { if (item.SubItems[i].Text.Equals("A")) item.SubItems[i].BackColor = Color.Green; else item.SubItems[i].BackColor = item.BackColor; } } item.SubItems[i].Font = item.Font; }//INDIVIDUELLE BACKCOLOR FÜR SUBITEMS } } private double[] GetBewertung(double kndums, int betten) { double[] bewertung = new double[4]; bewertung[0] = kndums / gesamtumsatz; //UMSATZANTEIL bewertung[1] = variablekosten * -1 * bewertung[0] / betten; //KOSTENANTEIL bewertung[2] = kndums / betten; //UMSATZ/GAST bewertung[3] = bewertung[2] - bewertung[1]; //BEWERTUNG IN EURO return bewertung; } private double[] Kosten_Pro_Gast() { double[] kosten = new double[3]; kosten[0] = fixmietkosten / (double)Mietbetten; //ABSCHREIBUNG MIETWÄSCHE kosten[1] = fixlohnkosten / (double)Gesamtbetten; //FIXGAST EIGENWÄSCHE kosten[2] = kosten[0] + kosten[1]; //FIXGAST MIETWÄSCHE return kosten; } private double[] Differenz_berechnen(double zahl1, double zahl2) { double[] diff = new double[2]; diff[0] = zahl1 - zahl2; //DIFFERENZ IN EUR diff[1] = diff[0] / zahl1; //DIFFERENZ IN % return diff; } private void listViewDeckungsbeitrag_ColumnClick(object sender, ColumnClickEventArgs e) { if (e.Column == lvwColumnSorter.SortColumn) { // Reverse the current sort direction for this column. if (lvwColumnSorter.Order == SortOrder.Ascending) lvwColumnSorter.Order = SortOrder.Descending; else lvwColumnSorter.Order = SortOrder.Ascending; } else { // Set the column number that is to be sorted; default to ascending. lvwColumnSorter.SortColumn = e.Column; lvwColumnSorter.Order = SortOrder.Ascending; } // Perform the sort with these new sort options. this.listViewDeckungsbeitrag.Sort(); ListView_Design(); } private void pictureBoxFilter_Click(object sender, EventArgs e) { if (filter == false) { filter = true; this.groupBoxFilter.Height = 100; }//CLICK AUF FILTERPFEIL else { filter = false; this.groupBoxFilter.Height = 20; } foreach (string region in Kunde.GetListSelection(1)) this.comboBoxregion.Items.Add(region); //COMBOBOX REGION BEFÜLLEN foreach (string art in Kunde.GetListSelection(2)) this.comboBoxwaescheart.Items.Add(art); //COMBOBOX WÄSCHEART BEFÜLLEN } private void buttonOK_Click(object sender, EventArgs e) { if (dTPMonat.Checked) { months = new int[1]; months[0] = dTPMonat.Value.Month; } else months = null;//FILTER NACH MONAT if (dTPJahr.Checked) year = dTPJahr.Value.Year;//FILTER NACH JAHR if (comboBoxregion.SelectedIndex >= 0) { selection = new string[2]; selection[0] = comboBoxregion.Name.Substring(8); selection[1] = comboBoxregion.SelectedItem.ToString(); }//FILTER NACH REGION if (comboBoxwaescheart.SelectedIndex >= 0) { selection = new string[2]; selection[0] = comboBoxwaescheart.Name.Substring(8); selection[1] = comboBoxwaescheart.SelectedItem.ToString(); }//FILTER NACH WÄSCHEART (MIETE, LOHN) if (checkBox1.Checked) { months = new int[2]; months[0] = 1; months[1] = 3; }//QUARTAL 1 GEWÄHLT if (checkBox2.Checked) { months = new int[2]; months[0] = 4; months[1] = 6; }//QUARTAL 2 GEWÄHLT if (checkBox3.Checked) { months = new int[2]; months[0] = 7; months[1] = 9; }//QUARTAL 3 GEWÄHLT if (checkBox4.Checked) { months = new int[2]; months[0] = 10; months[1] = 12; }//QUARTAL 4 GEWÄHLT if (comboBoxregion.SelectedIndex >= 0 && comboBoxwaescheart.SelectedIndex >= 0) { Array.Resize(ref selection, 4); selection[0] = comboBoxregion.Name.Substring(8); selection[1] = comboBoxregion.SelectedItem.ToString(); selection[2] = comboBoxwaescheart.Name.Substring(8); selection[3] = comboBoxwaescheart.SelectedItem.ToString(); }//BEIDE SELECTIONS AUSGEWÄHLT!! if (!string.IsNullOrEmpty(textBoxkunde_nr.Text)) //FITERN NACH KUNDENNUMMER if (kunde.CheckKndNr(textBoxkunde_nr.Text) != 0) id = kunde.CheckKndNr(textBoxkunde_nr.Text); getUmsatz(); getKosten(); Lade_ListView(); } private void getUmsatz() { umsatzliste = Umsatz.GetList(id, year, months, order, selection, filter); gesamtumsatz = Umsatz.GetUmsatz(null, year, null, months); } private void getKosten() { fixlohnkosten = Kosten.GetKosten(year, months, 0); variablekosten = Kosten.GetKosten(year, months, 1); fixmietkosten = Kosten.GetKosten(year, months, 2); } private void buttonFilterCl_Click(object sender, EventArgs e) { foreach (Control ctl in this.groupBoxFilter.Controls) { Type t = ctl.GetType(); if(t == typeof(ComboBox)) { ComboBox cb = (ComboBox)ctl; cb.SelectedIndex = -1; } if(t == typeof(TextBox)) { TextBox tb = (TextBox)ctl; tb.Clear(); } if(t == typeof(DateTimePicker)) { DateTimePicker dtp = (DateTimePicker)ctl; if(dtp.Name == "dTPMonat")dtp.Checked = false; months = null; } if(t == typeof(CheckBox)) { CheckBox chb = (CheckBox)ctl; chb.Checked = false; } } foreach (Control ctl in this.groupBoxQuartal.Controls) { Type t = ctl.GetType(); if (t == typeof(ComboBox)) { ComboBox cb = (ComboBox)ctl; cb.SelectedIndex = -1; } if (t == typeof(TextBox)) { TextBox tb = (TextBox)ctl; tb.Clear(); } if (t == typeof(DateTimePicker)) { DateTimePicker dtp = (DateTimePicker)ctl; if (dtp.Name == "dTPMonat") dtp.Checked = false; months = null; } if (t == typeof(CheckBox)) { CheckBox chb = (CheckBox)ctl; chb.Checked = false; } } foreach (Control ctl in this.groupBoxBettenanzahl.Controls) { Type t = ctl.GetType(); if (t == typeof(ComboBox)) { ComboBox cb = (ComboBox)ctl; cb.SelectedIndex = -1; } if (t == typeof(TextBox)) { TextBox tb = (TextBox)ctl; tb.Clear(); } if (t == typeof(DateTimePicker)) { DateTimePicker dtp = (DateTimePicker)ctl; if (dtp.Name == "dTPMonat") dtp.Checked = false; months = null; } if (t == typeof(CheckBox)) { CheckBox chb = (CheckBox)ctl; chb.Checked = false; } } foreach (Control ctl in this.groupBoxUmsatzZeit.Controls) { Type t = ctl.GetType(); if (t == typeof(ComboBox)) { ComboBox cb = (ComboBox)ctl; cb.SelectedIndex = -1; } if (t == typeof(TextBox)) { TextBox tb = (TextBox)ctl; tb.Clear(); } if (t == typeof(DateTimePicker)) { DateTimePicker dtp = (DateTimePicker)ctl; if (dtp.Name == "dTPMonat") dtp.Checked = false; months = null; } if (t == typeof(CheckBox)) { CheckBox chb = (CheckBox)ctl; chb.Checked = false; } } } private void checkBox0ausblenden_Click(object sender, EventArgs e) { Lade_ListView(); } private void dTPJahr_ValueChanged(object sender, EventArgs e) { this.dTPVergleich.Value = dTPJahr.Value.AddYears(-1); }//VERGLEICHSJAHR AUTOMATISCH MINUS 1 JAHR } }