Form_SystemSet.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. // 机器IP配置
  56. bool boolS1 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC1", "false"));
  57. bool boolS2 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC2", "false"));
  58. bool boolS3 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC3", "false"));
  59. bool boolS4 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC4", "false"));
  60. bool boolS5 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC5", "false"));
  61. bool boolS6 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC6", "false"));
  62. bool boolS7 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC7", "false"));
  63. bool boolS8 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC8", "false"));
  64. bool boolS9 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC9", "false"));
  65. rdbS1.Checked = boolS1;
  66. rdbS2.Checked = boolS2;
  67. rdbS3.Checked = boolS3;
  68. rdbS4.Checked = boolS4;
  69. rdbS5.Checked = boolS5;
  70. rdbS6.Checked = boolS6;
  71. rdbS7.Checked = boolS7;
  72. rdbS8.Checked = boolS8;
  73. rdbS9.Checked = boolS9;
  74. txtPLCAddress1.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine1Address", GlobalContext.ConstMachine1Address);
  75. txtPLCAddress2.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine2Address", GlobalContext.ConstMachine2Address);
  76. txtPLCAddress3.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine3Address", GlobalContext.ConstMachine3Address);
  77. txtPLCAddress4.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine4Address", GlobalContext.ConstMachine4Address);
  78. txtPLCAddress5.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine5Address", GlobalContext.ConstMachine5Address);
  79. txtPLCAddress6.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine6Address", GlobalContext.ConstMachine6Address);
  80. txtPLCAddress7.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine7Address", GlobalContext.ConstMachine7Address);
  81. txtPLCAddress8.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine8Address", GlobalContext.ConstMachine8Address);
  82. txtPLCAddress9.Text = IniFile.INIGetStringValue(FilePath, "Machine", "Machine9Address", GlobalContext.ConstMachine9Address);
  83. numPLCPort.Value = int.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "MachinePort", "0"));
  84. // 产品2
  85. if (boolS1)
  86. {
  87. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s1_work_station", "");
  88. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s1_device_code", "");
  89. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s1_station", "");
  90. }
  91. else if (boolS2)
  92. {
  93. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s2_work_station", "");
  94. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s2_device_code", "");
  95. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_station", "");
  96. }
  97. else if (boolS3)
  98. {
  99. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_work_station", "");
  100. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_device_code", "");
  101. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s3_station", "");
  102. }
  103. else if (boolS4)
  104. {
  105. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s4_work_station", "");
  106. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s4_device_code", "");
  107. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s4_station", "");
  108. }
  109. else if (boolS5)
  110. {
  111. txtWorkStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s5_work_station", "");
  112. txtDeviceCode.Text = IniFile.INIGetStringValue(FilePath, "Station", "s5_device_code", "");
  113. txtStation.Text = IniFile.INIGetStringValue(FilePath, "Station", "s5_station", "");
  114. }
  115. }
  116. #endregion 窗体事件
  117. /// <summary>
  118. /// 改变用户时更新页面
  119. /// </summary>
  120. /// <param name="user"></param>
  121. public void ForUserChangeToUpdate(User user)
  122. {
  123. currentRole = user.ToString();
  124. //switch (user.ToString())
  125. //{
  126. // case "Operator":
  127. // groupBox2.Enabled = false;
  128. // groupBox3.Enabled = false;
  129. // break;
  130. // case "Admin":
  131. // groupBox2.Enabled = true;
  132. // groupBox3.Enabled = false;
  133. // break;
  134. // case "SuperAdmin":
  135. // groupBox2.Enabled = true;
  136. // groupBox3.Enabled = true;
  137. // break;
  138. // default:
  139. // groupBox2.Enabled = true;
  140. // groupBox3.Enabled = true;
  141. // break;
  142. //}
  143. }
  144. /// <summary>
  145. /// 保存产线信息
  146. /// </summary>
  147. private void buttonConfirm_Click(object sender, EventArgs e)
  148. {
  149. #region 产线信息
  150. try
  151. {
  152. IniFile.INIWriteValue(FilePath, "Product", "ProjectCode", txtProject_code.Text.Trim());
  153. IniFile.INIWriteValue(FilePath, "Product", "FactoryCode", txtFactory_Code.Text.Trim());
  154. IniFile.INIWriteValue(FilePath, "Product", "ProcessSectionCode", txtProcess_Section_Code.Text.Trim());
  155. IniFile.INIWriteValue(FilePath, "Product", "LineCode", textBoxLineCode.Text.Trim());
  156. IniFile.INIWriteValue(FilePath, "Product", "LineName", textBoxLineName.Text.Trim());
  157. IniFile.INIWriteValue(FilePath, "Product", "ProgramName", txtProgramName.Text.Trim());
  158. // 产品2
  159. if (rdbS1.Checked)
  160. {
  161. IniFile.INIWriteValue(FilePath, "Station", "s1_work_station", txtWorkStation.Text.Trim());
  162. IniFile.INIWriteValue(FilePath, "Station", "s1_device_code", txtDeviceCode.Text.Trim());
  163. IniFile.INIWriteValue(FilePath, "Station", "s1_station", txtStation.Text.Trim());
  164. }
  165. else if (rdbS2.Checked)
  166. {
  167. IniFile.INIWriteValue(FilePath, "Station", "s2_work_station", txtWorkStation.Text.Trim());
  168. IniFile.INIWriteValue(FilePath, "Station", "s2_device_code", txtDeviceCode.Text.Trim());
  169. IniFile.INIWriteValue(FilePath, "Station", "s2_station", txtStation.Text.Trim());
  170. }
  171. else if (rdbS3.Checked)
  172. {
  173. IniFile.INIWriteValue(FilePath, "Station", "s3_work_station", txtWorkStation.Text.Trim());
  174. IniFile.INIWriteValue(FilePath, "Station", "s3_device_code", txtDeviceCode.Text.Trim());
  175. IniFile.INIWriteValue(FilePath, "Station", "s3_station", txtStation.Text.Trim());
  176. }
  177. else if (rdbS4.Checked)
  178. {
  179. IniFile.INIWriteValue(FilePath, "Station", "s4_work_station", txtWorkStation.Text.Trim());
  180. IniFile.INIWriteValue(FilePath, "Station", "s4_device_code", txtDeviceCode.Text.Trim());
  181. IniFile.INIWriteValue(FilePath, "Station", "s4_station", txtStation.Text.Trim());
  182. }
  183. else if (rdbS5.Checked)
  184. {
  185. IniFile.INIWriteValue(FilePath, "Station", "s5_work_station", txtWorkStation.Text.Trim());
  186. IniFile.INIWriteValue(FilePath, "Station", "s5_device_code", txtDeviceCode.Text.Trim());
  187. IniFile.INIWriteValue(FilePath, "Station", "s5_station", txtStation.Text.Trim());
  188. }
  189. else if (rdbS6.Checked)
  190. {
  191. IniFile.INIWriteValue(FilePath, "Station", "s6_work_station", txtWorkStation.Text.Trim());
  192. IniFile.INIWriteValue(FilePath, "Station", "s6_device_code", txtDeviceCode.Text.Trim());
  193. IniFile.INIWriteValue(FilePath, "Station", "s6_station", txtStation.Text.Trim());
  194. }
  195. else if (rdbS7.Checked)
  196. {
  197. IniFile.INIWriteValue(FilePath, "Station", "s7_work_station", txtWorkStation.Text.Trim());
  198. IniFile.INIWriteValue(FilePath, "Station", "s7_device_code", txtDeviceCode.Text.Trim());
  199. IniFile.INIWriteValue(FilePath, "Station", "s7_station", txtStation.Text.Trim());
  200. }
  201. else if (rdbS8.Checked)
  202. {
  203. IniFile.INIWriteValue(FilePath, "Station", "s8_work_station", txtWorkStation.Text.Trim());
  204. IniFile.INIWriteValue(FilePath, "Station", "s8_device_code", txtDeviceCode.Text.Trim());
  205. IniFile.INIWriteValue(FilePath, "Station", "s8_station", txtStation.Text.Trim());
  206. }
  207. else if (rdbS9.Checked)
  208. {
  209. IniFile.INIWriteValue(FilePath, "Station", "s9_work_station", txtWorkStation.Text.Trim());
  210. IniFile.INIWriteValue(FilePath, "Station", "s9_device_code", txtDeviceCode.Text.Trim());
  211. IniFile.INIWriteValue(FilePath, "Station", "s9_station", txtStation.Text.Trim());
  212. }
  213. GlobalContext.UpdateData();
  214. //记录修改日志
  215. List<string> productSetVlaue = new List<string>();
  216. productSetVlaue.Add(txtProject_code.Text.Trim());
  217. productSetVlaue.Add(txtFactory_Code.Text.Trim());
  218. productSetVlaue.Add(txtProcess_Section_Code.Text.Trim());
  219. productSetVlaue.Add(textBoxLineCode.Text.Trim());
  220. productSetVlaue.Add(textBoxLineName.Text.Trim());
  221. productSetVlaue.Add(txtProgramName.Text.Trim());
  222. productSetVlaue.Add(txtWorkStation.Text.Trim());
  223. productSetVlaue.Add(txtDeviceCode.Text.Trim());
  224. productSetVlaue.Add(txtStation.Text.Trim());
  225. String.Join(";", productSetVlaue);
  226. OnMessage(LogType.Info, currentRole + "修改系统值[产线信息]为[" + String.Join(";", productSetVlaue) + "]");
  227. }
  228. catch (Exception ex)
  229. {
  230. string str = ex.StackTrace;
  231. OnMessage(LogType.Info, "保存产线信息出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  232. }
  233. #endregion
  234. #region MES
  235. try
  236. {
  237. // 是否 启用MES
  238. IniFile.INIWriteValue(FilePath, "MES", "IsUseMES", chkIsUseMes.Checked.ToString());
  239. IniFile.INIWriteValue(FilePath, "MES", "ServerHost", textBoxServerHost.Text.Trim().ToString());
  240. IniFile.INIWriteValue(FilePath, "MES", "IsSendStationIn", cbSendStationIn.Checked.ToString());
  241. IniFile.INIWriteValue(FilePath, "MES", "IsSendProcessData", cbSendProcessData.Checked.ToString());
  242. GlobalContext.UpdateData();
  243. //记录修改日志
  244. List<string> mesSetVlaue = new List<string>();
  245. mesSetVlaue.Add(chkIsUseMes.Checked.ToString());
  246. mesSetVlaue.Add(textBoxServerHost.Text);
  247. mesSetVlaue.Add(cbSendStationIn.Checked.ToString());
  248. mesSetVlaue.Add(cbSendProcessData.Checked.ToString());
  249. String.Join(";", mesSetVlaue);
  250. OnMessage(LogType.Info, currentRole + "修改系统值[MES配置]为[" + String.Join(";", mesSetVlaue) + "]");
  251. }
  252. catch (Exception ex)
  253. {
  254. string str = ex.StackTrace;
  255. OnMessage(LogType.Info, "保存MES配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  256. }
  257. #endregion
  258. #region IOT
  259. try
  260. {
  261. IniFile.INIWriteValue(FilePath, "MQTT", "IsUseIot", chkIsUseIot.Checked.ToString());
  262. IniFile.INIWriteValue(FilePath, "MQTT", "MQTTServerHost", IPAddress.Parse(txtMqttIP.Text.Trim()).ToString());
  263. IniFile.INIWriteValue(FilePath, "MQTT", "MQTTServerPort", numMqttPort.Value.ToString());
  264. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttSendProcessData", chkMqttPassStation.Checked.ToString()); // 上传过站数据
  265. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttDeviceState", chkMqttDeviceState.Checked.ToString()); // 上传设备状态
  266. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttFaultLog", chkMqttFaultLog.Checked.ToString()); // 上传故障⽇志
  267. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttSensorData", chkMqttSensorData.Checked.ToString()); // 上传传感器数据
  268. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttStationInputBegin", chkMqttStationInputBegin.Checked.ToString()); // 上传节拍⽇志
  269. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttOperateLog", chkMqttOperateLog.Checked.ToString()); // 上传操作记录
  270. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttEquiConfig", chkMqttEquiConfig.Checked.ToString()); // 上传装备配置
  271. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttProcConfig", chkMqttProcConfig.Checked.ToString()); // 上传⼯艺配置
  272. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttSendProcessResult", chkMqttPassResult.Checked.ToString()); // 上传过站结果
  273. IniFile.INIWriteValue(FilePath, "MQTT", "MQTTIsSendUpFile", chkMqttUpFile.Checked.ToString()); // 上传非结构化
  274. GlobalContext.UpdateData();
  275. //记录修改日志
  276. List<string> mesSetVlaue = new List<string>();
  277. mesSetVlaue.Add(chkIsUseIot.Checked.ToString());
  278. mesSetVlaue.Add(txtMqttIP.Text.Trim());
  279. mesSetVlaue.Add(numMqttPort.Value.ToString());
  280. mesSetVlaue.Add(chkMqttPassStation.Checked.ToString());
  281. mesSetVlaue.Add(chkMqttDeviceState.Checked.ToString());
  282. mesSetVlaue.Add(chkMqttFaultLog.Checked.ToString());
  283. mesSetVlaue.Add(chkMqttSensorData.Checked.ToString());
  284. mesSetVlaue.Add(chkMqttStationInputBegin.Checked.ToString());
  285. mesSetVlaue.Add(chkMqttOperateLog.Checked.ToString());
  286. mesSetVlaue.Add(chkMqttEquiConfig.Checked.ToString());
  287. mesSetVlaue.Add(chkMqttProcConfig.Checked.ToString());
  288. String.Join(";", mesSetVlaue);
  289. OnMessage(LogType.Info, currentRole + "修改系统值[IOT配置]为[" + String.Join(";", mesSetVlaue) + "]");
  290. }
  291. catch (Exception ex)
  292. {
  293. string str = ex.StackTrace;
  294. OnMessage(LogType.Info, "保存IOT配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  295. }
  296. #endregion
  297. #region AGV
  298. try
  299. {
  300. IniFile.INIWriteValue(FilePath, "AGV", "IsUseAGV", chkIsUseAGV.Checked.ToString()); // 是否 启用AGV
  301. IniFile.INIWriteValue(FilePath, "AGV", "AGVHttpHost", IPAddress.Parse(txtAGVHttpIP.Text.Trim()).ToString()); // Http IP地址
  302. IniFile.INIWriteValue(FilePath, "AGV", "AGVMQTTHost", IPAddress.Parse(txtAGVMQTTIP.Text.Trim()).ToString()); // MQTT IP地址
  303. IniFile.INIWriteValue(FilePath, "AGV", "AGVMQTTPort", numAGVMQTTPort.Value.ToString()); // MQTT端口
  304. IniFile.INIWriteValue(FilePath, "AGV", "AGVMQTTDeviceCode", txtTPortCode.Text.ToString()); // MQTT PortCode
  305. GlobalContext.UpdateData();
  306. //记录修改日志
  307. List<string> mesSetVlaue = new List<string>();
  308. mesSetVlaue.Add(chkIsUseAGV.Checked.ToString());
  309. mesSetVlaue.Add(txtAGVHttpIP.Text.Trim());
  310. mesSetVlaue.Add(txtAGVMQTTIP.Text.Trim());
  311. mesSetVlaue.Add(numAGVMQTTPort.Text.Trim());
  312. mesSetVlaue.Add(txtTPortCode.Text.Trim());
  313. String.Join(";", mesSetVlaue);
  314. OnMessage(LogType.Info, currentRole + "修改系统值[AGV配置]为[" + String.Join(";", mesSetVlaue) + "]");
  315. }
  316. catch (Exception ex)
  317. {
  318. string str = ex.StackTrace;
  319. OnMessage(LogType.Error, "保存AGV配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  320. }
  321. #endregion
  322. #region 装备设置
  323. try
  324. {
  325. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC1", rdbS1.Checked.ToString());
  326. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC2", rdbS2.Checked.ToString());
  327. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC3", rdbS3.Checked.ToString());
  328. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC4", rdbS4.Checked.ToString());
  329. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC5", rdbS5.Checked.ToString());
  330. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC6", rdbS6.Checked.ToString());
  331. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC7", rdbS7.Checked.ToString());
  332. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC8", rdbS8.Checked.ToString());
  333. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC9", rdbS9.Checked.ToString());
  334. IniFile.INIWriteValue(FilePath, "Machine", "Machine1Address", IPAddress.Parse(txtPLCAddress1.Text.Trim()).ToString());
  335. IniFile.INIWriteValue(FilePath, "Machine", "Machine2Address", IPAddress.Parse(txtPLCAddress2.Text.Trim()).ToString());
  336. IniFile.INIWriteValue(FilePath, "Machine", "Machine3Address", IPAddress.Parse(txtPLCAddress3.Text.Trim()).ToString());
  337. IniFile.INIWriteValue(FilePath, "Machine", "Machine4Address", IPAddress.Parse(txtPLCAddress4.Text.Trim()).ToString());
  338. IniFile.INIWriteValue(FilePath, "Machine", "Machine5Address", IPAddress.Parse(txtPLCAddress5.Text.Trim()).ToString());
  339. IniFile.INIWriteValue(FilePath, "Machine", "Machine6Address", IPAddress.Parse(txtPLCAddress6.Text.Trim()).ToString());
  340. IniFile.INIWriteValue(FilePath, "Machine", "Machine7Address", IPAddress.Parse(txtPLCAddress7.Text.Trim()).ToString());
  341. IniFile.INIWriteValue(FilePath, "Machine", "Machine8Address", IPAddress.Parse(txtPLCAddress8.Text.Trim()).ToString());
  342. IniFile.INIWriteValue(FilePath, "Machine", "Machine9Address", IPAddress.Parse(txtPLCAddress9.Text.Trim()).ToString());
  343. IniFile.INIWriteValue(FilePath, "Machine", "MachinePort", numPLCPort.Value.ToString());
  344. GlobalContext.UpdateData();
  345. //记录修改日志
  346. List<string> machineSetVlaue = new List<string>();
  347. machineSetVlaue.Add(rdbS1.Checked.ToString());
  348. machineSetVlaue.Add(rdbS2.Checked.ToString());
  349. machineSetVlaue.Add(rdbS3.Checked.ToString());
  350. machineSetVlaue.Add(rdbS4.Checked.ToString());
  351. machineSetVlaue.Add(rdbS5.Checked.ToString());
  352. machineSetVlaue.Add(rdbS6.Checked.ToString());
  353. machineSetVlaue.Add(rdbS7.Checked.ToString());
  354. machineSetVlaue.Add(rdbS8.Checked.ToString());
  355. machineSetVlaue.Add(rdbS9.Checked.ToString());
  356. machineSetVlaue.Add(txtPLCAddress1.Text.Trim());
  357. machineSetVlaue.Add(txtPLCAddress2.Text.Trim());
  358. machineSetVlaue.Add(txtPLCAddress3.Text.Trim());
  359. machineSetVlaue.Add(txtPLCAddress4.Text.Trim());
  360. machineSetVlaue.Add(txtPLCAddress5.Text.Trim());
  361. machineSetVlaue.Add(txtPLCAddress6.Text.Trim());
  362. machineSetVlaue.Add(txtPLCAddress7.Text.Trim());
  363. machineSetVlaue.Add(txtPLCAddress8.Text.Trim());
  364. machineSetVlaue.Add(txtPLCAddress9.Text.Trim());
  365. machineSetVlaue.Add(numPLCPort.Value.ToString());
  366. String.Join(";", machineSetVlaue);
  367. OnMessage(LogType.Info, currentRole + "修改系统值[设备配置]为[" + String.Join(";", machineSetVlaue) + "]");
  368. }
  369. catch (Exception ex)
  370. {
  371. string str = ex.StackTrace;
  372. OnMessage(LogType.Error, "保存设备配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  373. }
  374. #endregion
  375. try
  376. {
  377. MessageBox.Show("参数保存成功!");
  378. Form_Home home = new Form_Home();
  379. home.ConnectToIOT();
  380. GlobalContext.UpdateData();
  381. }
  382. catch (Exception)
  383. {
  384. throw;
  385. }
  386. }
  387. /// <summary>
  388. /// 获取订单信息
  389. /// </summary>
  390. private void btnGetOrderInfo_Click(object sender, EventArgs e)
  391. {
  392. }
  393. //private void textBoxWC_KeyPress(object sender, KeyPressEventArgs e)
  394. //{
  395. // if (e.KeyChar == 13)
  396. // {
  397. // WorkOrderInfo workOrderInfo;
  398. // workOrderInfo = HttpUitls.GetWOData(textBoxWC.Text.Trim());
  399. // if (workOrderInfo != null)
  400. // {
  401. // textBoxWC.Text = workOrderInfo.sono;
  402. // textBoxBN.Text = workOrderInfo.splcode;
  403. // comboBoxProductModel.Text = workOrderInfo.prtno;
  404. // comboBoxKeyValue.Text = workOrderInfo.prodline;
  405. // }
  406. // else
  407. // {
  408. // textBoxWC.Text = string.Empty;
  409. // }
  410. // }
  411. //}
  412. /// <summary>
  413. /// 保存信息
  414. /// </summary>
  415. /// <param name="logType"></param>
  416. /// <param name="msg"></param>
  417. private void OnMessage(LogType logType, string msg)
  418. {
  419. MessageEvent?.Invoke(logType, msg);
  420. }
  421. }
  422. }