Option Explicit On

Option Strict   On

 

Public Class MagicForm

    Inherits System.Windows.Forms.Form

 

#Region " Windows Form Designer generated code "

'    The form is pretty basic: Button, status bar, progress bar, and various data access controls.

 

#End Region

 

Private Sub cGenerateAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cGenerateAll.Click

    Me.GenerateMain()

    Me.GenerateAll()

    Me.GeneratePages()

 

'    Me.GenerateComicTitles()

 

    cStatus.Panels(0).Text = "COMPLETE"

End Sub

 

Private Sub GenerateAll()

Dim filename    As String = "C:\usr\Spilled Milk\SpilledMilk.com\SpilledMilk_Local\magic_cards_all.htm"

Dim count       As Int32

Dim data        As String

Dim color       As String

Dim pad         As String

Dim stream      As System.IO.StreamWriter   = New System.IO.StreamWriter(filename)

Dim dispData    As System.Data.DataTable    = New System.Data.DataTable()

Dim theRow      As System.Data.DataRow      = Nothing

 

    cStatus.Panels(0).Text = "Generating All Editions"

   

    pad = "   "

   

    data += Me.GenerateHeader()

 

    data +="<table>" + vbCrLf

 

    Me.cOdbcDataAdapterDisplay.Fill(dispData)

  

    cProgress.Maximum = dispData.Rows.Count

    cProgress.Minimum = 0

 

    'dispData.Recordset.Sort = "Edition, Name"

   

    For Each theRow In dispData.Rows

        data += Me.GenerateRow(theRow)

 

        cProgress.Value = count

        count = count + 1

    Next

 

    data +="</table>"

   

    data += Me.GenerateFooter()

 

    data +="</body>"

    data +="</html>"

   

    stream.Write(data)

    stream.Close()

   

    cProgress.Value = 0

End Sub

 

Private Function GenerateFooter() As String

Dim result As String = ""

 

    result += "<font size=""1"">" + vbCrLf

    result += "<p align=""left"">This HTML code entirely generated, "

    result += "<a href=""magic_source.htm"">source</a> available on request <a href=""mailto:psmart@SpilledMilk.com"">psmart@SpilledMilk.com</a>." + vbCrLf

    result += "<br>Generated on: " + DateTime.Now.ToString("MM/dd/yyyy HH:mm:SS") + " MDT" + vbCrLf

    result += "</p>" + vbCrLf

    result += "</font>" + vbCrLf

   

    Return result

End Function

 

Private Function GenerateHeader() As String

Dim result As String = ""

 

    result += Me.GenerateHeaderMain("Parker Smart's Magic Cards For Sale")

   

    result += "<p align=""left""><font size=""6"">Magic: The Gathering Cards For Sale</font></p>" + vbCrLf

    result += "<p align=""left"">Here is a complete list of all my magic cards that are for sale. &nbsp;" + vbCrLf

    result += "I didn't put any prices down because I figure everything is " + vbCrLf

    result += "negotiable anyway and I'm just looking for a fair price. &nbsp;You'll have to give me some time to get " + vbCrLf

    result += "the cards together and make sure that I've got your cards in inventory. &nbsp;" + vbCrLf

    result += "I use <a href=""http://www.EssentialMagic.com"" target=""_blank"">Essential Magic</a> to figure a fair price. " + vbCrLf

    result += "For the rares I will sometimes use eBay, so do your homework and it will pay off in the end. &nbsp;" + vbCrLf

    result += "Please send a reasonable offer and I will consider it quicker than receiving a list of cards with no prices next to them. &nbsp;" + vbCrLf

    result += "When placing an offer, please include the quantity, formal card name (it makes it easier to look up), and Edition (since cards are reprinted on a whim). &nbsp;" + vbCrLf

    result += "</p>" + vbCrLf

 

    result += "<p align=""left"">Don't forget that handy ""Find"" feature on your browser to look for what you need.  As always " + vbCrLf

    result += "you can contact me at <a href=""mailto:psmart@SpilledMilk.com"">psmart@SpilledMilk.com</a>." + vbCrLf

    result += "</p>" + vbCrLf

 

    result += "<p align=""left"">Don't forget to check out the comics on this site, they're still in print and a must have for any collector." + vbCrLf

    result += "</p>" + vbCrLf

    Return result

End Function

 

Private Function GenerateHeaderMain(ByVal pTitle As String) As String

Dim result As String = ""

 

    result += "<!--This HTML code was completely generated by VB source written by Parker Smart" + vbCrLf

    result += "    and does not touch a server data source at all." + vbCrLf

    result += "Date and Time Generated: " + DateTime.Now.ToString("MM/dd/yy HH:mm:SS") + " MST" + vbCrLf

    result += "-->" + vbCrLf

    result += "<html>" + vbCrLf

    result += "<head>" + vbCrLf

    result += vbCrLf

    result += "<title>" + pTitle + "</title>" + vbCrLf

    result += vbCrLf

    result += "<link type=""text/css"" rel=""stylesheet"" href=""style_normal.css"" media=""screen"">" + vbCrLf

    result += "<script type=""text/javascript"" language=""javascript"" src=""script_frames.js""></script>" + vbCrLf

    result += vbCrLf

    result += "</head>" + vbCrLf

    result += vbCrLf

    result += "<body onload=""onloadCheckIfWeNeedARedirect();"">" + vbCrLf

    result += vbCrLf

    Return result

End Function

 

Private Sub GenerateComicTitles()

Dim count       As Int32

Dim data        As String = ""

Dim filename    As String = "C:\usr\Spilled Milk\SpilledMilk.com\SpilledMilk_Local\comic_titles.htm"

Dim stream      As System.IO.StreamWriter   = New System.IO.StreamWriter(filename)

Dim comicData   As System.Data.DataTable    = New System.Data.DataTable()

Dim theRow      As System.Data.DataRow      = Nothing

 

    cStatus.Panels(0).Text = "Generating Comic Book Titles"

 

    Me.cOdbcDataAdapterComics.Fill(comicData)

 

    Me.GenerateHeaderMain("Parker Smart's Comics for Sale")

   

    data += "<p align=""left""><font size=""6"">Tons of Comics for Sale</font></p>" + vbCrLf

    data += "<p align=""left"">Below is a list of comic titles that I've got.  I'm sure there are more " + vbCrLf

    data += "because it has been about two or three years since I've entered anthing new into the datase. " + vbCrLf

    data += "Those will be entered eventually.  Right now, it was all I could do to put the titles on this " + vbCrLf

    data += "site.  I hope this sparks some interest and I'll put the numbers of each issue out shortly. " + vbCrLf

    data += "</p>" + vbCrLf

   

    cProgress.Maximum = comicData.Rows.Count

    cProgress.Minimum = 0

 

    data += "<table>" + vbCrLf

 

    For Each theRow In comicData.Rows

   

        data += vbTab + "<tr>" + vbCrLf

        data +="<td align=""left"">" + theRow!Title.ToString() + "</td>" + vbCrLf

        data +="</tr>" + vbCrLf

 

        cProgress.Value = count

        count = count + 1

    Next

 

    data += "</table>" + vbCrLf

 

    data += Me.GenerateFooter()

 

    data += "</body>" + vbCrLf

    data += "</html>" + vbCrLf

   

    stream.Write(data)

    stream.Close()

       

    cProgress.Value = 0

End Sub

 

 

Private Sub GenerateMain()

Dim filename    As String = "C:\usr\Spilled Milk\SpilledMilk.com\SpilledMilk_Local\magic_cards.htm"

Dim count       As Int32

Dim data        As String

Dim pad         As String

Dim stream      As System.IO.StreamWriter   = New System.IO.StreamWriter(filename)

Dim totalData   As System.Data.DataTable    = New System.Data.DataTable()

Dim theRow      As System.Data.DataRow      = Nothing

 

    cStatus.Panels(0).Text = "Generating Main Magic page"

 

    pad = "&nbsp;&nbsp;&nbsp;"

 

    data = Me.GenerateHeader()

 

' No more sealed anything...

 

    'data += "<p align=""left"">Sealed Boxes:</p>" + vbCrLf

    'data += "<menu>" + vbCrLf

    'data += vbTab + "<li type=""disc"">Alliances Boosters" + vbCrLf

    'data += vbTab + "<li type=""disc"">Fallen Empires Boosters" + vbCrLf

    'data += vbTab + "<li type=""disc"">Homelands Boosters" + vbCrLf

    'data += vbTab + "<li type=""disc"">Ice Age Starters" + vbCrLf

    'data += vbTab + "<li type=""disc"">Ice Age Boosters" + vbCrLf

    'data += vbTab + "<li type=""disc"">Mirage Boosters" + vbCrLf

    'data += vbTab + "<li type=""disc"">Mirage Starters" + vbCrLf

    'data += vbTab + "<li type=""disc"">Visions Starters" + vbCrLf

    'data += vbTab + "<li type=""disc"">Visions Boosters" + vbCrLf

    'data += "</menu>" + vbCrLf

   

    data += "<table>" + vbCrLf

   

    data += vbTab + "<tr>" + vbCrLf

    data += vbTab + vbTab + "<td><a href=""magic_cards_all.htm"">All Editions</a>" + pad + "</td>" + vbCrLf

    data += vbTab + vbTab + "<td align=""right"">(622 KB)" + pad + "</td>" + vbCrLf

    data += vbTab + "</tr>"

    data += vbTab + "<tr>" + vbCrLf

    data += vbTab + vbTab + "<td>" + pad + "</td>" + vbCrLf

    data += vbTab + vbTab + "<td>" + pad + "</td>" + vbCrLf

    data += vbTab + "</tr>"

    data += vbTab + "<tr>" + vbCrLf

    data += vbTab + vbTab + "<td>Edition Name" + pad + "</td>" + vbCrLf

    data += vbTab + vbTab + "<td>Card Qty" + pad + "</td>" + vbCrLf

    data += vbTab + "</tr>"

   

    Me.cOdbcDataAdapterTotals.Fill(totalData)

   

    cProgress.Maximum = totalData.Rows.Count

    cProgress.Minimum = 0

 

    For Each theRow In totalData.Rows

        data += vbTab + "<tr>" + vbCrLf

        data += vbTab + vbTab + "<td><a href=""magic_cards_" + theRow!Edition.ToString() + ".htm"">" + theRow!EditionName.ToString() + "</a>" + pad + "</td>" + vbCrLf

        data += vbTab + vbTab + "<td align=""right"">" + theRow!SumOfQty.ToString() + pad + "</td>" + vbCrLf

        data += vbTab + "</tr>"

 

        cProgress.Value = count

        count += 1

    Next

 

    data += "</table>"

   

    data += Me.GenerateFooter()

 

    data += "</body>"

    data += "</html>"

   

    stream.Write(data)

    stream.Close()

   

    cProgress.Value = 0

End Sub

 

Private Sub GeneratePages()

Dim filename    As String

Dim count       As Int32

Dim data        As String

Dim color       As String

Dim pad         As String

Dim totalData   As System.Data.DataTable    = New System.Data.DataTable()

Dim dispData    As System.Data.DataTable    = New System.Data.DataTable()

Dim theRow      As System.Data.DataRow      = Nothing

Dim theSubRow   As System.Data.DataRowView  = Nothing

 

    Me.cOdbcDataAdapterTotals.Fill(totalData)

    Me.cOdbcDataAdapterDisplay.Fill(dispData)

 

    For Each theRow In totalData.Rows

        count = 0

        pad = "&nbsp;&nbsp;&nbsp;"

        filename = "C:\usr\Spilled Milk\SpilledMilk.com\SpilledMilk_Local\magic_cards_" + theRow!Edition.ToString() + ".htm"

               

    Dim stream      As System.IO.StreamWriter   = New System.IO.StreamWriter(filename)

       

        data = Me.GenerateHeader()

   

        data += "<font size=""-1"">"

        data += "<table>"

       

    Dim theView As System.Data.DataView = New System.Data.DataView(dispData)

   

        theView.RowFilter = "Edition='" + theRow!Edition.ToString() + "'"

        theView.RowStateFilter = DataViewRowState.OriginalRows

 

        cStatus.Panels(0).Text = "Generating Edition: " & theRow!EditionName.ToString()

        cProgress.Maximum = theView.Count

        cProgress.Minimum = 0

 

        count = 0

 

        For Each theSubRow In theView

            data += Me.GenerateRow(theSubRow)

 

            cProgress.Value = count

            count = count + 1

        Next

   

        data += "</table>"

        data += "</font>"

       

        data += Me.GenerateFooter()

 

        data += "</body>"

        data += "</html>"

       

        stream.Write(data)

        stream.Close()

       

        cProgress.Value = 0

        cStatus.Panels(0).Text = ""

    Next

End Sub

 

Private Function GenerateRow(ByVal theRow As System.Data.DataRow) As String

Dim data        As String

Dim color       As String

Dim pad         As String

 

    pad = vbTab

 

    data = pad + "<tr>" + vbCrLf

    pad = vbTab + vbTab

 

    If (System.Convert.ToInt32(theRow!Qty) <= 0) Then

        data += pad + "<td align=""right"">--</td>" + vbCrLf

    Else

        data += pad + "<td align=""right"">" + theRow!Qty.ToString() + pad + "</td>" + vbCrLf

    End If

    data += pad + "<td>" + theRow!Name.ToString() + pad + "</td>" + vbCrLf

 

    color = LCase(theRow!ColorName.ToString())

    data += pad + "<td><font color=""" + color + """>" + theRow!ColorName.ToString() + pad + "</font></td>" + vbCrLf

 

    Select Case (theRow!RarityName.ToString().Substring(0, 1))

    Case "C"

        color = "black"

    Case "U"

        color = "whitesmoke"

    Case "R"

        color = "goldenrod"

        'color = "gold"

        'color = "darkkhaki"

    End Select

    data += pad + "<td><font color=""" + color + """>" + theRow!RarityName.ToString() + pad + "</font></td>" + vbCrLf

    'data +=pad + "<td>" + cMagic.Recordset.Fields("Edition").Value + pad + "</td>" + vbCrLf

    data += pad + "<td>" + theRow!EditionName.ToString() + pad + "</td>" + vbCrLf

    pad = vbTab

 

    data += pad + "</tr>"

 

    Return data

End Function

 

Private Function GenerateRow(ByVal theRow As System.Data.DataRowView) As String

Dim data        As String

Dim color       As String

Dim pad         As String

 

    pad = vbTab

 

    data = pad + "<tr>" + vbCrLf

    pad = vbTab + vbTab

 

    If (System.Convert.ToInt32(theRow!Qty) <= 0) Then

        data += pad + "<td align=""right"">--</td>" + vbCrLf

    Else

        data += pad + "<td align=""right"">" + theRow!Qty.ToString() + pad + "</td>" + vbCrLf

    End If

    data += pad + "<td>" + theRow!Name.ToString() + pad + "</td>" + vbCrLf

 

    color = LCase(theRow!ColorName.ToString())

    data += pad + "<td><font color=""" + color + """>" + theRow!ColorName.ToString() + pad + "</font></td>" + vbCrLf

 

    Select Case (theRow!RarityName.ToString().Substring(0, 1))

    Case "C"

        color = "black"

    Case "U"

        color = "whitesmoke"

    Case "R"

        color = "goldenrod"

        'color = "gold"

        'color = "darkkhaki"

    End Select

    data += pad + "<td><font color=""" + color + """>" + theRow!RarityName.ToString() + pad + "</font></td>" + vbCrLf

    'data +=pad + "<td>" + cMagic.Recordset.Fields("Edition").Value + pad + "</td>" + vbCrLf

    data += pad + "<td>" + theRow!EditionName.ToString() + pad + "</td>" + vbCrLf

    pad = vbTab

 

    data += pad + "</tr>"

 

    Return data

End Function

 

End Class