ResetPosFirstFlagAndIsExecuteService.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5. using System.Data;
  6. using MySystem;
  7. using MySystem.Models;
  8. using Library;
  9. using LitJson;
  10. /// <summary>
  11. /// 每月1号重置机具首个标记和是否执行首个标记
  12. /// </summary>
  13. public class ResetPosFirstFlagAndIsExecuteService
  14. {
  15. public readonly static ResetPosFirstFlagAndIsExecuteService Instance = new ResetPosFirstFlagAndIsExecuteService();
  16. private ResetPosFirstFlagAndIsExecuteService()
  17. {
  18. }
  19. public void Start()
  20. {
  21. Thread th = new Thread(doSomething);
  22. th.IsBackground = true;
  23. th.Start();
  24. }
  25. private void doSomething()
  26. {
  27. while (true)
  28. {
  29. try
  30. {
  31. DataTable dt = CustomerSqlConn.dtable("UPDATE PosMachinesTwo SET FirstFlag=1,IsExecute=1 WHERE IsExecute=0 AND Id IN(SELECT Id FROM(SELECT c.Id FROM(SELECT MerIdcardNo,MIN(Id) Id FROM PosMerchantInfo WHERE MerIdcardNo IS NOT NULL AND MerIdcardNo !='' AND MerIdcardNo NOT LIKE '%*%' GROUP BY MerIdcardNo)a LEFT JOIN (SELECT Id,MerIdcardNo,KqSnNo FROM PosMerchantInfo WHERE MerIdcardNo IS NOT NULL AND MerIdcardNo !='' AND MerIdcardNo NOT LIKE '%*%')b ON a.Id=b.Id LEFT JOIN (SELECT Id,PosSn FROM PosMachinesTwo) c ON b.KqSnNo=c.PosSn)d)", MysqlConn.SqlConnStr);
  32. }
  33. catch (Exception ex)
  34. {
  35. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "每月1号重置机具首个标记和是否执行首个标记线程异常");
  36. }
  37. Thread.Sleep(600000);
  38. }
  39. }
  40. }