?? news.vb
字號:
Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.OleDb
Namespace Packaging
Public Class News
Public NewsId As Integer
Public NewsCat As Integer
Public NewsTitle As String
Public NewsContent As String
Public NewsGeneral As String
Public NewsTime As DateTime
Public NewsFrom As String
Public NewsAuthor As String
Public NewsClicks As Integer
Public NewsCover As Boolean
Public IsHTML As Boolean
End Class
Public Class NewsDB
Public NewsCat As Integer
Public TopNum As Integer
Public LessNum As Integer
Public Function GetTopNews() As DataView
' 取得最新的 N 條新聞
Dim MySQL As String
MySQL="SELECT TOP "& TopNum &" NewsID, NewsGeneral, IsHTML FROM [News] "
MySQL &="WHERE NewsCover=false And NewsCat="
MySQL &=NewsCat &" ORDER BY NewsTime DESC"
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim MyDS As DataSet=MyDB.SelectFromDB()
Dim DV As DataView=MyDS.Tables("My").DefaultView
Dim MyFilter As StringFilter=New StringFilter()
If DV.Table.Rows(0)("IsHTML")=True
MyFilter.FilterDegree=0
Else
MyFilter.FilterDegree=1
End If
Dim i As Integer
For i=0 to DV.Table.Rows.Count-1
DV.Table.Rows(i)("NewsGeneral")=MyFilter.Change4Showing(DV.Table.Rows(i)("NewsGeneral"))
Next
Return DV
End Function
Public Function GetNewsContent(ByVal id As Integer) As DataView
' 取得標(biāo)號為id的新聞內(nèi)容
Dim MySQL As String
MySQL="SELECT * FROM [News] WHERE NewsCover=false And NewsID="
MySQL &=ID &""
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim MyDS As DataSet=MyDB.SelectFromDB()
Dim DV As DataView=MyDS.Tables("My").DefaultView
DV.Table.Rows(0)("NewsClicks")+=1
Dim MyFilter As StringFilter=New StringFilter()
If DV.Table.Rows(0)("IsHTML")=True
MyFilter.FilterDegree=0
Else
MyFilter.FilterDegree=1
End If
DV.Table.Rows(0)("NewsContent")=MyFilter.Change4Showing(DV.Table.Rows(0)("NewsContent"))
ReadOnce(id)
Return DV
End Function
Public Function GetNewsContent1(ByVal id As Integer) As DataView
' 取得標(biāo)號為id的新聞內(nèi)容
Dim MySQL As String
MySQL="SELECT * FROM [News] WHERE NewsCover=false And NewsID="
MySQL &=ID &""
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim MyDS As DataSet=MyDB.SelectFromDB()
Dim DV As DataView=MyDS.Tables("My").DefaultView
DV.Table.Rows(0)("NewsClicks")+=1
ReadOnce(id)
Return DV
End Function
Public Function GetLessLatestNews() As DataView
' 取得次新的 N 條新聞
Dim MySQL As String
MySQL="SELECT TOP "& TopNum+LessNum &" NewsID, NewsTitle FROM [News] "
MySQL &="WHERE NewsCover=false And NewsCat="
MySQL &=NewsCat &" ORDER BY NewsTime DESC"
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim MyDS As DataSet=MyDB.SelectFromDB()
Dim DV As DataView=MyDS.Tables("My").DefaultView
Dim i As Integer
Dim DR As DataRow
For i=1 to TopNum
Try
DR=DV.Table.Rows(i-1)
DV.Table.Rows(i-1).Delete
Catch
End Try
Next
DV.Table.AcceptChanges()
Return DV
End Function
Public Function GetAllNews() As DataView
Dim MySQL As String
MySQL="SELECT NewsID, NewsTitle, NewsCat, NewsTime, NewsCover, NewsClicks, NewsAuthor FROM [News] "
MySQL &="ORDER BY NewsTime DESC"
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim MyDS As DataSet=MyDB.SelectFromDB()
Dim DV As DataView=MyDS.Tables("My").DefaultView
Return DV
End Function
Public PageSize As Integer
Public Function GetNewsList(ByVal CurPage As Integer, ByRef TotalPage As Integer) As DataView
Dim MySQL As String
MySQL="SELECT NewsID,NewsTitle FROM [News] WHERE NewsCover=false And NewsCat="
MySQL &=NewsCat &" ORDER BY NewsTime DESC"
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim MyPage As PageDS=New PageDS()
MyPage.DataSource=MyDB.SelectFromDB()
MyPage.PageSize=PageSize
Dim MyDV As DataView=MyPage.PageSelect(CurPage)
TotalPage=MyPage.TotalPage
Return MyDV
End Function
Private Function ReadOnce(ByVal id As Integer)
Dim MySQL As String
MySQL="UPDATE [News] SET NewsClicks=NewsClicks+1 WHERE NewsID="
MySQL &=id
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Function
Private Sub Change4SQL(ByRef MyNews As News)
Dim MyFilter As StringFilter=New StringFilter()
MyFilter.FilterDegree=0
MyNews.NewsTitle=MyFilter.Change4Saving(MyNews.NewsTitle)
MyNews.NewsContent=MyFilter.Change4Saving(MyNews.NewsContent)
MyNews.NewsAuthor=MyFilter.Change4Saving(MyNews.NewsAuthor)
MyNews.NewsGeneral=MyFilter.Change4Saving(MyNews.NewsGeneral)
MyNews.NewsFrom=MyFilter.Change4Saving(MyNews.NewsFrom)
End Sub
Public Sub AddNews(ByVal MyNews As News)
Change4SQL(MyNews)
Dim MySQL As String="INSERT INTO [News] "
MySQL &= "(NewsTitle, NewsContent, NewsGeneral,"
MySQL &= "NewsCat, NewsFrom, NewsAuthor, "
MySQL &= "NewsTime, IsHTML) VALUES ('"
MySQL &= MyNews.NewsTitle & "', '"
MySQL &= MyNews.NewsContent & "', '"
MySQL &= MyNews.NewsGeneral & "', "
MySQL &= MyNews.NewsCat & ", '"
MySQL &= MyNews.NewsFrom & "', '"
MySQL &= MyNews.NewsAuthor & "', #"
MySQL &= DateTime.Now() & "#, "
MySQL &= MyNews.IsHTML & ")"
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Sub
Public Sub ChangeNews(ByVal MyNews As News)
Change4SQL(MyNews)
Dim MySQL As String="UPDATE [News] SET "
MySQL &= "NewsTitle='" & MyNews.NewsTitle & "', "
MySQL &= "NewsContent='" & MyNews.NewsContent & "', "
MySQL &= "NewsGeneral='" & MyNews.NewsGeneral & "', "
MySQL &= "NewsCat=" & MyNews.NewsCat & ", "
MySQL &= "NewsFrom='" & MyNews.NewsFrom & "', "
MySQL &= "NewsAuthor='" & MyNews.NewsAuthor & "', "
MySQL &= "IsHTML=" & MyNews.IsHTML
MySQL &= " WHERE NewsId=" & MyNews.NewsId
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Sub
Public Sub DeleteNews(ByVal Id As Integer)
Dim MySQL As String="DELETE FROM [News] WHERE NewsId="
MySQL &= Id
MySQL &= " "
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Sub
Public Sub CoverNews(ByVal id As Integer)
Dim MySQL As String="UPDATE [News] SET NewsCover=true WHERE NewsID="
MySQL &= id
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Sub
Public Sub UnCoverNews(ByVal id As Integer)
Dim MySQL As String="UPDATE [News] SET NewsCover=false WHERE NewsID="
MySQL &= id
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Sub
Public Function IsCovered(ByVal id As Integer) As Boolean
Dim MySQL As String
MySQL="SELECT NewsCover FROM [News] WHERE NewsID="
MySQL &=ID &""
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim MyDS As DataSet=MyDB.SelectFromDB()
Dim DV As DataView=MyDS.Tables("My").DefaultView
Return DV.Table.Rows(0)("NewsCover")
End Function
End Class
End Namespace
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -