Imports System.Data
Imports System.Text.RegularExpressions
Imports System.Data.OleDb
Public Class ShowArticle
Inherits System.Web.UI.Page
#Region " Web Form設計器產生的程式碼 "
'該調用是 Web Form設計器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents LblTitle As System.Web.UI.WebControls.Label
Protected WithEvents LblContent As System.Web.UI.WebControls.Label
'注意: 以下預留位置聲明是 Web Form設計器所必需的。
'不要刪除或移動它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法調用是 Web Form設計器所必需的
'不要使用代碼編輯器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此處放置初始化頁的使用者代碼
Dim StrArticleId As String
StrArticleId = Request("ArticleId")
Dim myArticle As New AccessDb
Dim myReader As OleDbDataReader
Dim myStrTitle As String
myReader = myArticle.ExecuteSqlStrDetails("select * from portal_Articles where articleid=" + StrArticleId + ";")
If myReader.Read Then
myStrTitle = myReader("title")
If strlen(myStrTitle) > 20 Then
myStrTitle = gotTopic(myStrTitle, 20)
End If
LblTitle.Text = myStrTitle
LblContent.Text = HTMLEncode(myReader("Content"))
End If
End Sub
Function HTMLEncode(ByVal reString As String) '轉換HTML代碼
Dim Str As String = reString
If Str.Length > 0 Then
Str = Replace(Str, ">", ">")
Str = Replace(Str, "<", "<")
Str = Replace(Str, Chr(9), " ")
Str = Replace(Str, Chr(39), "'")
Str = Replace(Str, Chr(34), """)
Str = Replace(Str, Chr(13), "")
Str = Replace(Str, Chr(10), "<br/>")
HTMLEncode = Str
End If
End Function
'得到字串長度
Function strlen(ByVal str As String) As Integer
Dim p_len As Integer
Dim xx As Integer
p_len = 0
strlen = 0
If Trim(str) <> "" Then '去掉空格
p_len = Len(Trim(str))
For xx = 1 To p_len
If Asc(Mid(str, xx, 1)) < 0 Then
strlen = Int(strlen) + 2
Else
strlen = Int(strlen) + 1
End If
Next
End If
End Function
'得到標題,如果多於strlen寬度,則以...顯示
Function gotTopic(ByVal str As String, ByVal strlen1 As String) As String
Dim l, t, c, i As Integer
l = Len(str)
t = 0
For i = 1 To l
c = Math.Abs(Asc(Mid(str, i, 1)))
If c > 255 Then
t = t + 2
Else
t = t + 1
End If
If t >= strlen1 Then
gotTopic = Left(str, i) & "..."
Exit For
Else
gotTopic = str & " "
End If
Next
End Function
Function RemoveHtml(ByVal str) As String '過濾Html格式
Dim re As Regex
str = re.Match(str, "(\<.[^\<]*\>)")
str = re.Replace(str, " ")
str = re.Match(str, "(\<\/[^\<]*\>")
str = re.Replace(str, "")
RemoveHtml = str
re = Nothing
End Function
End Class