GlobalContext.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. using System;
  2. using System.Data;
  3. using StandardLibrary;
  4. using MainForm.Models;
  5. using MainForm.DbHelper;
  6. using MainForm.ClassFile.ProjectClass;
  7. namespace MainForm
  8. {
  9. /// <summary>
  10. /// 全局变量
  11. /// </summary>
  12. public class GlobalContext
  13. {
  14. #region 变量
  15. //消息委托和事件
  16. public static Action Set; // 更新UI的委托方法
  17. public static Action Save; // 保存的委托方法
  18. public static Action Close; // 关闭的委托方法
  19. /// <summary>
  20. /// 日志文件保存位置
  21. /// </summary>
  22. public static string FilePath = AppDomain.CurrentDomain.BaseDirectory + "Config.ini";
  23. public static string MainDir = @"D:\MESFile\";
  24. public static string WorkLogDir = MainDir + @"WorkLog\"; // 运行日志
  25. public static string PlcLogDir = MainDir + @"PLCLog\"; // plc写入日志
  26. public static string MqttLogDir = MainDir + @"MqttLog\"; // mqtt日志
  27. public static string ProcessDataDir = MainDir + @"ProcessData\"; // 加工数据日志
  28. public static string OneCheckDataDir = MainDir + @"OneCheckData\"; // 点检数据日志
  29. public static string SQLLogDir = MainDir + @"SQLLog\"; // sql日志
  30. public static string DBDir = @"D:\LocalDataBase\";
  31. public static string MESConfig = MainDir + @"MESConfig.ini"; // MES接口的配置文件
  32. public static string MqttServerPath = AppDomain.CurrentDomain.BaseDirectory + @"\ThingsMode\MqttServer.exe";
  33. public static string MqttServerName = "MqttServer";
  34. /// <summary>
  35. /// 点检数据文件
  36. /// </summary>
  37. public static string CheckOneDataPath = AppDomain.CurrentDomain.BaseDirectory + "CheckOneData.ini";
  38. // 产线及产品信息
  39. public static string Project_Code; // 项⽬编码
  40. public static string Factory_Code; // ⼯⼚ID
  41. public static string Process_Section_Code; // ⼯段编码
  42. public static string LineCode; // 线体编码
  43. public static string LineName; // 线体名称
  44. public static string ProgramName; // 程序名
  45. public static string WorkOrderCode; // 车间订单号
  46. public static string BatchNumber; // 批次号(splcode)
  47. public static string Mtltmrk; // 产品型号(mtltmrk)
  48. public static string S1_work_station; // [S1] ⼯站
  49. public static string S1_device_code; // [S1] 装备编码
  50. public static string S1_station; // [S1] ⼯位Id
  51. public static string S2_work_station; // [S2] ⼯站
  52. public static string S2_device_code; // [S2] 装备编码
  53. public static string S2_station; // [S2] ⼯位Id
  54. public static string S3_work_station; // [S3] ⼯站
  55. public static string S3_device_code; // [S3] 装备编码
  56. public static string S3_station; // [S3] ⼯位Id
  57. public static string S4_1_work_station; // [S4_1] ⼯站
  58. public static string S4_1_device_code; // [S4_1] 装备编码
  59. public static string S4_1_station; // [S4_1] ⼯位Id
  60. public static string S4_3_work_station; // [S4_3] ⼯站
  61. public static string S4_3_device_code; // [S4_3] 装备编码
  62. public static string S4_3_station; // [S4_3] ⼯位Id
  63. public static string S4_4_work_station; // [S4_4] ⼯站
  64. public static string S4_4_device_code; // [S4_4] 装备编码
  65. public static string S4_4_station; // [S4_4] ⼯位Id
  66. public static string S4_5_work_station; // [S4_5] ⼯站
  67. public static string S4_5_device_code; // [S4_5] 装备编码
  68. public static string S4_5_station; // [S4_5] ⼯位Id
  69. public static string S5_work_station; // [S5] ⼯站
  70. public static string S5_device_code; // [S5] 装备编码
  71. public static string S5_station; // [S5] ⼯位Id
  72. // 设备
  73. //public static string PCAddress="192.168.1.244";
  74. public static bool IsUsePLC1;
  75. public static bool IsUsePLC2;
  76. public static bool IsUsePLC3;
  77. public static bool IsUsePLC4;
  78. public static bool IsUsePLC5;
  79. public static bool IsUsePLC6;
  80. public static bool IsUsePLC7;
  81. public static bool IsUsePLC8;
  82. public static bool IsUsePLC9;
  83. public static string Machine1Address;
  84. public static string Machine2Address;
  85. public static string Machine3Address;
  86. public static string Machine4Address;
  87. public static string Machine5Address;
  88. public static string Machine6Address;
  89. public static string Machine7Address;
  90. public static string Machine8Address;
  91. public static string Machine9Address;
  92. public static string PC1Address;
  93. public static string PC2Address;
  94. public static string PC3Address;
  95. public static string PC4Address;
  96. public static string PC5Address;
  97. public static string PC6Address;
  98. public static string PC7Address;
  99. public static string PC8Address;
  100. public static string PC9Address;
  101. public static int MachinePort;
  102. // TCP
  103. public static string QrCodeTCPAddress1;
  104. public static int QrCodeTCPPort1;
  105. public static string QrCodeTCPAddress2;
  106. public static int QrCodeTCPPort2;
  107. public static string QrCodeTCPAddress3;
  108. public static int QrCodeTCPPort3;
  109. public static string QrCodeTCPAddress4;
  110. public static int QrCodeTCPPort4;
  111. public static string QrCodeTCPAddress5;
  112. public static int QrCodeTCPPort5;
  113. // MES
  114. public static bool IsUseMES; // 是否 启用MES
  115. public static string MESAppId; // 应用ID;mes_test
  116. public static string MESAppKey; // API接口名称;mes
  117. public static string MESUserId; // 用户ID
  118. public static string ServerHost; // 主服务器地址
  119. public static string StationInMESUrl; // 入站接口Url
  120. public static string StationOutMESUrl; // 出站接口Url
  121. public static string ServerIp; // 主服务器IP-解析所得
  122. //public static string StationInMESUrl; // 入站接口Url
  123. //public static string StationOutMESUrl; // 出站接口Url
  124. public static bool IsSendStationIn; // 启用上传进站
  125. public static bool IsSendProcessData; // 启用上传出站
  126. public static bool IsSendCheckOneData; // 启用上传点检
  127. public static bool IsSendWorkingData; // 启用上传状态
  128. public static bool IsSendAlarmData; // 启用上传报警
  129. public static bool IsUseMESRoute; // 启用边线MES软件
  130. public static bool MESIsConnect; // MES是否正常连接
  131. // IOT - MQTT
  132. public static bool IsUseIot; // 是否 启用IOT
  133. public static string MQTTServerHost; // 服务器IP
  134. public static int MQTTServerPort; // 服务器Port
  135. public static bool IsMqttSendProcessData; // 上传过站数据
  136. public static bool IsMqttDeviceState; // 上传设备状态
  137. public static bool IsMqttFaultLog; // 上传故障⽇志
  138. public static bool IsMqttSensorData; // 上传传感器数据
  139. public static bool IsMqttStationInputBegin; // 上传节拍⽇志
  140. public static bool IsMqttOperateLog; // 上传操作记录
  141. public static bool IsMqttEquiConfig; // 上传装备配置
  142. public static bool IsMqttProcConfig; // 上传⼯艺配置
  143. // IOT-AGV
  144. public static bool IsUseAGV; // 是否 启用AGV
  145. public static string AGVHttpHost; // Http 服务器地址
  146. public static string AGVHttpIp; // Http IP地址
  147. public static string AGVMQTTHost; // MQTT IP地址
  148. public static int AGVMQTTPort; // MQTT端口
  149. public static string AGVMQTTDeviceCode; // MQTT设备Code
  150. public static bool AGVMQTTIsConnect; // AGV MQTT是否正常连接
  151. // MES进出站 配置信息
  152. public static string S1_MachineId; // 工站1 - 壳体清洁上料装备
  153. public static string S1_StationId; // 工站1 - 壳体清洁上料装备
  154. public static string S2_MachineId; // 工站2 - 上盖板上料装备
  155. public static string S2_StationId; // 工站2 - 上盖板上料装备
  156. public static string S3_MachineId; // 工站3 - 点散热胶装备
  157. public static string S3_StationId; // 工站3 - 点散热胶装备
  158. public static string S3_StationId_1; // 工站3 - 点散热胶装备
  159. public static string S3_StationId_2; // 工站3 - 点散热胶装备
  160. public static string S4_MachineId; // 工站4 - 胶线检测装备
  161. public static string S4_StationId; // 工站4 - 胶线检测装备
  162. public static string S5_MachineId; // 工站5 - ADD板上料组装装备
  163. public static string S5_StationId; // 工站5 - ADD板上料组装装备
  164. public static string S6_MachineId; // 工站6 - 组上盖板装备
  165. public static string S6_StationId; // 工站6 - 组上盖板装备
  166. public static string S7_MachineId; // 工站7 - 上盖板锁螺丝装备
  167. public static string S7_StationId; // 工站7 - 上盖板锁螺丝装备
  168. public static string S7_StationId_1; // 工站7 - 上盖板锁螺丝装备
  169. public static string S7_StationId_2; // 工站7 - 上盖板锁螺丝装备
  170. public static string S8_MachineId; // 工站8 - NG下料装备
  171. public static string S8_StationId; // 工站8 - NG下料装备
  172. public static string S9_MachineId; // 工站9 - 产品下料装备
  173. public static string S9_StationId; // 工站9 - 产品下料装备
  174. // 本地数据库
  175. public static string Server;
  176. public static string User;
  177. public static string PassWord;
  178. //其它
  179. public static string CurrentUser = "";
  180. public static string MacStr = "";
  181. #region 是否可连接PLC-用户手动控制用(后加)
  182. public static bool _IsCon_Funs1 = true;
  183. public static bool _IsCon_Funs2 = true;
  184. public static bool _IsCon_Funs3 = true;
  185. public static bool _IsCon_Funs4 = true;
  186. public static bool _IsCon_Funs5 = true;
  187. public static bool _IsCon_plc1Heat = true;
  188. public static bool _IsCon_plc1Alarm = true;
  189. #endregion 是否可连接PLC-用户手动控制用(后加)
  190. #endregion 变量
  191. #region 常量
  192. //产品常量
  193. public const string ConstLineCode = "A1";
  194. public const string ConstLineName = "A1产线";
  195. public const string ConstProgramName = "A1程序名";
  196. public const string ConstSono = " ";
  197. public const string ConstWorkOrderCode = " ";
  198. public const string ConstBatchNumber = " ";
  199. public const string ConstMtltmrk = " ";
  200. public const string ConstSupplierCode = " ";
  201. //设备常量
  202. public const string ConstMachine1Address = "192.168.10.87";
  203. public const string ConstMachine2Address = "192.168.2.1";
  204. public const string ConstMachine3Address = "192.168.4.111";
  205. public const string ConstMachine4Address = "192.168.4.1";
  206. public const string ConstMachine5Address = "192.168.6.111";
  207. public const string ConstMachine6Address = "192.168.6.1";
  208. public const string ConstMachine7Address = "192.168.6.71";
  209. public const string ConstMachine8Address = "192.168.6.81";
  210. public const string ConstMachine9Address = "192.168.1.91";
  211. public const string ConstPc1Address = "192.168.1.10";
  212. public const string ConstPc2Address = "192.168.1.10";
  213. public const string ConstPc3Address = "192.168.1.10";
  214. public const string ConstPc4Address = "192.168.1.10";
  215. public const string ConstPc5Address = "192.168.1.10";
  216. public const string ConstPc6Address = "192.168.1.10";
  217. public const string ConstPc7Address = "192.168.1.10";
  218. public const string ConstPc8Address = "192.168.1.10";
  219. public const string ConstPc9Address = "192.168.1.10";
  220. public const string ConstMachinePort = "1217";
  221. //MES常量
  222. public const string ConstServerHost = "10.1.19.33:8080";
  223. public const string ConstIsSend = "false";
  224. #endregion 常量
  225. public GlobalContext()
  226. {
  227. UpdateData();
  228. }
  229. /// <summary>
  230. /// 更新全局变量
  231. /// </summary>
  232. public static void UpdateData()
  233. {
  234. try
  235. {
  236. // 产线及产品信息
  237. Project_Code = IniFile.INIGetStringValue(FilePath, "Product", "ProjectCode", "");
  238. Factory_Code = IniFile.INIGetStringValue(FilePath, "Product", "FactoryCode", "");
  239. Process_Section_Code = IniFile.INIGetStringValue(FilePath, "Product", "ProcessSectionCode", "");
  240. LineCode = IniFile.INIGetStringValue(FilePath, "Product", "LineCode", ConstLineCode);
  241. LineName = IniFile.INIGetStringValue(FilePath, "Product", "LineName", ConstLineName);
  242. ProgramName = IniFile.INIGetStringValue(FilePath, "Product", "ProgramName", ConstProgramName);
  243. WorkOrderCode = IniFile.INIGetStringValue(FilePath, "Product", "WorkOrderCode", ConstWorkOrderCode); // 车间订单号
  244. BatchNumber = IniFile.INIGetStringValue(FilePath, "Product", "BatchNumber", ConstBatchNumber); // 批次号(splcode)
  245. Mtltmrk = IniFile.INIGetStringValue(FilePath, "Product", "Mtltmrk", ConstMtltmrk); // 产品型号(mtltmrk)
  246. // 工位信息
  247. S1_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s1_work_station", ""); // [S1] ⼯站
  248. S1_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s1_device_code", ""); // [S1] 装备编码
  249. S1_station = IniFile.INIGetStringValue(FilePath, "Station", "s1_station", ""); // [S1] ⼯位Id
  250. S2_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s2_work_station", ""); // [S2] ⼯站
  251. S2_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s2_device_code", ""); // [S2] 装备编码
  252. S2_station = IniFile.INIGetStringValue(FilePath, "Station", "s2_station", ""); // [S2] ⼯位Id
  253. S3_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_work_station", ""); // [S3] ⼯站
  254. S3_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s3_device_code", ""); // [S3] 装备编码
  255. S3_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_station", ""); // [S3] ⼯位Id
  256. S4_1_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_1_work_station", ""); // [S4_1] ⼯站
  257. S4_1_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_1_device_code", ""); // [S4_1] 装备编码
  258. S4_1_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_1_station", ""); // [S4_1] ⼯位Id
  259. S4_3_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_3_work_station", ""); // [S4_3] ⼯站
  260. S4_3_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_3_device_code", ""); // [S4_3] 装备编码
  261. S4_3_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_3_station", ""); // [S4_3] ⼯位Id
  262. S4_4_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_4_work_station", ""); // [S4_4] ⼯站
  263. S4_4_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_4_device_code", ""); // [S4_4] 装备编码
  264. S4_4_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_4_station", ""); // [S4_4] ⼯位Id
  265. S4_5_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_5_work_station", ""); // [S4_5] ⼯站
  266. S4_5_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_5_device_code", ""); // [S4_5] 装备编码
  267. S4_5_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_5_station", ""); // [S4_5] ⼯位Id
  268. S5_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s5_work_station", ""); // [S5] ⼯站
  269. S5_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s5_device_code", ""); // [S5] 装备编码
  270. S5_station = IniFile.INIGetStringValue(FilePath, "Station", "s5_station", ""); // [S5] ⼯位Id
  271. // 设备
  272. IsUsePLC1 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC1", "false"));
  273. IsUsePLC2 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC2", "false"));
  274. IsUsePLC3 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC3", "false"));
  275. IsUsePLC4 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC4", "false"));
  276. IsUsePLC5 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC5", "false"));
  277. IsUsePLC6 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC6", "false"));
  278. IsUsePLC7 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC7", "false"));
  279. IsUsePLC8 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC8", "false"));
  280. IsUsePLC9 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC9", "false"));
  281. Machine1Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine1Address", ConstMachine1Address);
  282. Machine2Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine2Address", ConstMachine2Address);
  283. Machine3Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine3Address", ConstMachine3Address);
  284. Machine4Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine4Address", ConstMachine4Address);
  285. Machine5Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine5Address", ConstMachine5Address);
  286. Machine6Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine6Address", ConstMachine6Address);
  287. Machine7Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine7Address", ConstMachine7Address);
  288. Machine8Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine8Address", ConstMachine8Address);
  289. Machine9Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine9Address", ConstMachine9Address);
  290. PC1Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc1Address", ConstPc1Address);
  291. PC2Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc2Address", ConstPc2Address);
  292. PC3Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc3Address", ConstPc3Address);
  293. PC4Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc4Address", ConstPc4Address);
  294. PC5Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc5Address", ConstPc5Address);
  295. PC6Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc6Address", ConstPc6Address);
  296. PC7Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc7Address", ConstPc7Address);
  297. PC8Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc8Address", ConstPc8Address);
  298. PC9Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc9Address", ConstPc9Address);
  299. MachinePort = int.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "MachinePort", ConstMachinePort));
  300. QrCodeTCPAddress1 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress1", "127.0.0.1");
  301. QrCodeTCPPort1 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort1", "0"));
  302. QrCodeTCPAddress2 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress2", "127.0.0.1");
  303. QrCodeTCPPort2 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort2", "0"));
  304. QrCodeTCPAddress3 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress3", "127.0.0.1");
  305. QrCodeTCPPort3 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort3", "0"));
  306. QrCodeTCPAddress4 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress4", "127.0.0.1");
  307. QrCodeTCPPort4 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort4", "0"));
  308. QrCodeTCPAddress5 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress5", "127.0.0.1");
  309. QrCodeTCPPort5 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort5", "0"));
  310. // MES
  311. MESAppId = IniFile.INIGetStringValue(FilePath, "MES", "MESAppId", "mes_test");
  312. MESAppKey = IniFile.INIGetStringValue(FilePath, "MES", "MESAppKey", "mes");
  313. MESUserId = IniFile.INIGetStringValue(FilePath, "MES", "MESUserId", "mes_userid");
  314. ServerHost = IniFile.INIGetStringValue(FilePath, "MES", "ServerHost", ConstServerHost);
  315. StationInMESUrl = IniFile.INIGetStringValue(FilePath, "MES", "StationInMESUrl", "");
  316. StationInMESUrl = string.Format(StationInMESUrl, ServerHost);
  317. StationOutMESUrl = IniFile.INIGetStringValue(FilePath, "MES", "StationOutMESUrl", "");
  318. StationOutMESUrl = string.Format(StationOutMESUrl, ServerHost);
  319. if (ServerHost.Contains(":"))
  320. {
  321. string[] mesServers = ServerHost.Split(':');
  322. ServerIp = mesServers[0];
  323. ServerIp = ServerHost.Replace("\\", "/");
  324. mesServers = ServerHost.Split('/');
  325. if (mesServers.Length > 3)
  326. ServerIp = mesServers[2];
  327. }
  328. else
  329. {
  330. ServerHost = ServerHost.Replace("\\", "/");
  331. string[] mesServers = ServerHost.Split('/');
  332. if (mesServers.Length > 3)
  333. ServerIp = mesServers[2];
  334. }
  335. //StationInMESUrl = IniFile.INIGetStringValue(MESConfig, "MES", "StationInMESUrl", "");
  336. //StationInMESUrl = string.Format(StationInMESUrl, ServerHost);
  337. //StationOutMESUrl = IniFile.INIGetStringValue(MESConfig, "MES", "StationOutMESUrl", "");
  338. //StationOutMESUrl = string.Format(StationOutMESUrl, ServerHost);
  339. IsUseMES = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsUseMES", ConstIsSend));
  340. IsSendStationIn = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendStationIn", ConstIsSend));
  341. IsSendProcessData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendProcessData", ConstIsSend));
  342. IsSendCheckOneData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendCheckOneData", ConstIsSend));
  343. IsSendWorkingData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendWorkingData", ConstIsSend));
  344. IsSendAlarmData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendAlarmData", ConstIsSend));
  345. IsUseMESRoute = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsUseMESRoute", ConstIsSend));
  346. // MQTT
  347. IsUseIot = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsUseIot", "false"));
  348. MQTTServerHost = IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTServerHost", "127.0.0.1");
  349. MQTTServerPort = int.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTServerPort", "80"));
  350. IsMqttSendProcessData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSendProcessData", ConstIsSend));
  351. IsMqttDeviceState = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttDeviceState", ConstIsSend));
  352. IsMqttFaultLog = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttFaultLog", ConstIsSend));
  353. IsMqttSensorData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSensorData", ConstIsSend));
  354. IsMqttStationInputBegin = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttStationInputBegin", ConstIsSend));
  355. IsMqttOperateLog = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttOperateLog", ConstIsSend));
  356. IsMqttEquiConfig = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttEquiConfig", ConstIsSend));
  357. IsMqttProcConfig = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttProcConfig", ConstIsSend));
  358. // AGV配置
  359. IsUseAGV = bool.Parse(IniFile.INIGetStringValue(FilePath, "AGV", "IsUseAGV", "false")); // 是否 启用AGV
  360. AGVHttpHost = IniFile.INIGetStringValue(FilePath, "AGV", "AGVHttpHost", "127.0.0.1:80"); // Http IP地址
  361. string[] AGVHttps = AGVHttpHost.Split(':');
  362. AGVHttpIp = AGVHttps[0];
  363. AGVMQTTHost = IniFile.INIGetStringValue(FilePath, "AGV", "AGVMQTTHost", "127.0.0.1"); // MQTT IP地址
  364. AGVMQTTPort = int.Parse(IniFile.INIGetStringValue(FilePath, "AGV", "AGVMQTTPort", "80")); // MQTT端口
  365. AGVMQTTDeviceCode = IniFile.INIGetStringValue(FilePath, "AGV", "AGVMQTTDeviceCode", ""); // portCode
  366. // 入出站参数
  367. S1_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S1_MachineId", "MId");
  368. S1_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S1_StationId", "SId");
  369. S2_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S2_MachineId", "MId");
  370. S2_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S2_StationId", "SId");
  371. S3_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S3_MachineId", "MId");
  372. S3_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S3_StationId", "SId");
  373. S3_StationId_1 = IniFile.INIGetStringValue(FilePath, "StationOut", "S3_StationId_1", "SId");
  374. S3_StationId_2 = IniFile.INIGetStringValue(FilePath, "StationOut", "S3_StationId_2", "SId");
  375. S4_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S4_MachineId", "MId");
  376. S4_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S4_StationId", "SId");
  377. S5_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S5_MachineId", "MId");
  378. S5_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S5_StationId", "SId");
  379. S6_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S6_MachineId", "MId");
  380. S6_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S6_StationId", "SId");
  381. S7_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S7_MachineId", "MId");
  382. S7_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S7_StationId", "SId");
  383. S7_StationId_1 = IniFile.INIGetStringValue(FilePath, "StationOut", "S7_StationId_1", "SId");
  384. S7_StationId_2 = IniFile.INIGetStringValue(FilePath, "StationOut", "S7_StationId_2", "SId");
  385. S8_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S8_MachineId", "MId");
  386. S8_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S8_StationId", "SId");
  387. S9_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S9_MachineId", "MId");
  388. S9_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S9_StationId", "SId");
  389. // 本地数据库
  390. Server = IniFile.INIGetStringValue(FilePath, "LocalDB", "Server", @"localhost");
  391. User = IniFile.INIGetStringValue(FilePath, "LocalDB", "User", "sa");
  392. PassWord = IniFile.INIGetStringValue(FilePath, "LocalDB", "PassWord", "Aa123456");
  393. MacStr = IPHelper.GetMoAddress();
  394. // 同步一次数据库当前订单信息到配置文件-后加的(加完后,设置页修改订单信息的功能不可用)
  395. //SyncCurOrderInfo();
  396. Set?.Invoke();
  397. }
  398. catch (Exception ex) { }
  399. }
  400. /// <summary>
  401. /// 同步数据量存储的当前订单信息到配置文件中
  402. /// </summary>
  403. public static void SyncCurOrderInfo()
  404. {
  405. #region 校验配置文件是否和数据库实际订单一致,如果配置文件的订单和数据库不一致,以数据库优先
  406. string sql = @" SELECT TOP 1
  407. WorkOrderNum,
  408. BatchNumber,
  409. ProductMtltmrk,
  410. SupplierCode
  411. FROM OrderTable
  412. WHERE WorkOrderStatus = '正在处理订单'
  413. ORDER BY
  414. CreatedTime DESC ";
  415. SqlHelper _sqlHelper = new SqlHelper();
  416. DataTable dt_data = _sqlHelper.Db.SqlQueryable<OrderTable>(sql).ToDataTable(); // 查询订单数据
  417. if (dt_data != null && dt_data.Rows.Count > 0)
  418. {
  419. string _workOrderNum = dt_data.Rows[0][1].ToString().Trim();
  420. if (WorkOrderCode != _workOrderNum)
  421. {
  422. IniFile.INIWriteValue(FilePath, "Product", "WorkOrderCode", dt_data.Rows[0][0].ToString().Trim());
  423. IniFile.INIWriteValue(FilePath, "Product", "BatchNumber", dt_data.Rows[0][1].ToString().Trim());
  424. IniFile.INIWriteValue(FilePath, "Product", "Mtltmrk", dt_data.Rows[0][2].ToString().Trim());
  425. }
  426. else
  427. {
  428. IniFile.INIWriteValue(FilePath, "Product", "WorkOrderCode", string.Empty);
  429. IniFile.INIWriteValue(FilePath, "Product", "BatchNumber", string.Empty);
  430. IniFile.INIWriteValue(FilePath, "Product", "Mtltmrk", string.Empty);
  431. }
  432. }
  433. else
  434. {
  435. IniFile.INIWriteValue(FilePath, "Product", "WorkOrderCode", string.Empty);
  436. IniFile.INIWriteValue(FilePath, "Product", "BatchNumber", string.Empty);
  437. IniFile.INIWriteValue(FilePath, "Product", "Mtltmrk", string.Empty);
  438. }
  439. #endregion
  440. }
  441. }
  442. }