温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyShop网络商城080617源码
当前文件:
MyShop080617/AccessDAL/ProductKinds.cs,打开代码结构图
MyShop080617/AccessDAL/ProductKinds.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
11
public class ProductKinds : IProductKinds 12
...{ 13
14
private ConfigInfo configInfo = new ConfigInfo(); 15
private string tableName = "Ljh_ProductKinds"; 16
17
public ProductKinds() 18
...{ 19
if (!string.IsNullOrEmpty(configInfo.TablePrefix.Trim())) 20
tableName = configInfo.TablePrefix + "ProductKinds"; 21
} 22
23
IProductKinds member#region IProductKinds member 24
25
/**//// <summary> 26
/// 27
/// </summary> 28
/// <param name="model"></param> 29
/// <returns>返回ID, 如果发生错误则返回-1</returns> 30
public int Add(ProductKindsInfo model) 31
...{ 32
if (model == null) 33
...{ 34
return 0; 35
} 36
string commandText = "insert into " + this.tableName + "(ProductKindName,productKindIntro,IsDisabled,OrderId) values(@ProductKindName,@productKindIntro,@IsDisabled,@OrderId) "; 37
OleDbParameter[] commandParameters =...{ 38
Database.MakeInParam("@ProductKindName",OleDbType.VarWChar,50,model.ProductKindName), 39
Database.MakeInParam("@ProductKindIntro",OleDbType.VarWChar,255,model.ProductKindIntro), 40
Database.MakeInParam("@IsDisabled",OleDbType.UnsignedTinyInt,1,model.IsDisabled), 41
Database.MakeInParam("@OrderId",OleDbType.Integer,4,model.OrderId) 42
}; 43
44
int intIdentity = -1; 45
try 46
...{ 47
Database.ExecuteNonQuery(CommandType.Text, out intIdentity, commandText, commandParameters); 48
} 49
catch (Exception exception) 50
...{ 51
throw exception; 52
} 53
return intIdentity; 54
} 55
56
57
58
59
/**//// <summary> 60
/// 删除购物车项目 61
/// </summary> 62
/// <param name="filter">where后面的条件语句,不加where</param> 63
/// <returns>返回影响行数</returns> 64
public int Delete(string filter) 65
...{ 66
int count = -1; 67
string sql = @"delete from " + tableName; 68
if (!string.IsNullOrEmpty(filter.Trim())) 69
...{ 70
sql = sql + " where " + filter; 71
} 72
try 73
...{ 74
75
count = Database.ExecuteNonQuery(sql); 76
} 77
catch (Exception ex) 78
...{ 79
throw ex; 80
} 81
return count; 82
} 83
84
/**//// <summary> 85
/// 判断购物车项目是否存在 86
/// </summary> 87
/// <param name="filter"></param> 88
/// <returns></returns> 89
public bool Exist(string filter) 90
...{ 91
bool result = false; 92
string sql = @"select * from " + tableName; 93
if (!string.IsNullOrEmpty(filter.Trim())) 94
...{ 95
sql = sql + " where " + filter; 96
} 97
try 98
...{ 99
100
101
DataSet dataset = new DataSet(); 102
dataset = Database.ExecuteDataSet(sql); 103
if (dataset.Tables[0].Rows.Count > 0) 104
...{ 105
result = true; 106
} 107
} 108
catch (Exception ex) 109
...{ 110
throw ex; 111
} 112
return result; 113
} 114
115
/**//// <summary> 116
/// 返回所有购物车项目 117
/// </summary> 118
/// <returns>返回所有购物车项目</returns> 119
public DataSet GetDataSet() 120
...{ 121
string sql = "select * from " + tableName; 122
DataSet dataset = new DataSet(); 123
try 124
...{ 125
126
dataset = Database.ExecuteDataSet(sql); 127
128
} 129
catch (Exception ex) 130
...{ 131
throw ex; 132
} 133
return dataset; 134
} 135
136
137
/**//// <summary> 138
/// 139
/// </summary> 140
/// <param name="filter"></param> 141
/// <returns></returns> 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
162
/**//// <summary> 163
/// 164
/// </summary> 165
/// <param name="dr"></param> 166
/// <returns></returns> 167
public ProductKindsInfo GetModel(DataRow dr) 168
...{ 169
if (dr == null) 170
return null; 171
ProductKindsInfo model = new ProductKindsInfo(); 172
173
if (dr["ProductKindId"].ToString() != "") 174
model.ProductKindId = Convert.ToInt32(dr["ProductKindId"]); 175
if (dr["ProductKindName"].ToString() != "") 176
model.ProductKindName =dr["ProductKindName"].ToString(); 177
if (dr["ProductKindIntro"].ToString() != "") 178
model.ProductKindIntro = dr["ProductKindIntro"].ToString(); 179
180
if (dr["OrderID"].ToString() != "") model.OrderId = Convert.ToInt32( dr["OrderID"]); 181
if (dr["IsDisabled"].ToString() != "") model.IsDisabled = Convert.ToInt32( dr["IsDisabled"]); 182
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(ProductKindsInfo 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 ProductKindName=@ProductKindName,ProductKindIntro=@ProductKindIntro,IsDisabled=@IsDisabled,OrderId=@OrderId " + " where " + filter; 224
OleDbParameter[] prams = 225
...{ 226
Database.MakeInParam("@ProductKindName",OleDbType.VarWChar,50,model.ProductKindName), 227
Database.MakeInParam("@ProductKindIntro",OleDbType.VarWChar,255,model.ProductKindIntro), 228
Database.MakeInParam("@IsDisabled",OleDbType.UnsignedTinyInt,1,model.IsDisabled), 229
Database.MakeInParam("@OrderId",OleDbType.Integer,4,model.OrderId) 230
}; 231
232
try 233
...{ 234
235
result = Database.ExecuteNonQuery(sql, prams); 236
} 237
catch (Exception ex) 238
...{ 239
throw ex; 240
} 241
return result; 242
} 243
244
#endregion 245
} 246
} 247





}
}