public void rotation_setAngle_90()
        {
            //Make
            PointF point = new PointF(200, 200);
            ProductModel product = new ProductModel(10, 10, 50);
            PlacedProduct placedP = new PlacedProduct(product, point);

            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X + product.Width / 2, point.Y - product.Length / 2); //now the top right
            pointCorner[1] = new PointF(point.X + product.Width / 2, point.Y + product.Length / 2); //now the lower right
            pointCorner[2] = new PointF(point.X - product.Width / 2, point.Y + product.Length / 2); //now the lower left
            pointCorner[3] = new PointF(point.X - product.Width / 2, point.Y - product.Length / 2); //now the top left


            //Do
            placedP.SetAngle(90);



            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product has changed!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product has changed!");

            for (int index = 0; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }
 //creates a product where a table and chair are combined.
 public static ChairTablePair CreatePair(ProductModel chair, ProductModel table, float margin) {
     ChairTablePair pair = new ChairTablePair();
     pair.Chair = chair;
     pair.Table = table;
     pair.Representation = DetermineSize(pair, margin);
     return pair;
 }
 public RemoveProductController(RemoveProductScreen screen, ProductModel product)
 {
     _dbc = DatabaseController.Instance;
     this._screen = screen;
     this._product = product;
     screen.productNameLabel.Text = product.Name;
 }
        public void ShouldThrowExceptionWhenRoomIsTooSmall() {
            IDesignAlgorithm algorithm = new TestSetupDesign();
            ProductModel chair = new ProductModel {
                Brand = "Ahrend",
                Width = 1,
                Height = 1
            };
            ProductModel table = new ProductModel {
                Brand = "TableCompany",
                Width = 2,
                Height = 1
            };

            int width = 10;
            int height = 10;
            int people = 10;
            float margin = 0.5f;

            try {
                List<ProductModel> result = algorithm.Design(chair, table, people, width, height, margin);
            }
            catch (RoomTooSmallException e) {
                throw;
            }
        }
        public void PairShouldBeCorrectSize() {
            TestSetupDesign algo = new TestSetupDesign();
            ProductModel chair = new ProductModel {
                Brand = "Ahrend",
                Width = 1,
                Height = 1
            };
            ProductModel table = new ProductModel {
                Brand = "TableCompany",
                Width = 2,
                Height = 1
            };
            float margin = 0.5f;
            int expectedWidth = (int) (chair.Height + table.Height + margin*2);
            int expectedHeight = (int) (table.Width + margin*2);

            int width = 10;
            int height = 10;
            ChairTablePair pair = ChairTablePair.CreatePair(chair, table, 0.5f);
            List<Rectangle> possibilities = algo.CalculatePossibilities(pair, width, height, 0.5f);
            List<ChairTablePair> designResult = algo.FillRoom(7, pair, possibilities);
            ChairTablePair teacher = designResult[0];
            Rectangle teacherRectangle = teacher.Representation;
            int actualWidth = teacherRectangle.Width;
            int actualHeight = teacherRectangle.Height;
            Assert.IsTrue(actualHeight == expectedHeight && actualWidth == expectedWidth);
        }
 public InventoryEditController(InventoryEdit screen, ProductModel product, InventoryScreen inventoryScreen)
 {
     _dbc = DatabaseController.Instance;
     this._product = product;
     this._screen = screen;
     this._inventoryScreen = inventoryScreen;
     FillWithProductInfo();
 }
        public List<ProductModel> Design(ProductModel chair, ProductModel table,
            int people, float width, float height, float margin)
        {
            ChairTablePair pair = ChairTablePair.CreatePair(chair, table, margin);
            List<Rectangle> possibilities = CalculatePossibilities(pair, width, height, margin);
            List<ChairTablePair> result = FillRoom(people, pair, possibilities);
            List<ProductModel> finalResult = CreateModelList(result, margin);

            return finalResult;
        }
 public EditProductController(EditProductScreen screen, ProductModel productModel)
 {
     this._screen = screen;
     _dbc = DatabaseController.Instance;
     this._productModel = productModel;
     _currentImagePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                         @"\Kantoor Inrichting\Afbeeldingen producten\" + productModel.ImageFileName;
     _isNewImage = false;
     FillComboBox();
     FillTextBoxes();
 }
 public EditProductController(EditProductScreen screen, ProductModel productModel)
 {
     this._screen = screen;
     _dbc = DatabaseController.Instance;
     this._productModel = productModel;
     _currentImagePath = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())) +
                        @"\Resources\" + productModel.ImageFileName;
     _isNewImage = false;
     FillComboBox();
     FillTextBoxes();
 }
        public void rotation_setAngle_45()
        {
            //Make
            PointF point = new PointF(200, 200);
            ProductModel product = new ProductModel(10, 10, 50);
            PlacedProduct placedP = new PlacedProduct(product, point);

            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X, point.Y - (float)Math.Sqrt(50));    //{200 ; 200-√50}
            pointCorner[1] = new PointF(point.X + (float)Math.Sqrt(50), point.Y);                           //{200+√50 ; 200}
            pointCorner[2] = new PointF(point.X, point.Y + (float)Math.Sqrt(50));    //{200 ; 200+√50}
            pointCorner[3] = new PointF(point.X - (float)Math.Sqrt(50), point.Y);                           //{200-√50 ; 200}

            /*
                Coordinate = {(centerlocation) (direction + or -) (size/2)}

                Point 0 = Top Left
                {200-(10/2) ; 200-(10/2)} = {195 ; 195}

                Point 1 = Top Right
                {200+(10/2) ; 200-(10/2)} = {205 ; 195}

                Point 2 = Lower Right
                {200+(10/2) ; 200+(10/2)} = {205 ; 205}

                Point 3 = Lower Left
                {200-(10/2) ; 200+(10/2)} = {195 ; 205}


                Do some math, and when the square turns 45 degrees, the points are the following:

                [0] = {200 ; 200-√50}
                [1] = {200+√50 ; 200}
                [2] = {200 ; 200+√50}
                [3] = {200-√50 ; 200}
            */



            //Do
            placedP.SetAngle(45);



            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product has changed!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product has changed!");

            for (int index = 0; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }
        public void collision_MoveCollision()
        {
            //Move -> Collision

            //Move X+50, Y+0
            //Move X+50, Y+0 - can't move all the way because collision, so only X+30

            //Make
            PointF point = new PointF(200, 200); //Right end = 350 (200+150)
            PointF pointWall = new PointF(440, 200); //Left end = 430 (440-10)

            ProductModel product = new ProductModel(100, 300, 50); //Width = 300, so it's 150 + 150
            ProductModel productWall = new ProductModel(20, 20, 50); //Width = 20, so it's 10 + 10
            

            PlacedProduct placedP = new PlacedProduct(product, point);
            PlacedProduct placedWall = new PlacedProduct(productWall, pointWall);

            PlacementController.placedProductList.Add(placedP);
            PlacementController.placedProductList.Add(placedWall);

            int move_x = 60;
            int move_y = 0; 

            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X - (product.Width / 2) + move_x, point.Y - (product.Length / 2) + move_y);   //{205 ; 195}
            pointCorner[1] = new PointF(point.X + (product.Width / 2) + move_x, point.Y - (product.Length / 2) + move_y);   //{215 ; 195}
            pointCorner[2] = new PointF(point.X + (product.Width / 2) + move_x, point.Y + (product.Length / 2) + move_y);   //{215 ; 205}
            pointCorner[3] = new PointF(point.X - (product.Width / 2) + move_x, point.Y + (product.Length / 2) + move_y);   //{205 ; 205}




            //Do
            placedP.GridSpace = 50; //Set grid (movement speed) to 50.
            placedP.Move(true); //{250;200}
            placedP.Move(true); //{300;200}Cant perform this.
            placedP.GridSpace = 10;
            placedP.Move(true); //{260;200} Now it can, because the grid was changed, and that allowed it to move 'slower'
            point.X += move_x;
            point.Y += move_y;


            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product is different!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product is different!");

            for (int index = 0; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }
 public void ShouldCreateAPairOfProducts() {
     ProductModel chair = new ProductModel {
         Brand = "Ahrend",
         Width = 1,
         Height = 1
     };
     ProductModel table = new ProductModel {
         Brand = "TableCompany",
         Width = 2,
         Height = 1
     };
     Assert.IsInstanceOfType(ChairTablePair.CreatePair(chair, table, 1), typeof (ChairTablePair));
 }
        public void AddItem_Test() {
            GridFieldModel grid = new GridFieldModel(10, 10, 0.5f);
            //ProductModel i1 = new ProductModel("Chair 1", "Atlas", "Chair", "Chair", "Deskchair", 2, 2, 2, "een stoel", 1);
            ProductModel i1 = new ProductModel(2, 2, 2);

            int x = 5; // x and y have to be the tilenumber that the user wants to add an item to.
            int y = 5; //

            grid.AddItem(5, 2, i1);

            bool found = false;
            for (int i = 0; i < grid.Rows.GetLength(0); i++)
                for (int j = 0; j < grid.Rows.GetLength(1); j++) if (grid[i, j].Product == i1) found = true;
            Assert.IsTrue(found);
        }
        //all products are collected from the database
        public void GetProducts_FromDatabase()
        {
            foreach (var product in this.DataSet.product)
            {
                var countPlacedProduct = DataSet.placement
                           .Where(c => c.product_id == product.product_id)
                           .Select(c => c)
                           .ToList();

                var p1 = new ProductModel(product.product_id, product.name, product.brand, product.type,
                    product.category_id, product.length, product.width, product.height, product.description,
                    product.amount, product.image, product.removed, product.price, countPlacedProduct.Count);
                //checkAmountPlaced(p1);
            }

        }
        public void ShouldCalculateAllPossibilitiesInRoom_WithHorizontalOrientation() {
            TestSetupDesign algo = new TestSetupDesign();
            ProductModel chair = new ProductModel {
                Brand = "Ahrend",
                Width = 1,
                Height = 1
            };
            ProductModel table = new ProductModel {
                Brand = "TableCompany",
                Width = 2,
                Height = 1
            };
            ChairTablePair pair = ChairTablePair.CreatePair(chair, table, 0.5f);
            List<Rectangle> result = algo.CalculatePossibilities(pair, 10, 10, 0.5f);

            Assert.IsTrue(result.Count > 1);
        }
        public void setProduct(ProductModel p)
        {
            product = p;
            txt_Name.Text = product.Name;
            txt_Dimension.Text = product.Length.ToString() + " x " + product.Width.ToString() + " x " + product.Height.ToString();
            pbx_Image.Image = product.Image;

            if (!p.StaticProduct) //If it is a Non-Static Product, add extra information.
            {
                int count = dbc.CountProductsAmountPlaced(product);
                
                txt_Brand.Text = product.Brand;
                txt_Type.Text = product.Type;
                txt_Stock.Text = product.Amount.ToString() + " (" + count + " in gebruik )";
                CurrentlyPlaced.Text = ProductGridController.PlacementCount(product).ToString();   
            }
            
        }
        /// <summary>
        /// Make a product to be placed on the map with a custom angle.
        /// </summary>
        /// <param name="product">Give a product that will be presented.</param>
        /// <param name="center">The center location of the item.</param>
        /// <param name="angle">Give the product a set angle to take.</param>
        public PlacedProduct(ProductModel product, PointF center, int angle)
        {
            //Core variables
            this.Product = product;
            Location = center;
            this.ProductID = Product.ProductId;

            //static or not
            StaticProductBoolean = product.StaticProduct;
            ToList();

            //angle
            CurrentAngle = angle;

            //space
            //this.SpaceID = space;

            //Corner and image
            CornerPoints = new PointF[5];
            ResetImage();
        }
        public void ShouldReturnListOfProducts() {
            IDesignAlgorithm algorithm = new TestSetupDesign();
            ProductModel chair = new ProductModel {
                Brand = "Ahrend",
                Width = 1,
                Height = 1
            };
            ProductModel table = new ProductModel {
                Brand = "TableCompany",
                Width = 2,
                Height = 1
            };

            int width = 10;
            int height = 10;
            int people = 7;
            float margin = 0.5f;

            List<ProductModel> result = algorithm.Design(chair, table, people, width, height, margin);

            Assert.IsTrue(result.Count > 0);
            Assert.IsTrue(result.Count == (people*2));
        }
        public void move_SingleMoveVertical()
        {
            //Move X+0, Y+10

            //Make
            PointF point = new PointF(200, 200);
            ProductModel product = new ProductModel(10, 10, 50);
            PlacedProduct placedP = new PlacedProduct(product, point);

            int move_x = 0;
            int move_y = 10;

            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X - (product.Width / 2) + move_x, point.Y - (product.Length / 2) + move_y);   //{195 ; 205}
            pointCorner[1] = new PointF(point.X + (product.Width / 2) + move_x, point.Y - (product.Length / 2) + move_y);   //{205 ; 205}
            pointCorner[2] = new PointF(point.X + (product.Width / 2) + move_x, point.Y + (product.Length / 2) + move_y);   //{205 ; 215}
            pointCorner[3] = new PointF(point.X - (product.Width / 2) + move_x, point.Y + (product.Length / 2) + move_y);   //{195 ; 215}




            //Do
            placedP.GridSpace = 10;
            placedP.Move(false);
            point.X += move_x;
            point.Y += move_y;


            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product is different!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product is different!");

            for (int index = 0; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }
 public ProductInfo(ProductModel model) : this()
 {   
     setProduct(model);
 }
        //Add a new product to the database
        private void AddProductToDatabase()
        {
            //Create a newProductrow and fill the row for each corresponding column
            var newProduct = _dbc.DataSet.product.NewproductRow();
            newProduct.name = _productModel.Name;
            newProduct.product_id = _productModel.ProductId;
            newProduct.removed = false;
            newProduct.type = _productModel.Type;
            newProduct.brand = _productModel.Brand;
            newProduct.height = _productModel.Height;
            newProduct.width = _productModel.Width;
            newProduct.length = _productModel.Length;
            newProduct.amount = _productModel.Amount;
            newProduct.image = _productModel.ImageFileName;
            newProduct.category_id = _productModel.ProductCategory.CatId;
            newProduct.description = _productModel.Description;
            newProduct.price = _productModel.Price;

            //Try to add the new product row in the database
            try
            {
                _dbc.DataSet.product.Rows.Add(newProduct);
                _dbc.ProductTableAdapter.Update(_dbc.DataSet.product);
                MessageBox.Show("Update successful");
            }
            //If it fails remove the newly placed image from the resource folder
            catch (Exception ex)
            {
                MessageBox.Show("Update failed" + ex);
                RemoveImage();
                this._productModel = null;
            }
        }
        //Create a new product
        private void CreateProductModel()
        {
            //Fill the TableAdapter with data from the dataset, select MAX Product_ID, Create an int with MAX Product_ID + 1
            var maxProductId = _dbc.DataSet.product.Select("Product_ID = MAX(Product_ID)");
            var newProductId = (int)maxProductId[0]["Product_ID"] + 1;

            var product = new ProductModel(newProductId, _name, _brand, _type, _categoryId, _length, _width, _height,
                _description, _amount, _newImageFileName, false, _price, 0);
            this._productModel = product;
        }
 /// <summary>
 /// This is a helper method for the CreateModelList method, so that I don't have to assign PointF objects there.
 /// </summary>
 /// <param name="p"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public void SetLocation(ProductModel p, float x, float y)
 {
     PointF point = new PointF(x, y); // using a PointF instead of a Point to increase accuracy.
     p.Location = point;
 }
        public int CountProductsAmountPlaced(ProductModel product)
        {
            // get the amount of placed products from dataset
            var countPlacedProduct = DataSet.placement
                           .Where(c => c.product_id == product.ProductId)
                           .Select(c => c)
                           .ToList();

            // give the current product the new count
            product.AmountPlaced = countPlacedProduct.Count;
            return countPlacedProduct.Count;
        }
 //all static products are collected from the database WILL NEED TO BE ENABLED
 public void GetStaticProducts_FromDatabase()
 {
     foreach (var product in this.DataSet.static_product)
     {
         var sp1 = new ProductModel(product.product_id, product.name, product.description, product.width,
             product.height, product.length, true);
     }
 }
 public static int PlacementCount(ProductModel model)
 {
     int count = 0;
     foreach (PlacedProduct placedproduct in placedProductList)
     {
         if (placedproduct.Product.ProductId == model.ProductId)
         {
             count++;
         }
             
     }
     return count;
 }
        public void rotation_addAngle_45()
        {
            //Make
            PointF point = new PointF(200, 200);
            ProductModel product = new ProductModel(10, 10, 50);
            PlacedProduct placedP = new PlacedProduct(product, point);

            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X, point.Y - (float)Math.Sqrt(50));    //{200 ; 200-√50}
            pointCorner[1] = new PointF(point.X + (float)Math.Sqrt(50), point.Y);                           //{200+√50 ; 200}
            pointCorner[2] = new PointF(point.X, point.Y + (float)Math.Sqrt(50));    //{200 ; 200+√50}
            pointCorner[3] = new PointF(point.X - (float)Math.Sqrt(50), point.Y);                           //{200-√50 ; 200}
            

            //Do
            placedP.AddAngle(25);
            placedP.AddAngle(20);



            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product has changed!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product has changed!");

            for (int index = 0; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }
 public RemoveProductScreen(ProductModel product)
 {
     InitializeComponent();
     _controller = new RemoveProductController(this, product);
 }
        public void collision_RotateCollision()
        {
            //Rotate -> Collision

            //Rotate 15
            //Rotate 15
            //Rotate 15
            //Rotate 15 -can't do this because collision

            //Make
            PointF point = new PointF(400, 200);
            PointF pointWall = new PointF(400, 50);

            ProductModel product = new ProductModel(100, 300, 50);
            ProductModel productWall = new ProductModel(100, 50, 50);

            PlacedProduct placedP = new PlacedProduct(product, point);
            PlacedProduct placedWall = new PlacedProduct(productWall, pointWall);

            PlacementController.placedProductList.Add(placedP);
            PlacementController.placedProductList.Add(placedWall);
            

            double radius = Math.Sqrt(Math.Pow(product.Width/2, 2) + Math.Pow(product.Length/2, 2));
            double initialAngle = (Math.Atan((0.5 * product.Length) / (0.5 * product.Width)) * 180 / Math.PI);
            
            double angle_Even = 45 + initialAngle;
            double angle_Uneven = 45 - initialAngle;            

            float Cos_Even = (float)(Math.Cos(angle_Even * Math.PI / 180) * radius);
            float Sin_Even = (float)(Math.Sin(angle_Even * Math.PI / 180) * radius);

            float Cos_Uneven = (float)(Math.Cos(angle_Uneven * Math.PI / 180) * radius);
            float Sin_Uneven = (float)(Math.Sin(angle_Uneven * Math.PI / 180) * radius);


            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X - Cos_Even, point.Y - Sin_Even);   //{205 ; 195}
            pointCorner[1] = new PointF(point.X + Cos_Uneven, point.Y + Sin_Uneven);   //{215 ; 195}
            pointCorner[2] = new PointF(point.X + Cos_Even, point.Y + Sin_Even);   //{215 ; 205}
            pointCorner[3] = new PointF(point.X - Cos_Uneven, point.Y - Sin_Uneven);   //{205 ; 205}



            //Do
            placedP.AddAngle(15); //after this it's 15
            placedP.AddAngle(15); //after this it's 30
            placedP.AddAngle(15); //after this it's 45
            placedP.AddAngle(15); //after this it's 60 -Can't perform this because of the collision.
            placedP.AddAngle(15); //after this it's 75 -Can't perform this.
            placedP.AddAngle(15); //after this it's 90 -Can't perform this.


            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product is different!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product is different!");

            for (int index = 1; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }
 public void Createproduct_Test()
 {
     ProductModel p = new ProductModel();
     Assert.IsNotNull(p);
 }