AGVParaSetting.xaml.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Shapes;
  13. using System.Configuration;
  14. using System.Text.RegularExpressions;
  15. using AGV_WPF_Global;
  16. namespace AGV_WPF
  17. {
  18. /// <summary>
  19. /// AGVParaSetting.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class AGVParaSetting : Window
  22. {
  23. /// <summary>
  24. /// 构造函数,读取配置文件中的系统参数
  25. /// </summary>
  26. public AGVParaSetting()
  27. {
  28. InitializeComponent();
  29. }
  30. /// <summary>
  31. /// 加载窗体,初始化textbox中内容
  32. /// </summary>
  33. /// <param name="sender"></param>
  34. /// <param name="e"></param>
  35. private void Window_Loaded(object sender, RoutedEventArgs e)
  36. {
  37. tbAGVnum.Text = ConfigurationManager.AppSettings["AGVNUM_MAX"];
  38. tbMapScale.Text = ConfigurationManager.AppSettings["MapScale"];
  39. //tbTraffic.Text = ConfigurationManager.AppSettings["TRAFFIC_CONAREA_MAX"];
  40. //tbMark.Text = ConfigurationManager.AppSettings["TRAFFIC_CONAREA_MARKNUM_MAX"];
  41. tbWaiting.Text = ConfigurationManager.AppSettings["TRAFFIC_CONAREA_WAITAGVNUM_MAX"];
  42. txtAGVPicW.Text = GlobalPara.AgvIconW.ToString();
  43. txtAGVPicH.Text = GlobalPara.AgvIconH.ToString();
  44. txtAreaName.Text = GlobalPara.areaName;
  45. checkBox_SavePic.IsChecked = GlobalPara.IsExceptionSavePic;
  46. DAL.ZSql sqlRequirePara = new DAL.ZSql();
  47. //修改日期:2014-1-21
  48. //总共交通管制数量,与生产区无关,无数据时也会有一行数据,数据为0
  49. sqlRequirePara.Open("SELECT COUNT(DISTINCT TrafficNum) AS TrafficCount FROM T_Traffic");
  50. if (sqlRequirePara.rowcount > 0)
  51. {
  52. tbTraffic.Text = sqlRequirePara.Rows[0]["TrafficCount"].ToString();
  53. }
  54. else
  55. {
  56. tbTraffic.Text = "0";
  57. }
  58. //修改日期:2014-1-21
  59. //交通管制中设置了地标数量最大的一个,无数据时也会有一行数据,其中没有任何数据,也不为空
  60. sqlRequirePara.Open("SELECT MAX(TrafficCount) AS MaxTrafficCount FROM (SELECT COUNT(MarkID) AS TrafficCount FROM T_Traffic GROUP BY TrafficNum) AS T_TrafficCount");
  61. if (sqlRequirePara.rowcount > 0)
  62. {
  63. string oMaxTrafficCount = sqlRequirePara.Rows[0]["MaxTrafficCount"].ToString().Trim();
  64. tbMark.Text = string.IsNullOrEmpty(oMaxTrafficCount) ? "0" : oMaxTrafficCount;
  65. }
  66. else
  67. {
  68. tbMark.Text = "0";
  69. }
  70. sqlRequirePara.Close();
  71. }
  72. #region 确认修改
  73. /// <summary>
  74. /// 修改配置参数
  75. /// </summary>
  76. /// <param name="sender"></param>
  77. /// <param name="e"></param>
  78. private void btnModify_Click(object sender, RoutedEventArgs e)
  79. {
  80. try
  81. {
  82. if (string.IsNullOrEmpty(tbAGVnum.Text.Trim()) || string.IsNullOrEmpty(tbWaiting.Text.Trim()) || string.IsNullOrEmpty(txtAGVPicH.Text) || string.IsNullOrEmpty(txtAGVPicW.Text))
  83. {
  84. MessageBox.Show("输入不能为空!");
  85. return;
  86. }
  87. Regex regex = new Regex(@"^[0-9]*[1-9][0-9]*$");//匹配正整数
  88. if (regex.IsMatch(tbAGVnum.Text.Trim()) && regex.IsMatch(tbWaiting.Text.Trim()) && regex.IsMatch(txtAGVPicW.Text) && regex.IsMatch(txtAGVPicH.Text))
  89. {
  90. Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  91. cfa.AppSettings.Settings["AGVNUM_MAX"].Value = tbAGVnum.Text.Trim();
  92. cfa.AppSettings.Settings["MapScale"].Value = tbMapScale.Text.Trim();
  93. if (!cfa.AppSettings.Settings.AllKeys.Contains(GlobalPara.strAgvIconW))
  94. {
  95. cfa.AppSettings.Settings.Add(GlobalPara.strAgvIconW, txtAGVPicW.Text);
  96. }
  97. if (!cfa.AppSettings.Settings.AllKeys.Contains(GlobalPara.strAgvIconH))
  98. {
  99. cfa.AppSettings.Settings.Add(GlobalPara.strAgvIconH, txtAGVPicH.Text);
  100. }
  101. if (!cfa.AppSettings.Settings.AllKeys.Contains(GlobalPara.strSavePic))
  102. {
  103. cfa.AppSettings.Settings.Add(GlobalPara.strSavePic, checkBox_SavePic.IsChecked.ToString());
  104. }
  105. if (!cfa.AppSettings.Settings.AllKeys.Contains(GlobalPara.strAreaName))
  106. {
  107. cfa.AppSettings.Settings.Add(GlobalPara.strAreaName, txtAreaName.Text);
  108. }
  109. cfa.AppSettings.Settings[GlobalPara.strAgvIconW].Value = txtAGVPicW.Text;
  110. cfa.AppSettings.Settings[GlobalPara.strAgvIconH].Value = txtAGVPicH.Text;
  111. cfa.AppSettings.Settings[GlobalPara.strSavePic].Value = checkBox_SavePic.IsChecked.ToString();
  112. cfa.AppSettings.Settings[GlobalPara.strAreaName].Value = txtAreaName.Text;
  113. //cfa.AppSettings.Settings["TRAFFIC_CONAREA_MAX"].Value = tbTraffic.Text.Trim();
  114. //cfa.AppSettings.Settings["TRAFFIC_CONAREA_MARKNUM_MAX"].Value = tbMark.Text.Trim();
  115. cfa.AppSettings.Settings["TRAFFIC_CONAREA_WAITAGVNUM_MAX"].Value = tbWaiting.Text.Trim();
  116. cfa.Save(ConfigurationSaveMode.Modified);
  117. MessageBox.Show("修改成功!重启软件生效。");
  118. return;
  119. }
  120. else
  121. {
  122. MessageBox.Show("请输入正整数字!");
  123. return;
  124. }
  125. }
  126. catch (System.Exception ex)
  127. {
  128. MessageBox.Show("修改失败!");
  129. return;
  130. }
  131. }
  132. #endregion
  133. #region 退出系统
  134. /// <summary>
  135. /// 退出系统
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. private void btnExit_Click(object sender, RoutedEventArgs e)
  140. {
  141. this.Close();
  142. }
  143. #endregion
  144. }
  145. }