温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyShop网络商城080617源码
当前文件:
MyShop080617/AccessDAL/PaymentType.cs,打开代码结构图
MyShop080617/AccessDAL/PaymentType.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Data.OleDb; 4
using MyShop.IDAL; 5
using MyShop.Model; 6
namespace MyShop.AccessDAL 7
...{ 8
public class PaymentType :IPaymentType 9
...{ 10
11
private ConfigInfo configInfo = new ConfigInfo(); 12
private string tableName = "PaymentType"; 13
14
public PaymentType() 15
...{ 16
if (!string.IsNullOrEmpty(configInfo.TablePrefix.Trim())) 17
tableName = configInfo.TablePrefix + "PaymentType"; 18
} 19
20
IPaymentType member#region IPaymentType member 21
22
23
/**//// <summary> 24
/// add PaymentType 25
/// </summary> 26
/// <param name="model"></param> 27
/// <returns>返回ID, 如果发生错误则返回-1</returns> 28
public int Add(PaymentTypeInfo model) 29
...{ 30
if (model == null) 31
...{ 32
return 0; 33
} 34
string commandText = "insert into " + this.tableName + "(typeName,intro,discount,isDefault,orderId,isDisabled) values(@typeName,@intro,@discount,@isDefault,@orderId,@isDisabled) "; 35
OleDbParameter[] commandParameters = ...{ 36
Database.MakeInParam("@TypeName",OleDbType.VarWChar,50,model.TypeName), 37
Database.MakeInParam("@Intro",OleDbType.VarWChar,50,model.Intro), 38
Database.MakeInParam("@Discount",OleDbType.Double,8,model.Discount), 39
Database.MakeInParam("@IsDefault",OleDbType.UnsignedTinyInt,1,model.IsDefault), 40
Database.MakeInParam("@OrderId",OleDbType.Integer,4,model.OrderId), 41
Database.MakeInParam("@IsDisabled",OleDbType.UnsignedTinyInt,1,model.IsDisabled) 42
}; 43
int intIdentity = -1; 44
try 45
...{ 46
Database.ExecuteNonQuery(CommandType.Text, out intIdentity, commandText, commandParameters); 47
} 48
catch (Exception exception) 49
...{ 50
throw exception; 51
} 52
return intIdentity; 53
} 54
55
56
57
58
59
60
/**//// <summary> 61
/// 删除会员 62
/// </summary> 63
/// <param name="filter">where后面的条件语句,不加where</param> 64
/// <returns>返回影响行数</returns> 65
public int Delete(string filter) 66
...{ 67
int count = -1; 68
string sql = @"delete from " + tableName; 69
if (!string.IsNullOrEmpty(filter.Trim())) 70
...{ 71
sql = sql + " where " + filter; 72
} 73
try 74
...{ 75
76
count = Database.ExecuteNonQuery(sql); 77
} 78
catch (Exception ex) 79
...{ 80
throw ex; 81
} 82
return count; 83
} 84
85
/**//// <summary> 86
/// 87
/// </summary> 88
/// <param name="filter"></param> 89
/// <returns></returns> 90
public bool Exist(string filter) 91
...{ 92
bool result = false; 93
string sql = @"select * from " + tableName; 94
if (!string.IsNullOrEmpty(filter)) 95
...{ 96
sql = sql + " where " + filter; 97
} 98
try 99
...{ 100
101
102
DataSet dataset = new DataSet(); 103
dataset = Database.ExecuteDataSet(sql); 104
if (dataset.Tables[0].Rows.Count > 0) 105
...{ 106
result = true; 107
} 108
} 109
catch (Exception ex) 110
...{ 111
throw ex; 112
} 113
return result; 114
} 115
116
/**//// <summary> 117
/// 返回所有产品 118
/// </summary> 119
/// <returns>返回所有产品</returns> 120
public DataSet GetDataSet() 121
...{ 122
string sql = "select * from " + tableName; 123
DataSet dataset = new DataSet(); 124
try 125
...{ 126
127
dataset = Database.ExecuteDataSet(sql); 128
129
} 130
catch (Exception ex) 131
...{ 132
throw ex; 133
} 134
return dataset; 135
} 136
137
public DataSet GetDataSet(string filter) 138
...{ 139
if (string.IsNullOrEmpty(filter)) 140
return null; 141
142
string sql = "select * from " + tableName + " where " + filter; 143
DataSet dataset = new DataSet(); 144
try 145
...{ 146
147
dataset = Database.ExecuteDataSet(sql); 148
} 149
catch (Exception ex) 150
...{ 151
throw ex; 152
} 153
return dataset; 154
} 155
156
/**//// <summary> 157
/// 158
/// </summary> 159
/// <param name="dr"></param> 160
/// <returns></returns> 161
public PaymentTypeInfo GetModel(DataRow dr) 162
...{ 163
if (dr == null) 164
return null; 165
PaymentTypeInfo model = new PaymentTypeInfo(); 166
167
if (dr["typeId"].ToString() != "") model.TypeId = Convert.ToInt32( dr["typeId"]); 168
if (dr["typeName"].ToString() != "") model.TypeName = dr["typeName"].ToString(); 169
if (dr["intro"].ToString() != "") model.Intro = dr["intro"].ToString(); 170
if (dr["discount"].ToString() != "") model.Discount = Convert.ToInt32( dr["discount"]); 171
if (dr["isDefault"].ToString() != "") model.IsDefault = Convert.ToInt32( dr["isDefault"]); 172
if (dr["orderId"].ToString() != "") model.OrderId = Convert.ToInt32( dr["orderId"]); 173
if (dr["isDisabled"].ToString() != "") model.IsDisabled = Convert.ToInt32( dr["isDisabled"]); 174
175
return model; 176
} 177
178
/**//// <summary> 179
/// 180
/// </summary> 181
/// <param name="sql"></param> 182
/// <returns></returns> 183
public DataSet Query(string sql) 184
...{ 185
if (string.IsNullOrEmpty(sql)) 186
return null; 187
188
DataSet dataset = new DataSet(); 189
try 190
...{ 191
192
dataset = Database.ExecuteDataSet(sql); 193
} 194
catch (Exception ex) 195
...{ 196
throw ex; 197
} 198
return dataset; 199
} 200
201
202
/**//// <summary> 203
/// update Product 204
/// </summary> 205
/// <param name="model"></param> 206
/// <param name="filter"></param> 207
/// <returns></returns> 208
public int Update(PaymentTypeInfo model, string filter) 209
...{ 210
int result; 211
if (string.IsNullOrEmpty(filter)) 212
...{ 213
throw new Exception("The 'filter' can not be null!"); 214
} 215
string sql = @"update " + tableName + " set typeName=@typeName,intro=@intro,discount=@discount,isDefault=@isDefault,orderId=@orderId,isDisabled=@isDisabled " + " where " + filter; 216
217
OleDbParameter[] prams = ...{ 218
Database.MakeInParam("@TypeName",OleDbType.VarWChar,50,model.TypeName), 219
Database.MakeInParam("@Intro",OleDbType.VarWChar,50,model.Intro), 220
Database.MakeInParam("@Discount",OleDbType.Double,8,model.Discount), 221
Database.MakeInParam("@IsDefault",OleDbType.UnsignedTinyInt,1,model.IsDefault), 222
Database.MakeInParam("@OrderId",OleDbType.Integer,4,model.OrderId), 223
Database.MakeInParam("@IsDisabled",OleDbType.UnsignedTinyInt,1,model.IsDisabled) 224
}; 225
try 226
...{ 227
228
result = Database.ExecuteNonQuery(sql, prams); 229
} 230
catch (Exception ex) 231
...{ 232
throw ex; 233
} 234
return result; 235
} 236
237
#endregion 238
} 239
} 240





}
}