Files
AVISO/Aviso/Auswertung/frmStatFrima.vb
2020-01-08 15:01:48 +01:00

232 lines
8.6 KiB
VB.net

Imports Gemeinsames
Imports VERAG_PROG_ALLGEMEIN
Public Class frmStatFrima
Public srch As String = ""
Public auftrFraecht As String = ""
Public StatVon As String = ""
Public StatBis As String = ""
Public DauerVon As String = ""
Public DauerBis As String = ""
Public firma As String = ""
Dim Sql As New Statistik
Private Sub frmStatFrima_Load(sender As Object, e As EventArgs) Handles Me.Load
initList()
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DataGridView2.SelectionMode = DataGridViewSelectionMode.FullRowSelect
lblFirma.Text = firma
Try
lblZeitraum.Text = StatVon & " - " & StatBis
Catch ex As Exception
End Try
' Me.Height =
End Sub
Sub initPnlStat()
If Not IsDate(StatVon) Then StatVon = "1800-01-01 00:00:00"
If Not IsDate(StatBis) Then StatBis = Now.ToString("yyyy-MM-dd HH:mm:ss")
If Not IsNumeric(DauerVon) Then DauerVon = "0"
If Not IsNumeric(DauerBis) Then DauerBis = "99999"
Dim SQLstat As New StatDB
Dim c As Integer = 0
Dim stdVon As Integer = CInt(Math.Floor(CInt(DauerVon) / 60))
Dim stdBis As Integer = CInt(Math.Ceiling(CInt(DauerBis) / 60))
' Dim s3(,) As String
Dim stepValue As Integer = 1
If (stdBis - stdVon) > 15 Then
stepValue = CInt(Math.Ceiling((stdBis - stdVon) / 15))
End If
DauerBis = CStr(CInt(DauerBis) + 1)
Dim s(CInt(stdBis / stepValue - stdVon), 2) As String
For i = stdVon To stdBis - 1 Step stepValue
Dim lkws As Integer = SQLstat.getAnzahlLkwDauer(CDate(StatVon), CDate(StatBis), CStr(i * 60), CStr((i + stepValue) * 60 - 1), DauerVon, DauerBis, " AND ( " & srch & " LIKE '" & auftrFraecht & "' ) ")
s(c, 0) = i & "-" & (i + stepValue) & " h"
s(c, 1) = CStr(lkws)
c += 1
Next
drawStat(pnlStat, s)
Dim listStatAvisoProleme As List(Of listStatAvisoProleme) = SQLstat.getAnzahlAvisoProbleme("", CDate(StatVon), CDate(StatBis), DauerVon, DauerBis, " AND ( " & srch & " LIKE '" & auftrFraecht & "' ) ")
ListView1.Columns.Add("Probleme", 150)
ListView1.Columns.Add("Anzahl", 50)
ListView1.View = View.Details
ListView1.FullRowSelect = True
For Each l In listStatAvisoProleme
Dim eintrag1 As New ListViewItem(l.Bezeichnung, 0)
eintrag1.SubItems.Add(l.AnzahlVermerke.ToString)
ListView1.Items.Add(eintrag1)
Next
End Sub
Sub initList()
With DataGridView1
Dim sqlstr As String = "select AvisoID, Datum, LKW_Nr, Dauer, Auftraggeber, Frächter, Ankunft, Freigabe, AvisoEingang, Grenzstelle, Info,LetzterMitarbeiter from Aviso "
'WHERE
Dim where As String = ""
If StatVon <> "" Then where &= " AND Datum >= '" & StatVon & "' "
If StatBis <> "" Then where &= " AND Datum <= '" & StatBis & "' "
If DauerVon <> "" Then where &= " AND Dauer >= '" & DauerVon & "' "
If DauerBis <> "" Then where &= " AND Dauer <= '" & DauerBis & "' "
sqlstr &= " WHERE ( " & srch & " LIKE '" & auftrFraecht & "' " & where & " ) AND Firma='" & VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA & "' "
sqlstr &= " ORDER BY Dauer DESC "
.DataSource = Sql.getKunden(sqlstr)
'.Columns(0).HeaderText
.Columns(0).Visible = False
.Columns(1).HeaderText = "Datum"
.Columns(4).HeaderText = "Avisierer"
.Columns("Info").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.Columns(2).HeaderText = "LKW-Kz"
If .RowCount > 0 Then
DataGridView1.Rows(0).Cells(0).Selected = True
DataGridView1_CellContentClick(DataGridView1, New DataGridViewCellEventArgs(0, 0))
End If
End With
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
If DataGridView1.SelectedCells.Count > 0 Then
With DataGridView2
If DataGridView1.SelectedRows.Count > 0 Then
Dim sqlstr As String = ""
sqlstr += " ("
sqlstr += " select VermerkID,'' as [AenderungID],AvisoID, Datum, Mitarbeiter, Hinweis_Vermerk from Vermerke WHERE ( AvisoID = '" & CStr(DataGridView1.SelectedRows(0).Cells(0).Value) & "' ) "
sqlstr += " union "
sqlstr += " select '',[AenderungID],[AvisoID],[Datum],[Mitarbeiter],[Aenderung_Text] "
sqlstr += " FROM [Aenderungen] WHERE ( AvisoID = '" & CStr(DataGridView1.SelectedRows(0).Cells(0).Value) & "' ) "
sqlstr += " ) "
sqlstr += " ORDER By Datum DESC"
' Dim sqlstr As String = "select VermerkID,AvisoID, Datum, Mitarbeiter, Hinweis_Vermerk from Vermerke WHERE ( AvisoID = '" & CStr(DataGridView1.SelectedRows(0).Cells(0).Value) & "' ) "
' sqlstr &= " ORDER BY Datum DESC "
.DataSource = Sql.getKunden(sqlstr)
.Columns(0).Visible = False
.Columns(1).Visible = False
.Columns(2).Visible = False
.Columns(3).HeaderText = "Datum"
.Columns(3).Width = 150
.Columns(4).HeaderText = "Mitarbeiter"
.Columns(4).Width = 300
.Columns(5).HeaderText = "Vermerk"
.Columns(5).MinimumWidth = 300
.Columns(5).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
End If
End With
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If DataGridView1.SelectedRows.Count > 0 Then
Dim frmLKWBericht As New frmLKWBericht(DataGridView1.SelectedRows(0).Cells("AvisoID").Value)
frmLKWBericht.ShowDialog(Me)
End If
Exit Sub
Dim str As String = ""
For Each r As DataGridViewRow In DataGridView1.Rows()
If r.Selected Then
str &= "'" & CStr(r.Cells(0).Value) & "',"
End If
Next
If str.EndsWith(",") Then str = str.Substring(0, str.Length - 1)
Dim f As New cStatFunctions
f.showReport("DETAILS", " SELECT * from Aviso where AvisoID IN (" & str & ")", True)
End Sub
Private Sub drawStat(p As Panel, s(,) As String) 'Handles Panel1.Paint
Dim g As Graphics = pnlStat.CreateGraphics
Dim topbound = 10
Dim y0 As Integer = 0
Dim x0 As Integer = 0
Dim yMax As Integer = p.Height - 50
Dim xMax As Integer = p.Width
Dim h As Integer = p.Height
Dim w As Integer = p.Width
Dim sMax As Long = getMax(s)
Dim xLeftBound As Integer = 0
For i = 0 To s.GetUpperBound(0) - 1
Try
Dim hoehe = 0
If sMax > 0 Then hoehe = CInt(yMax * (CLng(s(i, 1)) * 100 / sMax) / 100)
' MsgBox(CStr(s(i, 0)).ToString)
' g.FillRectangle(Brushes.Red, New Rectangle(x0 + xLeftBound, y0, 20, hoehe))
g.FillRectangle(Brushes.Red, CoordRectangle(w, h, x0 + xLeftBound, y0 + 20, 20, hoehe))
g.DrawString(CInt(s(i, 1)).ToString, New Font(p.Font.FontFamily, 8), Brushes.Black, CoordPoint(h, x0 + xLeftBound, 20 + hoehe + 15))
g.DrawString(CStr(s(i, 0)).ToString, New Font(p.Font.FontFamily, 7), Brushes.Black, CoordPoint(h, x0 + xLeftBound, 15))
xLeftBound += 30
Catch ex As Exception
End Try
Next
End Sub
Function getMax(s(,) As String) As Long
Dim max As Long = 0
For i = 0 To s.GetUpperBound(0) - 1
If CLng(s(i, 1)) > max Then
max = CLng(s(i, 1))
End If
Next
Return max
End Function
Function CoordRectangle(w As Integer, h As Integer, x0 As Integer, y0 As Integer, x As Integer, y As Integer) As Rectangle
' MsgBox(" x0: " & x0 & " y0: " & CStr(h - y0 - y) & " x: " & x & " y: " & y)
Return New Rectangle(x0, h - y0 - y, x, y)
End Function
Function CoordPoint(h As Integer, x As Integer, y As Integer) As Point
Return New Point(x, h - y)
End Function
Private Sub frmStatFrima_Shown(sender As Object, e As EventArgs) Handles Me.Shown
initPnlStat()
End Sub
Private Sub Label8_Click(sender As Object, e As EventArgs) Handles lblAnzLKWs.Click
End Sub
End Class