private void SaveButton_Click(object sender, RoutedEventArgs e) { if (TitleTextBox.Text == "" || ModelTextBox.Text == "" || TransmissionSpeedTextBox.Text == "" || TypeOfAdapterTextBox.Text == "") { MessageBox.Show("Должны быть заполнены все поля"); return; } try { NetworkInterfaceController newNIC = new NetworkInterfaceController(); newNIC.Title = TitleTextBox.Text; newNIC.Model = ModelTextBox.Text; newNIC.TypeOfAdapter = TypeOfAdapterTextBox.Text; newNIC.TransmissionSpeed = Convert.ToInt32(TransmissionSpeedTextBox.Text); newNIC.GenerationId = Database.Connection.Generation.First(g => g.Title == GenerationComboBox.SelectedItem.ToString()).Id; if (SaveButton.Content.ToString() == "Добавить") { Database.Connection.NetworkInterfaceController.Add(newNIC); } Database.Connection.SaveChanges(); MessageBox.Show("Успешное сохранение"); NavigationService.Navigate(new PageOfHardware("Сетевой адаптер")); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Builds an internal list of NICs and if passed true for forceUpdate, will update the wireless NIC entry in the configuration file. /// </summary> /// <param name="forceUpdate">Boolean if true, forces the application to update the configuration with the name of the wireless NIC installed on the computer.</param> private void PopulateWirelessNicsAndController(bool forceUpdate) { const string MemberName = "PopulateWirelessNicsAndController"; using (new Tracer(MemberName)) { try { if ((forceUpdate == true)) { // No wireless adapters were found during installation. // Perhaps it was disabled in the BIOS upon install. // Let's try again... ConMonInstaller installer = new ConMonInstaller(); installer.UpdateAppConfigFile(); } string vpnExceptionList = GetVPNExceptionList(); MonitoredDevice[] monitoredDevices = ReadMonitoredDevicesFromConfig(); nicController = new NetworkInterfaceController(eventLog, vpnExceptionList, monitoredDevices); // Build list of NIC Names and publish NICsFound event to WCF service List <string> nics = new List <string>(); foreach (MonitoredDevice device in monitoredDevices) { nics.Add(device.Name); } if (nics != null && nics.Count > 0) { this.ConMonServiceEventsWCFServiceClient.NICsFound(nics.ToArray()); } } catch (ConnectionMonitorException cme) { Logger.Write(cme); throw cme; } catch (Exception ex) { Logger.Write(ex); throw ex; } } }
public FormForAddOrNIC(NetworkInterfaceController myNIC) { MyNIC = myNIC; GenerationList = Database.Connection.Generation.Select(g => g.Title).ToList(); InitializeComponent(); Mail.DataContext = Current.user; if (String.IsNullOrEmpty(myNIC.Title)) { SaveButton.Content = "Добавить"; } if (myNIC.Path == null) { HardwareImage.Visibility = Visibility.Hidden; } else { HardwareImage.Source = new BitmapImage(new Uri(myNIC.Path)); } DataContext = this; }