Exemplo n.º 1
0
        public List <Orden> getOrdenes()
        {
            List <Orden>    ordenes   = new List <Orden>();
            List <Producto> productos = new List <Producto>();

            con.Open();
            coman = new NpgsqlCommand("select * from orden;", con);
            resp  = new NpgsqlDataAdapter(coman);
            DataTable tOrden = new DataTable();

            resp.Fill(tOrden);
            resp = null;
            Orden    orden;
            Pizza    pizza;
            Refresco refrescos;

            foreach (DataRow rowOrden in tOrden.Rows)
            {
                orden    = new Orden((string)rowOrden["fecha"], Convert.ToInt32(rowOrden["num_ficha"]));
                orden.ID = Convert.ToInt64(rowOrden["id"]);
                coman    = new NpgsqlCommand("select * from orden_pizzas where fk_orden=" + orden.ID + ";", con);
                resp     = new NpgsqlDataAdapter(coman);
                DataTable tOrdenPizzas = new DataTable();
                resp.Fill(tOrdenPizzas);
                foreach (DataRow rowOrPi in tOrdenPizzas.Rows)
                {
                    coman = new NpgsqlCommand("select * from pizzas where id=" + rowOrPi["fk_pizza"] + ";", con);
                    resp  = new NpgsqlDataAdapter(coman);
                    DataTable tp = new DataTable();
                    resp.Fill(tp);
                    pizza      = new Pizza((string)tp.Rows[0]["nombre"], Convert.ToDouble(tp.Rows[0]["precio"]), (string)tp.Rows[0]["ingredientes"]);
                    pizza.Size = Convert.ToChar(tp.Rows[0]["size"]);
                    orden.agregarProducto(pizza, Convert.ToInt32(rowOrPi["cantidad"]));
                }
                coman = new NpgsqlCommand("select * from orden_refrescos where fk_orden=" + orden.ID + ";", con);
                resp  = new NpgsqlDataAdapter(coman);
                DataTable tOrdenRefrescos = new DataTable();
                resp.Fill(tOrdenRefrescos);
                foreach (DataRow rowOrRe in tOrdenRefrescos.Rows)
                {
                    coman = new NpgsqlCommand("select * from refrescos where id=" + rowOrRe["fk_refrescos"] + ";", con);
                    resp  = new NpgsqlDataAdapter(coman);
                    DataTable tr = new DataTable();
                    resp.Fill(tr);
                    refrescos = new Refresco((string)tr.Rows[0]["nombre"], Convert.ToDouble(tr.Rows[0]["precio"]), Convert.ToInt32(tr.Rows[0]["litros"]));
                    orden.agregarProducto(refrescos, Convert.ToInt32(rowOrRe["cantidad"]));
                }

                if (orden.Productos.Count > 0)
                {
                    ordenes.Add(orden);
                }
            }

            con.Close();
            return(ordenes);
        }
        private void btAgregar_Click(object sender, EventArgs e)
        {
            string   opcion    = rbPizza.Checked ? "pizza":"refresco";
            string   urlImagen = "C:\\Users\\Public\\Pictures\\" + Path.GetFileName(openFileDialog1.FileName);
            Producto producto  = null;

            try
            {
                if (opcion.Equals("pizza"))
                {
                    if (validarCampos("pizza"))
                    {
                        Pizza pizza = new Pizza();
                        pizza.Nombre       = tbNombre.Text;
                        pizza.Precio       = Convert.ToDouble(tbPrecio.Text);
                        pizza.Descripcion  = tbDescripcion.Text;
                        pizza.Ingredientes = tbIngredientes.Text;
                        pizza.Size         = cbSize.Text[0];
                        pizza.UrlImagen    = urlImagen;
                        producto           = pizza;
                    }
                }
                else
                {
                    if (validarCampos("refresco"))
                    {
                        Refresco p = new Refresco();
                        p.Nombre      = tbNombre.Text;
                        p.Precio      = Convert.ToDouble(tbPrecio.Text);
                        p.Descripcion = tbDescripcion.Text;
                        p.UrlImagen   = urlImagen;
                        p.Litros      = Convert.ToInt32(tbLitros.Text);
                        producto      = p;
                    }
                }
                if (producto != null)
                {
                    FileInfo f = new FileInfo(openFileDialog1.FileName);
                    f.CopyTo(producto.UrlImagen);
                    bdPizzeria.guardarProducto(producto);
                    MessageBox.Show("Se agregó correctamente el nuevo producto. ");
                    limipiarVentana();
                }
            }
            catch (FormatException excep)
            {
                MessageBox.Show("Error: se debe de especificar en numeros.");
            }
            catch (FileNotFoundException excep)
            {
                MessageBox.Show("Debe de seleccionar una imagen");
            }
            catch (IOException exceo)
            {
                MessageBox.Show("El nombre de la imagen ya existe. Elige otro o cambia el nombre de la imagen.");
            }
        }
Exemplo n.º 3
0
        public List <Producto> getProductos()
        {
            List <Producto> productos = new List <Producto>();

            con.Open();
            coman = new NpgsqlCommand("select * from pizzas;", con);
            resp  = new NpgsqlDataAdapter(coman);
            DataTable tpizzas = new DataTable();

            resp.Fill(tpizzas);

            Pizza p;

            foreach (DataRow fila in tpizzas.Rows)
            {
                p              = new Pizza();
                p.ID           = Convert.ToInt64(fila["id"]);
                p.Nombre       = (string)fila["nombre"];
                p.Precio       = Convert.ToDouble(fila["Precio"]);
                p.Descripcion  = (string)fila["descripcion"];
                p.Ingredientes = (string)fila["ingredientes"];
                p.Size         = Convert.ToChar(fila["size"]);
                p.UrlImagen    = (string)fila["url_imagen"];
                productos.Add(p);
            }
            coman = new NpgsqlCommand("select * from refrescos;", con);
            resp  = new NpgsqlDataAdapter(coman);
            DataTable tRefrescos = new DataTable();

            resp.Fill(tRefrescos);

            Refresco r;

            foreach (DataRow fila in tRefrescos.Rows)
            {
                r             = new Refresco();
                r.ID          = Convert.ToInt64(fila["id"]);
                r.Nombre      = (string)fila["nombre"];
                r.Precio      = Convert.ToDouble(fila["Precio"]);
                r.Descripcion = (string)fila["descripcion"];
                r.UrlImagen   = (string)fila["url_imagen"];
                r.Litros      = Convert.ToInt32(fila["litros"]);
                productos.Add(r);
            }

            con.Close();
            return(productos);
        }
        private void VerOrden_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            listBox1.Visible = true;
            or = new Orden();
            pg = new Pizza();
            r  = new Refresco();

            //Pizzas Grandes
            if (Menu_Pizzas_Grande.GetItemChecked(0))
            {
                pg.Precio = 100;
                pg.Nombre = "Pepperoni";
                pg.ID     = 15;
                count     = Convert.ToInt32(numericUpDown1.Value);
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizzas_Grande.GetItemChecked(1))
            {
                pg.Precio = 100;
                pg.Nombre = "Hawaiana";
                pg.ID     = 12;
                count     = Convert.ToInt32(numericUpDown2.Value);
                indice    = count;
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizzas_Grande.GetItemChecked(2))
            {
                pg.Precio = 120;
                pg.Nombre = "Carnes Frias";
                pg.ID     = 18;
                count     = Convert.ToInt32(numericUpDown3.Value);
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizzas_Grande.GetItemChecked(3))
            {
                pg.Precio = 120;
                pg.Nombre = "Mexicana";
                pg.ID     = 21;
                count     = Convert.ToInt32(numericUpDown4.Value);
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizzas_Grande.GetItemChecked(4))
            {
                pg.Precio = 120;
                pg.Nombre = "Cuatro Quesos";
                pg.ID     = 24;
                count     = Convert.ToInt32(numericUpDown5.Value);
                or.agregarProducto(pg, count);
            }

            foreach (var s in Menu_Pizzas_Grande.CheckedItems)
            {
                listBox1.Items.Add(s);
            }

            //Pizzas Mediana
            if (Menu_Pizza_Mediana.GetItemChecked(0))
            {
                pg.Precio = 80;
                pg.Nombre = "Pepperoni";
                pg.ID     = 16;
                count     = Convert.ToInt32(numericUpDown6.Value);
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizza_Mediana.GetItemChecked(1))
            {
                pg.Precio = 80;
                pg.Nombre = "Hawaiana";
                pg.ID     = 13;
                count     = Convert.ToInt32(numericUpDown7.Value);
                indice    = count;
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizza_Mediana.GetItemChecked(2))
            {
                pg.Precio = 100;
                pg.Nombre = "Carnes Frias";
                pg.ID     = 19;
                count     = Convert.ToInt32(numericUpDown8.Value);
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizza_Mediana.GetItemChecked(3))
            {
                pg.Precio = 100;
                pg.Nombre = "Mexicana";
                pg.ID     = 22;
                count     = Convert.ToInt32(numericUpDown9.Value);
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizza_Mediana.GetItemChecked(4))
            {
                pg.Precio = 100;
                pg.Nombre = "Cuatro Quesos";
                pg.ID     = 25;
                count     = Convert.ToInt32(numericUpDown10.Value);
                or.agregarProducto(pg, count);
            }

            foreach (var s in Menu_Pizza_Mediana.CheckedItems)
            {
                listBox1.Items.Add(s);
            }

            //Pizzas Chica
            if (Menu_Pizza_Chica.GetItemChecked(0))
            {
                pg.Precio = 60;
                pg.Nombre = "Pepperoni";
                pg.ID     = 17;
                count     = Convert.ToInt32(numericUpDown11.Value);
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizza_Chica.GetItemChecked(1))
            {
                pg.Precio = 60;
                pg.Nombre = "Hawaiana";
                pg.ID     = 14;
                count     = Convert.ToInt32(numericUpDown12.Value);
                indice    = count;
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizza_Chica.GetItemChecked(2))
            {
                pg.Precio = 80;
                pg.Nombre = "Carnes Frias";
                pg.ID     = 20;
                count     = Convert.ToInt32(numericUpDown13.Value);
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizza_Chica.GetItemChecked(3))
            {
                pg.Precio = 80;
                pg.Nombre = "Mexicana";
                pg.ID     = 23;
                count     = Convert.ToInt32(numericUpDown14.Value);
                or.agregarProducto(pg, count);
            }

            pg = new Pizza();
            if (Menu_Pizza_Chica.GetItemChecked(4))
            {
                pg.Precio = 80;
                pg.ID     = 26;
                pg.Nombre = "Cuatro Quesos";
                count     = Convert.ToInt32(numericUpDown15.Value);
                or.agregarProducto(pg, count);
            }

            foreach (var s in Menu_Pizza_Chica.CheckedItems)
            {
                listBox1.Items.Add(s);
            }

            //Refrescos 2Lts.
            r = new Refresco();
            if (ListaRefrescos.GetItemChecked(0))
            {
                r.Precio = 35;
                r.Nombre = "Coca Cola";
                r.ID     = 6;
                count    = Convert.ToInt32(numericUpDown16.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (ListaRefrescos.GetItemChecked(1))
            {
                r.Precio = 35;
                r.Nombre = "Pepsi";
                r.ID     = 9;
                count    = Convert.ToInt32(numericUpDown17.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }
            r = new Refresco();
            if (ListaRefrescos.GetItemChecked(2))
            {
                r.Precio = 30;
                r.Nombre = "Manzanita";
                r.ID     = 12;
                count    = Convert.ToInt32(numericUpDown18.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (ListaRefrescos.GetItemChecked(3))
            {
                r.Precio = 30;
                r.Nombre = "7Up";
                r.ID     = 15;
                count    = Convert.ToInt32(numericUpDown19.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (ListaRefrescos.GetItemChecked(4))
            {
                r.Precio = 25;
                r.Nombre = "Mirinda";
                r.ID     = 18;
                count    = Convert.ToInt32(numericUpDown20.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (ListaRefrescos.GetItemChecked(5))
            {
                r.Precio = 25;
                r.Nombre = "Sangria";
                r.ID     = 21;
                count    = Convert.ToInt32(numericUpDown21.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }
            foreach (string m in ListaRefrescos.CheckedItems)
            {
                listBox1.Items.Add(m);
            }

            //Refrescos 1Lt.
            r = new Refresco();
            if (refrescos1.GetItemChecked(0))
            {
                r.Precio = 25;
                r.Nombre = "Coca Cola";
                r.ID     = 7;
                count    = Convert.ToInt32(numericUpDown22.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (refrescos1.GetItemChecked(1))
            {
                r.Precio = 25;
                r.Nombre = "Pepsi";
                r.ID     = 10;
                count    = Convert.ToInt32(numericUpDown23.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }
            r = new Refresco();
            if (refrescos1.GetItemChecked(2))
            {
                r.Precio = 20;
                r.Nombre = "Manzanita";
                r.ID     = 13;
                count    = Convert.ToInt32(numericUpDown24.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (refrescos1.GetItemChecked(3))
            {
                r.Precio = 20;
                r.Nombre = "7Up";
                r.ID     = 16;
                count    = Convert.ToInt32(numericUpDown25.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (refrescos1.GetItemChecked(4))
            {
                r.Precio = 20;
                r.Nombre = "Mirinda";
                r.ID     = 19;
                count    = Convert.ToInt32(numericUpDown26.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (refrescos1.GetItemChecked(5))
            {
                r.Precio = 20;
                r.Nombre = "Sangria";
                r.ID     = 22;
                count    = Convert.ToInt32(numericUpDown27.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }
            foreach (string m in refrescos1.CheckedItems)
            {
                listBox1.Items.Add(m);
            }

            //Refrescos 375ml.
            r = new Refresco();
            if (refrescos375.GetItemChecked(0))
            {
                r.Precio = 20;
                r.Nombre = "Coca Cola";
                r.ID     = 8;
                count    = Convert.ToInt32(numericUpDown28.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (refrescos375.GetItemChecked(1))
            {
                r.Precio = 20;
                r.Nombre = "Pepsi";
                r.ID     = 11;
                count    = Convert.ToInt32(numericUpDown29.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }
            r = new Refresco();
            if (refrescos375.GetItemChecked(2))
            {
                r.Precio = 15;
                r.Nombre = "Manzanita";
                r.ID     = 14;
                count    = Convert.ToInt32(numericUpDown30.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (refrescos375.GetItemChecked(3))
            {
                r.Precio = 15;
                r.Nombre = "7Up";
                r.ID     = 17;
                count    = Convert.ToInt32(numericUpDown31.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (refrescos375.GetItemChecked(4))
            {
                r.Precio = 15;
                r.Nombre = "Mirinda";
                r.ID     = 20;
                count    = Convert.ToInt32(numericUpDown32.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }

            r = new Refresco();
            if (refrescos375.GetItemChecked(5))
            {
                r.Precio = 15;
                r.Nombre = "Sangria";
                r.ID     = 23;
                count    = Convert.ToInt32(numericUpDown33.Value);
                or.agregarProducto(r, count);
                //orden.Add(or);
            }
            foreach (string m in refrescos375.CheckedItems)
            {
                listBox1.Items.Add(m);
            }
            StreamReader sr;

            if (File.Exists("ficha.txt"))
            {
                sr          = new StreamReader("ficha.txt");
                or.NumFicha = Convert.ToInt32(sr.ReadLine());
                //Si el número de fichas es mayor a 100 se vuelve a contar desde 1
                if (or.NumFicha > 100)
                {
                    or.NumFicha = 1;
                }
                sr.Close();
            }
            else
            {
                or.NumFicha = 1;
            }

            listBox1.Items.Add("Número de ficha: " + or.NumFicha);
            listBox1.Items.Add("");
            listBox1.Items.Add("\tTotal: " + or.getTotal());
        }