Exemplo n.º 1
0
        private void DeleteClient(ExCommandParameter param)
        {
            var sender = param.Sender as Button;
            int id     = int.Parse(sender.Tag.ToString());

            //删除
            if (ModernDialog.ShowMessage("确实要删除该上位机吗?", "提示", System.Windows.MessageBoxButton.YesNo) == System.Windows.MessageBoxResult.Yes)
            {
                UDPHost.DeleteClient(id);
                this.Clients.Remove(this.Clients.Single(c => c.Id == id));
            }
        }
Exemplo n.º 2
0
        private void RowEditEnding(ExCommandParameter param)
        {
            if (this.CurrentUDPClient == null)
            {
                return;
            }
            var sender = param.Sender as DataGrid;
            var args   = param.EventArgs as DataGridRowEditEndingEventArgs;
            int id     = int.Parse((sender.Columns[0].GetCellContent(args.Row) as TextBlock).Text);
            var client = this.Clients.SingleOrDefault(c => c.Id == id);

            //保存
            UDPHost.UpdateClient(client);
        }
Exemplo n.º 3
0
        private void AddNewClient()
        {
            int id = 0;

            if (this.Clients.Count > 0)
            {
                id = this.Clients.Max(c => c.Id);
            }
            UDPHost client = new UDPHost()
            {
                Id   = id + 1,
                IP   = "0.0.0.0",
                Port = 3333
            };

            this.Clients.Add(client);
            //保存到配置文件
            UDPHost.AddClient(client);
        }
Exemplo n.º 4
0
        public AlarmContentViewModel()
        {
            //填充端口号
            InitPortNames();
            //填充波特率
            InitBaudRates();
            //填充数据位
            InitDataBits();
            //填充校验位
            InitParity();
            //填充停止位
            InitStopBits();

            //读取配置文件
            //串口
            SerialComm comm = new SerialComm();

            this.PortName = PortList.SingleOrDefault(p => p.Value.ToString() == comm.PortName);
            this.BaudRate = BaudRateList.SingleOrDefault(b => (int)b.Value == comm.BaudRate);
            this.Parity   = ParityList.SingleOrDefault(p => (Parity)p.Value == comm.Parity);
            this.DataBits = DataBitList.SingleOrDefault(d => (int)d.Value == comm.DataBits);
            this.StopBits = StopBitList.SingleOrDefault(s => (StopBits)s.Value == comm.StopBits);
            //CopyImagePath
            XDocument doc  = XDocument.Load("Application.config");
            var       path = doc.Descendants("copyImagePath").Single();

            this.CopyImagePath = path.Attribute("path").Value;
            //UDP
            this.UDPServer = UDPServer.GetServerFromConfig();
            //Clients
            this.Clients = UDPHost.GetClients();
            this.ChangeSerialPortParamsCommand = new DelegateCommand <ExCommandParameter>(ChangeSerialPortsParam);
            this.ChangeUDPServerParamsCommand  = new DelegateCommand <ExCommandParameter>(ChangeUDPServerParams);
            this.BeginningEditCommand          = new DelegateCommand <ExCommandParameter>(BeginningEdit);
            this.RowEditEndingCommand          = new DelegateCommand <ExCommandParameter>(RowEditEnding);
            this.DeleteClientCommand           = new DelegateCommand <ExCommandParameter>(DeleteClient);
            this.AddNewClientCommand           = new DelegateCommand(AddNewClient);
            this.BrowseDirCommand           = new DelegateCommand(BrowseDir);
            this.ChangeCopyImagePathCommand = new DelegateCommand <ExCommandParameter>(ChangeCopyImagePath);
        }
Exemplo n.º 5
0
 void Start()
 {
     host = new UDPHost(ip, port);
 }