// Opens the selected xml file.
        public void OpenXml(string filepath)
        {
            dp.containsInactiveProduct = false;

            XmlDocument doc = new XmlDocument();

            doc.Load(filepath);

            // Gets first child of the document.
            XmlNode roomNode = doc.DocumentElement.FirstChild;

            // Gets the information from the document.
            room = DatabaseController.GetRoomById(Int32.Parse(roomNode.ChildNodes[4].InnerText));
            //room.shape = roomNode.ChildNodes[0].InnerText;
            //room.height = Int32.Parse(roomNode.ChildNodes[1].InnerText);
            //room.width = Int32.Parse(roomNode.ChildNodes[2].InnerText);
            room.floorType = Db.DatabaseController.floorTypeList.Find(f => f.name == roomNode.ChildNodes[3].InnerText);
            dp.rDesign     = room;

            dp.rDesign.productList = new List <Product>();

            fromMainMenu = false;
            // Gets the information from all the saved products in the document.
            foreach (XmlNode node in doc.DocumentElement.ChildNodes[1].ChildNodes)
            {
                Product product = DatabaseController.productList.Find(p => p.productId == Int32.Parse(node.ChildNodes[0].InnerText)).Clone();
                if (product != null && product.active)
                {
                    product.SetLocation(Int32.Parse(node.ChildNodes[1].InnerText), Int32.Parse(node.ChildNodes[2].InnerText));
                    product.rp = new RotatePanel(product, dp);
                    product.rp.StartRotation(Int32.Parse(node.ChildNodes[3].InnerText));
                    product.rp.count = Int32.Parse(node.ChildNodes[3].InnerText);
                    dp.AddProduct(product);
                }
                // Handle inactive products, giving them a replacement image.
                else if (product != null && !product.active)
                {
                    Product inactiveProduct = product;
                    inactiveProduct.image = new Bitmap(Properties.Resources.InactiveProduct, new Size(product.image.Width, product.image.Height));
                    inactiveProduct.SetLocation(Int32.Parse(node.ChildNodes[1].InnerText), Int32.Parse(node.ChildNodes[2].InnerText));
                    inactiveProduct.rp = new RotatePanel(inactiveProduct, dp);
                    inactiveProduct.rp.StartRotation(Int32.Parse(node.ChildNodes[3].InnerText));
                    inactiveProduct.rp.count = Int32.Parse(node.ChildNodes[3].InnerText);
                    dp.AddProduct(inactiveProduct);
                    dp.containsInactiveProduct = true;
                }
            }
        }
Exemple #2
0
        public void PlaceProduct_ShouldAddProductToDesignPanel_WhenProductIsDropped()
        {
            //Arrange
            Product     p  = new Chair();
            DesignPanel dp = new DesignPanel();
            Room        r  = new Room();

            dp.rDesign             = r;
            dp.rDesign.productList = new List <Product>();

            //Act
            dp.AddProduct(p);
            int expected = 1;

            //Assert
            Assert.AreEqual(expected, dp.rDesign.productList.Count);
        }
Exemple #3
0
        public void DeleteProduct_ShouldDeleteProductFromDesignPanel_WhenDeleteButtonIsClicked()
        {
            //Arrange
            Product     p  = new Chair();
            DesignPanel dp = new DesignPanel();
            Room        r  = new Room();

            dp.rDesign             = r;
            dp.rDesign.productList = new List <Product>();
            dp.AddProduct(p);

            //Act
            dp.DeleteProduct(p);
            int expected = 0;

            //Assert
            Assert.AreEqual(expected, dp.rDesign.productList.Count);
        }
        // When left mousebutton is released:
        // Clone product and give it the current location. Then add it to the productlist.
        public void PlaceProduct()
        {
            if (dp != null)
            {
                if (dp.gPath.IsVisible(Cursor.Position))
                {
                    Product added = p.Clone();
                    added.productId = p.productId;

                    added.rp = new RotatePanel(added, dp);
                    added.rp.StartRotation(0);

                    int halfScaledWidth  = (int)(added.rp.bmWidth / dp.scale / 2);
                    int halfScaledHeight = (int)(added.rp.bmHeight / dp.scale / 2);

                    // 24 is the height in px of the tasbar at the top of the program.
                    added.SetLocation(Cursor.Position.X - halfScaledWidth, Cursor.Position.Y - halfScaledHeight - 24);

                    added.image = new Bitmap(added.image, new Size(added.image.Width, added.image.Height));
                    dp.AddProduct(added);
                    dp.Invalidate();
                }
            }
        }