Danke @EaranMaleasi für deinen EInschub. Das finde ich enorm hilfreich! :o)
@ErfinderDesRades
Ich habe erstmal nur ein bisschen Code erstellt, um sicherzugehen, dass ich deine Vorgehensweise korrekt umgesetzt habe.
Den alten Code habe ich in der hochgeladenen Solution gelassen, aber auskommentiert - um eben nicht vom ooben erwähnten abzulenken.
Im nicht auskommentierten Code fehlt noch die höchste Tageseinnahme für jede Warengruppe - aber die ließe sich ja - sofern korrekt umgesetzt - auf die gleiche Art einbauen.
Den alten Code zur Jahresauswertung habe ich nicht eingebaut, da dieser einfach schlecht ist.
Ich habe diesen mal hinter folgendem Spoiler versteckt - er lässt sich in der Demosulution in die frmMain einkopieren und ist dort lauffähig.
Spoiler anzeigen
Hier die Zusammenfassung, was angezeigt werden soll:
@ErfinderDesRades
Ich habe erstmal nur ein bisschen Code erstellt, um sicherzugehen, dass ich deine Vorgehensweise korrekt umgesetzt habe.
ErfinderDesRades schrieb:
Ich würde die Rekorde beim Einlesen des Datasets ausrechnen und merken.
Man kann innerhalb des Datasets ja zusätzlichen Code anlegen - auch Variablen, die die Rekorde merken.
Den alten Code habe ich in der hochgeladenen Solution gelassen, aber auskommentiert - um eben nicht vom ooben erwähnten abzulenken.
Im nicht auskommentierten Code fehlt noch die höchste Tageseinnahme für jede Warengruppe - aber die ließe sich ja - sofern korrekt umgesetzt - auf die gleiche Art einbauen.
Den alten Code zur Jahresauswertung habe ich nicht eingebaut, da dieser einfach schlecht ist.
Ich habe diesen mal hinter folgendem Spoiler versteckt - er lässt sich in der Demosulution in die frmMain einkopieren und ist dort lauffähig.
VB.NET-Quellcode
- 'Sub zum erstellen der Monatsrekorde
- Private Sub DrawControlsMonthlyRecords()
- 'Anzahl der Warengruppen ermitteln
- Dim GroupCount As Integer
- GroupCount = DtsSettings.ProductGroup.Count
- If GroupCount = 0 Then Exit Sub
- Dim yPosition As Integer = 60 'y = unten / 570
- 'Controls für Kunden und Monatsumsatz anlegen
- 'Prüfen ob Umsätze vorhanden sind
- If DtsSettings.DailyIncome.Count = 0 Then Exit Sub
- 'Umsatz und Kundenrekorde suchen
- Dim strRecord As String = GetMonthlyIncomeAndCustomersRecord()
- Dim arrRecord() As String = strRecord.Split("|")
- 'Label für Beschriftung - Gesamtusatzrekord
- Dim LBLLabelIncome = New System.Windows.Forms.Label
- With LBLLabelIncome
- .Location = New System.Drawing.Point(490, yPosition)
- .Font = New Font("Microsoft Sans Serif", 12)
- .TextAlign = ContentAlignment.MiddleRight
- .Name = "LBLLabelMonthlyIncome"
- .Size = New System.Drawing.Size(200, 20)
- .Text = "Monatseinnahme"
- .Visible = True
- End With
- 'Label für Gesamtusatzrekord
- Dim LBLRecordIncome = New System.Windows.Forms.Label
- With LBLRecordIncome
- .Location = New System.Drawing.Point(700, yPosition)
- .Font = New Font("Microsoft Sans Serif", 12)
- .TextAlign = ContentAlignment.MiddleRight
- .Name = "LBLRecordMonthlyIncome"
- .Size = New System.Drawing.Size(120, 20)
- .Text = arrRecord(0)
- .Visible = True
- End With
- 'Label für Rekord Datum - Gesamtumsatz
- Dim LBLRecordIncomeDate = New System.Windows.Forms.Label
- With LBLRecordIncomeDate
- .Location = New System.Drawing.Point(830, yPosition)
- .Font = New Font("Microsoft Sans Serif", 12)
- .TextAlign = ContentAlignment.MiddleLeft
- .Name = "LBLRecordIncomeMonth"
- .Size = New System.Drawing.Size(150, 20)
- .Text = "im " & arrRecord(1)
- .Visible = True
- End With
- 'Controls auf die Form malen
- Me.Controls.Add(LBLLabelIncome)
- Me.Controls.Add(LBLRecordIncome)
- Me.Controls.Add(LBLRecordIncomeDate)
- yPosition += 30
- 'Label für Beschriftung - Gesamtkunden
- Dim LBLLabelCustomers = New System.Windows.Forms.Label
- With LBLLabelCustomers
- .Location = New System.Drawing.Point(490, yPosition)
- .Font = New Font("Microsoft Sans Serif", 12)
- .TextAlign = ContentAlignment.MiddleRight
- .Name = "LBLLabelMonthlyCustomers"
- .Size = New System.Drawing.Size(200, 20)
- .Text = "Kunden:"
- .Visible = True
- End With
- 'Label für Gesamtkundenrekord
- Dim LBLRecordCustomers = New System.Windows.Forms.Label
- With LBLRecordCustomers
- .Location = New System.Drawing.Point(700, yPosition)
- .Font = New Font("Microsoft Sans Serif", 12)
- .TextAlign = ContentAlignment.MiddleRight
- .Name = "LBLMonthlyRecordCustomers"
- .Size = New System.Drawing.Size(120, 20)
- .Text = arrRecord(2)
- .Visible = True
- End With
- 'Label für Rekord Datum - Kunden
- Dim LBLRecordCustomersDate = New System.Windows.Forms.Label
- With LBLRecordCustomersDate
- .Location = New System.Drawing.Point(830, yPosition)
- .Font = New Font("Microsoft Sans Serif", 12)
- .TextAlign = ContentAlignment.MiddleLeft
- .Name = "LBLRecordCustomersMonth"
- .Size = New System.Drawing.Size(150, 20)
- .Text = "im " & arrRecord(3)
- .Visible = True
- End With
- 'Controls auf die Form malen
- Me.Controls.Add(LBLLabelCustomers)
- Me.Controls.Add(LBLRecordCustomers)
- Me.Controls.Add(LBLRecordCustomersDate)
- yPosition += 50
- Dim Groupname As String
- 'Controls für jede Warengruppe erzeugen
- For i = 1 To GroupCount
- 'Name aus BindingSource lesen
- Dim ProductGroup = DirectCast(DirectCast(ProductGroupBindingSource(i - 1), DataRowView).Row, DtsSettings.ProductGroupRow)
- GroupName = ProductGroup.Name
- Dim strProductGroupRecord As String = GetMonthlyIncome(Groupname)
- 'LabelText in Variable speichern
- Dim arrProductGroupRecord() As String = strProductGroupRecord.Split("|")
- 'Label für Beschriftung
- Dim LBLLabel = New System.Windows.Forms.Label
- With LBLLabel
- .Location = New System.Drawing.Point(490, yPosition)
- .Font = New Font("Microsoft Sans Serif", 12)
- .TextAlign = ContentAlignment.MiddleRight
- .Name = "LBLLabelMonth " & Groupname
- .Size = New System.Drawing.Size(200, 20)
- .Text = GroupName
- .Visible = True
- End With
- 'Label für Rekord
- Dim LBLRecord = New System.Windows.Forms.Label
- With LBLRecord
- .Location = New System.Drawing.Point(700, yPosition)
- .Font = New Font("Microsoft Sans Serif", 12)
- .TextAlign = ContentAlignment.MiddleRight
- .Name = "LBLRecordMonth " & Groupname
- .Size = New System.Drawing.Size(120, 20)
- .Text = arrProductGroupRecord(0)
- .Visible = True
- End With
- 'Label für Rekord Datum
- Dim LBLRecordDate = New System.Windows.Forms.Label
- With LBLRecordDate
- .Location = New System.Drawing.Point(830, yPosition)
- .Font = New Font("Microsoft Sans Serif", 12)
- .TextAlign = ContentAlignment.MiddleLeft
- .Name = "LBLRecordMonth " & Groupname
- .Size = New System.Drawing.Size(150, 20)
- .Text = "im " & arrProductGroupRecord(1)
- .Visible = True
- End With
- 'Controls auf die Form malen
- Me.Controls.Add(LBLLabel)
- Me.Controls.Add(LBLRecord)
- Me.Controls.Add(LBLRecordDate)
- 'Position für nächste Controls anpassen
- yPosition += 30
- Next
- End Sub
- Private Function GetMonthlyIncomeAndCustomersRecord() As String
- 'Minimum und Maximum Jahr suchen
- Dim maxDate As Integer = Integer.Parse(DtsSettings.DailyIncome.Max(Function(x) x._Date).ToString("yyyy"))
- Dim minDate As Integer = Integer.Parse(DtsSettings.DailyIncome.Min(Function(x) x._Date).ToString("yyyy"))
- Dim _Date As Date
- Dim tempdate As Date
- Dim numberofdays As Integer
- Dim MonthlyIncome As Integer
- Dim MaxIncome As Integer
- Dim MonthlyCustomers As Integer
- Dim MaxCustomers As Integer
- Dim DateOfMaxIncome As Date
- Dim DateOfMaxCustomers As Date
- '1. Schleife für jedes Jahr
- For i = minDate To maxDate
- '2. Schleife für jeden Monat
- For j = 1 To 12
- 'Datum zusammenbauen
- _Date = Date.Parse("01." & j & "." & i)
- 'Anzahl der Tage für aktuellen Monat auslesen
- numberofdays = Integer.Parse(DateTime.DaysInMonth(i, j).ToString)
- '3. Schleife für jeden Tag des Monats
- For k = 0 To numberofdays - 1
- 'ausgewähltes Jahr
- tempdate = _Date.AddDays(k)
- 'Datum in den Einnahmen suchen
- Dim IncomeRow = DtsSettings.DailyIncome.FirstOrDefault(Function(x) x._Date.Date = tempdate)
- If IncomeRow Is Nothing Then Continue For 'Wenn nicht gefunden, nächster Durchgang
- 'Einnahme zusammenrechnen
- MonthlyIncome += IncomeRow.DailyIncome
- 'Kunden zusammenrechnen
- MonthlyCustomers += IncomeRow.CustomerCount
- Next
- 'Wenn Monatsumsatz größer als Gesamtumsatz speichern der Daten
- If MonthlyIncome > MaxIncome Then
- MaxIncome = MonthlyIncome
- DateOfMaxIncome = Date.Parse("01." & j & "." & i)
- End If
- 'Wenn Monatskunden größer als Gesamtkunden speichern der Daten
- If MonthlyCustomers > MaxCustomers Then
- MaxCustomers = MonthlyCustomers
- DateOfMaxCustomers = Date.Parse("01." & j & "." & i)
- End If
- MonthlyIncome = 0
- MonthlyCustomers = 0
- Next
- Next
- Return (MaxIncome / 100).ToString("#,##0.00 €") & "|" & DateOfMaxIncome.ToString("MMMM yyyy") & "|" & MaxCustomers & "|" & DateOfMaxCustomers.ToString("MMMM yyyy")
- End Function
- 'Funktion zum auslesen der Monatsumsätze für jede Warengruppe
- Private Function GetMonthlyIncome(Groupname As String) As String
- 'Minimum und Maximum Jahr suchen
- Dim maxDate As Integer = Integer.Parse(DtsSettings.DailyIncome.Max(Function(x) x._Date).ToString("yyyy"))
- Dim minDate As Integer = Integer.Parse(DtsSettings.DailyIncome.Min(Function(x) x._Date).ToString("yyyy"))
- Dim _Date As Date
- Dim tempdate As Date
- Dim numberofdays As Integer
- Dim groupcount As Integer = DtsSettings.ProductGroup.Count
- Dim MonthlyIncome As Integer
- Dim MaxIncome As Integer
- Dim DateofMaxIncome As Date
- '1. Schleife für jedes Jahr
- For i = minDate To maxDate
- '2. Schleife für jeden Monat
- For j = 1 To 12
- 'Datum zusammenbauen
- _Date = Date.Parse("01." & j & "." & i)
- 'Anzahl der Tage für aktuellen Monat auslesen
- numberofdays = Integer.Parse(DateTime.DaysInMonth(i, j).ToString)
- '3. Schleife für jeden Tag des Monats
- For k = 0 To numberofdays - 1
- 'ausgewähltes Jahr
- tempdate = _Date.AddDays(k)
- 'Datum in den Einnahmen suchen
- Dim IncomeRow = DtsSettings.DailyIncome.FirstOrDefault(Function(x) x._Date.Date = tempdate)
- If IncomeRow Is Nothing Then Continue For 'Wenn nicht gefunden, nächster Durchgang
- '4. Schleife für jede Warengruppe
- For L = 0 To groupcount - 1 'Schleife durch Product Group DataTable
- 'Name aus BindingSource lesen
- Dim ProductGroup = DirectCast(DirectCast(ProductGroupBindingSource(L), DataRowView).Row, DtsSettings.ProductGroupRow)
- If ProductGroup.Name = Groupname Then
- 'Warengruppenumsatz für Datum ermitteln und addieren
- Dim ProductGroupRow = DtsSettings.Distribution_Table.SingleOrDefault(Function(x) x.DailyIncomeRow._Date.Date = tempdate AndAlso x.ProductGroupRow.Name = groupname)
- If ProductGroupRow Is Nothing Then Continue For
- 'Umsätze addieren
- MonthlyIncome += ProductGroupRow.ProductGroupIncome
- End If
- Next
- Next
- If MonthlyIncome > MaxIncome Then
- MaxIncome = MonthlyIncome
- DateofMaxIncome = Date.Parse("01." & j & "." & i)
- End If
- MonthlyIncome = 0
- Next
- Next
- Return (MaxIncome / 100).ToString("#,##0.00 €") & "|" & DateofMaxIncome.ToString("MMMM yyyy")
- End Function
Hier die Zusammenfassung, was angezeigt werden soll:
- höchste Tageseinnahme (in Demo fertig)
- Tag mit den meisten Kunden (in Demo fertig)
- höchster Tagesumsatz für jede Warengruppe (wie höchste Tageseinnahme in Demo einbaubar - wenn mein Lösungsweg so ok ist)
- höchste Monatseinnahme
- Monat mit den meisten Kunden
- höchster Monatsumsatz für jede Warengruppe
- Monat mit höchstem pro Kopf Umsatz