Пример #1
0
 //ListViewItem DoubleClick Edit Menu
 private void borderListViewItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     if (e.ClickCount == 2)
     {
         classHost  host   = lvHosts.SelectedItem as classHost;
         windowHost whEdit = new windowHost(this, host);
         whEdit.ShowDialog();
         if (whEdit.DialogResult == true)
         {
             host.IP          = whEdit.IP_address.Text;
             host.DNS_Name    = whEdit.DNS_Name.Text;
             host.Description = whEdit.Description.Text;
             IsChanged        = true;
         }
     }
 }
Пример #2
0
        //MenuItem Events
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var mi = sender as MenuItem;

            if (mi.Name == "AddContainer")
            {
                windowContainer wc = new windowContainer(this);
                wc.ShowDialog();
                if (wc.DialogResult == true)
                {
                    classContainer container = new classContainer(wc.Name.Text, true);
                    Containers.Add(container);
                    IsChanged = true;

                    TreeViewItem tvi = FindTreeViewItemFromObject(tvContainers.ItemContainerGenerator, container);
                    tvi.IsSelected = true;
                }
            }
            else if (mi.Name == "AddSubContainer")
            {
                windowContainer wc = new windowContainer(this);
                wc.ShowDialog();
                if (wc.DialogResult == true)
                {
                    classContainer container    = tvContainers.SelectedItem as classContainer;
                    classContainer subcontainer = new classContainer(wc.Name.Text, true);
                    container.Children.Add(subcontainer);
                    container.IsExpanded = true;
                    IsChanged            = true;

                    TreeViewItem tvi = FindTreeViewItemFromObject(tvContainers.ItemContainerGenerator, subcontainer);
                    tvi.IsSelected = true;
                }
            }
            else if (mi.Name == "EditContainer")
            {
                classContainer  container = tvContainers.SelectedItem as classContainer;
                windowContainer wcEdit    = new windowContainer(this, container);
                wcEdit.ShowDialog();
                if (wcEdit.DialogResult == true)
                {
                    container.Name = wcEdit.Name.Text;
                    IsChanged      = true;
                }
            }
            else if (mi.Name == "RemoveContainer")
            {
                DeleteContainer(tvContainers.SelectedItem as classContainer);
            }
            else if (mi.Name == "CreateHost")
            {
                if (tvContainers.SelectedItem != null)
                {
                    windowHost wh = new windowHost(this);
                    wh.ShowDialog();
                    if (wh.DialogResult == true)
                    {
                        classHost      host      = new classHost(wh.IP_address.Text, wh.DNS_Name.Text, wh.Description.Text);
                        classContainer container = (classContainer)tvContainers.SelectedItem;
                        container.Hosts.Add(host);
                        IsChanged = true;
                    }
                }
            }
            else if (mi.Name == "EditHost")
            {
                classHost  host   = lvHosts.SelectedItem as classHost;
                windowHost whEdit = new windowHost(this, host);
                whEdit.ShowDialog();
                if (whEdit.DialogResult == true)
                {
                    host.IP          = whEdit.IP_address.Text;
                    host.DNS_Name    = whEdit.DNS_Name.Text;
                    host.Description = whEdit.Description.Text;
                    IsChanged        = true;
                }
            }
            else if (mi.Name == "RemoveHost")
            {
                if (lvHosts.SelectedItems.Count == 1)
                {
                    DeleteHosts(lvHosts.SelectedItem as classHost);
                }
                else if (lvHosts.SelectedItems.Count > 1)
                {
                    List <classHost> hosts = new List <classHost>();
                    foreach (classHost item in lvHosts.SelectedItems)
                    {
                        hosts.Add(item);
                    }
                    DeleteHosts(null, hosts);
                }
            }
        }