Public Class Lide_nadpis_upravit
    Inherits System.Web.UI.UserControl

    Public cTitle As Admin.Title
    Public sID As String  'ID zaznamu

    Public sAdresaSave As String = gadrLide_seznam
    Public sAdresaStorno As String = gadrLide_seznam

    Public sTable As String = "[kontakt].[lide]"

    Public bShowLocalization As Boolean = True

    ''' <summary>
    ''' Seznam zaznamu - upravit zaznam
    ''' Verze: 1.0
    ''' </summary>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

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

        cTitle._Nadpis("Lidé")

        sID = Request.QueryString("id")

        lblBC.Text = "<a href=""" & gadrLide_seznam & """>Lidé</a>"

        If sID = "" Then
            chkZobrazit.Checked = True
        End If
        '@

        If sID = "0" Then sID = ""

        If sID <> "" Then
            sID = Request.QueryString("id")
            lblCaption.Text = "Lidé - nadpis"
            cTitle._Podnadpis("upravit")
        Else
            lblCaption.Text = "Lidé - nadpis"
            cTitle._Podnadpis("nový nadpis")
            lblBC.Text &= "➞ Nový nadpis"
        End If

        If IsPostBack = False Then
            Me.NacistData()
        End If

        txtNadpis.Focus()

    End Sub

#Region "  NACIST DATA  "

    Sub NacistData()

        If sID = "" Then
            ajax.ResponseScripts.Add("$('.label-localize').css('display','none');")
            Exit Sub
        End If

        Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT * FROM " & sTable & " WHERE id = '" & sID & "'")
        If DS.Rows.Count = 0 Then Exit Sub

        Dim cRow As DataRow = DS.Rows(0)

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

        chkZobrazit.Checked = cRow("zobrazit" & _Language)

        If txtNadpis.Text <> "" Then
            lblBC.Text &= "➞ " & txtNadpis.Text
        Else
            lblBC.Text &= "➞ " & cRow("nadpiscz")
        End If

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

    End Sub

#End Region

#Region "  ULOZIT  "

    Sub UlozitZaznam()

        If sID = "" Then '# Vytvorit novy zaznam

            Dim iSort As Int16 = 1
            Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT max(sort) FROM " & sTable)
            Try
                iSort = DS.Rows(0)(0) + 1
            Catch ex As Exception
            End Try
            DB.ExecuteCommand("INSERT INTO " & sTable & " (typ, sort) VALUES (1, " & iSort & ")")

            DS = DB.ExecuteSelectCommand("SELECT max(id) FROM " & sTable)
            sID = DS.Rows(0)(0)

        End If

        DB.ExecuteCommand("UPDATE " & sTable & " SET " &
                           "nadpis" & _Language & " = '" & _PrevestTextNaBezpecny(txtNadpis.Text) & "', " &
                           "zobrazit" & _Language & " = '" & chkZobrazit.Checked & "' " &
                           "WHERE id = " & sID)

    End Sub

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

        Me.UlozitZaznam()
        Response.Redirect(sAdresaStorno)

    End Sub

    Private Sub cmdStorno_Click(sender As Object, e As EventArgs) Handles cmdStorno.Click

        Response.Redirect(sAdresaStorno)

    End Sub

#End Region

End Class