Beispiel #1
0
        /// <summary>
        /// Looks for information about a client in the database
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        private void button21_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBox9.Text))
            {
                panel4.Visible = false;
            }
            else
            {
                if (int.TryParse(textBox9.Text, out int id) && DbConnect.searchClient(id) != null)
                {
                    string testbox = textBox9.Text;
                    Person client  = DbConnect.searchClient(Convert.ToInt32(textBox9.Text));

                    string clientFname = client.FirstName;
                    string clientLName = client.LastName;

                    Order test = new Order();
                    test.CurrentClient = client;
                    client.Id          = Convert.ToInt32(textBox9.Text);
                    test.CurrentClient = client;

                    Dictionary <string, object> dictBill;
                    dictBill = test.GetBill(1);             // Replace 1 by Order_Id

                    // The dictionary components contains the wardrobes
                    Dictionary <string, Dictionary <string, List <object> > > components = (Dictionary <string, Dictionary <string, List <object> > >)dictBill["Components"];

                    // Number of Wardrobes
                    int nbrWardRobes = components.Count();


                    /********************************** Prices of Wardrobes*********************************/
                    List <double> prices = new List <double>();
                    Dictionary <string, Dictionary <string, List <string> > > wardrobe_components_list = new Dictionary <string, Dictionary <string, List <string> > >();

                    int wardrobe_id    = 0;
                    int nbr_components = 0;
                    foreach (KeyValuePair <string, Dictionary <string, List <object> > > kvp1 in components)
                    {
                        prices.Add(0);
                        foreach (KeyValuePair <string, List <object> > kvp2 in kvp1.Value)
                        {
                            prices[wardrobe_id] += Convert.ToDouble(kvp2.Value[0]) * Convert.ToDouble(kvp2.Value[1]);
                        }
                        wardrobe_id++;
                    }


                    /*Code - Reference - Quantiy of Components of Wardrobes*/
                    foreach (KeyValuePair <string, Dictionary <string, List <object> > > kvp5 in components)
                    {
                        foreach (KeyValuePair <string, List <object> > kvp4 in kvp5.Value)
                        {
                            nbr_components += 1;
                        }
                    }

                    List <List <object> > orders = test.GetOrder(Convert.ToInt32(textBox9.Text));
                    int OrderNum = orders.Count();

                    // List of Wardrobes' name
                    List <string> listWardName = new List <string>();
                    foreach (string codeComp in components.Keys)
                    {
                        listWardName.Add(codeComp);
                    }

                    label36.Text       = clientFname + " " + clientLName;
                    clientIDValue.Text = textBox9.Text;

                    List <object> orders_numb = new List <object>();
                    // Row generation and Auto completion of the result Table from the client's search
                    for (int i = 0; i < OrderNum; i++)
                    {
                        tableLayoutPanel1.RowCount = i + 1;
                        tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F));

                        //Num order
                        Label NumCom = new Label();
                        NumCom.Text = Convert.ToString(orders[i][0]);
                        tableLayoutPanel1.Controls.Add(NumCom, 0, i + 1);
                        orders_numb.Add(orders[i][0].ToString());

                        // Date order
                        Label Date = new Label();
                        Date.Text = Convert.ToString(orders[i][1]);
                        tableLayoutPanel1.Controls.Add(Date, 1, i + 1);
                    }

                    boxBill.Items.AddRange(orders_numb.ToArray());
                    boxLComp.Items.AddRange(orders_numb.ToArray());


                    /*Code - Reference - Quantiy of Components of Wardrobes*/
                    List <List <object> > ward_specs = new List <List <object> >();
                    int current_ward = 0;
                    foreach (KeyValuePair <string, Dictionary <string, List <object> > > kvp5 in components)
                    {
                        current_ward++;

                        foreach (KeyValuePair <string, List <object> > kvp4 in kvp5.Value)
                        {
                            nbr_components += 1;
                        }
                    }

                    // Number of Rows of List of Components' Table
                    tableLayoutPanel3.RowCount = components["Wardrobe1"].Count();
                    int count = 0;
                    foreach (KeyValuePair <string, Dictionary <string, List <object> > > kvp5 in components)
                    {
                        // Wardrobe name
                        //Code empty
                        Label col1 = new Label();
                        col1.Text = "";
                        tableLayoutPanel3.Controls.Add(col1, 0, count + 1);

                        //Reference
                        Label col2 = new Label();
                        col2.Text = kvp5.Key;
                        tableLayoutPanel3.Controls.Add(col2, 1, count + 1);

                        //Quantity empty
                        Label col3 = new Label();
                        col3.Text = "";
                        tableLayoutPanel3.Controls.Add(col3, 2, count + 1);



                        foreach (KeyValuePair <string, List <object> > kvp4 in kvp5.Value)
                        {
                            count++;

                            //Code
                            Label Code = new Label();
                            Code.Text = kvp4.Key;
                            tableLayoutPanel3.Controls.Add(Code, 0, count + 1);

                            //Reference
                            Label Reference = new Label();
                            Reference.Text = kvp4.Value[2].ToString();
                            tableLayoutPanel3.Controls.Add(Reference, 1, count + 1);

                            //Quantity
                            Label Quantity = new Label();
                            Quantity.Text = kvp4.Value[0].ToString();
                            tableLayoutPanel3.Controls.Add(Quantity, 2, count + 1);
                        }

                        count++;
                    }


                    double total_price = 0;

                    // Number of Rows for  Bill's Table
                    tableLayoutPanel2.RowCount = nbrWardRobes + 1;

                    textHeader.Text = test.GetBill(1)["Header"].ToString();
                    textFooter.Text = test.GetBill(1)["Footer"].ToString();
                    totPrice.Text   = total_price.ToString();

                    panel4.Visible = true;
                }
                else
                {
                    ;
                }
            }
        }