203 lines
6.0 KiB
VB.net
203 lines
6.0 KiB
VB.net
Imports System.CodeDom
|
|
Imports DocumentFormat.OpenXml.Bibliography
|
|
Imports DocumentFormat.OpenXml.Drawing
|
|
Imports Org.BouncyCastle.Utilities
|
|
Imports SDL
|
|
Imports Therefore.API
|
|
|
|
Public Class frmRoutendauerBerechnen
|
|
|
|
Public calculatedDate As New DateTime
|
|
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
|
|
Dim destination As String = ""
|
|
Dim departure As String
|
|
Dim transportmittel As String = "LKW" 'Defaultvalue -> wird in Zukunft ev. noch erweitert (LKW, Sprinter, etc.)
|
|
Dim days As Integer = -1
|
|
Dim calcDays As Integer = -1
|
|
Dim destinationShortcut As String = ""
|
|
|
|
|
|
Sub New(dest As String)
|
|
|
|
InitializeComponent()
|
|
destination = dest
|
|
|
|
End Sub
|
|
|
|
|
|
Function findDestinationAndReplaceToShortCut(destination As String) As String
|
|
|
|
Dim shortcut As String
|
|
shortcut = CStr(SQL.DLookup("[grz_ZollamtDST]", "[tblGrenzstelle]", "[grz_Grenzstelle]= '" & destination & "'", "AVISO", ""))
|
|
Return shortcut
|
|
|
|
End Function
|
|
|
|
Private Sub frmRoutendauerBerechnen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|
|
|
txtNach.Text = destination
|
|
destinationShortcut = findDestinationAndReplaceToShortCut(destination)
|
|
If destinationShortcut = "" Then
|
|
initComboboxDeparture(destination)
|
|
Else
|
|
initComboboxDeparture(destinationShortcut)
|
|
End If
|
|
|
|
txbAbgangsdatum._value = ""
|
|
|
|
End Sub
|
|
|
|
Sub initComboboxDeparture(destination As String)
|
|
|
|
cbxVon.Items.Clear()
|
|
cbxVon.fillWithSQL("SELECT [nctsr_von], [nctsr_von_region] FROM [tblNTCSRouten] WHERE [nctsr_nach] = '" & destination & "'", False, "FMZOLL", False)
|
|
cbxVon.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))
|
|
cbxVon.changeItem("")
|
|
If cbxVon._value = "" Then
|
|
MsgBox("Es wurde für die Bestimmungszollstelle " & txtNach.Text & " keine Route definiert." & vbCrLf & "Bitte voraus. Datum des Eintreffens manuell eingeben!")
|
|
End If
|
|
|
|
|
|
End Sub
|
|
|
|
Private Sub btnPlus_Click(sender As Object, e As EventArgs) Handles btnPlus.Click
|
|
If checkIfDepartureDateIsFilled() = False Then Exit Sub
|
|
addDaysToGivenDate(txbVoraussichtlichesEintreffen, 1)
|
|
calcDays += 1
|
|
checkIfDepatureDateIsNotPast()
|
|
End Sub
|
|
|
|
Private Sub btnMinus_Click(sender As Object, e As EventArgs) Handles btnMinus.Click
|
|
If checkIfDepartureDateIsFilled() = False Then Exit Sub
|
|
addDaysToGivenDate(txbVoraussichtlichesEintreffen, -1)
|
|
calcDays -= 1
|
|
checkIfDepatureDateIsNotPast()
|
|
End Sub
|
|
|
|
Function lookUpTripDuration() As Integer
|
|
|
|
Dim departure As String
|
|
|
|
departure = cbxVon._value
|
|
|
|
Try
|
|
days = CInt(SQL.DLookup("nctsr_dauer_in_tagen", "tblNTCSRouten", "[nctsr_von]='" & departure & "' AND [nctsr_nach]= '" & destinationShortcut & "' AND [nctsr_route]= 'Landweg' AND [nctsr_transportmittel]= '" & transportmittel & "'", "VERAG", 0))
|
|
Catch ex As Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
|
|
Return days
|
|
|
|
End Function
|
|
|
|
Private Sub addDaysToGivenDate(givenDate As VERAG_PROG_ALLGEMEIN.MyTextBox, days As Integer)
|
|
|
|
txbVoraussichtlichesEintreffen._value = Convert.ToDateTime(givenDate._value).AddDays(days)
|
|
txbVoraussichtlichesEintreffen.Show()
|
|
|
|
lblberechneteDauer.Text = CStr(calcDuration())
|
|
lblberechneteDauer.Visible = True
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
|
|
|
|
calculatedDate = CDate(txbVoraussichtlichesEintreffen._value)
|
|
|
|
End Sub
|
|
|
|
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
|
|
Close()
|
|
End Sub
|
|
|
|
Private Sub txbAbgangsdatum_TextChanged(sender As Object, e As EventArgs) Handles txbAbgangsdatum.TextChanged, cbxVon.SelectedValueChanged
|
|
|
|
If checkIfDepartureDateIsFilled() = False Then Exit Sub
|
|
|
|
days = lookUpTripDuration()
|
|
calcDays = days
|
|
|
|
If days >= 0 Then
|
|
addDaysToGivenDate(txbAbgangsdatum, days)
|
|
End If
|
|
|
|
checkIfDepatureDateIsNotPast()
|
|
|
|
End Sub
|
|
|
|
Function checkIfDepartureDateIsFilled() As Boolean
|
|
|
|
Dim isFilled = False
|
|
|
|
If txbAbgangsdatum._value = "" Then
|
|
lblWarning.Visible = True
|
|
lblDauer.Visible = False
|
|
lblberechneteDauer.Text = ""
|
|
lblberechneteDauer.Visible = False
|
|
btnOK.DialogResult = DialogResult.None
|
|
|
|
|
|
Else
|
|
|
|
lblWarning.Visible = False
|
|
isFilled = True
|
|
lblDauer.Visible = True
|
|
btnOK.DialogResult = DialogResult.OK
|
|
|
|
|
|
|
|
|
|
End If
|
|
|
|
Return isFilled
|
|
|
|
End Function
|
|
|
|
Function checkIfDepatureDateIsNotPast() As Boolean
|
|
Dim depatureDateIsNotPast = False
|
|
|
|
If txbVoraussichtlichesEintreffen._value <> "" Then
|
|
If CDate(txbVoraussichtlichesEintreffen._value) >= CDate(Today().ToShortDateString) Then
|
|
|
|
|
|
depatureDateIsNotPast = True
|
|
lbWarningDateIsPast.Visible = False
|
|
btnOK.DialogResult = DialogResult.OK
|
|
btnMinus.Enabled = True
|
|
Else
|
|
btnOK.DialogResult = DialogResult.None
|
|
lbWarningDateIsPast.Visible = True
|
|
btnMinus.Enabled = False
|
|
|
|
End If
|
|
End If
|
|
|
|
Return depatureDateIsNotPast
|
|
|
|
End Function
|
|
|
|
|
|
Function calcDuration() As Integer
|
|
Dim result As Integer = 0
|
|
|
|
If txbVoraussichtlichesEintreffen._value <> "" Then
|
|
Dim StartDate = Convert.ToDateTime(txbAbgangsdatum._value)
|
|
Dim EndDate = Convert.ToDateTime(txbVoraussichtlichesEintreffen._value)
|
|
result = (EndDate - StartDate).Days
|
|
If (result < 0) Then
|
|
MsgBox("Transportdauer kann nicht negativ sein!")
|
|
|
|
btnOK.DialogResult = DialogResult.None
|
|
Else
|
|
|
|
btnOK.DialogResult = DialogResult.OK
|
|
End If
|
|
End If
|
|
Return result
|
|
|
|
End Function
|
|
|
|
|
|
End Class |