Namespace PCSolution

    Public Class GetUniqueURLAddress

        Function GetURL(sURL As String, iStrankaID As Int32, iZaznamID As Int32, iTyp As Int16, sLang As String) As String

            Dim pDoc As New PCSolution.Document
            sURL = pDoc.OdstranitDiakritiku(sURL, "-")

            Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT * FROM [nastaveni].[adresy] WHERE adresa = '" & sURL & "'")
            If DS.Rows.Count = 0 Then 'Pokud adresa neexistuje, ulozit.
                Return sURL
            Else
                If DS.Rows(0)("strankaid") = iStrankaID And DS.Rows(0)("zaznamid") = iZaznamID And DS.Rows(0)("lang") = sLang And DS.Rows(0)("typ") = iTyp Then 'Pokud je adresa nalezena, ale patri editovane adrese, tak povolit
                    Return sURL
                End If
            End If

            For n As Int16 = 1 To 99 'Pokud adresa existuje, priradit cislo nakonec.

                DS = DB.ExecuteSelectCommand("SELECT * FROM [nastaveni].[adresy] WHERE adresa = '" & sURL & "-" & n & "'")
                If DS.Rows.Count = 0 Then
                    Return sURL & "-" & n
                Else
                    If DS.Rows(0)("strankaid") = iStrankaID And DS.Rows(0)("zaznamid") = iZaznamID And DS.Rows(0)("lang") = sLang And DS.Rows(0)("typ") = iTyp Then 'Pokud je adresa nalezena, ale patri editovane adrese, tak povolit
                        Return sURL & "-" & n
                    End If
                End If

            Next

            Return ""

        End Function

    End Class

End Namespace