Esempio n. 1
0
 public ResponsesTableViewModel()
 {
     using (var db = new PingDataContext())
     {
         PingResponses = db.Responses.ToList();
     }
 }
Esempio n. 2
0
 public ComputersViewModel()
 {
     DeleteCommand = new RelayCommand(Delete);
     using (var db = new PingDataContext())
     {
         Computers = new ObservableCollection <Devices>(db.Devices.ToList()); //przypisanie tabelki z bazy do programu (na ten sposób wpadłem puźniej dlatego w innych jest to zrobione przez przegląd listy - MainWindowViewModel)
     }
 }
Esempio n. 3
0
 private void Delete()//funkcja usuwania rekordów z bazy (usuwa też powiązane kaskadowo)
 {
     using (var db = new PingDataContext())
     {
         Devices device = new Devices()
         {
             Id = _Computers[_SelectedDevice].Id
         };                                                                   //sprawdzenie id zaznaczoneko rekordu i stworzenie jego obiektu
         db.Devices.Attach(device);                                           //przyłączenie tego obiektu do istniejącego w bazie (id jest tylko jedno)
         db.Devices.Remove(device);                                           //usunięcie rekordu
         db.SaveChanges();
         Computers = new ObservableCollection <Devices>(db.Devices.ToList()); //aktualizacja tabelki
     }
 }
Esempio n. 4
0
        }                         //służy do wywołania funkcji przez binding musi być przypisana do funkcji w konstruktorze
        private void PingDevice() //funkcja pingowania
        {
            Ping pinger = new Ping();

            try
            {
                if (_SelectedDevice != -1)
                {
                    var       id    = IdControl[_SelectedDevice];             //bierze id zaznaczonego urządzenia
                    PingReply reply = pinger.Send(DevicesIP[SelectedDevice]); //przypisanie jakie ip pingujemy
                    using (var db = new PingDataContext())
                    {
                        if (reply.Status == IPStatus.Success)//jeśli ping się powiódł
                        {
                            PingStatusColor = "Green";
                            PingStatusText  = "TRUE";
                            db.Responses.Add(new Responses() //sapisanie donych do bazy
                            {
                                Device_Id = id,
                                Success   = true,
                                PingTime  = reply.RoundtripTime, //czas pingu (ms)
                                Time      = DateTime.Now         //Data pingu
                            });
                        }
                        else//jak się nie udał
                        {
                            PingStatusColor = "Red";
                            PingStatusText  = "False";
                            db.Responses.Add(new Responses()
                            {
                                Device_Id = id,
                                Success   = false,
                                Time      = DateTime.Now
                            });
                        }
                        db.SaveChanges(); //zapis danych do bazy (zostaje przesłane do bazy SQL)
                    }
                }
            }
            catch (PingException)
            {
                // Discard PingExceptions and return false;
            }
        }
Esempio n. 5
0
        private void OpenComputersTable()//funkcja która otwiera tabelkę urządzeń
        {
            Computers computers = new Computers();

            computers.ShowDialog();                // nie można kożystać z głównego okna puki to jest otwarty (Dialog)
            using (var db = new PingDataContext()) // wyczyszczenie i wpisanie danych na nowo (można w tym oknie usuwać dane więc po zamknięciu trzeba zaktualizować)
            {
                DevicesIP.Clear();
                IdControl.Clear();
                DevicesList.Clear();
                var devicesAll = db.Devices.ToList();
                foreach (var item in devicesAll)
                {
                    DevicesIP.Add(item.IP);
                    IdControl.Add(item.Id);
                    DevicesList.Add(item.Name + " " + item.IP);
                }
            }
        }
Esempio n. 6
0
 public MainWindowViewModel()                                          //ustawienie początkowych wartości elementów
 {
     OpenComputersTableCommand = new RelayCommand(OpenComputersTable); //stworzenie relaycommand tak by można było przypiosać funkcje do elementów okna (naciśnięcie przycisku itp.
     OpenResponsesTableCommand = new RelayCommand(OpenResponsesTable);
     AddDeviceCommand          = new RelayCommand(AddDevice);
     PingCommand = new RelayCommand(PingDevice);
     CanPing     = false;
     CanAdd      = false;
     using (var db = new PingDataContext())    // operowanie na bazie
     {
         db.Database.CreateIfNotExists();      // stworzenie bazy jeśli nie istnieje
         var devicesAll = db.Devices.ToList(); // wpisanie wszyskich urządzeń do listy by potem poszczególne elementy dodać do właściwości ViewModelu
         foreach (var item in devicesAll)
         {
             DevicesIP.Add(item.IP);
             IdControl.Add(item.Id);
             DevicesList.Add(item.Name + " " + item.IP);
         }
     }
 }
Esempio n. 7
0
        private void AddDevice() // dodawanie urządzenia
        {
            using (var db = new PingDataContext())
            {
                db.Devices.Add(new Devices()
                {
                    IP          = _IPAddress,
                    Name        = _Name,
                    Description = _Description
                });

                db.SaveChanges();
                DevicesList.Add(_Name + " " + _IPAddress);    //dodanie nowego urządzenia do listy
                DevicesIP.Add(_IPAddress);                    //dodanie ip
                IdControl.Add(db.Devices.ToList().Last().Id); //dodanie id nowego elementu (bierze ostatnie id z bazy - to dodane)
                Name        = "";
                IPAddress   = "";
                Description = "";
            }
        }