LogicHandler.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Data;
  3. using UAS_LabelMachine.CustomControl;
  4. using UAS_LabelMachine.Entity;
  5. namespace UAS_LabelMachine.PublicMethod
  6. {
  7. class LogicHandler
  8. {
  9. static SqliteDBHelper adh = SystemInf.adh;
  10. static DataHelper dh = SystemInf.dh;
  11. /// <summary>
  12. /// 更新为已复核
  13. /// </summary>
  14. /// <param name="iPibID"></param>
  15. public static void UpdateRowRechecked(object iPibID)
  16. {
  17. adh.UpdateByCondition("prodiobarcode", "pib_ifcheck=-1", "pib_id=" + iPibID);
  18. }
  19. /// <summary>
  20. /// 更新为已打印
  21. /// </summary>
  22. /// <param name="iPibID"></param>
  23. public static void UpdateRowPrinted(object iPibID)
  24. {
  25. adh.UpdateByCondition("prodiobarcode", "pib_ifprint=-1", "pib_id=" + iPibID);
  26. }
  27. /// <summary>
  28. /// 更新为已采集
  29. /// </summary>
  30. /// <param name="iPibID"></param>
  31. public static void UpdateRowPicked(object iPibID)
  32. {
  33. adh.UpdateByCondition("prodiobarcode", "pib_ifpick=-1,pib_modify=-1", "pib_id=" + iPibID);
  34. }
  35. /// <summary>
  36. /// 根据对应的动作查找字段发送指令
  37. /// </summary>
  38. /// <param name="PLC"></param>
  39. /// <param name="Movement"></param>
  40. public static void SendDataToPLC(SerialPortWithTag PLC, string Movement, SqliteDBHelper adh)
  41. {
  42. DataTable dt = (DataTable)adh.ExecuteSql("select * from plcinstruct", "select");
  43. if (PLC.IsOpen && dt.Rows.Count > 0)
  44. {
  45. string DevStart = dt.Rows[0][Movement].ToString();
  46. byte[] newbyte = new byte[1];
  47. newbyte[0] = (byte)Convert.ToInt32(DevStart == "" ? "0" : DevStart, 16);
  48. PLC.Write(newbyte, 0, 1);
  49. }
  50. }
  51. public static void GetBarCode(string iPIID, string iPDID, int BarCodeNum, out string oBarCode)
  52. {
  53. oBarCode = "";
  54. string[] param = new string[] { iPIID, iPDID, BarCodeNum.ToString(), "", "", "", "", "", "", oBarCode };
  55. dh.CallProcedure("GETCUSTBARCODERULE", ref param);
  56. oBarCode = param[9];
  57. }
  58. public static void GetTimeFromDatecode(DataHelper dh, string iDatecode, string iCustcode, out string oYear, out string oMonth, out string oDay, out string oDate)
  59. {
  60. oYear = "0";
  61. oMonth = "0";
  62. oDay = "0";
  63. oDate = "19000101";
  64. string[] param = new string[] { iDatecode, iCustcode, oYear, oMonth, oDay, oDate };
  65. dh.CallProcedure("GETTIMEFROMDATECODE", ref param);
  66. oYear = param[2];
  67. oMonth = param[3];
  68. oDay = param[4];
  69. oDate = param[5];
  70. }
  71. /// <summary>
  72. /// 获取十六进制字节数组
  73. /// </summary>
  74. /// <param name="Data"></param>
  75. /// <returns></returns>
  76. public static byte[] SendPLCData(string Data)
  77. {
  78. byte[] arr = new byte[1];
  79. arr[0] = (byte)Convert.ToInt32(Data, 16);
  80. return arr;
  81. }
  82. /// <summary>
  83. /// 检测数据库未上传的数据,根据设置的上传条数上传数据
  84. /// </summary>
  85. /// <param name="iInoutno"></param>
  86. public static bool CheckUploadData(string iInoutno, int iUploadNum)
  87. {
  88. DataTable dt = (DataTable)adh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifmodify,pib_ifupload,pib_ifpick,pib_ifprint,pib_ifrecheck,pib_year,pib_month,pib_day from prodiobarcode where pib_inoutno='" + iInoutno + "' ", "select");
  89. DataTable upload = BaseUtil.filterDataTable(dt, "pib_ifupload=0 and pib_ifrecheck=-1");
  90. DataTable unupload = BaseUtil.filterDataTable(dt, "pib_ifpick=0");
  91. //如果本地需要上传的数据已经达到了需要上传的条数或者已经采集完了最后一条数据
  92. for (int i = 0; i < upload.Rows.Count; i++)
  93. {
  94. upload.Rows[i]["pib_ifupload"] = -1;
  95. }
  96. if (iUploadNum <= upload.Rows.Count || unupload.Rows.Count == 0)
  97. {
  98. dh.CallProcedure("sp_uploadbarcode", upload);
  99. //更新本地数据为已上传
  100. if (adh.UpdateByCondition("prodiobarcode", "pib_ifupload=-1", "pib_inoutno='" + iInoutno + "' and pib_ifrecheck=-1 and pib_ifupload<>-1") > 0)
  101. {
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. /// <summary>
  108. /// 检测数据库未上传的数据,根据设置的上传条数上传数据
  109. /// </summary>
  110. /// <param name="iInoutno"></param>
  111. public static bool CheckUploadData(string iInoutno)
  112. {
  113. DataTable dt = (DataTable)adh.ExecuteSql("select count(1) from prodiobarcode where pib_inoutno='" + iInoutno + "' and pib_ifupload=0 and pib_ifrecheck=-1 ", "select");
  114. if (dt.Rows[0][0].ToString() != "")
  115. {
  116. int rowcount = int.Parse(dt.Rows[0][0].ToString());
  117. for (int i = 0; i < rowcount; i++)
  118. {
  119. if (i % 100 == 0 || i == rowcount - 1)
  120. {
  121. dt = (DataTable)adh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifmodify,-1 as pib_ifupload,pib_ifpick,pib_ifprint,pib_ifrecheck,pib_year,pib_month,pib_day from prodiobarcode where pib_inoutno='" + iInoutno + "' and pib_ifupload=0 and pib_ifrecheck=-1 limit " + 150, "select");
  122. string pibid = "";
  123. if (dt.Rows.Count > 0)
  124. {
  125. dh.CallProcedure("sp_uploadbarcode", dt, out pibid);
  126. dt = (DataTable)dh.ExecuteSql("select count(1) from prodiobarcode where pib_inoutno='" + iInoutno + "' and pib_ifupload=0", "select");
  127. if (dt.Rows.Count > 0)
  128. {
  129. //全部数据上传之后更新单据状态
  130. if (int.Parse(dt.Rows[0][0].ToString()) == 0)
  131. {
  132. dh.ExecuteSql("update prodinout set pi_pdastatus='已复核' where pi_inoutno='" + iInoutno + "'", "update");
  133. }
  134. }
  135. //更新本地数据为已上传
  136. if (adh.UpdateByCondition("prodiobarcode", "pib_ifupload=-1", "pib_id in (" + pibid + ")") > 0)
  137. {
  138. //return true;
  139. }
  140. }
  141. }
  142. }
  143. }
  144. return true;
  145. }
  146. }
  147. }