예제 #1
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();
        }
예제 #2
0
        public GadgetControl()
        {
            InitializeComponent();

            String ServerUrl = "http://localhost:8080";
            service = new LibraryAdminService(ServerUrl);
        }
예제 #3
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            String ServerUrl = "http://localhost:8080";
            var service = new LibraryAdminService(ServerUrl);

            // Create Gadget
            String value = this.tbPrice.Text;
            Double result = 0;
            try
            {
                result = Convert.ToDouble(value);
            }
            catch (FormatException)
            {
                Console.WriteLine("Unable to convert '{0}' to a Double.", value);
            }
            catch (OverflowException)
            {
                Console.WriteLine("'{0}' is outside the range of a Double.", value);
            }
            ch.hsr.wpf.gadgeothek.domain.Condition condition = new ch.hsr.wpf.gadgeothek.domain.Condition();
            switch (cbCondition.Text.ToUpper())
            {
                case "NEW":
                    condition = ch.hsr.wpf.gadgeothek.domain.Condition.New;
                    break;
                case "GOOD":
                    condition = ch.hsr.wpf.gadgeothek.domain.Condition.Good;
                    break;
                case "DAMAGED":
                    condition = ch.hsr.wpf.gadgeothek.domain.Condition.Damaged;
                    break;
                case "WASTE":
                    condition = ch.hsr.wpf.gadgeothek.domain.Condition.Waste;
                    break;
                case "LOST":
                    condition = ch.hsr.wpf.gadgeothek.domain.Condition.Lost;
                    break;
                default:
                    condition = ch.hsr.wpf.gadgeothek.domain.Condition.New;
                    break;
            }

            Gadget newGadget = new Gadget();

            string invetoryNr = "0";
            if (!this.tbID.Text.Equals(""))
            {
                invetoryNr = this.tbID.Text;
            }
            newGadget.InventoryNumber = invetoryNr;
            newGadget.Name = this.tbName.Text;
            newGadget.Manufacturer = this.tbManufacturer.Text;
            newGadget.Price = result;
            newGadget.Condition = condition;

            service.UpdateGadget(newGadget);
            this.DialogResult = true;
        }
        public Gadget_hinzufügen()
        {
            InitializeComponent();
            String ServerUrl = "http://localhost:8080";
            service = new LibraryAdminService(ServerUrl);

            tbID.Text = findInventoryNumber();
        }
 public AddGadgetWindow()
 {
     InitializeComponent();
     _service = new LibraryAdminService(ConfigurationManager.AppSettings["server"]);
     conditionComboBox.ItemsSource = Enum.GetValues(typeof(ch.hsr.wpf.gadgeothek.domain.Condition));
     conditionComboBox.SelectedIndex = 0;
     idTextBlock.Text = GetNewGadgetId();
     nameTextBox.Focus();
 }
예제 #6
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            ServerUrl = "http://localhost:8080";
            Service = new LibraryAdminService(ServerUrl);
            ClientListener = new WebSocketClient(ServerUrl);
            ClientListener.NotificationReceived += ClientListenerNotified;
            ClientListener.ListenAsync();

            Gadgets = new ObservableCollection<Gadget>(Service.GetAllGadgets());
            Loans = new ObservableCollection<Loan>(Service.GetAllLoans());
            
            InputComboCondition.ItemsSource = Enum.GetValues(typeof(domain.Condition)).Cast<domain.Condition>();
        }
예제 #7
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();
        }
        public MainWindow()
        {
            InitializeComponent();
            _service = new LibraryAdminService(ConfigurationManager.AppSettings["server"]);

            EnableDisableButtons(false);

            GadgetList = GetGadgets();
            CustomerList = GetCustomers();
            ReservationList = GetReservations();
            LoanList = GetLoans();

            DataContext = this;

            GadgetsDataGridView.ItemsSource = GadgetList;
        }
예제 #9
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!");
     }
 }
예제 #10
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            String ServerUrl = "http://localhost:8080";
            var service = new LibraryAdminService(ServerUrl);

            Customer customer = service.GetCustomer(tbStudentID.Text);
            DateTime time = DateTime.Now;
            String gadgetID = tbGadgetID.Text;

            Loan loan = new Loan(
                tbLoanID.Text,
                service.GetGadget(gadgetID),
                service.GetCustomer(tbStudentID.Text),
                time,
                time.AddDays(30)
                );

            service.AddLoan(loan);

            this.DialogResult = true;
        }
 public GadgetViewModel(LibraryAdminService service, Gadget gadget)
 {
     _service = service;
     _gadget = gadget;
 }
예제 #12
0
 public LoanViewModel(LibraryAdminService service, Loan loan)
 {
     _service = service;
     _loan = loan;
 }
예제 #13
0
        private void Initialisation()
        {
            libserv = new LibraryAdminService("http://mge2.dev.ifs.hsr.ch/");

            GadgetList = new ObservableCollection<Gadget>();
            dataGrid_Gadget.ItemsSource = GadgetList;

            LoanList = new ObservableCollection<Loan>();
            dataGrid_Loan.ItemsSource = LoanList;

            ReservationList = new ObservableCollection<Reservation>();
            dataGrid_Reservation.ItemsSource = ReservationList;

            refreshTimer.Tick += new EventHandler(refreshTimer_Tick);
            refreshTimer.Interval = new TimeSpan(0, 0, 1);
            refreshTimer.Start();

            comboBox_GadgetCondition.ItemsSource = Enum.GetValues(typeof(domain.Condition));
        }
        public void Connect()
        {
            if (_connected) return;
            try
            {
                ServiceUrl = "http://localhost:8080";
                _libraryAdminService = new LibraryAdminService(ServiceUrl);
                _connected = true;
                LoadData();
                RefreshComponents();
                StatusBarInfo.Content = $"Connected to {ServiceUrl}";
                StatusBar.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x07, 0x78, 0xB5));

                HideLoadingScreen();

                var client = new WebSocketClient(ServiceUrl);
                client.NotificationReceived += (o, e) =>
                {
                    Debug.WriteLine("WebSocket::Notification: " + e.Notification.Target + " > " + e.Notification.Type);

                    // demonstrate how these updates could be further used
                    if (e.Notification.Target == typeof(Gadget).Name.ToLower())
                    {
                        var gadget = e.Notification.DataAs<Gadget>();
                        var oldGadget = Gadgets.Find(g => g.InventoryNumber == gadget.InventoryNumber);
                        Gadgets.Remove(oldGadget);
                        if (e.Notification.Type != WebSocketClientNotificationTypeEnum.Delete)
                        {
                            Gadgets.Add(gadget);
                        }

                    } else if (e.Notification.Target == typeof(Reservation).Name.ToLower())
                    {
                        var reservation = e.Notification.DataAs<Reservation>();
                        var oldReservation = Reservations.Find(r => r.Id == reservation.Id);
                        Reservations.Remove(oldReservation);

                        reservation.Customer = Customers.Find(c => c.Studentnumber == reservation.CustomerId);
                        reservation.Gadget = Gadgets.Find(c => c.InventoryNumber == reservation.GadgetId);
                        if (e.Notification.Type != WebSocketClientNotificationTypeEnum.Delete)
                        {
                            Reservations.Add(reservation);
                        }

                    } else if (e.Notification.Target == typeof(Loan).Name.ToLower())
                    {
                        var loan = e.Notification.DataAs<Loan>();
                        var oldLoans = Loans.Find(l => l.Id == loan.Id);
                        Loans.Remove(oldLoans);

                        loan.Customer = Customers.Find(c => c.Studentnumber == loan.CustomerId);
                        loan.Gadget = Gadgets.Find(c => c.InventoryNumber == loan.GadgetId);
                        if (e.Notification.Type != WebSocketClientNotificationTypeEnum.Delete)
                        {
                            Loans.Add(loan);
                        }
                    }

                    LoadModels();
                    UpdateView();

                    HideLoadingScreen();
                };

                // spawn a new background thread in which the websocket client listens to notifications from the server
                try
                {
                    var bgTask = client.ListenAsync();
                }
                catch (WebSocketException e)
                {
                    ShowErrorScreen();
                }
            }
            catch (Exception e)
            {
                _connected = false;
                StatusBarInfo.Content = $"Can't connect to {ServiceUrl} - Click here to reconnect";
                StatusBar.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x62, 0x1F));

            }
        }
 public CustomerViewModel(LibraryAdminService service, Customer customer)
 {
     _service = service;
     _customer = customer;
 }
 public ReservationViewModel(LibraryAdminService service, Reservation reservation)
 {
     _service = service;
     _reservation = reservation;
 }