|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+using CallCenterApi.DB;
|
|
|
2
|
+using System;
|
|
|
3
|
+using System.Collections.Generic;
|
|
|
4
|
+using System.Data;
|
|
|
5
|
+using System.Data.SqlClient;
|
|
|
6
|
+using System.Linq;
|
|
|
7
|
+using System.Text;
|
|
|
8
|
+using System.Threading.Tasks;
|
|
|
9
|
+
|
|
|
10
|
+namespace CallCenterApi.DAL
|
|
|
11
|
+{
|
|
|
12
|
+ public partial class T_Sys_Address
|
|
|
13
|
+ {
|
|
|
14
|
+ public T_Sys_Address()
|
|
|
15
|
+ { }
|
|
|
16
|
+ #region BasicMethod
|
|
|
17
|
+
|
|
|
18
|
+ /// <summary>
|
|
|
19
|
+ /// 得到最大ID
|
|
|
20
|
+ /// </summary>
|
|
|
21
|
+ public int GetMaxId()
|
|
|
22
|
+ {
|
|
|
23
|
+ return DbHelperSQL.GetMaxID("ID", "T_Sys_Address");
|
|
|
24
|
+ }
|
|
|
25
|
+
|
|
|
26
|
+ /// <summary>
|
|
|
27
|
+ /// 是否存在该记录
|
|
|
28
|
+ /// </summary>
|
|
|
29
|
+ public bool Exists(int ID, string Code)
|
|
|
30
|
+ {
|
|
|
31
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
32
|
+ strSql.Append("select count(1) from T_Sys_Address");
|
|
|
33
|
+ strSql.Append(" where ID=@ID and Code=@Code ");
|
|
|
34
|
+ SqlParameter[] parameters = {
|
|
|
35
|
+ new SqlParameter("@ID", SqlDbType.Int,4),
|
|
|
36
|
+ new SqlParameter("@Code", SqlDbType.NVarChar,160) };
|
|
|
37
|
+ parameters[0].Value = ID;
|
|
|
38
|
+ parameters[1].Value = Code;
|
|
|
39
|
+
|
|
|
40
|
+ return DbHelperSQL.Exists(strSql.ToString(), parameters);
|
|
|
41
|
+ }
|
|
|
42
|
+
|
|
|
43
|
+
|
|
|
44
|
+ /// <summary>
|
|
|
45
|
+ /// 增加一条数据
|
|
|
46
|
+ /// </summary>
|
|
|
47
|
+ public bool Add(Model.T_Sys_Address model)
|
|
|
48
|
+ {
|
|
|
49
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
50
|
+ strSql.Append("insert into T_Sys_Address(");
|
|
|
51
|
+ strSql.Append("ID,Code,Parent_Code,Name,Short_Name,Lng,Lat,Sort)");
|
|
|
52
|
+ strSql.Append(" values (");
|
|
|
53
|
+ strSql.Append("@ID,@Code,@Parent_Code,@Name,@Short_Name,@Lng,@Lat,@Sort)");
|
|
|
54
|
+ SqlParameter[] parameters = {
|
|
|
55
|
+ new SqlParameter("@ID", SqlDbType.Int,4),
|
|
|
56
|
+ new SqlParameter("@Code", SqlDbType.NVarChar,160),
|
|
|
57
|
+ new SqlParameter("@Parent_Code", SqlDbType.NVarChar,160),
|
|
|
58
|
+ new SqlParameter("@Name", SqlDbType.NVarChar,200),
|
|
|
59
|
+ new SqlParameter("@Short_Name", SqlDbType.NVarChar,80),
|
|
|
60
|
+ new SqlParameter("@Lng", SqlDbType.NVarChar,80),
|
|
|
61
|
+ new SqlParameter("@Lat", SqlDbType.NVarChar,80),
|
|
|
62
|
+ new SqlParameter("@Sort", SqlDbType.Int,4)};
|
|
|
63
|
+ parameters[0].Value = model.ID;
|
|
|
64
|
+ parameters[1].Value = model.Code;
|
|
|
65
|
+ parameters[2].Value = model.Parent_Code;
|
|
|
66
|
+ parameters[3].Value = model.Name;
|
|
|
67
|
+ parameters[4].Value = model.Short_Name;
|
|
|
68
|
+ parameters[5].Value = model.Lng;
|
|
|
69
|
+ parameters[6].Value = model.Lat;
|
|
|
70
|
+ parameters[7].Value = model.Sort;
|
|
|
71
|
+
|
|
|
72
|
+ int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
|
|
|
73
|
+ if (rows > 0)
|
|
|
74
|
+ {
|
|
|
75
|
+ return true;
|
|
|
76
|
+ }
|
|
|
77
|
+ else
|
|
|
78
|
+ {
|
|
|
79
|
+ return false;
|
|
|
80
|
+ }
|
|
|
81
|
+ }
|
|
|
82
|
+ /// <summary>
|
|
|
83
|
+ /// 更新一条数据
|
|
|
84
|
+ /// </summary>
|
|
|
85
|
+ public bool Update(Model.T_Sys_Address model)
|
|
|
86
|
+ {
|
|
|
87
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
88
|
+ strSql.Append("update T_Sys_Address set ");
|
|
|
89
|
+ strSql.Append("Parent_Code=@Parent_Code,");
|
|
|
90
|
+ strSql.Append("Name=@Name,");
|
|
|
91
|
+ strSql.Append("Short_Name=@Short_Name,");
|
|
|
92
|
+ strSql.Append("Lng=@Lng,");
|
|
|
93
|
+ strSql.Append("Lat=@Lat,");
|
|
|
94
|
+ strSql.Append("Sort=@Sort");
|
|
|
95
|
+ strSql.Append(" where ID=@ID and Code=@Code ");
|
|
|
96
|
+ SqlParameter[] parameters = {
|
|
|
97
|
+ new SqlParameter("@Parent_Code", SqlDbType.NVarChar,160),
|
|
|
98
|
+ new SqlParameter("@Name", SqlDbType.NVarChar,200),
|
|
|
99
|
+ new SqlParameter("@Short_Name", SqlDbType.NVarChar,80),
|
|
|
100
|
+ new SqlParameter("@Lng", SqlDbType.NVarChar,80),
|
|
|
101
|
+ new SqlParameter("@Lat", SqlDbType.NVarChar,80),
|
|
|
102
|
+ new SqlParameter("@Sort", SqlDbType.Int,4),
|
|
|
103
|
+ new SqlParameter("@ID", SqlDbType.Int,4),
|
|
|
104
|
+ new SqlParameter("@Code", SqlDbType.NVarChar,160)};
|
|
|
105
|
+ parameters[0].Value = model.Parent_Code;
|
|
|
106
|
+ parameters[1].Value = model.Name;
|
|
|
107
|
+ parameters[2].Value = model.Short_Name;
|
|
|
108
|
+ parameters[3].Value = model.Lng;
|
|
|
109
|
+ parameters[4].Value = model.Lat;
|
|
|
110
|
+ parameters[5].Value = model.Sort;
|
|
|
111
|
+ parameters[6].Value = model.ID;
|
|
|
112
|
+ parameters[7].Value = model.Code;
|
|
|
113
|
+
|
|
|
114
|
+ int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
|
|
|
115
|
+ if (rows > 0)
|
|
|
116
|
+ {
|
|
|
117
|
+ return true;
|
|
|
118
|
+ }
|
|
|
119
|
+ else
|
|
|
120
|
+ {
|
|
|
121
|
+ return false;
|
|
|
122
|
+ }
|
|
|
123
|
+ }
|
|
|
124
|
+
|
|
|
125
|
+ /// <summary>
|
|
|
126
|
+ /// 删除一条数据
|
|
|
127
|
+ /// </summary>
|
|
|
128
|
+ public bool Delete(int ID, string Code)
|
|
|
129
|
+ {
|
|
|
130
|
+
|
|
|
131
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
132
|
+ strSql.Append("delete from T_Sys_Address ");
|
|
|
133
|
+ strSql.Append(" where ID=@ID and Code=@Code ");
|
|
|
134
|
+ SqlParameter[] parameters = {
|
|
|
135
|
+ new SqlParameter("@ID", SqlDbType.Int,4),
|
|
|
136
|
+ new SqlParameter("@Code", SqlDbType.NVarChar,160) };
|
|
|
137
|
+ parameters[0].Value = ID;
|
|
|
138
|
+ parameters[1].Value = Code;
|
|
|
139
|
+
|
|
|
140
|
+ int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
|
|
|
141
|
+ if (rows > 0)
|
|
|
142
|
+ {
|
|
|
143
|
+ return true;
|
|
|
144
|
+ }
|
|
|
145
|
+ else
|
|
|
146
|
+ {
|
|
|
147
|
+ return false;
|
|
|
148
|
+ }
|
|
|
149
|
+ }
|
|
|
150
|
+
|
|
|
151
|
+
|
|
|
152
|
+ /// <summary>
|
|
|
153
|
+ /// 得到一个对象实体
|
|
|
154
|
+ /// </summary>
|
|
|
155
|
+ public Model.T_Sys_Address GetModel(int ID, string Code)
|
|
|
156
|
+ {
|
|
|
157
|
+
|
|
|
158
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
159
|
+ strSql.Append("select top 1 ID,Code,Parent_Code,Name,Short_Name,Lng,Lat,Sort from T_Sys_Address ");
|
|
|
160
|
+ strSql.Append(" where ID=@ID and Code=@Code ");
|
|
|
161
|
+ SqlParameter[] parameters = {
|
|
|
162
|
+ new SqlParameter("@ID", SqlDbType.Int,4),
|
|
|
163
|
+ new SqlParameter("@Code", SqlDbType.NVarChar,160) };
|
|
|
164
|
+ parameters[0].Value = ID;
|
|
|
165
|
+ parameters[1].Value = Code;
|
|
|
166
|
+
|
|
|
167
|
+ Model.T_Sys_Address model = new Model.T_Sys_Address();
|
|
|
168
|
+ DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
|
|
|
169
|
+ if (ds.Tables[0].Rows.Count > 0)
|
|
|
170
|
+ {
|
|
|
171
|
+ return DataRowToModel(ds.Tables[0].Rows[0]);
|
|
|
172
|
+ }
|
|
|
173
|
+ else
|
|
|
174
|
+ {
|
|
|
175
|
+ return null;
|
|
|
176
|
+ }
|
|
|
177
|
+ }
|
|
|
178
|
+
|
|
|
179
|
+
|
|
|
180
|
+ /// <summary>
|
|
|
181
|
+ /// 得到一个对象实体
|
|
|
182
|
+ /// </summary>
|
|
|
183
|
+ public Model.T_Sys_Address DataRowToModel(DataRow row)
|
|
|
184
|
+ {
|
|
|
185
|
+ Model.T_Sys_Address model = new Model.T_Sys_Address();
|
|
|
186
|
+ if (row != null)
|
|
|
187
|
+ {
|
|
|
188
|
+ if (row["ID"] != null && row["ID"].ToString() != "")
|
|
|
189
|
+ {
|
|
|
190
|
+ model.ID = int.Parse(row["ID"].ToString());
|
|
|
191
|
+ }
|
|
|
192
|
+ if (row["Code"] != null)
|
|
|
193
|
+ {
|
|
|
194
|
+ model.Code = row["Code"].ToString();
|
|
|
195
|
+ }
|
|
|
196
|
+ if (row["Parent_Code"] != null)
|
|
|
197
|
+ {
|
|
|
198
|
+ model.Parent_Code = row["Parent_Code"].ToString();
|
|
|
199
|
+ }
|
|
|
200
|
+ if (row["Name"] != null)
|
|
|
201
|
+ {
|
|
|
202
|
+ model.Name = row["Name"].ToString();
|
|
|
203
|
+ }
|
|
|
204
|
+ if (row["Short_Name"] != null)
|
|
|
205
|
+ {
|
|
|
206
|
+ model.Short_Name = row["Short_Name"].ToString();
|
|
|
207
|
+ }
|
|
|
208
|
+ if (row["Lng"] != null)
|
|
|
209
|
+ {
|
|
|
210
|
+ model.Lng = row["Lng"].ToString();
|
|
|
211
|
+ }
|
|
|
212
|
+ if (row["Lat"] != null)
|
|
|
213
|
+ {
|
|
|
214
|
+ model.Lat = row["Lat"].ToString();
|
|
|
215
|
+ }
|
|
|
216
|
+ if (row["Sort"] != null && row["Sort"].ToString() != "")
|
|
|
217
|
+ {
|
|
|
218
|
+ model.Sort = int.Parse(row["Sort"].ToString());
|
|
|
219
|
+ }
|
|
|
220
|
+ }
|
|
|
221
|
+ return model;
|
|
|
222
|
+ }
|
|
|
223
|
+
|
|
|
224
|
+ /// <summary>
|
|
|
225
|
+ /// 获得数据列表
|
|
|
226
|
+ /// </summary>
|
|
|
227
|
+ public DataSet GetList(string strWhere)
|
|
|
228
|
+ {
|
|
|
229
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
230
|
+ strSql.Append("select ID,Code,Parent_Code,Name,Short_Name,Lng,Lat,Sort ");
|
|
|
231
|
+ strSql.Append(" FROM T_Sys_Address ");
|
|
|
232
|
+ if (strWhere.Trim() != "")
|
|
|
233
|
+ {
|
|
|
234
|
+ strSql.Append(" where " + strWhere);
|
|
|
235
|
+ }
|
|
|
236
|
+ return DbHelperSQL.Query(strSql.ToString());
|
|
|
237
|
+ }
|
|
|
238
|
+
|
|
|
239
|
+ /// <summary>
|
|
|
240
|
+ /// 获得前几行数据
|
|
|
241
|
+ /// </summary>
|
|
|
242
|
+ public DataSet GetList(int Top, string strWhere, string filedOrder)
|
|
|
243
|
+ {
|
|
|
244
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
245
|
+ strSql.Append("select ");
|
|
|
246
|
+ if (Top > 0)
|
|
|
247
|
+ {
|
|
|
248
|
+ strSql.Append(" top " + Top.ToString());
|
|
|
249
|
+ }
|
|
|
250
|
+ strSql.Append(" ID,Code,Parent_Code,Name,Short_Name,Lng,Lat,Sort ");
|
|
|
251
|
+ strSql.Append(" FROM T_Sys_Address ");
|
|
|
252
|
+ if (strWhere.Trim() != "")
|
|
|
253
|
+ {
|
|
|
254
|
+ strSql.Append(" where " + strWhere);
|
|
|
255
|
+ }
|
|
|
256
|
+ strSql.Append(" order by " + filedOrder);
|
|
|
257
|
+ return DbHelperSQL.Query(strSql.ToString());
|
|
|
258
|
+ }
|
|
|
259
|
+
|
|
|
260
|
+ /// <summary>
|
|
|
261
|
+ /// 获取记录总数
|
|
|
262
|
+ /// </summary>
|
|
|
263
|
+ public int GetRecordCount(string strWhere)
|
|
|
264
|
+ {
|
|
|
265
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
266
|
+ strSql.Append("select count(1) FROM T_Sys_Address ");
|
|
|
267
|
+ if (strWhere.Trim() != "")
|
|
|
268
|
+ {
|
|
|
269
|
+ strSql.Append(" where " + strWhere);
|
|
|
270
|
+ }
|
|
|
271
|
+ object obj = DbHelperSQL.GetSingle(strSql.ToString());
|
|
|
272
|
+ if (obj == null)
|
|
|
273
|
+ {
|
|
|
274
|
+ return 0;
|
|
|
275
|
+ }
|
|
|
276
|
+ else
|
|
|
277
|
+ {
|
|
|
278
|
+ return Convert.ToInt32(obj);
|
|
|
279
|
+ }
|
|
|
280
|
+ }
|
|
|
281
|
+ /// <summary>
|
|
|
282
|
+ /// 分页获取数据列表
|
|
|
283
|
+ /// </summary>
|
|
|
284
|
+ public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
|
|
|
285
|
+ {
|
|
|
286
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
287
|
+ strSql.Append("SELECT * FROM ( ");
|
|
|
288
|
+ strSql.Append(" SELECT ROW_NUMBER() OVER (");
|
|
|
289
|
+ if (!string.IsNullOrEmpty(orderby.Trim()))
|
|
|
290
|
+ {
|
|
|
291
|
+ strSql.Append("order by T." + orderby);
|
|
|
292
|
+ }
|
|
|
293
|
+ else
|
|
|
294
|
+ {
|
|
|
295
|
+ strSql.Append("order by T.Code desc");
|
|
|
296
|
+ }
|
|
|
297
|
+ strSql.Append(")AS Row, T.* from T_Sys_Address T ");
|
|
|
298
|
+ if (!string.IsNullOrEmpty(strWhere.Trim()))
|
|
|
299
|
+ {
|
|
|
300
|
+ strSql.Append(" WHERE " + strWhere);
|
|
|
301
|
+ }
|
|
|
302
|
+ strSql.Append(" ) TT");
|
|
|
303
|
+ strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
|
|
|
304
|
+ return DbHelperSQL.Query(strSql.ToString());
|
|
|
305
|
+ }
|
|
|
306
|
+
|
|
|
307
|
+ /*
|
|
|
308
|
+ /// <summary>
|
|
|
309
|
+ /// 分页获取数据列表
|
|
|
310
|
+ /// </summary>
|
|
|
311
|
+ public DataSet GetList(int PageSize,int PageIndex,string strWhere)
|
|
|
312
|
+ {
|
|
|
313
|
+ SqlParameter[] parameters = {
|
|
|
314
|
+ new SqlParameter("@tblName", SqlDbType.VarChar, 255),
|
|
|
315
|
+ new SqlParameter("@fldName", SqlDbType.VarChar, 255),
|
|
|
316
|
+ new SqlParameter("@PageSize", SqlDbType.Int),
|
|
|
317
|
+ new SqlParameter("@PageIndex", SqlDbType.Int),
|
|
|
318
|
+ new SqlParameter("@IsReCount", SqlDbType.Bit),
|
|
|
319
|
+ new SqlParameter("@OrderType", SqlDbType.Bit),
|
|
|
320
|
+ new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
|
|
|
321
|
+ };
|
|
|
322
|
+ parameters[0].Value = "T_Sys_Address";
|
|
|
323
|
+ parameters[1].Value = "Code";
|
|
|
324
|
+ parameters[2].Value = PageSize;
|
|
|
325
|
+ parameters[3].Value = PageIndex;
|
|
|
326
|
+ parameters[4].Value = 0;
|
|
|
327
|
+ parameters[5].Value = 0;
|
|
|
328
|
+ parameters[6].Value = strWhere;
|
|
|
329
|
+ return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
|
|
|
330
|
+ }*/
|
|
|
331
|
+
|
|
|
332
|
+ #endregion BasicMethod
|
|
|
333
|
+ #region ExtensionMethod
|
|
|
334
|
+
|
|
|
335
|
+ #endregion ExtensionMethod
|
|
|
336
|
+ }
|
|
|
337
|
+}
|