StrokeContentService.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. namespace DAL
  9. {
  10. /// <summary>
  11. /// 行程内容数据访问类
  12. /// </summary>
  13. public class StrokeContentService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<StrokeContent> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<StrokeContent>.excuteSql(new StrokeContent(), "StrokeContent", sql, CommandType.Text, param);
  24. }
  25. /// <summary>
  26. /// 获取单个对象
  27. /// </summary>
  28. /// <param name="sql">sql语句</param>
  29. /// <param name="param">可变参数数组</param>
  30. /// <returns>返回空或者单个对象</returns>
  31. StrokeContent excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<StrokeContent> scList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (scList == null || scList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return scList[0];
  41. }
  42. /// <summary>
  43. /// 增加 - 批量
  44. /// </summary>
  45. /// <returns></returns>
  46. public bool AddStrokeContent(List<StrokeContent> scList)
  47. {
  48. SqlCommand cmd = SqlHelper.createCon().CreateCommand();
  49. cmd.Connection.Open();
  50. SqlTransaction trans = cmd.Connection.BeginTransaction();
  51. try
  52. {
  53. foreach (StrokeContent sc in scList)
  54. {
  55. cmd.CommandText = "insert into StrokeContent values('" + sc.SId + "','" + sc.Date + "','" + sc.CityRange + "','" + sc.Traffic + "','" + sc.Content + "','" + sc.Point + "')";
  56. cmd.ExecuteNonQuery();
  57. }
  58. trans.Commit();
  59. cmd.Connection.Close();
  60. return true;
  61. }
  62. catch
  63. {
  64. trans.Rollback();
  65. cmd.Connection.Close();
  66. return false;
  67. }
  68. }
  69. /// <summary>
  70. /// 根据编号查询对象信息
  71. /// </summary>
  72. /// <param name="id">对象编号</param>
  73. /// <returns>返回空或者单个对象信息</returns>
  74. public StrokeContent GetStrokeContentByID(int id)
  75. {
  76. //调用获取单个对象的方法
  77. return excuteType("select * from StrokeContent where Id = @id", new SqlParameter("@id", id));
  78. }
  79. /// <summary>
  80. /// 根据编号查询对象信息
  81. /// </summary>
  82. /// <param name="id">对象编号</param>
  83. /// <returns>返回空或者单个对象信息</returns>
  84. public List<StrokeContent> GetStrokeContentList(int pageIndex, out int sumPage, out int totalRecord, string point, string cityRange)
  85. {
  86. string sqlwhere = "cityRange <> '' and Point = '" + point + "' and cityRange like '%" + cityRange + "%'";
  87. return PageBase<StrokeContent>.excutePageSql(new StrokeContent(), "StrokeContent", "StrokeContent", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  88. }
  89. /// <summary>
  90. /// 根据编号查询对象信息
  91. /// </summary>
  92. /// <param name="id">对象编号</param>
  93. /// <returns>返回空或者单个对象信息</returns>
  94. public List<StrokeContent> GetStrokeContentBySID(int sid)
  95. {
  96. //调用获取单个对象的方法
  97. return excuteSql("select * from StrokeContent where SId = @SId", new SqlParameter("@SId", sid));
  98. }
  99. /// <summary>
  100. /// 根据编号查询对象信息
  101. /// </summary>
  102. /// <param name="id">对象编号</param>
  103. /// <returns>返回空或者单个对象信息</returns>
  104. public List<StrokeContent> GetStrokeContentBySIDAndPoint(int sid,int point)
  105. {
  106. //调用获取单个对象的方法
  107. return excuteSql("select * from StrokeContent where SId = @SId and Point = @Point", new SqlParameter("@SId", sid), new SqlParameter("@Point", point));
  108. }
  109. /// <summary>
  110. /// 删除
  111. /// </summary>
  112. /// <param name="id"></param>
  113. /// <returns></returns>
  114. public bool DelStrokeContent(int sid)
  115. {
  116. if (SqlHelper.ExecuteNonQuery("delete StrokeContent where SId = @SId", CommandType.Text, new SqlParameter("@SId", sid)) > 0)
  117. return true;
  118. return false;
  119. }
  120. /// <summary>
  121. /// LiuChengYi 2014/5/08
  122. /// 用作微信平台上根据团组编号查询详细行程
  123. /// </summary>
  124. /// <returns></returns>
  125. public DataTable QueryTrip_weixin(string TourCode)
  126. {
  127. SqlParameter[] pars =
  128. {
  129. new SqlParameter("@TourCode",TourCode)
  130. };
  131. return SqlHelper.TransferProcedure("QueryTrip_weixin", CommandType.StoredProcedure, pars);
  132. }
  133. }
  134. }