Option Strict On

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports Microsoft.VisualBasic
Imports System.IO
Imports System.Web.Caching
Imports System.Net

Partial Class funebres
    Inherits System.Web.UI.Page
    Private d_fecha As Date
    Public nombres, f1, f2, simbolo As String
    Private DBReader, DBReader1 As SqlDataReader

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        d_fecha = Date.Now.AddDays(0)
        f1 = d_fecha.ToString("yyyyMMdd")
        DBReader = Clasi3.CheckFunebresNuevo(f1, 1, 1, True)
        If Not DBReader Is Nothing Then
            If DBReader.HasRows Then
                DBReader.Close()
                muestra_avisos_nuevo(1)
            Else
                DBReader = Clasi3.CheckFunebresNuevo(f1, 2, 1, True)
                If Not DBReader Is Nothing Then
                    If DBReader.HasRows Then
                        DBReader.Close()
                        muestra_avisos_nuevo(2)
                    End If
                End If
            End If
        
        End If
    End Sub
    Private Sub muestra_avisos_nuevo(ByVal int_tipo As Integer)



        Dim tipo As String = "SEPELIOS"
        Dim str_apellido_ant As String = ""

        Dim dbreader_avi As SqlDataReader = Clasi3.CheckFunebresNuevo(f1, int_tipo, 1, True) ''el 1 es para EL DIA 
        If dbreader_avi.Read Then
            nombres = "<div class=""flex flex-wrap px2""><div class=""col-12 block-title mb1_5""><a href=""http://funebres.eldia.com"" target=""_blank""><span>Avisos F&uacute;nebres</span></a></div><div class=""carousel""><ul class=""flex list-reset col-12"">"
            Dim simbolo As Integer = CInt(dbreader_avi.Item("simbolo"))
            Dim str_simbolo As String = ""
            Select Case simbolo
                Case 1
                    str_simbolo = "<img src=""img/cruz.png"">"
                Case 2
                    str_simbolo = "<img src=""img/estrella.png"">"
                Case 3
                    str_simbolo = ""
                Case 4
                    str_simbolo = ""
            End Select
            Dim str_fallecio As String = ""
            Dim str_pre As String = ""
            Dim str_post As String = ""
            Dim str_qepd As String = ""
            Dim str_apellido As String = ""
            Dim str_texto As String = ""

            If dbreader_avi.Item("fallecio").ToString.Length > 0 Then
                str_fallecio = " " + dbreader_avi.Item("fallecio").ToString
            End If
            If dbreader_avi.Item("pre").ToString.Length > 0 Then
                str_pre = dbreader_avi.Item("pre").ToString + " "
            End If
            If dbreader_avi.Item("post").ToString.Length > 0 Then
                str_post = " " + dbreader_avi.Item("post").ToString
            End If

            If dbreader_avi.Item("qepd").ToString.Length > 0 Then
                str_qepd = dbreader_avi.Item("qepd").ToString
                If dbreader_avi.Item("qepd").ToString = "(ZL)" Then
                    str_qepd = "(Z'L)"
                End If
                str_qepd = " " + str_qepd
            End If

            If dbreader_avi.Item("apellido").ToString.Length > 0 Then
                str_apellido = " " + dbreader_avi.Item("apellido").ToString
                str_apellido_ant = dbreader_avi.Item("apellidoreal").ToString
            End If

            If dbreader_avi.Item("texto").ToString.Length > 49 Then
                str_texto = dbreader_avi.Item("texto").ToString.Substring(0, 50)
            Else
                str_texto = dbreader_avi.Item("texto").ToString
            End If
            nombres += "<div class=""col-12""><div class=""funebre-ad""><div class=""funebre-icon"">" + str_simbolo + "</div><div class=""funebre-content"">" _
                + "<h2><a href=""http://funebres.eldia.com"" target=""_blank""><span>" + str_pre + dbreader_avi.Item("Nombre").ToString.ToUpper + " " + dbreader_avi.Item("Apellido").ToString.ToUpper + str_post _
             + "</span></a></h2><p>" + str_qepd + str_fallecio + ".- " + str_texto + " [...]" + "</p></div></div></div>"

        Else
            nombres = ""
            Exit Sub
        End If
        While dbreader_avi.Read
            If str_apellido_ant.Trim <> dbreader_avi.Item("apellidoreal").ToString.Trim Then
                Dim simbolo As Integer = CInt(dbreader_avi.Item("simbolo"))
                Dim str_simbolo As String = ""
                Select Case simbolo
                    Case 1
                        str_simbolo = "<img src=""img/cruz.png"">"
                    Case 2
                        str_simbolo = "<img src=""img/estrella.png"">"
                    Case 3
                        str_simbolo = ""
                    Case 4
                        str_simbolo = ""
                End Select
                Dim str_fallecio As String = ""
                Dim str_pre As String = ""
                Dim str_post As String = ""
                Dim str_qepd As String = ""
                Dim str_apellido As String = ""
                Dim str_texto As String = ""

                If dbreader_avi.Item("fallecio").ToString.Length > 0 Then
                    str_fallecio = " " + dbreader_avi.Item("fallecio").ToString
                End If
                If dbreader_avi.Item("pre").ToString.Length > 0 Then
                    str_pre = dbreader_avi.Item("pre").ToString + " "
                End If
                If dbreader_avi.Item("post").ToString.Length > 0 Then
                    str_post = " " + dbreader_avi.Item("post").ToString
                End If

                If dbreader_avi.Item("qepd").ToString.Length > 0 Then
                    str_qepd = dbreader_avi.Item("qepd").ToString
                    If dbreader_avi.Item("qepd").ToString = "(ZL)" Then
                        str_qepd = "(Z'L)"
                    End If
                    str_qepd = " " + str_qepd
                End If

                If dbreader_avi.Item("apellido").ToString.Length > 0 Then
                    str_apellido = " " + dbreader_avi.Item("apellido").ToString
                    str_apellido_ant = dbreader_avi.Item("apellidoreal").ToString
                End If

                If dbreader_avi.Item("texto").ToString.Length > 49 Then
                    str_texto = dbreader_avi.Item("texto").ToString.Substring(0, 50)
                Else
                    str_texto = dbreader_avi.Item("texto").ToString
                End If

                nombres += "<div class=""col-12""><div class=""funebre-ad""><div class=""funebre-icon"">" + str_simbolo + "</div><div class=""funebre-content"">" _
                    + "<h2><a href=""http://funebres.eldia.com""><span>" + str_pre + dbreader_avi.Item("Nombre").ToString.ToUpper + " " + dbreader_avi.Item("Apellido").ToString.ToUpper + str_post _
                 + "</span></a></h2><p>" + str_qepd + str_fallecio + ".- " + str_texto + " [...]" + "</p></div></div></div>"
            End If

        End While
        dbreader_avi.Close()
        nombres += "</ul></div><div class=""col-12 flex pt2""><a href=""http://funebres.eldia.com"" target=""_blank"" class=""button""><span>Ver todos los avisos</span></a></div></div>"

    End Sub
End Class
