private void AddExistingControlSystemComponentProperty(NodeView nodeView)
        {
            int? groupId = null;
            var controlSystemEquipmentComponentTypeId = -1;

            if (nodeView.Type == NodeType.ComponentTypeGroup)
            {
                groupId = nodeView.GroupId;
                controlSystemEquipmentComponentTypeId = nodeView.Parent.Parent.Id;
            }
            else
            {
                controlSystemEquipmentComponentTypeId = nodeView.Parent.Id;
            }

            var cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetControlSystemComponentTypeCompleted +=
                (s, e) =>
                {
                    var dialog = new AddEditExistingControlSystemComponentPropertyDialog(e.Result, groupId);
                    dialog.Show();

                    dialog.Closed += (s1, e1) =>
                    {
                        if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                        {
                            EventHandler<AddUpdateControlSystemComponentTypePropertyCompletedEventArgs> addCompleted = null;
                            addCompleted = (s2, eventArgs) =>
                            {
                                var pcpt = eventArgs.Result;

                                if (pcpt != null)
                                {
                                    var child = new NodeView(nodeView)
                                    {
                                        Id = pcpt.Id,
                                        Name = dialog.ControlSystemComponentTypeProperty.ControlSystemProperty.Name,
                                        Description = dialog.ControlSystemComponentTypeProperty.ControlSystemProperty.Description,
                                        Icon = "/CmsEquipmentDatabase;component/Images/Configuration.png",
                                        Type = NodeType.ControlSystemComponentTypeEngineeringProperty,
                                        HasChildren = false,
                                        SortField = groupId.HasValue ? pcpt.GroupOrdinal.ToString() : pcpt.Ordinal.ToString()
                                    };
                                    nodeView.Children.Add(child);
                                    nodeView.Sort(true);
                                }

                                cmsWebServiceClient.AddUpdateControlSystemComponentTypePropertyCompleted -= addCompleted;
                            };
                            cmsWebServiceClient.AddUpdateControlSystemComponentTypePropertyCompleted += addCompleted;

                            var controlSystemEquipmentComponentTypeProperty = new ControlSystemComponentTypeProperty
                            {
                                ControlSystemComponentTypeId = controlSystemEquipmentComponentTypeId,
                                ControlSystemPropertyId = dialog.ControlSystemComponentTypeProperty.ControlSystemPropertyId,
                                ComponentTypeGroupId = dialog.ControlSystemComponentTypeProperty.ComponentTypeGroupId,
                                Ordinal = dialog.ControlSystemComponentTypeProperty.Ordinal,
                                GroupOrdinal = dialog.ControlSystemComponentTypeProperty.GroupOrdinal
                            };

                            if (dialog.GroupChanged)
                            {
                                //Group has changed, reload the Nodes
                                ReloadComponentTypeEquipmentProperties(CommonUtils.EquipmentPropertyType.ControlEngineeringProperty, nodeView, NodeType.ControlSystemComponentTypeEngineeringProperties);
                            }

                            cmsWebServiceClient.AddUpdateControlSystemComponentTypePropertyAsync(controlSystemEquipmentComponentTypeProperty);
                        }
                    };
                };
            cmsWebServiceClient.GetControlSystemComponentTypeAsync(controlSystemEquipmentComponentTypeId);
        }
        private void EditControlSystemComponentTypeProperty(NodeView nodeView)
        {
            var dialog = new AddEditExistingControlSystemComponentPropertyDialog(nodeView.Id);
            dialog.Title = "Edit ControlSystem Component Property";

            dialog.Closed +=
                (s1, e1) =>
                {
                    if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                    {
                        var cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
                        EventHandler<AddUpdateControlSystemComponentTypePropertyCompletedEventArgs> addCompleted = null;
                        addCompleted = (s2, eventArgs) =>
                        {
                            var pcpt = eventArgs.Result;
                            if (pcpt != null)
                            {
                                nodeView.Name = dialog.ControlSystemComponentTypeProperty.ControlSystemProperty.Name;
                                nodeView.Description = dialog.ControlSystemComponentTypeProperty.ControlSystemProperty.Description;
                                nodeView.SortField = dialog.ControlSystemComponentTypeProperty.ComponentTypeGroupId.HasValue
                                    ? dialog.ControlSystemComponentTypeProperty.GroupOrdinal.ToString()
                                    : dialog.ControlSystemComponentTypeProperty.Ordinal.ToString();
                            }
                            cmsWebServiceClient.AddUpdateControlSystemComponentTypePropertyCompleted -= addCompleted;
                            nodeView.Parent.Sort();
                        };
                        cmsWebServiceClient.AddUpdateControlSystemComponentTypePropertyCompleted += addCompleted;

                        var controlSystemEquipmentComponentTypeProperty = new ControlSystemComponentTypeProperty
                        {
                            Id = dialog.ControlSystemComponentTypeProperty.Id,
                            ControlSystemComponentTypeId = dialog.ControlSystemComponentTypeProperty.ControlSystemComponentTypeId,
                            ControlSystemPropertyId = dialog.ControlSystemComponentTypeProperty.ControlSystemPropertyId,
                            Ordinal = dialog.ControlSystemComponentTypeProperty.Ordinal,
                            ComponentTypeGroupId = dialog.ControlSystemComponentTypeProperty.ComponentTypeGroupId,
                            GroupOrdinal = dialog.ControlSystemComponentTypeProperty.GroupOrdinal
                        };
                        cmsWebServiceClient.AddUpdateControlSystemComponentTypePropertyAsync(controlSystemEquipmentComponentTypeProperty);

                        var controlSystemComponentTypeEngineeringPropertiesNode = nodeView.Parent;
                        if (controlSystemComponentTypeEngineeringPropertiesNode.Type != NodeType.ControlSystemComponentTypeEngineeringProperties)
                        {
                            controlSystemComponentTypeEngineeringPropertiesNode = controlSystemComponentTypeEngineeringPropertiesNode.Parent;
                        }

                        if (dialog.GroupChanged)
                        {
                            //Group has changed, reload the Nodes
                            ReloadComponentTypeEquipmentProperties(CommonUtils.EquipmentPropertyType.ControlEngineeringProperty,
                                controlSystemComponentTypeEngineeringPropertiesNode, NodeType.ControlSystemComponentTypeEngineeringProperties);
                        }
                    }
                };
            dialog.Show();
        }