private void InsertButton_Click(object sender, RoutedEventArgs e) { if (CheckInput()) { try { Networks network = new Networks(); network.networkID = Int32.Parse(networkID.Text); network.networkName = networkName.Text; network.networkPassword = networkPassword.Text; network.networkIP = networkIP.Text; entities.Networks.Add(network); entities.SaveChanges(); this.Close(); } catch { MessageBox.Show("Ошибка добавления данных в базу."); } } else { MessageBox.Show("Не все поля заполнены."); } }
public NetworksWindow(NetworkBaseEntities db, Networks network) { InitializeComponent(); uNetwork = network; entities = db; insertButton.IsEnabled = false; updateButton.IsEnabled = true; networkID.IsReadOnly = true; ShowData(); }
/// <summary> /// Удаление сети /// </summary> private void DeleteNetworks() { try { Networks network = tablesGrid.SelectedItem as Networks; var dNetwork = db.Networks.Where(n => n.networkID == network.networkID).FirstOrDefault(); db.Networks.Remove(dNetwork); db.SaveChanges(); } catch { MessageBox.Show("Ошибка удаления данных из базы"); } }
/// <summary> /// Реализация Update /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateButton_Click(object sender, RoutedEventArgs e) { //Устройства if (shownTable == Table.device) { Devices device = tablesGrid.SelectedItem as Devices; var uDevice = db.Devices.Where(d => d.deviceID == device.deviceID).FirstOrDefault(); DevicesWin window = new DevicesWin(db, uDevice); window.ShowDialog(); SelectDevices(); } //Отделы if (shownTable == Table.department) { Departments department = tablesGrid.SelectedItem as Departments; var udepartment = db.Departments.Where(d => d.departmentID == department.departmentID).FirstOrDefault(); DepartmentWindow window = new DepartmentWindow(db, udepartment); window.ShowDialog(); SelectDeparments(); } //Пользователи if (shownTable == Table.user) { Users user = tablesGrid.SelectedItem as Users; var uUser = db.Users.Where(u => u.userID == user.userID).FirstOrDefault(); UsersWindow window = new UsersWindow(db, uUser); window.ShowDialog(); SelectUsers(); } //Сети устройства if (shownTable == Table.deviceNateworks) { DeviceNetworks network = tablesGrid.SelectedItem as DeviceNetworks; var uNetwork = db.DeviceNetworks.Where(n => n.networkID == network.networkID && n.deviceID == network.deviceID).FirstOrDefault(); DeviceNetworksWindow window = new DeviceNetworksWindow(db, uNetwork); window.ShowDialog(); SelectDeviceNetworks(); } //Сети if (shownTable == Table.network) { Networks network = tablesGrid.SelectedItem as Networks; var uNetwork = db.Networks.Where(n => n.networkID == network.networkID).FirstOrDefault(); NetworksWindow window = new NetworksWindow(db, uNetwork); window.ShowDialog(); SelectNetworks(); } }