FormSysConfig.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Net;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using DevComponents.DotNetBar;
  11. using parkMonitor.LOG;
  12. namespace centralController
  13. {
  14. public partial class FormSysConfig : DevComponents.DotNetBar.OfficeForm
  15. {
  16. public FormSysConfig()
  17. {
  18. InitializeComponent();
  19. tb_garageID.Text = Monitor.Monitor.garageID.ToString();
  20. tb_defaultLic.Text = Monitor.Monitor.defaultLic;
  21. lbx_logAddress.Text = "当前日志路径:"+ LogManager.logAddress;
  22. lbx_advertAddress.Text = "当前广告路径:" +Monitor.Monitor.advertPath;
  23. }
  24. private void cb_nmIP_DropDown(object sender, EventArgs e)
  25. {
  26. Dictionary<string, int>.Enumerator enumer = Monitor.Monitor.numMachineLinker.GetIpIdMap().GetEnumerator();
  27. while (enumer.MoveNext())
  28. {
  29. cb_nmIP.Items.Add(enumer.Current.Key);
  30. }
  31. }
  32. /// <summary>
  33. /// 查询号牌机当前IP
  34. /// </summary>
  35. /// <param name="sender"></param>
  36. /// <param name="e"></param>
  37. private void btnx_nmSearch_Click(object sender, EventArgs e)
  38. {
  39. string selectedIP = (string)cb_nmIP.SelectedItem;
  40. Dictionary<string, int> dictionary = Monitor.Monitor.numMachineLinker.GetIpIdMap();
  41. if (dictionary != null && selectedIP != null)
  42. {
  43. bool result = dictionary.TryGetValue(selectedIP, out int id);
  44. if (result)
  45. tb_nmId.Text = id.ToString();
  46. else
  47. MessageBox.Show("未能找到该IP对应的号牌机ID", "查询失败");
  48. }
  49. else
  50. MessageBox.Show("当前未识别到号牌机", "查询失败");
  51. }
  52. /// <summary>
  53. /// 修改号牌机对应IP
  54. /// </summary>
  55. /// <param name="sender"></param>
  56. /// <param name="e"></param>
  57. private void btnx_nmIdAlter_Click(object sender, EventArgs e)
  58. {
  59. string selectedIP = (string)cb_nmIP.SelectedItem;
  60. if (selectedIP == null)
  61. {
  62. MessageBox.Show("未选择IP", "修改失败");
  63. return;
  64. }
  65. else
  66. {
  67. if (int.TryParse(tb_nmId.Text, out int id))
  68. {
  69. ConfigurationManager.AppSettings.Set(selectedIP, tb_nmId.Text);
  70. ConfModify(selectedIP, tb_nmId.Text);
  71. MessageBox.Show("修改ip " + selectedIP + "对应id为" + tb_nmId.Text + "\n编号将在重启后生效", "修改成功");
  72. }
  73. else
  74. {
  75. MessageBox.Show("识别到id并非整型数字", "修改失败");
  76. }
  77. }
  78. }
  79. /// <summary>
  80. /// 修改号牌筛选比例
  81. /// </summary>
  82. /// <param name="sender"></param>
  83. /// <param name="e"></param>
  84. private void btnx_nmRatioConfirm_Click(object sender, EventArgs e)
  85. {
  86. int ratio = sld_nmfilterRatio.Value / 10 * 10;
  87. Monitor.Monitor.numMachineLinker.SetRatio((ratio / 100.0));
  88. ConfModify("filterRatio", (ratio / 100.0).ToString());
  89. MessageBox.Show("号牌筛选比例已修改为" + (ratio / 100.0).ToString(), "修改成功");
  90. }
  91. /// <summary>
  92. /// 保存配置文件修改
  93. /// </summary>
  94. /// <param name="key"></param>
  95. /// <param name="value"></param>
  96. private void ConfModify(string key, string value)
  97. {
  98. Configuration conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  99. if (conf.AppSettings.Settings[key] != null)
  100. conf.AppSettings.Settings[key].Value = value;
  101. //else
  102. // conf.AppSettings.Settings.Add(key, value);
  103. conf.Save(ConfigurationSaveMode.Modified);
  104. }
  105. /// <summary>
  106. /// 实时显示slider值
  107. /// </summary>
  108. /// <param name="sender"></param>
  109. /// <param name="e"></param>
  110. private void sld_nmfilterRatio_ValueChanged(object sender, EventArgs e)
  111. {
  112. sld_nmfilterRatio.Text = "号牌筛选比例:" +(sld_nmfilterRatio.Value/10*10)/100.0;
  113. }
  114. }
  115. }