Form_SystemSet.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Windows.Forms;
  7. using StandardLibrary;
  8. namespace MainForm
  9. {
  10. public delegate void SystemSetMessageHandler(LogType logType, string message);
  11. public partial class Form_SystemSet : Form
  12. {
  13. private string FilePath = AppDomain.CurrentDomain.BaseDirectory + "Config.ini";
  14. public event SystemSetMessageHandler MessageEvent;
  15. private string currentRole = "";
  16. #region 窗体事件
  17. public Form_SystemSet()
  18. {
  19. InitializeComponent();
  20. }
  21. private void Form_SystemSet_Load(object sender, EventArgs e)
  22. {
  23. // 产品
  24. txtProject_code.Text = IniFile.INIGetStringValue(FilePath, "Product", "ProjectCode", ""); // 项⽬编码
  25. txtFactory_Code.Text = IniFile.INIGetStringValue(FilePath, "Product", "FactoryCode", ""); // ⼯⼚Id
  26. txtProcess_Section_Code.Text = IniFile.INIGetStringValue(FilePath, "Product", "ProcessSectionCode", ""); // ⼯段编码
  27. textBoxLineCode.Text = IniFile.INIGetStringValue(FilePath, "Product", "LineCode", ""); // 线体编码
  28. textBoxLineName.Text = IniFile.INIGetStringValue(FilePath, "Product", "LineName", ""); // 线体名称
  29. txtProgramName.Text = IniFile.INIGetStringValue(FilePath, "Product", "ProgramName", ""); // 程序名称
  30. // MES API配置
  31. chkIsUseMes.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsUseMES", "False"));
  32. textBoxServerHost.Text = IniFile.INIGetStringValue(FilePath, "MES", "ServerHost", GlobalContext.ConstServerHost);
  33. cbSendStationIn.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendStationIn", GlobalContext.ConstIsSend));
  34. cbSendProcessData.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendProcessData", GlobalContext.ConstIsSend));
  35. // MQTT配置
  36. chkIsUseIot.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsUseIot", "False"));
  37. txtMqttIP.Text = IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTServerHost", "127.0.0.1");
  38. numMqttPort.Text = IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTServerPort", "0");
  39. chkMqttPassStation.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSendProcessData", GlobalContext.ConstIsSend)); // 上传过站数据
  40. chkMqttDeviceState.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttDeviceState", GlobalContext.ConstIsSend)); // 上传设备状态
  41. chkMqttFaultLog.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttFaultLog", GlobalContext.ConstIsSend)); // 上传故障⽇志
  42. chkMqttSensorData.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSensorData", GlobalContext.ConstIsSend)); // 上传传感器数据
  43. chkMqttStationInputBegin.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttStationInputBegin", GlobalContext.ConstIsSend)); ; // 上传节拍⽇志
  44. chkMqttOperateLog.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttOperateLog", GlobalContext.ConstIsSend)); // 上传操作记录
  45. chkMqttEquiConfig.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttEquiConfig", GlobalContext.ConstIsSend)); // 上传装备配置
  46. chkMqttProcConfig.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttProcConfig", GlobalContext.ConstIsSend)); // 上传⼯艺配置
  47. chkMqttUpFile.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTIsSendUpFile", GlobalContext.ConstIsSend)); // 上传⼯艺配置
  48. chkMqttPassResult.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSendProcessResult", GlobalContext.ConstIsSend)); // 上传⼯艺配置
  49. // AGV配置
  50. chkIsUseAGV.Checked = bool.Parse(IniFile.INIGetStringValue(FilePath, "AGV", "IsUseAGV", "False")); // 是否 启用AGV
  51. txtAGVHttpIP.Text = IniFile.INIGetStringValue(FilePath, "AGV", "AGVHttpHost", ""); // Http IP地址
  52. txtAGVMQTTIP.Text = IniFile.INIGetStringValue(FilePath, "AGV", "AGVMQTTHost", ""); // MQTT IP地址
  53. numAGVMQTTPort.Text = IniFile.INIGetStringValue(FilePath, "AGV", "AGVMQTTPort", ""); // MQTT端口
  54. txtTPortCode.Text = IniFile.INIGetStringValue(FilePath, "AGV", "AGVMQTTDeviceCode", ""); // MQTT PortCode
  55. txtPLCAddress1.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine1Address", GlobalContext.ConstMachine1Address);
  56. txtPLCAddress2.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine2Address", GlobalContext.ConstMachine2Address);
  57. txtPLCAddress3.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine3Address", GlobalContext.ConstMachine3Address);
  58. txtPLCAddress4.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine4Address", GlobalContext.ConstMachine4Address);
  59. txtPLCAddress5.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine5Address", GlobalContext.ConstMachine5Address);
  60. txtPLCAddress6.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine6Address", GlobalContext.ConstMachine6Address);
  61. txtPLCAddress7.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine7Address", GlobalContext.ConstMachine7Address);
  62. txtPLCAddress8.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine8Address", GlobalContext.ConstMachine8Address);
  63. txtPLCAddress9.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine9Address", GlobalContext.ConstMachine9Address);
  64. numPLCPort.Value = int.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "MachinePort", "0"));
  65. // 机器IP配置
  66. bool boolS1 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC1", "false"));
  67. bool boolS2 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC2", "false"));
  68. bool boolS3 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC3", "false"));
  69. bool boolS4 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC4", "false"));
  70. bool boolS5 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC5", "false"));
  71. bool boolS6 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC6", "false"));
  72. bool boolS7 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC7", "false"));
  73. bool boolS8 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC8", "false"));
  74. bool boolS9 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC9", "false"));
  75. rdbS1.Checked = boolS1;
  76. rdbS2.Checked = boolS2;
  77. rdbS3.Checked = boolS3;
  78. rdbS4.Checked = boolS4;
  79. rdbS5.Checked = boolS5;
  80. rdbS6.Checked = boolS6;
  81. rdbS7.Checked = boolS7;
  82. rdbS8.Checked = boolS8;
  83. rdbS9.Checked = boolS9;
  84. RefreshStationInfo();
  85. }
  86. #endregion 窗体事件
  87. private void RefreshStationInfo() {
  88. // 机器IP配置
  89. bool boolS1 = rdbS1.Checked;
  90. bool boolS2 = rdbS2.Checked;
  91. bool boolS3 = rdbS3.Checked;
  92. bool boolS4 = rdbS4.Checked;
  93. bool boolS5 = rdbS5.Checked;
  94. bool boolS6 = rdbS6.Checked;
  95. bool boolS7 = rdbS7.Checked;
  96. bool boolS8 = rdbS8.Checked;
  97. bool boolS9 = rdbS9.Checked;
  98. txtDeviceCode2.Text = string.Empty;
  99. txtStation2.Text = string.Empty;
  100. txtWorkStation2.Text = string.Empty;
  101. if (boolS1)
  102. {
  103. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s1_work_station", "");
  104. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s1_device_code", "");
  105. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s1_station", "");
  106. }
  107. else if (boolS2)
  108. {
  109. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s2_work_station", "");
  110. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s2_device_code", "");
  111. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s2_1_station", "");
  112. }
  113. else if (boolS3)
  114. {
  115. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_1_work_station", "");
  116. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_1_device_code", "");
  117. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_1_station", "");
  118. txtWorkStation2.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_2_work_station", "");
  119. txtDeviceCode2.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_2_device_code", "");
  120. txtStation2.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_2_station", "");
  121. }
  122. else if (boolS4)
  123. {
  124. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s4_work_station", "");
  125. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s4_device_code", "");
  126. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s4_station", "");
  127. }
  128. else if (boolS5)
  129. {
  130. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s5_work_station", "");
  131. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s5_device_code", "");
  132. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s5_station", "");
  133. }
  134. else if (boolS6)
  135. {
  136. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s6_work_station", "");
  137. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s6_device_code", "");
  138. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s6_station", "");
  139. }
  140. else if (boolS7)
  141. {
  142. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s7_1_work_station", "");
  143. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s7_1_device_code", "");
  144. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s7_1_station", "");
  145. txtWorkStation2.Text = IniFile.INIGetStringValue(FilePath, "Station", "s7_2_work_station", "");
  146. txtDeviceCode2.Text = IniFile.INIGetStringValue(FilePath, "Station", "s7_2_device_code", "");
  147. txtStation2.Text = IniFile.INIGetStringValue(FilePath, "Station", "s7_2_station", "");
  148. }
  149. else if (boolS8)
  150. {
  151. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s8_work_station", "");
  152. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s8_device_code", "");
  153. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s8_station", "");
  154. }
  155. else if (boolS9)
  156. {
  157. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s9_work_station", "");
  158. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s9_device_code", "");
  159. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s9_station", "");
  160. }
  161. }
  162. /// <summary>
  163. /// 改变用户时更新页面
  164. /// </summary>
  165. /// <param name="user"></param>
  166. public void ForUserChangeToUpdate(User user)
  167. {
  168. currentRole = user.ToString();
  169. //switch (user.ToString())
  170. //{
  171. // case "Operator":
  172. // groupBox2.Enabled = false;
  173. // groupBox3.Enabled = false;
  174. // break;
  175. // case "Admin":
  176. // groupBox2.Enabled = true;
  177. // groupBox3.Enabled = false;
  178. // break;
  179. // case "SuperAdmin":
  180. // groupBox2.Enabled = true;
  181. // groupBox3.Enabled = true;
  182. // break;
  183. // default:
  184. // groupBox2.Enabled = true;
  185. // groupBox3.Enabled = true;
  186. // break;
  187. //}
  188. }
  189. /// <summary>
  190. /// 保存产线信息
  191. /// </summary>
  192. private void buttonConfirm_Click(object sender, EventArgs e)
  193. {
  194. RefreshStationInfo();
  195. #region 产线信息
  196. try
  197. {
  198. IniFile.INIWriteValue(FilePath, "Product", "ProjectCode", txtProject_code.Text.Trim());
  199. IniFile.INIWriteValue(FilePath, "Product", "FactoryCode", txtFactory_Code.Text.Trim());
  200. IniFile.INIWriteValue(FilePath, "Product", "ProcessSectionCode", txtProcess_Section_Code.Text.Trim());
  201. IniFile.INIWriteValue(FilePath, "Product", "LineCode", textBoxLineCode.Text.Trim());
  202. IniFile.INIWriteValue(FilePath, "Product", "LineName", textBoxLineName.Text.Trim());
  203. IniFile.INIWriteValue(FilePath, "Product", "ProgramName", txtProgramName.Text.Trim());
  204. // 产品2
  205. if (rdbS1.Checked)
  206. {
  207. IniFile.INIWriteValue(FilePath, "Station", "s1_work_station", txtWorkStation.Text.Trim());
  208. IniFile.INIWriteValue(FilePath, "Station", "s1_device_code", txtDeviceCode.Text.Trim());
  209. IniFile.INIWriteValue(FilePath, "Station", "s1_station", txtStation.Text.Trim());
  210. }
  211. else if (rdbS2.Checked)
  212. {
  213. IniFile.INIWriteValue(FilePath, "Station", "s2_work_station", txtWorkStation.Text.Trim());
  214. IniFile.INIWriteValue(FilePath, "Station", "s2_device_code", txtDeviceCode.Text.Trim());
  215. IniFile.INIWriteValue(FilePath, "Station", "s2_station", txtStation.Text.Trim());
  216. }
  217. else if (rdbS3.Checked)
  218. {
  219. IniFile.INIWriteValue(FilePath, "Station", "s3_1_work_station", txtWorkStation.Text.Trim());
  220. IniFile.INIWriteValue(FilePath, "Station", "s3_1_device_code", txtDeviceCode.Text.Trim());
  221. IniFile.INIWriteValue(FilePath, "Station", "s3_1_station", txtStation.Text.Trim());
  222. IniFile.INIWriteValue(FilePath, "Station", "s3_2_work_station", txtWorkStation2.Text.Trim());
  223. IniFile.INIWriteValue(FilePath, "Station", "s3_2_device_code", txtDeviceCode2.Text.Trim());
  224. IniFile.INIWriteValue(FilePath, "Station", "s3_2_station", txtStation2.Text.Trim());
  225. }
  226. else if (rdbS4.Checked)
  227. {
  228. IniFile.INIWriteValue(FilePath, "Station", "s4_work_station", txtWorkStation.Text.Trim());
  229. IniFile.INIWriteValue(FilePath, "Station", "s4_device_code", txtDeviceCode.Text.Trim());
  230. IniFile.INIWriteValue(FilePath, "Station", "s4_station", txtStation.Text.Trim());
  231. }
  232. else if (rdbS5.Checked)
  233. {
  234. IniFile.INIWriteValue(FilePath, "Station", "s5_work_station", txtWorkStation.Text.Trim());
  235. IniFile.INIWriteValue(FilePath, "Station", "s5_device_code", txtDeviceCode.Text.Trim());
  236. IniFile.INIWriteValue(FilePath, "Station", "s5_station", txtStation.Text.Trim());
  237. }
  238. else if (rdbS6.Checked)
  239. {
  240. IniFile.INIWriteValue(FilePath, "Station", "s6_work_station", txtWorkStation.Text.Trim());
  241. IniFile.INIWriteValue(FilePath, "Station", "s6_device_code", txtDeviceCode.Text.Trim());
  242. IniFile.INIWriteValue(FilePath, "Station", "s6_station", txtStation.Text.Trim());
  243. }
  244. else if (rdbS7.Checked)
  245. {
  246. IniFile.INIWriteValue(FilePath, "Station", "s7_1_work_station", txtWorkStation.Text.Trim());
  247. IniFile.INIWriteValue(FilePath, "Station", "s7_1_device_code", txtDeviceCode.Text.Trim());
  248. IniFile.INIWriteValue(FilePath, "Station", "s7_1_station", txtStation.Text.Trim());
  249. IniFile.INIWriteValue(FilePath, "Station", "s7_2_work_station", txtWorkStation2.Text.Trim());
  250. IniFile.INIWriteValue(FilePath, "Station", "s7_2_device_code", txtDeviceCode2.Text.Trim());
  251. IniFile.INIWriteValue(FilePath, "Station", "s7_2_station", txtStation2.Text.Trim());
  252. }
  253. else if (rdbS8.Checked)
  254. {
  255. IniFile.INIWriteValue(FilePath, "Station", "s8_work_station", txtWorkStation.Text.Trim());
  256. IniFile.INIWriteValue(FilePath, "Station", "s8_device_code", txtDeviceCode.Text.Trim());
  257. IniFile.INIWriteValue(FilePath, "Station", "s8_station", txtStation.Text.Trim());
  258. }
  259. else if (rdbS9.Checked)
  260. {
  261. IniFile.INIWriteValue(FilePath, "Station", "s9_work_station", txtWorkStation.Text.Trim());
  262. IniFile.INIWriteValue(FilePath, "Station", "s9_device_code", txtDeviceCode.Text.Trim());
  263. IniFile.INIWriteValue(FilePath, "Station", "s9_station", txtStation.Text.Trim());
  264. }
  265. GlobalContext.UpdateData();
  266. //记录修改日志
  267. List<string> productSetVlaue = new List<string>();
  268. productSetVlaue.Add(txtProject_code.Text.Trim());
  269. productSetVlaue.Add(txtFactory_Code.Text.Trim());
  270. productSetVlaue.Add(txtProcess_Section_Code.Text.Trim());
  271. productSetVlaue.Add(textBoxLineCode.Text.Trim());
  272. productSetVlaue.Add(textBoxLineName.Text.Trim());
  273. productSetVlaue.Add(txtProgramName.Text.Trim());
  274. productSetVlaue.Add(txtWorkStation.Text.Trim());
  275. productSetVlaue.Add(txtDeviceCode.Text.Trim());
  276. productSetVlaue.Add(txtStation.Text.Trim());
  277. String.Join(";", productSetVlaue);
  278. OnMessage(LogType.Info, currentRole + "修改系统值[产线信息]为[" + String.Join(";", productSetVlaue) + "]");
  279. }
  280. catch (Exception ex)
  281. {
  282. string str = ex.StackTrace;
  283. OnMessage(LogType.Info, "保存产线信息出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  284. }
  285. #endregion
  286. #region MES
  287. try
  288. {
  289. // 是否 启用MES
  290. IniFile.INIWriteValue(FilePath, "MES", "IsUseMES", chkIsUseMes.Checked.ToString());
  291. IniFile.INIWriteValue(FilePath, "MES", "ServerHost", textBoxServerHost.Text.Trim().ToString());
  292. IniFile.INIWriteValue(FilePath, "MES", "IsSendStationIn", cbSendStationIn.Checked.ToString());
  293. IniFile.INIWriteValue(FilePath, "MES", "IsSendProcessData", cbSendProcessData.Checked.ToString());
  294. GlobalContext.UpdateData();
  295. //记录修改日志
  296. List<string> mesSetVlaue = new List<string>();
  297. mesSetVlaue.Add(chkIsUseMes.Checked.ToString());
  298. mesSetVlaue.Add(textBoxServerHost.Text);
  299. mesSetVlaue.Add(cbSendStationIn.Checked.ToString());
  300. mesSetVlaue.Add(cbSendProcessData.Checked.ToString());
  301. String.Join(";", mesSetVlaue);
  302. OnMessage(LogType.Info, currentRole + "修改系统值[MES配置]为[" + String.Join(";", mesSetVlaue) + "]");
  303. }
  304. catch (Exception ex)
  305. {
  306. string str = ex.StackTrace;
  307. OnMessage(LogType.Info, "保存MES配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  308. }
  309. #endregion
  310. #region IOT
  311. try
  312. {
  313. IniFile.INIWriteValue(FilePath, "MQTT", "IsUseIot", chkIsUseIot.Checked.ToString());
  314. IniFile.INIWriteValue(FilePath, "MQTT", "MQTTServerHost", IPAddress.Parse(txtMqttIP.Text.Trim()).ToString());
  315. IniFile.INIWriteValue(FilePath, "MQTT", "MQTTServerPort", numMqttPort.Value.ToString());
  316. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttSendProcessData", chkMqttPassStation.Checked.ToString()); // 上传过站数据
  317. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttDeviceState", chkMqttDeviceState.Checked.ToString()); // 上传设备状态
  318. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttFaultLog", chkMqttFaultLog.Checked.ToString()); // 上传故障⽇志
  319. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttSensorData", chkMqttSensorData.Checked.ToString()); // 上传传感器数据
  320. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttStationInputBegin", chkMqttStationInputBegin.Checked.ToString()); // 上传节拍⽇志
  321. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttOperateLog", chkMqttOperateLog.Checked.ToString()); // 上传操作记录
  322. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttEquiConfig", chkMqttEquiConfig.Checked.ToString()); // 上传装备配置
  323. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttProcConfig", chkMqttProcConfig.Checked.ToString()); // 上传⼯艺配置
  324. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttSendProcessResult", chkMqttPassResult.Checked.ToString()); // 上传过站结果
  325. IniFile.INIWriteValue(FilePath, "MQTT", "MQTTIsSendUpFile", chkMqttUpFile.Checked.ToString()); // 上传非结构化
  326. GlobalContext.UpdateData();
  327. //记录修改日志
  328. List<string> mesSetVlaue = new List<string>();
  329. mesSetVlaue.Add(chkIsUseIot.Checked.ToString());
  330. mesSetVlaue.Add(txtMqttIP.Text.Trim());
  331. mesSetVlaue.Add(numMqttPort.Value.ToString());
  332. mesSetVlaue.Add(chkMqttPassStation.Checked.ToString());
  333. mesSetVlaue.Add(chkMqttDeviceState.Checked.ToString());
  334. mesSetVlaue.Add(chkMqttFaultLog.Checked.ToString());
  335. mesSetVlaue.Add(chkMqttSensorData.Checked.ToString());
  336. mesSetVlaue.Add(chkMqttStationInputBegin.Checked.ToString());
  337. mesSetVlaue.Add(chkMqttOperateLog.Checked.ToString());
  338. mesSetVlaue.Add(chkMqttEquiConfig.Checked.ToString());
  339. mesSetVlaue.Add(chkMqttProcConfig.Checked.ToString());
  340. String.Join(";", mesSetVlaue);
  341. OnMessage(LogType.Info, currentRole + "修改系统值[IOT配置]为[" + String.Join(";", mesSetVlaue) + "]");
  342. }
  343. catch (Exception ex)
  344. {
  345. string str = ex.StackTrace;
  346. OnMessage(LogType.Info, "保存IOT配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  347. }
  348. #endregion
  349. #region AGV
  350. try
  351. {
  352. IniFile.INIWriteValue(FilePath, "AGV", "IsUseAGV", chkIsUseAGV.Checked.ToString()); // 是否 启用AGV
  353. IniFile.INIWriteValue(FilePath, "AGV", "AGVHttpHost", IPAddress.Parse(txtAGVHttpIP.Text.Trim()).ToString()); // Http IP地址
  354. IniFile.INIWriteValue(FilePath, "AGV", "AGVMQTTHost", IPAddress.Parse(txtAGVMQTTIP.Text.Trim()).ToString()); // MQTT IP地址
  355. IniFile.INIWriteValue(FilePath, "AGV", "AGVMQTTPort", numAGVMQTTPort.Value.ToString()); // MQTT端口
  356. IniFile.INIWriteValue(FilePath, "AGV", "AGVMQTTDeviceCode", txtTPortCode.Text.ToString()); // MQTT PortCode
  357. GlobalContext.UpdateData();
  358. //记录修改日志
  359. List<string> mesSetVlaue = new List<string>();
  360. mesSetVlaue.Add(chkIsUseAGV.Checked.ToString());
  361. mesSetVlaue.Add(txtAGVHttpIP.Text.Trim());
  362. mesSetVlaue.Add(txtAGVMQTTIP.Text.Trim());
  363. mesSetVlaue.Add(numAGVMQTTPort.Text.Trim());
  364. mesSetVlaue.Add(txtTPortCode.Text.Trim());
  365. String.Join(";", mesSetVlaue);
  366. OnMessage(LogType.Info, currentRole + "修改系统值[AGV配置]为[" + String.Join(";", mesSetVlaue) + "]");
  367. }
  368. catch (Exception ex)
  369. {
  370. string str = ex.StackTrace;
  371. OnMessage(LogType.Error, "保存AGV配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  372. }
  373. #endregion
  374. #region 装备设置
  375. try
  376. {
  377. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC1", rdbS1.Checked.ToString());
  378. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC2", rdbS2.Checked.ToString());
  379. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC3", rdbS3.Checked.ToString());
  380. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC4", rdbS4.Checked.ToString());
  381. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC5", rdbS5.Checked.ToString());
  382. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC6", rdbS6.Checked.ToString());
  383. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC7", rdbS7.Checked.ToString());
  384. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC8", rdbS8.Checked.ToString());
  385. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC9", rdbS9.Checked.ToString());
  386. IniFile.INIWriteValue(FilePath, "Machine", "Machine1Address", IPAddress.Parse(txtPLCAddress1.Text.Trim()).ToString());
  387. IniFile.INIWriteValue(FilePath, "Machine", "Machine2Address", IPAddress.Parse(txtPLCAddress2.Text.Trim()).ToString());
  388. IniFile.INIWriteValue(FilePath, "Machine", "Machine3Address", IPAddress.Parse(txtPLCAddress3.Text.Trim()).ToString());
  389. IniFile.INIWriteValue(FilePath, "Machine", "Machine4Address", IPAddress.Parse(txtPLCAddress4.Text.Trim()).ToString());
  390. IniFile.INIWriteValue(FilePath, "Machine", "Machine5Address", IPAddress.Parse(txtPLCAddress5.Text.Trim()).ToString());
  391. IniFile.INIWriteValue(FilePath, "Machine", "Machine6Address", IPAddress.Parse(txtPLCAddress6.Text.Trim()).ToString());
  392. IniFile.INIWriteValue(FilePath, "Machine", "Machine7Address", IPAddress.Parse(txtPLCAddress7.Text.Trim()).ToString());
  393. IniFile.INIWriteValue(FilePath, "Machine", "Machine8Address", IPAddress.Parse(txtPLCAddress8.Text.Trim()).ToString());
  394. IniFile.INIWriteValue(FilePath, "Machine", "Machine9Address", IPAddress.Parse(txtPLCAddress9.Text.Trim()).ToString());
  395. IniFile.INIWriteValue(FilePath, "Machine", "MachinePort", numPLCPort.Value.ToString());
  396. GlobalContext.UpdateData();
  397. //记录修改日志
  398. List<string> machineSetVlaue = new List<string>();
  399. machineSetVlaue.Add(rdbS1.Checked.ToString());
  400. machineSetVlaue.Add(rdbS2.Checked.ToString());
  401. machineSetVlaue.Add(rdbS3.Checked.ToString());
  402. machineSetVlaue.Add(rdbS4.Checked.ToString());
  403. machineSetVlaue.Add(rdbS5.Checked.ToString());
  404. machineSetVlaue.Add(rdbS6.Checked.ToString());
  405. machineSetVlaue.Add(rdbS7.Checked.ToString());
  406. machineSetVlaue.Add(rdbS8.Checked.ToString());
  407. machineSetVlaue.Add(rdbS9.Checked.ToString());
  408. machineSetVlaue.Add(txtPLCAddress1.Text.Trim());
  409. machineSetVlaue.Add(txtPLCAddress2.Text.Trim());
  410. machineSetVlaue.Add(txtPLCAddress3.Text.Trim());
  411. machineSetVlaue.Add(txtPLCAddress4.Text.Trim());
  412. machineSetVlaue.Add(txtPLCAddress5.Text.Trim());
  413. machineSetVlaue.Add(txtPLCAddress6.Text.Trim());
  414. machineSetVlaue.Add(txtPLCAddress7.Text.Trim());
  415. machineSetVlaue.Add(txtPLCAddress8.Text.Trim());
  416. machineSetVlaue.Add(txtPLCAddress9.Text.Trim());
  417. machineSetVlaue.Add(numPLCPort.Value.ToString());
  418. String.Join(";", machineSetVlaue);
  419. OnMessage(LogType.Info, currentRole + "修改系统值[设备配置]为[" + String.Join(";", machineSetVlaue) + "]");
  420. }
  421. catch (Exception ex)
  422. {
  423. string str = ex.StackTrace;
  424. OnMessage(LogType.Error, "保存设备配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  425. }
  426. #endregion
  427. try
  428. {
  429. MessageBox.Show("参数保存成功!");
  430. Form_Home home = new Form_Home();
  431. home.ConnectToIOT();//上抛iot配置修改
  432. home.deviceConfigToIot("project_name", GlobalContext.Project_Code);//上抛装备配置
  433. GlobalContext.UpdateData();
  434. }
  435. catch (Exception)
  436. {
  437. throw;
  438. }
  439. }
  440. /// <summary>
  441. /// 获取订单信息
  442. /// </summary>
  443. private void btnGetOrderInfo_Click(object sender, EventArgs e)
  444. {
  445. }
  446. //private void textBoxWC_KeyPress(object sender, KeyPressEventArgs e)
  447. //{
  448. // if (e.KeyChar == 13)
  449. // {
  450. // WorkOrderInfo workOrderInfo;
  451. // workOrderInfo = HttpUitls.GetWOData(textBoxWC.Text.Trim());
  452. // if (workOrderInfo != null)
  453. // {
  454. // textBoxWC.Text = workOrderInfo.sono;
  455. // textBoxBN.Text = workOrderInfo.splcode;
  456. // comboBoxProductModel.Text = workOrderInfo.prtno;
  457. // comboBoxKeyValue.Text = workOrderInfo.prodline;
  458. // }
  459. // else
  460. // {
  461. // textBoxWC.Text = string.Empty;
  462. // }
  463. // }
  464. //}
  465. /// <summary>
  466. /// 保存信息
  467. /// </summary>
  468. /// <param name="logType"></param>
  469. /// <param name="msg"></param>
  470. private void OnMessage(LogType logType, string msg)
  471. {
  472. MessageEvent?.Invoke(logType, msg);
  473. }
  474. }
  475. }