public Venta_Producto FindById(int?id)
        {
            Venta_Producto ventaproducto = null;

            try
            {
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["BD_Pizza"].ToString()))
                {
                    con.Open();
                    var cmd = new SqlCommand("select vp.CVenta_Producto, vp.CVenta, p.NProducto, vp.QCantidad from Venta_Producto vp, Producto p where vp.CProducto=p.CProducto and vp.CVenta_Producto='" + id + "'", con);
                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            ventaproducto = new Venta_Producto();
                            var venta    = new Venta();
                            var producto = new Producto();

                            ventaproducto.CVenta_Producto = Convert.ToInt32(dr["CVenta_Producto"]);
                            venta.CVenta            = Convert.ToInt32(dr["CVenta"]);
                            ventaproducto.CVenta    = venta;
                            producto.NProducto      = dr["NProducto"].ToString();
                            ventaproducto.CProducto = producto;
                            ventaproducto.QCantidad = Convert.ToInt32(dr["QCantidad"]);
                        }
                    }
                    con.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(ventaproducto);
        }
        public bool Update(Venta_Producto t)
        {
            bool rpta = false;

            try
            {
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["BD_Pizza"].ToString()))
                {
                    con.Open();
                    var cmd = new SqlCommand("update Venta_Producto set CProducto=@cproducto,CVenta=@cventa, QCantidad=@cantidad where CVenta_Producto=@id", con);
                    cmd.Parameters.AddWithValue("@id", t.CVenta_Producto);
                    cmd.Parameters.AddWithValue("@cproducto", t.CProducto.CProducto);
                    cmd.Parameters.AddWithValue("@cventa", t.CVenta.CVenta);
                    cmd.Parameters.AddWithValue("@cantidad", t.QCantidad);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    rpta = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(rpta);
        }
Пример #3
0
        public static ArrayList getVenta_Producto_no_impreso_todos()
        {
            //creo la conexion
            SqlConnection cnn = new SqlConnection(conexion);

            //abro la conexion
            cnn.Open();
            //creo la lista para almacenar las personas
            ArrayList listaventa = new ArrayList();
            //Creo el comando sql a utlizar
            SqlCommand cmd = new SqlCommand("select v.id_venta from  venta v where  v.impreso like '0'");


            //asigno la conexion al comando
            cmd.Connection = cnn;
            //creo el datareader
            SqlDataReader obdr = cmd.ExecuteReader();

            //recorro el datareader
            while (obdr.Read())
            {
                Venta_Producto vp = new Venta_Producto();


                vp.Id_venta = obdr.GetInt64(0);
                listaventa.Add(vp);
            }
            //Cierro la conexion
            cnn.Close();
            //retorno la lsita
            return(listaventa);
        }
Пример #4
0
        public bool Update(Venta_Producto t)
        {
            Venta    venta    = ventaRepository.FindById(t.CVenta.CVenta);
            Producto producto = productoRepository.FindById(t.CProducto.CProducto);

            t.CProducto = producto;
            t.CVenta    = venta;
            return(vntprodctRepository.Update(t));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            Venta_Producto ventaprod = venta_productoservice.FindById(id);

            return(View(ventaprod));
        }
        public ActionResult Edit(int?id)
        {
            ViewBag.producto = productoservice.FindAll();
            ViewBag.venta    = ventaservice.FindAll();
            if (id == null)
            {
                return(HttpNotFound());
            }
            Venta_Producto ventaprod = venta_productoservice.FindById(id);

            return(View(ventaprod));
        }
        public ActionResult Create(Venta_Producto ventaproducto)
        {
            ViewBag.producto = productoservice.FindAll();
            ViewBag.venta    = ventaservice.FindAll();
            bool rpta = venta_productoservice.Insert(ventaproducto);

            if (rpta)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
        public ActionResult Edit(Venta_Producto ventaprod)
        {
            ViewBag.producto = productoservice.FindAll();
            ViewBag.venta    = ventaservice.FindAll();
            if (!ModelState.IsValid)
            {
                return(View());
            }
            bool rpta = venta_productoservice.Update(ventaprod);

            if (rpta)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Пример #9
0
        public static void NuevaVentaProducto(Venta_Producto vp)
        {
            //creo la conexion
            SqlConnection cnn = new SqlConnection(conexion);

            //abro la conexion
            cnn.Open();
            //Creo el comando sql a utlizar
            SqlCommand cmd = new SqlCommand("insert into venta_producto(id_venta, id_producto, precio, cantidad) Values (@id_venta, @id_producto, @precio, @cantidad)");

            cmd.Parameters.Add(new SqlParameter("@id_venta", vp.Id_venta));

            cmd.Parameters.Add(new SqlParameter("@id_producto", vp.Id_producto));
            cmd.Parameters.Add(new SqlParameter("@precio", vp.Precio));
            cmd.Parameters.Add(new SqlParameter("@cantidad", vp.Cantidad));

            //asigno la conexion al comando
            cmd.Connection = cnn;

            cmd.ExecuteNonQuery();
        }
Пример #10
0
        public static ArrayList getVenta_Producto_no_impreso(DateTime fecha)
        {
            //creo la conexion
            SqlConnection cnn = new SqlConnection(conexion);

            //abro la conexion
            cnn.Open();
            //creo la lista para almacenar las personas
            ArrayList listaventa = new ArrayList();
            //Creo el comando sql a utlizar
            SqlCommand cmd = new SqlCommand("select vp.precio, vp.cantidad, p.detalle,c.nombre, p.codigo, p.id_producto from venta_producto vp, producto p, categoria c, venta v where vp.id_producto = p.id_producto and p.id_categoria = c.id_categoria and vp.id_venta = v.id_venta and v.impreso like '0' and v.fecha = @fecha order by id_venta_producto");

            cmd.Parameters.Add(new SqlParameter("@fecha", fecha));

            //asigno la conexion al comando
            cmd.Connection = cnn;
            //creo el datareader
            SqlDataReader obdr = cmd.ExecuteReader();

            //recorro el datareader
            while (obdr.Read())
            {
                Venta_Producto vp = new Venta_Producto();

                vp.Precio      = Convert.ToDecimal(Math.Round(Convert.ToDecimal(obdr.GetDecimal(0)), 2));
                vp.Cantidad    = obdr.GetInt32(1);
                vp.Dato1       = obdr.GetString(2);
                vp.Dato2       = obdr.GetString(4);
                vp.Dato3       = obdr.GetString(3);
                vp.Id_producto = obdr.GetInt64(5);
                listaventa.Add(vp);
            }
            //Cierro la conexion
            cnn.Close();
            //retorno la lsita
            return(listaventa);
        }
Пример #11
0
        public List <Venta_Producto> FindAll()
        {
            var arr_vntproduct = new List <Venta_Producto>();

            try
            {
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["BD_Pizza"].ToString()))
                {
                    con.Open();
                    var cmd = new SqlCommand("select vp.CVenta_Producto, vp.CVenta, p.NProducto, vp.QCantidad from Venta_Producto vp, Producto p where vp.CProducto=p.CProducto", con);
                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            var ventaproducto = new Venta_Producto();
                            var venta         = new Venta();
                            var producto      = new Producto();

                            ventaproducto.CVenta_Producto = Convert.ToInt32(dr["CVenta_Producto"]);
                            venta.CVenta            = Convert.ToInt32(dr["CVenta"]);
                            ventaproducto.CVenta    = venta;
                            producto.NProducto      = dr["NProducto"].ToString();
                            ventaproducto.CProducto = producto;
                            ventaproducto.QCantidad = Convert.ToInt32(dr["QCantidad"]);
                            arr_vntproduct.Add(ventaproducto);
                        }
                    }
                    con.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(arr_vntproduct);
        }
Пример #12
0
        public void guardar_imprimir(bool imprime)
        {
            //verifico si hay items en el carrito


            if (listacarrito.Count > 0)
            {
                this.Cursor = Cursors.WaitCursor;
                int conteo;
                for (conteo = listacarrito.Count; conteo > 0;)
                {
                    conteo = conteo - factura.Items_max;

                    cant_facturas = cant_facturas + 1;
                }


                factura_numero_conteo = factura.Factura_numero_dato;

                // verifico si el cliente es nuevo
                if (cbox_cliente.SelectedItem == null)
                {
                    if (txt_rut.Text == "")
                    {
                        txt_rut.Text = " ";
                    }


                    id_pais = DatosPais.obtener_id_pais_maximo();


                    Cliente c = new Cliente(0, cbox_cliente.Text, txt_n_documento.Text, " ", " ", " ", " ", id_pais, txt_rut.Text, Convert.ToDateTime("1/1/2000"));
                    DatosCliente.NuevoCliente(c);
                    id_cliente = DatosCliente.obtener_id_cliente_maximo();
                }
                //verifico si hay un cliente seleccionado en el cbox_cliente
                else
                {
                    id_cliente = ((Cliente)cbox_cliente.SelectedItem).Id_cliente;
                }
                int impre = 0;
                //creo una nueva venta en la bdd
                Int64 id_venta;
                if (imprime == true)
                {
                    impre = 1;
                }
                else
                {
                    txt_factura_num.Text = " ";
                    txt_venta_num.Text   = " ";
                }
                if (txt_observaciones.Text == "")
                {
                    txt_observaciones.Text = " ";
                }
                Venta v = new Venta(0, id_cliente, DateTime.Now, Convert.ToDecimal(txt_total_pesos.Text), impre, txt_venta_num.Text, " ", tipo, "Pago", 1, 1, 1, 1, 0, 0, 0, 0, descuento_monto, Convert.ToDecimal(Principal.iva), txt_observaciones.Text, Convert.ToDecimal(txt_enPesos.Text));
                DatosVenta.NuevaVenta(v);


                // obtengo el id max de venta
                try
                {
                    id_venta = DatosVenta.obtener_id_venta();
                }
                catch
                {
                    id_venta = 0;
                }


                //agrego items a Venta_producto en la bdd
                for (int i = 0; i < listacarrito.Count; i++)
                {
                    Venta_Producto vp = new Venta_Producto(0, id_venta, ((Producto)listacarrito[i]).Id_producto, ((Producto)listacarrito[i]).Total, ((Producto)listacarrito[i]).Stock);
                    DatosVenta_Producto.NuevaVentaProducto(vp);
                    for (Int32 h = 0; h < listaInicial.Count; h++)
                    {
                        if (((Producto)listacarrito[i]).Id_producto == ((Producto)listainicial2[h]).Id_producto)
                        {
                            DatosProducto.CambiarStock(((Producto)listacarrito[i]).Id_producto, ((Producto)listainicial2[h]).Stock - ((Producto)listacarrito[i]).Stock);
                        }
                    }
                }
                if (imprime == true)
                {
                    for (int y = 0; y < cant_facturas; y++)
                    {
                        Factura fa = new Factura(factura.Factura_Prefijo_dato + (factura.Factura_numero_dato + y).ToString(), 0, id_venta);
                        Datos_Factura.NuevaFacura(fa);
                    }
                    Clases.Configuracion_factura factura_guardar = new Clases.Configuracion_factura();
                    factura_guardar = factura;
                    factura_guardar.Factura_numero_dato = factura.Factura_numero_dato + cant_facturas;
                    factura_guardar.Venta_numero_dato   = factura.Venta_numero_dato + 1;
                    Conex.Modificar_Factura(factura_guardar);
                    try
                    {
                        PrintAString(0);
                    }
                    catch
                    {
                        MessageBox.Show(this, "Error al imprimir factura", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }


                tipo    = null;
                detalle = null;


                Font   printFont   = null;
                string printString = null;
                clientes      = null;
                listaVacia    = null;
                listaInicial  = null;
                listacarrito  = null;
                listainicial2 = null;
                factura       = null;


                Principal.cerrar_ventana_generar_venta = false;
                this.Close();
            }
            else
            {
                MessageBox.Show(this, "No hay items en el carrito", "¡Aviso!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txt_codigo2.Focus();
            }
        }
Пример #13
0
        public void cargar()
        {
            txt_pesos.Text = "0";



            lista2.Clear();
            // modelo



            lista2 = Datos.DatosVenta.getVenta_cliente_porfecha_impreso(date_fecha.Value.Date);


            for (int i = 0; i < lista2.Count; i++)
            {
                txt_pesos.Text    = (Convert.ToDecimal(txt_pesos.Text) + ((Venta)lista2[i]).Total).ToString();
                txt_en_pesos.Text = (Convert.ToDecimal(txt_en_pesos.Text) + ((Venta)lista2[i]).En_pesos).ToString();
            }

            if (lista2.Count > 0)
            {
                listacarrito          = Datos.DatosVenta_Producto.getVenta_Producto_no_impreso(date_fecha.Value.Date);
                lista                 = lista2;
                bdd_ventas.DataSource = lista;
                for (int i = 0; i < listacarrito.Count; i++)
                {
                    bool existe = false;


                    for (int x = 0; x < listaimprimir.Count; x++)
                    {
                        if (((Venta_Producto)listacarrito[i]).Dato2 == ((Venta_Producto)listaimprimir[x]).Dato2)
                        {
                            existe = true;
                            ((Venta_Producto)listaimprimir[x]).Cantidad = ((Venta_Producto)listaimprimir[x]).Cantidad + ((Venta_Producto)listacarrito[i]).Cantidad;
                        }
                    }


                    if (existe == false)
                    {
                        Venta_Producto p = new Venta_Producto();
                        p = (Venta_Producto)listacarrito[i];
                        //    p.Stock = Convert.ToInt32(txt_cantidad.Text);
                        //     bdd_carrito.Rows.Add(p.Codigo, p.Detalle, p.Stock, p.Total);
                        //bdd_print.Rows.Add(p.Stock, p.Detalle, p.Total);
                        listaimprimir.Add(p);
                        // txt_cantidad.Text = "1";
                    }
                    existe = false;
                }

                btn_imprimir.Enabled = true;
                btn_ver.Enabled      = true;
            }
            else
            {
                btn_ver.Enabled = false;
                lista.Clear();
                Venta vt = new Venta(0, 0, DateTime.Today, 0, 0, "No hay registros", "No hay registro", "No hay registro", "No hay registro", 1, 1, 1, 1, 0, 0, 0, 0, 0, Principal.iva, " ", 0);
                vt.Provisorio = "No hay registros";
                lista.Add(vt);
                bdd_ventas.Refresh();
                bdd_ventas.DataSource = lista;
                btn_imprimir.Enabled  = false;

                MessageBox.Show(this, "No hay registros con la fecha seleccionada", "¡Aviso!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                btn_imprimir.Enabled = false;
            }
        }
Пример #14
0
        private void btn_imprimir_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show(this, "A continuacion se imprimirá los productos no impresos en facturas, ¿Desea continuar?", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr == DialogResult.Yes)
            {
                this.Cursor = Cursors.WaitCursor;
                Cliente cli = new Cliente();
                cli = DatosCliente.getCliente(42);
                nombre_del_cliente = cli.Nombre;
                int conteo;
                for (conteo = listaimprimir.Count; conteo > 0;)
                {
                    conteo = conteo - factura.Items_max;

                    cant_facturas = cant_facturas + 1;
                }


                factura_numero_conteo = factura.Factura_numero_dato;

                for (int y = 0; y < lista.Count; y++)
                {
                    DatosVenta.setBajaVenta(((Venta)lista[y]).Id_venta);
                    DatosVenta_Producto.setBajaVenta_producto(((Venta)lista[y]).Id_venta);
                }


                Venta v = new Venta(0, 42, DateTime.Now, Convert.ToDecimal(txt_pesos.Text), 1, factura.Venta_Prefijo_dato + factura.Venta_numero_dato.ToString(), " ", "Contado", "Pago", 1, 1, 1, 1, 0, 0, 0, 0, 0, Principal.iva, " ", 0);
                DatosVenta.NuevaVenta(v);
                Int64 id_venta = DatosVenta.obtener_id_venta();
                for (int y = 0; y < cant_facturas; y++)
                {
                    Factura fa = new Factura(factura.Factura_Prefijo_dato + (factura.Factura_numero_dato + y).ToString(), 0, id_venta);
                    Datos_Factura.NuevaFacura(fa);
                }
                Clases.Configuracion_factura factura_guardar = new Clases.Configuracion_factura();
                factura_guardar = factura;
                factura_guardar.Factura_numero_dato = factura.Factura_numero_dato + cant_facturas;
                factura_guardar.Venta_numero_dato   = factura.Venta_numero_dato + 1;
                Conex.Modificar_Factura(factura_guardar);


                for (int x = 0; x < listaimprimir.Count; x++)
                {
                    Venta_Producto vp = new Venta_Producto(0, id_venta, ((Venta_Producto)listaimprimir[x]).Id_producto, ((Venta_Producto)listaimprimir[x]).Precio, ((Venta_Producto)listaimprimir[x]).Cantidad);
                    DatosVenta_Producto.NuevaVentaProducto(vp);
                }

                try
                {
                    PrintAString(0);
                }
                catch
                {
                    MessageBox.Show(this, "Error al imprimir", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Principal.cerrar_venta_no_impresa = false;
                this.Cursor = Cursors.Default;
                this.Close();
            }
        }