WageService.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 WageService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<Wage> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<Wage>.excuteSql(new Wage(), "Wage", 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. Wage excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<Wage> WageList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (WageList == null || WageList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return WageList[0];
  41. }
  42. /// <summary>
  43. /// 查找工资表里最新的月份
  44. /// </summary>
  45. /// <param name="userId"></param>
  46. /// <returns></returns>
  47. public List<Wage> GetWageByUID(int userId)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteSql("select * from Wage where Isdel = 0 and UserId=@userId order by Id desc", new SqlParameter("@userId", userId));
  51. }
  52. /// <summary>
  53. /// 根据编号查询对象信息
  54. /// </summary>
  55. /// <param name="id">对象编号</param>
  56. /// <returns>返回空或者单个对象信息</returns>
  57. public Wage GetWageByID(int id)
  58. {
  59. //调用获取单个对象的方法
  60. return excuteType("select * from Wage where Id = @id", new SqlParameter("@id", id));
  61. }
  62. /// <summary>
  63. /// 根据编号查询对象信息
  64. /// </summary>
  65. /// <returns>返回空或者单个对象信息</returns>
  66. public Wage GetWageByEntity(string yearMonth,int userId)
  67. {
  68. //调用获取单个对象的方法
  69. return excuteType("select * from Wage where YearMonth = @YearMonth and UserId = @UserId and IsDel = 0 order by id desc", new SqlParameter("@YearMonth", yearMonth), new SqlParameter("@userId", userId));
  70. }
  71. /// <summary>
  72. /// 获取全部有效数据
  73. /// </summary>
  74. /// <returns></returns>
  75. public List<Wage> GetAll(string yearMonth)
  76. {
  77. return excuteSql("select * from Wage Where IsDel = 0 and YearMonth=@YearMonth", new SqlParameter("@YearMonth", yearMonth));
  78. }
  79. /// <summary>
  80. /// 获取全部有效数据 - 导出工资列表
  81. /// </summary>
  82. /// <returns></returns>
  83. public List<Wage> GetAllByIdStr(string idStr)
  84. {
  85. return excuteSql("select * from wage where id in (" + idStr + ")");
  86. }
  87. /// <summary>
  88. /// 新增
  89. /// </summary>
  90. /// <param name="sdt">对象</param>
  91. public bool AddWage(Wage w)
  92. {
  93. string sql = "insert into Wage values(@YearMonth,@UserId,@StartDate,@EndDate,@Basic,@Floats, @PostAllowance, @GarmentWashSubsidies, @CommunicationSubsidies, @TrafficSubsidies,@InformationSecurityFee, @OperationBonus,@SpecialAllowance,@OtherSubsidies,@WithholdingInsurance,@SickLeave, @SomethingFalse,@LateTo,@LeaveEarly,@Absenteeism,@NotPunch,@OtherDeductions,@Should,@TotalDeductions,@TotalRealHair,@Tax,@AfterTax,@IsLock,@Remark,@Operator,@OperatorDate,@IsDel,@Mealsupplement,@Gongjijin,@GroupCost)";
  94. SqlParameter[] parameter = new SqlParameter[]{
  95. new SqlParameter("@YearMonth",w.YearMonth),
  96. new SqlParameter("@UserId",w.UserId),
  97. new SqlParameter("@StartDate",w.StartDate),
  98. new SqlParameter("@EndDate",w.EndDate),
  99. new SqlParameter("@Basic", w.Basic),
  100. new SqlParameter("@Floats",w.Floats),
  101. new SqlParameter("@PostAllowance",w.PostAllowance),
  102. new SqlParameter("@GarmentWashSubsidies",w.GarmentWashSubsidies),
  103. new SqlParameter("@CommunicationSubsidies",w.CommunicationSubsidies),
  104. new SqlParameter("@TrafficSubsidies",w.TrafficSubsidies),
  105. new SqlParameter("@InformationSecurityFee",w.InformationSecurityFee),
  106. new SqlParameter("@OperationBonus",w.OperationBonus),
  107. new SqlParameter("@SpecialAllowance",w.SpecialAllowance),
  108. new SqlParameter("@OtherSubsidies",w.OtherSubsidies),
  109. new SqlParameter("@WithholdingInsurance",w.WithholdingInsurance),
  110. new SqlParameter("@SickLeave",w.SickLeave),
  111. new SqlParameter("@SomethingFalse",w.SomethingFalse),
  112. new SqlParameter("@LateTo",w.LateTo),
  113. new SqlParameter("@LeaveEarly",w.LeaveEarly),
  114. new SqlParameter("@Absenteeism",w.Absenteeism),
  115. new SqlParameter("@NotPunch",w.NotPunch),
  116. new SqlParameter("@OtherDeductions",w.OtherDeductions),
  117. new SqlParameter("@Should",w.Should),
  118. new SqlParameter("@TotalDeductions",w.TotalDeductions),
  119. new SqlParameter("@TotalRealHair",w.TotalRealHair),
  120. new SqlParameter("@Tax",w.Tax),
  121. new SqlParameter("@AfterTax",w.AfterTax),
  122. new SqlParameter("@IsLock",w.IsLock),
  123. new SqlParameter("@Remark",w.Remark),
  124. new SqlParameter("@Operator",w.Operators),
  125. new SqlParameter("@OperatorDate",w.OperatorsDate),
  126. new SqlParameter("@IsDel",w.IsDel),
  127. new SqlParameter("@Mealsupplement",w.Mealsupplement),
  128. new SqlParameter("@Gongjijin",w.Gongjijin),
  129. new SqlParameter("@GroupCost",w.GroupCost)
  130. };
  131. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  132. return true;
  133. return false;
  134. }
  135. /// <summary>
  136. /// 编辑
  137. /// </summary>
  138. /// <param name="sdt"></param>
  139. /// <returns></returns>
  140. public bool EditWage(Wage w)
  141. {
  142. string sql = "update Wage set YearMonth = @YearMonth,UserId = @UserId,StartDate = @StartDate,EndDate = @EndDate,Basic = @Basic,Floats = @Floats,PostAllowance = @PostAllowance,GarmentWashSubsidies = @GarmentWashSubsidies,CommunicationSubsidies = @CommunicationSubsidies,TrafficSubsidies = @TrafficSubsidies,InformationSecurityFee = @InformationSecurityFee,OperationBonus = @OperationBonus,SpecialAllowance = @SpecialAllowance,OtherSubsidies = @OtherSubsidies,WithholdingInsurance = @WithholdingInsurance,SickLeave = @SickLeave,SomethingFalse = @SomethingFalse,LateTo = @LateTo,LeaveEarly = @LeaveEarly,Absenteeism = @Absenteeism,NotPunch = @NotPunch,OtherDeductions = @OtherDeductions,Should = @Should,TotalDeductions = @TotalDeductions,TotalRealHair = @TotalRealHair,Tax=@Tax,AfterTax=@AfterTax,IsLock = @IsLock,Remark = @Remark,Operator = @Operator,OperatorDate = @OperatorDate,Mealsupplement=@Mealsupplement,Gongjijin=@Gongjijin,GroupCost=@GroupCost where Id = @Id";
  143. SqlParameter[] parameter = new SqlParameter[]{
  144. new SqlParameter("@YearMonth",w.YearMonth),
  145. new SqlParameter("@UserId",w.UserId),
  146. new SqlParameter("@StartDate",w.StartDate),
  147. new SqlParameter("@EndDate",w.EndDate),
  148. new SqlParameter("@Basic", w.Basic),
  149. new SqlParameter("@Floats",w.Floats),
  150. new SqlParameter("@PostAllowance",w.PostAllowance),
  151. new SqlParameter("@GarmentWashSubsidies",w.GarmentWashSubsidies),
  152. new SqlParameter("@CommunicationSubsidies",w.CommunicationSubsidies),
  153. new SqlParameter("@TrafficSubsidies",w.TrafficSubsidies),
  154. new SqlParameter("@InformationSecurityFee",w.InformationSecurityFee),
  155. new SqlParameter("@OperationBonus",w.OperationBonus),
  156. new SqlParameter("@SpecialAllowance",w.SpecialAllowance),
  157. new SqlParameter("@OtherSubsidies",w.OtherSubsidies),
  158. new SqlParameter("@WithholdingInsurance",w.WithholdingInsurance),
  159. new SqlParameter("@SickLeave",w.SickLeave),
  160. new SqlParameter("@SomethingFalse",w.SomethingFalse),
  161. new SqlParameter("@LateTo",w.LateTo),
  162. new SqlParameter("@LeaveEarly",w.LeaveEarly),
  163. new SqlParameter("@Absenteeism",w.Absenteeism),
  164. new SqlParameter("@NotPunch",w.NotPunch),
  165. new SqlParameter("@OtherDeductions",w.OtherDeductions),
  166. new SqlParameter("@Should",w.Should),
  167. new SqlParameter("@TotalDeductions",w.TotalDeductions),
  168. new SqlParameter("@TotalRealHair",w.TotalRealHair),
  169. new SqlParameter("@Tax",w.Tax),
  170. new SqlParameter("@AfterTax",w.AfterTax),
  171. new SqlParameter("@IsLock",w.IsLock),
  172. new SqlParameter("@Remark",w.Remark),
  173. new SqlParameter("@Operator",w.Operators),
  174. new SqlParameter("@OperatorDate",w.OperatorsDate),
  175. new SqlParameter("@Id",w.Id),
  176. new SqlParameter("@Mealsupplement",w.Mealsupplement),
  177. new SqlParameter("@Gongjijin",w.Gongjijin),
  178. new SqlParameter("@GroupCost",w.GroupCost)
  179. };
  180. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  181. return true;
  182. return false;
  183. }
  184. /// <summary>
  185. /// 批量更新
  186. /// </summary>
  187. /// <param name="sdt"></param>
  188. /// <returns></returns>
  189. public bool EditWage(List<Wage> ws)
  190. {
  191. SqlCommand cmd = SqlHelper.createCon().CreateCommand();
  192. cmd.Connection.Open();
  193. SqlTransaction trans = cmd.Connection.BeginTransaction();
  194. cmd.Transaction = trans;
  195. string sql = "update Wage set YearMonth = @YearMonth,UserId = @UserId,StartDate = @StartDate,EndDate = @EndDate,Basic = @Basic,Floats = @Floats,PostAllowance = @PostAllowance,GarmentWashSubsidies = @GarmentWashSubsidies,CommunicationSubsidies = @CommunicationSubsidies,TrafficSubsidies = @TrafficSubsidies,InformationSecurityFee = @InformationSecurityFee,OperationBonus = @OperationBonus,SpecialAllowance = @SpecialAllowance,OtherSubsidies = @OtherSubsidies,WithholdingInsurance = @WithholdingInsurance,SickLeave = @SickLeave,SomethingFalse = @SomethingFalse,LateTo = @LateTo,LeaveEarly = @LeaveEarly,Absenteeism = @Absenteeism,NotPunch = @NotPunch,OtherDeductions = @OtherDeductions,Should = @Should,TotalDeductions = @TotalDeductions,TotalRealHair = @TotalRealHair,Tax=@Tax,AfterTax=@AfterTax,IsLock = @IsLock,Remark = @Remark,Operator = @Operator,OperatorDate = @OperatorDate,Mealsupplement=@Mealsupplement,Gongjijin=@Gongjijin,GroupCost=@GroupCost where Id = @Id";
  196. cmd.CommandText = sql;
  197. SqlParameter[] parameter = new SqlParameter[]{
  198. new SqlParameter("@YearMonth",SqlDbType.VarChar),
  199. new SqlParameter("@UserId",SqlDbType.Int),
  200. new SqlParameter("@StartDate",SqlDbType.VarChar),
  201. new SqlParameter("@EndDate",SqlDbType.VarChar),
  202. new SqlParameter("@Basic", SqlDbType.Float),
  203. new SqlParameter("@Floats",SqlDbType.Float),
  204. new SqlParameter("@PostAllowance",SqlDbType.Float),
  205. new SqlParameter("@GarmentWashSubsidies",SqlDbType.Float),
  206. new SqlParameter("@CommunicationSubsidies",SqlDbType.Float),
  207. new SqlParameter("@TrafficSubsidies",SqlDbType.Float),
  208. new SqlParameter("@InformationSecurityFee",SqlDbType.Float),
  209. new SqlParameter("@OperationBonus",SqlDbType.Float),
  210. new SqlParameter("@SpecialAllowance",SqlDbType.Float),
  211. new SqlParameter("@OtherSubsidies",SqlDbType.Float),
  212. new SqlParameter("@WithholdingInsurance",SqlDbType.Float),
  213. new SqlParameter("@SickLeave",SqlDbType.Float),
  214. new SqlParameter("@SomethingFalse",SqlDbType.Float),
  215. new SqlParameter("@LateTo",SqlDbType.Float),
  216. new SqlParameter("@LeaveEarly",SqlDbType.Float),
  217. new SqlParameter("@Absenteeism",SqlDbType.Float),
  218. new SqlParameter("@NotPunch",SqlDbType.Float),
  219. new SqlParameter("@OtherDeductions",SqlDbType.Float),
  220. new SqlParameter("@Should",SqlDbType.Float),
  221. new SqlParameter("@TotalDeductions",SqlDbType.Float),
  222. new SqlParameter("@TotalRealHair",SqlDbType.Float),
  223. new SqlParameter("@Tax",SqlDbType.Float),
  224. new SqlParameter("@AfterTax",SqlDbType.Float),
  225. new SqlParameter("@IsLock",SqlDbType.Int),
  226. new SqlParameter("@Remark",SqlDbType.VarChar),
  227. new SqlParameter("@Operator",SqlDbType.VarChar),
  228. new SqlParameter("@OperatorDate",SqlDbType.VarChar),
  229. new SqlParameter("@Id",SqlDbType.Int),
  230. new SqlParameter("@Mealsupplement",SqlDbType.Float),
  231. new SqlParameter("@Gongjijin",SqlDbType.Float),
  232. new SqlParameter("@GroupCost",SqlDbType.Float)
  233. };
  234. try
  235. {
  236. foreach (var w in ws)
  237. {
  238. parameter[0].Value = w.YearMonth;
  239. parameter[1].Value = w.UserId;
  240. parameter[2].Value = w.StartDate;
  241. parameter[3].Value = w.EndDate;
  242. parameter[4].Value = w.Basic;
  243. parameter[5].Value = w.Floats;
  244. parameter[6].Value = w.PostAllowance;
  245. parameter[7].Value = w.GarmentWashSubsidies;
  246. parameter[8].Value = w.CommunicationSubsidies;
  247. parameter[9].Value = w.TrafficSubsidies;
  248. parameter[10].Value = w.InformationSecurityFee;
  249. parameter[11].Value = w.OperationBonus;
  250. parameter[12].Value = w.SpecialAllowance;
  251. parameter[13].Value = w.OtherSubsidies;
  252. parameter[14].Value = w.WithholdingInsurance;
  253. parameter[15].Value = w.SickLeave;
  254. parameter[16].Value = w.SomethingFalse;
  255. parameter[17].Value = w.LateTo;
  256. parameter[18].Value = w.LeaveEarly;
  257. parameter[19].Value = w.Absenteeism;
  258. parameter[20].Value = w.NotPunch;
  259. parameter[21].Value = w.OtherDeductions;
  260. parameter[22].Value = w.Should;
  261. parameter[23].Value = w.TotalDeductions;
  262. parameter[24].Value = w.TotalRealHair;
  263. parameter[25].Value = w.Tax;
  264. parameter[26].Value = w.AfterTax;
  265. parameter[27].Value = w.IsLock;
  266. parameter[28].Value = w.Remark;
  267. parameter[29].Value = w.Operators;
  268. parameter[30].Value = w.OperatorsDate;
  269. parameter[31].Value = w.Id;
  270. parameter[32].Value = w.Mealsupplement;
  271. parameter[33].Value = w.Gongjijin;
  272. parameter[34].Value = w.GroupCost;
  273. if (parameter != null)
  274. {
  275. foreach (SqlParameter item in parameter)
  276. {
  277. cmd.Parameters.Add(item);
  278. }
  279. }
  280. //SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter);
  281. cmd.ExecuteNonQuery();
  282. cmd.Parameters.Clear();
  283. }
  284. trans.Commit();
  285. cmd.Connection.Close();
  286. cmd.Connection.Dispose();
  287. return true;
  288. }
  289. catch
  290. {
  291. trans.Rollback();
  292. cmd.Connection.Close();
  293. cmd.Connection.Dispose();
  294. return false;
  295. }
  296. }
  297. /// <summary>
  298. /// 更改锁定状态
  299. /// </summary>
  300. /// <param name="isLock"></param>
  301. /// <returns></returns>
  302. public bool UpdateWageIsLock(int isLock, string idStr)
  303. {
  304. if (SqlHelper.ExecuteNonQuery("update Wage set IsLock = @IsLock where Id in (" + idStr + ")", CommandType.Text, new SqlParameter("@IsLock", isLock)) > 0)
  305. return true;
  306. return false;
  307. }
  308. /// <summary>
  309. /// 删除
  310. /// </summary>
  311. /// <param name="id"></param>
  312. /// <returns></returns>
  313. public bool DelWage(int id)
  314. {
  315. if (SqlHelper.ExecuteNonQuery("update Wage set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  316. return true;
  317. return false;
  318. }
  319. }
  320. }