Public Partial Class Webforms_AddSetlist
    Inherits System.Web.UI.Page

    Private WithEvents theSetlist As Setlist
    Private WithEvents theShow As Show
    Private intShowNumber As Integer
    Private flag As Boolean

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If User.Identity.Name <> "" Then
            lbSignOut.Visible = True
        End If

        theShow = New Show
        If Not Page.IsPostBack Then
            theSetlist = New Setlist
            intShowNumber = CInt(Request.QueryString("ShowNumber"))
            If Not theShow.Exists(intShowNumber) Then
                Response.Redirect("../ResponsePages/PageNotFound.aspx")
            End If
            If theSetlist.ExistsByShow(intShowNumber) Then
                Response.Redirect("../ResponsePages/ExistingSetlist.aspx")
            End If
            Session("Show") = intShowNumber
            theShow.Item(intShowNumber)
            lblDate.Text = ConvertToMonth(theShow.Month) + " " + theShow.Day.ToString + ", " + theShow.Year.ToString
            If String.IsNullOrEmpty(theShow.State) Then
                lblLocation.Text = theShow.City + ", " + theShow.Country
            Else
                lblLocation.Text = theShow.City + ", " + theShow.State + ", " + theShow.Country
            End If
            lblVenue.Text = theShow.Venue
        Else
            intShowNumber = Session("Show")
            theShow.Item(intShowNumber)
        End If
    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        If Page.IsValid Then
            flag = True
            Dim blankSpace As Integer = 128
            theSetlist = New Setlist
            theSetlist.ShowNumber = intShowNumber
            theSetlist.Song01 = ddlSong01.SelectedValue
            If ddlSong02.SelectedValue < blankSpace Then
                theSetlist.Song02 = ddlSong02.SelectedValue
            End If
            If ddlSong03.SelectedValue < blankSpace Then
                theSetlist.Song03 = ddlSong03.SelectedValue
            End If
            If ddlSong04.SelectedValue < blankSpace Then
                theSetlist.Song04 = ddlSong04.SelectedValue
            End If
            If ddlSong05.SelectedValue < blankSpace Then
                theSetlist.Song05 = ddlSong05.SelectedValue
            End If
            If ddlSong06.SelectedValue < blankSpace Then
                theSetlist.Song06 = ddlSong06.SelectedValue
            End If
            If ddlSong07.SelectedValue < blankSpace Then
                theSetlist.Song07 = ddlSong07.SelectedValue
            End If
            If ddlSong08.SelectedValue < blankSpace Then
                theSetlist.Song08 = ddlSong08.SelectedValue
            End If
            If ddlSong09.SelectedValue < blankSpace Then
                theSetlist.Song09 = ddlSong09.SelectedValue
            End If
            If ddlSong10.SelectedValue < blankSpace Then
                theSetlist.Song10 = ddlSong10.SelectedValue
            End If
            If ddlSong11.SelectedValue < blankSpace Then
                theSetlist.Song11 = ddlSong11.SelectedValue
            End If
            If ddlSong12.SelectedValue < blankSpace Then
                theSetlist.Song12 = ddlSong12.SelectedValue
            End If
            If ddlSong13.SelectedValue < blankSpace Then
                theSetlist.Song13 = ddlSong13.SelectedValue
            End If
            If ddlSong14.SelectedValue < blankSpace Then
                theSetlist.Song14 = ddlSong14.SelectedValue
            End If
            If ddlSong15.SelectedValue < blankSpace Then
                theSetlist.Song15 = ddlSong15.SelectedValue
            End If
            If ddlSong16.SelectedValue < blankSpace Then
                theSetlist.Song16 = ddlSong16.SelectedValue
            End If
            If ddlSong17.SelectedValue < blankSpace Then
                theSetlist.Song17 = ddlSong17.SelectedValue
            End If
            If ddlSong18.SelectedValue < blankSpace Then
                theSetlist.Song18 = ddlSong18.SelectedValue
            End If
            If ddlSong19.SelectedValue < blankSpace Then
                theSetlist.Song19 = ddlSong19.SelectedValue
            End If
            If ddlSong20.SelectedValue < blankSpace Then
                theSetlist.Song20 = ddlSong20.SelectedValue
            End If
            If ddlSong21.SelectedValue < blankSpace Then
                theSetlist.Song21 = ddlSong21.SelectedValue
            End If
            If ddlSong22.SelectedValue < blankSpace Then
                theSetlist.Song22 = ddlSong22.SelectedValue
            End If
            If ddlSong23.SelectedValue < blankSpace Then
                theSetlist.Song23 = ddlSong23.SelectedValue
            End If
            If ddlSong24.SelectedValue < blankSpace Then
                theSetlist.Song24 = ddlSong24.SelectedValue
            End If
            If ddlSong25.SelectedValue < blankSpace Then
                theSetlist.Song25 = ddlSong25.SelectedValue
            End If
            theSetlist.Save()
            If flag Then
                Response.Redirect("../DisplayShow.aspx?ShowNumber=" + theShow.ShowNumber.ToString)
            End If
        End If
    End Sub

    Private Sub theShow_DBError(ByVal message As String) Handles theShow.DBError
        flag = False
    End Sub

    Public Function ConvertToMonth(ByVal month As Integer) As String
        Select Case month
            Case 1
                Return "January"
            Case 2
                Return "February"
            Case 3
                Return "March"
            Case 4
                Return "April"
            Case 5
                Return "May"
            Case 6
                Return "June"
            Case 7
                Return "July"
            Case 8
                Return "August"
            Case 9
                Return "September"
            Case 10
                Return "October"
            Case 11
                Return "November"
            Case 12
                Return "December"
            Case Else
                Return "Invalid Month"
        End Select
    End Function

    Protected Sub lbSignOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbSignOut.Click
        System.Web.Security.FormsAuthentication.SignOut()
        lbSignOut.Visible = False
    End Sub
End Class