Esempio n. 1
0
        public Login GetLogin()
        {
            var login = LoginManager.Login(UsernameField.Text, PasswordField.Password);

            if (login != null)
            {
                var personId = login.PersonId;
                //Check the database to see if the person is a admin, and returns a admin object
                var admin = proxy.GetAdmin(personId);
                //Uses the admin object to login

                if (admin != null)
                {
                    //Creates a new MainWindow and shows it to the user
                    var mainWindow = new MainWindow();
                    mainWindow.Show();
                    //Closes the login form
                    Close();
                }
                else
                {
                    //If the person who logsin is not an admin, then it return this box, to say the person can't use the program
                    MessageBox.Show("Du er ikke en administrator, du har ikke lov til at bruge dette program");
                }
            }
            else
            {
                MessageBox.Show("Dit login virkede ikke, prøv igen");
            }
            return(login);
        }
Esempio n. 2
0
        /// <summary>
        /// Find an product, and then adding a new warehouse
        /// </summary>
        public void AddProductToWarehouse()
        {
            var proxy = new BestilNemtServiceClient();
            //Finds the currentuser, by using our static class
            var currentUser = LoginManager.User;
            var id          = currentUser.PersonId;
            //finds the corret admin
            var admin       = proxy.GetAdmin(id);
            var shopIdAdmin = 0;

            shopIdAdmin = admin.ShopId;
            //finds the shop through admin
            Shop getShop = proxy.GetShop(shopIdAdmin);

            if (ProductId.Text.Equals(""))
            {
                MessageBox.Show("Du har glemt at indlæse i produkt");
            }
            else
            {
                Warehouse warehouse = new Warehouse();
                var       productId = int.Parse(ProductId.Text);
                //Getting all warehouse with a shopID, and loop through it
                var warehouses = proxy.GetAllWarehousesByShopId(getShop.Id);
                foreach (var w in warehouses)
                {
                    if (w.Product.Id == productId)
                    {
                        warehouse = w;
                    }
                }

                //sets value in the textboxes
                warehouse.MinStock = int.Parse(minStock.Text);
                warehouse.Stock    = int.Parse(Stock.Text);
                warehouse.Shop     = getShop;
                warehouse.SavingId = null;
                warehouse.Product  = proxy.GetProduct(productId);
                var warehouseId = proxy.AddWarehouse(warehouse);

                //If the warehouse couldn't be created, it shows a message telling the user
                //If the warehouse is create, then the user gets a message telling it succeced
                if (warehouseId == 0)
                {
                    MessageBox.Show("Varehus findes allerede, opret et ny produkt");
                }
                else
                {
                    MessageBox.Show("Produktet er tilføjet til dit varehus");
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a saving for a product in the warehouse
        /// </summary>
        public void CreateSaving()
        {
            var proxy = new BestilNemtServiceClient();
            //gets the current admin
            var currentUser = LoginManager.User;
            var id          = currentUser.PersonId;
            //Get admin
            var admin = proxy.GetAdmin(id);
            //Finds the login shop
            var shop = proxy.GetShop(admin.ShopId);
            //Create a local saving object
            var saving = new Saving();

            //Takes the date selected and makes them a datetime, instead of strings
            var startDate = StartDate.SelectedDate;
            var endDate   = EndDate.SelectedDate;

            //Sets the datetime to the local saving
            if (startDate != null)
            {
                saving.StartDate = startDate.Value;
            }
            if (endDate != null)
            {
                saving.EndDate = endDate.Value;
            }
            //Parses the textfield string to a doube to corresponnd to the database
            saving.SavingPercent = double.Parse(SavingPercent.Text);
            //Checks if the user has loaded in a product
            if (WarehouseIdField.Text == "")
            {
                MessageBox.Show("Du mangler at indlæse fra tabellen ");
            }
            else
            {
                var warehouse = proxy.GetWarehouse(int.Parse(WarehouseIdField.Text));
                if (warehouse.SavingId != null)
                {
                    saving.Id = warehouse.SavingId.Value;
                }
                //Adding saving with a warehouse
                proxy.AddSaving(saving, warehouse);
                //Setting savingId equals to warehouseId

                //Reloading the tabel agin
                FillProductWareHouse();
                MessageBox.Show("Du har lavet en rabet på " + ProductName1.Text + " i " + shop.Name);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Fills the warehouse datatable with data
        /// </summary>
        public void FillProductWareHouse()
        {
            var proxy = new BestilNemtServiceClient();
            //Creates a empty user,
            var currentUser = LoginManager.User;

            //Sets the shopId To be 0
            //If the user is loged in, then it will get all the details of the person
            if (currentUser != null)
            {
                var id          = currentUser.PersonId;
                var admin       = proxy.GetAdmin(id);
                var shopIdAdmin = admin.ShopId;
                var dt          = proxy.GetProductWareHouse(shopIdAdmin);
                //Sets the datatable to correspond to the datatable in the GUI
                ProductWarehouse.ItemsSource = dt.DefaultView;
            }
            else
            {
                MessageBox.Show("Du er ikke logget ind, hvordan åbenede du det her vindue?");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Updates the amount on a product in a warehouse
        /// </summary>
        public void UpdateAmount()
        {
            var proxy = new BestilNemtServiceClient();
            //getting the current User
            var currentUser = LoginManager.User;
            //Finds his PersonID
            var id = currentUser.PersonId;
            //With id we find the admin, and all admin has shopID
            var admin = proxy.GetAdmin(id);

            //Checks for value input
            if (admin.Id == 0)
            {
                MessageBox.Show("Du er ikke admin for en bestemt shop");
            }
            if (ProductIdWareHouse.Text.Equals(""))
            {
                MessageBox.Show("Du har glemt at indlæs et produkt");
            }
            if (NewAmount1.Text.Equals(""))
            {
                MessageBox.Show("Du har glemt at tilføje et antal");
            }
            if (MinAmount.Text.Equals(""))
            {
                MessageBox.Show("Du mangler tilføje et minamount");
            }
            else
            {
                //var newamount = Int32.TryParse(NewAmount1.Text);
                //var minamount = Int32.TryParse(MinAmount.Text);
                if (Convert.ToInt32(NewAmount1.Text) < Convert.ToInt32(MinAmount.Text))
                {
                    MessageBox.Show("Nye Antal kan ikke være mindre min. Antal");
                }
                else
                {
                    var shopIdAdmin = admin.ShopId;
                    //we find the shop for the currentuser/admin
                    var getShop = proxy.GetShop(shopIdAdmin);
                    //Make a new instance of warehouse
                    var warehouse = new Warehouse();
                    //Get the productID
                    var productId = int.Parse(ProductIdWareHouse.Text);
                    //GetAllWarehousebyShopid() is a list, so we make a foreach loop, and find the corret warehouse =
                    //with right productID
                    var warehouses = proxy.GetAllWarehousesByShopId(getShop.Id);
                    foreach (var w in warehouses)
                    {
                        if (w.Product.Id == productId)
                        {
                            warehouse = w;
                        }
                    }
                    //sets value for textbox
                    warehouse.Stock    = int.Parse(NewAmount1.Text);
                    warehouse.MinStock = int.Parse(MinAmount.Text);
                    warehouse.Shop     = getShop;
                    //we update warehouse with a new amount
                    proxy.UpdateWarehouse(warehouse);
                    FillProductWareHouse();
                    MessageBox.Show("Dit Antal er nu blevet opdateret");
                }
            }
        }