GoogleMapApiResultService.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. namespace DAL
  7. {
  8. public class GoogleMapApiResultService
  9. {
  10. //增
  11. public Boolean Add(GoogleMapApiResult g)
  12. {
  13. //select @@identity可获取插入记录时生成的标识ID
  14. string sql = "insert into GoogleMapApiResult Values(@Diid,@Date,@Moment,@StartAddress,@EndAddress,@Time,@Distance);SELECT @@IDENTITY ";
  15. SqlParameter[] param = new SqlParameter[]
  16. {
  17. new SqlParameter("@Diid",g.Diid),
  18. new SqlParameter("@Date",g.Date),
  19. new SqlParameter("@Moment",g.Moment),
  20. new SqlParameter("@StartAddress",g.StartAddress),
  21. new SqlParameter("@EndAddress",g.EndAddress),
  22. new SqlParameter("@Time",g.Time),
  23. new SqlParameter("@Distance",g.Distance)
  24. };
  25. //执行,得到受影响行数
  26. int affectRows = SqlHelper.ExecuteNonQuery(sql, CommandType.Text, param);
  27. if (affectRows > 0)
  28. {
  29. return true;
  30. }
  31. else
  32. {
  33. return false;
  34. }
  35. }
  36. //删
  37. public bool Del(int id)
  38. {
  39. string sql = "Delete from GoogleMapApiResult where Id=" + id;
  40. //执行,得到受影响行数
  41. int affectRows = SqlHelper.ExecuteNonQuery(sql, CommandType.Text);
  42. if (affectRows > 0)
  43. {
  44. return true;
  45. }
  46. else
  47. {
  48. return false;
  49. }
  50. }
  51. //改
  52. public bool Edit(GoogleMapApiResult g)
  53. {
  54. string sql = "Update GoogleMapApiResult set Diid=@Diid,Date=@Date,Time=@Time,Distance=@Distance where Id=@Id";
  55. SqlParameter[] param = new SqlParameter[]
  56. {
  57. new SqlParameter("@Diid",g.Diid),
  58. new SqlParameter("@Date",g.Date),
  59. new SqlParameter("@Moment",g.Moment),
  60. new SqlParameter("@StartAddress",g.StartAddress),
  61. new SqlParameter("@EndAddress",g.EndAddress),
  62. new SqlParameter("@Time",g.Time),
  63. new SqlParameter("@Distance",g.Distance),
  64. new SqlParameter("@Id",g.Id)
  65. };
  66. //执行,得到受影响行数
  67. int affectRows = SqlHelper.ExecuteNonQuery(sql, CommandType.Text, param);
  68. if (affectRows > 0)
  69. {
  70. return true;
  71. }
  72. else
  73. {
  74. return false;
  75. }
  76. }
  77. /// <summary>
  78. /// 多个查询
  79. /// </summary>
  80. /// <returns></returns>
  81. public List<GoogleMapApiResult> GetMultiple()
  82. {
  83. return excuteMultiple("Select * from GoogleMapApiResult");
  84. }
  85. /// <summary>
  86. /// 单查询
  87. /// </summary>
  88. /// <param name="id"></param>
  89. /// <returns></returns>
  90. public GoogleMapApiResult GetSingle(int id)
  91. {
  92. return excuteSingle("Select * from GoogleMapApiResult where Id=" + id);
  93. }
  94. /// <summary>
  95. /// 条件查询
  96. /// </summary>
  97. /// <param name="diid"></param>
  98. /// <param name="startaddress"></param>
  99. /// <param name="endadress"></param>
  100. /// <returns></returns>
  101. public GoogleMapApiResult GetByDiidAddress(int diid, string startaddress, string endadress)
  102. {
  103. return excuteSingle("select * from GoogleMapApiResult where Diid=" + diid + " and StartAddress='" + startaddress + "' and EndAddress='" + endadress + "'");
  104. }
  105. //分页查询;多个
  106. /// <summary>
  107. /// 条件查询
  108. /// </summary>
  109. /// <param name="startaddress">起始地址</param>
  110. /// <param name="endadress">目的地址</param>
  111. /// <returns></returns>
  112. public GoogleMapApiResult GetByAddress(string startaddress, string endadress)
  113. {
  114. return excuteSingle("select * from GoogleMapApiResult where StartAddress='" + startaddress + "' and EndAddress='" + endadress + "'");
  115. }
  116. //条件查询2;多个
  117. //...
  118. /// <summary>
  119. ///查询读取执行入口
  120. /// </summary>
  121. /// <param name="sql"></param>
  122. /// <param name="param"></param>
  123. /// <returns>返回集合</returns>
  124. List<GoogleMapApiResult> excuteMultiple(string sql, params SqlParameter[] param)
  125. {
  126. List<GoogleMapApiResult> list = ServiceBase<GoogleMapApiResult>.excuteSql(new GoogleMapApiResult(), "GoogleMapApiResult", sql, CommandType.Text, param);
  127. return list;
  128. }
  129. /// <summary>
  130. ///查询读取执行入口
  131. /// </summary>
  132. /// <param name="sql"></param>
  133. /// <param name="param"></param>
  134. /// <returns>返回单个对象</returns>
  135. GoogleMapApiResult excuteSingle(string sql, params SqlParameter[] param)
  136. {
  137. List<GoogleMapApiResult> list = excuteMultiple(sql, param);
  138. if (list == null || list.Count == 0)
  139. {
  140. return null;
  141. }
  142. else
  143. {
  144. return list[0];
  145. }
  146. }
  147. }
  148. }