void SaveNode(Node node, bool isNew)
 {
     SystemMessages sm;
     try
     {
         string result = CommonFunctions.SaveNode(null, node, isNew);
         try
         {
             string nodeID = CommonFunctions.GetNodeByName(null, node.Name).ID;
             if (isNew)
                 CreateRoles(nodeID);
         }
         catch (Exception ex1)
         {
             CommonFunctions.LogException(null, "WPF.CreateRoles", ex1);
             sm = new SystemMessages(new Message() { UserMessage = "Failed to Create Application Roles for Node", SystemMessage = ex1.Message, UserMessageType = MessageType.Error },
                    ButtonType.OkOnly);
             sm.Owner = Window.GetWindow(this);
             sm.ShowPopup();
         }
         sm = new SystemMessages(new Message() { UserMessage = result, SystemMessage = string.Empty, UserMessageType = MessageType.Success },
                 ButtonType.OkOnly);
         sm.Owner = Window.GetWindow(this);
         sm.ShowPopup();
         GetNodes();
         //ClearForm();
         ((MasterLayoutWindow)Window.GetWindow(this)).UserControlSelectNode.RaiseNotification();
     }
     catch (Exception ex)
     {
         CommonFunctions.LogException(null, "WPF.SaveNode", ex);
         sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Node Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error },
                ButtonType.OkOnly);
         sm.Owner = Window.GetWindow(this);
         sm.ShowPopup();
     }
 }
        void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            #if SILVERLIGHT
            Storyboard sb = new Storyboard();
            sb = Application.Current.Resources["ButtonPressAnimation"] as Storyboard;
            sb.Completed += new EventHandler(delegate(object obj, EventArgs es) { sb.Stop(); });
            Storyboard.SetTarget(sb, ButtonSaveTransform);
            sb.Begin();
            #endif
            if (IsValid())
            {
                Node node = new Node();
                node.Name = TextBoxName.Text.CleanText();
                node.CompanyID = ((KeyValuePair<int, string>)ComboBoxCompany.SelectedItem).Key == 0 ? (int?)null : ((KeyValuePair<int, string>)ComboBoxCompany.SelectedItem).Key;
                node.Longitude = TextBoxLongitude.Text.ToNullableDecimal();
                node.Latitude = TextBoxLatitude.Text.ToNullableDecimal();
                node.Description = TextBoxDescription.Text.CleanText();
                node.Image = TextBoxImage.Text.CleanText();
                node.Master = (bool)CheckboxMaster.IsChecked;
                node.LoadOrder = TextBoxLoadOrder.Text.ToInteger();
                node.Enabled = (bool)CheckboxEnabled.IsChecked;
                node.TimeSeriesDataServiceUrl = TextBoxTimeSeriesDataServiceUrl.Text.CleanText();
                node.RemoteStatusServiceUrl = TextBoxRemoteStatusServiceUrl.Text.CleanText();
                node.RealTimeStatisticServiceUrl = TextBoxRealTimeStatisticServiceUrl.Text.CleanText();

                if (m_inEditMode == true && !string.IsNullOrEmpty(m_nodeID))
                {
                    node.ID = m_nodeID;
                    SaveNode(node, false);
                }
                else
                    SaveNode(node, true);
            }
        }