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));
        }
Exemplo n.º 2
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.º 3
0
 private void initalLoadLoans()
 {
     // Load inital all Gadgets and save settings
     service = new LibraryAdminService(ConfigurationManager.AppSettings["serverGadgeothek"]);
     client  = new websocket.WebSocketClient(ConfigurationManager.AppSettings["serverGadgeothek"]);
     Loans   = new ObservableCollection <Loan>(service.GetAllLoans());
 }
        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.º 5
0
        public ApplicationViewModel()
        {
            string serverUrl = ConfigurationManager.AppSettings["server"].ToString();

            _service = new LibraryAdminService(serverUrl);

            ChangePage(Pages.First());
        }
Exemplo n.º 6
0
        public GadgetControl()
        {
            InitializeComponent();

            String ServerUrl = "http://localhost:8080";

            service = new LibraryAdminService(ServerUrl);
        }
Exemplo n.º 7
0
        public Gadget_hinzufügen()
        {
            InitializeComponent();
            String ServerUrl = "http://localhost:8080";

            service = new LibraryAdminService(ServerUrl);

            tbID.Text = findInventoryNumber();
        }
        public GadgetDeleteViewModel(Gadget gadget)
        {
            service = new LibraryAdminService(ConfigurationManager.AppSettings["serverGadgeothek"]);

            delGadget = gadget;

            sureGadgetCom   = new RelayCommand <Window>((x) => funcsureGadget(x), (x) => true);
            cancelGadgetCom = new RelayCommand <Window>((x) => funcCancel(x), (x) => true);
        }
        public GadgetNewViewModel()
        {
            service = new LibraryAdminService(ConfigurationManager.AppSettings["serverGadgeothek"]);

            newGadget = new Gadget();

            addGadgetCom    = new RelayCommand <Window>((x) => funcAddGadget(x), (x) => true);
            cancelGadgetCom = new RelayCommand <Window>((x) => funcCancel(x), (x) => true);
        }
Exemplo n.º 10
0
        public NewGadgetViewModel()
        {
            var url = System.Configuration.ConfigurationManager.AppSettings["serverGadgeothek"];

            Service = new LibraryAdminService(url);

            SaveCommand   = new RelayCommand.RelayCommand <Object>((o) => Save());
            CancelCommand = new RelayCommand.RelayCommand <Object>((o) => Cancel());
        }
        public void setData()
        {
            GadgetItem.Clear();
            List <Gadget> gadgetList = new LibraryAdminService(serverUrl).GetAllGadgets();

            foreach (Gadget gadget in gadgetList)
            {
                GadgetItem.Add(gadget);
            }
        }
Exemplo n.º 12
0
        public EditGadgetViewModel(Gadget gadget)
        {
            var url = System.Configuration.ConfigurationManager.AppSettings["serverGadgeothek"];

            Service = new LibraryAdminService(url);

            EditGadget = gadget;

            ConfirmEditCommand = new RelayCommand.RelayCommand <Object>((o) => ConfirmEdit());
            CancelEditCommand  = new RelayCommand.RelayCommand <Object>((o) => CancelEdit());
        }
Exemplo n.º 13
0
        public CustomerPage()
        {
            InitializeComponent();
            var appSettings = ConfigurationManager.AppSettings;
            var ServerUrl   = appSettings.Get("server");
            var Service     = new LibraryAdminService(ServerUrl);

            ViewModel   = new CustomerViewModel(Service);
            DataContext = ViewModel;
            ViewModel.LoadCustomers();
        }
Exemplo n.º 14
0
        public DeleteGadgetViewModel(Gadget gadgetToDelete)
        {
            var url = System.Configuration.ConfigurationManager.AppSettings["serverGadgeothek"];

            Service = new LibraryAdminService(url);

            Gadget = gadgetToDelete;

            ConfirmDeleteGadgetCommand = new RelayCommand <Object>((o) => ConfirmDeleteGadget());
            CancelDeleteGadgetCommand  = new RelayCommand <Object>((o) => CancelDeleteGadget());
        }
Exemplo n.º 15
0
        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.º 17
0
        public Gadgets()
        {
            InitializeComponent();

            LibraryAdminService lib = new LibraryAdminService("http://mge7.dev.ifs.hsr.ch/");

            List <Loan> gadgets = lib.GetAllLoans();

            dgGadgets.ItemsSource = gadgets;

            Regex regex = new Regex("(?<WEAKDAY>Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?<MONTH>[0-9]{1,2})/(?<DAY>[0-9]{1,2})/(?<YEAR>[0-9]*)");
        }
Exemplo n.º 18
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.º 19
0
        public void setData()
        {
            LoanItem.Clear();
            List <Loan> loanList = new LibraryAdminService(serverUrl).GetAllLoans();

            foreach (Loan loan in loanList)
            {
                if (loan.IsLent)
                {
                    LoanItem.Add(loan);
                }
            }
        }
        private void FillData()
        {
            LoansItem.Clear();
            var         url     = ConfigurationManager.AppSettings["server"];
            var         service = new LibraryAdminService(url);
            List <Loan> loans   = service.GetAllLoans();

            foreach (Loan l in loans)
            {
                if (l.IsLent)
                {
                    LoansItem.Add(l);
                }
            }
        }
Exemplo n.º 21
0
        public void TestPreventSelectionWhenHasUnsavedChanges()
        {
            var Service   = new LibraryAdminService("http://localhost:8080");
            var ViewModel = new CustomerViewModel(Service);

            ViewModel.LoadCustomers();
            Customer CustomerA = ViewModel.AllCustomers[0];
            Customer CustomerB = ViewModel.AllCustomers[1];

            ViewModel.CustomerInEditor = CustomerA;
            ViewModel.EditorName       = "test";
            ViewModel.CustomerInEditor = CustomerB;

            Assert.AreEqual(ViewModel.CustomerInEditor, CustomerA);
        }
Exemplo n.º 22
0
        public void TestSetEditrValues()
        {
            var Service   = new LibraryAdminService("http://localhost:8080");
            var ViewModel = new CustomerViewModel(Service);

            ViewModel.LoadCustomers();
            Customer CustomerA = ViewModel.AllCustomers[0];

            ViewModel.CustomerInEditor = CustomerA;

            Assert.AreEqual(ViewModel.EditorStudentnumber, CustomerA.Studentnumber);
            Assert.AreEqual(ViewModel.EditorName, CustomerA.Name);
            Assert.AreEqual(ViewModel.EditorEmail, CustomerA.Email);
            Assert.AreEqual(ViewModel.EditorStudentnumber, CustomerA.Studentnumber);
        }
Exemplo n.º 23
0
        public void TestPreventSelectionDuringCreation()
        {
            var Service   = new LibraryAdminService("http://localhost:8080");
            var ViewModel = new CustomerViewModel(Service);

            ViewModel.LoadCustomers();
            Customer OldCustomer = ViewModel.AllCustomers[0];

            ViewModel.NewCustomer();
            Customer NewCustomer = ViewModel.CustomerInEditor;

            ViewModel.EditorName       = "test";
            ViewModel.CustomerInEditor = OldCustomer;

            Assert.AreEqual(ViewModel.CustomerInEditor, NewCustomer);
        }
Exemplo n.º 24
0
        public MainWindow()
        {
            InitializeComponent();

            //DataContext = this;
            Ausleihe.DataContext = this;
            Gadget.DataContext   = this;

            GadgetList = new ObservableCollection <Gadget>();
            LoanList   = new ObservableCollection <Loan>();

            String ServerUrl = "http://localhost:8080";

            service = new LibraryAdminService(ServerUrl);

            RefreshDataGrid();
        }
Exemplo n.º 25
0
        public void TestPreventResetAfterCreationWhenHasUnsavedChanges()
        {
            var Service   = new LibraryAdminService("http://localhost:8080");
            var ViewModel = new CustomerViewModel(Service);

            ViewModel.LoadCustomers();
            Customer CustomerA = ViewModel.AllCustomers[0];

            ViewModel.CustomerInEditor = CustomerA;
            var TEST_NAME = "test";

            ViewModel.EditorName = TEST_NAME;
            ViewModel.NewCustomer();

            Assert.AreEqual(ViewModel.CustomerInEditor, CustomerA);
            Assert.AreEqual(ViewModel.EditorName, TEST_NAME);
        }
        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.º 27
0
        public MainWindow()
        {
            String ServerUrl            = ConfigurationManager.AppSettings["server"].ToString();
            LibraryAdminService Service = new LibraryAdminService(ServerUrl);

            InitializeComponent();
            AppViewModel AppViewModel = new AppViewModel(Service);

            DataContext = AppViewModel;

            GadgetsListView.GadgetsListViewModel.AppViewModel = AppViewModel;
            GadgetsListView.GadgetsListViewModel.PullAllGadgets();

            LoansListView.LoansListViewModel.AppViewModel = AppViewModel;
            LoansListView.LoansListViewModel.PullAllLoans();

            ClientsListView.ClientsListViewModel.AppViewModel = AppViewModel;
            ClientsListView.ClientsListViewModel.PullAllClients();
        }
Exemplo n.º 28
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Gadget gadget = new Gadget(name.Text.ToString());
            double isDouble;

            double.TryParse(price.Text.ToString(), out isDouble);
            gadget.Price        = isDouble;
            gadget.Manufacturer = manufacturer.Text.ToString();
            LibraryAdminService service = new LibraryAdminService(ConfigurationSettings.AppSettings.Get("server"));

            if (service.AddGadget(gadget))
            {
                MessageBox.Show("Gadget successfully added!");
                this.Close();
            }
            else
            {
                MessageBox.Show("Operation failed!");
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// demonstrates the use of the admin functions to add/remove
        /// new loans and reservations to/from the gadgeothek
        /// (internally a bit more complicated since holding
        /// referenced values)
        /// </summary>
        public void ShowAdminInteractionForLoans()
        {
            var service = new LibraryAdminService(ServerUrl);

            var rnd      = new Random();
            var randomId = rnd.Next(100000, 999999).ToString();

            var android = service.GetGadget("26");   // Android2
            var michael = service.GetCustomer("10"); // Michael
            var loan    = new Loan(randomId, android, michael, DateTime.Today.AddDays(-1), null);

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

            var loans = service.GetAllLoans();

            PrintAll(loans, "Loans (NEW)");

            loan.ReturnDate = DateTime.Now;
            if (!service.UpdateLoan(loan))
            {
                Console.WriteLine($"{loan} konnte nicht aktualisiert werden...");
                return;
            }


            loans = service.GetAllLoans();
            PrintAll(loans, "Loans (NEW 2)");;

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

            loans = service.GetAllLoans();
            PrintAll(loans, "Loans (NEW 3)");
        }
Exemplo n.º 30
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)");
        }