Exemplo n.º 1
0
        private void btAddHost_Click(object sender, EventArgs e)
        {
            AddHost addHost = new AddHost();

            addHost.ShowDialog();
            if (addHost.NewHost != null)
            {
                hosts.HostsList.Add(addHost.NewHost);
                GridViewSettings.ViewNotes(MainDataGridView, hosts.HostsList, globalSettings);
                FileWorker.SaveToFile(hosts, "hosts.txt");
            }
        }
Exemplo n.º 2
0
 private void btEditHost_Click(object sender, EventArgs e)
 {
     if (MainDataGridView.SelectedRows.Count > 0)
     {
         int  index          = MainDataGridView.SelectedRows[0].Index;
         Host hostForEditing = new Host(MainDataGridView[0, index].Value.ToString(), MainDataGridView[1, index].Value.ToString());
         foreach (Host anyHost in hosts.HostsList)
         {
             if (anyHost.IP.Equals(hostForEditing.IP) && anyHost.Name.Equals(hostForEditing.Name))
             {
                 hostForEditing = anyHost;
             }
         }
         if (hostForEditing != null)
         {
             // Preparing and showing dialog
             AddHost editHost = new AddHost();
             editHost.tbNewHostAdd.Text  = hostForEditing.IP;
             editHost.tbNewHostName.Text = hostForEditing.Name;
             editHost.btAdd.Text         = "Изменить";
             editHost.ShowDialog();
             // Save changes
             if (editHost.NewHost != null)
             {
                 hostForEditing.IP   = editHost.NewHost.IP;
                 hostForEditing.Name = editHost.NewHost.Name;
                 GridViewSettings.ViewNotes(MainDataGridView, hosts.HostsList, globalSettings);
                 FileWorker.SaveToFile(hosts, "hosts.txt");
             }
         }
     }
     else
     {
         MessageBox.Show("Ни один из хостов не выбран!");
     }
 }