温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:NetShopForge网上商店程序(VB)源码
当前文件:
NetShopForge/Library/Componets/News/NewsController.vb[9K,2009-6-12 11:49:45],打开代码结构图
NetShopForge/Library/Componets/News/NewsController.vb[9K,2009-6-12 11:49:45],打开代码结构图12
Imports Microsoft.Practices.EnterpriseLibrary.Data 3
Imports Microsoft.Practices.EnterpriseLibrary.Common 4
Imports System.Data.SqlClient 5
Imports System.Data.Common 6
Imports System.Data 7
Imports System.Collections.Generic 8
Imports System.Text 9
Imports NetShopForge.Common.Globals 10
11
Namespace NetShopForgeNamespace NetShopForge.Library.News 12
13
Public Class NewsControllerClass NewsController 14
15
Private Member#Region "Private Member" 16
Private Shared _Instance As NewsController 17
#End Region 18
Shared Method#Region "Shared Method" 19
Public Shared ReadOnly Property Instance()Property Instance() As NewsController 20
Get 21
If IsNothing(_Instance) Then 22
_Instance = New NewsController 23
End If 24
Return _Instance 25
End Get 26
End Property 27
#End Region 28
29
30
---Private Method---#Region "---Private Method---" 31
Private Function FillNewsCategoryInfo()Function FillNewsCategoryInfo(ByVal dr As IDataReader) As NewsCategoryInfo 32
33
Dim objNC As New NewsCategoryInfo 34
35
objNC.Name = dr.Item("Name") 36
objNC.Description = dr.Item("Description") 37
objNC.IsSiteNews = CBool(dr.Item("IsSiteNews")) 38
objNC.IsSubscription = CBool(dr.Item("IsSubscription")) 39
objNC.NewsCategoryID = dr.Item("NewsCategoryID") 40
objNC.IsValid = dr.Item("IsValid") 41
42
Return objNC 43
44
End Function 45
46
Private Function FillNewsInfo()Function FillNewsInfo(ByVal dr As IDataReader) As NewsInfo 47
48
Dim objNewsInfo As New NewsInfo 49
50
objNewsInfo.Body = dr.Item("Body") 51
objNewsInfo.NewsID = dr.Item("NewsID") 52
objNewsInfo.NewsCategoryID = dr.Item("NewsCategoryID") 53
objNewsInfo.Subject = dr.Item("Subject") 54
objNewsInfo.IsSiteNews = CBool(dr.Item("IsSiteNews")) 55
objNewsInfo.UpdateDT = CDate(dr.Item("UpdateDT")) 56
objNewsInfo.Status = dr.Item("Status") 57
58
Return objNewsInfo 59
60
End Function 61
62
63
#End Region 64
65
66
67
---Public Method---#Region "---Public Method---" 68
69
Public Function GetNewsCategoryList()Function GetNewsCategoryList() As List(Of NewsCategoryInfo) 70
71
Dim objNCI As New List(Of NewsCategoryInfo) 72
73
Dim db As Database = DatabaseFactory.CreateDatabase 74
Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_News_GetNewsCategoryList") 75
Using reader As IDataReader = db.ExecuteReader(dbCommand) 76
While reader.Read 77
objNCI.Add(FillNewsCategoryInfo(reader)) 78
End While 79
Return objNCI 80
End Using 81
82
End Function 83
84
85
Public Function GetNewsCategory()Function GetNewsCategory(ByVal NewsCategoryID As Integer) As NewsCategoryInfo 86
Dim db As Database = DatabaseFactory.CreateDatabase 87
Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_News_GetNewsCategory") 88
' Add paramters 89
' Input parameters can specify the input value 90
db.AddInParameter(dbCommand, "@NewsCategoryID", DbType.Int32, NewsCategoryID) 91
Using reader As IDataReader = db.ExecuteReader(dbCommand) 92
While reader.Read 93
Return FillNewsCategoryInfo(reader) 94
End While 95
Return Nothing 96
End Using 97
End Function 98
99
Public Sub AddNews()Sub AddNews(ByVal newsinfo As NewsInfo) 100
101
Dim db As Database = DatabaseFactory.CreateDatabase() 102
103
Dim sqlCommand As String = "nsf_News_AddNews" 104
Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand) 105
106
Dim newID As Integer = GetKeys("NewsID") 107
108
db.AddInParameter(dbCommand, "@NewsID", DbType.Int32, newID) 109
db.AddInParameter(dbCommand, "@NewsCategoryID", DbType.Int32, newsinfo.NewsCategoryID) 110
db.AddInParameter(dbCommand, "@Subject", DbType.String, newsinfo.Subject) 111
db.AddInParameter(dbCommand, "@Body", DbType.String, newsinfo.Body) 112
db.AddInParameter(dbCommand, "@IsSiteNews", DbType.Boolean, newsinfo.IsSiteNews) 113
114
db.ExecuteNonQuery(dbCommand) 115
116
End Sub 117
Public Sub AddNewsCategory()Sub AddNewsCategory(ByVal newCategoryInfo As NewsCategoryInfo) 118
119
Dim db As Database = DatabaseFactory.CreateDatabase() 120
121
Dim sqlCommand As String = "nsf_News_AddNewsCategory" 122
Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand) 123
124
Dim NewsCategoryID As Integer = GetKeys("NewsCategoryID") 125
126
db.AddInParameter(dbCommand, "@NewsCategoryID", DbType.Int32, NewsCategoryID) 127
db.AddInParameter(dbCommand, "@Name", DbType.String, newCategoryInfo.Name) 128
db.AddInParameter(dbCommand, "@Description", DbType.String, newCategoryInfo.Description) 129
db.AddInParameter(dbCommand, "@IsValid", DbType.Boolean, newCategoryInfo.IsValid) 130
db.AddInParameter(dbCommand, "@IsSubscription", DbType.Boolean, newCategoryInfo.IsSubscription) 131
db.AddInParameter(dbCommand, "@IsSiteNews", DbType.Boolean, newCategoryInfo.IsSiteNews) 132
db.ExecuteNonQuery(dbCommand) 133
End Sub 134
Public Sub UpdateNews()Sub UpdateNews(ByVal newsinfo As NewsInfo) 135
Dim db As Database = DatabaseFactory.CreateDatabase() 136
137
Dim sqlCommand As String = "nsf_News_UpdateNews" 138
Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand) 139
140
db.AddInParameter(dbCommand, "@NewsID", DbType.Int32, newsinfo.NewsID) 141
db.AddInParameter(dbCommand, "@NewsCategoryID", DbType.Int32, newsinfo.NewsCategoryID) 142
db.AddInParameter(dbCommand, "@Subject", DbType.String, newsinfo.Subject) 143
db.AddInParameter(dbCommand, "@Body", DbType.String, newsinfo.Body) 144
db.AddInParameter(dbCommand, "@IsSiteNews", DbType.Boolean, newsinfo.IsSiteNews) 145
db.ExecuteNonQuery(dbCommand) 146
End Sub 147
Public Sub UpdateNewsCategory()Sub UpdateNewsCategory(ByVal newCategoryInfo As NewsCategoryInfo) 148
Dim db As Database = DatabaseFactory.CreateDatabase() 149
150
Dim sqlCommand As String = "nsf_News_UpdateNewsCategory" 151
Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand) 152
153
db.AddInParameter(dbCommand, "@NewsCategoryID", DbType.Int32, newCategoryInfo.NewsCategoryID) 154
db.AddInParameter(dbCommand, "@Name", DbType.String, newCategoryInfo.Name) 155
db.AddInParameter(dbCommand, "@Description", DbType.String, newCategoryInfo.Description) 156
db.AddInParameter(dbCommand, "@IsValid", DbType.Boolean, newCategoryInfo.IsValid) 157
db.AddInParameter(dbCommand, "@IsSubscription", DbType.Boolean, newCategoryInfo.IsSubscription) 158
db.AddInParameter(dbCommand, "@IsSiteNews", DbType.Boolean, newCategoryInfo.IsSiteNews) 159
db.ExecuteNonQuery(dbCommand) 160
End Sub 161
162
Public Sub UpdateNewsCategoryQuick()Sub UpdateNewsCategoryQuick(ByVal newsCategoryID As Integer, ByVal isValid As Boolean, ByVal isSiteNews As Boolean) 163
Dim sqlb As New StringBuilder 164
sqlb.Append("UPDATE NewsCategory SET ") 165
sqlb.Append("IsValid={0},", IIf(isValid, 1, 0)) 166
sqlb.Append("IsSiteNews={0}", IIf(isSiteNews, 1, 0)) 167
sqlb.Append(" WHERE NewsCategoryID={0}", newsCategoryID.ToString) 168
Dim db As Database = DatabaseFactory.CreateDatabase 169
db.ExecuteNonQuery(CommandType.Text, sqlb.ToString) 170
171
End Sub 172
Public Sub DeleteNews()Sub DeleteNews(ByVal newsID As Integer) 173
Dim db As Database = DatabaseFactory.CreateDatabase() 174
175
Dim sqlCommand As String = "nsf_News_DeleteNews" 176
Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand) 177
178
db.AddInParameter(dbCommand, "@NewsID", DbType.Int32, newsID) 179
180
db.ExecuteNonQuery(dbCommand) 181
End Sub 182
Public Sub DeleteNewsCategory()Sub DeleteNewsCategory(ByVal newCategoryID As Integer) 183
Dim db As Database = DatabaseFactory.CreateDatabase() 184
185
Dim sqlCommand As String = "nsf_News_DeleteNewsCategory" 186
Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand) 187
188
db.AddInParameter(dbCommand, "@NewsCategoryID", DbType.Int32, newCategoryID) 189
190
db.ExecuteNonQuery(dbCommand) 191
End Sub 192
Public Sub DeleteNewsSubscription()Sub DeleteNewsSubscription(ByVal email As String) 193
194
End Sub 195
196
Public Function GetNewsSubscriptionList()Function GetNewsSubscriptionList() As List(Of NewsSubscriptionInfo) 197
Return Nothing 198
End Function 199
Public Function GetNewsList()Function GetNewsList(ByVal NewsCategoryID As Integer) As List(Of NewsInfo) 200
201
Dim objNewsList As New List(Of NewsInfo) 202
203
Dim db As Database = DatabaseFactory.CreateDatabase 204
205
Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_News_GetNewsList") 206
db.AddInParameter(dbCommand, "@NewsCategoryID", DbType.Int32, NewsCategoryID) 207
Using reader As IDataReader = db.ExecuteReader(dbCommand) 208
While reader.Read 209
objNewsList.Add(FillNewsInfo(reader)) 210
End While 211
Return objNewsList 212
End Using 213
214
End Function 215
Public Function GetNews()Function GetNews(ByVal NewsID As Integer) As NewsInfo 216
217
Dim db As Database = DatabaseFactory.CreateDatabase 218
Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_News_GetNews") 219
' Add paramters 220
' Input parameters can specify the input value 221
db.AddInParameter(dbCommand, "@NewsID", DbType.Int32, NewsID) 222
Using reader As IDataReader = db.ExecuteReader(dbCommand) 223
While reader.Read 224
Return FillNewsInfo(reader) 225
End While 226
Return Nothing 227
End Using 228
229
End Function 230
231
232
233
#End Region 234
235
236
237
238
End Class 239
240
End Namespace








