﻿
Partial Class dillners_admin
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If (Not Session("DILLNER-IS-VALID").Equals("true")) Then
                Response.Redirect("index.apsx", True)
            End If
        Catch ex As Exception
            Response.Redirect("index.aspx", True)
        End Try

        driversDiv.InnerHtml += GenerateTableHeader()

        Dim _webWS As New WebWS
        Dim _ds As System.Data.DataSet = _webWS.GetDillnerLicenses()
        For i As Integer = 0 To _ds.Tables(0).Rows().Count - 1
            If (i.ToString.EndsWith("0") Or i.ToString.EndsWith("2") Or i.ToString.EndsWith("4") Or i.ToString.EndsWith("6") Or i.ToString.EndsWith("8")) Then
                driversDiv.InnerHtml += GenerateRow(_ds.Tables(0).Rows(i), True)
            Else
                driversDiv.InnerHtml += GenerateRow(_ds.Tables(0).Rows(i), False)
            End If
        Next

        driversDiv.InnerHtml += "</table>"
    End Sub

    Private Function GenerateTableHeader() As String
        Dim _htmlTable As String = ""

        _htmlTable = "<table id=""drivers""><tr>"
        _htmlTable += "<th> </th>"
        _htmlTable += "<th> License Number </th>"
        _htmlTable += "<th> Client Name </th>"
        _htmlTable += "</tr>"

        Return _htmlTable

    End Function

    Private Function GenerateRow(ByVal dr As System.Data.DataRow, ByVal isAlt As Boolean) As String
        Dim _htmlRow As String = ""
        Dim _downloadDirectory As String = "\\10.5.0.10\iis\Sites\goprint2.com\jobFiles\Dilners"

        _htmlRow = "<tr>"
        If (isAlt) Then
            _htmlRow = "<tr class=""alt"">"
        End If

        Dim _extraOptionsHtml As String = ""
	Dim _file As String = _downloadDirectory + "\GP2_Dillners_VO_" + dr("DilnerLicense").ToString().TrimEnd().TrimStart() + ".zip"

        If (System.IO.File.Exists(_file)) Then
            _extraOptionsHtml += "<a href=""https://www.goprint2.com/jobFiles/Dilners/GP2_Dillners_VO_" + dr("DilnerLicense").ToString().TrimEnd().TrimStart() + ".zip""> [Download] </a>"
        End If
        _extraOptionsHtml += "&nbsp; <a href=""regenerate-print-driver.aspx?license=" + dr("DilnerLicense").ToString().TrimEnd().TrimStart() + """> [Generate] </a>"
        _extraOptionsHtml += "&nbsp; <a title=""Update License Information"" href=""update-license.aspx?license=" + dr("DilnerLicense").ToString().TrimEnd().TrimStart() + """ onclick=""Modalbox.show(this.href, {title: this.title, width: 600, afterHide: reloadPage}); return false;""> [Edit] </a>"
        _htmlRow += " <td> " + _extraOptionsHtml + " </td> "
        _htmlRow += " <td> " + dr("DilnerLicense").ToString() + " </td>"
        _htmlRow += " <td> " + dr("ClientName").ToString() + "  </td>"
        _htmlRow += "</tr>"

        Return _htmlRow
    End Function
End Class
