Files
AVISO/Aviso/frmFrachtkostenBerechnen.vb

269 lines
9.9 KiB
VB.net

Imports System.Linq.Expressions
Imports System.Security.Cryptography
Imports DocumentFormat.OpenXml.Drawing
Imports DocumentFormat.OpenXml.Office.MetaAttributes
Imports VERAG_PROG_ALLGEMEIN
Public Class frmFrachtkostenBerechnen
Dim absenderID As Integer = -1
Dim empfaengerID As Integer = -1
Dim origin As String
Dim destination As String
Public EUAnteil As Double
Public nichtEUAnteil As Double
Dim gewicht As Double
Dim gesamtFrachtkosten As Double
Dim sql As New VERAG_PROG_ALLGEMEIN.SQL
Sub New(absID As String, empfID As String, gewichtInput As Double)
InitializeComponent()
Try
gewicht = IIf(gewichtInput.ToString <> "", CDbl(gewichtInput), 0)
If absID IsNot Nothing AndAlso absID.ToString <> "" AndAlso IsNumeric(absID) Then
absenderID = CInt(absID)
Else
absenderID = -1
End If
If empfID IsNot Nothing AndAlso empfID.ToString <> "" AndAlso IsNumeric(empfID) Then
empfaengerID = Int(empfID)
Else
empfaengerID = -1
End If
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
Private Sub frmFrachtkotenBerechnen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cbxLandVon.fillWithSQL("SELECT Distinct(ISNULL([LandKz],'')) as LandKZ FROM [VERAG].[dbo].[Adressen] order by LandKz asc", False, "FMZOLL", True, True)
cbxLandVon.changeItem(sql.DLookup("[LandKz]", "[Adressen]", "[AdressenNr]='" & absenderID & "'", "FMZOLL", ""))
txbVonPLZ.fillWithSQL("SELECT ISNULL([PLZ],'') FROM [VERAG].[dbo].[Adressen] where AdressenNr = '" & absenderID & "'")
txbVonOrt.fillWithSQL("SELECT ISNULL([Ort],'') FROM [VERAG].[dbo].[Adressen] where AdressenNr = '" & absenderID & "'")
cbxLandNach.Items.AddRange(cbxLandVon.Items.Cast(Of VERAG_PROG_ALLGEMEIN.MyListItem).ToArray())
cbxLandNach.changeItem(sql.DLookup("[LandKz]", "[Adressen]", "[AdressenNr]='" & empfaengerID & "'", "FMZOLL", ""))
txbNachPLZ.fillWithSQL("SELECT ISNULL([PLZ],'-') FROM [VERAG].[dbo].[Adressen] where AdressenNr = '" & empfaengerID & "'")
txbNachOrt.fillWithSQL("SELECT ISNULL([Ort],'') FROM [VERAG].[dbo].[Adressen] where AdressenNr = '" & empfaengerID & "'")
ckbManAnteilsermittlung.Checked = True
tbEUAnteil._value = 0
tbNichtEUAnteil._value = 0
txbGewicht._value = gewicht.ToString
txbFactor._value = 0.15
checkInputFields()
End Sub
Sub calculateFreight()
'resetInputFields()
setControlEUAnteile()
origin = IIf(cbxLandVon._value <> "", cbxLandVon._value, "") & " " & IIf(txbVonPLZ._value <> "", txbVonPLZ._value, "") & " " & IIf(txbVonOrt._value <> "", txbVonOrt._value, "")
destination = IIf(cbxLandNach._value <> "", cbxLandNach._value, "") & " " & IIf(txbNachPLZ._value <> "", txbNachPLZ._value, "") & " " & IIf(txbNachOrt._value <> "", txbNachOrt._value, "")
Dim getValues = True
Dim twoRouteRequest As Boolean = False
Dim duration = ""
Dim distance = ""
Dim durationEU = ""
Dim distanceEU = ""
If cbxLandVon._value = "TR" AndAlso ckbManAnteilsermittlung.Checked Then
twoRouteRequest = True
'Kapitan Andreevo ist EU Grenze für Lieferungen aus der Türkei
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Kapitan Andreevo", duration, distance,, getValues)
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Kapitan Andreevo", destination, durationEU, distanceEU,, getValues)
ElseIf cbxLandVon._value = "SRB" AndAlso ckbManAnteilsermittlung.Checked Then
twoRouteRequest = True
'Horgoš ist EU Grenze für Lieferungen aus Serbien
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Horgoš", duration, distance,, getValues)
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Horgoš", destination, durationEU, distanceEU,, getValues)
End If
If twoRouteRequest = True AndAlso ckbManAnteilsermittlung.Checked Then
lblDistanzEU.Text = "EU-Distanz"
lblDistanzNichtEU.Visible = True
txbCalcDistanceNichtEU.Visible = True
Try
If (IsNumeric(distanceEU)) Then
IIf(distanceEU > 1000, Math.Round(distanceEU / 1000, 0), distanceEU)
txbCalcDistanceEU._value = IIf(distanceEU > 1000, Math.Round(distanceEU / 1000, 0), distanceEU)
Else
distanceEU = "0"
MsgBox("Standort vom Bestimmungsort kann nicht ermittelt werden!" & vbCr & "Bitte Eingabe " & txbNachPLZ._value & " " & txbNachOrt._value & " prüfen")
Exit Sub
End If
If (IsNumeric(distance)) Then
txbCalcDistanceNichtEU._value = IIf(CInt(distance) > 1000, Math.Round(CInt(distance) / 1000, 0), CInt(distance))
Else
distance = "0"
MsgBox("Standort vom Abgangsort kann nicht ermittelt werden!" & vbCr & "Bitte Eingabe " & txbVonPLZ._value & " " & txbVonOrt._value & " prüfen")
Exit Sub
End If
Dim totalDistance = CDbl(distance) + CDbl(distanceEU)
Dim distanceNotEUpercent = CDbl(distance) * 100 / totalDistance
Dim distanceEUpercent = CDbl(distanceEU) * 100 / totalDistance
Math.Round(distanceNotEUpercent, 2)
Math.Round(distanceEUpercent, 2)
tbEUAnteil._value = CDbl(distanceEUpercent) / 100
tbNichtEUAnteil._value = CDbl(distanceNotEUpercent) / 100
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
ElseIf ckbManAnteilsermittlung.Checked Then
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, destination, duration, distance)
tbEUAnteil._value = 0.6
tbNichtEUAnteil._value = 0.4
If distance = "0" Or distance = "" Then
MsgBox("Standort vom Abgangsort/Bestimmungsort kann nicht ermittelt werden!" & vbCr & "Bitte Eingabe prüfen")
End If
lblDistanzEU.Text = "Distanz"
txbCalcDistanceEU._value = distance
lblDistanzNichtEU.Visible = False
txbCalcDistanceNichtEU.Visible = False
Else
lblDistanzEU.Text = "Distanz"
txbCalcDistanceEU._value = distance
lblDistanzNichtEU.Visible = False
txbCalcDistanceNichtEU.Visible = False
End If
End Sub
Sub calculateFreightCosts()
Try
gesamtFrachtkosten = gewicht * CDbl(txbFactor._value)
tbxGesamtfrachtkosten._value = gesamtFrachtkosten
EUAnteil = gesamtFrachtkosten * tbEUAnteil._value
nichtEUAnteil = gesamtFrachtkosten * CDbl(tbNichtEUAnteil._value)
tbEUAnteilberechnet._value = CStr(EUAnteil)
tbNichtEUAnteilberechnet._value = CStr(nichtEUAnteil)
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
Function checkInputFields() As Boolean
Dim isFilled As Boolean = True
lblWarningAbgangort.Visible = False
lblWarningBestimmungsort.Visible = False
lblWarningEUAnteil.Visible = False
lblWarningNichtEUAnteil.Visible = False
btnOK.DialogResult = DialogResult.OK
If (tbEUAnteil._value = "" Or Not IsNumeric(tbEUAnteil._value)) Then
lblWarningEUAnteil.Visible = True
btnOK.DialogResult = DialogResult.OK
isFilled = False
End If
If (tbNichtEUAnteil._value = "" Or Not IsNumeric(tbNichtEUAnteil._value)) Then
lblWarningNichtEUAnteil.Visible = True
btnOK.DialogResult = DialogResult.OK
isFilled = False
End If
If (txbFactor._value = "" Or Not IsNumeric(txbFactor._value)) Then
'Hinweis INPUT false
End If
If (txbVonOrt._value = "" Or txbVonPLZ._value = "") Then
lblWarningAbgangort.Visible = True
btnOK.DialogResult = DialogResult.OK
isFilled = False
End If
If (txbNachOrt._value = "" Or txbNachPLZ._value = "") Then
lblWarningBestimmungsort.Visible = True
btnOK.DialogResult = DialogResult.OK
isFilled = False
End If
Return isFilled
End Function
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
If (checkInputFields() = False) Then Exit Sub
calculateFreight()
If (checkInputFields() = False) Then Exit Sub
calculateFreightCosts()
End Sub
Private Sub resetInputFields()
txbCalcDistanceEU.Clear()
txbCalcDistanceNichtEU.Clear()
tbEUAnteilberechnet.Clear()
tbNichtEUAnteilberechnet.Clear()
If tbEUAnteil._value = "" Then tbEUAnteil._value = 0
If tbNichtEUAnteil._value = "" Then tbNichtEUAnteil._value = 0
End Sub
Private Sub setControlEUAnteile()
If ckbManAnteilsermittlung.Checked Then
tbEUAnteil.Enabled = False
tbNichtEUAnteil.Enabled = False
Else
tbEUAnteil.Enabled = True
tbNichtEUAnteil.Enabled = True
resetInputFields()
End If
End Sub
Private Sub ckbManAnteilsermittlung_CheckStateChanged(sender As Object, e As EventArgs) Handles ckbManAnteilsermittlung.CheckStateChanged
setControlEUAnteile()
End Sub
End Class