温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyShop网络商城080617源码
当前文件:
MyShop080617/AccessDAL/Cart.cs,打开代码结构图
MyShop080617/AccessDAL/Cart.cs,打开代码结构图1using System; 2
using System.Collections.Generic; 3
4
using System.Data; 5
using System.Data.OleDb; 6
using MyShop.IDAL; 7
using MyShop.Model; 8
namespace MyShop.AccessDAL 9
...{ 10
public class Cart: ICart 11
...{ 12
private ConfigInfo configInfo = new ConfigInfo(); 13
private string tableName = "Ljh_Cart"; 14
public Cart() 15
...{ 16
if (!string.IsNullOrEmpty(configInfo.TablePrefix.Trim())) 17
tableName = configInfo.TablePrefix + "Cart"; 18
} 19
20
ICart 成员#region ICart 成员 21
22
/**//// <summary> 23
/// 24
/// </summary> 25
/// <param name="model"></param> 26
/// <returns>返回ID, 如果发生错误则返回-1</returns> 27
public int Add(CartInfo model) 28
...{ 29
if (model == null) 30
...{ 31
return 0; 32
} 33
string commandText = "insert into " + this.tableName + "(productId,cartId,quantity,updateTime,subtotal,presentId) values(@productId,@cartId,@quantity,@updateTime,@subtotal,@presentId) "; 34
OleDbParameter[] commandParameters = ...{ 35
Database.MakeInParam("@ProductId", OleDbType.Integer,4,model.ProductId), 36
Database.MakeInParam("@CartId", OleDbType.VarWChar,50,model.CartId), 37
Database.MakeInParam("@Quantity", OleDbType.Integer,4,model.Quantity), 38
Database.MakeInParam("@UpdateTime", OleDbType.Date,8,model.UpdateTime), 39
Database.MakeInParam("@Subtotal", OleDbType.Currency,8,model.Subtotal), 40
Database.MakeInParam("@PresentId", OleDbType.Integer,4,model.PresentId) 41
}; 42
int intIdentity = -1; 43
try 44
...{ 45
Database.ExecuteNonQuery(CommandType.Text, out intIdentity, commandText, commandParameters); 46
} 47
catch (Exception exception) 48
...{ 49
throw exception; 50
} 51
return intIdentity; 52
} 53
54
55
/**//// <summary> 56
/// 删除购物车项目 57
/// </summary> 58
/// <param name="filter">where后面的条件语句,不加where</param> 59
/// <returns>返回影响行数</returns> 60
public int Delete(string filter) 61
...{ 62
int count = -1; 63
string sql = @"delete from " + tableName; 64
if (!string.IsNullOrEmpty(filter.Trim())) 65
...{ 66
sql = sql + " where " + filter; 67
} 68
try 69
...{ 70
71
count = Database.ExecuteNonQuery(sql); 72
} 73
catch (Exception ex) 74
...{ 75
throw ex; 76
} 77
return count; 78
} 79
80
/**//// <summary> 81
/// 判断购物车项目是否存在 82
/// </summary> 83
/// <param name="filter"></param> 84
/// <returns></returns> 85
public bool Exist(string filter) 86
...{ 87
bool result = false; 88
string sql = @"select * from " + tableName; 89
if (!string.IsNullOrEmpty(filter.Trim())) 90
...{ 91
sql = sql + " where " + filter; 92
} 93
try 94
...{ 95
96
97
DataSet dataset = new DataSet(); 98
dataset = Database.ExecuteDataSet(sql); 99
if (dataset.Tables[0].Rows.Count > 0) 100
...{ 101
result = true; 102
} 103
} 104
catch (Exception ex) 105
...{ 106
throw ex; 107
} 108
return result; 109
} 110
111
/**//// <summary> 112
/// 返回所有购物车项目 113
/// </summary> 114
/// <returns>返回所有购物车项目</returns> 115
public DataSet GetDataSet() 116
...{ 117
string sql = "select * from " + tableName; 118
DataSet dataset = new DataSet(); 119
try 120
...{ 121
122
dataset = Database.ExecuteDataSet(sql); 123
124
} 125
catch (Exception ex) 126
...{ 127
throw ex; 128
} 129
return dataset; 130
} 131
132
133
/**//// <summary> 134
/// 135
/// </summary> 136
/// <param name="filter"></param> 137
/// <returns></returns> 138
public DataSet GetDataSet(string filter) 139
...{ 140
if (string.IsNullOrEmpty(filter)) 141
return null; 142
143
string sql = "select * from " + tableName + " where " + filter; 144
DataSet dataset = new DataSet(); 145
try 146
...{ 147
148
dataset = Database.ExecuteDataSet(sql); 149
} 150
catch (Exception ex) 151
...{ 152
throw ex; 153
} 154
return dataset; 155
} 156
157
158
/**//// <summary> 159
/// 160
/// </summary> 161
/// <param name="dr"></param> 162
/// <returns></returns> 163
public CartInfo GetModel(DataRow dr) 164
...{ 165
if (dr == null) 166
return null; 167
CartInfo model = new CartInfo(); 168
169
if (dr["cartItemId"].ToString() != "") 170
model.CartItemId = Convert.ToInt32(dr["cartItemId"]); 171
if (dr["ProductId"].ToString() != "") 172
model.ProductId = Convert.ToInt32(dr["ProductId"]); 173
if (dr["cartId"].ToString() != "") 174
model.CartId = dr["cartId"].ToString() ; 175
if (dr["quantity"].ToString() != "") 176
model.Quantity = Convert.ToInt32( dr["quantity"].ToString()); 177
if (dr["UpdateTime"].ToString() != "") 178
model.UpdateTime = dr["UpdateTime"].ToString(); 179
if (dr["subtotal"].ToString() != "") 180
model.Subtotal = Convert.ToDecimal( dr["subtotal"].ToString() ); 181
if (dr["presentId"].ToString() != "") 182
model.PresentId = Convert.ToInt32(dr["presentId"].ToString()); 183
return model; 184
} 185
186
/**//// <summary> 187
/// 188
/// </summary> 189
/// <param name="sql"></param> 190
/// <returns></returns> 191
public DataSet Query(string sql) 192
...{ 193
if (string.IsNullOrEmpty(sql)) 194
return null; 195
196
DataSet dataset = new DataSet(); 197
try 198
...{ 199
200
dataset = Database.ExecuteDataSet(sql); 201
} 202
catch (Exception ex) 203
...{ 204
throw ex; 205
} 206
return dataset; 207
} 208
209
210
/**//// <summary> 211
/// 212
/// </summary> 213
/// <param name="model"></param> 214
/// <param name="filter"></param> 215
/// <returns></returns> 216
public int Update(CartInfo model, string filter) 217
...{ 218
int result; 219
if (string.IsNullOrEmpty(filter)) 220
...{ 221
throw new Exception("The 'filter' can not be null!"); 222
} 223
string sql = @"update " + tableName + " set ProductId=@ProductId,cartId=@cartId,quantity=@quantity,UpdateTime=@UpdateTime,subtotal=@subtotal,presentId=@presentId " + " where " + filter; 224
OleDbParameter[] prams = ...{ 225
Database.MakeInParam("@ProductId", OleDbType.Integer,4,model.ProductId), 226
Database.MakeInParam("@CartId", OleDbType.VarWChar,50,model.CartId), 227
Database.MakeInParam("@Quantity", OleDbType.Integer,4,model.Quantity), 228
Database.MakeInParam("@UpdateTime", OleDbType.Date,8,model.UpdateTime), 229
Database.MakeInParam("@Subtotal", OleDbType.Currency,8,model.Subtotal), 230
Database.MakeInParam("@PresentId", OleDbType.Integer,4,model.PresentId) 231
}; 232
233
try 234
...{ 235
236
result = Database.ExecuteNonQuery(sql, prams); 237
} 238
catch (Exception ex) 239
...{ 240
throw ex; 241
} 242
return result; 243
} 244
245
246
#endregion 247
248
后台管理#region 后台管理 249
250
/**//// <summary> 251
/// 快速搜索 252
/// </summary> 253
/// <param name="searchType"></param> 254
/// <returns></returns> 255
public DataSet QuickSearch(int searchType) 256
...{ 257
DataSet set = new DataSet(); 258
string sql = ""; 259
switch (searchType) 260
...{ 261
case 1: 262
sql = " Select * From " + this.tableName + " Where DateDiff('d',updateTime,now())=0 order by [CartId] Desc "; 263
break; 264
265
case 2: 266
sql = " Select * From " + this.tableName + " Where DateDiff('ww',updateTime,now()) =0 order by [CartId] Desc "; 267
break; 268
269
case 3: 270
sql = " Select * From " + this.tableName + " Where DateDiff('m',updateTime,now()) =0 order by [CartId] Desc "; 271
break; 272
273
default: 274
sql = " Select * From [" + this.configInfo.TablePrefix + "Cart] order by [CartId] Desc "; 275
break; 276
} 277
return this.Query(sql); 278
} 279
280
public int Admin_Shop_Cart_Delete(int type) 281





}