LogicHandler.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 AccessDBHelper 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. public static void SendDataToPLC(SerialPortWithTag PLC, string Movement)
  36. {
  37. DataTable dt = (DataTable)adh.ExecuteSql("select * from plcinstruct", "select");
  38. if (dt.Rows.Count > 0)
  39. {
  40. string DevStart = dt.Rows[0][Movement].ToString();
  41. byte[] newbyte = new byte[1];
  42. newbyte[0] = (byte)Convert.ToInt32(DevStart, 16);
  43. PLC.Write(newbyte, 0, 1);
  44. }
  45. }
  46. public static void GetBarCode(string iPIID, string iPDID, int BarCodeNum, out string oBarCode)
  47. {
  48. oBarCode = "";
  49. string[] param = new string[] { iPIID, iPDID, BarCodeNum.ToString(), "", "", "", "", "", "", oBarCode };
  50. dh.CallProcedure("GETCUSTBARCODERULE", ref param);
  51. oBarCode = param[9];
  52. }
  53. /// <summary>
  54. /// 获取十六进制字节数组
  55. /// </summary>
  56. /// <param name="Data"></param>
  57. /// <returns></returns>
  58. public static byte[] SendPLCData(string Data)
  59. {
  60. byte[] arr = new byte[1];
  61. arr[0] = (byte)Convert.ToInt32(Data, 16);
  62. return arr;
  63. }
  64. /// <summary>
  65. /// 检测数据库未上传的数据,根据设置的上传条数上传数据
  66. /// </summary>
  67. /// <param name="iInoutno"></param>
  68. public static bool CheckUploadData(string iInoutno, int iUploadNum)
  69. {
  70. DataTable dt = (DataTable)adh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_lotno,pib_ifmodify,pib_datecode,pib_ifpick,-1 as pib_ifupload,pib_ifprint,pib_ifrecheck from prodiobarcode where pib_inoutno='" + iInoutno + "' and pib_ifupload=0 and pib_ifrecheck=-1", "select");
  71. //如果本地需要上传的数据已经达到了需要上传的条数
  72. if (iUploadNum <= dt.Rows.Count)
  73. {
  74. //上传数据
  75. dh.SaveDataTable(dt, "prodiobarcode", "pib_id");
  76. //更新本地数据为已上传
  77. if (adh.UpdateByCondition("prodiobarcode", "pib_ifupload=-1", "pib_inoutno='" + iInoutno + "' and pib_ifrecheck=-1 and pib_ifupload<>-1") > 0)
  78. {
  79. return true;
  80. }
  81. }
  82. return false;
  83. }
  84. }
  85. }