UsersService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 UsersService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<Users> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<Users>.excuteSql(new Users(), "Users", 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. Users excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<Users> usersList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (usersList == null || usersList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return usersList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public Users GetUsersByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from Users where Id = @id", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// 获取全部有效员工,排除掉管理员
  54. /// </summary>
  55. /// <returns></returns>
  56. public List<Users> GetAll()
  57. {
  58. return excuteSql("select * from Users Where IsDel = 0 and Id<>4");
  59. }
  60. /// <summary>
  61. /// 获取全部有效员工,包含管理员
  62. /// </summary>
  63. /// <returns></returns>
  64. public List<Users> GetAllGM()
  65. {
  66. return excuteSql("select * from Users Where IsDel = 0");
  67. }
  68. /// <summary>
  69. /// 获取全部有效员工-主管级别
  70. /// </summary>
  71. /// <returns></returns>
  72. public List<Users> GetAll(string id)
  73. {
  74. return excuteSql("select * from Users Where IsDel = 0 and id in (" + id + ")");
  75. }
  76. /// <summary>
  77. /// 根据部门获取全部有效员工
  78. /// </summary>
  79. /// <returns></returns>
  80. public List<Users> GetAll(int did)
  81. {
  82. return excuteSql("select * from Users Where IsDel = 0 and Did = @Did", new SqlParameter("@Did", did));
  83. }
  84. /// <summary>
  85. /// 根据条件获取全部员工
  86. /// </summary>
  87. /// <param name="userNumber"></param>
  88. /// <returns></returns>
  89. public Users GetEntity(string userNumber)
  90. {
  91. return excuteType("select * from Users Where Number = @UserNumber and IsDel = 0", new SqlParameter("@UserNumber", userNumber));
  92. }
  93. /// <summary>
  94. /// 获取登录信息
  95. /// </summary>
  96. /// <returns></returns>
  97. public Users GetEntityByUserNoAndPwd(string userNo, string pwd)
  98. {
  99. return excuteType("select * from Users Where Number = @userNo and Password = @Password and IsDel = 0", new SqlParameter("@userNo", userNo), new SqlParameter("@Password", pwd));
  100. }
  101. /// <summary>
  102. /// 根据条件查询条件获取 - 分页
  103. /// </summary>
  104. /// <param name="pageIndex"></param>
  105. /// <param name="sumPage"></param>
  106. /// <param name="totalRecord"></param>
  107. /// <param name="dataType"></param>
  108. /// <param name="name"></param>
  109. /// <returns></returns>
  110. public List<Users> GetAll(int pageIndex, out int sumPage, out int totalRecord, string departmentType, string name)
  111. {
  112. string sqlwhere = "";
  113. if (departmentType != "全部")
  114. sqlwhere += "Did = " + departmentType + " and IsDel = 0";
  115. if (!string.IsNullOrEmpty(name) && departmentType != "全部")
  116. sqlwhere += " and CnName like '%" + name + "%' and IsDel = 0";
  117. if (!string.IsNullOrEmpty(name) && departmentType == "全部")
  118. sqlwhere += "CnName like '%" + name + "%' and IsDel = 0";
  119. if (string.IsNullOrEmpty(name) && departmentType == "全部")
  120. sqlwhere += "CnName like '%" + name + "%' and IsDel = 0";
  121. return PageBase<Users>.excutePageSql(new Users(), "Users", "Users", "*", "id asc", sqlwhere, 15, pageIndex, out sumPage, out totalRecord);
  122. }
  123. /// <summary>
  124. /// 根据条件查询条件获取 - 分页
  125. /// 所有员工IsDel=1
  126. /// </summary>
  127. /// <param name="pageIndex"></param>
  128. /// <param name="sumPage"></param>
  129. /// <param name="totalRecord"></param>
  130. /// <param name="dataType"></param>
  131. /// <param name="name"></param>
  132. /// <returns></returns>
  133. public List<Users> GetAllNoIsDel(int pageIndex, out int sumPage, out int totalRecord, string departmentType, string name)
  134. {
  135. string sqlwhere = "";
  136. if (departmentType != "全部")
  137. sqlwhere += "Did = " + departmentType + " ";
  138. if (!string.IsNullOrEmpty(name) && departmentType != "全部")
  139. sqlwhere += " and CnName like '%" + name + "%'";
  140. if (!string.IsNullOrEmpty(name) && departmentType == "全部")
  141. sqlwhere += "CnName like '%" + name + "%'";
  142. if (string.IsNullOrEmpty(name) && departmentType == "全部")
  143. sqlwhere += "CnName like '%" + name + "%'";
  144. return PageBase<Users>.excutePageSql(new Users(), "Users", "Users", "*", "id asc", sqlwhere, 15, pageIndex, out sumPage, out totalRecord);
  145. }
  146. /// <summary>
  147. /// 新增
  148. /// </summary>
  149. /// <param name="sdt">对象</param>
  150. public bool AddUsers(Users u)
  151. {
  152. string sql = "insert into Users values(@CnName,@EnName,@Number,@Did,@Password,@Sex,@Post,@Ext,@Phone,@UrgentPhone,@Email,@Address,@Edate,@Rdate,@Seniority,@Remark,@IsDel,@Company,@Birthday,@IDCard,@StartWorkDate,@Education,@Professional,@GraduateInstitutions,@TheOrAdultEducation,@MaritalStatus,@HomeAddress,@UsePeriod,@WorkExperience,@CertificateTime,@Certificate)";
  153. SqlParameter[] parameter = new SqlParameter[]{
  154. new SqlParameter("@CnName",u.CnName),
  155. new SqlParameter("@EnName",u.EnName),
  156. new SqlParameter("@Number",u.Number),
  157. new SqlParameter("@Did",u.Did),
  158. new SqlParameter("@Password",u.Password),
  159. new SqlParameter("@Sex",u.Sex),
  160. new SqlParameter("@Post",u.Post),
  161. new SqlParameter("@Ext",u.Ext),
  162. new SqlParameter("@Phone",u.Phone),
  163. new SqlParameter("@UrgentPhone",u.UrgentPhone),
  164. new SqlParameter("@Email",u.Email),
  165. new SqlParameter("@Address",u.Address),
  166. new SqlParameter("@Edate",u.Edate),
  167. new SqlParameter("@Rdate",u.Rdate),
  168. new SqlParameter("@Remark",u.Remark),
  169. new SqlParameter("@Seniority",u.Seniority),
  170. new SqlParameter("@IsDel",u.IsDel),
  171. new SqlParameter("@Company",u.Company),
  172. new SqlParameter("@Birthday",u.Birthday),
  173. new SqlParameter("@IDCard",u.IDCard),
  174. new SqlParameter("@StartWorkDate",u.StartWorkDate),
  175. new SqlParameter("@Education",u.Education),
  176. new SqlParameter("@Professional",u.Professional),
  177. new SqlParameter("@GraduateInstitutions",u.GraduateInstitutions),
  178. new SqlParameter("@TheOrAdultEducation",u.TheOrAdultEducation),
  179. new SqlParameter("@MaritalStatus",u.MaritalStatus),
  180. new SqlParameter("@HomeAddress",u.HomeAddress),
  181. new SqlParameter("@UsePeriod",u.UsePeriod),
  182. new SqlParameter("@WorkExperience",u.WorkExperience),
  183. new SqlParameter("@CertificateTime",u.CertificateTime),
  184. new SqlParameter("@Certificate",u.Certificate)
  185. };
  186. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  187. return true;
  188. return false;
  189. }
  190. /// <summary>
  191. /// 编辑
  192. /// </summary>
  193. /// <param name="sdt"></param>
  194. /// <returns></returns>
  195. public bool EditUsers(Users u)
  196. {
  197. string sql = "update Users set CnName = @CnName,EnName = @EnName,Number = @Number,Did = @Did,Password = @Password,Sex = @Sex,Post = @Post,Ext = @Ext,Phone = @Phone,UrgentPhone = @UrgentPhone,Email = @Email,Address = @Address,Edate= @Edate,Rdate = @Rdate,Remark=@Remark,Seniority=@Seniority,IsDel=@IsDel,Company=@Company,Birthday=@Birthday,IDCard=@IDCard,StartWorkDate=@StartWorkDate,Education=@Education,Professional=@Professional,GraduateInstitutions=@GraduateInstitutions,TheOrAdultEducation=@TheOrAdultEducation,MaritalStatus=@MaritalStatus,HomeAddress=@HomeAddress,UsePeriod=@UsePeriod,WorkExperience=@WorkExperience,CertificateTime=@CertificateTime,Certificate=@Certificate where Id = @Id";
  198. SqlParameter[] parameter = new SqlParameter[] {
  199. new SqlParameter("@Id",u.Id),
  200. new SqlParameter("@CnName",u.CnName),
  201. new SqlParameter("@EnName",u.EnName),
  202. new SqlParameter("@Number",u.Number),
  203. new SqlParameter("@Did",u.Did),
  204. new SqlParameter("@Password",u.Password),
  205. new SqlParameter("@Sex",u.Sex),
  206. new SqlParameter("@Post",u.Post),
  207. new SqlParameter("@Ext",u.Ext),
  208. new SqlParameter("@Phone",u.Phone),
  209. new SqlParameter("@UrgentPhone",u.UrgentPhone),
  210. new SqlParameter("@Email",u.Email),
  211. new SqlParameter("@Address",u.Address),
  212. new SqlParameter("@Edate",u.Edate),
  213. new SqlParameter("@Rdate",u.Rdate),
  214. new SqlParameter("@Remark",u.Remark),
  215. new SqlParameter("@Seniority",u.Seniority),
  216. new SqlParameter("@IsDel",u.IsDel),
  217. new SqlParameter("@Company",u.Company),
  218. new SqlParameter("@Birthday",u.Birthday),
  219. new SqlParameter("@IDCard",u.IDCard),
  220. new SqlParameter("@StartWorkDate",u.StartWorkDate),
  221. new SqlParameter("@Education",u.Education),
  222. new SqlParameter("@Professional",u.Professional),
  223. new SqlParameter("@GraduateInstitutions",u.GraduateInstitutions),
  224. new SqlParameter("@TheOrAdultEducation",u.TheOrAdultEducation),
  225. new SqlParameter("@MaritalStatus",u.MaritalStatus),
  226. new SqlParameter("@HomeAddress",u.HomeAddress),
  227. new SqlParameter("@UsePeriod",u.UsePeriod),
  228. new SqlParameter("@WorkExperience",u.WorkExperience),
  229. new SqlParameter("@CertificateTime",u.CertificateTime),
  230. new SqlParameter("@Certificate",u.Certificate)
  231. };
  232. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  233. return true;
  234. return false;
  235. }
  236. /// <summary>
  237. /// 删除
  238. /// </summary>
  239. /// <param name="id"></param>
  240. /// <returns></returns>
  241. public bool DelUsers(int id)
  242. {
  243. if (SqlHelper.ExecuteNonQuery("update Users set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  244. return true;
  245. return false;
  246. }
  247. /// <summary>
  248. /// 修改密码
  249. /// </summary>
  250. /// <param name="userNo"></param>
  251. /// <param name="pwd"></param>
  252. /// <returns></returns>
  253. public bool DelUpdatePwd(string userNo, string pwd)
  254. {
  255. if (SqlHelper.ExecuteNonQuery("update Users set Password = @Password where Number = @UserNo and IsDel = 0", CommandType.Text, new SqlParameter("@Password", pwd), new SqlParameter("@UserNo", userNo)) > 0)
  256. return true;
  257. return false;
  258. }
  259. /// <summary>
  260. /// 根据姓名查询对象信息
  261. /// </summary>
  262. /// <param name="id">对象编号</param>
  263. /// <returns>返回空或者单个对象信息</returns>
  264. public Users GetUsersByName(string name)
  265. {
  266. //调用获取单个对象的方法
  267. return excuteType("select * from Users where CnName = @name and Isdel=0", new SqlParameter("@name", name));
  268. }
  269. /// <summary>
  270. /// 根据职位查询有效员工
  271. /// </summary>
  272. /// <returns></returns>
  273. public List<Users> GetJobAll()
  274. {
  275. return excuteSql("select * from Users where Post like '%酒店%' and IsDel=0 or Post like '%机票%' or Id=149");
  276. }
  277. }
  278. }