Imports System.Data
Imports System.Data.SqlClient
Imports System.Globalization
Imports System.IO
Imports System.Web.Services
Imports iTextSharp.text
Imports iTextSharp.text.pdf

Partial Class Customers_Default3
    Inherits System.Web.UI.Page

    Dim datevon As DateTime
    Dim datebis As DateTime
    Dim Kdnrtext As String
    Dim Absender As String = ""
    Dim Empfaenger As String = ""
    Dim LKWNR As String = ""
    Dim KDNAFNR As String = ""
    Dim dt As List(Of VERAG_PROG_ALLGEMEIN.cRechnungsausgang)
    Dim reNr As String = "-1"
    Dim provider As CultureInfo = CultureInfo.InvariantCulture

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Page.UnobtrusiveValidationMode = UnobtrusiveValidationMode.WebForms
        VERAG_VARIABLES.initerrorcount()

        If Not Me.Page.User.Identity.IsAuthenticated = True Then
            FormsAuthentication.RedirectToLoginPage()
        Else
            Try
                Kdnrtext = Session.Item("CustomerID")
            Catch
                Response.Redirect("Error.aspx&P1=" + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt("Invoices.aspx"))
            End Try

            DataBind()

            Dim confirmValue As String = hidField.Value
            'Script für Schließen wirklich verlassen Meldung auf der Masterseite für diese Seite zu registrieren und nicht ueberall
            Dim csm1 As ClientScriptManager = Page.ClientScript
            Dim cstype As Type = Page.GetType
            Dim erster As Date
            If Not csm1.IsStartupScriptRegistered(cstype, "Startup") Then
                Dim string1 As String = "<script language=\""JavaScript\"">"
                string1 += "</"
                string1 += "window.addEventListener('onunload', (event) => {"
                string1 += " event.preventDefault();"
                string1 += "event.returnValue = '';"
                string1 += "script>"
                csm1.RegisterClientScriptBlock(cstype, "Startup", string1)
            End If

            tbl_Header_row.TableSection = TableRowSection.TableHeader

            If (Page.IsPostBack) Then
                Page.MaintainScrollPositionOnPostBack = True

                If txt_Absender.Text IsNot "" Then
                    txt_Absender.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_Absender.Enabled = True
                    regex_txt_Absender.Validate()
                    If regex_txt_Absender.IsValid = True Then
                        Try
                            Absender = txt_Absender.Text
                        Catch ex As Exception
                            lbl_status.ForeColor = Drawing.Color.Red
                            lbl_status.Text = "Der Absender ist nicht richtig. Bitte korrigieren."
                        End Try
                    End If
                Else
                    regex_txt_Absender.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_Absender.Enabled = False
                End If
                If txt_Empfaenger.Text IsNot "" Then
                    txt_Empfaenger.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_Empfaenger.Enabled = True
                    If regex_txt_Empfaenger.IsValid = True Then
                        Try
                            Empfaenger = txt_Empfaenger.Text
                        Catch ex As Exception
                            regex_txt_Empfaenger.ForeColor = Drawing.Color.Red
                            regex_txt_Empfaenger.ErrorMessage = "Empfänger ist nicht korrekt!"
                        End Try
                    End If
                Else
                    regex_txt_Empfaenger.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_Empfaenger.Enabled = False
                End If
                If txt_KdNrAuftrag.Text IsNot "" Then
                    txt_KdNrAuftrag.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_KdNrAuftrag.Enabled = True
                    regex_txt_KdNrAuftrag.Validate()
                    If regex_txt_KdNrAuftrag.IsValid = True Then
                        Try
                            KDNAFNR = txt_KdNrAuftrag.Text
                        Catch ex As Exception
                            regex_txt_KdNrAuftrag.ForeColor = Drawing.Color.Red
                            regex_txt_KdNrAuftrag.Text = "Fehler bei Validierung der Kundenauftragsnummer!"
                        End Try
                    End If
                Else
                    txt_KdNrAuftrag.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_KdNrAuftrag.Enabled = False
                End If
                If txt_LKW.Text IsNot "" Then
                    txt_LKW.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_LKW.Enabled = True
                    regex_txt_LKW.Validate()
                    If regex_txt_LKW.IsValid = True Then
                        Try
                            LKWNR = txt_LKW.Text
                        Catch ex As Exception
                            regex_txt_LKW.ForeColor = Drawing.Color.Red
                            regex_txt_LKW.ErrorMessage = "Das LKW-Kennzeichen ist nicht korrekt formatiert!"
                        End Try
                    End If
                Else
                    txt_LKW.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_LKW.Enabled = False
                End If
                If txt_ReNr.Text IsNot "" Then
                    txt_ReNr.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_ReNr.Enabled = True
                    regex_txt_ReNr.Validate()
                    If regex_txt_ReNr.IsValid = True Then
                        Try
                            reNr = txt_ReNr.Text
                        Catch ex As Exception
                            regex_txt_ReNr.ForeColor = Drawing.Color.Red
                            regex_txt_ReNr.ErrorMessage = "Die Rechnungsnummer ist nicht korrekt."
                        End Try
                    End If
                Else
                    txt_ReNr.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_ReNr.Enabled = False
                End If
                'Mobil
                If txt_Absender_M.Text IsNot "" Then
                    txt_Absender_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_Absender_M.Enabled = True
                    regex_txt_Absender_M.Validate()
                    If regex_txt_Absender_M.IsValid = True Then
                        Try
                            Absender = txt_Absender_M.Text
                        Catch ex As Exception
                            regex_txt_Absender_M.ForeColor = Drawing.Color.Red
                            regex_txt_Absender_M.ErrorMessage = "Der Absender ist nicht richtig. Bitte korrigieren."
                        End Try
                    End If
                Else
                    txt_Absender_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_Absender_M.Enabled = False
                End If
                If txt_Empfaenger_M.Text IsNot "" Then
                    txt_Empfaenger_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_Empaenger_M.Enabled = True
                    regex_txt_Empaenger_M.Validate()
                    If regex_txt_Empaenger_M.IsValid = True Then
                        Try
                            Empfaenger = txt_Empfaenger_M.Text
                        Catch ex As Exception
                            regex_txt_Empaenger_M.ForeColor = Drawing.Color.Red
                            regex_txt_Empaenger_M.Text = "Empfänger ist nicht korrekt!"
                        End Try
                    End If
                Else
                    txt_Empfaenger_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_Empaenger_M.Enabled = False
                End If
                If txt_KdNrAuftrag_M.Text IsNot "" Then
                    txt_KdNrAuftrag_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_KdNrAuftrag_M.Enabled = True
                    regex_txt_KdNrAuftrag_M.Validate()
                    If regex_txt_KdNrAuftrag_M.IsValid = True Then
                        Try
                            KDNAFNR = txt_KdNrAuftrag_M.Text
                        Catch ex As Exception
                            regex_txt_KdNrAuftrag_M.ForeColor = Drawing.Color.Red
                            regex_txt_KdNrAuftrag_M.ErrorMessage = "Fehler bei Validierung der Kundenauftragsnummer!"
                        End Try
                    End If
                Else
                    txt_KdNrAuftrag_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_KdNrAuftrag_M.Enabled = False
                End If
                If txt_LKW_M.Text IsNot "" Then
                    txt_LKW_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_LKW_M.Enabled = True
                    regex_txt_LKW_M.Validate()
                    If regex_txt_LKW_M.IsValid = True Then
                        Try
                            LKWNR = txt_LKW_M.Text
                        Catch Ex As Exception
                            regex_txt_LKW_M.ForeColor = Drawing.Color.Red
                            regex_txt_LKW_M.Text = "Das LKW-Kennzeichen ist nicht korrekt formatiert!"
                        End Try
                    End If
                Else
                    txt_LKW_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_LKW_M.Enabled = False
                End If
                If txt_ReNr_M.Text IsNot "" Then
                    txt_ReNr_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    regex_txt_ReNr_M.Enabled = True
                    regex_txt_ReNr_M.Validate()
                    If regex_txt_ReNr_M.IsValid = True Then
                        Try
                            reNr = txt_ReNr_M.Text
                        Catch ex As Exception
                            regex_txt_ReNr_M.ForeColor = Drawing.Color.Red
                            regex_txt_ReNr_M.Text = "Die Rechnungsnummer ist nicht korrekt."
                        End Try
                    End If
                Else
                    txt_ReNr_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                    regex_txt_ReNr_M.Enabled = False
                End If

                If pickdate1.Text = Nothing Or pickdate2.Text = Nothing Then
                    Try
                        erster = New Date(Now().Year, Now.Month, 1)
                        datevon = erster
                        datebis = Date.Parse(Now.ToShortDateString)
                        pickdate1.Text = erster.ToUniversalTime.ToString("yyyy-MM-dd")
                        pickdate2.Text = Date.Now.ToUniversalTime.ToString("yyyyy-MM-dd")
                        dt = VERAG_PROG_ALLGEMEIN.cRechnungsausgang.GET_LIST_WEB(Integer.Parse(Kdnrtext), datevon, datebis, Integer.Parse(reNr), Absender, Empfaenger, LKWNR, KDNAFNR)
                    Catch ex As Exception
                        lbl_status.ForeColor = Drawing.Color.Red
                        lbl_status.Text = "Die Daten konnten nicht initialisiert werden. Bitte erneut versuchen."
                    End Try
                Else
                    Try
                        datevon = Date.Parse(pickdate1.Text)
                        datebis = Date.Parse(pickdate2.Text)
                        dt = VERAG_PROG_ALLGEMEIN.cRechnungsausgang.GET_LIST_WEB(Integer.Parse(Kdnrtext), datevon, datebis, Integer.Parse(reNr), Absender, Empfaenger, LKWNR, KDNAFNR)
                    Catch
                        lbl_status.ForeColor = Drawing.Color.Red
                        lbl_status.Text = "Fehler bei der Datenvergabe."
                    End Try
                End If

                addrows()
            Else
                erster = New Date(Now().Year, Now().Month, 1)
                datevon = erster
                datebis = Date.Parse(Now.ToShortDateString)
                pickdate1.Text = erster.ToUniversalTime.ToString("yyyy-MM-dd")
                pickdate2.Text = Date.Now.ToUniversalTime.ToString("yyyy-MM-dd")

            End If

        End If
    End Sub

    Private Sub addrows()
        Session.Item("mytable") = Nothing
        normaltable.Rows.Clear()

        Dim header As TableHeaderRow = New TableHeaderRow()
        header.Cells.Add(tbl_HeaderCellIndex)
        header.Cells.Add(tbl_HeaderCell_ReNr)
        header.Cells.Add(tbl_HeaderCell_LKWNr)
        header.Cells.Add(tbl_HeaderCell_Auftragsdatum)
        header.Cells.Add(tbl_HeaderCell_KundenAuftrNummer)
        header.Cells.Add(tbl_HeaderCell_Absender)
        header.Cells.Add(tbl_HeaderCell_Empfaenger)
        header.Cells.Add(tbl_HeaderCell_Info)
        normaltable.Rows.Add(header)

        If Not dt Is Nothing And Not dt.Count = 0 Then
            Dim i As Integer = 0
            For Each d In dt
                Dim tr As TableRow = New TableRow
                Dim Cell As TableCell = New TableCell
                Dim tbl_Cell_Index As TableCell = New TableCell
                Dim tbl_Cell_ReNr As TableCell = New TableCell
                Dim tbl_Cell_Auftragsdat As TableCell = New TableCell
                Dim tbl_Cell_Absender As TableCell = New TableCell
                Dim tbl_Cell_Empfaenger As TableCell = New TableCell
                Dim tbl_Cell_LKWs As TableCell = New TableCell
                Dim tbl_Cell_KundAuftrNr As TableCell = New TableCell
                Dim tbl_Cell_Info As TableCell = New TableCell

                Dim zahl = i + 1
                initcells(tr, tbl_Cell_Index, tbl_Cell_ReNr, tbl_Cell_LKWs, tbl_Cell_Auftragsdat, tbl_Cell_KundAuftrNr, tbl_Cell_Absender, tbl_Cell_Empfaenger, tbl_Cell_Info,
                        tbl_HeaderCellIndex, tbl_HeaderCell_ReNr, tbl_HeaderCell_LKWNr, tbl_HeaderCell_Auftragsdatum, tbl_HeaderCell_KundenAuftrNummer, tbl_HeaderCell_Absender, tbl_HeaderCell_Empfaenger, tbl_HeaderCell_Info)

                tbl_Cell_Index.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                tbl_Cell_Index.Text = zahl
                tr.Cells.Add(tbl_Cell_Index)
                tbl_Cell_ReNr.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                If d.RechnungsNr = Nothing Then
                    tbl_Cell_ReNr.Text = String.Empty
                Else
                    tbl_Cell_ReNr.Text = d.RechnungsNr.ToString
                End If
                tr.Cells.Add(tbl_Cell_ReNr)
                tbl_Cell_LKWs.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                If d.LKW_Kennzeichen = Nothing Then
                    tbl_Cell_LKWs.Text = String.Empty
                Else
                    tbl_Cell_LKWs.Text = d.LKW_Kennzeichen.ToString
                End If
                tr.Cells.Add(tbl_Cell_LKWs)
                tbl_Cell_Auftragsdat.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                If d.RechnungsDatum = Nothing Then
                    tbl_Cell_Auftragsdat.Text = String.Empty
                Else
                    tbl_Cell_Auftragsdat.Text = d.RechnungsDatum.ToString
                End If
                tr.Cells.Add(tbl_Cell_Auftragsdat)
                tbl_Cell_KundAuftrNr.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                If d.KdAuftragsNr = Nothing Then
                    tbl_Cell_KundAuftrNr.Text = String.Empty
                Else
                    tbl_Cell_KundAuftrNr.Text = d.KdAuftragsNr.ToString
                End If
                tr.Cells.Add(tbl_Cell_KundAuftrNr)
                tbl_Cell_Absender.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                If d.AbsenderName_1 = Nothing Then
                    tbl_Cell_Absender.Text = String.Empty
                Else
                    tbl_Cell_Absender.Text = d.AbsenderName_1.ToString
                End If
                tr.Cells.Add(tbl_Cell_Absender)
                tbl_Cell_Empfaenger.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                If d.EmpfängerName_1 = Nothing Then
                    tbl_Cell_Empfaenger.Text = String.Empty
                Else
                    tbl_Cell_Empfaenger.Text = d.EmpfängerName_1.ToString
                End If
                tr.Cells.Add(tbl_Cell_Empfaenger)

                Dim btn As New ImageButton
                btn.ViewStateMode = ViewStateMode.Enabled
                btn.CssClass = "btn btn-primary"
                btn.ImageUrl = "../images/Icons/main/833px-PDF_file_icon_small_more.png"
                btn.BackColor = Drawing.Color.FromArgb(1, Drawing.Color.GhostWhite)
                btn.BorderStyle = BorderStyle.None
                'Hier PDF-File creation einfügen
                btn.Style.Add("Display", "table-cell")
                btn.Style.Add("Vertical-align", "middle")
                btn.Style.Add("margin", "2px 2px 8px 4px")
                btn.Width = Unit.Pixel(64)
                btn.Height = Unit.Pixel(72)

                'btn.Attributes.Add("href", "pdfviewer.aspx?P1=" + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(d.FilialenNr).ToString() + "&P2=" + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(d.AbfertigungsNr).ToString + "&P3=" + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(d.RK_ID).ToString)
                btn.Attributes.Add("onclick", "window.open('../pdf/Bonizertifikat.pdf')")
                'btn.PostBackUrl = "pdfviewer.aspx?P1=" + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(d.FilialenNr).ToString + "&P2=" + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(d.AbfertigungsNr).ToString + "&P3=" + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(d.RK_ID).ToString
                tbl_Cell_Info.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                tbl_Cell_Info.Width = Unit.Pixel(64)
                tbl_Cell_Info.Height = Unit.Pixel(70)
                tbl_Cell_Info.Controls.Add(btn)
                tr.Cells.Add(tbl_Cell_Info)

                normaltable.Rows.Add(tr)
                i += 1
            Next
        Else
            Dim tbl_cellNothing = New TableCell()
            tbl_cellNothing.ColumnSpan = tbl_Header_row.Cells.Count
            tbl_cellNothing.Style.Add("text-align", "center")
            Dim tr As New TableRow
            tr.Style.Add("text-align", "center")
            tbl_cellNothing.Text = Server.HtmlEncode("No data found!")
            tr.Cells.Add(tbl_cellNothing)
            normaltable.Rows.Add(tr)
        End If

    End Sub

    Protected Sub initcells(tr As TableRow, t1 As TableCell, t2 As TableCell, t3 As TableCell, t4 As TableCell, t5 As TableCell, t6 As TableCell, t7 As TableCell, t8 As TableCell, th1 As TableHeaderCell, th2 As TableHeaderCell, th3 As TableHeaderCell, th4 As TableHeaderCell, th5 As TableHeaderCell, th6 As TableHeaderCell, th7 As TableHeaderCell, th8 As TableHeaderCell)
        Dim white As Drawing.Color = Drawing.Color.White
        Dim schwarz As Drawing.Color = Drawing.Color.Black
        Dim darkgrau As Drawing.Color = Drawing.Color.DarkGray
        Dim veragblue As Drawing.Color = Drawing.Color.FromArgb(4, 51, 129)

        tr.BackColor = white
        If String.IsNullOrEmpty(t1.Text) Then
            t1.BackColor = white
            t1.ForeColor = schwarz
        Else
            t1.BackColor = white
            t1.ForeColor = veragblue
        End If
        If String.IsNullOrEmpty(t2.Text) Then
            t2.BackColor = white
            t2.ForeColor = schwarz
        Else
            t2.BackColor = white
            t2.ForeColor = veragblue
        End If
        If String.IsNullOrEmpty(t3.Text) Then
            t3.BackColor = white
            t3.ForeColor = schwarz
        Else
            t3.BackColor = white
            t3.ForeColor = veragblue
        End If
        If String.IsNullOrEmpty(t4.Text) Then
            t4.BackColor = white
            t4.ForeColor = schwarz
        Else
            t4.BackColor = white
            t4.ForeColor = veragblue
        End If
        If String.IsNullOrEmpty(t5.Text) Then
            t5.BackColor = white
            t5.ForeColor = schwarz
        Else
            t5.BackColor = white
            t5.ForeColor = veragblue
        End If
        If String.IsNullOrEmpty(t6.Text) Then
            t6.BackColor = white
            t6.ForeColor = schwarz
        Else
            t6.BackColor = white
            t6.ForeColor = veragblue
        End If
        If String.IsNullOrEmpty(t7.Text) Then
            t7.BackColor = white
            t7.ForeColor = schwarz
        Else
            t7.BackColor = white
            t7.ForeColor = veragblue
        End If
        If String.IsNullOrEmpty(t8.Text) Then
            t8.BackColor = white
            t8.Width = Unit.Pixel(64)
            t8.Height = Unit.Pixel(72)
        Else
            t8.BackColor = white
            t8.ForeColor = veragblue
            t8.Width = Unit.Pixel(64)
            t8.Height = Unit.Pixel(72)
        End If

        th1.Font.Bold = True
        th2.Font.Bold = True
        th3.Font.Bold = True
        th4.Font.Bold = True
        th5.Font.Bold = True
        th6.Font.Bold = True
        th7.Font.Bold = True
        th8.Font.Bold = True
        th1.BackColor = veragblue
        th2.BackColor = veragblue
        th3.BackColor = veragblue
        th4.BackColor = veragblue
        th5.BackColor = veragblue
        th6.BackColor = veragblue
        th7.BackColor = veragblue
        th8.BackColor = veragblue
        th1.ForeColor = white
        th2.ForeColor = white
        th3.ForeColor = white
        th4.ForeColor = white
        th5.ForeColor = white
        th6.ForeColor = white
        th7.ForeColor = white
        th8.ForeColor = white
        th8.Width = Unit.Pixel(64)
    End Sub


    Protected Sub btn_resetForm_Click(sender As Object, e As EventArgs)
        dt = Nothing
        Session.Remove("mytable")
        Kdnrtext = ""
        Absender = ""
        Empfaenger = ""
        LKWNR = ""
        KDNAFNR = ""
        reNr = ""
        datevon = Date.ParseExact("01." + Date.Now.Month.ToString + "." + Date.Now.Year.ToString, "dd.MM.yyyy", Nothing)
        datebis = Date.Now
        pickdate1.Text = datevon.ToString
        pickdate2.Text = datebis.ToString
        If String.IsNullOrEmpty(txt_Absender.Text) = False Or String.IsNullOrEmpty(txt_Empfaenger.Text) = False Or String.IsNullOrEmpty(txt_KdNrAuftrag.Text) = False Or String.IsNullOrEmpty(txt_LKW.Text) = False Or String.IsNullOrEmpty(txt_ReNr.Text) = False Then
            txt_Absender.Text = String.Empty
            txt_Empfaenger.Text = String.Empty
            txt_KdNrAuftrag.Text = String.Empty
            txt_LKW.Text = String.Empty
            txt_ReNr.Text = String.Empty

            valdaterage_1.Enabled = valdaterange_2.Enabled = True
            valreq_pickdate1.Enabled = True
            valreq_pickdate2.Enabled = True
            regex_txt_Absender_M.Enabled = True
            regex_txt_Empaenger_M.Enabled = True
            regex_txt_KdNrAuftrag_M.Enabled = True
            regex_txt_LKW_M.Enabled = True
            regex_txt_ReNr_M.Enabled = True
            'Mobil
            regex_txt_Absender.Enabled = False
            regex_txt_Empfaenger.Enabled = False
            regex_txt_KdNrAuftrag.Enabled = False
            regex_txt_LKW.Enabled = False
            regex_txt_ReNr.Enabled = False
            Response.Redirect(Request.RawUrl)
            Return
        ElseIf String.IsNullOrEmpty(txt_Absender.Text) = False Or String.IsNullOrEmpty(txt_Empfaenger.Text) = False Or String.IsNullOrEmpty(txt_KdNrAuftrag.Text) = False Or String.IsNullOrEmpty(txt_LKW.Text) = False Or String.IsNullOrEmpty(txt_ReNr.Text) = False Then
            txt_Absender_M.Text = String.Empty
            txt_Empfaenger_M.Text = String.Empty
            txt_KdNrAuftrag_M.Text = String.Empty
            txt_LKW_M.Text = String.Empty
            txt_ReNr_M.Text = String.Empty

            regex_txt_Absender.Enabled = True
            regex_txt_Empfaenger.Enabled = True
            regex_txt_KdNrAuftrag.Enabled = True
            regex_txt_LKW.Enabled = True
            regex_txt_ReNr.Enabled = True
            'Desktop
            regex_txt_Absender.Enabled = True
            regex_txt_Empfaenger.Enabled = True
            regex_txt_KdNrAuftrag.Enabled = True
            regex_txt_LKW.Enabled = True
            regex_txt_ReNr.Enabled = True
            Response.Redirect(Request.RawUrl)
            Return
        End If

        'MsgBox("Reset")
    End Sub

    Protected Sub valdaterage_1_ServerValidate(source As Object, args As ServerValidateEventArgs)
        If Date.Parse(pickdate1.Text) < Date.ParseExact("01.04.2001", "dd.MM.yyyy", provider) Then
            VERAG_VARIABLES.seterrorcount(9)
            lbl_status.ForeColor = Drawing.Color.Red
            lbl_status.Text = VERAG_VARIABLES.geterrornumb + "The chosen time " + pickdate1.Text + " is too early"
        End If
    End Sub

    Protected Sub valdaterange_2_ServerValidate(source As Object, args As ServerValidateEventArgs)
        If Date.Parse(pickdate2.Text) > Date.ParseExact(Date.Now.ToShortDateString, "dd.MM.yyyy", provider) Then
            VERAG_VARIABLES.seterrorcount(10)
            lbl_status.ForeColor = Drawing.Color.Red
            lbl_status.Text = VERAG_VARIABLES.geterrornumb + "The chosen time " + pickdate2.Text + " is too far in the future"
        End If
    End Sub

    Protected Sub btn_SendData_Click(sender As Object, e As EventArgs)
        'MsgBox("Rechnung.pdf")
        dt = Nothing
        Session.Add("mytable", Nothing)
        If Session.Item("mytable") = Nothing Then
            If txt_Absender.Text IsNot "" Then
                txt_Absender.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_Absender.Enabled = True
                regex_txt_Absender.Validate()
                If regex_txt_Absender.IsValid = True Then
                    Try
                        Absender = txt_Absender.Text
                    Catch ex As Exception
                        lbl_status.ForeColor = Drawing.Color.Red
                        lbl_status.Text = "Der Absender ist nicht richtig. Bitte korrigieren."
                    End Try
                End If
            Else
                regex_txt_Absender.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_Absender.Enabled = False
            End If
            If txt_Empfaenger.Text IsNot "" Then
                txt_Empfaenger.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_Empfaenger.Enabled = True
                If regex_txt_Empfaenger.IsValid = True Then
                    Try
                        Empfaenger = txt_Empfaenger.Text
                    Catch ex As Exception
                        regex_txt_Empfaenger.ForeColor = Drawing.Color.Red
                        regex_txt_Empfaenger.ErrorMessage = "Empfänger ist nicht korrekt!"
                    End Try
                End If
            Else
                regex_txt_Empfaenger.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_Empfaenger.Enabled = False
            End If
            If txt_KdNrAuftrag.Text IsNot "" Then
                txt_KdNrAuftrag.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_KdNrAuftrag.Enabled = True
                regex_txt_KdNrAuftrag.Validate()
                If regex_txt_KdNrAuftrag.IsValid = True Then
                    Try
                        KDNAFNR = txt_KdNrAuftrag.Text
                    Catch ex As Exception
                        regex_txt_KdNrAuftrag.ForeColor = Drawing.Color.Red
                        regex_txt_KdNrAuftrag.Text = "Fehler bei Validierung der Kundenauftragsnummer!"
                    End Try
                End If
            Else
                txt_KdNrAuftrag.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_KdNrAuftrag.Enabled = False
            End If
            If txt_LKW.Text IsNot "" Then
                txt_LKW.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_LKW.Enabled = True
                regex_txt_LKW.Validate()
                If regex_txt_LKW.IsValid = True Then
                    Try
                        LKWNR = txt_LKW.Text
                    Catch ex As Exception
                        regex_txt_LKW.ForeColor = Drawing.Color.Red
                        regex_txt_LKW.ErrorMessage = "Das LKW-Kennzeichen ist nicht korrekt formatiert!"
                    End Try
                End If
            Else
                txt_LKW.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_LKW.Enabled = False
            End If
            If txt_ReNr.Text IsNot "" Then
                txt_ReNr.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_ReNr.Enabled = True
                regex_txt_ReNr.Validate()
                If regex_txt_ReNr.IsValid = True Then
                    Try
                        reNr = txt_ReNr.Text
                    Catch ex As Exception
                        regex_txt_ReNr.ForeColor = Drawing.Color.Red
                        regex_txt_ReNr.ErrorMessage = "Die Rechnungsnummer ist nicht korrekt."
                    End Try
                End If
            Else
                txt_ReNr.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_ReNr.Enabled = False
            End If
            'Mobil
            If txt_Absender_M.Text IsNot "" Then
                txt_Absender_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_Absender_M.Enabled = True
                regex_txt_Absender_M.Validate()
                If regex_txt_Absender_M.IsValid = True Then
                    Try
                        Absender = txt_Absender_M.Text
                    Catch ex As Exception
                        regex_txt_Absender_M.ForeColor = Drawing.Color.Red
                        regex_txt_Absender_M.ErrorMessage = "Der Absender ist nicht richtig. Bitte korrigieren."
                    End Try
                End If
            Else
                txt_Absender_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_Absender_M.Enabled = False
            End If
            If txt_Empfaenger_M.Text IsNot "" Then
                txt_Empfaenger_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_Empaenger_M.Enabled = True
                regex_txt_Empaenger_M.Validate()
                If regex_txt_Empaenger_M.IsValid = True Then
                    Try
                        Empfaenger = txt_Empfaenger_M.Text
                    Catch ex As Exception
                        regex_txt_Empaenger_M.ForeColor = Drawing.Color.Red
                        regex_txt_Empaenger_M.Text = "Empfänger ist nicht korrekt!"
                    End Try
                End If
            Else
                txt_Empfaenger_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_Empaenger_M.Enabled = False
            End If
            If txt_KdNrAuftrag_M.Text IsNot "" Then
                txt_KdNrAuftrag_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_KdNrAuftrag_M.Enabled = True
                regex_txt_KdNrAuftrag_M.Validate()
                If regex_txt_KdNrAuftrag_M.IsValid = True Then
                    Try
                        KDNAFNR = txt_KdNrAuftrag_M.Text
                    Catch ex As Exception
                        regex_txt_KdNrAuftrag_M.ForeColor = Drawing.Color.Red
                        regex_txt_KdNrAuftrag_M.ErrorMessage = "Fehler bei Validierung der Kundenauftragsnummer!"
                    End Try
                End If
            Else
                txt_KdNrAuftrag_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_KdNrAuftrag_M.Enabled = False
            End If
            If txt_LKW_M.Text IsNot "" Then
                txt_LKW_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_LKW_M.Enabled = True
                regex_txt_LKW_M.Validate()
                If regex_txt_LKW_M.IsValid = True Then
                    Try
                        LKWNR = txt_LKW_M.Text
                    Catch Ex As Exception
                        regex_txt_LKW_M.ForeColor = Drawing.Color.Red
                        regex_txt_LKW_M.Text = "Das LKW-Kennzeichen ist nicht korrekt formatiert!"
                    End Try
                End If
            Else
                txt_LKW_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_LKW_M.Enabled = False
            End If
            If txt_ReNr_M.Text IsNot "" Then
                txt_ReNr_M.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                regex_txt_ReNr_M.Enabled = True
                regex_txt_ReNr_M.Validate()
                If regex_txt_ReNr_M.IsValid = True Then
                    Try
                        reNr = txt_ReNr_M.Text
                    Catch ex As Exception
                        regex_txt_ReNr_M.ForeColor = Drawing.Color.Red
                        regex_txt_ReNr_M.Text = "Die Rechnungsnummer ist nicht korrekt."
                    End Try
                End If
            Else
                txt_ReNr_M.ValidateRequestMode = UI.ValidateRequestMode.Disabled
                regex_txt_ReNr_M.Enabled = False
            End If
            pickdate1.ValidateRequestMode = UI.ValidateRequestMode.Enabled
            pickdate2.ValidateRequestMode = UI.ValidateRequestMode.Enabled
            If pickdate1.Text = Nothing Or pickdate2.Text = Nothing Then
                Try
                    Dim erster = New Date(Now().Year, Now.Month, 1)
                    datevon = erster
                    datebis = Date.Parse(Now.ToShortDateString)
                    pickdate1.Text = erster.ToUniversalTime.ToString("yyyy-MM-dd")
                    pickdate2.Text = Date.Now.ToUniversalTime.ToString("yyyyy-MM-dd")
                    dt = VERAG_PROG_ALLGEMEIN.cRechnungsausgang.GET_LIST_WEB(Integer.Parse(Kdnrtext), CDate(datevon), CDate(datebis), Integer.Parse(reNr), Absender, Empfaenger, LKWNR, KDNAFNR)
                Catch ex As Exception
                    lbl_status.ForeColor = Drawing.Color.Red
                    lbl_status.Text = "Die Daten konnten nicht initialisiert werden. Bitte erneut versuchen."
                End Try
            Else
                Try
                    datevon = Date.Parse(pickdate1.Text)
                    datebis = Date.Parse(pickdate2.Text)
                    dt = VERAG_PROG_ALLGEMEIN.cRechnungsausgang.GET_LIST_WEB(Integer.Parse(Kdnrtext), CDate(datevon), CDate(datebis), Integer.Parse(reNr), Absender, Empfaenger, LKWNR, KDNAFNR)
                Catch
                    lbl_status.ForeColor = Drawing.Color.Red
                    lbl_status.Text = "Fehler bei der Datenvergabe."
                End Try
            End If
        End If
        addrows()
        Session.Item("mytable") = normaltable
    End Sub
End Class