温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyShop网络商城080617源码
当前文件:
MyShop080617/BLL/Article.cs,打开代码结构图
MyShop080617/BLL/Article.cs,打开代码结构图1using System; 2
using System.Collections.Generic; 3
using System.Data; 4
5
using MyShop.DALFactory; 6
using MyShop.IDAL; 7
using MyShop.Model; 8
using MyShop.Enumerations; 9
using MyShop.Common; 10
namespace MyShop.BLL 11
...{ 12
public class Article 13
...{ 14
ConfigInfo configInfo = new ConfigInfo(); 15
Config config = new Config(); 16
17
private int _id; 18
private IArticle dal = DataAccess.CreateArticle(); 19
20
public Article() 21
...{ 22
configInfo = config.GetModel(); 23
} 24
25
26
private int _articleId; 27
28
29
public Article(int articleId) 30
...{ 31
this._id = articleId; 32
} 33
34
IArticle#region IArticle 35
36
/**//// <summary> 37
/// 38
/// </summary> 39
/// <param name="model"></param> 40
/// <returns></returns> 41
protected int Add(ArticleInfo model) 42
...{ 43
if (model == null) 44
...{ 45
return 0; 46
} 47
return dal.Add(model); 48
} 49
50
protected int Delete(string filter) 51
...{ 52
if (string.IsNullOrEmpty(filter)) 53
return 0; 54
return dal.Delete(filter); 55
} 56
57
public bool Exist(string filter) 58
...{ 59
filter = filter.Trim(); 60
if (string.IsNullOrEmpty(filter)) 61
return false; 62
return dal.Exist(filter); 63
} 64
public DataSet GetDataSet() 65
...{ 66
return dal.GetDataSet(); 67
} 68
69
public DataSet GetDataSet(string filter) 70
...{ 71
filter = filter.Trim(); 72
if (string.IsNullOrEmpty(filter)) 73
return null; 74
return dal.GetDataSet(filter); 75
} 76
77
public ArticleInfo GetModel(DataRow dr) 78
...{ 79
if (dr == null) 80
return null; 81
return dal.GetModel(dr); 82
} 83
84
private DataSet Query(string sql) 85
...{ 86
sql = sql.Trim(); 87
if (string.IsNullOrEmpty(sql)) 88
return null; 89
return dal.Query(sql); 90
} 91
92
public int Update(ArticleInfo model, string filter) 93
...{ 94
if (model == null) 95
return 0; 96
filter = filter.Trim(); 97
if (string.IsNullOrEmpty(filter)) 98
return 0; 99
return dal.Update(model, filter); 100
} 101
102
#endregion 103
104
common#region common 105
106
/**//// <summary> 107
/// 108
/// </summary> 109
/// <param name="model"></param> 110
/// <param name="msg"></param> 111
/// <returns></returns> 112
public int Add(ArticleInfo model, out string msg) 113
...{ 114
msg = ""; 115
if (model == null) 116
...{ 117
msg = msg + "<li>数据不能为空</li>"; 118
return 0; 119
} 120
bool isErr = false; 121
122
if (isErr) 123
return 0; 124
125
int count = 0; 126
count = Add(model); 127
if (count == 0) 128
msg = "<li>系统发生错误,请重新添加!</li>"; 129
if (count == 1) 130
msg = "<li>添加成功!</li>"; 131
return count; 132
} 133
134
/**//// <summary> 135
/// 真正从数据库中删除,注意使用时要分清是不是只放到回收站 136
/// </summary> 137
/// <param name="articleId"></param> 138
/// <returns></returns> 139
public int Delete(int articleId) 140
...{ 141
ArticleInfo model = new ArticleInfo(); 142
model = GetModel(articleId); 143
if (model == null) 144
return 0; 145
146
string filer; 147
filer = " articleId =" + articleId; 148
return Delete(filer); 149
} 150
151
public int Update(ArticleInfo model) 152
...{ 153
154
if (model == null) 155
...{ 156
return 0; 157
} 158
string filter; 159
filter = " articleId=" + model.ArticleID; 160
return Update(model, filter); 161
} 162
163
public ArticleInfo GetModel(int articleId) 164
...{ 165
DataSet dataset = new DataSet(); 166
dataset = GetDataSet(" articleId=" + articleId); 167
if (dataset != null && dataset.Tables[0].Rows.Count > 0) 168
return GetModel(dataset.Tables[0].Rows[0]); 169
return null; 170
} 171
public ArticleInfo GetModel(string title) 172
...{ 173
title = DataSecurity.ReplaceBadSQL(title.Trim()); 174
if (string.IsNullOrEmpty(title.ToString())) 175
return null; 176
DataSet dataset = new DataSet(); 177
dataset = GetDataSet(" title='" + title + "'"); 178
if (dataset != null && dataset.Tables[0].Rows.Count > 0) 179
return GetModel(dataset.Tables[0].Rows[0]); 180
return null; 181
} 182
183
184
185
186
#endregion 187
188
获取文章列表#region 获取文章列表 189
190
191
192
/**//// <summary> 193
/// 获取文章列表(前台用) 194
/// </summary> 195
/// <param name="channelId">频道ID。如果是所有频道,参数值应为-1</param> 196
/// <param name="classId">栏目ID。如果是所有栏目,参数值应为-1</param> 197
/// <returns></returns> 198
public DataSet GetArticlList(int channelId, int classId) 199
...{ 200
bool status = true; 201
bool deleted = false; 202
int isDeleted = deleted ? 1 : 0; 203
int _status = (status == true) ? 1 : 0; 204
205
string filter = ""; 206
filter = (channelId == -1) ? filter : filter + " and [channelId] = " + channelId; 207
filter = (classId == -1) ? filter : filter + " and [classId] = " + classId; 208
filter = filter + " and [Status] = " + _status + " and [deleted] =" + isDeleted; 209
filter = " [articleId] > 0 " + filter + " order by onTop desc, articleId desc "; 210
return GetDataSet(filter); 211
} 212
213
214
215
/**//// <summary> 216
/// 获取文章列表 217
/// </summary> 218
/// <param name="channelId">文章频道ID</param> 219
/// <returns></returns> 220
public DataSet GetDataSetByChannelId(int channelId) 221
...{ 222
return GetDataSet(channelId,-1); 223
} 224
225
226
/**//// <summary> 227
/// 获取文章列表 228
/// </summary> 229
/// <param name="classId">文章栏目ID</param> 230
/// <returns></returns> 231
public DataSet GetDataSetByClassId(int classId) 232
...{ 233
return GetDataSet(-1,classId); 234
} 235
236
/**//// <summary> 237
/// 获取文章列表 238
/// </summary> 239
/// <param name="channelId">频道ID。如果是所有频道,参数值应为-1</param> 240
/// <param name="classId">栏目ID。如果是所有栏目,参数值应为-1</param> 241
/// <returns></returns> 242
public DataSet GetDataSet(int channelId, int classId) 243
...{ 244
string filter = ""; 245
filter = (channelId == -1) ? filter : filter + " and [channelId] = " + channelId; 246
filter = (classId == -1) ? filter : filter + " and [classId] = " + classId; 247
filter = " [articleId] > 0 " + filter + " order by articleId desc "; 248
return GetDataSet(filter); 249
} 250
251
//================================ 252
253
/**//// <summary> 254
/// 获取文章列表 255
/// </summary> 256
/// <param name="Status">是否审核通过</param> 257
/// <param name="deleted">是否已删除</param> 258
/// <returns></returns> 259
public DataSet GetDataSet(bool status, bool deleted) 260
...{ 261
return GetDataSet(-1,-1,status,deleted); 262
} 263
264
/**//// <summary> 265
/// 获取文章列表 266
/// </summary> 267
/// <param name="channelId">频道ID。如果是所有频道,参数值应为-1</param> 268
/// <param name="status">是否审核通过</param> 269
/// <param name="deleted">是否已删除</param> 270
/// <returns></returns> 271
public DataSet GetDataSetByChannelId(int channelId,bool status, bool deleted) 272
...{ 273
return GetDataSet(channelId,-1,status,deleted); 274
} 275
276
277
278
279
/**//// <summary> 280
/// 获取文章列表 281
/// </summary> 282
/// <param name="classId">栏目ID。如果是所有栏目,参数值应为-1</param> 283
/// <param name="status">是否审核通过</param> 284
/// <param name="deleted">是否已删除</param> 285
/// <returns></returns> 286
public DataSet GetDataSetByClassId(int classId,bool status, bool deleted) 287
...{ 288
return GetDataSet(-1,classId,status,deleted); 289
} 290
291
292
/**//// <summary> 293
/// 获取文章列表 294
/// </summary> 295
/// <param name="channelId">频道ID。如果是所有频道,参数值应为-1</param> 296
/// <param name="classId





}