private void mnuAddGroup_Click(object sender, RoutedEventArgs e) { try { var dlg = new dlgInputDialog("Please input Group name:", ""); if (dlg.ShowDialog() == false) { return; } if (dlg.Answer == "") { throw new Exception("Please input Group name"); } var node = treeGroup.SelectedItem as TreeViewItem; var group = new GroupRequestModel(); group.RequestType = RequestType.AddGroup; group.GroupName = dlg.Answer; if ((NodeType)node.Tag == NodeType.Server) { group.ServerName = node.Header.ToString(); } else { var parent = node.Parent as TreeViewItem; group.ServerName = parent.Header.ToString(); } _opcService.AddGroup(group); } catch (Exception ex) { MessageBox.Show(ex.Message, "Info", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void mnuSetValue_Click(object sender, RoutedEventArgs e) { try { var info = lvTag.SelectedItem as ListTagModel; if (info == null) { throw new Exception("Please, choose an item"); } var inputDialog = new dlgInputDialog("Please, input new value:", ""); if (inputDialog.ShowDialog() == true) { var value = inputDialog.Answer; int k; if (!int.TryParse(value, out k)) { throw new Exception("Please, input a number"); } var success = _opcService.WriteTag(info.Server.Name, info.Group.Name, info.Name, value); if (!success) { MessageBox.Show("Can not write"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Info", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void mnuAddTag_Click(object sender, RoutedEventArgs e) { try { var node = treeGroup.SelectedItem as TreeViewItem; //node group if (node == null || (NodeType)node.Tag != NodeType.Group) { throw new Exception("Please, select a group"); } var dlg = new dlgInputDialog("Please input Tag name:", ""); if (dlg.ShowDialog() == true) { var tagName = dlg.Answer; if (tagName == "") { throw new Exception("Please input Tag name"); } var nParent = node.Parent as TreeViewItem; var info = new TagInfoModel() { Server = new ServerModel() { Name = nParent.Header.ToString() }, Group = new GroupModel() { Name = node.Header.ToString() }, Tag = new TagModel() { Name = tagName } }; var success = _opcService.AddTag(info); if (!success) { MessageBox.Show("Can not write"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Info", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void mnuAddServer_Click(object sender, RoutedEventArgs e) { try { var dlg = new dlgInputDialog("Please input Server name:", ""); if (dlg.ShowDialog() == false) { return; } if (dlg.Answer == "") { throw new Exception("Please input Server name"); } var server = new ServerRequestModel() { RequestType = RequestType.AddServer, ServerName = dlg.Answer }; _opcService.AddServer(server); } catch (Exception ex) { MessageBox.Show(ex.Message, "Info", MessageBoxButton.OK, MessageBoxImage.Warning); } }