GlobalContext.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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 ProcessDataDir = MainDir + @"ProcessData\"; // 加工数据日志
  27. public static string OneCheckDataDir = MainDir + @"OneCheckData\"; // 点检数据日志
  28. public static string SQLLogDir = MainDir + @"SQLLog\"; // sql日志
  29. public static string DBDir = @"D:\LocalDataBase\";
  30. public static string MESConfig = MainDir + @"MESConfig.ini"; // MES接口的配置文件
  31. public static string MqttLogDir = MainDir + @"MqttLog\"; // mqtt日志
  32. public static string MqttCallbackDir = MqttLogDir + @"Callback\"; // mqtt日志 - Callback内容
  33. public static string MqttDeviceStateDir = MqttLogDir + @"设备状态\"; // mqtt日志 - 设备状态日志
  34. public static string MqttInputBeginDir = MqttLogDir + @"节拍日志\"; // mqtt日志 - 节拍日志
  35. public static string MqttOperateLogDir = MqttLogDir + @"用户操作\"; // mqtt日志 - 用户操作日志
  36. public static string MqttAlarmLogDir = MqttLogDir + @"故障日志\"; // mqtt日志 - 故障日志日志
  37. public static string MqttPassResultLogDir = MqttLogDir + @"过站结果\"; // mqtt日志 - 过站结果日志
  38. public static string MqttPassDetailLogDir = MqttLogDir + @"过站明细\"; // mqtt日志 - 过站明细日志
  39. public static string MqttFileUpLogDir = MqttLogDir + @"文件上传\"; // mqtt日志 - 文件上传日志
  40. public static string MqttFileBackupLogDir = MqttLogDir + @"文件上传\文件备份"; // mqtt日志 - 文件上传日志
  41. public static string MqttFileTempDir = MqttLogDir + @"文件上传\临时文件"; // mqtt日志 - 文件上传日志
  42. public static string MqttDeviceConfigLogDir = MqttLogDir + @"装备配置\"; // mqtt日志 - 装备配置日志
  43. public static string MqttServerPath = AppDomain.CurrentDomain.BaseDirectory + @"\ThingsMode\MqttServer.exe";
  44. public static string MqttServerName = "MqttServer";
  45. /// <summary>
  46. /// 点检数据文件
  47. /// </summary>
  48. public static string CheckOneDataPath = AppDomain.CurrentDomain.BaseDirectory + "CheckOneData.ini";
  49. // 产线及产品信息
  50. public static string Project_Code; // 项⽬编码
  51. public static string Factory_Code; // ⼯⼚ID
  52. public static string Process_Section_Code; // ⼯段编码
  53. public static string LineCode; // 线体编码
  54. public static string LineName; // 线体名称
  55. public static string ProgramName; // 程序名
  56. public static string WorkOrderCode; // 车间订单号
  57. public static string BatchNumber; // 批次号(splcode)
  58. public static string Mtltmrk; // 产品型号(mtltmrk)
  59. public static string run_mode; // 生产阶段 online/offline
  60. public static string product_mode; // 运行模式 debug(调试)/tp(试产)/mp(量产)
  61. public static string FileAppId; // 文件上传
  62. public static string FileAppKey; // 文件上传
  63. public static string S1_work_station; // [S1] ⼯站
  64. public static string S1_device_code; // [S1] 装备编码
  65. public static string S1_station; // [S1] ⼯位Id
  66. public static string S2_work_station; // [S2] ⼯站
  67. public static string S2_device_code; // [S2] 装备编码
  68. public static string S2_station; // [S2] ⼯位Id
  69. public static string s3_1_work_station; // [S3] ⼯站
  70. public static string s3_1_device_code; // [S3] 装备编码
  71. public static string s3_1_station; // [S3] ⼯位Id
  72. public static string s3_2_work_station; // [S4_1] ⼯站
  73. public static string s3_2_device_code; // [S4_1] 装备编码
  74. public static string s3_2_station; // [S4_1] ⼯位Id
  75. public static string s4_work_station; // [S4_3] ⼯站
  76. public static string s4_device_code; // [S4_3] 装备编码
  77. public static string s4_station; // [S4_3] ⼯位Id
  78. public static string s5_work_station; // [S4_4] ⼯站
  79. public static string s5_device_code; // [S4_4] 装备编码
  80. public static string s5_station; // [S4_4] ⼯位Id
  81. public static string s6_work_station; // [S4_5] ⼯站
  82. public static string s6_device_code; // [S4_5] 装备编码
  83. public static string s6_station; // [S4_5] ⼯位Id
  84. public static string s7_1_work_station; // [S5] ⼯站
  85. public static string s7_1_device_code; // [S5] 装备编码
  86. public static string s7_1_station; // [S5] ⼯位Id
  87. public static string s7_2_work_station; // [S5] 装备编码
  88. public static string s7_2_device_code; // [S5] ⼯位Id
  89. public static string s7_2_station; // [S5] 装备编码
  90. public static string s8_work_station; // [S5] ⼯位Id
  91. public static string s8_device_code; // [S5] 装备编码
  92. public static string s8_station; // [S5] ⼯位Id
  93. public static string s9_work_station; // [S5] 装备编码
  94. public static string s9_device_code; // [S5] ⼯位Id
  95. public static string s9_station; // [S5] ⼯位Id
  96. // 设备
  97. //public static string PCAddress="192.168.1.244";
  98. public static bool IsUsePLC1;
  99. public static bool IsUsePLC2;
  100. public static bool IsUsePLC3;
  101. public static bool IsUsePLC4;
  102. public static bool IsUsePLC5;
  103. public static bool IsUsePLC6;
  104. public static bool IsUsePLC7;
  105. public static bool IsUsePLC8;
  106. public static bool IsUsePLC9;
  107. public static string Machine1Address;
  108. public static string Machine2Address;
  109. public static string Machine3Address;
  110. public static string Machine4Address;
  111. public static string Machine5Address;
  112. public static string Machine6Address;
  113. public static string Machine7Address;
  114. public static string Machine8Address;
  115. public static string Machine9Address;
  116. public static string PC1Address;
  117. public static string PC2Address;
  118. public static string PC3Address;
  119. public static string PC4Address;
  120. public static string PC5Address;
  121. public static string PC6Address;
  122. public static string PC7Address;
  123. public static string PC8Address;
  124. public static string PC9Address;
  125. public static int MachinePort;
  126. public static string AtlasAddressLeft;
  127. public static string AtlasAddressRight;
  128. public static int AtlasAddressPort;
  129. // TCP
  130. public static string QrCodeTCPAddress1;
  131. public static int QrCodeTCPPort1;
  132. public static string QrCodeTCPAddress2;
  133. public static int QrCodeTCPPort2;
  134. public static string QrCodeTCPAddress3;
  135. public static int QrCodeTCPPort3;
  136. public static string QrCodeTCPAddress4;
  137. public static int QrCodeTCPPort4;
  138. public static string QrCodeTCPAddress5;
  139. public static int QrCodeTCPPort5;
  140. // MES
  141. public static bool IsUseMES; // 是否 启用MES
  142. public static string MESAppId; // 应用ID;mes_test
  143. public static string MESAppKey; // API接口名称;mes
  144. public static string MESUserId; // 用户ID
  145. public static string ServerHost; // 主服务器地址
  146. public static string StationInMESUrl; // 入站接口Url
  147. public static string StationOutMESUrl; // 出站接口Url
  148. public static string ServerIp; // 主服务器IP-解析所得
  149. //public static string StationInMESUrl; // 入站接口Url
  150. //public static string StationOutMESUrl; // 出站接口Url
  151. public static bool IsSendStationIn; // 启用上传进站
  152. public static bool IsSendProcessData; // 启用上传出站
  153. public static bool IsSendCheckOneData; // 启用上传点检
  154. public static bool IsSendWorkingData; // 启用上传状态
  155. public static bool IsSendAlarmData; // 启用上传报警
  156. public static bool IsSendProcessDetail; // 启用上传出站明细
  157. public static bool IsSendTestData; // 启用上传出站测试项
  158. public static bool IsUseMESRoute; // 启用边线MES软件
  159. public static bool MESIsConnect; // MES是否正常连接
  160. public static string MESLaserLPath; // 三点激光数据本地存放地址
  161. public static string MESLaserRPath; // 三点激光数据本地存放地址
  162. public static string UpFileUrl; // 文档库地址
  163. public static string UpFilePath; // 本地文件路径
  164. public static bool MESIsSendUpFile; // 启用上传文件
  165. // IOT - MQTT
  166. public static bool IsUseIot; // 是否 启用IOT
  167. public static string MQTTServerHost; // 服务器IP
  168. public static int MQTTServerPort; // 服务器Port
  169. public static bool IsMqttSendProcessData; // 上传过站数据
  170. public static bool IsMqttSendProcessResult; // 上传过站结果
  171. public static bool IsMqttDeviceState; // 上传设备状态
  172. public static bool IsMqttFaultLog; // 上传故障⽇志
  173. public static bool IsMqttSensorData; // 上传传感器数据
  174. public static bool IsMqttStationInputBegin; // 上传节拍⽇志
  175. public static bool IsMqttOperateLog; // 上传操作记录
  176. public static bool IsMqttEquiConfig; // 上传装备配置
  177. public static bool IsMqttProcConfig; // 上传⼯艺配置
  178. public static bool MQTTIsSendUpFile; // 启用上传出战明细
  179. public static string MQTTAppId; // IOT应用ID
  180. public static string MQTTAppPwd; // IOT登录密码
  181. public static int IsUsePLCNow { set; get; } = 0; // 单机模式下,存储当前在用的plcNum
  182. public static string IsUseStationName { set; get; } = ""; // 单机模式下,存储当前在用的主工站全称
  183. public static string address; // fds地址
  184. public static string appId; // fds应⽤识别码
  185. public static string appKey; // fds应⽤密钥
  186. // IOT-AGV
  187. public static bool IsUseAGV; // 是否 启用AGV
  188. public static string AGVHttpHost; // Http 服务器地址
  189. public static string AGVHttpIp; // Http IP地址
  190. public static string AGVMQTTHost; // MQTT IP地址
  191. public static int AGVMQTTPort; // MQTT端口
  192. public static string AGVMQTTDeviceCode; // MQTT设备Code
  193. public static bool AGVMQTTIsConnect; // AGV MQTT是否正常连接
  194. // MES进出站 配置信息
  195. public static string S1_MachineId; // 工站1 - 壳体清洁上料装备
  196. public static string S1_StationId; // 工站1 - 壳体清洁上料装备
  197. public static string S2_MachineId; // 工站2 - 上盖板上料装备
  198. public static string S2_StationId; // 工站2 - 上盖板上料装备
  199. public static string S3_MachineId; // 工站3 - 点散热胶装备
  200. public static string S3_StationId; // 工站3 - 点散热胶装备
  201. public static string S3_StationId_1; // 工站3 - 点散热胶装备
  202. public static string S3_StationId_2; // 工站3 - 点散热胶装备
  203. public static string S4_MachineId; // 工站4 - 胶线检测装备
  204. public static string S4_StationId; // 工站4 - 胶线检测装备
  205. public static string S5_MachineId; // 工站5 - ADD板上料组装装备
  206. public static string S5_StationId; // 工站5 - ADD板上料组装装备
  207. public static string S6_MachineId; // 工站6 - 组上盖板装备
  208. public static string S6_StationId; // 工站6 - 组上盖板装备
  209. public static string S7_MachineId; // 工站7 - 上盖板锁螺丝装备
  210. public static string S7_StationId; // 工站7 - 上盖板锁螺丝装备
  211. public static string S7_StationId_1; // 工站7 - 上盖板锁螺丝装备
  212. public static string S7_StationId_2; // 工站7 - 上盖板锁螺丝装备
  213. public static string S8_MachineId; // 工站8 - NG下料装备
  214. public static string S8_StationId; // 工站8 - NG下料装备
  215. public static string S9_MachineId; // 工站9 - 产品下料装备
  216. public static string S9_StationId; // 工站9 - 产品下料装备
  217. // 本地数据库
  218. public static string Server;
  219. public static string User;
  220. public static string PassWord;
  221. //其它
  222. public static string CurrentUser = "";
  223. public static string MacStr = "";
  224. #region 是否可连接PLC-用户手动控制用(后加)
  225. public static bool _IsCon_Funs1 = true;
  226. public static bool _IsCon_Funs2 = true;
  227. public static bool _IsCon_Funs3 = true;
  228. public static bool _IsCon_Funs4 = true;
  229. public static bool _IsCon_Funs5 = true;
  230. public static bool _IsCon_plc1Heat = true;
  231. public static bool _IsCon_plc1Alarm = true;
  232. #endregion 是否可连接PLC-用户手动控制用(后加)
  233. #endregion 变量
  234. #region 常量
  235. //产品常量
  236. public const string ConstLineCode = "A1";
  237. public const string ConstLineName = "A1产线";
  238. public const string ConstProgramName = "A1程序名";
  239. public const string ConstSono = " ";
  240. public const string ConstWorkOrderCode = " ";
  241. public const string ConstBatchNumber = " ";
  242. public const string ConstMtltmrk = " ";
  243. public const string ConstSupplierCode = " ";
  244. //设备常量
  245. public const string ConstMachine1Address = "192.168.10.87";
  246. public const string ConstMachine2Address = "192.168.2.1";
  247. public const string ConstMachine3Address = "192.168.4.111";
  248. public const string ConstMachine4Address = "192.168.4.1";
  249. public const string ConstMachine5Address = "192.168.6.111";
  250. public const string ConstMachine6Address = "192.168.6.1";
  251. public const string ConstMachine7Address = "192.168.6.71";
  252. public const string ConstMachine8Address = "192.168.6.81";
  253. public const string ConstMachine9Address = "192.168.1.91";
  254. public const string ConstPc1Address = "192.168.1.10";
  255. public const string ConstPc2Address = "192.168.1.10";
  256. public const string ConstPc3Address = "192.168.1.10";
  257. public const string ConstPc4Address = "192.168.1.10";
  258. public const string ConstPc5Address = "192.168.1.10";
  259. public const string ConstPc6Address = "192.168.1.10";
  260. public const string ConstPc7Address = "192.168.1.10";
  261. public const string ConstPc8Address = "192.168.1.10";
  262. public const string ConstPc9Address = "192.168.1.10";
  263. public const string ConstMachinePort = "1217";
  264. //MES常量
  265. public const string ConstServerHost = "10.1.19.33:8080";
  266. public const string ConstIsSend = "false";
  267. #endregion 常量
  268. public GlobalContext()
  269. {
  270. UpdateData();
  271. }
  272. /// <summary>
  273. /// 更新全局变量
  274. /// </summary>
  275. public static void UpdateData()
  276. {
  277. try
  278. {
  279. // 产线及产品信息
  280. Project_Code = IniFile.INIGetStringValue(FilePath, "Product", "ProjectCode", "");
  281. Factory_Code = IniFile.INIGetStringValue(FilePath, "Product", "FactoryCode", "");
  282. Process_Section_Code = IniFile.INIGetStringValue(FilePath, "Product", "ProcessSectionCode", "");
  283. LineCode = IniFile.INIGetStringValue(FilePath, "Product", "LineCode", ConstLineCode);
  284. LineName = IniFile.INIGetStringValue(FilePath, "Product", "LineName", ConstLineName);
  285. ProgramName = IniFile.INIGetStringValue(FilePath, "Product", "ProgramName", ConstProgramName);
  286. MESLaserLPath = IniFile.INIGetStringValue(FilePath, "MES", "MESLaserLPath", "");
  287. MESLaserRPath = IniFile.INIGetStringValue(FilePath, "MES", "MESLaserRPath", "");
  288. WorkOrderCode = IniFile.INIGetStringValue(FilePath, "Product", "WorkOrderCode", ConstWorkOrderCode); // 车间订单号
  289. BatchNumber = IniFile.INIGetStringValue(FilePath, "Product", "BatchNumber", ConstBatchNumber); // 批次号(splcode)
  290. Mtltmrk = IniFile.INIGetStringValue(FilePath, "Product", "Mtltmrk", ConstMtltmrk); // 产品型号(mtltmrk)
  291. // 工位信息
  292. S1_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s1_work_station", ""); // [S1] ⼯站
  293. S1_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s1_device_code", ""); // [S1] 装备编码
  294. S1_station = IniFile.INIGetStringValue(FilePath, "Station", "s1_station", ""); // [S1] ⼯位Id
  295. S2_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s2_work_station", ""); // [S2] ⼯站
  296. S2_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s2_device_code", ""); // [S2] 装备编码
  297. S2_station = IniFile.INIGetStringValue(FilePath, "Station", "s2_station", ""); // [S2] ⼯位Id
  298. s3_1_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_1_work_station", ""); // [S3] ⼯站
  299. s3_1_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s3_1_device_code", ""); // [S3] 装备编码
  300. s3_1_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_1_station", ""); // [S3] ⼯位Id
  301. s3_2_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_2_work_station", ""); // [S3] ⼯站
  302. s3_2_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s3_2_device_code", ""); // [S3] 装备编码
  303. s3_2_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_2_station", ""); // [S3] ⼯位Id
  304. s4_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_work_station", ""); // [S4_1] ⼯站
  305. s4_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_device_code", ""); // [S4_1] 装备编码
  306. s4_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_station", ""); // [S4_1] ⼯位Id
  307. s5_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s5_work_station", ""); // [S4_4] ⼯站
  308. s5_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s5_device_code", ""); // [S4_4] 装备编码
  309. s5_station = IniFile.INIGetStringValue(FilePath, "Station", "s5_station", ""); // [S4_4] ⼯位Id
  310. s6_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s6_work_station", ""); // [S4_5] ⼯站
  311. s6_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s6_device_code", ""); // [S4_5] 装备编码
  312. s6_station = IniFile.INIGetStringValue(FilePath, "Station", "s6_station", ""); // [S4_5] ⼯位Id
  313. s7_1_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s7_1_work_station", ""); // [S5] ⼯站
  314. s7_1_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s7_1_device_code", ""); // [S5] 装备编码
  315. s7_1_station = IniFile.INIGetStringValue(FilePath, "Station", "s7_1_station", ""); // [S5] ⼯位Id
  316. s7_2_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s7_2_work_station", ""); // [S4_5] ⼯站
  317. s7_2_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s7_2_device_code", ""); // [S4_5] 装备编码
  318. s7_2_station = IniFile.INIGetStringValue(FilePath, "Station", "s7_2_station", ""); // [S4_5] ⼯位Id
  319. s8_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s8_work_station", ""); // [S4_5] ⼯站
  320. s8_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s8_device_code", ""); // [S4_5] 装备编码
  321. s8_station = IniFile.INIGetStringValue(FilePath, "Station", "s8_station", ""); // [S4_5] ⼯位Id
  322. s9_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s9_work_station", ""); // [S4_5] ⼯站
  323. s9_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s9_device_code", ""); // [S4_5] 装备编码
  324. s9_station = IniFile.INIGetStringValue(FilePath, "Station", "s9_station", ""); // [S4_5] ⼯位Id
  325. // 设备
  326. IsUsePLC1 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC1", "false"));
  327. IsUsePLC2 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC2", "false"));
  328. IsUsePLC3 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC3", "false"));
  329. IsUsePLC4 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC4", "false"));
  330. IsUsePLC5 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC5", "false"));
  331. IsUsePLC6 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC6", "false"));
  332. IsUsePLC7 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC7", "false"));
  333. IsUsePLC8 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC8", "false"));
  334. IsUsePLC9 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC9", "false"));
  335. Machine1Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine1Address", ConstMachine1Address);
  336. Machine2Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine2Address", ConstMachine2Address);
  337. Machine3Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine3Address", ConstMachine3Address);
  338. Machine4Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine4Address", ConstMachine4Address);
  339. Machine5Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine5Address", ConstMachine5Address);
  340. Machine6Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine6Address", ConstMachine6Address);
  341. Machine7Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine7Address", ConstMachine7Address);
  342. Machine8Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine8Address", ConstMachine8Address);
  343. Machine9Address = IniFile.INIGetStringValue(FilePath, "Machine", "Machine9Address", ConstMachine9Address);
  344. PC1Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc1Address", ConstPc1Address);
  345. PC2Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc2Address", ConstPc2Address);
  346. PC3Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc3Address", ConstPc3Address);
  347. PC4Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc4Address", ConstPc4Address);
  348. PC5Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc5Address", ConstPc5Address);
  349. PC6Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc6Address", ConstPc6Address);
  350. PC7Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc7Address", ConstPc7Address);
  351. PC8Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc8Address", ConstPc8Address);
  352. PC9Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc9Address", ConstPc9Address);
  353. MachinePort = int.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "MachinePort", ConstMachinePort));
  354. AtlasAddressLeft = IniFile.INIGetStringValue(FilePath, "Machine", "AtlasAddressLeft", "");
  355. AtlasAddressRight = IniFile.INIGetStringValue(FilePath, "Machine", "AtlasAddressRight", "");
  356. AtlasAddressPort = int.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "AtlasAddressPort", ""));
  357. QrCodeTCPAddress1 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress1", "127.0.0.1");
  358. QrCodeTCPPort1 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort1", "0"));
  359. QrCodeTCPAddress2 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress2", "127.0.0.1");
  360. QrCodeTCPPort2 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort2", "0"));
  361. QrCodeTCPAddress3 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress3", "127.0.0.1");
  362. QrCodeTCPPort3 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort3", "0"));
  363. QrCodeTCPAddress4 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress4", "127.0.0.1");
  364. QrCodeTCPPort4 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort4", "0"));
  365. QrCodeTCPAddress5 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress5", "127.0.0.1");
  366. QrCodeTCPPort5 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort5", "0"));
  367. // MES
  368. MESAppId = IniFile.INIGetStringValue(FilePath, "MES", "MESAppId", "mes_test");
  369. MESAppKey = IniFile.INIGetStringValue(FilePath, "MES", "MESAppKey", "mes");
  370. MESUserId = IniFile.INIGetStringValue(FilePath, "MES", "MESUserId", "mes_userid");
  371. ServerHost = IniFile.INIGetStringValue(FilePath, "MES", "ServerHost", ConstServerHost);
  372. StationInMESUrl = IniFile.INIGetStringValue(FilePath, "MES", "StationInMESUrl", "");
  373. StationInMESUrl = string.Format(StationInMESUrl, ServerHost);
  374. StationOutMESUrl = IniFile.INIGetStringValue(FilePath, "MES", "StationOutMESUrl", "");
  375. StationOutMESUrl = string.Format(StationOutMESUrl, ServerHost);
  376. UpFileUrl = IniFile.INIGetStringValue(FilePath, "MQTT", "UpFileUrl", "");
  377. UpFilePath = IniFile.INIGetStringValue(FilePath, "MQTT", "UpFilePath", "");
  378. MESIsSendUpFile = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "MESIsSendUpFile", ConstIsSend));
  379. if (ServerHost.Contains(":"))
  380. {
  381. string[] mesServers = ServerHost.Split(':');
  382. ServerIp = mesServers[0];
  383. ServerIp = ServerHost.Replace("\\", "/");
  384. mesServers = ServerHost.Split('/');
  385. if (mesServers.Length > 3)
  386. ServerIp = mesServers[2];
  387. }
  388. else
  389. {
  390. ServerHost = ServerHost.Replace("\\", "/");
  391. string[] mesServers = ServerHost.Split('/');
  392. if (mesServers.Length > 3)
  393. ServerIp = mesServers[2];
  394. }
  395. //StationInMESUrl = IniFile.INIGetStringValue(MESConfig, "MES", "StationInMESUrl", "");
  396. //StationInMESUrl = string.Format(StationInMESUrl, ServerHost);
  397. //StationOutMESUrl = IniFile.INIGetStringValue(MESConfig, "MES", "StationOutMESUrl", "");
  398. //StationOutMESUrl = string.Format(StationOutMESUrl, ServerHost);
  399. IsUseMES = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsUseMES", ConstIsSend));
  400. IsSendStationIn = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendStationIn", ConstIsSend));
  401. IsSendProcessData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendProcessData", ConstIsSend));
  402. IsSendCheckOneData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendCheckOneData", ConstIsSend));
  403. IsSendWorkingData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendWorkingData", ConstIsSend));
  404. IsSendAlarmData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendAlarmData", ConstIsSend));
  405. IsUseMESRoute = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsUseMESRoute", ConstIsSend));
  406. IsSendProcessDetail = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendProcessDetail", ConstIsSend));
  407. IsSendTestData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendTestData", ConstIsSend));
  408. // MQTT
  409. IsUseIot = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsUseIot", "false"));
  410. MQTTServerHost = IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTServerHost", "127.0.0.1");
  411. MQTTServerPort = int.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTServerPort", "80"));
  412. IsMqttSendProcessData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSendProcessData", ConstIsSend));
  413. IsMqttSendProcessResult = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSendProcessResult", ConstIsSend));
  414. IsMqttDeviceState = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttDeviceState", ConstIsSend));
  415. IsMqttFaultLog = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttFaultLog", ConstIsSend));
  416. IsMqttSensorData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSensorData", ConstIsSend));
  417. IsMqttStationInputBegin = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttStationInputBegin", ConstIsSend));
  418. IsMqttOperateLog = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttOperateLog", ConstIsSend));
  419. IsMqttEquiConfig = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttEquiConfig", ConstIsSend));
  420. IsMqttProcConfig = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttProcConfig", ConstIsSend));
  421. MQTTIsSendUpFile = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTIsSendUpFile", ConstIsSend));
  422. MQTTAppId = IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTAppId", "AKPKTSQAS46NKE4NHY");
  423. MQTTAppPwd = IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTAppPwd", "pwd");
  424. appKey = IniFile.INIGetStringValue(FilePath, "MQTT", "appKey", ConstIsSend);
  425. appId = IniFile.INIGetStringValue(FilePath, "MQTT", "appId", ConstIsSend);
  426. address = IniFile.INIGetStringValue(FilePath, "MQTT", "address", ConstIsSend);
  427. product_mode = IniFile.INIGetStringValue(FilePath, "MQTT", "product_mode", ConstIsSend);
  428. run_mode = IniFile.INIGetStringValue(FilePath, "MQTT", "run_mode", ConstIsSend);
  429. FileAppId = IniFile.INIGetStringValue(FilePath, "MQTT", "FileAppId", ConstIsSend);
  430. FileAppKey = IniFile.INIGetStringValue(FilePath, "MQTT", "FileAppKey", ConstIsSend);
  431. // AGV配置
  432. IsUseAGV = bool.Parse(IniFile.INIGetStringValue(FilePath, "AGV", "IsUseAGV", "false")); // 是否 启用AGV
  433. AGVHttpHost = IniFile.INIGetStringValue(FilePath, "AGV", "AGVHttpHost", "127.0.0.1:80"); // Http IP地址
  434. string[] AGVHttps = AGVHttpHost.Split(':');
  435. AGVHttpIp = AGVHttps[0];
  436. AGVMQTTHost = IniFile.INIGetStringValue(FilePath, "AGV", "AGVMQTTHost", "127.0.0.1"); // MQTT IP地址
  437. AGVMQTTPort = int.Parse(IniFile.INIGetStringValue(FilePath, "AGV", "AGVMQTTPort", "80")); // MQTT端口
  438. AGVMQTTDeviceCode = IniFile.INIGetStringValue(FilePath, "AGV", "AGVMQTTDeviceCode", ""); // portCode
  439. // 入出站参数
  440. S1_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S1_MachineId", "MId");
  441. S1_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S1_StationId", "SId");
  442. S2_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S2_MachineId", "MId");
  443. S2_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S2_StationId", "SId");
  444. S3_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S3_MachineId", "MId");
  445. S3_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S3_StationId", "SId");
  446. S3_StationId_1 = IniFile.INIGetStringValue(FilePath, "StationOut", "S3_StationId_1", "SId");
  447. S3_StationId_2 = IniFile.INIGetStringValue(FilePath, "StationOut", "S3_StationId_2", "SId");
  448. S4_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S4_MachineId", "MId");
  449. S4_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S4_StationId", "SId");
  450. S5_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S5_MachineId", "MId");
  451. S5_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S5_StationId", "SId");
  452. S6_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S6_MachineId", "MId");
  453. S6_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S6_StationId", "SId");
  454. S7_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S7_MachineId", "MId");
  455. S7_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S7_StationId", "SId");
  456. S7_StationId_1 = IniFile.INIGetStringValue(FilePath, "StationOut", "S7_StationId_1", "SId");
  457. S7_StationId_2 = IniFile.INIGetStringValue(FilePath, "StationOut", "S7_StationId_2", "SId");
  458. S8_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S8_MachineId", "MId");
  459. S8_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S8_StationId", "SId");
  460. S9_MachineId = IniFile.INIGetStringValue(FilePath, "StationOut", "S9_MachineId", "MId");
  461. S9_StationId = IniFile.INIGetStringValue(FilePath, "StationOut", "S9_StationId", "SId");
  462. // 本地数据库
  463. Server = IniFile.INIGetStringValue(FilePath, "LocalDB", "Server", @"localhost");
  464. User = IniFile.INIGetStringValue(FilePath, "LocalDB", "User", "sa");
  465. PassWord = IniFile.INIGetStringValue(FilePath, "LocalDB", "PassWord", "bozhong123");
  466. MacStr = IPHelper.GetMoAddress();
  467. // 同步一次数据库当前订单信息到配置文件-后加的(加完后,设置页修改订单信息的功能不可用)
  468. //SyncCurOrderInfo();
  469. Set?.Invoke();
  470. }
  471. catch (Exception ex) { }
  472. }
  473. /// <summary>
  474. /// 同步数据量存储的当前订单信息到配置文件中
  475. /// </summary>
  476. public static void SyncCurOrderInfo()
  477. {
  478. #region 校验配置文件是否和数据库实际订单一致,如果配置文件的订单和数据库不一致,以数据库优先
  479. string sql = @" SELECT TOP 1
  480. WorkOrderNum,
  481. BatchNumber,
  482. ProductMtltmrk,
  483. SupplierCode
  484. FROM OrderTable
  485. WHERE WorkOrderStatus = '正在处理订单'
  486. ORDER BY
  487. CreatedTime DESC ";
  488. SqlHelper _sqlHelper = new SqlHelper();
  489. DataTable dt_data = _sqlHelper.Db.SqlQueryable<OrderTable>(sql).ToDataTable(); // 查询订单数据
  490. if (dt_data != null && dt_data.Rows.Count > 0)
  491. {
  492. string _workOrderNum = dt_data.Rows[0][1].ToString().Trim();
  493. if (WorkOrderCode != _workOrderNum)
  494. {
  495. IniFile.INIWriteValue(FilePath, "Product", "WorkOrderCode", dt_data.Rows[0][0].ToString().Trim());
  496. IniFile.INIWriteValue(FilePath, "Product", "BatchNumber", dt_data.Rows[0][1].ToString().Trim());
  497. IniFile.INIWriteValue(FilePath, "Product", "Mtltmrk", dt_data.Rows[0][2].ToString().Trim());
  498. }
  499. else
  500. {
  501. IniFile.INIWriteValue(FilePath, "Product", "WorkOrderCode", string.Empty);
  502. IniFile.INIWriteValue(FilePath, "Product", "BatchNumber", string.Empty);
  503. IniFile.INIWriteValue(FilePath, "Product", "Mtltmrk", string.Empty);
  504. }
  505. }
  506. else
  507. {
  508. IniFile.INIWriteValue(FilePath, "Product", "WorkOrderCode", string.Empty);
  509. IniFile.INIWriteValue(FilePath, "Product", "BatchNumber", string.Empty);
  510. IniFile.INIWriteValue(FilePath, "Product", "Mtltmrk", string.Empty);
  511. }
  512. #endregion
  513. }
  514. }
  515. }