Пример #1
0
        //Return a list of snacks from the database
        public List <Snack> GetAllSnacks()
        {
            string       sql       = "SELECT * FROM Product WHERE IsItSnack = \"1\";";
            MySqlCommand command   = new MySqlCommand(sql, MySqlconnection);
            List <Snack> snackList = new List <Snack>();

            try
            {
                MySqlconnection.Open();
                MySqlDataReader reader = command.ExecuteReader();
                Snack           snack;

                int    productId;
                String name;
                int    quantity;
                double price;
                bool   isItSnack;
                string pathstring;
                while (reader.Read())
                {
                    productId = Convert.ToInt32(reader[0]);
                    name      = Convert.ToString(reader[1]);
                    //quantity = Convert.ToInt32(reader[2]);
                    price      = Convert.ToDouble(reader[3]);
                    isItSnack  = Convert.ToBoolean(reader[4]);
                    pathstring = Convert.ToString(reader[5]);
                    snack      = new Snack(productId, name, price);

                    snackList.Add(snack);
                }
            }
            catch (MySqlException e)
            {
            }
            finally
            {
                MySqlconnection.Close();
            }
            return(snackList);
        }
Пример #2
0
        private void onClick(object sender, EventArgs e)
        {
            quanTextbox = Convert.ToInt16(numericUpDown1.Value);
            String name  = ((MyButton)sender).Text;
            double price = ((MyButton)sender).Price;
            int    id    = ((MyButton)sender).ProductId1;



            //  listBox1.Items.Add(snack.ToString());

            if (tabControl1.SelectedTab == tabPage1)
            {
                Snack     snack     = new Snack(id, name, price);
                OrderLine orderLine = new OrderLine(holder1, quanTextbox, snack);
                order.AddOrderLine(orderLine);
                listBox1.Items.Add(orderLine.AsString());
                double p = 0;
                foreach (OrderLine item in order.getAllOrderLines())
                {
                    p += item.Price * item.Quantity;
                }
                lbTotal.Text = "Total: € " + p;
            }
            else if (tabControl1.SelectedTab == tabPage2)
            {
                Drink     drink     = new Drink(id, name, price);
                OrderLine orderLine = new OrderLine(drink.Name, quanTextbox, drink);
                order.AddOrderLine(orderLine);
                listBox1.Items.Add(orderLine.AsString());
                double p = 0;
                foreach (OrderLine item in order.getAllOrderLines())
                {
                    p += item.Price * item.Quantity;
                }
                lbTotal.Text = "Total: € " + p;
            }
        }