OvertimeApplicationService.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.SqlClient;
  6. using Models;
  7. using System.Data;
  8. using System.Runtime.InteropServices.ComTypes;
  9. using System.Security.Cryptography;
  10. namespace DAL
  11. {
  12. /// <summary>
  13. /// 加班申请数据访问层
  14. /// </summary>
  15. public class OvertimeApplicationService
  16. {
  17. /// <summary>
  18. /// 新增考勤补卡
  19. /// </summary>
  20. /// <param name="ota"></param>
  21. /// <returns></returns>
  22. public bool AddOvertimeApplication(OvertimeApplication ota)
  23. {
  24. string sql = "INSERT INTO OvertimeApplication(UID,OverDate,StardTime,EndTime,ObjectiveTime,SubjectiveTime,Reason,MAudio,IsAudio,AudioMan,AudioTime,Remark,IsDel,Did,OvertimeType)"
  25. + " VALUES(@UID,@OverDate,@StardTime,@EndTime,@ObjectiveTime,@SubjectiveTime,@Reason,@MAudio,@IsAudio,@AudioMan,@AudioTime,@Remark,@IsDel,@Did,@OvertimeType)";
  26. SqlParameter[] parameter = new SqlParameter[]{
  27. new SqlParameter("@UID",ota.UID),
  28. new SqlParameter("@OverDate",ota.OverDate),
  29. new SqlParameter("@StardTime",ota.StardTime),
  30. new SqlParameter("@EndTime",ota.EndTime),
  31. new SqlParameter("@ObjectiveTime",ota.ObjectiveTime),
  32. new SqlParameter("@SubjectiveTime",ota.SubjectiveTime),
  33. new SqlParameter("@Reason",ota.Reason),
  34. new SqlParameter("@MAudio",ota.MAudio),
  35. new SqlParameter("@IsAudio",ota.IsAudio),
  36. new SqlParameter("@AudioMan",ota.AudioMan),
  37. new SqlParameter("@AudioTime",ota.AudioTime),
  38. new SqlParameter("@Remark",ota.Remark),
  39. new SqlParameter("@IsDel",ota.IsDel),
  40. new SqlParameter("@Did",ota.Did),
  41. new SqlParameter("@OvertimeType",ota.OvertimeType)
  42. };
  43. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) <= 0)
  44. return false;
  45. return true;
  46. }
  47. /// <summary>
  48. /// 根据用户ID,人事审核状态查询
  49. /// 获取全部有效新增考勤补卡数据
  50. /// </summary>
  51. /// <returns></returns>
  52. public List<OvertimeApplication> GetAll(int UID, DateTime StartDate, DateTime EndDate, int IsAudio, int MAudit, int Did, int OvertimeType)
  53. {
  54. string sql = "select * from OvertimeApplication Where Uid = '" + UID + "' and (OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "') " + "and IsAudio=" + IsAudio + " and MAudio =" + MAudit + " and IsDel = 0";
  55. if (OvertimeType != 0)
  56. sql = sql + " and OvertimeType = " + OvertimeType;
  57. return excuteSql(sql);
  58. }
  59. /// <summary>
  60. /// 根据用户ID,起止时间,人事审核状态,经理审核状态,团组did查询
  61. /// 根据条件查询条件获取 - 分页
  62. /// </summary>
  63. /// <param name="pageIndex"></param>
  64. /// <param name="sumPage"></param>
  65. /// <param name="totalRecord"></param>
  66. /// <param name="dataType"></param>
  67. /// <returns></returns>
  68. public List<OvertimeApplication> GetAll(int pageIndex, out int sumPage, out int totalRecord, int UID, DateTime StartDate, DateTime EndDate, int IsAudio, int MAudit, int Did, int userID, int OvertimeType)
  69. {
  70. string sqlcmd = "select * from OvertimeApplication where MAudio=" + MAudit + " and IsAudio=" + IsAudio + " and (OverDate between '" + StartDate + "' and '" + EndDate + "')" + " and IsDel=0";
  71. if (UID > 0)
  72. {
  73. sqlcmd = sqlcmd + " and UID = " + UID;
  74. }
  75. if (Did > 0 && Did != 99 && Did != 3)
  76. {
  77. sqlcmd = sqlcmd + " and Did=" + Did;
  78. }
  79. string sqlwhere = "";
  80. //"1=1 and OverDate >= '"+StartDate+"' and OverDate <='"+EndDate+"' and IsAudio="+IsAudio;
  81. //if (UID > 0 && UID!=21 && UID!=41)
  82. // sqlwhere = sqlwhere+" and UID = "+UID;
  83. //if (Did > 0 && Did!=99 && Did!=3)
  84. // sqlwhere = sqlwhere + " and Did=" + Did;
  85. //if (userID == 21)
  86. // sqlwhere = sqlwhere + " and UID in (10,16,18,22,37,5,11,41)";
  87. //sqlwhere =sqlwhere+ " and IsDel = 0";
  88. //if (Status == "Maudit")
  89. //{
  90. sqlwhere = sqlwhere + "1=1 and OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "' and MAudio=" + MAudit + "and IsAudio=" + IsAudio;
  91. //}
  92. //else
  93. //{
  94. //sqlwhere = sqlwhere + "1=1 and OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "'and IsAudio=" + IsAudio;
  95. //}
  96. if (UID > 0)
  97. {
  98. sqlwhere = sqlwhere + " and UID = " + UID;
  99. }
  100. if (Did > 0 && Did != 99 && Did != 3)
  101. {
  102. sqlwhere = sqlwhere + " and Did=" + Did;
  103. }
  104. if (OvertimeType != 0)
  105. {
  106. sqlwhere = sqlwhere + " and OvertimeType=" + OvertimeType;
  107. }
  108. sqlwhere = sqlwhere + " and IsDel = 0";
  109. return PageBase<OvertimeApplication>.excutePageSql(new OvertimeApplication(), "OvertimeApplication", "OvertimeApplication", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  110. }
  111. /// <summary>
  112. /// 根据用户ID,起止时间,人事审核状态,未知status,未知did查询
  113. /// 根据条件查询条件获取 - 分页
  114. /// </summary>
  115. /// <param name="pageIndex"></param>
  116. /// <param name="sumPage"></param>
  117. /// <param name="totalRecord"></param>
  118. /// <param name="dataType"></param>
  119. /// <returns></returns>
  120. public List<OvertimeApplication> GetAll(int pageIndex, out int sumPage, out int totalRecord, int UID, DateTime StartDate, DateTime EndDate, int IsAudio, int Did, int userID)
  121. {
  122. string sqlwhere = "1=1 and OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "' and IsAudio=" + IsAudio;
  123. //if (UID > 0 && UID!=21 && UID!=41)
  124. // sqlwhere = sqlwhere+" and UID = "+UID;
  125. //if (Did > 0 && Did!=99 && Did!=3)
  126. // sqlwhere = sqlwhere + " and Did=" + Did;
  127. //if (userID == 21)
  128. // sqlwhere = sqlwhere + " and UID in (10,16,18,22,37,5,11,41)";
  129. //sqlwhere =sqlwhere+ " and IsDel = 0";
  130. if (UID > 0)
  131. {
  132. sqlwhere = sqlwhere + " and UID = " + UID;
  133. }
  134. if (Did > 0 && Did != 99 && Did != 3)
  135. sqlwhere = sqlwhere + " and Did=" + Did;
  136. sqlwhere = sqlwhere + " and IsDel = 0";
  137. return PageBase<OvertimeApplication>.excutePageSql(new OvertimeApplication(), "OvertimeApplication", "OvertimeApplication", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  138. }
  139. /// <summary>
  140. /// 根据用户ID,起止时间查询
  141. /// 根据条件查询条件获取 - 所有
  142. /// </summary>
  143. /// <param name="pageIndex"></param>
  144. /// <param name="sumPage"></param>
  145. /// <param name="totalRecord"></param>
  146. /// <param name="dataType"></param>
  147. /// <returns></returns>
  148. public double GetAll(int did, int uid, string startDate, string endDate)
  149. {
  150. SqlParameter[] parameter = new SqlParameter[]
  151. {
  152. new SqlParameter("@did",did),
  153. new SqlParameter("@uid",uid),
  154. new SqlParameter("@startTime",startDate),
  155. new SqlParameter("@endTime",endDate)
  156. };
  157. DataTable dt = SqlHelper.TransferProcedure("Leavel_Hourse_Count", CommandType.StoredProcedure, parameter);
  158. if (dt != null && dt.Rows.Count > 0)
  159. {
  160. try
  161. {
  162. return Convert.ToDouble(dt.Rows[0]["Hourse"]);
  163. }
  164. catch
  165. {
  166. return 0.00;
  167. }
  168. }
  169. else
  170. return 0.00;
  171. }
  172. //public double GetJBDX(int uid, string startDate, string endDate) {
  173. // string sql="select sum(ucac.UpCardHours) as JBDXT from UpCardAudit ucajoin UpCardAuditContent ucac on uca.id = ucac.UCAid where uca.isDel = 0 and ucac.isdel=0 and ucac.Did = 281 and isAudit = 1 and uid ="+ uid +"and (uca.YearMonth between '"+ startDate +" and '"+ endDate +"')";
  174. // SqlHelper.ExecuteNonQuery(sql, CommandType.Text, null);
  175. // return 0.00;
  176. //}
  177. /// <summary>
  178. ///加班抵休或者年假抵休的时间
  179. /// </summary>
  180. /// <param name="did">抵休原因</param>
  181. /// <param name="uid">用户ID</param>
  182. /// <param name="startDate">起始日</param>
  183. /// <param name="endDate">终止日</param>
  184. /// <returns></returns>
  185. public double GetDX(int did, int uid, string startDate, string endDate)
  186. {
  187. SqlParameter[] parameter = new SqlParameter[]
  188. {
  189. new SqlParameter("@did",did),
  190. new SqlParameter("@uid",uid),
  191. new SqlParameter("@startTime",startDate),
  192. new SqlParameter("@endTime",endDate)
  193. };
  194. DataTable dt = SqlHelper.TransferProcedure("JBDX_Count", CommandType.StoredProcedure, parameter);
  195. if (dt != null && dt.Rows.Count > 0)
  196. {
  197. try
  198. {
  199. return Convert.ToDouble(dt.Rows[0]["Xtime"]);
  200. }
  201. catch
  202. {
  203. return 0.00;
  204. }
  205. }
  206. else
  207. return 0.00;
  208. }
  209. /// <summary>
  210. /// 逻辑删除
  211. /// </summary>
  212. /// <param name="p"></param>
  213. public bool DelOvertimeApplication(int id)
  214. {
  215. string sql = "delete from OvertimeApplication where id=" + id;
  216. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, null) > 0)
  217. return true;
  218. return false;
  219. }
  220. /// <summary>
  221. /// 根据数据ID查询
  222. /// </summary>
  223. /// <param name="id"></param>
  224. /// <returns></returns>
  225. public OvertimeApplication GetAllByID(int id)
  226. {
  227. string sql = "select * from OvertimeApplication where id=" + id;
  228. return excuteType(sql, null);
  229. }
  230. /// <summary>
  231. /// 查询所有
  232. /// </summary>
  233. /// <param name="sql">sql语句</param>
  234. /// <param name="param">可变参数数组</param>
  235. /// <returns>返回集合</returns>
  236. List<OvertimeApplication> excuteSql(string sql, params SqlParameter[] param)
  237. {
  238. return ServiceBase<OvertimeApplication>.excuteSql(new OvertimeApplication(), "OvertimeApplication", sql, CommandType.Text, param);
  239. }
  240. /// <summary>
  241. /// 获取单个对象
  242. /// </summary>
  243. /// <param name="sql">sql语句</param>
  244. /// <param name="param">可变参数数组</param>
  245. /// <returns>返回空或者单个对象</returns>
  246. OvertimeApplication excuteType(string sql, params SqlParameter[] param)
  247. {
  248. //查询结果放入对象集合
  249. List<OvertimeApplication> cList = excuteSql(sql, param);
  250. //判断集合是否为空
  251. if (cList == null || cList.Count == 0)
  252. //返回null
  253. return null;
  254. //返回单个对象
  255. return cList[0];
  256. }
  257. /// <summary>
  258. /// 修改加班申请
  259. /// </summary>
  260. /// <param name="oat"></param>
  261. /// <returns></returns>
  262. public bool EditOvertimeApplication(OvertimeApplication oat, int id)
  263. {
  264. string sql = "update OvertimeApplication set OverDate=@OverDate,StardTime=@StardTime,EndTime=@EndTime,ObjectiveTime=@ObjectiveTime,SubjectiveTime=@SubjectiveTime,Reason=@Reason,Remark=@Remark,Did=@Did,OvertimeType=@OvertimeType where ID=" + id;
  265. SqlParameter[] parameter = new SqlParameter[]
  266. {
  267. new SqlParameter("@OverDate",oat.OverDate),
  268. new SqlParameter("@StardTime",oat.StardTime),
  269. new SqlParameter("@ObjectiveTime",oat.ObjectiveTime),
  270. new SqlParameter("@SubjectiveTime",oat.SubjectiveTime),
  271. new SqlParameter("@EndTime",oat.EndTime),
  272. new SqlParameter("@Reason",oat.Reason),
  273. new SqlParameter("@Remark",oat.Remark),
  274. new SqlParameter("@Did",oat.Did),
  275. new SqlParameter("@OvertimeType",oat.OvertimeType)
  276. };
  277. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  278. return true;
  279. return false;
  280. }
  281. /// <summary>
  282. /// 人事审核
  283. /// </summary>
  284. /// <param name="state"></param>
  285. /// <param name="id"></param>
  286. /// <returns></returns>
  287. public bool AuditOvertimeApplication(int state, int id, string name, DateTime Now)
  288. {
  289. string sql = "update OvertimeApplication set IsAudio=" + state + " ,AudioMan='" + name + "',AudioTime='" + Now + "' where ID=" + id;
  290. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, null) > 0)
  291. return true;
  292. return false;
  293. }
  294. /// <summary>
  295. /// 部门经理审核
  296. /// </summary>
  297. /// <param name="state"></param>
  298. /// <param name="id"></param>
  299. /// <param name="name"></param>
  300. /// <param name="Now"></param>
  301. /// <returns></returns>
  302. public bool Maudit(int state, int id, string name, DateTime Now)
  303. {
  304. string sql = "update OvertimeApplication set MAudio=" + state + " ,AudioMan='" + name + "',AudioTime='" + Now + "' where ID=" + id;
  305. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, null) > 0)
  306. return true;
  307. return false;
  308. }
  309. public List<OvertimeApplication> GetAfterSixMonth()
  310. {
  311. return excuteSql("select * from OvertimeApplication WHERE iSDEL = 0 and OverDate>= '2021-06-01' order by OverDate");
  312. //return excuteSql("select * from OvertimeApplication Where (OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "') " + "and IsAudio=" + IsAudio + " and MAudio =" + MAudit + " and IsDel = 0");
  313. }
  314. public List<OvertimeApplication> GetUnreviewedOvertime(string uids)
  315. {
  316. string sql = " select * from OvertimeApplication where isdel = 0 and isAudio = 0 and uid in("+ uids +")";
  317. return excuteSql(sql);
  318. }
  319. }
  320. }