Form_SystemSet.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. try
  150. {
  151. IniFile.INIWriteValue(FilePath, "Product", "ProjectCode", txtProject_code.Text.Trim());
  152. IniFile.INIWriteValue(FilePath, "Product", "FactoryCode", txtFactory_Code.Text.Trim());
  153. IniFile.INIWriteValue(FilePath, "Product", "ProcessSectionCode", txtProcess_Section_Code.Text.Trim());
  154. IniFile.INIWriteValue(FilePath, "Product", "LineCode", textBoxLineCode.Text.Trim());
  155. IniFile.INIWriteValue(FilePath, "Product", "LineName", textBoxLineName.Text.Trim());
  156. IniFile.INIWriteValue(FilePath, "Product", "ProgramName", txtProgramName.Text.Trim());
  157. // 产品2
  158. if (rdbS1.Checked)
  159. {
  160. IniFile.INIWriteValue(FilePath, "Station", "s1_work_station", txtWorkStation.Text.Trim());
  161. IniFile.INIWriteValue(FilePath, "Station", "s1_device_code", txtDeviceCode.Text.Trim());
  162. IniFile.INIWriteValue(FilePath, "Station", "s1_station", txtStation.Text.Trim());
  163. }
  164. else if (rdbS2.Checked)
  165. {
  166. IniFile.INIWriteValue(FilePath, "Station", "s2_work_station", txtWorkStation.Text.Trim());
  167. IniFile.INIWriteValue(FilePath, "Station", "s2_device_code", txtDeviceCode.Text.Trim());
  168. IniFile.INIWriteValue(FilePath, "Station", "s2_station", txtStation.Text.Trim());
  169. }
  170. else if (rdbS3.Checked)
  171. {
  172. IniFile.INIWriteValue(FilePath, "Station", "s3_work_station", txtWorkStation.Text.Trim());
  173. IniFile.INIWriteValue(FilePath, "Station", "s3_device_code", txtDeviceCode.Text.Trim());
  174. IniFile.INIWriteValue(FilePath, "Station", "s3_station", txtStation.Text.Trim());
  175. }
  176. else if (rdbS4.Checked)
  177. {
  178. IniFile.INIWriteValue(FilePath, "Station", "s4_work_station", txtWorkStation.Text.Trim());
  179. IniFile.INIWriteValue(FilePath, "Station", "s4_device_code", txtDeviceCode.Text.Trim());
  180. IniFile.INIWriteValue(FilePath, "Station", "s4_station", txtStation.Text.Trim());
  181. }
  182. else if (rdbS5.Checked)
  183. {
  184. IniFile.INIWriteValue(FilePath, "Station", "s5_work_station", txtWorkStation.Text.Trim());
  185. IniFile.INIWriteValue(FilePath, "Station", "s5_device_code", txtDeviceCode.Text.Trim());
  186. IniFile.INIWriteValue(FilePath, "Station", "s5_station", txtStation.Text.Trim());
  187. }
  188. else if (rdbS6.Checked)
  189. {
  190. IniFile.INIWriteValue(FilePath, "Station", "s6_work_station", txtWorkStation.Text.Trim());
  191. IniFile.INIWriteValue(FilePath, "Station", "s6_device_code", txtDeviceCode.Text.Trim());
  192. IniFile.INIWriteValue(FilePath, "Station", "s6_station", txtStation.Text.Trim());
  193. }
  194. else if (rdbS7.Checked)
  195. {
  196. IniFile.INIWriteValue(FilePath, "Station", "s7_work_station", txtWorkStation.Text.Trim());
  197. IniFile.INIWriteValue(FilePath, "Station", "s7_device_code", txtDeviceCode.Text.Trim());
  198. IniFile.INIWriteValue(FilePath, "Station", "s7_station", txtStation.Text.Trim());
  199. }
  200. else if (rdbS8.Checked)
  201. {
  202. IniFile.INIWriteValue(FilePath, "Station", "s8_work_station", txtWorkStation.Text.Trim());
  203. IniFile.INIWriteValue(FilePath, "Station", "s8_device_code", txtDeviceCode.Text.Trim());
  204. IniFile.INIWriteValue(FilePath, "Station", "s8_station", txtStation.Text.Trim());
  205. }
  206. else if (rdbS9.Checked)
  207. {
  208. IniFile.INIWriteValue(FilePath, "Station", "s9_work_station", txtWorkStation.Text.Trim());
  209. IniFile.INIWriteValue(FilePath, "Station", "s9_device_code", txtDeviceCode.Text.Trim());
  210. IniFile.INIWriteValue(FilePath, "Station", "s9_station", txtStation.Text.Trim());
  211. }
  212. MessageBox.Show("参数保存成功!");
  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. }
  234. /// <summary>
  235. /// 保存MES配置
  236. /// </summary>
  237. private void button2_Click(object sender, EventArgs e)
  238. {
  239. try
  240. {
  241. // 是否 启用MES
  242. IniFile.INIWriteValue(FilePath, "MES", "IsUseMES", chkIsUseMes.Checked.ToString());
  243. IniFile.INIWriteValue(FilePath, "MES", "ServerHost", textBoxServerHost.Text.Trim().ToString());
  244. IniFile.INIWriteValue(FilePath, "MES", "IsSendStationIn", cbSendStationIn.Checked.ToString());
  245. IniFile.INIWriteValue(FilePath, "MES", "IsSendProcessData", cbSendProcessData.Checked.ToString());
  246. MessageBox.Show("参数保存成功!");
  247. GlobalContext.UpdateData();
  248. //记录修改日志
  249. List<string> mesSetVlaue = new List<string>();
  250. mesSetVlaue.Add(chkIsUseMes.Checked.ToString());
  251. mesSetVlaue.Add(textBoxServerHost.Text);
  252. mesSetVlaue.Add(cbSendStationIn.Checked.ToString());
  253. mesSetVlaue.Add(cbSendProcessData.Checked.ToString());
  254. String.Join(";", mesSetVlaue);
  255. OnMessage(LogType.Info, currentRole + "修改系统值[MES配置]为[" + String.Join(";", mesSetVlaue) + "]");
  256. }
  257. catch (Exception ex)
  258. {
  259. string str = ex.StackTrace;
  260. OnMessage(LogType.Info, "保存MES配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  261. }
  262. }
  263. /// <summary>
  264. /// 保存IOT配置
  265. /// </summary>
  266. private void btnIOTData_Click(object sender, EventArgs e)
  267. {
  268. try
  269. {
  270. IniFile.INIWriteValue(FilePath, "MQTT", "IsUseIot", chkIsUseIot.Checked.ToString());
  271. IniFile.INIWriteValue(FilePath, "MQTT", "MQTTServerHost", IPAddress.Parse(txtMqttIP.Text.Trim()).ToString());
  272. IniFile.INIWriteValue(FilePath, "MQTT", "MQTTServerPort", numMqttPort.Value.ToString());
  273. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttSendProcessData", chkMqttPassStation.Checked.ToString()); // 上传过站数据
  274. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttDeviceState", chkMqttDeviceState.Checked.ToString()); // 上传设备状态
  275. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttFaultLog", chkMqttFaultLog.Checked.ToString()); // 上传故障⽇志
  276. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttSensorData", chkMqttSensorData.Checked.ToString()); // 上传传感器数据
  277. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttStationInputBegin", chkMqttStationInputBegin.Checked.ToString()); // 上传节拍⽇志
  278. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttOperateLog", chkMqttOperateLog.Checked.ToString()); // 上传操作记录
  279. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttEquiConfig", chkMqttEquiConfig.Checked.ToString()); // 上传装备配置
  280. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttProcConfig", chkMqttProcConfig.Checked.ToString()); // 上传⼯艺配置
  281. IniFile.INIWriteValue(FilePath, "MQTT", "IsMqttSendProcessResult", chkMqttPassResult.Checked.ToString()); // 上传过站结果
  282. IniFile.INIWriteValue(FilePath, "MQTT", "MQTTIsSendUpFile", chkMqttUpFile.Checked.ToString()); // 上传非结构化
  283. MessageBox.Show("参数保存成功!");
  284. GlobalContext.UpdateData();
  285. //记录修改日志
  286. List<string> mesSetVlaue = new List<string>();
  287. mesSetVlaue.Add(chkIsUseIot.Checked.ToString());
  288. mesSetVlaue.Add(txtMqttIP.Text.Trim());
  289. mesSetVlaue.Add(numMqttPort.Value.ToString());
  290. mesSetVlaue.Add(chkMqttPassStation.Checked.ToString());
  291. mesSetVlaue.Add(chkMqttDeviceState.Checked.ToString());
  292. mesSetVlaue.Add(chkMqttFaultLog.Checked.ToString());
  293. mesSetVlaue.Add(chkMqttSensorData.Checked.ToString());
  294. mesSetVlaue.Add(chkMqttStationInputBegin.Checked.ToString());
  295. mesSetVlaue.Add(chkMqttOperateLog.Checked.ToString());
  296. mesSetVlaue.Add(chkMqttEquiConfig.Checked.ToString());
  297. mesSetVlaue.Add(chkMqttProcConfig.Checked.ToString());
  298. String.Join(";", mesSetVlaue);
  299. OnMessage(LogType.Info, currentRole + "修改系统值[IOT配置]为[" + String.Join(";", mesSetVlaue) + "]");
  300. }
  301. catch (Exception ex)
  302. {
  303. string str = ex.StackTrace;
  304. OnMessage(LogType.Info, "保存IOT配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  305. }
  306. }
  307. /// <summary>
  308. /// 保存AGV配置
  309. /// </summary>
  310. private void btnAGV_Click(object sender, EventArgs e)
  311. {
  312. try
  313. {
  314. IniFile.INIWriteValue(FilePath, "AGV", "IsUseAGV", chkIsUseAGV.Checked.ToString()); // 是否 启用AGV
  315. IniFile.INIWriteValue(FilePath, "AGV", "AGVHttpHost", IPAddress.Parse(txtAGVHttpIP.Text.Trim()).ToString()); // Http IP地址
  316. IniFile.INIWriteValue(FilePath, "AGV", "AGVMQTTHost", IPAddress.Parse(txtAGVMQTTIP.Text.Trim()).ToString()); // MQTT IP地址
  317. IniFile.INIWriteValue(FilePath, "AGV", "AGVMQTTPort", numAGVMQTTPort.Value.ToString()); // MQTT端口
  318. IniFile.INIWriteValue(FilePath, "AGV", "AGVMQTTDeviceCode", txtTPortCode.Text.ToString()); // MQTT PortCode
  319. MessageBox.Show("参数保存成功!");
  320. GlobalContext.UpdateData();
  321. //记录修改日志
  322. List<string> mesSetVlaue = new List<string>();
  323. mesSetVlaue.Add(chkIsUseAGV.Checked.ToString());
  324. mesSetVlaue.Add(txtAGVHttpIP.Text.Trim());
  325. mesSetVlaue.Add(txtAGVMQTTIP.Text.Trim());
  326. mesSetVlaue.Add(numAGVMQTTPort.Text.Trim());
  327. mesSetVlaue.Add(txtTPortCode.Text.Trim());
  328. String.Join(";", mesSetVlaue);
  329. OnMessage(LogType.Info, currentRole + "修改系统值[AGV配置]为[" + String.Join(";", mesSetVlaue) + "]");
  330. }
  331. catch (Exception ex)
  332. {
  333. string str = ex.StackTrace;
  334. OnMessage(LogType.Error, "保存AGV配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  335. }
  336. }
  337. /// <summary>
  338. /// 保存设备配置
  339. /// </summary>
  340. private void button3_Click(object sender, EventArgs e)
  341. {
  342. try
  343. {
  344. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC1", rdbS1.Checked.ToString());
  345. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC2", rdbS2.Checked.ToString());
  346. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC3", rdbS3.Checked.ToString());
  347. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC4", rdbS4.Checked.ToString());
  348. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC5", rdbS5.Checked.ToString());
  349. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC6", rdbS6.Checked.ToString());
  350. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC7", rdbS7.Checked.ToString());
  351. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC8", rdbS8.Checked.ToString());
  352. IniFile.INIWriteValue(FilePath, "Machine", "IsUsePLC9", rdbS9.Checked.ToString());
  353. IniFile.INIWriteValue(FilePath, "Machine", "Machine1Address", IPAddress.Parse(txtPLCAddress1.Text.Trim()).ToString());
  354. IniFile.INIWriteValue(FilePath, "Machine", "Machine2Address", IPAddress.Parse(txtPLCAddress2.Text.Trim()).ToString());
  355. IniFile.INIWriteValue(FilePath, "Machine", "Machine3Address", IPAddress.Parse(txtPLCAddress3.Text.Trim()).ToString());
  356. IniFile.INIWriteValue(FilePath, "Machine", "Machine4Address", IPAddress.Parse(txtPLCAddress4.Text.Trim()).ToString());
  357. IniFile.INIWriteValue(FilePath, "Machine", "Machine5Address", IPAddress.Parse(txtPLCAddress5.Text.Trim()).ToString());
  358. IniFile.INIWriteValue(FilePath, "Machine", "Machine6Address", IPAddress.Parse(txtPLCAddress6.Text.Trim()).ToString());
  359. IniFile.INIWriteValue(FilePath, "Machine", "Machine7Address", IPAddress.Parse(txtPLCAddress7.Text.Trim()).ToString());
  360. IniFile.INIWriteValue(FilePath, "Machine", "Machine8Address", IPAddress.Parse(txtPLCAddress8.Text.Trim()).ToString());
  361. IniFile.INIWriteValue(FilePath, "Machine", "Machine9Address", IPAddress.Parse(txtPLCAddress9.Text.Trim()).ToString());
  362. IniFile.INIWriteValue(FilePath, "Machine", "MachinePort",numPLCPort.Value.ToString());
  363. MessageBox.Show("参数保存成功!");
  364. GlobalContext.UpdateData();
  365. //记录修改日志
  366. List<string> machineSetVlaue = new List<string>();
  367. machineSetVlaue.Add(rdbS1.Checked.ToString());
  368. machineSetVlaue.Add(rdbS2.Checked.ToString());
  369. machineSetVlaue.Add(rdbS3.Checked.ToString());
  370. machineSetVlaue.Add(rdbS4.Checked.ToString());
  371. machineSetVlaue.Add(rdbS5.Checked.ToString());
  372. machineSetVlaue.Add(rdbS6.Checked.ToString());
  373. machineSetVlaue.Add(rdbS7.Checked.ToString());
  374. machineSetVlaue.Add(rdbS8.Checked.ToString());
  375. machineSetVlaue.Add(rdbS9.Checked.ToString());
  376. machineSetVlaue.Add(txtPLCAddress1.Text.Trim());
  377. machineSetVlaue.Add(txtPLCAddress2.Text.Trim());
  378. machineSetVlaue.Add(txtPLCAddress3.Text.Trim());
  379. machineSetVlaue.Add(txtPLCAddress4.Text.Trim());
  380. machineSetVlaue.Add(txtPLCAddress5.Text.Trim());
  381. machineSetVlaue.Add(txtPLCAddress6.Text.Trim());
  382. machineSetVlaue.Add(txtPLCAddress7.Text.Trim());
  383. machineSetVlaue.Add(txtPLCAddress8.Text.Trim());
  384. machineSetVlaue.Add(txtPLCAddress9.Text.Trim());
  385. machineSetVlaue.Add(numPLCPort.Value.ToString());
  386. String.Join(";", machineSetVlaue);
  387. OnMessage(LogType.Info, currentRole + "修改系统值[设备配置]为[" + String.Join(";", machineSetVlaue) + "]");
  388. }
  389. catch (Exception ex)
  390. {
  391. string str = ex.StackTrace;
  392. OnMessage(LogType.Error, "保存设备配置出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  393. }
  394. }
  395. /// <summary>
  396. /// 获取订单信息
  397. /// </summary>
  398. private void btnGetOrderInfo_Click(object sender, EventArgs e)
  399. {
  400. }
  401. //private void textBoxWC_KeyPress(object sender, KeyPressEventArgs e)
  402. //{
  403. // if (e.KeyChar == 13)
  404. // {
  405. // WorkOrderInfo workOrderInfo;
  406. // workOrderInfo = HttpUitls.GetWOData(textBoxWC.Text.Trim());
  407. // if (workOrderInfo != null)
  408. // {
  409. // textBoxWC.Text = workOrderInfo.sono;
  410. // textBoxBN.Text = workOrderInfo.splcode;
  411. // comboBoxProductModel.Text = workOrderInfo.prtno;
  412. // comboBoxKeyValue.Text = workOrderInfo.prodline;
  413. // }
  414. // else
  415. // {
  416. // textBoxWC.Text = string.Empty;
  417. // }
  418. // }
  419. //}
  420. /// <summary>
  421. /// 保存信息
  422. /// </summary>
  423. /// <param name="logType"></param>
  424. /// <param name="msg"></param>
  425. private void OnMessage(LogType logType, string msg)
  426. {
  427. MessageEvent?.Invoke(logType, msg);
  428. }
  429. }
  430. }