温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyShop网络商城080617源码
当前文件:
MyShop080617/AccessDAL/OrderItem.cs,打开代码结构图
MyShop080617/AccessDAL/OrderItem.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 OrderItem :IOrderItem 11
...{ 12
private ConfigInfo configInfo = new ConfigInfo(); 13
private string tableName = "Ljh_OrderItems"; 14
15
public OrderItem() 16
...{ 17
if (!string.IsNullOrEmpty(configInfo.TablePrefix.Trim())) 18
tableName = configInfo.TablePrefix + "OrderItems"; 19
} 20
IOrderItem member#region IOrderItem member 21
22
23
/**//// <summary> 24
/// 添加记录 25
/// </summary> 26
/// <param name="model"></param> 27
/// <returns>返回ID, 如果发生错误则返回-1</returns> 28
public int Add(OrderItemInfo model) 29
...{ 30
if (model == null) 31
...{ 32
return -1; 33
} 34
string commandText = "insert into " + this.tableName + "(orderId,productId,saleType,priceOriginal,truePrice,amount,subTotal,beginDate,remark,presentExp,price) values(@orderId,@productId,@saleType,@priceOriginal,@truePrice,@amount,@subTotal,@beginDate,@remark,@presentExp,@price) "; 35
OleDbParameter[] commandParameters = ...{ 36
Database.MakeInParam("@OrderId",OleDbType.Integer,4,model.OrderId), 37
Database.MakeInParam("@ProductId",OleDbType.Integer,4,model.ProductId), 38
Database.MakeInParam("@SaleType",OleDbType.Integer,4,model.SaleType), 39
Database.MakeInParam("@PriceOriginal",OleDbType.Currency,4,model.PriceOriginal), 40
Database.MakeInParam("@TruePrice",OleDbType.Currency,4,model.TruePrice), 41
Database.MakeInParam("@Amount",OleDbType.Integer,4,model.Amount), 42
Database.MakeInParam("@SubTotal",OleDbType.Currency,8,model.SubTotal), 43
Database.MakeInParam("@BeginDate",OleDbType.Date,8,model.BeginDate), 44
Database.MakeInParam("@Remark",OleDbType.VarWChar,0,model.Remark), 45
Database.MakeInParam("@PresentExp",OleDbType.Integer,4,model.PresentExp), 46
Database.MakeInParam("@Price",OleDbType.Currency,8,model.Price) 47
}; 48
int intIdentity = -1; 49
try 50
...{ 51
Database.ExecuteNonQuery(CommandType.Text, out intIdentity, commandText, commandParameters); 52
} 53
catch (Exception exception) 54
...{ 55
throw exception; 56
} 57
return intIdentity; 58
} 59
60
61
62
63
64
65
/**//// <summary> 66
/// 删除 67
/// </summary> 68
/// <param name="filter">where后面的条件语句,不加where</param> 69
/// <returns>返回影响行数</returns> 70
public int Delete(string filter) 71
...{ 72
int count = -1; 73
string sql = @"delete from " + tableName; 74
if (!string.IsNullOrEmpty(filter.Trim())) 75
...{ 76
sql = sql + " where " + filter; 77
} 78
try 79
...{ 80
81
count = Database.ExecuteNonQuery(sql); 82
} 83
catch (Exception ex) 84
...{ 85
throw ex; 86
} 87
return count; 88
} 89
90
/**//// <summary> 91
/// 92
/// </summary> 93
/// <param name="filter"></param> 94
/// <returns></returns> 95
public bool Exist(string filter) 96
...{ 97
bool result = false; 98
string sql = @"select * from " + tableName; 99
if (!string.IsNullOrEmpty(filter)) 100
...{ 101
sql = sql + " where " + filter; 102
} 103
try 104
...{ 105
106
107
DataSet dataset = new DataSet(); 108
dataset = Database.ExecuteDataSet(sql); 109
if (dataset.Tables[0].Rows.Count > 0) 110
...{ 111
result = true; 112
} 113
} 114
catch (Exception ex) 115
...{ 116
throw ex; 117
} 118
return result; 119
} 120
121
/**//// <summary> 122
/// 返回所有 123
/// </summary> 124
/// <returns>返回所有</returns> 125
public DataSet GetDataSet() 126
...{ 127
string sql = "select * from " + tableName; 128
DataSet dataset = new DataSet(); 129
try 130
...{ 131
132
dataset = Database.ExecuteDataSet(sql); 133
134
} 135
catch (Exception ex) 136
...{ 137
throw ex; 138
} 139
return dataset; 140
} 141
142
public DataSet GetDataSet(string filter) 143
...{ 144
if (string.IsNullOrEmpty(filter)) 145
return null; 146
147
string sql = "select * from " + tableName + " where " + filter; 148
DataSet dataset = new DataSet(); 149
try 150
...{ 151
152
dataset = Database.ExecuteDataSet(sql); 153
} 154
catch (Exception ex) 155
...{ 156
throw ex; 157
} 158
return dataset; 159
} 160
161
/**//// <summary> 162
/// 163
/// </summary> 164
/// <param name="dr"></param> 165
/// <returns></returns> 166
public OrderItemInfo GetModel(DataRow dr) 167
...{ 168
if (dr == null) 169
return null; 170
OrderItemInfo model = new OrderItemInfo(); 171
172
if (dr["itemId"].ToString() != "") model.ItemId = Convert.ToInt32(dr["itemId"]); 173
if (dr["orderId"].ToString() != "") model.OrderId = Convert.ToInt32(dr["orderId"].ToString()); 174
if (dr["ProductId"].ToString() != "") model.ProductId = Convert.ToInt32(dr["ProductId"]); 175
if (dr["saleType"].ToString() != "") model.SaleType = Convert.ToInt32(dr["saleType"]); 176
if (dr["priceOriginal"].ToString() != "") model.PriceOriginal = Convert.ToDecimal(dr["priceOriginal"].ToString()); 177
if (dr["truePrice"].ToString() != "") model.TruePrice = Convert.ToInt32(dr["truePrice"]); 178
if (dr["amount"].ToString() != "") model.Amount = Convert.ToInt32(dr["amount"].ToString()); 179
if (dr["subTotal"].ToString() != "") model.SubTotal = Convert.ToDecimal(dr["subTotal"].ToString()); 180
if (dr["beginDate"].ToString() != "") model.BeginDate = dr["beginDate"].ToString(); 181
if (dr["Remark"].ToString() != "") model.Remark = dr["Remark"].ToString(); 182
if (dr["PresentExp"].ToString() != "") model.PresentExp = Convert.ToInt32(dr["PresentExp"]); 183
if (dr["price"].ToString() != "") model.Price = Convert.ToDecimal(dr["price"]); 184
185
186
return model; 187
} 188
189
/**//// <summary> 190
/// 191
/// </summary> 192
/// <param name="sql"></param> 193
/// <returns></returns> 194
public DataSet Query(string sql) 195
...{ 196
if (string.IsNullOrEmpty(sql)) 197
return null; 198
199
DataSet dataset = new DataSet(); 200
try 201
...{ 202
203
dataset = Database.ExecuteDataSet(sql); 204
} 205
catch (Exception ex) 206
...{ 207
throw ex; 208
} 209
return dataset; 210
} 211
212
213
/**//// <summary> 214
/// update 215
/// </summary> 216
/// <param name="model"></param> 217
/// <param name="filter"></param> 218
/// <returns></returns> 219
public int Update(OrderItemInfo model, string filter) 220
...{ 221
int result; 222
if (string.IsNullOrEmpty(filter)) 223
...{ 224
throw new Exception("The 'filter' can not be null!"); 225
} 226
string sql = @"update " + tableName + " set orderId=@orderId,ProductId=@ProductId,saleType=@saleType,priceOriginal=@priceOriginal,truePrice=@truePrice,amount=@amount,subTotal=@subTotal,beginDate=@beginDate,Remark=@Remark,PresentExp=@PresentExp,price=@price " + " where " + filter; 227
228
OleDbParameter[] prams = ...{ 229
Database.MakeInParam("@OrderId",OleDbType.Integer,4,model.OrderId), 230
Database.MakeInParam("@ProductId",OleDbType.Integer,4,model.ProductId), 231
Database.MakeInParam("@SaleType",OleDbType.Integer,4,model.SaleType), 232
Database.MakeInParam("@PriceOriginal",OleDbType.Currency,4,model.PriceOriginal), 233
Database.MakeInParam("@TruePrice",OleDbType.Currency,4,model.TruePrice), 234
Database.MakeInParam("@Amount",OleDbType.Integer,4,model.Amount), 235
Database.MakeInParam("@SubTotal",OleDbType.Currency,8,model.SubTotal), 236
Database.MakeInParam("@BeginDate",OleDbType.Date,8,model.BeginDate), 237
Database.MakeInParam("@Remark",OleDbType.VarWChar,0,model.Remark), 238
Database.MakeInParam("@PresentExp",OleDbType.Integer,4,model.PresentExp), 239
Database.MakeInParam("@Price",OleDbType.Currency,8,model.Price) 240
}; 241
242
try 243
...{ 244
245
result = Database.ExecuteNonQuery(sql, prams); 246
} 247
catch (Exception ex) 248
...{ 249
throw ex; 250
} 251
return result; 252
} 253
254
255
#endregion 256
257
SearchOrderItem#region SearchOrderItem 258
/**//// <summary> 259
/// 销售明细快速搜索 260
/// </summary> 261
/// <param name="searchType"></param> 262
/// <returns></returns> 263
public DataSet QuickSearch(int searchType) 264
...{ 265
OleDbParameter[] parameters = new OleDbParameter[] ...{ Database.MakeInParam("@type", OleDbType.Integer, 4, searchType) }; 266
DataSet set = new DataSet(); 267
string commandText = ""; 268
switch (searchType) 269





}