温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyShop网络商城080617源码
当前文件:
MyShop080617/AccessDAL/Help.cs,打开代码结构图
MyShop080617/AccessDAL/Help.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 Help : IHelp 11
...{ 12
13
private ConfigInfo configInfo = new ConfigInfo(); 14
private string tableName = "Ljh_Help"; 15
16
public Help() 17
...{ 18
if (!string.IsNullOrEmpty(configInfo.TablePrefix.Trim())) 19
tableName = configInfo.TablePrefix + "Help"; 20
} 21
22
IArticle member#region IArticle member 23
24
25
/**//// <summary> 26
/// add 27
/// </summary> 28
/// <param name="model"></param> 29
/// <returns>返回ID, 如果发生错误则返回-1</returns> 30
public int Add(HelpInfo model) 31
...{ 32
if (model == null) 33
...{ 34
return -1; 35
} 36
string commandText = "insert into " + this.tableName + "(Title,Inputer,InputTime,Content) values(@Title,@Inputer,@InputTime,@Content) "; 37
OleDbParameter[] commandParameters = ...{ 38
Database.MakeInParam("@Title", OleDbType.VarWChar , 255 ,model.Title ), 39
Database.MakeInParam("@Inputer", OleDbType.VarWChar , 20 ,model.Inputer ), 40
Database.MakeInParam("@InputTime", OleDbType.Date , 8 ,model.InputTime ), 41
Database.MakeInParam("@Content", OleDbType.VarWChar,0,model.Content), 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
/**//// <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)) 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
public DataSet GetDataSet(string filter) 137
...{ 138
if (string.IsNullOrEmpty(filter)) 139
return null; 140
141
string sql = "select * from " + tableName + " where " + filter; 142
DataSet dataset = new DataSet(); 143
try 144
...{ 145
146
dataset = Database.ExecuteDataSet(sql); 147
} 148
catch (Exception ex) 149
...{ 150
throw ex; 151
} 152
return dataset; 153
} 154
155
/**//// <summary> 156
/// 157
/// </summary> 158
/// <param name="dr"></param> 159
/// <returns></returns> 160
public HelpInfo GetModel(DataRow dr) 161
...{ 162
if (dr == null) 163
return null; 164
HelpInfo model = new HelpInfo(); 165
166
if (dr["ArticleID"].ToString() != "") model.ArticleID = Convert.ToInt32(dr["ArticleID"]); 167
if (dr["Title"].ToString() != "") model.Title = dr["Title"].ToString(); 168
if (dr["Inputer"].ToString() != "") model.Inputer = dr["Inputer"].ToString(); 169
if (dr["InputTime"].ToString() != "") model.InputTime = dr["InputTime"].ToString(); 170
if (dr["Content"].ToString() != "") model.Content = dr["Content"].ToString(); 171
172
return model; 173
} 174
175
/**//// <summary> 176
/// 177
/// </summary> 178
/// <param name="sql"></param> 179
/// <returns></returns> 180
public DataSet Query(string sql) 181
...{ 182
if (string.IsNullOrEmpty(sql)) 183
return null; 184
185
DataSet dataset = new DataSet(); 186
try 187
...{ 188
189
dataset = Database.ExecuteDataSet(sql); 190
} 191
catch (Exception ex) 192
...{ 193
throw ex; 194
} 195
return dataset; 196
} 197
198
199
/**//// <summary> 200
/// update 201
/// </summary> 202
/// <param name="model"></param> 203
/// <param name="filter"></param> 204
/// <returns></returns> 205
public int Update(HelpInfo model, string filter) 206
...{ 207
int result; 208
if (string.IsNullOrEmpty(filter)) 209
...{ 210
throw new Exception("The 'filter' can not be null!"); 211
} 212
string sql = @"update " + tableName + " set Title=@Title,Inputer=@Inputer,InputTime=@InputTime,Content=@Content " + " where " + filter; 213
214
215
OleDbParameter[] prams = ...{ 216
Database.MakeInParam("@Title", OleDbType.VarWChar , 255 ,model.Title ), 217
Database.MakeInParam("@Inputer", OleDbType.VarWChar , 20 ,model.Inputer ), 218
Database.MakeInParam("@InputTime", OleDbType.Date , 8 ,model.InputTime ), 219
Database.MakeInParam("@Content", OleDbType.VarWChar,0,model.Content), 220
}; 221
222
223
try 224
...{ 225
226
result = Database.ExecuteNonQuery(sql, prams); 227
} 228
catch (Exception ex) 229
...{ 230
throw ex; 231
} 232
return result; 233
} 234
235
236
#endregion 237
238
239
} 240
} 241





}
}