private void Decrease_Click(object sender, RoutedEventArgs e)
        {
            if (Valor > Minimum)
            {
                Valor--;
                if (datagridVentas.SelectedItem != null)
                {
                    if (datagridVentas.Items.Count > 0)
                    {
                        if (datagridVentas.SelectedItem is VentaTemporal)
                        {
                            var row = (VentaTemporal)datagridVentas.SelectedItem;
                            ProductoFacade prodFobtener = new ProductoFacade();
                            Producto Prod = new Producto();
                            Prod = prodFobtener.getProductosByID(row.idProducto);
                            int filaProd = 0;
                            int num = 0;
                            if (row != null)
                            {

                                //MessageBox.Show(row.cantidad); 
                                //Tomar valor de cantidad  datagrid y aumentar 
                                List<VentaTemporal> vtemporal = new List<VentaTemporal>();
                                var rows = GetDataGridRows(datagridVentas);
                                foreach (DataGridRow r in rows)
                                {
                                    VentaTemporal rv = (VentaTemporal)r.Item;
                                    vtemporal.Add(rv);
                                }
                                //buscar el id de list con el seleccionado en datagrid
                                foreach (var r in vtemporal)
                                {
                                    if (row.idProducto.Equals(r.idProducto))
                                    {
                                        filaProd = num;
                                    }
                                    num = num + 1;

                                }

                                int total = Convert.ToInt32(Prod.precio) * Convert.ToInt32(Valor);
                                vtemporal[filaProd].devolver = Valor.ToString();
                                //vtemporal[filaProd].total = total.ToString();
                                ltotal.Content = total.ToString();
                                datagridVentas.ItemsSource = null;
                                datagridVentas.ItemsSource = vtemporal;
                                datagridVentas.SelectedIndex = filaProd;



                            }
                        }
                    }
                }
                //Recorrer tabla para sumar total
                /*subtotal = 0;

                foreach (var i in venta)
                {
                    subtotal = subtotal + Convert.ToInt32(i.total);
                    //MessageBox.Show(i.total.ToString());
                }
                txtsubtotal.Text = subtotal.ToString();*/
                subtotal = 0;
                int numProducto = 0;
                foreach (var i in venta)
                {
                    subtotal = subtotal + Convert.ToInt32(i.total);
                    //MessageBox.Show(i.total.ToString());
                    numProducto = numProducto + 1;
                }
                /*
                txtsubtotal.Text = subtotal.ToString();
                txtCantidadProductos.Content = numProducto.ToString();
                if (Convert.ToInt32(txtdescuento.Text) == 0)
                {
                    txttotal.Text = txtsubtotal.Text;
                }
                else
                {
                    double des = Convert.ToDouble(txtdescuento.Text) / Convert.ToDouble(100);
                    txttotal.Text = (Convert.ToInt32(txtsubtotal.Text) - Convert.ToDouble(txtsubtotal.Text) * des).ToString();
                }*/
                RaiseEvent(new RoutedEventArgs(DecreaseClickedEvent));
            }
        }
        private void btnBuscarVenta_Click(object sender, RoutedEventArgs e)
        {

            if (txtidventa.Text.Equals(""))
            {
                MessageBox.Show("Ingresar idventa", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (txtidProducto.Text.Equals(""))
            {
                MessageBox.Show("Ingresar idProducto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (fechaventa.Text.Equals(""))
            {
                MessageBox.Show("Ingresar Fecha", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {


                ventasFacade ventFac = new ventasFacade();
                List<MVentas> listaVentaDevolucion = ventFac.getVentasForDevolucion(Convert.ToDouble(txtidventa.Text), txtidProducto.Text, Convert.ToDateTime(fechaventa.Text));
                var rows = GetDataGridRows(datagridVentas);
                if (listaVentaDevolucion.Count != 0)
                {
                    venta.Clear();
                    datagridVentas.ItemsSource = venta;
                    //llenar datagridVenta para devoulcion
                    foreach (var item in listaVentaDevolucion)
                    {
                        ProductoFacade prodFobtener = new ProductoFacade();
                        Producto Prod = new Producto();
                        Prod = prodFobtener.getProductosByID(item.idProducto);
                        vtemp = new VentaTemporal(item.idVenta, item.idProducto, Prod.nombre, Prod.precio, item.cantidad.ToString(), "1", item.total.ToString());
                        venta.Add(vtemp);
                        cantidad = cantidad + 1;
                        total = total + Convert.ToInt32(item.total);

                        //ltotal.Content = Prod.precio;
                        ltotal.Content = item.total;
                        TextBoxValue.Text = item.cantidad.ToString();
                    }
                    datagridVentas.ItemsSource = venta;
                }
                else
                {
                    MessageBox.Show("No se han encontrado ventas con estos datos.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                }

            }

        }
        //Al presionar enter en spinkbox que se actualice en tabla la cantidad 
        private void TextBoxValue_KeyDown(Object sender, KeyEventArgs e)
        {

            if (e.Key == Key.Enter)
            {
                if (datagridVentas.Items.Count > 0)
                {
                    if (datagridVentas.SelectedItem != null)
                    {
                        if (datagridVentas.SelectedItem is VentaTemporal)
                        {
                            var row = (VentaTemporal)datagridVentas.SelectedItem;
                            ProductoFacade prodFobtener = new ProductoFacade();
                            Producto Prod = new Producto();
                            Prod = prodFobtener.getProductosByID(row.idProducto);
                            int filaProd = 0;
                            int num = 0;
                            if (row != null)
                            {
                                //Tomar valor de cantidad  datagrid y aumentar 
                                List<VentaTemporal> vtemporal = new List<VentaTemporal>();
                                var rows = GetDataGridRows(datagridVentas);
                                foreach (DataGridRow r in rows)
                                {
                                    VentaTemporal rv = (VentaTemporal)r.Item;
                                    vtemporal.Add(rv);
                                }
                                //buscar el id de list con el seleccionado en datagrid
                                foreach (var r in vtemporal)
                                {
                                    if (row.idProducto.Equals(r.idProducto))
                                    {
                                        filaProd = num;
                                    }
                                    num = num + 1;

                                }

                                //Verificar stock de producto
                                ProductoFacade prodcantiFacade = new ProductoFacade();
                                int maxstock = Convert.ToInt32(prodcantiFacade.getStockProductoByidProd(row.idProducto));
                                if (Valor <= Convert.ToInt32(row.cantidad))
                                {
                                    int total = Convert.ToInt32(Prod.precio) * Convert.ToInt32(Valor);
                                    vtemporal[filaProd].devolver = Valor.ToString();
                                    //vtemporal[filaProd].total = total.ToString();
                                    ltotal.Content = total.ToString();
                                    datagridVentas.ItemsSource = null;
                                    datagridVentas.ItemsSource = vtemporal;
                                    datagridVentas.SelectedIndex = filaProd;
                                }
                                else
                                {
                                    //MessageBox.Show("Producto, segun inventario, no cuenta con mas stock");
                                    Valor = Convert.ToInt32(row.cantidad);
                                }

                            }
                        }
                    }
                }
                //Recorrer tabla para sumar total
                /* subtotal = 0;

                 foreach (var i in venta)
                 {
                     subtotal = subtotal + Convert.ToInt32(i.total);
                     //MessageBox.Show(i.total.ToString());
                 }
                 txtsubtotal.Text = subtotal.ToString();*/
                subtotal = 0;
                int numProducto = 0;
                foreach (var i in venta)
                {
                    subtotal = subtotal + Convert.ToInt32(i.total);
                    //MessageBox.Show(i.total.ToString());
                    numProducto = numProducto + 1;
                }
                /*txtsubtotal.Text = subtotal.ToString();
                txtCantidadProductos.Content = numProducto.ToString();
                if (Convert.ToInt32(txtdescuento.Text) == 0)
                {
                    txttotal.Text = txtsubtotal.Text;
                }
                else
                {
                    double des = Convert.ToDouble(txtdescuento.Text) / Convert.ToDouble(100);
                    txttotal.Text = (Convert.ToInt32(txtsubtotal.Text) - Convert.ToDouble(txtsubtotal.Text) * des).ToString();
                }*/
            }

        }
Exemple #4
0
        /*********************************/


        /*********************************/


        //buscar producto mediante id ingresado
        private void codProdVenta_TextChanged(object sender, TextChangedEventArgs e)
        {

            ProductoFacade prodF = new ProductoFacade();
            bool existe = prodF.getExisteProductoByidProd(txtcodProdVenta.Text);


            if (existe)
            {
                ProductoFacade prodFobtener = new ProductoFacade();
                Producto Prod = new Producto();
                Prod = prodFobtener.getProductosByID(txtcodProdVenta.Text);
                //Si producto ya esta en tablapara venta aumentar cantidad
                if (Convert.ToInt32(Prod.stock) <= 0)
                {
                    MessageBox.Show("El producto no cuenta con más stock", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {

                    //comparar en datagrid si esta
                    bool sumarCantidad = false;
                    int cantidad = 0;
                    int totaldatos = datagridVentas.Items.Count;
                    int filaProd = 0;
                    List<VentaTemporal> vtemporal = new List<VentaTemporal>();
                    VentaTemporal vtemp = new VentaTemporal();
                    var rows = GetDataGridRows(datagridVentas);
                    int num = 0;
                    //Se verifica si tabla tiene ya ese producto y asi aumentar canditad
                    if (totaldatos > 0)
                    { //Llenar lista con los productos en datagrid para sumarle uno mas en cantidad
                        foreach (DataGridRow r in rows)
                        {
                            VentaTemporal rv = (VentaTemporal)r.Item;
                            vtemporal.Add(rv);

                        }
                        foreach (DataGridRow r in rows)
                        {
                            VentaTemporal rv = (VentaTemporal)r.Item;
                            //MessageBox.Show(txtcodProdVenta.Text+"="+rv.idProducto);
                            if (txtcodProdVenta.Text.Equals(rv.idProducto))
                            {
                                sumarCantidad = true;
                                /*int pre = ToEntero(rv.precio, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                string m = pre.ToString("#,#", CultureInfo.InvariantCulture);
                                MessageBox.Show(rv.precio);*/
                                vtemp = new VentaTemporal(rv.idVenta, rv.idProducto, rv.nombre, rv.precio, rv.cantidad, rv.total);
                                cantidad = Convert.ToInt32(rv.cantidad) + 1;
                                filaProd = num;
                            }
                            num = num + 1;
                        }
                    }

                    //Verificar stock de producto
                    ProductoFacade prodcantiFacade = new ProductoFacade();
                    int maxstock = Convert.ToInt32(prodcantiFacade.getStockProductoByidProd(txtcodProdVenta.Text));
                    if (cantidad <= maxstock)
                    {

                        if (sumarCantidad)
                        {
                            //Editar cantidad y setear total precio

                            int totalProducto = Convert.ToInt32(Prod.precio) * Convert.ToInt32(cantidad);
                            //borrar fila delista con id y actualizar la cantidad y precio
                            vtemporal[filaProd].cantidad = cantidad.ToString();
                            vtemporal[filaProd].total = totalProducto.ToString();

                            // subtotal = subtotal + totalProducto;

                            datagridVentas.ItemsSource = null;
                            datagridVentas.ItemsSource = vtemporal;

                            //Llenar textbox con total

                        }
                        else
                        {
                            //MessageBox.Show("Primer producto agregado");
                            //Nuevo producto para venta a  proceso de venta
                            venta.Add(new VentaTemporal { idProducto = Prod.idProducto, nombre = Prod.nombre, precio = Prod.precio, cantidad = "1", total = Prod.precio });
                            datagridVentas.ItemsSource = venta;
                            subtotal = subtotal + Convert.ToInt32(Prod.precio);
                        }
                        //txtcodProdVenta.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("El producto no cuenta con más stock", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                txtcodProdVenta.Text = "";
            }
            else
            {


            }
            //Recorrer tabla para sumar total
            subtotal = 0;
            int numProducto = 0;
            foreach (var i in venta)
            {
                subtotal = subtotal + Convert.ToInt32(i.total);
                //MessageBox.Show(i.total.ToString());
                numProducto = numProducto + 1;
            }
            int mtotalDevo = subtotal - dineroDevolucion;
            if (mtotalDevo < 0)
            {
                //Quiere decir que totaldevolucion tiene saldo 
                txtDiferencia.Text = (mtotalDevo * -1).ToString();
                mtotalDevo = 0;

            }
            else

            {
                txtDiferencia.Text = "0";
            }

            if (mtotalDevo < 0)
            {
                mtotalDevo = mtotalDevo * -1;
            }
            int p = ToEntero(mtotalDevo.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
            txtsubtotal.Text = p.ToString("#,#", CultureInfo.InvariantCulture);


            txtCantidadProductos.Content = numProducto.ToString();
            if (Convert.ToInt32(txtdescuento.Text) == 0)
            {
                int pr = ToEntero(txtsubtotal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                txttotal.Text = pr.ToString("#,#", CultureInfo.InvariantCulture);

            }
            else
            {
                int pr = ToEntero(txtsubtotal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));

                double des = Convert.ToDouble(txtdescuento.Text) / Convert.ToInt32(100);
                double res = (Convert.ToInt32(pr) - Convert.ToDouble(pr) * des);
                txttotal.Text = res.ToString("#,#", CultureInfo.InvariantCulture);
            }

        }
        public Producto getProductosByID(string idProducto)
        {

            MySqlDataReader rdr = null;
            Producto producto = new Producto();


            string consulta = "SELECT*FROM producto WHERE idProducto=\"" + idProducto + "\"";
            //MySqlDataAdapter mdaDatos = new MySqlDataAdapter("SELECT*FROM producto", conexion.getConexion());
            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                // producto.Add(new Producto(rdr.GetString(0), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3), rdr.GetString(4)));
                producto.idProducto = rdr.GetString(0);
                producto.nombre = rdr.GetString(1);
                producto.stock = rdr.GetString(2);
                producto.precio = rdr.GetString(4);
                producto.idCategoria = rdr.GetInt32(5);

            }
            getconexion.CerrarConexion();

            return producto;


        }
Exemple #6
0
        private void Decrease_Click(object sender, RoutedEventArgs e)
        {
            if (Value > Minimum)
            {
                Value--;
                if (datagridVentas.SelectedItem != null)
                {
                    if (datagridVentas.SelectedItem is VentaTemporal)
                    {
                        var row = (VentaTemporal)datagridVentas.SelectedItem;
                        ProductoFacade prodFobtener = new ProductoFacade();
                        Producto Prod = new Producto();
                        Prod = prodFobtener.getProductosByID(row.idProducto);
                        int filaProd = 0;
                        int num = 0;
                        if (row != null)
                        {

                            //MessageBox.Show(row.cantidad); 
                            //Tomar valor de cantidad  datagrid y aumentar 
                            List<VentaTemporal> vtemporal = new List<VentaTemporal>();
                            var rows = GetDataGridRows(datagridVentas);
                            foreach (DataGridRow r in rows)
                            {
                                VentaTemporal rv = (VentaTemporal)r.Item;
                                vtemporal.Add(rv);
                            }
                            //buscar el id de list con el seleccionado en datagrid
                            foreach (var r in vtemporal)
                            {
                                if (row.idProducto.Equals(r.idProducto))
                                {
                                    filaProd = num;
                                }
                                num = num + 1;

                            }

                            int total = Convert.ToInt32(Prod.precio) * Convert.ToInt32(Value);
                            vtemporal[filaProd].cantidad = Value.ToString();
                            vtemporal[filaProd].total = total.ToString();


                            string d = (Convert.ToDouble(txttotal.Text) - dineroDevolucion).ToString();

                            int prT = ToEntero(d, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            txttotal.Text = prT.ToString("#,#", CultureInfo.InvariantCulture); ;



                            datagridVentas.ItemsSource = null;
                            datagridVentas.ItemsSource = vtemporal;
                            datagridVentas.SelectedIndex = filaProd;

                        }
                    }
                }
                //Recorrer tabla para sumar total
                /*subtotal = 0;

                foreach (var i in venta)
                {
                    subtotal = subtotal + Convert.ToInt32(i.total);
                    //MessageBox.Show(i.total.ToString());
                }
                txtsubtotal.Text = subtotal.ToString();*/
                subtotal = 0;
                int numProducto = 0;
                foreach (var i in venta)
                {
                    subtotal = subtotal + Convert.ToInt32(i.total);
                    //MessageBox.Show(i.total.ToString());
                    numProducto = numProducto + 1;
                }
                int p = ToEntero(subtotal.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                txtsubtotal.Text = p.ToString("#,#", CultureInfo.InvariantCulture);

                txtCantidadProductos.Content = numProducto.ToString();
                if (Convert.ToInt32(txtdescuento.Text) == 0)
                {
                    /********************************************************/
                    //En proceso de cambio, al presionar spinbox decre al total se descuenta el valor de cambio
                    int mtotalDevo = subtotal - dineroDevolucion;
                    if (mtotalDevo < 0)
                    {
                        //Quiere decir que totaldevolucion tiene saldo 
                        txtDiferencia.Text = (mtotalDevo * -1).ToString();
                        mtotalDevo = 0;

                    }
                    else

                    {
                        txttotal.Text = "0";
                        txtDiferencia.Text = "0";
                    }

                    if (mtotalDevo < 0)
                    {
                        mtotalDevo = mtotalDevo * -1;
                    }

                    int pr = ToEntero(mtotalDevo.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txtsubtotal.Text = pr.ToString("#,#", CultureInfo.InvariantCulture);
                    int prT = ToEntero(mtotalDevo.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txttotal.Text = prT.ToString("#,#", CultureInfo.InvariantCulture); ;

                    /********************************************************/

                }
                else
                {
                    double des = Convert.ToDouble(txtdescuento.Text) / Convert.ToInt32(100);
                    /********************************************************/
                    int mtotalDevo = subtotal - dineroDevolucion;
                    if (mtotalDevo < 0)
                    {
                        //Quiere decir que totaldevolucion tiene saldo 
                        txtDiferencia.Text = (mtotalDevo * -1).ToString();
                        mtotalDevo = 0;

                    }
                    else

                    {
                        txttotal.Text = "0";
                        txtDiferencia.Text = "0";
                    }

                    if (mtotalDevo < 0)
                    {
                        mtotalDevo = mtotalDevo * -1;
                    }
                    int pr = ToEntero(mtotalDevo.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txtsubtotal.Text = pr.ToString("#,#", CultureInfo.InvariantCulture);

                    string g = (mtotalDevo - mtotalDevo * des).ToString();
                    int prT = ToEntero(g, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txttotal.Text = prT.ToString("#,#", CultureInfo.InvariantCulture); ;
                    /********************************************************/
                    //                    txttotal.Text = (Convert.ToInt32(txtsubtotal.Text) - Convert.ToDouble(txtsubtotal.Text) * des).ToString();
                }
                RaiseEvent(new RoutedEventArgs(DecreaseClickedEvent));
            }
        }
Exemple #7
0
        private void Increase_Click(object sender, RoutedEventArgs e)
        {
            if (Value < Maximum)
            {
                Value++;
                /*Aumentar en tabla valor  de cantidad de valor seleccionado de producto*/
                if (datagridVentas.SelectedItem != null)
                {
                    if (datagridVentas.SelectedItem is VentaTemporal)
                    {
                        var row = (VentaTemporal)datagridVentas.SelectedItem;
                        ProductoFacade prodFobtener = new ProductoFacade();
                        Producto Prod = new Producto();
                        Prod = prodFobtener.getProductosByID(row.idProducto);
                        int filaProd = 0;
                        int num = 0;
                        if (row != null)
                        {

                            //MessageBox.Show(row.cantidad); 
                            //Tomar valor de cantidad  datagrid y aumentar 
                            List<VentaTemporal> vtemporal = new List<VentaTemporal>();
                            var rows = GetDataGridRows(datagridVentas);
                            foreach (DataGridRow r in rows)
                            {
                                VentaTemporal rv = (VentaTemporal)r.Item;
                                vtemporal.Add(rv);
                            }
                            //buscar el id de list con el seleccionado en datagrid
                            foreach (var r in vtemporal)
                            {
                                if (row.idProducto.Equals(r.idProducto))
                                {
                                    filaProd = num;
                                }
                                num = num + 1;

                            }
                            ProductoFacade prodcantiFacade = new ProductoFacade();
                            int maxstock = Convert.ToInt32(prodcantiFacade.getStockProductoByidProd(row.idProducto));
                            if (Value <= maxstock)
                            {
                                int total = Convert.ToInt32(Prod.precio) * Convert.ToInt32(Value);
                                vtemporal[filaProd].cantidad = Value.ToString();
                                vtemporal[filaProd].total = total.ToString();



                                datagridVentas.ItemsSource = null;
                                datagridVentas.ItemsSource = vtemporal;
                                datagridVentas.SelectedIndex = filaProd;
                            }
                            else
                            {
                                MessageBox.Show("El producto no cuenta con más stock", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                Value = maxstock;
                            }

                        }
                    }
                }
                subtotal = 0;
                int numProducto = 0;
                foreach (var i in venta)
                {
                    subtotal = subtotal + Convert.ToInt32(i.total);

                    numProducto = numProducto + 1;
                }

                txtCantidadProductos.Content = numProducto.ToString();

                if (Convert.ToInt32(txtdescuento.Text) == 0)
                {
                    /********************************************************/
                    int mtotalDevo = subtotal - dineroDevolucion;
                    if (mtotalDevo < 0)
                    {
                        //Quiere decir que totaldevolucion tiene saldo 
                        txtDiferencia.Text = (mtotalDevo * -1).ToString();
                        mtotalDevo = 0;

                    }
                    else

                    {
                        txttotal.Text = "0";
                        txtDiferencia.Text = "0";
                    }

                    if (mtotalDevo < 0)
                    {
                        mtotalDevo = mtotalDevo * -1;
                    }
                    int p = ToEntero(mtotalDevo.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txtsubtotal.Text = p.ToString("#,#", CultureInfo.InvariantCulture);

                    int prT = ToEntero(mtotalDevo.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txttotal.Text = prT.ToString("#,#", CultureInfo.InvariantCulture); ;

                    /********************************************************/

                    //txttotal.Text = txtsubtotal.Text;

                }
                else
                {
                    double des = Convert.ToDouble(txtdescuento.Text) / Convert.ToInt32(100);
                    /********************************************************/
                    int mtotalDevo = subtotal - dineroDevolucion;
                    if (mtotalDevo < 0)
                    {
                        //Quiere decir que totaldevolucion tiene saldo 
                        txtDiferencia.Text = (mtotalDevo * -1).ToString();
                        mtotalDevo = 0;

                    }
                    else

                    {
                        txttotal.Text = "0";
                        txtDiferencia.Text = "0";
                    }

                    if (mtotalDevo < 0)
                    {
                        mtotalDevo = mtotalDevo * -1;
                    }
                    int p = ToEntero(mtotalDevo.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txtsubtotal.Text = p.ToString("#,#", CultureInfo.InvariantCulture);

                    double d = (mtotalDevo - mtotalDevo * des);

                    int prT = ToEntero(d.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txttotal.Text = prT.ToString("#,#", CultureInfo.InvariantCulture); ;

                    /********************************************************/
                }
                RaiseEvent(new RoutedEventArgs(IncreaseClickedEvent));
            }
        }
Exemple #8
0
        //Al presionar enter en spinkbox que se actualice en tabla la cantidad 
        private void TextBoxValue_KeyDown(Object sender, KeyEventArgs e)
        {

            if (e.Key == Key.Enter)
            {
                if (datagridVentas.SelectedItem != null)
                {
                    if (datagridVentas.SelectedItem is VentaTemporal)
                    {
                        var row = (VentaTemporal)datagridVentas.SelectedItem;
                        ProductoFacade prodFobtener = new ProductoFacade();
                        Producto Prod = new Producto();
                        Prod = prodFobtener.getProductosByID(row.idProducto);
                        int filaProd = 0;
                        int num = 0;
                        if (row != null)
                        {
                            //Tomar valor de cantidad  datagrid y aumentar 
                            List<VentaTemporal> vtemporal = new List<VentaTemporal>();
                            var rows = GetDataGridRows(datagridVentas);
                            foreach (DataGridRow r in rows)
                            {
                                VentaTemporal rv = (VentaTemporal)r.Item;
                                vtemporal.Add(rv);
                            }
                            //buscar el id de list con el seleccionado en datagrid
                            foreach (var r in vtemporal)
                            {
                                if (row.idProducto.Equals(r.idProducto))
                                {
                                    filaProd = num;
                                }
                                num = num + 1;

                            }

                            //Verificar stock de producto
                            ProductoFacade prodcantiFacade = new ProductoFacade();
                            int maxstock = Convert.ToInt32(prodcantiFacade.getStockProductoByidProd(row.idProducto));
                            if (Value <= maxstock)
                            {
                                int total = Convert.ToInt32(Prod.precio) * Convert.ToInt32(Value);
                                vtemporal[filaProd].cantidad = Value.ToString();
                                vtemporal[filaProd].total = total.ToString();

                                datagridVentas.ItemsSource = null;
                                datagridVentas.ItemsSource = vtemporal;
                                datagridVentas.SelectedIndex = filaProd;
                            }
                            else
                            {
                                MessageBox.Show("El producto no cuenta con más stock", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                Value = maxstock;
                            }

                        }
                    }
                }
                //Recorrer tabla para sumar total
                /* subtotal = 0;

                 foreach (var i in venta)
                 {
                     subtotal = subtotal + Convert.ToInt32(i.total);
                     //MessageBox.Show(i.total.ToString());
                 }
                 txtsubtotal.Text = subtotal.ToString();*/
                subtotal = 0;
                int numProducto = 0;
                foreach (var i in venta)
                {
                    subtotal = subtotal + Convert.ToInt32(i.total);
                    //MessageBox.Show(i.total.ToString());
                    numProducto = numProducto + 1;
                }
                int p = ToEntero(txtsubtotal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                txtsubtotal.Text = p.ToString("#,#", CultureInfo.InvariantCulture); ;
                //                txtDiferencia.Text = (Convert.ToInt32(txtsubtotal.Text) - dineroDevolucion).ToString();
                txtCantidadProductos.Content = numProducto.ToString();
                if (Convert.ToInt32(txtdescuento.Text) == 0)
                {

                    /********************************************************/
                    int mtotalDevo = subtotal - dineroDevolucion;
                    if (mtotalDevo < 0)
                    {
                        //Quiere decir que totaldevolucion tiene saldo 
                        txtDiferencia.Text = (mtotalDevo * -1).ToString();
                        mtotalDevo = 0;

                    }
                    else

                    {
                        txttotal.Text = "0";
                        txtDiferencia.Text = "0";
                    }

                    if (mtotalDevo < 0)
                    {
                        mtotalDevo = mtotalDevo * -1;
                    }
                    int pr = ToEntero(mtotalDevo.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txtsubtotal.Text = pr.ToString("#,#", CultureInfo.InvariantCulture); ;

                    int prT = ToEntero(mtotalDevo.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txttotal.Text = prT.ToString("#,#", CultureInfo.InvariantCulture); ;


                    /********************************************************/

                }
                else
                {
                    //falto en varia parte el pasar 
                    double des = Convert.ToDouble(txtdescuento.Text) / Convert.ToInt32(100);
                    int pr = ToEntero(txtsubtotal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    double totalDes = Convert.ToInt32(pr) - Convert.ToDouble(pr) * des;

                    int prT = ToEntero(totalDes.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    txttotal.Text = prT.ToString("#,#", CultureInfo.InvariantCulture); ;


                    //txtDiferencia.Text = (totalDes - dineroDevolucion).ToString();
                }
            }

        }
        private void Increase_Click(object sender, RoutedEventArgs e)
        {
            if (Valor < Maximum)
            {
               
                /*Aumentar en tabla valor  de cantidad de valor seleccionado de producto*/
                if (datagridVentas.SelectedItem != null)
                {
                    if (datagridVentas.Items.Count > 0)
                    {
                        if (datagridVentas.SelectedItem is VentaTemporal)
                        {
                            Valor++;
                            var row = (VentaTemporal)datagridVentas.SelectedItem;
                            ProductoFacade prodFobtener = new ProductoFacade();
                            Producto Prod = new Producto();
                            Prod = prodFobtener.getProductosByID(row.idProducto);
                            int filaProd = 0;
                            int num = 0;
                            if (row != null)
                            {

                                //MessageBox.Show(row.cantidad); 
                                //Tomar valor de cantidad  datagrid y aumentar 
                                List<VentaTemporal> vtemporal = new List<VentaTemporal>();
                                var rows = GetDataGridRows(datagridVentas);
                                foreach (DataGridRow r in rows)
                                {
                                    VentaTemporal rv = (VentaTemporal)r.Item;
                                    vtemporal.Add(rv);
                                }
                                //buscar el id de list con el seleccionado en datagrid
                                foreach (var r in vtemporal)
                                {
                                    if (row.idProducto.Equals(r.idProducto))
                                    {
                                        filaProd = num;
                                    }
                                    num = num + 1;

                                }
                                ProductoFacade prodcantiFacade = new ProductoFacade();
                                int maxstock = Convert.ToInt32(prodcantiFacade.getStockProductoByidProd(row.idProducto));
                                if (Valor <= Convert.ToInt32(row.cantidad))
                                {
                                    int total = Convert.ToInt32(Prod.precio) * Convert.ToInt32(Valor);
                                    vtemporal[filaProd].devolver = Valor.ToString();
                                    //vtemporal[filaProd].total = total.ToString();
                                    int t = ToEntero(total.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                    string totalF = t.ToString("#,#", CultureInfo.InvariantCulture); ;
                                    ltotal.Content = totalF.ToString();
                                    datagridVentas.ItemsSource = null;
                                    datagridVentas.ItemsSource = vtemporal;
                                    datagridVentas.SelectedIndex = filaProd;
                                }
                                else
                                {
                                    //MessageBox.Show("Producto, segun inventario, no cuenta con mas stock");
                                    Valor = Convert.ToInt32(row.cantidad);
                                }

                            }
                        }
                    }
                }
                //Recorrer tabla para sumar total
                /*  subtotal = 0;

                  foreach (var i in venta)
                  {
                      subtotal = subtotal + Convert.ToInt32(i.total);
                      //MessageBox.Show(i.total.ToString());
                  }
                  txtsubtotal.Text = subtotal.ToString*/
                //Recorrer tabla para sumar total
                subtotal = 0;
                int numProducto = 0;
                foreach (var i in venta)
                {
                    int p1 = ToEntero(i.total, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    subtotal = subtotal + Convert.ToInt32(p1);

                    //subtotal = subtotal + Convert.ToInt32(i.total);
                    //MessageBox.Show(i.total.ToString());
                    numProducto = numProducto + 1;
                }
               /* txtsubtotal.Text = subtotal.ToString();
                txtCantidadProductos.Content = numProducto.ToString();
                if (Convert.ToInt32(txtdescuento.Text) == 0)
                {
                    txttotal.Text = txtsubtotal.Text;
                }
                else
                {
                    double des = Convert.ToDouble(txtdescuento.Text) / Convert.ToDouble(100);
                    txttotal.Text = (Convert.ToInt32(txtsubtotal.Text) - Convert.ToDouble(txtsubtotal.Text) * des).ToString();
                }*/
                RaiseEvent(new RoutedEventArgs(IncreaseClickedEvent));
            }
        }
        private void btnBuscarVenta_Click(object sender, RoutedEventArgs e)
        {

            if (txtidventa.Text.Equals(""))
            {
                MessageBox.Show("Ingresar idventa", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (txtidProducto.Text.Equals(""))
            {
                MessageBox.Show("Ingresar idProducto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (fechaventa.Text.Equals(""))
            {
                MessageBox.Show("Ingresar Fecha", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                int n;
                bool isNumeric = int.TryParse(txtidventa.Text, out n);
                if (isNumeric)
                {

                    ventasFacade ventFac = new ventasFacade();
                    List<MVentas> listaVentaDevolucion = ventFac.getVentasForDevolucion(Convert.ToInt32(txtidventa.Text), txtidProducto.Text, Convert.ToDateTime(fechaventa.Text));
                    var rows = GetDataGridRows(datagridVentas);
                    if (listaVentaDevolucion.Count != 0)
                    {
                        venta.Clear();
                        datagridVentas.ItemsSource = venta;
                        //llenar datagridVenta para devoulcion
                        foreach (var item in listaVentaDevolucion)
                        {
                            ProductoFacade prodFobtener = new ProductoFacade();
                            Producto Prod = new Producto();
                            Prod = prodFobtener.getProductosByID(item.idProducto);
                            int p = ToEntero(Prod.precio, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            string precio = p.ToString("#,#", CultureInfo.InvariantCulture);
                            int t = ToEntero(item.total.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            string total = t.ToString("#,#", CultureInfo.InvariantCulture); ;
                            vtemp = new VentaTemporal(Convert.ToInt32(item.idVenta), item.idProducto, Prod.nombre, precio, item.cantidad.ToString(), "1", total.ToString());
                            venta.Add(vtemp);
                            cantidad = cantidad + 1;
                            total = total + Convert.ToInt32(item.total);

                            //ltotal.Content = Prod.precio;
                            int st = ToEntero(item.total.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            string stp = st.ToString("#,#", CultureInfo.InvariantCulture);

                            ltotal.Content = stp;
                            TextBoxValue.Text = item.cantidad.ToString();
                        }
                        datagridVentas.ItemsSource = venta;
                    }
                    else
                    {
                        MessageBox.Show("No se han encontrado ventas con estos datos.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("No se han encontrado ventas con estos datos.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                }

            }

        }