/// <summary> /// Creates a new dialog using the associated data manager. /// </summary> /// <param name="dataManager">Data manager associated with the hosts file</param> /// <param name="rowIndex">The row index where the host entry is from</param> /// <param name="hostRow">The host row data relative to the row index</param> public EditHostWindow(DataManager dataManager, int rowIndex, HostRow hostRow) { InitializeComponent(); this.dataManager = dataManager; this.hostRow = hostRow; ipValid = false; hostnameValid = false; this.rowIndex = rowIndex; InputIPAddress.Text = hostRow.IP; InputHostname.Text = hostRow.Host; ShowValidationResult(); }
private void ButtonEditHost_Click(object sender, EventArgs e) { if (ipValid && hostnameValid) { HostRow newHostRow = new HostRow(hostRow.FileRow, InputIPAddress.Text, InputHostname.Text); if (dataManager.UpdateHost(newHostRow)) { Close(); } else { MessageBox.Show("The host entry could not be updated. Please correct the input and try again."); } } }
private void ButtonAddHost_Click(object sender, EventArgs e) { if (ipValid && hostnameValid) { HostRow hostRow = new HostRow(-1, InputIPAddress.Text, InputHostname.Text); if (dataManager.AddHostToFile(hostRow)) { MessageBox.Show("New host was added to the hosts file!"); Close(); } else { MessageBox.Show("The host entry could not be added. Please try again."); } } }