PageSystemParameterSet.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using HZY.Framework.DependencyInjection;
  11. using Sunny.UI;
  12. namespace Scada.Page
  13. {
  14. public partial class PageSystemParameterSet : UIPage, ISingletonSelfDependency
  15. {
  16. public PageSystemParameterSet()
  17. {
  18. InitializeComponent();
  19. this.Load += PageSystemParameterSet_Load;
  20. }
  21. protected override CreateParams CreateParams
  22. {
  23. get
  24. {
  25. CreateParams paras = base.CreateParams;
  26. paras.ExStyle |= 0x02000000;
  27. return paras;
  28. }
  29. }
  30. private void PageSystemParameterSet_Load(object sender, EventArgs e)
  31. {
  32. InitSystemParameter();
  33. }
  34. private void InitSystemParameter()
  35. {
  36. this.txt_plcConfig.Text = Globals.PlcVarConfigPath;
  37. this.txt_ConnectTimeOut.Text = Globals.ConnectTimeOut.ToString();
  38. this.txt_ReadTimeInterval.Text = Globals.ReadTimeInterval.ToString();
  39. this.txt_ReConnectTimeInterval.Text = Globals.ReConnectTimeInterval.ToString();
  40. this.txt_IPAddress.Text = Globals.IpAddress;
  41. this.txt_Port.Text = Globals.Port.ToString();
  42. this.cb_CPUType.Text = Globals.CpuType.ToString();
  43. this.txt_Slot.Text = Globals.Slot.ToString();
  44. this.txt_Rack.Text = Globals.Rack.ToString();
  45. this.txt_DirePath.Text = Globals.DelFilePath;
  46. switch (Globals.SaveDay)
  47. {
  48. case "不清理":
  49. this.rbg_Save.SelectedIndex = 0;
  50. break;
  51. case "3天":
  52. this.rbg_Save.SelectedIndex = 1;
  53. break;
  54. case "7天":
  55. this.rbg_Save.SelectedIndex = 2;
  56. break;
  57. case "15天":
  58. this.rbg_Save.SelectedIndex = 3;
  59. break;
  60. case "30天":
  61. this.rbg_Save.SelectedIndex = 4;
  62. break;
  63. case "60天":
  64. this.rbg_Save.SelectedIndex = 5;
  65. break;
  66. }
  67. this.txt_SoftTime.Text = Globals.SYTime.ToString();
  68. this.txt_SoftwareVersion.Text = Globals.SoftwareVersion;
  69. }
  70. private void btn_Save_Click(object sender, EventArgs e)
  71. {
  72. var parameters = new Dictionary<string, string>
  73. {
  74. {"PLC地址",this.txt_IPAddress.Text },
  75. {"PLC端口" ,this.txt_Port.Text},
  76. { "CPU类型", this.cb_CPUType.Text },
  77. { "机架号", this.txt_Rack.Text },
  78. { "插槽号", this.txt_Slot.Text },
  79. { "超时时间",this.txt_ConnectTimeOut.Text },
  80. { "循环读取时间",this.txt_ReadTimeInterval.Text},
  81. { "重连时间",this.txt_ReConnectTimeInterval.Text }
  82. };
  83. foreach (var parameter in parameters)
  84. {
  85. if (!Globals.IniFile.Write("PLC参数", parameter.Key, parameter.Value))
  86. {
  87. UIMessageTip.ShowWarning($"保存{parameter.Key}失败!");
  88. return;
  89. }
  90. }
  91. string delDirePath = this.txt_DirePath.Text;
  92. string saveDay = this.rbg_Save.Items[this.rbg_Save.SelectedIndex].ToString();
  93. if (Directory.Exists(delDirePath))
  94. {
  95. if (!Globals.IniFile.Write("系统参数", "删除文件夹路径", delDirePath))
  96. {
  97. UIMessageTip.ShowWarning("删除文件夹路径失败");
  98. return;
  99. }
  100. }
  101. else
  102. {
  103. UIMessageTip.ShowWarning("删除文件夹不存在");
  104. return;
  105. }
  106. if (!Globals.IniFile.Write("系统参数", "保存文件夹天数", saveDay))
  107. {
  108. UIMessageTip.ShowWarning("保存天数失败");
  109. return;
  110. }
  111. if (!Globals.IniFile.Write("软件参数", "软件版本", this.txt_SoftwareVersion.Text))
  112. {
  113. UIMessageTip.ShowWarning("保存软件版本信息失败!");
  114. return;
  115. }
  116. if (!Globals.IniFile.Write("软件参数", "试用时间", this.txt_SoftTime.Text))
  117. {
  118. UIMessageTip.ShowWarning("保存软件试用时间失败!");
  119. return;
  120. }
  121. UIMessageTip.ShowOk("保存成功!");
  122. }
  123. }
  124. }