Imports System.Data
Imports LYB.VB
Imports LYB.VB.CLASSES

Partial Class group1_Default_test
    Inherits System.Web.UI.Page
    Private member As Member
    Private utils As New DataUtils

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim lnkRepertoar As LinkButton = Master.FindControl("lnkRepertoar")
        lnkRepertoar.Style.Add("color", "white")
        Dim lnkParty As LinkButton = Master.FindControl("lnkParty")
        lnkParty.Style.Add("color", "yellow")
        Dim lnkMR As LinkButton = Master.FindControl("lnkMR")
        lnkMR.Style.Add("color", "yellow")
        Dim lnkMusicFiles As LinkButton = Master.FindControl("lnkMusicFiles")
        lnkMusicFiles.Style.Add("color", "yellow")
        Dim btnChangePassword As LinkButton = Master.FindControl("btnChangePassword")
        btnChangePassword.Style.Add("color", "yellow")
        Dim btnLogout As LinkButton = Master.FindControl("btnLogout")
        btnLogout.Style.Add("color", "yellow")
        MultiView1.ActiveViewIndex = 0
        Try
            DisplayList("AR", "repertoarTable")
        Catch ez As System.Exception
            Dim memberId As Integer = 0
            Dim emailAddress As String = ""
            If Not IsNothing(Session("member")) Then
                memberId = CType(Session("member"), Member).MemberID
                emailAddress = CType(Session("member"), Member).MailAddressHome
                If emailAddress = "" Then
                    emailAddress = CType(Session("member"), Member).MailAddressWork
                End If
            End If
            utils.AddToErrorLog(emailAddress, memberId, 1, ez.Message, Session.SessionID, 0)
        End Try

    End Sub
    Public Sub DisplayList(ByVal listType As String, ByVal table As String)
        member = CType(Session("member"), Member)
        Dim defaultFilePath As String = utils.GetDefaultDocumentURL()
        Dim display As New Display
        Dim data As New DataUtils
        Dim listTable As Table = Me.MultiView1.FindControl(table)
        listTable.CellSpacing = 0
        listTable.CellPadding = 5
        Dim tbrowHeading As New TableRow
        tbrowHeading.Cells.Add(display.MakeTableHeaderCell("Musikstycke", member.FontFamily, member.FontSize, 2))
        tbrowHeading.Cells.Add(display.MakeTableHeaderCell("Kompositör / Arr.", member.FontFamily, member.FontSize))
        'tbrowHeading.Cells.Add(display.MakeTableHeaderCell("Piano"))
        listTable.Rows.Add(tbrowHeading)
        Try
            Dim dw As DataView = utils.GetDocuments(member.CurrentLoginGroup, listType)
            If Not IsNothing(dw) Then
                Dim savedCompositionName As String = ""
                For Each row As DataRowView In dw
                    Dim tbrow As New TableRow
                    If Not row.Item("HeadingID") Is System.DBNull.Value Then
                        Dim tbrowEmpty As New TableRow
                        tbrowEmpty.Cells.Add(display.MakeTableCell("&nbsp;", member.FontFamily, member.FontSize, 3))
                        listTable.Rows.Add(tbrowEmpty)
                        tbrow.Cells.Add(display.MakeTableCell(row.Item("HeadingText").ToString, member.FontFamily, row.Item("HeadingFontSize").ToString, "bold", 3))
                    Else
                        If Not row.Item("CompositionID") Is System.DBNull.Value Then
                            If row.Item("CompositionName").ToString = savedCompositionName Then
                                ' show only document icon
                                row.Item("CompositionID") = System.DBNull.Value
                                row.Item("ComposerID") = System.DBNull.Value
                            End If
                            savedCompositionName = row.Item("CompositionName").ToString
                        End If
                        If Not row.Item("CompositionID") Is System.DBNull.Value Then
                            tbrow.Cells.Add(display.MakeTableCell(row.Item("CompositionName").ToString, member.FontFamily, member.FontSize))
                        Else
                            tbrow.Cells.Add(display.MakeTableCell("&nbsp;", member.FontFamily, member.FontSize))
                        End If
                        Dim documentLink As String
                        Dim documentLinkAddition As String = ""
                        If Not row.Item("FileName") Is System.DBNull.Value Then
                            Select Case LCase(row.Item("type").ToString)
                                Case "pdf"
                                    documentLinkAddition = "pdf/"
                                Case "mp3"
                                    documentLinkAddition = "mp3/"
                                Case "doc"
                                    documentLinkAddition = "word/"
                                Case "wma"
                                    documentLinkAddition = "wma/"
                                Case "wmv"
                                    documentLinkAddition = "videos/"
                                Case "nwc"
                                    documentLinkAddition = "noteworthy/"
                            End Select
                            documentLink = "<a href='" & defaultFilePath & documentLinkAddition
                            If Not row.Item("URL") Is System.DBNull.Value Then
                                documentLink = "<a href='" & row.Item("URL").ToString()
                            End If
                            documentLink = documentLink & row.Item("filename").ToString & "." & row.Item("type").ToString
                            documentLink = documentLink & "' target='_blank'><img src='../images/" & LCase(row.Item("type").ToString) & "_ico.gif' border='no' /></a>"
                        Else
                            documentLink = "&nbsp;"
                        End If
                        tbrow.Cells.Add(display.MakeTableCell(documentLink, member.FontFamily, member.FontSize))
                        Dim celltext As String
                        If Not row.Item("ComposerID") Is System.DBNull.Value Then
                            If Not row.Item("CommentBeforeComposer") Is System.DBNull.Value Then
                                celltext = "&nbsp;&nbsp;&nbsp;" & row.Item("CommentBeforeComposer").ToString & "&nbsp;" & row.Item("ComposerName").ToString
                            Else
                                celltext = "&nbsp;&nbsp;&nbsp;" & row.Item("ComposerName").ToString
                            End If
                            If Not row.Item("CommentAfterComposer") Is System.DBNull.Value Then
                                celltext = celltext & ",&nbsp;" & row.Item("CommentAfterComposer").ToString
                            End If
                        ElseIf Not row.Item("CommentBeforeComposer") Is System.DBNull.Value Then
                            celltext = "&nbsp;&nbsp;&nbsp;" & row.Item("CommentBeforeComposer").ToString
                        Else
                            celltext = "&nbsp;"
                        End If
                        tbrow.Cells.Add(display.MakeTableCell(celltext, member.FontFamily, member.FontSize))
                        If Session("emailAddress") = "leif.bjorkman@comhem.se" Then
                            celltext = row.Item("sortorder").ToString
                            tbrow.Cells.Add(display.MakeTableCell(celltext, member.FontFamily, member.FontSize))
                        End If
                    End If
                    listTable.Rows.Add(tbrow)
                Next
            End If
        Catch ex As System.Exception
            Throw New System.Exception(ex.Message)
        End Try
    End Sub
End Class
