/// <summary> /// 绑定单元列表 /// </summary> void bindChilds() { this.Text = "控制单元 Loading..."; Helper.Remote.Invoke <SunRizServer.ControlUnit[]>("GetUnitList", (ret, err) => { this.Text = "控制单元"; if (err != null) { MessageBox.Show(MainWindow.Instance, err); } else { foreach (var unit in ret) { ControlUnitNode node = new ControlUnitNode(unit); node.ContextMenuItems.Add(new ContextMenuItem() { Text = "重命名", ClickHandler = editUnitClick, Tag = node, }); this.Nodes.Add(node); } } }); }
void addControlUnitClick(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等数字编号形式"); addControlUnitClick(sender, e); return; } var unit = new SunRizServer.ControlUnit(); unit.Name = "UNIT" + frm.Value; MainWindow.Instance.Cursor = Cursors.Hand; //异步调用服务器方法 Helper.Remote.Invoke <int>("UpdateControlUnit", (ret, err) => { MainWindow.Instance.Cursor = null; if (err != null) { MessageBox.Show(MainWindow.Instance, err); } else { unit.id = ret; unit.ChangedProperties.Clear(); this.IsExpanded = true; ControlUnitNode node = new ControlUnitNode(unit); node.ContextMenuItems.Add(new ContextMenuItem() { Text = "重命名", ClickHandler = editUnitClick, Tag = node, }); this.Nodes.Add(node); } }, unit); } }