コード例 #1
0
 private void buttonBack_Click(object sender, EventArgs e)
 {
     this.configpage.Show();
     this.cupboard = null; //Tentative de correction de bug quand on back
     this.Close();
     //this.Hide();
 }
 private void MkOrdrBtn_Click(object sender, EventArgs e)
 {
     if (height[0] != 0)
     {
         if (this.cupboard1 != null)
         {
             for(int x = 0; x < 7; x++)
             {
                 cupboard1.RemoveBlock(x);
             }
             this.cupboard1 = null;//Tentative de correction de bug quand on back
             this.configpage = null;//Tentative de correction de bug quand on back
             System.GC.Collect();//Tentative de correction de bug quand on back
             System.GC.WaitForPendingFinalizers(); 
         }
         cupboard1 = new Cupboard(depth, width, angleColor, Number());
         //Door();
         for (int i = 0; i < Number(); i++)
         {
             Console.WriteLine(String.Format("height of box {0} is {1}", i, height[i]));
             cupboard1.AddBlock(new Box(height[i], panelsColor[i], cupboard1, door[i]));//hasdoor[i], doorcolor[i]
         }
         cupboard1.AddAngles(stock);
         Console.WriteLine("\n cupboard built");
         configpage = new ConfirmOrderPage(this, cupboard1);
         configpage.Show();
         this.Hide();
     }
     else
     {
         MessageBox.Show("You have not set up the cupboard");
     }
 }
コード例 #3
0
 /*Builder*/
 public Box(int height, string pannelsColor, Cupboard cupboard, string door)
 {
     this.height       = height;
     this.pannelsColor = pannelsColor;
     this.hasdoor      = (door == "No door") ? false : true;
     this.doorcolor    = ((door == "No door") || (door == "Glass")) ? null : door;
     this.typedoor     = (door == "Glass") ? "GlassDoor" : "ClassicDoor";
     this.Cupboard     = cupboard.GetDescription();
     this.depth        = Convert.ToInt32(Cupboard["depth"]);
     this.width        = Convert.ToInt32(Cupboard["width"]);
     this.stock        = new Stock("Server=localhost;Port=3306;Database=mykitbox;Uid=root;Pwd=; Connect Timeout=60");
     BuildParts();
     ComputePrice();
 }
コード例 #4
0
        /*****************************************************************************
        * Pre : - Receives a cupboard as a parameter                                *
        *       - Database server is on                                             *
        * Post : Calls OrderPart for each par of the cupboard                       *
        *****************************************************************************/
        public Dictionary <string, int> MakeOrder(Cupboard cupboard)
        {
            /*Maximum number of arts in a cupboard is (7 boxes * 15 parts) + 4 angles = 109*/
            Dictionary <string, int> quantities = new Dictionary <string, int>();

            for (int b = 0; b < cupboard.GetBlock().Length; b++)
            {
                Block block = cupboard.GetBlock()[b];
                for (int p = 0; p < block.GetParts().Length; p++)
                {
                    Part part = block.GetParts()[p];
                    if (part != null)
                    {
                        string code = part.GetDescription()["code"].ToString();
                        /*Part is counted as ordered*/
                        OrderPart(part);
                        if (quantities.ContainsKey(code))
                        {
                            quantities[code] += 1;
                        }
                        else
                        {
                            quantities.Add(code, 1);
                        }
                    }
                }
            }
            Angle[] angles = cupboard.GetAngles();
            if (angles.Length == 4)
            {
                quantities.Add(angles[0].GetDescription()["code"].ToString(), 4);
            }
            else
            {
                Console.WriteLine("There are not 4 angles in the cupboard, there must have been an issue with addAngles function.");
            }
            return(quantities);
        }
コード例 #5
0
 public ConfirmOrderPage(ConfigurationPage configpage, Cupboard cup)
 {
     this.configpage = configpage;
     this.cupboard   = cup as Cupboard;
     InitializeComponent();
 }
コード例 #6
0
        /*****************************************************************************
        * Pre : - Receives order's infos as parameters                              *
        *       - Database server is on                                             *
        * Post : - Calls make order for the cupboard                                *
        *        - Creates the order in the database                                *
        *        - Creates the client if he does not exist in the database yet      *
        *****************************************************************************/
        public void ConfirmOrder(string clientFirstName, string clientLastName, string adress, string zip, string phoneNumber, Cupboard cupboard)
        {
            /*First handles the order's identifiers (idcom and idclient)*/
            int idCom = 0;

            Connect();
            this.command.CommandText = "SELECT MAX(idcom) FROM client_partscommand";
            try {
                string stepIDCom = command.ExecuteScalar().ToString();
                Console.WriteLine("Command ID is :");
                Console.WriteLine(stepIDCom);
                /* Command ID*/
                idCom = Int32.Parse(stepIDCom) + 1;
            }
            /*Means that there is no command yet in database*/
            catch (FormatException ex) {
                idCom = 1;
                Console.WriteLine("no command in the database yet.");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            connection.Close();
            string idClient = FindClient(clientFirstName, clientLastName);

            /*If the client was not found in the database, that means he has to be created*/
            if (idClient == "")
            {
                Connect();
                command.CommandText = "SELECT MAX(idclient) FROM client";
                try {
                    idClient = ((int)command.ExecuteScalar() + 1).ToString();
                }
                catch (InvalidCastException) {
                    idClient = "1";
                    Console.WriteLine("No client in the database yet.");
                }
                connection.Close();
                Connect();
                command.CommandText = String.Format("INSERT INTO client(idclient, firstname, lastname, adress, zip, phonenumber) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}');", idClient, clientFirstName, clientLastName, adress, zip, phoneNumber);
                command.ExecuteNonQuery();
                connection.Close();
            }
            //Orders the parts
            Dictionary <string, int> parts = MakeOrder(cupboard);

            Connect();
            command.CommandText = String.Format("INSERT INTO client_command(idcom, idclient, description) VALUES ('{0}', '{1}', '{2}');", idCom, idClient, cupboard.GetDescription().ToString());
            foreach (string code in parts.Keys)
            {
                command.CommandText += String.Format("INSERT INTO client_partscommand VALUES ('{0}', '{1}', '{2}');", idCom, code, parts[code]);
                command.CommandText += String.Format("UPDATE part SET real_quantity= real_quantity-{0} WHERE code='{1}';", parts[code], code);
            }
            command.ExecuteNonQuery();
            connection.Close();
        }