private void addButton_Click(object sender, EventArgs e) { var net = networkComBox.SelectedItem as System.Net.NetworkInformation.NetworkInterface; var model = IpSwitchHelper.CreateDefault(net?.Id); nameMaskedTextBox.Text = "新方案" + (itemListBox.Items.Count + 1); ipMaskedTextBox.Text = model.IpAddress; subnetMaskedTextBox.Text = model.SubnetMask; gateMaskedTextBox.Text = model.Gateway; dnsMaskedTextBox.Text = model.DNS; idMaskedTextBox.Text = tempId; itemListBox.SelectedIndex = -1; }
public void SelectItem() { var id = itemListBox.SelectedValue?.ToString(); var model = IpSwitchHelper.FindById(id); if (model == default(IpEntity)) { return; } nameMaskedTextBox.Text = model.Name; ipMaskedTextBox.Text = model.IpAddress; subnetMaskedTextBox.Text = model.SubnetMask; gateMaskedTextBox.Text = model.Gateway; dnsMaskedTextBox.Text = model.DNS; idMaskedTextBox.Text = model.Id; networkComBox.SelectedValue = model.NetworkID; }
private void delButton_Click(object sender, EventArgs e) { var id = itemListBox.SelectedValue?.ToString(); if (string.IsNullOrEmpty(id)) { return; } var se = itemListBox.SelectedIndex; var msg = IpSwitchHelper.DeleteConfig(new IpEntity { Id = id }); LoadConfig(); itemListBox.SelectedIndex = se >= 0 ? (se >= itemListBox.Items.Count ? se - 1 : se) : 0; MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public void LoadConfig() { nameMaskedTextBox.Text = ""; ipMaskedTextBox.Text = ""; subnetMaskedTextBox.Text = ""; gateMaskedTextBox.Text = ""; dnsMaskedTextBox.Text = ""; idMaskedTextBox.Text = ""; itemListBox.DataSource = null; itemListBox.Items.Clear(); var ls = IpSwitchHelper.LoadItems(); if (ls.Items.Count <= 0) { return; } itemListBox.DataSource = ls.Items; itemListBox.DisplayMember = "Name"; itemListBox.ValueMember = "Id"; }
private void saveButton_Click(object sender, EventArgs e) { var se = itemListBox.SelectedIndex; var net = networkComBox.SelectedItem as System.Net.NetworkInformation.NetworkInterface; var model = new IpEntity { Name = nameMaskedTextBox.Text.Trim(), IpAddress = ipMaskedTextBox.Text.Trim(), Id = idMaskedTextBox.Text.Trim(), Gateway = gateMaskedTextBox.Text.Trim(), SubnetMask = subnetMaskedTextBox.Text.Trim(), NetworkName = net?.Name, NetworkID = net?.Id, MACAddress = net?.GetPhysicalAddress()?.ToString(), DNS = dnsMaskedTextBox.Text.Trim() }; var isPass = true; var res = string.Empty; res = IpSwitchHelper.CheckIpEntity(model, ref isPass); if (!isPass) { MessageBox.Show(res, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (model.Id.Equals(tempId) || string.IsNullOrEmpty(model.Id)) { model.Id = Guid.NewGuid().ToString("N"); res = IpSwitchHelper.AddConfig(model); } else { res = IpSwitchHelper.UpdateConfig(model); } LoadConfig(); itemListBox.SelectedIndex = se >= 0 ? se : 0; MessageBox.Show(res, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }