/// <summary> /// TreeView显示内容 /// </summary> private void InitTrees() { tvCoor.Items.Clear(); List <ES.Domain.Coordinator> coor = CoordinatorApp.GetList(); foreach (ES.Domain.Coordinator gtParent in coor) { TreeViewItem tvCoorParent = new TreeViewItem() { Header = gtParent.Name, Tag = gtParent }; tvCoor.Items.Add(tvCoorParent); //设置父节点 List <Sensor> childType = SensorApp.GetCoorList(gtParent); foreach (Sensor gtChild in childType) { TreeViewItem tvCoorChild = new TreeViewItem() { Header = gtChild.Name, Tag = gtChild }; tvCoorParent.Items.Add(tvCoorChild); //设置子节点 } } }
/// <summary> /// 确认新增/编辑协调器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnOk_OnClick(object sender, RoutedEventArgs e) { if (GetControl()) { OperationResult result; if (_isInsert) { result = CoordinatorApp.Insert(_coordinator); message.Time = DateTime.Now; message.Messages = "新增协调器:" + _coordinator.Name + " 串口号:" + _coordinator.COM + " PanID:" + _coordinator.PanID; } else { result = CoordinatorApp.Update(_coordinator); message.Time = DateTime.Now; message.Messages = "更改协调器:" + _coordinator.Name + " 串口号:" + _coordinator.COM + " PanID:" + _coordinator.PanID; } if (result.ResultType != OperationResultType.Success) { MessageBox.Show(result.Message); return; } else { MessageApp.Insert(message); } DialogResult = true; } }
/// <summary> /// 删除协调器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnDeleteCoor_OnClick(object sender, RoutedEventArgs e) { if (lstCoor.SelectedItem != null) { if (MessageBox.Show("是否删除该项", "询问", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { OperationResult result = null; if (GetListboxSelected() != null) { _coordinator = GetListboxSelected(); result = CoordinatorApp.Delete(_coordinator); Message message = new Message(); message.Time = DateTime.Now; message.Messages = "删除协调器:" + _coordinator.Name + " 串口号:" + _coordinator.COM + " PanID:" + _coordinator.PanID; if (result.ResultType != OperationResultType.Success) { MessageBox.Show(result.Message); } else { MessageApp.Insert(message); SetListCoor(); } } else { MessageBox.Show("请选择要删除的协调器!"); } } } }
public UserControlinterface() { InitializeComponent(); cboRelay.ItemsSource = SensorApp.GetRelayList(); cboRelay.SelectedIndex = 0; cboCoor.ItemsSource = CoordinatorApp.GetList().OrderByDescending(p => p.ID); cboCoor.SelectedIndex = 0; }
/// <summary> /// 设置协调器列表 /// </summary> private void SetListCoor() { lstCoor.Items.Clear(); foreach (ES.Domain.Coordinator coor in CoordinatorApp.GetList()) { Label lbl = new Label(); lbl.Content = coor.Name; lbl.Tag = coor; lstCoor.Items.Add(lbl); } this.lstCoor.SelectedIndex = 0; lblSensorCount.Content = "传感器数量:" + lvSensorList.Items.Count; }