两个页面构建相同,现在遇到不同的结果

时间:2016-07-11 16:49:02

标签: sql-server vb.net

使用MS-SQL在可视化基本网站中使用两个单独的遗留网页。长话短说,第一页只显示“最新问题”(工作正常)。虽然第二页“用于”作为档案,但始终首先显示最新的问题,然后是所有过去的问题。在某些时候,存档页面恢复为仅显示2014年和更早的问题 - 您可以看到它迟了2年。

此时,我被困住了。我无法弄清楚为什么两个页面使用大多数相同的导入/类 - 在年份时给出不同的结果。如果有人能给我一个骨头/指向正确的方向,我会很感激。学习的一部分是知道何时寻求帮助=)

工作“第一”页面.aspx.vb - 正确显示最新版本

    Imports System.Web.UI.WebControls
    Imports System.IO
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Web

    Partial Class inprint_latestissue
    Inherits System.Web.UI.Page



Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

    'YearLinks.Text = GetYearLinks()'


End Sub

Dim lastIssueDate As String = Nothing
Dim lastIssueID As Integer = 0
Dim lastCategory As String = Nothing
Dim bookText As String = ""
Dim onlineextraText As String = ""
Dim onlineextracount As Integer = 0
Dim bookcount As Integer = 0
Dim extraText As String = ""

Protected Function AddGroupingRowIssue() As String
    Dim currentIssueDate As String = Eval("iDatePublished").ToString()
    Dim currentIssueID As String = Eval("iID").ToString()
    Dim currentVolume As String = Eval("vName").ToString()
    Dim currentIssue As String = Eval("iName").ToString()
    Dim coverImage = "/img/imgLibrary/Covers/cover" + currentVolume + "0" + currentIssue + "sm.jpg"
    If File.Exists(Server.MapPath(coverImage)) Then
        coverImage = "<img src='/img/imgLibrary/Covers/cover" + currentVolume + "0" + currentIssue + "sm.jpg' style='float:right;margin:0px 20px 5px 5px;'/>"
    Else
        coverImage = ""
    End If

    If currentIssueDate.Length = 0 Then
        currentIssueDate = ""
    End If

    If lastIssueDate <> currentIssueDate Then
        Dim IssueRecipes As String = GetRecipes(lastIssueID)
        lastIssueDate = currentIssueDate
        lastIssueID = currentIssueID
        Return String.Format(IssueRecipes + "</ul><br clear='both'/><h2>{0}</h2>" + coverImage + "<ul>", currentIssueDate)

    Else
        Return String.Empty
    End If
End Function

Protected Function GetStoryType() As String
    Dim category As String = Eval("arArticleCategoryID").ToString()
    Dim arID As String = Eval("arID").ToString()
    Dim arTitle As String = Eval("arTitle").ToString()
    Dim arPublicStatus As String = Eval("arPublicStatus").ToString()
    Dim arVideoURL As String = Eval("arVideoURL2").ToString()
    Dim returnText As String = ""
    Dim videoText As String = ""
    Dim subscriberText As String = ""

    If arVideoURL <> "" Then
        videoText = " <a href='/features/article.aspx?arID=" & Eval("arID") & "#video' CssClass='videolink'><img src='/img/icon-video.gif' alt='Watch video' /></a>"
    End If
    If arPublicStatus = "0" Then
        subscriberText = " <img src='/img/icon-subscriber.gif' alt='subscriber-only' width='16' height='16' />"
    End If

    Select Case category

        Case 1
            returnText = "<li>Gardening: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 2
            returnText = "<li>What's In Season: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 3
            returnText = "<li>California Country Close-Up: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 4
            bookText = bookText + "<a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + subscriberText + "<br />"
            'returnText = "Book Review: "
        Case 11
            onlineextraText = onlineextraText + "<li><a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 15
            returnText = "<li>On location: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 16
            returnText = "<li>It's a bountiful life: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 13
            returnText = "<li>Farmer &amp; Foodie: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 19
            returnText = "<li>From the editors: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 21
            returnText = "<li>Fresh ideas: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 17
            returnText = "<li>Health and wellness: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case Else
            returnText = "<li><a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
    End Select


    'If lastCategory <> category Then
    'If lastCategory = "4" Then
    'bookText = bookText.Substring(0, (bookText.Length() - 2))
    'bookText = bookText.Replace(subscriberText + ",", subscriberText)
    'returnText = "<li>Book Reviews: " + bookText + "</li>" + returnText
    'bookText = ""
    'End If

    'lastCategory = category
    'End If

    If category = "4" Then
        If bookcount = 0 Then
            'bookText = bookText.Substring(0, (bookText.Length() - 2))
            returnText = "<li>Book Reviews:<br />" + bookText
        Else
            'bookText = bookText.Substring(0, (bookText.Length() - 2))
            returnText = bookText

        End If
        bookText = ""
        bookcount = bookcount + 1
        lastCategory = category
    End If

    If category = "11" Then
        If onlineextracount = 0 Then
            returnText = "</ul><h3>Online Extras</h3><ul>" + onlineextraText
        Else
            returnText = onlineextraText
        End If
        onlineextraText = ""
        onlineextracount = onlineextracount + 1
    End If


    Return returnText

End Function




Protected Function GetRecipes(ByVal currentIssueDate As Integer) As String
    'Dim currentIssueDate As String = Eval("iID").ToString()

    Dim returnText As String = ""
    Dim recipeText As String = ""

    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("CFBFConnectionString").ConnectionString)
    Dim comm As New SqlCommand("select rid,rTitle from Recipes where (rIssueID=@id and rLive=1) order by rTitle", conn)

    comm.Parameters.Add(New SqlParameter("@id", SqlDbType.Int)).Value = currentIssueDate

    Try
        conn.Open()
        Dim reader = comm.ExecuteReader()
        While reader.Read
            recipeText = recipeText + "<li><a href='/recipes/recipes.aspx?rID=" + reader.Item(0).ToString() + "'>" + reader.Item(1) + "</a></li>"
        End While


    Catch e As Exception

    End Try

    If recipeText <> "" Then

        recipeText = recipeText.Substring(0, (recipeText.Length() - 2))
        returnText = "</ul><h3>Recipes</h3><ul>" + recipeText + "</ul>"

    End If


    Return returnText

End Function


Protected Sub ListView_articleList_DataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs)


End Sub
Protected Sub ListView_articleList_PreRender(ByVal sender As Object, ByVal e As EventArgs)



End Sub

Protected Function GetYearLinks() As String

    Dim returnText As String = ""
    Dim yearLinks As String = ""
    Dim thisYear As String = ""

    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("CFBFConnectionString").ConnectionString)
    Dim comm As New SqlCommand("select vName from Volume order by vName DESC", conn)


    Try
        conn.Open()
        Dim reader = comm.ExecuteReader()
        While reader.Read
            thisYear = (reader.Item(0) - 28) + 2005
            yearLinks = yearLinks + "<a href='?vName=" + reader.Item(0).ToString() + "'>" + thisYear + "</a> |"
        End While


    Catch e As Exception

    End Try

    yearLinks = yearLinks.Substring(0, (yearLinks.Length() - 2))
    returnText = yearLinks

    Return returnText

End Function




Protected Sub ArticlesList_OnSelecting(ByVal sender As Object, ByVal e As ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource_ArticlesList.Selecting



    e.InputParameters("iID") = GetLastIssueID()
End Sub

Protected Function GetLastIssueID() As Integer
    Dim thisIssue As Integer
    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("CFBFConnectionString").ConnectionString)
    'Dim comm As New SqlCommand("select top 1 iID from Issue order by iID desc", conn)
    'Dim comm As New SqlCommand("SELECT TOP 1 iID  FROM Issue  where iID not in (select top 1 iID from Issue order by iID desc)  order by iID desc", conn)
    Dim comm As New SqlCommand("SELECT TOP 1 iID FROM Issue WHERE iLive=1 ORDER BY iID DESC", conn)

    conn.Open()
    Dim reader = comm.ExecuteReader()
    While reader.Read
        thisIssue = reader.Item(0)
    End While
    'Preview new issue thisIssue = 55

    Return thisIssue
End Function

Protected Sub ArticlesList_OnSelected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs) Handles ObjectDataSource_ArticlesList.Selected

    If e.Exception Is Nothing AndAlso e.ReturnValue IsNot Nothing Then
        e.AffectedRows = DirectCast(e.ReturnValue, DataTable).Rows.Count
        If e.AffectedRows = 0 Then

        Else
            lastRecipes.Text = GetRecipes(GetLastIssueID())
        End If
    End If

End Sub


    End Class

存档页面 - 由于某种原因,显示2014年的最新结果

    Imports System.Web.UI.WebControls
    Imports System.IO
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Web

    Partial Class inprint_archives
Inherits System.Web.UI.Page

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

    YearLinks.Text = GetYearLinks()

End Sub

Dim lastIssueDate As String = Nothing
Dim lastIssueID As Integer = 0
Dim lastCategory As String = Nothing
Dim bookText As String = ""
Dim onlineextraText As String = ""
Dim onlineextracount As Integer = 0
Dim bookcount As Integer = 0
Dim extraText As String = ""

Protected Function AddGroupingRowIssue() As String
    Dim currentIssueDate As String = Eval("iDatePublished").ToString()
    Dim currentIssueID As String = Eval("iID").ToString()
    Dim currentVolume As String = Eval("vName").ToString()
    Dim currentIssue As String = Eval("iName").ToString()
    Dim coverImage = "/img/imgLibrary/Covers/cover" + currentVolume + "0" + currentIssue + "sm.jpg"
    If File.Exists(Server.MapPath(coverImage)) Then
        coverImage = "<img src='/img/imgLibrary/Covers/cover" + currentVolume + "0" + currentIssue + "sm.jpg' style='float:right;margin:0px 20px 5px 5px;'/>"
    Else
        coverImage = ""
    End If

    If currentIssueDate.Length = 0 Then
        currentIssueDate = ""
    End If

    If lastIssueDate <> currentIssueDate Then
        Dim IssueRecipes As String = GetRecipes(lastIssueID)
        lastIssueDate = currentIssueDate
        lastIssueID = currentIssueID
        Return String.Format(IssueRecipes + "</ul><br clear='both'/><h2>{0}</h2>" + coverImage + "<ul>", currentIssueDate)

    Else
        Return String.Empty
    End If
End Function

Protected Function GetStoryType() As String
    Dim category As String = Eval("arArticleCategoryID").ToString()
    Dim arID As String = Eval("arID").ToString()
    Dim arTitle As String = Eval("arTitle").ToString()
    Dim arPublicStatus As String = Eval("arPublicStatus").ToString()
    Dim arVideoURL As String = Eval("arVideoURL2").ToString()
    Dim returnText As String = ""
    Dim videoText As String = ""
    Dim subscriberText As String = ""


    If arVideoURL <> "" Then
        videoText = " <a href='/features/article.aspx?arID=" & Eval("arID") & "#video' CssClass='videolink'><img src='/img/icon-video.gif' alt='Watch video' /></a>"
    End If
    If arPublicStatus = "0" Then
        subscriberText = " <img src='/img/icon-subscriber.gif' alt='subscriber-only' width='16' height='16' />"

    End If

    Select Case category
        Case 1
            returnText = "<li>Gardening: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 2
            returnText = "<li>What's In Season: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 3
            returnText = "<li>California Country Close-Up: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 4
            bookText = bookText + "<a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + subscriberText + "<br />"
            'returnText = "<li>Book Review: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + subscriberText + "</li>"
        Case 11
            onlineextraText = onlineextraText + "<li><a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 15
            returnText = "<li>On location: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case 16
            returnText = "<li>It's a bountiful life: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"

        Case 13
            returnText = "<li>Farmer &amp; Foodie: <a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
        Case Else
            onlineextracount = 0
            bookcount = 0
            returnText = "<li><a href='/features/article.aspx?arID=" + arID + "'>" + arTitle + "</a>" + videoText + subscriberText + "</li>"
    End Select


    If category = "4" Then
        If bookcount = 0 Then
            'bookText = bookText.Substring(0, (bookText.Length() - 2))
            returnText = "<li>Book Reviews:<br />" + bookText
        Else
            'bookText = bookText.Substring(0, (bookText.Length() - 2))
            returnText = bookText

        End If
        bookText = ""
        bookcount = bookcount + 1
        lastCategory = category
    End If

    If category = "11" Then
        If lastCategory = "4" Then
            returnText = "</li>"
        End If
        If onlineextracount = 0 Then
            returnText = returnText + "</ul><h3>Online Extras</h3><ul>" + onlineextraText
        Else
            returnText = onlineextraText
        End If
        onlineextraText = ""
        onlineextracount = onlineextracount + 1
    End If


    Return returnText

End Function






Protected Function GetRecipes(ByVal currentIssueDate) As String
    'Dim currentIssueDate As String = Eval("iID").ToString()

    Dim returnText As String = ""
    Dim recipeText As String = ""

    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("CFBFConnectionString").ConnectionString)
    Dim comm As New SqlCommand("select rid,rTitle from Recipes where (rIssueID=@id and rLive=1) order by rTitle", conn)

    comm.Parameters.Add(New SqlParameter("@id", SqlDbType.Int)).Value = currentIssueDate

    Try
        conn.Open()
        Dim reader = comm.ExecuteReader()
        While reader.Read
            recipeText = recipeText + "<li><a href='/recipes/recipes.aspx?rID=" + reader.Item(0).ToString() + "'>" + reader.Item(1) + "</a></li>"
        End While


    Catch e As Exception

    End Try

    If recipeText <> "" Then

        recipeText = recipeText.Substring(0, (recipeText.Length() - 2))
        returnText = "</ul><h3>Recipes</h3><ul>" + recipeText + "</ul>"

    End If


    Return returnText

End Function


Protected Sub ListView_articleList_DataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs)

End Sub
Protected Sub ListView_articleList_PreRender(ByVal sender As Object, ByVal e As EventArgs)
    Dim lblTot As Label = TryCast(Me.ListView_articleList.FindControl("lastRecipes"), Label)

    lblTot.Text = GetRecipes(lastIssueID)
End Sub

Protected Function GetYearLinks() As String

    Dim returnText As String = ""
    Dim yearLinks As String = ""
    Dim thisYear As String = ""

    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("CFBFConnectionString").ConnectionString)
    Dim comm As New SqlCommand("select vName from Volume order by vName DESC", conn)


    Try
        conn.Open()
        Dim reader = comm.ExecuteReader()
        While reader.Read
            thisYear = (reader.Item(0) - 28) + 2005
            'If (thisYear <> "2012") Then
            '   yearLinks = yearLinks + "<a href='?vName=" + reader.Item(0).ToString() + "'>" + thisYear + "</a> | "
            'End If
            yearLinks = yearLinks + "<a href='?vName=" + reader.Item(0).ToString() + "'>" + thisYear + "</a> | "
        End While


    Catch e As Exception

    End Try

    yearLinks = yearLinks.Substring(0, (yearLinks.Length() - 2))
    returnText = yearLinks

    Return returnText

End Function


End Class

0 个答案:

没有答案