温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:MyShop网络商城源码(mvc开发)
当前文件路径:MyShop/BLL/Product.cs

1using System; 2
using System.Collections.Generic; 3
using System.Data; 4
using MyShop.Model; 5
using MyShop.IDAL; 6
using MyShop.DALFactory; 7
8
namespace MyShop.BLL 9
...{ 10
public class Product 11
...{ 12
private IProduct dal = DataAccess.CreateProduct(); 13
private ConfigInfo configInfo = new ConfigInfo(); 14
private string tableName = "Ljh_Products"; 15
private int _id; 16
17
public Product() 18
...{ 19
if (!string.IsNullOrEmpty(configInfo.TablePrefix.Trim())) 20
tableName = configInfo.TablePrefix + "Products"; 21
} 22
23
public Product(int id) 24
...{ 25
if (!string.IsNullOrEmpty(configInfo.TablePrefix.Trim())) 26
tableName = configInfo.TablePrefix + "Products"; 27
this._id = id; 28
29
} 30
31
IProduct member#region IProduct member 32
33
public int Add(ProductInfo model) 34
...{ 35
if (model == null) 36
...{ 37
return 0; 38
} 39
return dal.Add(model); 40
} 41
42
public int Delete(string filter) 43
...{ 44
if (string.IsNullOrEmpty(filter)) 45
return 0; 46
return dal.Delete(filter); 47
} 48
49
public bool Exist(string filter) 50
...{ 51
filter = filter.Trim(); 52
if (string.IsNullOrEmpty(filter)) 53
return false; 54
return dal.Exist(filter); 55
} 56
public DataSet GetDataSet() 57
...{ 58
return dal.GetDataSet(); 59
} 60
61
public DataSet GetDataSet(string filter) 62
...{ 63
filter = filter.Trim(); 64
if (string.IsNullOrEmpty(filter)) 65
return null; 66
return dal.GetDataSet(filter); 67
} 68
69
public DataSet GetDataSet(int productId) 70
...{ 71
if (productId <= 0) 72
return null; 73
string filter = " productId=" + productId; 74
return GetDataSet(filter); 75
} 76
77
public ProductInfo 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(ProductInfo 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
public int Add(ProductInfo model, out string msg) 107
...{ 108
msg = ""; 109
if (model == null) 110
...{ 111
msg = msg + "<li>数据不能为空</li>"; 112
return 0; 113
} 114
115
bool isErr = false; 116
117
if (string.IsNullOrEmpty(model.ProductName.Trim())) 118
...{ 119
msg = msg + "请输入商品名称"; 120
isErr = true; 121
} 122
123
if (isErr) 124
return 0; 125
126
int count = 0; 127
count = Add(model); 128
if (count == 0) 129
msg = "<li>系统发生错误,请重新添加!</li>"; 130
if (count == 1) 131
msg = "<li>添加成功!</li>"; 132
return count; 133
} 134
135
/**//// <summary> 136
/// 真正从数据库中删除,注意使用时要分清是不是只放到回收站 137
/// </summary> 138
/// <param name="productId"></param> 139
/// <returns></returns> 140
public int Delete(int productId) 141
...{ 142
if ( string.IsNullOrEmpty( productId.ToString()) ) 143
return 0; 144
string filer; 145
filer = " productId =" + productId; 146
return Delete(filer); 147
} 148
149
150
public int Update(ProductInfo model) 151
...{ 152
153
if (model == null) 154
...{ 155
return 0; 156
} 157
string filter; 158
filter = " productId=" + model.ProductId; 159
return Update(model, filter); 160
} 161
162
public ProductInfo GetModel(int productId) 163
...{ 164
DataSet dataset = new DataSet(); 165
dataset = GetDataSet(" productId=" + productId); 166
if (dataset != null && dataset.Tables[0].Rows.Count > 0) 167
return GetModel(dataset.Tables[0].Rows[0]); 168
return null; 169
170
} 171
172
获取商品列表#region 获取商品列表 173
174
/**//// <summary> 175
/// 获取商品列表 176
/// </summary> 177
/// <param name="EnableSale">是否允许销售</param> 178
/// <param name="deleted">是否已删除</param> 179
/// <returns></returns> 180
public DataSet GetDataSet(bool enableSale, bool deleted) 181
...{ 182
return dal.GetDataSet(enableSale,deleted); 183
} 184
185
186
/**//// <summary> 187
/// 获取商品列表 188
/// </summary> 189
/// <param name="productKindId">商品大类ID</param> 190
/// <param name="categoryId">商品小类ID</param> 191
/// <returns></returns> 192
public DataSet GetDataSet( int productKindId,int categoryId ) 193
...{ 194
return dal.GetDataSet(productKindId,categoryId); 195
} 196
197
/**//// <summary> 198
/// 获取商品列表 199
/// </summary> 200
/// <param name="productKindId">商品大类ID</param> 201
/// <param name="categoryId">商品小类ID</param> 202
/// <param name="enableSale">是否允许销售</param> 203
/// <param name="deleted">是否已删除</param> 204
/// <returns></returns> 205
public DataSet GetDataSet( int productKindId,int categoryId ,bool enableSale, bool deleted) 206
...{ 207
return dal.GetDataSet(productKindId,categoryId,enableSale,deleted); 208
} 209
210
/**//// <summary> 211
/// 获取商品列表 212
/// </summary> 213
/// <param name="productKindId">商品大类ID</param> 214
/// <returns></returns> 215
public DataSet GetDataSetByProductKindId(int productKindId) 216
...{ 217
return dal.GetDataSetByProductKindId(productKindId); 218
} 219
220
/**//// <summary> 221
/// 获取商品列表 222
/// </summary> 223
/// <param name="productKindId">商品大类ID</param> 224
/// <param name="deleted">是否已删除</param> 225
/// <returns></returns> 226
public DataSet GetDataSetByProductKindId(int productKindId,bool deleted) 227
...{ 228
return dal.GetDataSetByProductKindId(productKindId,deleted); 229
} 230
231
/**//// <summary> 232
/// 获取商品列表 233
/// </summary> 234
/// <param name="productKindId">商品大类ID</param> 235
/// <param name="enableSale">是否允许销售</param> 236
/// <param name="deleted">是否已删除</param> 237
/// <returns></returns> 238
public DataSet GetDataSetByProductKindId(int productKindId,bool enableSale, bool deleted) 239
...{ 240
return dal.GetDataSetByProductKindId(productKindId,enableSale,deleted); 241
} 242
243
244
/**//// <summary> 245
/// 获取商品列表 246
/// </summary> 247
/// <param name="categoryId">商品小类ID</param> 248
/// <returns></returns> 249
public DataSet GetDataSetByCategoryId(int categoryId) 250
...{ 251
return dal.GetDataSetByCategoryId(categoryId); 252
} 253
254
/**//// <summary> 255
/// 获取商品列表 256
/// </summary> 257
/// <param name="categoryId">商品小类ID</param> 258
/// <param name="deleted">是否已删除</param> 259
/// <returns></returns> 260
public DataSet GetDataSetByCategoryId(int categoryId,bool deleted) 261
...{ 262
return dal.GetDataSetByCategoryId(categoryId,deleted); 263
} 264
265
/**//// <summary> 266
/// 获取商品列表 267
/// </summary> 268
/// <param name="categoryId">商品小类ID</param> 269
/// <param name="enableSale">是否允许销售</param> 270
/// <param name="deleted">是否已删除</param> 271
/// <returns></returns> 272
public DataSet GetDataSetByCategoryId(int categoryId,bool enableSale, bool deleted) 273
...{ 274
return dal.GetDataSetByCategoryId(categoryId,enableSale,deleted); 275
} 276
277
public DataSet KeywordsSearch(string keywords) 278
...{ 279
keywords = Utils.ReplaceBadSQL(keywords.Trim()); 280
if (Utils.ChkBadChar(keywords.Trim()) || string.IsNullOrEmpty(keywords.Trim())) 281
return null; 282
return dal.KeywordsSearch(keywords); 283
} 284
285
#endregion 286
287
288
289
290
#endregion 291
292
以下过程要用Product product = new Product(id)实例化后才能进行调用#region 以下过程要用Product product = new Product(id)实例化后才能进行调用 293
294
295
property#region property 296
297





}