Exemplo n.º 1
0
        public Gadgets()
        {
            InitializeComponent();

            var service = new LibraryAdminService("http://mge1.dev.ifs.hsr.ch/");

            var           gadgets = service.GetAllGadgets();
            List <Gadget> AllG    = new List <Gadget>();

            foreach (Gadget gadget in gadgets)
            {
                AllG.Add(new Gadget()
                {
                    Name = gadget.Name, Price = gadget.Price, Condition = gadget.Condition, InventoryNumber = gadget.InventoryNumber, Manufacturer = gadget.Manufacturer
                });
            }
            allGadgets.ItemsSource = AllG;
            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(allGadgets.ItemsSource);

            view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("Price", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("Condition", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("InventoryNumber", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("Manufacturer", ListSortDirection.Ascending));
        }
        public AddGadget()
        {
            InitializeComponent();

            EditedGadget = new Gadget("neues Gadget");

            lib = new LibraryAdminService(serverUrl);
            //Inventorynumber erzeugen
            long          highestValue = 0;
            List <Gadget> tabelle      = lib.GetAllGadgets();

            foreach (Gadget i in tabelle)
            {
                if (i.InventoryNumber != null)
                {
                    long newNumber = long.Parse(i.InventoryNumber);
                    if (highestValue < newNumber)
                    {
                        highestValue = newNumber;
                    }
                }
            }
            EditedGadget.InventoryNumber = "" + ++highestValue;
            DataContext = this;
        }
Exemplo n.º 3
0
 private void LoadGadgets(Collection <Gadget> targetCollection)
 {
     foreach (Gadget gadget in libraryAdminService.GetAllGadgets())
     {
         targetCollection.Add(gadget);
     }
 }
Exemplo n.º 4
0
        public MainWindowViewModel()
        {
            dataService = new LibraryAdminService(ConfigurationManager.AppSettings.Get("server")?.ToString());

            try
            {
                Gadgets = new ObservableCollection <GadgetViewModel>(dataService.GetAllGadgets()
                                                                     .Select(g => new GadgetViewModel(g)));
                SelectedGadget = Gadgets.FirstOrDefault();

                Customers = new ObservableCollection <CustomerViewModel>(dataService.GetAllCustomers()
                                                                         .Select(c =>
                {
                    var customerViewModel          = new CustomerViewModel(c);
                    customerViewModel.DataChanged += OnCustomerDataChanged;
                    return(customerViewModel);
                }));
                SelectedCustomer = Customers.FirstOrDefault();

                //dataService.DeleteLoan(dataService.GetLoan("d4b05cc5-5948-472a-bbfd-600b4d7578fa"));

                Loans = new ObservableCollection <LoanViewModel>(dataService.GetAllLoans()
                                                                 .Select(l => new LoanViewModel(l)));
                SelectedLoan = Loans.FirstOrDefault();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Beim Laden ist ein Problem aufgetreten.", ex.Message, MessageBoxButton.OK);
                return;
            }
        }
Exemplo n.º 5
0
 private void initalLoadGadgets()
 {
     // Load inital all Gadgets and save settings
     service = new LibraryAdminService(ConfigurationManager.AppSettings["serverGadgeothek"]);
     client  = new websocket.WebSocketClient(ConfigurationManager.AppSettings["serverGadgeothek"]);
     Gadgets = new ObservableCollection <Gadget>(service.GetAllGadgets());
 }
Exemplo n.º 6
0
 private void AsyncGetGadgets()
 {
     foreach (var gadget in _service.GetAllGadgets())
     {
         System.Windows.Application.Current.Dispatcher.Invoke(() => { AllGadgets.Add(gadget); });
     }
     IsLoading = false;
 }
        public MainWindowViewModel()
        {
            libraryAdminService = new LibraryAdminService(ConfigurationManager.AppSettings.Get("server")?.ToString());

            var gadgets = libraryAdminService.GetAllGadgets();

            if (gadgets == null)
            {
                MessageBox.Show("Konnte Gadgets nicht vom Server laden.", "Serverfehler", MessageBoxButton.OK);
            }
            else if (gadgets.Count > 0)
            {
                Gadgets = new ObservableCollection <Gadget>(gadgets);

                SelectedGadget = Gadgets.First();
            }
            else
            {
                MessageBox.Show("Keine Gadgets vorhanden. Bitte fügen Sie zuerst ein Gadget hinzu.", "Keine Gadgets vorhanden", MessageBoxButton.OK);
            }


            var loans = libraryAdminService.GetAllLoans();

            if (loans == null)
            {
                MessageBox.Show("Konnte Ausleihen nicht vom Server laden.", "Serverfehler", MessageBoxButton.OK);
                return;
            }
            else if (loans.Count > 0)
            {
                Loans = new ObservableCollection <Loan>(loans);

                SelectedLoan = Loans.First();
            }

            Task.Run(() =>
            {
                while (true)
                {
                    Thread.Sleep(5000);
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        loans = libraryAdminService.GetAllLoans();
                        if (loans != null)
                        {
                            Loans.Clear();

                            loans.ForEach(Loans.Add);
                        }
                    });
                }
            });
        }
        private void InitializeList()
        {
            GadgetItems = new ObservableCollection <Gadget>();
            var           url     = ConfigurationManager.AppSettings["server"];
            var           service = new LibraryAdminService(url);
            List <Gadget> gadgets = service.GetAllGadgets();

            foreach (Gadget g in gadgets)
            {
                GadgetItems.Add(g);
            }
        }
Exemplo n.º 9
0
        public Ausleihe()
        {
            InitializeComponent();
            var service = new LibraryAdminService("http://mge5.dev.ifs.hsr.ch/");


            var gadgets      = service.GetAllGadgets();
            var customers    = service.GetAllCustomers();
            var reservations = service.GetAllReservations();
            var loans        = service.GetAllLoans();



            List <AllOfCustomer> allCustomer = new List <AllOfCustomer>();

            foreach (Customer c in customers)
            {
                List <Loan> cLoans = getLoans(c, loans);
                allCustomer.Add(new AllOfCustomer(c.Studentnumber, c.Name, getReservations(c, reservations), cLoans, getToBackInformations(cLoans)));
            }
            GadgetsByUser.ItemsSource = allCustomer;
            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(GadgetsByUser.ItemsSource);

            view.Filter = UserFilter1;


            List <ReserveByUser> allReservations = new List <ReserveByUser>();

            foreach (Reservation r in reservations)
            {
                allReservations.Add(new ReserveByUser(r.Customer.Name, r.Gadget.Name, r.WaitingPosition, r.IsReady));
            }
            ReservationsByUsers.ItemsSource = allReservations;
            CollectionView view2 = (CollectionView)CollectionViewSource.GetDefaultView(ReservationsByUsers.ItemsSource);

            view2.Filter = UserFilter2;


            List <LoansByUser> allLoans = new List <LoansByUser>();

            foreach (Loan l in loans)
            {
                if (l.Gadget != null)
                {
                    allLoans.Add(new LoansByUser(l.Gadget.Name, l.Customer.Name, l.ReturnDate, l.IsOverdue, getResByGadget(l, reservations)));
                }
            }
            LeansByGadget.ItemsSource = allLoans;
            CollectionView view3 = (CollectionView)CollectionViewSource.GetDefaultView(LeansByGadget.ItemsSource);

            view3.Filter = UserFilter3;
        }
Exemplo n.º 10
0
        /// <summary>
        /// demonstrates the use of the admin functions to add/remove
        /// new objects to/from the gadgeothek
        /// </summary>
        public void ShowAdminInteraction()
        {
            var service = new LibraryAdminService(ServerUrl);

            var gadget = new Gadget("XBOX360")
            {
                Manufacturer = "Microsoft"
            };

            if (!service.AddGadget(gadget))
            {
                Console.WriteLine($"{gadget} konnte nicht hinzugefügt werden...");
                return;
            }

            var gadgets = service.GetAllGadgets();

            PrintAll(gadgets, "Gadgets (NEW)");

            gadget.Condition = Condition.Damaged;
            if (!service.UpdateGadget(gadget))
            {
                Console.WriteLine($"{gadget} konnte nicht aktualisiert werden...");
                return;
            }


            gadgets = service.GetAllGadgets();
            PrintAll(gadgets, "Gadgets (NEW 2)");

            if (!service.DeleteGadget(gadget))
            {
                Console.WriteLine($"{gadget} konnte nicht gelöscht werden...");
                return;
            }

            gadgets = service.GetAllGadgets();
            PrintAll(gadgets, "Gadgets (NEW 3)");
        }
        public GadgetViewModel()
        {
            var url = System.Configuration.ConfigurationManager.AppSettings["serverGadgeothek"];

            Service = new LibraryAdminService(url);

            Gadgets = Service.GetAllGadgets();
            Loans   = Service.GetAllLoans();

            EditGadgetCommand   = new RelayCommand.RelayCommand <Object>((o) => EditGadget());
            DeleteGadgetCommand = new RelayCommand.RelayCommand <Object>((o) => DeleteGadget());

            aTimer          = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(OnTimerEvent);
            aTimer.Interval = 5000;
            aTimer.Enabled  = true;
            aTimer.Start();
        }
Exemplo n.º 12
0
        public void RefreshDataGrid()
        {
            AllGadgets = service.GetAllGadgets();
            GadgetList.Clear();
            if (AllGadgets != null)
            {
                AllGadgets.ForEach(GadgetList.Add);

                AllLoans = service.GetAllLoans();
                LoanList.Clear();
                AllLoans.ForEach(LoanList.Add);
            }
            else
            {
                MessageBox.Show("Keine Verbindung zum Server gefunden!", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown();
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// demonstrates how to get the full inventory from the gadgeothek
        /// </summary>
        public void ShowInventory()
        {
            var service = new LibraryAdminService(ServerUrl);

            // no need to login as admin, woohoo :-)

            var gadgets = service.GetAllGadgets();

            PrintAll(gadgets);

            var customers = service.GetAllCustomers();

            PrintAll(customers);

            var reservations = service.GetAllReservations();

            PrintAll(reservations);

            var loans = service.GetAllLoans();

            PrintAll(loans);
        }
Exemplo n.º 14
0
        public string findInventoryNumber()
        {
            List <Gadget> gadgets = service.GetAllGadgets();

            for (int i = 1; i < gadgets.Count; i++)
            {
                bool unused = true;
                foreach (Gadget gadget in gadgets)
                {
                    if (gadget.InventoryNumber.Equals(i.ToString()))
                    {
                        unused = false;
                        break;
                    }
                }
                if (unused)
                {
                    return(i.ToString());
                }
            }
            return("no inventory number found");
        }
Exemplo n.º 15
0
 public MainViewModel(String server)
 {
     ServerAddress = server;
     Gadgets       = new ObservableCollection <Gadget>(Service.GetAllGadgets());
     Loans         = new ObservableCollection <Loan>(Service.GetAllLoans());
     Reservations  = new ObservableCollection <Reservation>(Service.GetAllReservations());
     Task.Run(() =>
     {
         while (true)
         {
             Console.WriteLine("Update Loans");
             Thread.Sleep(3000);
             List <Loan> list = Service.GetAllLoans();
             Application.Current.Dispatcher.BeginInvoke(
                 DispatcherPriority.Background,
                 new Action(() => {
                 Loans.Clear();
                 list.ForEach(Loans.Add);
             }));
         }
     });
     Task.Run(() =>
     {
         while (true)
         {
             Console.WriteLine("Update Reservations");
             Thread.Sleep(3000);
             List <Reservation> list = Service.GetAllReservations();
             Application.Current.Dispatcher.BeginInvoke(
                 DispatcherPriority.Background,
                 new Action(() => {
                 Reservations.Clear();
                 list.ForEach(Reservations.Add);
             }));
         }
     });
 }
Exemplo n.º 16
0
        public MainWindow()
        {
            InitializeComponent();
            service = new LibraryAdminService(ConfigurationSettings.AppSettings.Get("server"));
            var client = new websocket.WebSocketClient(ConfigurationSettings.AppSettings.Get("server"));

            this.DataContext = this;
            Gadgets          = new ObservableCollection <Gadget>(service.GetAllGadgets());
            Loans            = new ObservableCollection <Loan>(service.GetAllLoans());
            List <domain.Customer>    customers    = service.GetAllCustomers();
            List <domain.Reservation> reservations = service.GetAllReservations();

            //gadgetGrid.ItemsSource = gadgets;
            //loanGrid.ItemsSource = loans;
            reservationGrid.ItemsSource = reservations;
            customerGrid.ItemsSource    = customers;


            client.NotificationReceived += (o, e) =>
            {
                Console.WriteLine("WebSocket::Notification: " + e.Notification.Target + " > " + e.Notification.Type);

                // demonstrate how these updates could be further used
                if (e.Notification.Target == typeof(Loan).Name.ToLower())
                {
                    // deserialize the json representation of the data object to an object of type Gadget
                    var loan = e.Notification.DataAs <Loan>();
                    // now you can use it as usual...
                    //Console.WriteLine("Details: " + gadget);
                    Loans.Add(loan);
                }
            };

            // spawn a new background thread in which the websocket client listens to notifications from the server
            var bgTask = client.ListenAsync();
        }
Exemplo n.º 17
0
 public List <Gadget> GetAllGadgets() => Service.GetAllGadgets();
Exemplo n.º 18
0
        public void LoadData()
        {
            Gadgets.Clear();

            _service.GetAllGadgets().ForEach(g => Gadgets.Add(g));
        }
Exemplo n.º 19
0
 public ViewModelGadgets()
 {
     allGadgets = new ObservableCollection <Gadget>(service.GetAllGadgets());
 }
Exemplo n.º 20
0
 private void RefreshGadgets()
 {
     Gadgets.Clear();
     service.GetAllGadgets().ForEach(g => Gadgets.Add(g));
 }