Exemplo n.º 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            //assign currentLocker
            if (ShoppingCart.currentLocker == 0)
            {
                ShoppingCart.currentLocker = ShoppingCart.cupboardComponentsList.Count;
            }

            //get former and cupboard values
            int    width         = ShoppingCart.getLockerByID(ShoppingCart.currentLocker).width;
            int    formerHeight  = Int32.Parse(dataGridView1[1, ShoppingCart.currentLocker - 1].Value.ToString());
            int    totalHeight   = Int32.Parse(textBox12.Text);
            int    maxHeight     = Int32.Parse(textBox14.Text);
            double formerPrice   = Double.Parse(dataGridView1[5, ShoppingCart.currentLocker - 1].Value.ToString());
            double cupboardPrice = Double.Parse(textBox16.Text);

            //verify every box filled
            if (comboBox5.SelectedItem != null && comboBox6.SelectedItem != null && comboBox7.SelectedItem != null)
            {
                //get new values
                int    height     = Int32.Parse(comboBox5.SelectedItem.ToString());
                string doorsColor = comboBox6.SelectedItem.ToString();
                string panelColor = comboBox7.SelectedItem.ToString();
                bool   doorCup    = false;

                //assign doorcup
                if (doorsColor != "Glass" && doorsColor != "none")
                {
                    //TODO check if combobox9 filled
                    if (comboBox9.SelectedItem.ToString() == "yes")
                    {
                        doorCup = true;
                    }
                }

                //compute totalHeight and verify max height not reached
                if (totalHeight - formerHeight - 4 + height < maxHeight)
                {
                    //save changes
                    totalHeight   -= formerHeight;
                    totalHeight   += height;
                    textBox12.Text = totalHeight.ToString();

                    //save locker new variables
                    ShoppingCart.getLockerByID(ShoppingCart.currentLocker).height     = height;
                    ShoppingCart.getLockerByID(ShoppingCart.currentLocker).panelColor = EnumParse.parseColorStrToEnum(panelColor);
                    ShoppingCart.getLockerByID(ShoppingCart.currentLocker).setCupOfDoor(doorCup);
                    if (doorsColor != "none")
                    {
                        ShoppingCart.getLockerByID(ShoppingCart.currentLocker).doorsColor = EnumParse.parseColorStrToEnum(doorsColor);
                    }

                    /*
                     * if doorsColor were none then add new doors
                     * if doorsColor were not none then new doors not added (locker definition)
                     */
                    CatalogueDB catalogueDB = new CatalogueDB();
                    int         doorWidth   = 0;
                    if (width >= 62)
                    {
                        if (width == 62)
                        {
                            doorWidth = 31;
                        }
                        else
                        {
                            doorWidth = width / 2 + 2;
                        }
                    }
                    Door door1 = (Door)catalogueDB.createComponents(height, doorWidth, 0, EnumParse.parseColorStrToEnum(doorsColor), doorCup, "Door");
                    ShoppingCart.getLockerByID(ShoppingCart.currentLocker).addComponent(new List <CatalogueComponents>()
                    {
                        door1, door1
                    });


                    //compute newPrice
                    foreach (CatalogueComponents compo in ShoppingCart.getLockerByID(ShoppingCart.currentLocker).componentsList)
                    {
                        compo.price = catalogueDB.newPrice(height, doorsColor, panelColor, compo);
                    }
                    double newPrice = ShoppingCart.getLockerByID(ShoppingCart.currentLocker).price;

                    //display new informations
                    dataGridView1.Rows[ShoppingCart.currentLocker - 1].SetValues(ShoppingCart.currentLocker, height, doorsColor, doorCup, panelColor, newPrice);

                    //TODO mettre yes no plutôt que true false dans l'afficheur

                    //display total lockers price
                    cupboardPrice -= formerPrice;
                    cupboardPrice += newPrice;
                    textBox16.Text = cupboardPrice.ToString();
                }
                else
                {
                    MessageBox.Show("Maximal height reached");
                }
            }
            else
            {
                MessageBox.Show("Fill every choices");
            }
        }
Exemplo n.º 2
0
 public void createComponentTest1()
 {
     cleat1 = (Cleat)catalogueDB.createComponents(32, 0, 0, "Cleat");
     Assert.AreEqual(0.2, cleat1.price);
 }
Exemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            int width          = ShoppingCart.widthChosen;
            int depth          = ShoppingCart.depthChosen;
            int numberOfLocker = ShoppingCart.boxNumberChosen;

            //TODO check if cups are checked
            // check that the object fields are filled
            if (comboBox5.SelectedItem != null && comboBox6.SelectedItem != null && comboBox7.SelectedItem != null)
            {
                int    height     = Int32.Parse(comboBox5.SelectedItem.ToString());
                string doorsColor = comboBox6.SelectedItem.ToString();
                string panelColor = comboBox7.SelectedItem.ToString();
                int    doorWidth  = 0;
                bool   doorCup    = false;
                if (doorsColor != "none")
                {
                    if (width >= 62)
                    {
                        if (width == 62)
                        {
                            doorWidth = 31;
                        }
                        else
                        {
                            doorWidth = width / 2 + 2;
                        }
                    }
                    if (doorsColor != "Glass" && comboBox9.SelectedItem != null)
                    {
                        if (comboBox9.SelectedItem.ToString() == "yes")
                        {
                            doorCup = true;
                        }
                    }
                }

                Locker locker = new Locker();

                CatalogueDB cb = new CatalogueDB();

                Cleat cleat1 = (Cleat)cb.createComponents(height, 0, 0, "Cleat");
                if (doorsColor != "none")
                {
                    Door door1 = (Door)cb.createComponents(height, doorWidth, 0, EnumParse.parseColorStrToEnum(doorsColor), doorCup, "Door");
                    locker.addComponent(new List <CatalogueComponents>()
                    {
                        door1, door1
                    });
                }
                Panels panelsHL = (Panels)cb.createComponents(0, width, depth, EnumParse.parseColorStrToEnum(panelColor), PanelsType.HL, "Panel");
                Panels panelsLR = (Panels)cb.createComponents(height, 0, depth, EnumParse.parseColorStrToEnum(panelColor), PanelsType.LR, "Panel");
                Panels panelsB  = (Panels)cb.createComponents(height, width, 0, EnumParse.parseColorStrToEnum(panelColor), PanelsType.B, "Panel");

                CrossBar crossBarF  = (CrossBar)cb.createComponents(0, width, 0, CrossBarType.F, "CrossBar");
                CrossBar crossBarB  = (CrossBar)cb.createComponents(0, width, 0, CrossBarType.B, "CrossBar");
                CrossBar crossBarLR = (CrossBar)cb.createComponents(0, 0, depth, CrossBarType.LR, "CrossBar");



                // numéro du casier sur lequel on travail
                int currentbox = locker.ID;


                locker.panelColor = EnumParse.parseColorStrToEnum(panelColor);
                locker.height     = height;
                locker.depth      = depth;
                locker.width      = width;
                if (doorsColor != "none")
                {
                    locker.doorsColor = EnumParse.parseColorStrToEnum(doorsColor);
                }



                locker.addComponent(new List <CatalogueComponents>()
                {
                    cleat1, cleat1, cleat1, cleat1,
                    panelsHL, panelsHL, panelsLR, panelsLR, panelsB,
                    crossBarF, crossBarF, crossBarB, crossBarB,
                    crossBarLR, crossBarLR, crossBarLR, crossBarLR
                });

                ShoppingCart.addCupboardComponent(locker);

                //premier essai de calcul de prix
                double prixTotal = locker.price;


                // met dans le order preview
                dataGridView1.Rows.Add(currentbox, height, doorsColor, doorCup, panelColor, prixTotal.ToString());

                //TODO remplacer total height par la somme des hauteurs
                int totalHeight = Int32.Parse(textBox12.Text);
                totalHeight   += height + 4;
                textBox12.Text = totalHeight.ToString();
                if (currentbox == numberOfLocker)
                {
                    button2.Enabled = false;
                }
                else
                {
                    currentbox++;
                    textBox8.Text = currentbox.ToString();
                }

                //TODO remplacer cupboardPrice par var globale
                double cupboardPrice = Double.Parse(textBox16.Text);
                textBox16.Text = (cupboardPrice + prixTotal).ToString();

                /*
                 * height choices gestion
                 */
                int           maxHeight    = Int32.Parse(textBox14.Text);
                List <string> choiceRemove = new List <string>();
                foreach (string heightChoice in comboBox5.Items)
                {
                    int boxHeight = Int32.Parse(heightChoice);
                    if (maxHeight - boxHeight - 4 < totalHeight)
                    {
                        choiceRemove.Add(heightChoice);
                    }
                }
                foreach (string heightChoice in choiceRemove)
                {
                    comboBox5.Items.Remove(heightChoice);
                }
            }
            else
            {
                MessageBox.Show("Fill every choices");
            }
            if (!button2.Enabled)
            {
                button3.Visible = true;
                button3.Enabled = true;
                button5.Visible = true;
                button5.Enabled = true;
            }
        }