Imports Telerik.Web.UI

Public Class Aktuality_Seznam
	Inherits System.Web.UI.UserControl

    Dim sStrankaID As String = "600"

    Public sAdresaUpravit As String = gadrAktuality_upravit
    Public sAdresaOdstranit As String = gadrAktuality_odstranit
    Public sAdresaSave As String = gadrAktuality

    Public sTable As String = "[aktuality].[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 [aktuality].[zaznam] WHERE id = 1")
        Dim cRow As DataRow = DS.Rows(0)

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

        '# 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 aktualitu', 'Opravdu chcete odstranit aktualitu?','/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>"
            If cRow("kratkytext" & _Language) = "" Then cRow("kratkytext" & _Language) = "<span class=""lokalizace-empty"">" & cRow("kratkytextcz") & "</span>"

            s &= cRow("nadpis" & _Language) & "</td>"
            's &= "<td class=""pointer"">" & cRow("kratkytext" & _Language) & "</td>"
            s &= "<td class=""right"">" & New Date(cRow("datum")).ToShortDateString & "</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á aktualita.</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 [aktuality].[zaznam] SET " &
                           "nadpis" & _Language & " = '" & txtNadpis.Text & "', " &
                           "text" & _Language & " = '" & txtText.Text & "', " &
                           "pocet_hlavni_strana = " & txtPocet_hlavni_strana.Text.Replace(",", ".") &
                           "WHERE id = 1")

        '# Ulozit informace o prohlizeci
        Dim sLink As String = 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