1
using 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.SQLServerDAL
9
...{
10
public class AboutUs : IAboutUs
11
...{
12
13
private ConfigInfo configInfo = new ConfigInfo();
14
private string tableName = "Ljh_AboutUs";
15
16
public AboutUs()
17
...{
18
if (!string.IsNullOrEmpty(configInfo.TablePrefix.Trim()))
19
tableName = configInfo.TablePrefix + "AboutUs";
20
}
21
22
IAboutUs member#region IAboutUs member
23
24
25
/**//// <summary>
26
/// add
27
/// </summary>
28
/// <param name="model"></param>
29
/// <returns>返回ID, 如果发生错误则返回-1</returns>
30
public int Add(AboutUsInfo model)
31
...{
32
int result;
33
if (model == null)
34
...{
35
return -1;
36
}
37
string sql = @"insert into " + tableName + "(Title,Content,OrderID) " +
38
" values(@Title,@Content,@OrderID)" + " ;SELECT @@IDENTITY ";
39
40
SqlParameter[] prams = ...{
41
Database.MakeInParam("@Title", OleDbType.VarWChar, 0 ,model.Title),
42
Database.MakeInParam("@Content", OleDbType.VarWChar, 50 ,model.Content),
43
Database.MakeInParam("@OrderID", OleDbType.Integer, 4 ,model.OrderID)
44
};
45
46
47
try
48
...{
49
50
result = (Convert.ToInt32(Database.ExecuteDataSet(sql, prams).Tables[0].Rows[0][0]));
51
}
52
catch
53
...{
54
result = -1;
55
}
56
return result;
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 AboutUsInfo GetModel(DataRow dr)
161
...{
162
if (dr == null)
163
return null;
164
AboutUsInfo model = new AboutUsInfo();
165
166
if (dr["TitleID"].ToString() != "") model.TitleID = Convert.ToInt32( dr["TitleID"]);
167
if (dr["Title"].ToString() != "") model.Title = dr["Title"].ToString();
168
if (dr["Content"].ToString() != "") model.Content = dr["Content"].ToString();
169
if (dr["OrderID"].ToString() != "") model.OrderID = Convert.ToInt32( dr["OrderID"]);
170
171
172
173
return model;
174
}
175
176
/**//// <summary>
177
///
178
/// </summary>
179
/// <param name="sql"></param>
180
/// <returns></returns>
181
public DataSet Query(string sql)
182
...{
183
if (string.IsNullOrEmpty(sql))
184
return null;
185
186
DataSet dataset = new DataSet();
187
try
188
...{
189
190
dataset = Database.ExecuteDataSet(sql);
191
}
192
catch (Exception ex)
193
...{
194
throw ex;
195
}
196
return dataset;
197
}
198
199
200
/**//// <summary>
201
/// update
202
/// </summary>
203
/// <param name="model"></param>
204
/// <param name="filter"></param>
205
/// <returns></returns>
206
public int Update(AboutUsInfo model, string filter)
207
...{
208
int result;
209
if (string.IsNullOrEmpty(filter))
210
...{
211
throw new Exception("The 'filter' can not be null!");
212
}
213
string sql = @"update " + tableName + " set Title=@Title,Content=@Content,OrderID=@OrderID " + " where " + filter;
214
215
216
SqlParameter[] prams = ...{
217
Database.MakeInParam("@Title", OleDbType.VarWChar, 0 ,model.Title),
218
Database.MakeInParam("@Content", OleDbType.VarWChar, 50 ,model.Content),
219
Database.MakeInParam("@OrderID", OleDbType.Integer, 4 ,model.OrderID)
220
};
221
222
try
223
...{
224
225
result = Database.ExecuteNonQuery(sql, prams);
226
}
227
catch (Exception ex)
228
...{
229
throw ex;
230
}
231
return result;
232
}
233
234
235
#endregion
236
}
237
}
238