版博士V2.0程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FrmGButtonSetting - 复制.cs 4.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Newtonsoft.Json.Linq;
  2. using ProductionControl.Utils;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace ProductionControl
  15. {
  16. public partial class FrmGButtonSetting : Form
  17. {
  18. JObject joJson=new JObject();
  19. public FrmGButtonSetting()
  20. {
  21. InitializeComponent();
  22. ArrayList list = new ArrayList();
  23. list.Add(new DictionaryEntry("start", "启动按钮"));
  24. list.Add(new DictionaryEntry("pause", "暂停按钮"));
  25. list.Add(new DictionaryEntry("reset", "复位按钮"));
  26. list.Add(new DictionaryEntry("warning", "告警事件"));
  27. list.Add(new DictionaryEntry("iodefault", "I/O默认输出状态"));
  28. cobBreakButton.DisplayMember = "Value";
  29. cobBreakButton.ValueMember = "Key";
  30. cobBreakButton.DataSource = list;
  31. cobBreakButton.SelectedIndex = 0;
  32. }
  33. private void initData()
  34. {
  35. string configPath = Application.StartupPath + "\\GButtonConfig.json";
  36. string lsTmp = File.ReadAllText(configPath);
  37. if (string.IsNullOrEmpty(lsTmp))
  38. lsTmp = "{}";
  39. joJson = JObject.Parse(lsTmp);
  40. }
  41. private void FrmSetParams_Load(object sender, EventArgs e)
  42. {
  43. try
  44. {
  45. uiIOCardDev0.init();
  46. initData();
  47. cobBreakButton_SelectedIndexChanged(null, null);
  48. }
  49. catch (Exception ex)
  50. {
  51. MessageBox.Show(ex.Message, "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
  52. this.Close();
  53. }
  54. }
  55. private void tsbtnSave_Click(object sender, EventArgs e)
  56. {
  57. try
  58. {
  59. string key = cobBreakButton.SelectedValue.ToString();
  60. var value = JObject.Parse(this.uiIOCardDev0.getParamsData());
  61. if (joJson.ContainsKey(key))
  62. joJson[key] = value;
  63. else
  64. joJson.Add(key, value);
  65. if (!joJson.ContainsKey("start")) throw new Exception("请设置启动按钮对应I/O指令!");
  66. if (!joJson.ContainsKey("pause")) throw new Exception("请设置暂停按钮对应I/O指令!");
  67. if (!joJson.ContainsKey("reset")) throw new Exception("请设置复位按钮对应I/O指令!");
  68. if (!joJson.ContainsKey("warning")) throw new Exception("请设置复位按钮对应I/O指令!");
  69. if (!joJson.ContainsKey("iodefault")) throw new Exception("请设置I/O默认输出状态!");
  70. string configPath = Application.StartupPath + "\\GButtonConfig.json";
  71. File.WriteAllText(configPath,joJson.ToString());
  72. //
  73. this.Hide();
  74. MessageBox.Show("保存成功,生效需重启程序!");
  75. this.Close();
  76. }
  77. catch (Exception ex)
  78. {
  79. MessageBox.Show(ex.Message, "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
  80. }
  81. }
  82. private void tsbtnClose_Click(object sender, EventArgs e)
  83. {
  84. this.Close();
  85. }
  86. private string curBreakKey = "";
  87. private void cobBreakButton_SelectedIndexChanged(object sender, EventArgs e)
  88. {
  89. var value = JObject.Parse(this.uiIOCardDev0.getParamsData());
  90. if (curBreakKey != "")
  91. {
  92. if (joJson.ContainsKey(curBreakKey))
  93. joJson[curBreakKey] = value;
  94. else
  95. joJson.Add(curBreakKey, value);
  96. }
  97. //
  98. string key = cobBreakButton.SelectedValue.ToString();
  99. //string key = ((System.Collections.DictionaryEntry)cobBreakButton.SelectedValue).Key.ToString();
  100. if (joJson.ContainsKey(key))
  101. this.uiIOCardDev0.setParamsData(joJson[key].ToString());
  102. curBreakKey = key;
  103. }
  104. }
  105. }