using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Configuration; using System.Text.RegularExpressions; using AGV_WPF_Global; namespace AGV_WPF { /// /// AGVParaSetting.xaml 的交互逻辑 /// public partial class AGVParaSetting : Window { /// /// 构造函数,读取配置文件中的系统参数 /// public AGVParaSetting() { InitializeComponent(); } /// /// 加载窗体,初始化textbox中内容 /// /// /// private void Window_Loaded(object sender, RoutedEventArgs e) { tbAGVnum.Text = ConfigurationManager.AppSettings["AGVNUM_MAX"]; tbMapScale.Text = ConfigurationManager.AppSettings["MapScale"]; //tbTraffic.Text = ConfigurationManager.AppSettings["TRAFFIC_CONAREA_MAX"]; //tbMark.Text = ConfigurationManager.AppSettings["TRAFFIC_CONAREA_MARKNUM_MAX"]; tbWaiting.Text = ConfigurationManager.AppSettings["TRAFFIC_CONAREA_WAITAGVNUM_MAX"]; txtAGVPicW.Text = GlobalPara.AgvIconW.ToString(); txtAGVPicH.Text = GlobalPara.AgvIconH.ToString(); txtAreaName.Text = GlobalPara.areaName; checkBox_SavePic.IsChecked = GlobalPara.IsExceptionSavePic; DAL.ZSql sqlRequirePara = new DAL.ZSql(); //修改日期:2014-1-21 //总共交通管制数量,与生产区无关,无数据时也会有一行数据,数据为0 sqlRequirePara.Open("SELECT COUNT(DISTINCT TrafficNum) AS TrafficCount FROM T_Traffic"); if (sqlRequirePara.rowcount > 0) { tbTraffic.Text = sqlRequirePara.Rows[0]["TrafficCount"].ToString(); } else { tbTraffic.Text = "0"; } //修改日期:2014-1-21 //交通管制中设置了地标数量最大的一个,无数据时也会有一行数据,其中没有任何数据,也不为空 sqlRequirePara.Open("SELECT MAX(TrafficCount) AS MaxTrafficCount FROM (SELECT COUNT(MarkID) AS TrafficCount FROM T_Traffic GROUP BY TrafficNum) AS T_TrafficCount"); if (sqlRequirePara.rowcount > 0) { string oMaxTrafficCount = sqlRequirePara.Rows[0]["MaxTrafficCount"].ToString().Trim(); tbMark.Text = string.IsNullOrEmpty(oMaxTrafficCount) ? "0" : oMaxTrafficCount; } else { tbMark.Text = "0"; } sqlRequirePara.Close(); } #region 确认修改 /// /// 修改配置参数 /// /// /// private void btnModify_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(tbAGVnum.Text.Trim()) || string.IsNullOrEmpty(tbWaiting.Text.Trim()) || string.IsNullOrEmpty(txtAGVPicH.Text) || string.IsNullOrEmpty(txtAGVPicW.Text)) { MessageBox.Show("输入不能为空!"); return; } Regex regex = new Regex(@"^[0-9]*[1-9][0-9]*$");//匹配正整数 if (regex.IsMatch(tbAGVnum.Text.Trim()) && regex.IsMatch(tbWaiting.Text.Trim()) && regex.IsMatch(txtAGVPicW.Text) && regex.IsMatch(txtAGVPicH.Text)) { Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); cfa.AppSettings.Settings["AGVNUM_MAX"].Value = tbAGVnum.Text.Trim(); cfa.AppSettings.Settings["MapScale"].Value = tbMapScale.Text.Trim(); if (!cfa.AppSettings.Settings.AllKeys.Contains(GlobalPara.strAgvIconW)) { cfa.AppSettings.Settings.Add(GlobalPara.strAgvIconW, txtAGVPicW.Text); } if (!cfa.AppSettings.Settings.AllKeys.Contains(GlobalPara.strAgvIconH)) { cfa.AppSettings.Settings.Add(GlobalPara.strAgvIconH, txtAGVPicH.Text); } if (!cfa.AppSettings.Settings.AllKeys.Contains(GlobalPara.strSavePic)) { cfa.AppSettings.Settings.Add(GlobalPara.strSavePic, checkBox_SavePic.IsChecked.ToString()); } if (!cfa.AppSettings.Settings.AllKeys.Contains(GlobalPara.strAreaName)) { cfa.AppSettings.Settings.Add(GlobalPara.strAreaName, txtAreaName.Text); } cfa.AppSettings.Settings[GlobalPara.strAgvIconW].Value = txtAGVPicW.Text; cfa.AppSettings.Settings[GlobalPara.strAgvIconH].Value = txtAGVPicH.Text; cfa.AppSettings.Settings[GlobalPara.strSavePic].Value = checkBox_SavePic.IsChecked.ToString(); cfa.AppSettings.Settings[GlobalPara.strAreaName].Value = txtAreaName.Text; //cfa.AppSettings.Settings["TRAFFIC_CONAREA_MAX"].Value = tbTraffic.Text.Trim(); //cfa.AppSettings.Settings["TRAFFIC_CONAREA_MARKNUM_MAX"].Value = tbMark.Text.Trim(); cfa.AppSettings.Settings["TRAFFIC_CONAREA_WAITAGVNUM_MAX"].Value = tbWaiting.Text.Trim(); cfa.Save(ConfigurationSaveMode.Modified); MessageBox.Show("修改成功!重启软件生效。"); return; } else { MessageBox.Show("请输入正整数字!"); return; } } catch (System.Exception ex) { MessageBox.Show("修改失败!"); return; } } #endregion #region 退出系统 /// /// 退出系统 /// /// /// private void btnExit_Click(object sender, RoutedEventArgs e) { this.Close(); } #endregion } }