TravelUsersService.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Models;
  9. namespace DAL
  10. {
  11. /// <summary>
  12. /// 雷怡 2021-10-12 11:51
  13. /// 外部用户登陆表数据访问层
  14. /// </summary>
  15. public class TravelUsersService
  16. {
  17. List<TravelUsers> excuteSql(string sql, params SqlParameter[] param)
  18. {
  19. return ServiceBase<TravelUsers>.excuteSql(new TravelUsers(), "TravelUsers", sql, CommandType.Text, param);
  20. }
  21. TravelUsers excuteType(string sql, params SqlParameter[] param)
  22. {
  23. //查询结果放入对象集合
  24. List<TravelUsers> hdList = excuteSql(sql, param);
  25. TravelUsers tu = new TravelUsers();
  26. //判断集合是否为空
  27. if (hdList == null || hdList.Count == 0)
  28. {
  29. return tu;
  30. }
  31. //返回单个对象
  32. return hdList[0];
  33. }
  34. /// <summary>
  35. /// 雷怡 2021-10-12 15:09
  36. /// 根据条件查询条件获取 - 分页
  37. /// </summary>
  38. /// <param name="pageIndex"></param>
  39. /// <param name="sumPage"></param>
  40. /// <param name="totalRecord"></param>
  41. /// <param name="name"></param>
  42. /// <returns></returns>
  43. public List<TravelUsers> GetAll(int pageIndex, out int sumPage, out int totalRecord)
  44. {
  45. string sqlwhere = " IsDel = 0";
  46. //if (departmentType != "全部")
  47. // sqlwhere += "Did = " + departmentType + " and IsDel = 0";
  48. //if (!string.IsNullOrEmpty(name) && departmentType != "全部")
  49. // sqlwhere += " and CnName like '%" + name + "%' and IsDel = 0";
  50. //if (!string.IsNullOrEmpty(name) && departmentType == "全部")
  51. // sqlwhere += "CnName like '%" + name + "%' and IsDel = 0";
  52. //if (string.IsNullOrEmpty(name) && departmentType == "全部")
  53. // sqlwhere += "CnName like '%" + name + "%' and IsDel = 0";
  54. return PageBase<TravelUsers>.excutePageSql(new TravelUsers(), "TravelUsers", "TravelUsers", "*", "id asc", sqlwhere, 15, pageIndex, out sumPage, out totalRecord);
  55. }
  56. /// <summary>
  57. /// 雷怡 2021-10-13 17:55
  58. /// 删除
  59. /// </summary>
  60. /// <param name="id"></param>
  61. /// <returns></returns>
  62. public bool DelUsers(int id)
  63. {
  64. if (SqlHelper.ExecuteNonQuery("update TravelUsers set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  65. return true;
  66. return false;
  67. }
  68. /// <summary>
  69. /// 雷怡 2021-10-14 15:24
  70. /// 根据Id查询信息
  71. /// </summary>
  72. /// <param name="id">编号id </param>
  73. /// <returns></returns>
  74. public TravelUsers GetbyId( int id)
  75. {
  76. return excuteType("select * from TravelUsers where isdel = 0 and Id = @id", new SqlParameter("@id", id));
  77. }
  78. /// <summary>
  79. /// 雷怡 2021-10-14 15:24
  80. /// 根据账户密码查询信息
  81. /// </summary>
  82. /// <param name="user"></param>
  83. /// <param name="password"></param>
  84. /// <returns></returns>
  85. public TravelUsers GetbyUsersNameAndPassword(string user,string password)
  86. {
  87. return excuteType("select * from TravelUsers where isdel = 0 and (LoginName = @LoginName and LoginPassWord = @LoginPassWord)"
  88. , new SqlParameter("@LoginName", user),new SqlParameter("@LoginPassWord", password));
  89. }
  90. /// <summary>
  91. /// 雷怡 2021-10-14 15:24
  92. /// 根据账户密码查询信息
  93. /// </summary>
  94. /// <param name="user"></param>
  95. /// <param name="password"></param>
  96. /// <returns></returns>
  97. public TravelUsers GetbyUsersName(string user)
  98. {
  99. return excuteType("select * from TravelUsers where isdel = 0 and LoginName = @LoginName"
  100. , new SqlParameter("@LoginName", user));
  101. }
  102. /// <summary>
  103. /// 雷怡 2021-10-14 15:39
  104. /// 编辑
  105. /// </summary>
  106. /// <param name="tu"></param>
  107. /// <returns></returns>
  108. public bool Edit(TravelUsers tu)
  109. {
  110. if (SqlHelper.ExecuteNonQuery("update TravelUsers set LoginPassWord=@LoginPassWord ,SubordinateUnits=@SubordinateUnits ,Oper=@Oper,OperDate=@OperDate where Id=@Id",
  111. CommandType.Text,
  112. new SqlParameter("@LoginPassWord", tu.LoginPassWord),
  113. new SqlParameter("@SubordinateUnits", tu.SubordinateUnits),
  114. new SqlParameter("@Oper", tu.Oper),
  115. new SqlParameter("@OperDate", tu.OperDate),
  116. new SqlParameter("@Id", tu.Id)) > 0)
  117. return true;
  118. return false;
  119. }
  120. /// <summary>
  121. /// 雷怡 2021-10-14 15:48
  122. /// 增Add
  123. /// </summary>
  124. /// <param name="Dov"></param>
  125. /// <returns></returns>
  126. public bool Add(TravelUsers tu)
  127. {
  128. string sql = "insert into TravelUsers values(@LoginName,@LoginPassWord,@SubordinateUnits,@CareteTime,@LoginState,@Oper,@OperDate,@Isdel);";
  129. SqlParameter[] parameter = new SqlParameter[]{
  130. new SqlParameter("@LoginName",tu.LoginName),
  131. new SqlParameter("@LoginPassWord",tu.LoginPassWord),
  132. new SqlParameter("@SubordinateUnits",tu.SubordinateUnits),
  133. new SqlParameter("@CareteTime",tu.CareteTime),
  134. new SqlParameter("@LoginState",tu.LoginState),
  135. new SqlParameter("@Oper",tu.Oper),
  136. new SqlParameter("@OperDate",tu.OperDate),
  137. new SqlParameter("@Isdel",tu.Isdel)
  138. };
  139. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  140. return true;
  141. return false;
  142. }
  143. /// <summary>
  144. /// 雷怡 2021-10-14 16:40
  145. /// 用户登录状态修改
  146. /// </summary>
  147. /// <param name="id"></param>
  148. /// <returns></returns>
  149. public bool SetLoginState(int id,int state)
  150. {
  151. string sql = "update TravelUsers set LoginState = 1 where Id =" + id;
  152. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, null) > 0)
  153. return true;
  154. return false;
  155. }
  156. }
  157. }