IM12345_Api demo - 代码源于 商丘市12345项目

T_Chat_IPList.cs 16KB

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