void loadPoints(SunRizServer.Device device) { //异步加载设备点 Helper.Remote.Invoke <DevicePoint[]>("GetDevicePoints", (ret, err) => { if (err != null) { MessageBox.Show(MainWindow.Instance, err); } else { //加载子节点 foreach (var point in ret) { var newNode = new DevicePointNode(point); this.Nodes.Add(newNode); } } }, device.id, FolderType, this.FolderModel.id); }
void addDeviceClick(object sender, RoutedEventArgs e) { Dialogs.InputBox frm = new Dialogs.InputBox("请输入控制器编号,如01、02等数字编号形式", "添加控制器"); frm.Owner = MainWindow.Instance; if (frm.ShowDialog() == true && !string.IsNullOrEmpty(frm.Value)) { var match = System.Text.RegularExpressions.Regex.Match(frm.Value, @"[0-9]+"); if (match.Value != frm.Value) { MessageBox.Show(MainWindow.Instance, "必须是01、02等数字编号形式"); addDeviceClick(sender, e); return; } var device = new SunRizServer.Device(); device.Name = "DROP" + frm.Value; device.UnitId = this.Data.id; Helper.Remote.Invoke <int>("UpdateDevice", (ret, err) => { if (err != null) { MessageBox.Show(MainWindow.Instance, err); } else { device.id = ret; device.ChangedProperties.Clear(); this.IsExpanded = true; var node = new DeviceNode(device); node.ContextMenuItems.Add(new ContextMenuItem() { Text = "重命名", ClickHandler = editDeviceClick, Tag = node, }); this.Nodes.Add(node); } }, device); } }
/// <summary> /// 异步加载子节点 /// </summary> protected override void LoadChildrenAsync() { base.LoadChildrenAsync(); //获取Device对象 SunRizServer.Device device = this.GetDevice(); Helper.Remote.Invoke <DevicePointFolder[]>("GetDevicePointFolders", (ret, err) => { if (err != null) { MessageBox.Show(MainWindow.Instance, err); } else { this.Nodes.Clear(); //加载子节点 foreach (var folder in ret) { AnalogNode newNode = null; if (FolderType == DevicePointFolder_TypeEnum.Analog) { newNode = new AnalogNode(folder); } else { newNode = new DigitalNode(folder); } newNode.Text = folder.Name; this.Nodes.Add(newNode); } //加载点 loadPoints(device); } }, device.id, FolderType, this.FolderModel.id); }