版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

81 lines
2.6 KiB

  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 FrmCMDProcess : Form
  17. {
  18. ArrayList cmdList=new ArrayList();
  19. private int currKey;
  20. public FrmCMDProcess()
  21. {
  22. InitializeComponent();
  23. this.uiIOCardDev0.GetParamsEvent = save;
  24. }
  25. private void initData()
  26. {
  27. cmdList = Utils.EnumUtil.GetArrayList<CMDName>();
  28. cobCMDProcess.DisplayMember = "Value";
  29. cobCMDProcess.ValueMember = "Key";
  30. cobCMDProcess.DataSource = cmdList;
  31. cobCMDProcess.SelectedIndex = 0;
  32. }
  33. private void FrmSetParams_Load(object sender, EventArgs e)
  34. {
  35. try
  36. {
  37. uiIOCardDev0.init();
  38. initData();
  39. }
  40. catch (Exception ex)
  41. {
  42. MessageBox.Show(ex.Message, "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
  43. this.Close();
  44. }
  45. }
  46. private void cobCMDProcess_SelectedIndexChanged(object sender, EventArgs e)
  47. {
  48. currKey = (int)cobCMDProcess.SelectedValue;
  49. if (Config.CMDProcess.ContainsKey((CMDName)currKey))
  50. this.uiIOCardDev0.setParamsData(Config.CMDProcess[(CMDName)currKey].ToString());
  51. }
  52. private void save(string json)
  53. {
  54. Config.CMDProcess[(CMDName)currKey] = JObject.Parse(json);
  55. File.WriteAllText(Application.StartupPath + "\\CMDProcess\\" + currKey + ".json", json);
  56. MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  57. }
  58. private void tsbtnClose_Click(object sender, EventArgs e)
  59. {
  60. this.Close();
  61. }
  62. private void FrmCMDProcess_FormClosing(object sender, FormClosingEventArgs e)
  63. {
  64. string lsBasePath = Application.StartupPath + "\\CMDProcess\\";
  65. foreach (DictionaryEntry item in cmdList)
  66. {
  67. if(!File.Exists(lsBasePath+item.Key+".json"))
  68. {
  69. MessageBox.Show($"[{item.Value}] 指令未设置,请先把系统指令集全部设置完成!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
  70. e.Cancel = true;
  71. return;
  72. }
  73. }
  74. }
  75. }
  76. }