Form_SystemSet.cs 32 KB

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