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





}