温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyShop网络商城080617源码
当前文件:
MyShop080617/AccessDAL/Product.cs,打开代码结构图
MyShop080617/AccessDAL/Product.cs,打开代码结构图1using System; 2
using System.Collections.Generic; 3
using System.Data; 4
using System.Data.OleDb; 5
using MyShop.IDAL; 6
using MyShop.Model; 7
8
namespace MyShop.AccessDAL 9
...{ 10
public class Product :IProduct 11
...{ 12
13
private ConfigInfo configInfo = new ConfigInfo(); 14
private string tableName = "Ljh_Products"; 15
16
public Product() 17
...{ 18
if (!string.IsNullOrEmpty(configInfo.TablePrefix.Trim())) 19
tableName = configInfo.TablePrefix + "Products"; 20
} 21
22
IProduct member#region IProduct member 23
24
25
/**//// <summary> 26
/// add Product 27
/// </summary> 28
/// <param name="model"></param> 29
/// <returns>返回ID, 如果发生错误则返回-1</returns> 30
public int Add(ProductInfo model) 31
...{ 32
if (model == null) 33
...{ 34
return 0; 35
} 36
string commandText = "insert into " + this.tableName + "(productName,productNum,productKindId,productModel,producerId,trademarkName,productIntro,productExplain,productThumb,productType,price,priceOriginal,priceMember,unit,onTop,isElite,hits,stocks,enableSale,discount,presentExp,barCode,productStandard,presentId,categoryId,ProductPhoto,InputTime,isHot,deleted,inputer,buyTimes,UpdateTime,CreateTime,Keywords,CommentCount,Weight,Price_Market,OrderNum,AlarmNum,Stars) values(@productName,@productNum,@productKindId,@productModel,@producerId,@trademarkName,@productIntro,@productExplain,@productThumb,@productType,@price,@priceOriginal,@priceMember,@unit,@onTop,@isElite,@hits,@stocks,@enableSale,@discount,@presentExp,@barCode,@productStandard,@presentId,@categoryId,@ProductPhoto,@InputTime,@ishot,@deleted,@inputer,@buyTimes,@UpdateTime,@CreateTime,@Keywords,@CommentCount,@Weight,@Price_Market,@OrderNum,@AlarmNum,@stars) "; 37
OleDbParameter[] commandParameters = ...{ 38
Database.MakeInParam("@ProductName",OleDbType.VarWChar,100,model.ProductName), 39
Database.MakeInParam("@ProductNum",OleDbType.VarWChar,50,model.ProductNum), 40
Database.MakeInParam("@ProductKindId",OleDbType.SmallInt,2,model.ProductKindId), 41
Database.MakeInParam("@ProductModel",OleDbType.VarWChar,100,model.ProductModel), 42
Database.MakeInParam("@ProducerId",OleDbType.Integer,4,model.ProducerId), 43
Database.MakeInParam("@TrademarkName",OleDbType.VarWChar,100,model.TrademarkName), 44
Database.MakeInParam("@ProductIntro",OleDbType.VarWChar,255,model.ProductIntro), 45
Database.MakeInParam("@ProductExplain",OleDbType.VarWChar,0,model.ProductExplain), 46
Database.MakeInParam("@ProductThumb",OleDbType.VarWChar,200,model.ProductThumb), 47
Database.MakeInParam("@ProductType",OleDbType.SmallInt,2,model.ProductType), 48
Database.MakeInParam("@Price",OleDbType.Currency,8,model.Price), 49
Database.MakeInParam("@PriceOriginal",OleDbType.Currency,8,model.PriceOriginal), 50
Database.MakeInParam("@PriceMember",OleDbType.Currency,8,model.PriceMember), 51
Database.MakeInParam("@Unit",OleDbType.VarWChar,5,model.Unit), 52
Database.MakeInParam("@OnTop",OleDbType.UnsignedTinyInt,1,model.OnTop), 53
Database.MakeInParam("@IsElite",OleDbType.UnsignedTinyInt,1,model.IsElite), 54
Database.MakeInParam("@Hits",OleDbType.Integer,4,model.Hits), 55
Database.MakeInParam("@Stocks",OleDbType.Integer,4,model.Stocks), 56
Database.MakeInParam("@EnableSale",OleDbType.UnsignedTinyInt,1,model.EnableSale), 57
58
Database.MakeInParam("@Discount",OleDbType.Double,8,model.Discount), 59
Database.MakeInParam("@PresentExp",OleDbType.Integer,4,model.PresentExp), 60
Database.MakeInParam("@BarCode",OleDbType.VarWChar,50,model.BarCode), 61
Database.MakeInParam("@ProductStandard",OleDbType.VarWChar,100,model.ProductStandard), 62
Database.MakeInParam("@PresentId",OleDbType.Integer,4,model.PresentId), 63
Database.MakeInParam("@CategoryId",OleDbType.Integer,4,model.CategoryId), 64
Database.MakeInParam("@ProductPhoto",OleDbType.VarWChar,200,model.ProductPhoto), 65
Database.MakeInParam("@InputTime",OleDbType.Date,8,model.InputTime), 66
Database.MakeInParam("@IsHot",OleDbType.UnsignedTinyInt,1,model.IsHot), 67
Database.MakeInParam("@Deleted",OleDbType.UnsignedTinyInt,1,model.Deleted), 68
Database.MakeInParam("@Inputer",OleDbType.VarWChar,20,model.Inputer), 69
Database.MakeInParam("@BuyTimes",OleDbType.Integer,4,model.BuyTimes), 70
Database.MakeInParam("@UpdateTime",OleDbType.Date,8,model.UpdateTime), 71
Database.MakeInParam("@CreateTime",OleDbType.Date,8,model.CreateTime), 72
Database.MakeInParam("@Weight",OleDbType.Double,8,model.Weight), 73
Database.MakeInParam("@Keywords",OleDbType.VarWChar,255,model.Keywords), 74
Database.MakeInParam("@CommentCount",OleDbType.Integer,4,model.CommentCount), 75
Database.MakeInParam("@Price_Market",OleDbType.Currency ,8,model.Price_Market), 76
Database.MakeInParam("@OrderNum",OleDbType.Integer,4,model.OrderNum), 77
Database.MakeInParam("@AlarmNum",OleDbType.Integer,4,model.AlarmNum), 78
Database.MakeInParam("@Stars",OleDbType.Integer,4,model.Stars) 79
}; 80
int intIdentity = -1; 81
try 82
...{ 83
Database.ExecuteNonQuery(CommandType.Text, out intIdentity, commandText, commandParameters); 84
} 85
catch (Exception exception) 86
...{ 87
throw exception; 88
} 89
return intIdentity; 90
} 91
92
93
94
95
/**//// <summary> 96
/// 删除会员 97
/// </summary> 98
/// <param name="filter">where后面的条件语句,不加where</param> 99
/// <returns>返回影响行数</returns> 100
public int Delete(string filter) 101
...{ 102
int count = -1; 103
string sql = @"delete from " + tableName; 104
if (!string.IsNullOrEmpty(filter.Trim())) 105
...{ 106
sql = sql + " where " + filter; 107
} 108
try 109
...{ 110
111
count = Database.ExecuteNonQuery(sql); 112
} 113
catch (Exception ex) 114
...{ 115
throw ex; 116
} 117
return count; 118
} 119
120
/**//// <summary> 121
/// 122
/// </summary> 123
/// <param name="filter"></param> 124
/// <returns></returns> 125
public bool Exist(string filter) 126
...{ 127
bool result = false; 128
string sql = @"select * from " + tableName; 129
if (!string.IsNullOrEmpty(filter)) 130
...{ 131
sql = sql + " where " + filter; 132
} 133
try 134
...{ 135
136
137
DataSet dataset = new DataSet(); 138
dataset = Database.ExecuteDataSet(sql); 139
if (dataset.Tables[0].Rows.Count > 0) 140
...{ 141
result = true; 142
} 143
} 144
catch (Exception ex) 145
...{ 146
throw ex; 147
} 148
return result; 149
} 150
151
/**//// <summary> 152
/// 返回所有产品 153
/// </summary> 154
/// <returns>返回所有产品</returns> 155
public DataSet GetDataSet() 156
...{ 157
string sql = "select * from " + tableName; 158
DataSet dataset = new DataSet(); 159
try 160
...{ 161
162
dataset = Database.ExecuteDataSet(sql); 163
164
} 165
catch (Exception ex) 166
...{ 167
throw ex; 168
} 169
return dataset; 170
} 171
172
public DataSet GetDataSet(string filter) 173
...{ 174
if (string.IsNullOrEmpty(filter)) 175
return null; 176
177
string sql = "select * from " + tableName + " where " + filter; 178
DataSet dataset = new DataSet(); 179
try 180
...{ 181
182
dataset = Database.ExecuteDataSet(sql); 183
} 184
catch (Exception ex) 185
...{ 186
throw ex; 187
} 188
return dataset; 189
} 190
191
/**//// <summary> 192
/// 193
/// </summary> 194
/// <param name="dr"></param> 195
/// <returns></returns> 196
public ProductInfo GetModel(DataRow dr) 197
...{ 198
if (dr == null) 199
return null; 200
ProductInfo model = new ProductInfo(); 201
202
if (dr["ProductId"].ToString() != "") model.ProductId = Convert.ToInt32( dr["ProductId"]); 203
if (dr["ProductName"].ToString() != "") model.ProductName = dr["ProductName"].ToString(); 204
if (dr["ProductNum"].ToString() != "") model.ProductNum = dr["ProductNum"].ToString(); 205
if (dr["ProductKindId"].ToString() != "") model.ProductKindId = Convert.ToInt32(dr["ProductKindId"]); 206
if (dr["ProductModel"].ToString() != "") model.ProductModel = dr["ProductModel"].ToString(); 207
if (dr["producerId"].ToString() != "") model.ProducerId = Convert.ToInt32( dr["producerId"]); 208
if (dr["trademarkName"].ToString() != "") model.TrademarkName = dr["trademarkName"].ToString(); 209
if (dr["ProductIntro"].ToString() != "") model.ProductIntro = dr["ProductIntro"].ToString(); 210
if (dr["ProductExplain"].ToString() != "") model.ProductExplain = dr["ProductExplain"].ToString(); 211
if (dr["ProductThumb"].ToString() != "") model.ProductThumb = dr["ProductThumb"].ToString(); 212
if (dr["ProductType"].ToString() != "") model.ProductType = Convert.ToInt32( dr["ProductType"]); 213
if (dr["price"].ToString() != "") model.Price = Convert.ToDecimal( dr["price"] ); 214
if (dr["priceOriginal"].ToString() != "") model.PriceOriginal = Convert.ToDecimal(dr["priceOriginal"]); 215
if (dr["priceMember"].ToString() != "") model.PriceMember = Convert.ToDecimal(dr["priceMember"]); 216
if (dr["unit"].ToString() != "") model.Unit = dr["unit"].ToString(); 217
if (dr["onTop"].ToString() != "") model.OnTop = Convert.ToInt32( dr["onTop"]); 218
if (dr["isElite"].ToString() != "") model.IsElite = Convert.ToInt32( dr["isElite"]); 219
if (dr["hits"].ToString() != "") model.Hits = Convert.ToInt32( dr["hits"]); 220
if (dr["stocks"].ToString() != "") model.Stocks = Convert.ToInt32( dr["stocks"]); 221
if (dr["enableSale"].ToString() != "") model.EnableSale = Convert.ToInt32( dr["enableSale"]); 222
if (dr["discount"].ToString() != "") model.Discount = Convert.ToSingle( dr["discount"]); 223
if (dr["PresentExp"].ToString() != "") model.PresentExp = Convert.ToInt32( dr["PresentExp"]); 224
if (dr["barCode"].ToString() != "") model.BarCode = dr["barCode"].ToString(); 225
if (dr["ProductStandard"].ToString() != "") model.ProductStandard = dr["ProductStandard"].ToString(); 226
if (dr["presentId"].ToString() != "") model.PresentId = Convert.ToInt32(dr["presentId"]); 227
if (dr["categoryId"].ToString() != "") model.CategoryId = Convert.ToInt32(dr["categoryId"]); 228
if (dr["ProductPhoto"].ToString() != "") model.ProductPhoto = dr["ProductPhoto"].ToString(); 229
if (dr["InputTime"].ToString() != "") model.InputTime = Convert.ToDateTime( dr["InputTime"].ToString()); 230
if (dr["isHot"].ToString() != "") model.IsHot = Convert.ToInt32(dr["ishot"]); 231
232
if (dr["Deleted"].ToString() != "") model.Deleted = Convert.ToInt32( dr["Deleted"]); 233
if (dr["Inputer"].ToString() != "") model.Inputer = dr["Inputer"].ToString(); 234
if (dr["BuyTimes"].ToString() != "") model.BuyTimes = Convert.ToInt32( dr["BuyTimes"]); 235
236
if (dr["UpdateTime"].ToString() != "") model.UpdateTime = dr["UpdateTime"].ToString(); 237
if (dr["CreateTime"].ToString() != "") model.CreateTime = dr["CreateTime"].ToString(); 238
if (dr["Keywords"].ToString() != "") model.Keywords = dr["Keywords"].ToString(); 239
if (dr["CommentCount"].ToString() != "") model.CommentCount = Convert.ToInt32( dr["CommentCount"]); 240
if (dr["Weight"].ToString() != "") model.Weight = Convert.ToSingle( dr["Weight"]); 241
if (dr["Price_Market"].ToString() != "") model.Price_Market = Convert.ToDecimal( dr["Price_Market"]); 242
243
if (dr["OrderNum"].ToString()





}