Imports Telerik.Web.UI

Public Class Sluzby_Seznam
    Inherits System.Web.UI.UserControl

    Dim sStrankaID As String = "300"

    Public sAdresaUpravit As String = gadrSluzby_upravit
    Public sAdresaOdstranit As String = gadrSluzby_odstranit
    Public sAdresaSave As String = gadrSluzby

    Public sTable As String = "[sluzby].[list]"

    Public bShowLocalization As Boolean = True

    ''' <summary>
    ''' Seznam zaznamu.
    ''' Verze: 1.0
    ''' Tabulka musi obsahovat pole - id, sort
    ''' </summary>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        NacistData()
        NacistZaznamy()

        cmdNovy.Attributes.Add("onclick", "ShowPopInfo('" & gstrProbihaNacitaniStranky & "');")
        cmdSave.Attributes.Add("onclick", "ShowPopInfo('" & gstrProbihaUkladaniZaznamu & "');")

        Dim pSort As New PCSolution.SortItems
        pSort.InsertSorting(sTable)

    End Sub

#Region "  NACIST DATA  "

    Sub NacistData()

        Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT * FROM [sluzby].[zaznam] WHERE id = " & sStrankaID)
        Dim cRow As DataRow = DS.Rows(0)

        txtNadpis.Text = cRow("nadpis" & _Language)
        txtText.Text = cRow("text" & _Language)

        '# Lokalizace
        If _Language <> "cz" Then
            lblNadpis.Text = cRow("nadpiscz")
            lblText.Text = cRow("textcz")
        Else
            ajax.ResponseScripts.Add("$('.label-localize').css('display','none');")
        End If
        '@

        LoadLink(sStrankaID, 0, txtTitle.Text, txtLink.Text, txtHorniMenuText.Text, txtDescription.Text)

    End Sub

#End Region

#Region "  NACIST ZAZNAMY  "

    Sub NacistZaznamy()

        Dim s As String = ""

        Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT * FROM " & sTable & " ORDER BY sort")

        For Each cRow As DataRow In DS.Rows

            s &= "<tr id=""sort" & cRow("id") & """>"
            s &= "<td class=""item-edit first""><a href=""/id-" & cRow("id") & sAdresaUpravit & """>Upravit</a></td>"
            s &= "<td class=""item-edit""><a href=""#"" onclick=""ConfirmDelete('Odstranit článek', 'Opravdu chcete odstranit článek?','/id-" & cRow("id") & sAdresaOdstranit & "','','');return false;"">Odstranit</a></td>"

            s &= "<td class=""pointer"">"
            If cRow("zobrazit" & _Language) = "False" Then s &= "<span class=""label label-red""> </span>&nbsp;"

            If cRow("nadpis" & _Language) = "" Then cRow("nadpis" & _Language) = "<span class=""lokalizace-empty"">" & cRow("nadpiscz") & "</span>"

            s &= cRow("nadpis" & _Language) & "</td>"
            s &= "</tr>"

        Next

        ph.Controls.Add(New LiteralControl(s)) : s = ""

        If DS.Rows.Count = 0 Then
            phTable.Visible = False
            phNoItem.Controls.Add(New LiteralControl("<div class=""noitem"">Není nalezený žádný článek.</div>"))
        End If

    End Sub

    Private Sub cmdNovy_Click(sender As Object, e As EventArgs) Handles cmdNovy.Click

        Response.Redirect(sAdresaUpravit)

    End Sub

#End Region

#Region "  ULOZIT  "

    Sub UlozitZaznam()

        DB.ExecuteCommand("UPDATE [sluzby].[zaznam] SET " &
                           "nadpis" & _Language & " = '" & txtNadpis.Text & "', " &
                           "text" & _Language & " = '" & txtText.Text & "' " &
                           "WHERE id = " & sStrankaID)

        SaveLink(sStrankaID, 0, txtTitle.Text, txtLink.Text, txtHorniMenuText.Text, txtDescription.Text)

    End Sub

    Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click

        Me.UlozitZaznam()
        _NotifyText = "Nastavení stránky je uložené."
        Response.Redirect(sAdresaSave)

    End Sub

#End Region

End Class