Imports DocumentFormat.OpenXml.Drawing.Diagrams Public Class usrcntlFrachtkostenberechnung Dim absenderID As Integer = -1 Dim empfaengerID As Integer = -1 Dim origin As String Dim destination As String Dim ware 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 Dim warenbez As String Sub New() InitializeComponent() End Sub Public Sub init(absID As String, empfID As String, gewichtInput As String, gesamtfrachtkostenInput As String, ware As String, warenwert As String) If gesamtfrachtkostenInput IsNot Nothing AndAlso gesamtfrachtkostenInput.ToString <> "" AndAlso IsNumeric(gesamtfrachtkostenInput) Then gesamtFrachtkosten = CDbl(gesamtfrachtkostenInput) tbxGesamtfrachtkosten._value = gesamtFrachtkosten Else gesamtFrachtkosten = 0 End If If gewichtInput IsNot Nothing AndAlso gewichtInput.ToString <> "" AndAlso IsNumeric(gewichtInput) Then gewicht = CDbl(gewichtInput) Else gewicht = 0 End If 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 'cbxLandVon.fillWithSQL("SELECT Distinct(ISNULL([LandKz],'')) as LandKZ FROM [Adressen] order by LandKz asc", False, "FMZOLL", True, True) cbxLandVon.fillWithSQL(" select distinct landkz, Währungstabelle.Land from Währungstabelle where landkz is not null order by LandKz", True, "FMZOLL", True) cbxLandVon.changeItem(sql.DLookup("[LandKz]", "[Adressen]", "[AdressenNr]='" & absenderID & "'", "FMZOLL", "")) txbVonPLZ.fillWithSQL("SELECT ISNULL([PLZ],'') FROM [Adressen] where AdressenNr = '" & absenderID & "'", "FMZOLL") txbVonOrt.fillWithSQL("SELECT ISNULL([Ort],'') FROM [Adressen] where AdressenNr = '" & absenderID & "'", "FMZOLL") 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 [Adressen] where AdressenNr = '" & empfaengerID & "'", "FMZOLL") txbNachOrt.fillWithSQL("SELECT ISNULL([Ort],'') FROM [Adressen] where AdressenNr = '" & empfaengerID & "'", "FMZOLL") ckbManAnteilsermittlung.Checked = True tbEUAnteil._value = 0 tbNichtEUAnteil._value = 0 txbGewicht._value = gewicht.ToString txbFactor._value = 0.15 txtWare._value = ware txtGesamtgewicht._value = gewichtInput checkInputFields() End Sub Sub calculateFreight() 'resetInputFields() setControlEUAnteile() origin = IIf(cbxLandVon._value <> "", cbxLandVon.Text.Replace(cbxLandVon._value & " -", "").Trim(), "") & " " & IIf(txbVonPLZ._value <> "", txbVonPLZ._value, "") & " " & IIf(txbVonOrt._value <> "", txbVonOrt._value, "") destination = IIf(cbxLandNach._value <> "", cbxLandNach.Text.Replace(cbxLandNach._value & " -", "").Trim(), "") & " " & 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 von Serbien VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Horgoš", duration, distance,, getValues) VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Horgoš", destination, durationEU, distanceEU,, getValues) ElseIf cbxLandNach._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) ElseIf cbxLandNach._value = "GB" AndAlso ckbManAnteilsermittlung.Checked Then twoRouteRequest = True 'Dover ist EU Grenze für Lieferungen nach England VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Dover", durationEU, distanceEU,, getValues) VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Dover", destination, duration, distance,, getValues) ElseIf cbxLandVon._value = "GB" AndAlso ckbManAnteilsermittlung.Checked Then twoRouteRequest = True 'Dover ist EU Grenze für Lieferungen aus England VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Dover", duration, distance,, getValues) VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Dover", destination, durationEU, distanceEU,, getValues) ElseIf cbxLandVon._value = "SRB" AndAlso cbxLandNach._value = "D" AndAlso (absenderID = "551038" Or absenderID = "722998") AndAlso ckbManAnteilsermittlung.Checked Then twoRouteRequest = True 'Sonderfall für Lukow-Berechnung VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Bajakovo", duration, distance,, getValues) VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Bajakovo", 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 If gesamtFrachtkosten = 0 Then gesamtFrachtkosten = gewicht * CDbl(txbFactor._value) tbxGesamtfrachtkosten._value = gesamtFrachtkosten End If 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 = "" And txbVonPLZ._value = "") Then lblWarningAbgangort.Visible = True btnOK.DialogResult = DialogResult.OK isFilled = False End If If (txbNachOrt._value = "" And 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 txbCalcDistanceEU_TextChanged(sender As Object, e As EventArgs) Handles txbCalcDistanceEU.TextChanged, txbCalcDistanceNichtEU.TextChanged, txbCalcDistanceNichtEU.TextChanged, tbNichtEUAnteilberechnet.TextChanged, tbEUAnteil.TextChanged, tbNichtEUAnteil.TextChanged txbCalcDistanceEU2.Text = txbCalcDistanceEU.Text txbCalcDistanceNichtEU2.Text = txbCalcDistanceNichtEU.Text 'tbEUAnteilberechnet2.Text = txbCalcDistanceNichtEU.Text 'tbNichtEUAnteilberechnet22.Text = tbNichtEUAnteilberechnet.Text 'tbEUAnteil2.Text = tbEUAnteil.Text 'tbNichtEUAnteil2.Text = tbNichtEUAnteil.Text End Sub Private Sub MyTextBox1_ValueChanged() Handles MyTextBox1.ValueChanged If IsNumeric(MyTextBox1._value) AndAlso IsNumeric(txtVerzollungskosten._value) Then If CDbl(MyTextBox1._value) < 100 And CDbl(MyTextBox1._value) > 0 And CDbl(txtVerzollungskosten._value) > 0 Then txtWeitereTarifPos._value = CDbl((MyTextBox1._value * 100) * txtVerzollungskosten._value / (100 + CDbl(MyTextBox1._value * 100))) End If End If End Sub Private Sub MyTextBox2_ValueChanged() Handles MyTextBox2.ValueChanged, MyTextBox3.ValueChanged If IsNumeric(MyTextBox2._value) And IsNumeric(MyTextBox3._value) Then txtPreis._value = MyTextBox2._value * MyTextBox3._value End If End Sub Private Sub txtFrachtanteil_ValueChanged() Handles txtFrachtanteil.ValueChanged, txtPreis.ValueChanged If IsNumeric(txtFrachtanteil._value) And IsNumeric(txtPreis._value) Then txtVerzollungskosten._value = CDbl(txtPreis._value - txtFrachtanteil._value) End If End Sub Private Sub txtWarengewicht_ValueChanged() Handles txtWarengewicht.ValueChanged, MyTextBox6.ValueChanged If IsNumeric(txtWarengewicht._value) And IsNumeric(txtGesamtgewicht._value) Then Dim anteil As Double = Math.Round(CDbl(txtWarengewicht._value / txtGesamtgewicht._value * 100), 2) lblAnteil.Text = anteil & " %" If IsNumeric(MyTextBox6._value) Then txtWarenanteil._value = CDbl(MyTextBox6._value * anteil / 100) End If Else lblAnteil.Text = "" End If End Sub Private Sub txbCalcDistanceNichtEU2_TextChanged(sender As Object, e As EventArgs) Handles txbCalcDistanceNichtEU2.TextChanged, txbCalcDistanceEU2.TextAlignChanged If IsNumeric(txbCalcDistanceNichtEU2._value) AndAlso IsNumeric(txbCalcDistanceEU2._value) Then txtDistanzGes._value = CDbl(txbCalcDistanceNichtEU2._value) + CDbl(txbCalcDistanceEU2._value) End If End Sub Private Sub txtDistanzGes_ValueChanged() Handles txtDistanzGes.ValueChanged, txtWarenanteil.ValueChanged If IsNumeric(txtDistanzGes._value) And IsNumeric(txtWarenanteil._value) And IsNumeric(txbCalcDistanceEU2._value) Then txtGesamtsumme._value = CDbl(txtWarenanteil._value / txtDistanzGes._value * txbCalcDistanceEU2._value) txtFrachtanteil._value = txtGesamtsumme._value End If End Sub Private Sub txtVerzollungskosten_ValueChanged() Handles txtVerzollungskosten.ValueChanged, txtWeitereTarifPos.ValueChanged If IsNumeric(txtVerzollungskosten._value) AndAlso IsNumeric(txtWeitereTarifPos._value) Then txtBGLZoll._value = CDbl(txtVerzollungskosten._value) + CDbl(txtWeitereTarifPos._value) End If End Sub Private Sub txtPreis_ValueChanged() Handles txtPreis.ValueChanged If IsNumeric(txtPreis._value) Then txtEUST._value = txtPreis._value End If End Sub End Class