
Imports System.Data
Imports System.Web.UI.HtmlControls

Partial Class Kundenbereich_Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        tbl_Header_row.TableSection = TableRowSection.TableHeader

        DataBind()
        If (Page.IsPostBack And normaltable.EnableViewState = False) Then
            normaltable.EnableViewState = True
        End If
    End Sub

    Protected Sub LogOutBtn1_Click(sender As Object, e As EventArgs)
        Response.Redirect("../login/Logout.aspx", True)
    End Sub
    Protected Sub LogOutBtn2_Click(sender As Object, e As EventArgs)
        Response.Redirect("../login/Logout.aspx", True)
    End Sub

    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 DataTable

    Enum ART
        Kunde
        AVISIERER
        Frächter
        VERAG
        ZOLL
    End Enum
    Protected Sub btn_Auftraege_Click(sender As Object, e As EventArgs)
        'MsgBox(Session.Item("test").ToString)
        'MsgBox(Session.Item("CustomerID").ToString)
        'MsgBox(Session.Item("PW").ToString)
        Kdnrtext = Session.Item("CustomerID").ToString

        dt = Nothing
        If txt_Absender.Text IsNot "" Then
            txt_Absender.ValidateRequestMode = UI.ValidateRequestMode.Enabled
            Absender = txt_Absender.Text
        ElseIf txt_Empfaenger.Text IsNot "" Then
            txt_Empfaenger.ValidateRequestMode = UI.ValidateRequestMode.Enabled
            Empfaenger = txt_Empfaenger.Text
        ElseIf txt_KdNrAuftrag.Text IsNot "" Then
            txt_KdNrAuftrag.ValidateRequestMode = UI.ValidateRequestMode.Enabled
            KDNAFNR = txt_KdNrAuftrag.Text
        ElseIf txt_LKWNr.Text IsNot "" Then
            txt_LKWNr.ValidateRequestMode = UI.ValidateRequestMode.Enabled
            LKWNR = txt_LKWNr.Text
        End If

        'Dim tr
        If rbt_Alle.Selected = True Then
            If pickdate1.Text = "TT.MM.JJJJ" And pickdate2.Text = "TT.MM.JJJJ" Then
                MsgBox("Bitte ein Datum auswählen!", MsgBoxStyle.Information, "Information!")
                pickdate1.Text = Date.ParseExact("01" + "-" + Date.Now.Month.ToString + "-" + Date.Now.Year.ToString, "dd-MM-yyyy", Nothing).ToString
                pickdate2.Text = Date.ParseExact(Date.Now.Day.ToString + "-" + Date.Now.Month.ToString + "-" + Date.Now.Year.ToString, "dd-MM-yyyy", Nothing).ToString
            End If


            If Date.Parse(pickdate2.Text) > Date.Parse(pickdate1.Text) Then
                    Try
                        datevon = Date.Parse(pickdate1.Text)
                        datebis = Date.Parse(pickdate2.Text)
                    Catch ex As Exception
                        MsgBox(ex.StackTrace, MsgBoxStyle.Exclamation)
                    End Try
                End If

                dt = VERAG_PROG_ALLGEMEIN.cAviso.GET_KDLIST_WEB("", Kdnrtext, {0, 1, 2, 3, 4, 5}, datevon, datebis, Absender, Empfaenger, LKWNR, KDNAFNR)

        ElseIf rbt_Erf.Selected = True Then
            dt = VERAG_PROG_ALLGEMEIN.cAviso.GET_KDLIST_WEB("", Kdnrtext, {0},,, Absender, Empfaenger, LKWNR, KDNAFNR)
        ElseIf rbt_Freig.Selected = True Then

            If Date.Parse(pickdate2.Text) > Date.Parse(pickdate1.Text) Then
                Try
                    pickdate1.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    datevon = Date.Parse(pickdate1.Text)
                    pickdate2.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                    datebis = Date.Parse(pickdate2.Text)
                Catch ex As Exception
                    MsgBox(ex.StackTrace, MsgBoxStyle.Exclamation)
                End Try
            Else
                dt = VERAG_PROG_ALLGEMEIN.cAviso.GET_KDLIST_WEB("", Kdnrtext, {1}, Date.ParseExact("01-MM-yyyy", "dd-MM-yyyy", Nothing), Date.Now)
            End If
            dt = VERAG_PROG_ALLGEMEIN.cAviso.GET_KDLIST_WEB("", Kdnrtext, {1}, datevon, datebis, Absender, Empfaenger, LKWNR, KDNAFNR)
        ElseIf pickdate1.Text = "TT.MM.JJJJ" And pickdate2.Text = "TT.MM.JJJJ" Then
            MsgBox("Bitte ein Datum auswählen!", MsgBoxStyle.Information, "Information!")


        ElseIf rbt_Ankunft.Selected = True Then
            dt = VERAG_PROG_ALLGEMEIN.cAviso.GET_KDLIST_WEB("", Kdnrtext, {3},,, Absender, Empfaenger, LKWNR, KDNAFNR)
        ElseIf rbt_Vorb.Selected = True Then
            dt = VERAG_PROG_ALLGEMEIN.cAviso.GET_KDLIST_WEB("", Kdnrtext, {4},,, Absender, Empfaenger, LKWNR, KDNAFNR)
        ElseIf rbt_Vorg.Selected = True Then
            dt = VERAG_PROG_ALLGEMEIN.cAviso.GET_KDLIST_WEB("", Kdnrtext, {5},,, Absender, Empfaenger, LKWNR, KDNAFNR)
        End If

        If dt IsNot Nothing Then
            Dim i As Integer = 0
            'Dim sb As StringBuilder = New StringBuilder()

            'Table start.
            'sb.Append("<table cellpadding='5' cellspacing='0' style='border: 1px solid #ccc;font-size: 9pt;font-family:Arial'>")
            'Adding HeaderRow.
            'sb.Append("<tr>")
            'For Each column As DataColumn In dt.Columns
            '  sb.Append(("<th style='background-color: #B8DBFD;border: 1px solid #ccc'>" _
            '               + (column.ColumnName + "</th>")))
            'Next
            'sb.Append("</tr>")
            'Adding DataRow.
            'For Each row As DataRow In dt.Rows
            'sb.Append("<tr>")
            'For Each column As DataColumn In dt.Columns
            '    sb.Append(("<td style='width:100px;border: 1px solid #ccc'>" _
            '                 + (row(column.ColumnName).ToString + "</td>")))
            '  Next
            '   sb.Append("</tr>")
            'Next
            'Table end.
            'sb.Append("</table>")
            ' ltTable.Text = sb.ToString

            For Each d In dt.Rows
                Dim Cell = New TableCell
                Dim tbl_CellIndex = New TableCell
                Dim tbl_CellStatus = New TableCell
                Dim tbl_Cell_Auftragsdatum = New TableCell
                Dim tbl_CellAbsender = New TableCell
                Dim tbl_CellEmpfaenger = New TableCell
                Dim tbl_CellLKWs = New TableCell
                Dim tbl_CellKundAuftNr = New TableCell
                Dim tbl_CellInfo = New TableCell
                'tr = New HtmlTableRow()
                Dim tr = New TableRow
                Dim zahl = i + 1
                tbl_CellIndex.Text = zahl
                tr.Cells.Add(tbl_CellIndex)
                tbl_CellLKWs.Text = d("LKW_Nr").ToString
                tr.Cells.Add(tbl_CellLKWs)

                Select Case d("Status")
                    Case 1
                        tbl_CellStatus.Text = "Erfasst"
                        tr.Cells.Add(tbl_CellStatus)
                    Case 2
                        tbl_CellStatus.Text = "Nicht eingetroffen"
                        tr.Cells.Add(Cell)
                    Case 3
                        tbl_CellStatus.Text = "Ankunft"
                        tr.Cells.Add(tbl_CellStatus)
                    Case 4
                        tbl_CellStatus.Text = "Vorbereitet"
                        tr.Cells.Add(tbl_CellStatus)
                    Case 5
                        tbl_CellStatus.Text = "Vorgeschrieben"
                        tr.Cells.Add(tbl_CellStatus)
                    Case Else
                        tbl_CellStatus.Text = "Undefiniert"
                        tr.Cells.Add(tbl_CellStatus)
                End Select

                tbl_Cell_Auftragsdatum.Text = d("AvisoEingang").ToString
                tr.Cells.Add(tbl_Cell_Auftragsdatum)
                tbl_CellAbsender.Text = d("Auftraggeber").ToString
                tr.Cells.Add(tbl_CellAbsender)
                tbl_CellEmpfaenger.Text = d("Auftraggeber").ToString
                tr.Cells.Add(tbl_CellEmpfaenger)
                tbl_CellKundAuftNr.Text = d("KdAuftragsNr_Avisierer").ToString
                tr.Cells.Add(tbl_CellKundAuftNr)

                Dim btn As New LinkButton
                btn.ViewStateMode = ViewStateMode.Disabled
                'btn.Text = "Text"
                btn.CssClass = "btn btn-primary"
                btn.Attributes.Add("Text", <img src="../images/Icons/service/hilfe_small.png" width="15" height="15"/>)
                btn.Attributes.Add("href", "../status_Julius.aspx?AvisoId=" + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(d("AvisoID")).ToString)
                btn.Attributes.Add("target", "_blank")
                btn.PostBackUrl = "../status_Julius.aspx?AvisoId=" + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(d("AvisoID")).ToString

                tbl_CellInfo.Controls.Add(btn)
                tbl_CellInfo.ValidateRequestMode = UI.ValidateRequestMode.Enabled
                tr.Cells.Add(tbl_CellInfo)

                If rbt_Alle.Selected = True Then
                    normaltable.Rows.Add(tr)
                ElseIf rbt_Ankunft.Selected = True AndAlso tbl_CellStatus.Text = "Ankunft" Then
                    normaltable.Rows.Add(tr)
                ElseIf rbt_Erf.Selected = True AndAlso tbl_CellStatus.Text = "Erfasst" Then
                    normaltable.Rows.Add(tr)
                ElseIf rbt_Freig.Selected = True AndAlso tbl_CellStatus.Text = "Freigegeben" Then
                    normaltable.Rows.Add(tr)
                ElseIf rbt_Vorb.Selected = True AndAlso tbl_CellStatus.Text = "Vorbereitet" Then
                    normaltable.Rows.Add(tr)
                ElseIf rbt_Vorg.Selected = True AndAlso tbl_CellStatus.Text = "Vorgeschrieben" Then
                    normaltable.Rows.Add(tr)
                End If

                i += 1
            Next
        End If
    End Sub

    Protected Sub btn_resetForm_Click(sender As Object, e As EventArgs)
        rbt_Alle.Selected = False
        rbt_Alle.Enabled = True
        rbt_Ankunft.Selected = False
        rbt_Ankunft.Enabled = True
        rbt_Erf.Selected = False
        rbt_Erf.Enabled = True
        rbt_Freig.Selected = False
        rbt_Freig.Enabled = True
        rbt_Vorg.Selected = False
        rbt_Vorg.Enabled = True
        rbt_Vorb.Selected = False
        rbt_Vorb.Enabled = True
        pickdate1.Text = ""
        pickdate2.Text = ""
        datevon = Nothing
        datebis = Nothing
        dt = Nothing
        Kdnrtext = ""
        'txt_KdNr.Focus()
    End Sub
End Class