Example #1
0
        public Boolean borrarCategoriaBynombre(string nombreCategoria)
        {
            Boolean borrar = false;

            try
            {
                //Borrar datos asociados a categoria


                ProductoFacade prodf = new ProductoFacade();
                prodf.borrarProductoBynombreCategoria(nombreCategoria);

                categoriaFacade ctf         = new categoriaFacade();
                string          idCategoria = ctf.getCategoriaByNombre(nombreCategoria);



                MySqlCommand cmdCategoria = new MySqlCommand("DELETE FROM categoria WHERE idCategoria =@idcategoria", getconexion.getConexion());
                cmdCategoria.Parameters.AddWithValue("@idCategoria", idCategoria);
                cmdCategoria.ExecuteNonQuery();
                borrar = true;
            }
            catch (Exception e)
            {
                borrar = false;
            }
            return(borrar);
        }
Example #2
0
        public List<Categoria> getCategoriaConProductosParaImprimirCodigos()
        {

            int totalCat = getTotalCategoria();
            ProductoFacade prodFac = new ProductoFacade();
            
            string consulta = "SELECT*FROM categoria";
            List<Categoria> listaCategoria = new List<Categoria>();

            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
            MySqlDataReader read = cmd.ExecuteReader();

            while (read.Read())
            {

                if (prodFac.getProductosBynombreCategoria(read.GetString(1)).Count > 0)
                {
                    listaCategoria.Add(new Categoria(read.GetInt32(0), read.GetString(1), read.GetDateTime(2)));
                }
            }
            getconexion.CerrarConexion();

            return listaCategoria;

        }
        public void llenarTablaProductobynombre(string nombre)
        {

            ProductoFacade prodF = new ProductoFacade();
            var itemList = new List<Producto>();
            var listaProd = prodF.getProductobyNombre(nombre);
            ListProductos.Clear();
            datagridProducto.ItemsSource = null;
            if (listaProd.Count > 0)
            {
                foreach (var item in listaProd)
                {
                    ListProductos.Add(new Producto { idProducto = item.idProducto, nombre = item.nombre, stock = item.stock, precioReal = item.precioReal, precio = item.precio, idCategoria = item.idCategoria, fecha = item.fecha });
                }

                datagridProducto.ItemsSource = ListProductos;
            }
            else
            {
                // DateTime fvacio = Convert.ToDateTime("15/08/2008");
                ListProductos.Add(new Producto { idProducto = "Sin productos", nombre = "", stock = "", precioReal = "", precio = "", idCategoria = 0 });

                datagridProducto.ItemsSource = ListProductos;

            }
        }
        public void llenarTablaProductobynombre(string nombre)
        {

            ProductoFacade prodF = new ProductoFacade();
            var itemList = new List<Producto>();
            var listaProd = prodF.getProductobyNombre(nombre);
            ListProductos.Clear();
            datagridProducto.ItemsSource = null;
            if (listaProd.Count > 0)
            {
                foreach (var item in listaProd)
                {
                    int p1 = ToEntero(item.precio, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    string m1 = p1.ToString("#,#", CultureInfo.InvariantCulture);
                    int st = ToEntero(item.stock, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    string stp = st.ToString("#,#", CultureInfo.InvariantCulture);
                    ListProductos.Add(new Producto { idProducto = item.idProducto, nombre = item.nombre, stock = stp, precio = m1, idCategoria = item.idCategoria, fecha = item.fecha });

                }

                datagridProducto.ItemsSource = ListProductos;
            }
            else
            {
                // DateTime fvacio = Convert.ToDateTime("15/08/2008");
                ListProductos.Add(new Producto { idProducto = "Sin productos", nombre = "", stock = "", precioReal = "", precio = "", idCategoria = 0 });

                datagridProducto.ItemsSource = ListProductos;

            }
        }
Example #5
0
        public List <Categoria> getCategoriaConProductosParaImprimirCodigos()
        {
            int            totalCat = getTotalCategoria();
            ProductoFacade prodFac  = new ProductoFacade();

            string           consulta       = "SELECT*FROM categoria";
            List <Categoria> listaCategoria = new List <Categoria>();

            MySqlCommand    cmd  = new MySqlCommand(consulta, getconexion.getConexion());
            MySqlDataReader read = cmd.ExecuteReader();

            while (read.Read())
            {
                if (prodFac.getProductosBynombreCategoria(read.GetString(1)).Count > 0)
                {
                    listaCategoria.Add(new Categoria(read.GetInt32(0), read.GetString(1), read.GetDateTime(2)));
                }
            }
            getconexion.CerrarConexion();

            return(listaCategoria);
        }
Example #6
0
        public List <MVentas> getCostoVentasbyIdProdSinNombreGroupByFechaAño(string idproducto, DateTime fecha)
        {
            MySqlDataReader rdr        = null;
            List <MVentas>  Listventas = new List <MVentas>();
            ProductoFacade  prodFac    = new ProductoFacade();
            string          consulta   = "";
            bool            existe     = prodFac.getExisteProductoByidProd(idproducto);

            if (existe)
            {
                //string consulta = "SELECT fecha, idProducto,sum(cantidad)as cantidad, sum(total) as total FROM db.venta  where idproducto=\"" + idproducto + "\" AND year(fecha)=" + fecha.Year + "  GROUP BY fecha;";
                consulta = "SELECT fecha,idproducto,(select precioReal from producto where idproducto=\"" + idproducto + "\")as precioReal,cantidad   FROM venta WHERE idproducto=\"" + idproducto + "\" AND year(fecha)=" + fecha.Year + "  GROUP BY fecha";
            }
            else
            {
                consulta = "SELECT fecha,idproducto,sum(cantidad)   FROM venta WHERE idproducto=\"" + idproducto + "\" AND year(fecha)=" + fecha.Year + "  GROUP BY fecha";
            }
            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());

            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                //Listventas.Add(new MVentas(rdr.GetDateTime(0), rdr.GetString(1), "Sin Nombre", rdr.GetString(2), rdr.GetInt32(3), Convert.ToInt32(rdr.GetInt32(2)) * rdr.GetInt32(3), 0));
                if (existe)
                {
                    Listventas.Add(new MVentas(rdr.GetDateTime(0), rdr.GetString(1), "Sin Nombre", rdr.GetString(2), rdr.GetInt32(3), Convert.ToInt32(rdr.GetInt32(2)) * rdr.GetInt32(3), 0));
                }
                else
                {
                    Listventas.Add(new MVentas(rdr.GetDateTime(0), rdr.GetString(1), "Sin Nombre", "0", rdr.GetInt32(2), 0, 0));
                }
            }
            getconexion.CerrarConexion();

            return(Listventas);
        }
        private void btnEditarProducto_Click(object sender, RoutedEventArgs e)
        {
            if (datagridProducto.SelectedItem != null)
            {
                if (datagridProducto.SelectedItem is Producto)
                {
                    var row = (Producto)datagridProducto.SelectedItem;

                    if (row != null)
                    {
                        //MessageBox.Show(row.nombre);
                        btnGuardarProducto.Visibility = Visibility.Hidden;
                        btncancelarEditarProd.Visibility = Visibility.Visible;
                        btnGuardarActualizarProducto.Visibility = Visibility.Visible;
                        txtcodprod.Text = row.idProducto;
                        txtnombreproducto.Text = row.nombre;
                        txtstock.Text = row.stock;
                        int pR = ToEntero(row.precioReal, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                        txtprecioReal.Text = pR.ToString("#,#", CultureInfo.InvariantCulture);


                        int p = ToEntero(row.precio, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                        txtprecio.Text = p.ToString("#,#", CultureInfo.InvariantCulture);

                        ProductoFacade prodF = new ProductoFacade();
                        categoriaFacade catFac = new categoriaFacade();
                        string nombreCat = catFac.getCategoriaById(prodF.getIdCatbyidProd(row.idProducto));
                        //MessageBox.Show(nombreCat);
                        cbCategoria.SelectedValue = nombreCat;
                        cbTipoCodigo.IsEnabled = false;
                        txtcodprod.IsEnabled = false;

                    }
                }
            }
            else
            {
                MessageBox.Show("Seleccionar Producto a editar", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

            }
        }
        private void btnGuardarActualizarProducto_Click(object sender, RoutedEventArgs e)
        {

            if (!string.IsNullOrWhiteSpace(txtnombreproducto.Text))
            {
                if (!string.IsNullOrWhiteSpace(txtstock.Text))
                {
                    if (!string.IsNullOrWhiteSpace(txtprecioReal.Text))
                    {
                        if (!string.IsNullOrWhiteSpace(txtprecio.Text))
                        {
                            int compra = ToEntero(txtprecioReal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            int venta = ToEntero(txtprecio.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            
                            if (compra < venta)
                            {
                                //MessageBox.Show(val.ToString().Length.ToString());
                                if (cbCategoria.Items.Count > 0)
                                {

                                    ProductoFacade prodF = new ProductoFacade();

                                    string codProd = txtcodprod.Text;
                                    string nombreProd = txtnombreproducto.Text;
                                    string nombreCat = cbCategoria.SelectedValue.ToString();
                                    int st = ToEntero(txtstock.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                    string stock = st.ToString();
                                    int pR = ToEntero(txtprecioReal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                    string precioReal = pR.ToString();
                                    int p = ToEntero(txtprecio.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                    string precio = p.ToString();
                                    //string res=prodF.GuardarProducto()

                                    //Agregar idCategoria al idProducto + el numItem
                                    ProductoFacade prodFCod = new ProductoFacade();
                                    categoriaFacade catFCod = new categoriaFacade();

                                    //verificar si cod es generado o ingresado por usuario
                                    int generado = prodF.getIdGenerado(txtcodprod.Text);
                                    DateTime fechaactual = DateTime.Now.Date;

                                    //actualizar con id que habia ingresado el usuario
                                    string res = prodF.ActualizarProducto(txtcodprod.Text, txtcodprod.Text, nombreProd, stock, precioReal, precio, nombreCat, fechaactual);
                                    if (res.Equals(""))
                                    {
                                        MessageBox.Show("Producto actualizado correctamente!", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                        limpiarTxtProducto();
                                        btnGuardarProducto.Visibility = Visibility.Visible;
                                        btncancelarEditarProd.Visibility = Visibility.Hidden;
                                        btnGuardarActualizarProducto.Visibility = Visibility.Hidden;
                                        llenarTablaProductoBynombreCat(nombreCat);
                                        cbTipoCodigo.IsEnabled = true;
                                        tabCodigos.actualizarArbolyTablaProductos();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Error al actualizar producto:" + res + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);

                                    }


                                }
                                else
                                {
                                    MessageBox.Show("Ingresar al menos 1 categoria!", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                                }
                            }
                            else
                            {
                                MessageBox.Show("Precio de venta debe ser mayor a precio de compra(?!)", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                            }
                        }
                        else
                        {
                            MessageBox.Show("Ingresar precio venta a producto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }

                    }
                    else
                    {
                        MessageBox.Show("Ingresar precio compra a producto!", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }

                }
                else
                {
                    MessageBox.Show("Ingresar stock a producto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                }

            }
            else
            {
                MessageBox.Show("Ingresar nombre a producto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

        }
Example #9
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);
            }

        }
Example #10
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 txtBuscarProducto_TextChanged(object sender, TextChangedEventArgs e)
        {

            ProductoFacade cf = new ProductoFacade();
            List<Producto> listGetCliente = new List<Producto>();

            listGetCliente = cf.getProductobyNombre(txtbuscarProducto.Text);
            if (listGetCliente.Count > 0)
            {
                //listGetCliente = cf.getClientesbyNombre(txtBuscarCliente.Text);
                llenarTablaProductobynombre(txtbuscarProducto.Text);
                //MessageBox.Show("Por nombre 0");
            }
            else
            {

                llenarTablaProductobyidCodigo(txtbuscarProducto.Text);
                //MessageBox.Show("por rut  0");
            }
            //MessageBox.Show("buscar");

        }
Example #12
0
        private void btnproductosXrubro_Click(object sender, RoutedEventArgs e)
        {

            categoriaFacade catFac1 = new categoriaFacade();

            int hay = catFac1.getTotalCategoriabyMes(MesRubroProd);
            if (!string.IsNullOrEmpty(month))
            {
                if (hay > 0)
                {

                    //buscar productos que fueron ingresados o modificados dentro de la fecha indicada
                    ProductoFacade prodFac = new ProductoFacade();
                    List<Producto> listProductoMes = prodFac.getALLProductosbyFechaMes(Convert.ToDateTime(month));
                    //MessageBox.Show(listProductoMes.Count.ToString());
                    //categorizar productos y obtener total de costo de compra en reporte

                    if (listProductoMes.Count > 0)
                    {
                        SaveFileDialog exportSaveFileDialog = new SaveFileDialog();
                        exportSaveFileDialog.Title = "Guardar reporte de costo para productos adquiridos";
                        exportSaveFileDialog.Filter = "PDF(*.pdf)|*.pdf";
                        exportSaveFileDialog.FileName = "ReporteCostoProdAdquiridos";
                        exportSaveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        if (exportSaveFileDialog.ShowDialog() == true)
                        {

                            string tempIdpro = "";

                            int dineroTotalbyCat = 0;
                            List<Producto> listProductoConCategoria = listProductoMes;

                            foreach (var item in listProductoMes)
                            {
                                if (!tempIdpro.Equals(item.idProducto))
                                {

                                    Document doc = new Document(PageSize.LETTER, 50, 50, 50, 50);
                                    PdfWriter writer = null;
                                    // Indicamos donde vamos a guardar el documento
                                    try
                                    {
                                        writer = PdfWriter.GetInstance(doc, new FileStream(exportSaveFileDialog.FileName, FileMode.Create));
                                        doc.AddCreator("Magnolia");
                                        doc.Open();
                                        iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlLogo, System.Drawing.Imaging.ImageFormat.Png);
                                        imagen.Alignment = Element.ALIGN_CENTER;
                                        imagen.ScaleToFit(120f, 120f);
                                        doc.Add(imagen);
                                        doc.Add(Chunk.NEWLINE);

                                        iTextSharp.text.Font _fontTitulo = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 25, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);


                                        iTextSharp.text.Paragraph titulo = new iTextSharp.text.Paragraph("Reporte de costo ventas mensuales");
                                        titulo.Alignment = Element.ALIGN_CENTER;
                                        titulo.Font = _fontTitulo;
                                        doc.Add(titulo);
                                        doc.Add(Chunk.NEWLINE);

                                        iTextSharp.text.Paragraph dgeneral = new iTextSharp.text.Paragraph("Detalles general");
                                        dgeneral.Alignment = Element.ALIGN_LEFT;

                                        //doc.AddTitle("Reporte de MVentas");
                                        iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);


                                        //////////////////////////////////////
                                        ///////Tabla especificos    //////////
                                        /////////////////////////////////////

                                        categoriaFacade catFacEsp = new categoriaFacade();
                                        ProductoFacade prodFacEsp = new ProductoFacade();
                                        ventasFacade ventasFacEsp = new ventasFacade();
                                        PdfPTable tblEspecifico = new PdfPTable(5);

                                        iTextSharp.text.Paragraph despecifico = new iTextSharp.text.Paragraph("Detalles Especificos");
                                        despecifico.Alignment = Element.ALIGN_LEFT;
                                        //LLenar tabla especifico 
                                        PdfPCell clFechaEsp = new PdfPCell();
                                        //PdfPCell clidprod = new PdfPCell();
                                        PdfPCell clnombreprod = new PdfPCell();
                                        PdfPCell clPrecioReal = new PdfPCell();
                                        PdfPCell clCant = new PdfPCell();
                                        PdfPCell cltotalEsp = new PdfPCell();

                                        listProductoConCategoria = listProductoConCategoria.OrderByDescending(i => i.idCategoria).ToList();
                                        //MessageBox.Show("TotalProductos:" + listProductoConCategoria.Count().ToString());
                                        var q = from x in listProductoConCategoria
                                                group x.idCategoria by x.idCategoria into g
                                                let count = g.Count()
                                                /*orderby count descending*/
                                                select new { Value = g.Key, Count = count };


                                        int posList = 0;
                                        foreach (var x in q)
                                        {
                                            tblEspecifico.WidthPercentage = 100;
                                            tblEspecifico.HorizontalAlignment = Element.ALIGN_LEFT;
                                            PdfPCell clnombreCat = new PdfPCell(new Phrase(catFacEsp.getNombreCategoriaById(x.Value.ToString()), _standardFont));
                                            clnombreCat.Colspan = 2;
                                            PdfPCell h1 = new PdfPCell(new Phrase(""));
                                            PdfPCell h2 = new PdfPCell(new Phrase(""));
                                            PdfPCell h3 = new PdfPCell(new Phrase(""));
                                            h1.Border = 0;
                                            h2.Border = 0;
                                            h3.Border = 0;
                                            tblEspecifico.AddCell(clnombreCat);
                                            tblEspecifico.AddCell(h1);
                                            tblEspecifico.AddCell(h2);
                                            tblEspecifico.AddCell(h3);

                                            clFechaEsp = new PdfPCell(new Phrase("Fecha", _standardFont));
                                            //clidprod = new PdfPCell(new Phrase("IDProducto", _standardFont));
                                            clnombreprod = new PdfPCell(new Phrase("Nombre", _standardFont));
                                            clPrecioReal = new PdfPCell(new Phrase("Precio Compra", _standardFont));
                                            clCant = new PdfPCell(new Phrase("Stock", _standardFont));
                                            //PdfPCell clTipoPag = new PdfPCell(new Phrase("Tipo Pago", _standardFont));
                                            cltotalEsp = new PdfPCell(new Phrase("Total", _standardFont));

                                            tblEspecifico.AddCell(clFechaEsp);
                                            // tblEspecifico.AddCell(clidprod);
                                            tblEspecifico.AddCell(clnombreprod);
                                            tblEspecifico.AddCell(clPrecioReal);
                                            tblEspecifico.AddCell(clCant);
                                            //tblEspecifico.AddCell(clTipoPag);
                                            tblEspecifico.AddCell(cltotalEsp);

                                            for (int i = 0; i < x.Count; i++)
                                            {
                                                var v = listProductoConCategoria[posList];

                                                clFechaEsp = new PdfPCell(new Phrase(v.fecha.ToString("y"), _standardFont));
                                                //clidprod = new PdfPCell(new Phrase(x.Value.ToString(), _standardFont));
                                                // clidprod = new PdfPCell(new Phrase(v.idProducto.ToString(), _standardFont));

                                                //clnombreprod = new PdfPCell(new Phrase(v.idCategoria.ToString() + ":" + v.nombreProducto, _standardFont));
                                                clnombreprod = new PdfPCell(new Phrase(v.nombre.ToString(), _standardFont));
                                                //clnombreprod= new PdfPCell(new Phrase(prodFacEsp.getnombreProdbyidProd(v.idProducto), _standardFont));
                                                clPrecioReal = new PdfPCell(new Phrase(v.precioReal.ToString(), _standardFont));
                                                clCant = new PdfPCell(new Phrase(v.stock.ToString(), _standardFont));
                                                //clTipoPag = new PdfPCell(new Phrase("", _standardFont));
                                                cltotalEsp = new PdfPCell(new Phrase(v.total.ToString(), _standardFont));

                                                tblEspecifico.AddCell(clFechaEsp);
                                                //tblEspecifico.AddCell(clidprod);
                                                tblEspecifico.AddCell(clnombreprod);
                                                tblEspecifico.AddCell(clPrecioReal);
                                                tblEspecifico.AddCell(clCant);
                                                //tblEspecifico.AddCell(clTipoPag);
                                                tblEspecifico.AddCell(cltotalEsp);
                                                dineroTotalbyCat = dineroTotalbyCat + v.total;
                                                tempIdpro = v.idProducto;
                                                posList = posList + 1;
                                            }
                                            //#################################
                                            //en cada categoria 
                                            //#################################
                                            clFechaEsp = new PdfPCell(new Phrase("", _standardFont));
                                            ////clidprod = new PdfPCell(new Phrase("", _standardFont));
                                            clnombreprod = new PdfPCell(new Phrase("", _standardFont));
                                            clPrecioReal = new PdfPCell(new Phrase("", _standardFont));
                                            clCant = new PdfPCell(new Phrase("Subtotal($)", _standardFont));
                                            //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                            cltotalEsp = new PdfPCell(new Phrase(dineroTotalbyCat.ToString(), _standardFont));
                                            dineroTotalbyCat = 0;

                                            clFechaEsp.Border = 0;
                                            // clidprod.Border = 0;
                                            clnombreprod.Border = 0;
                                            clPrecioReal.Border = 0;
                                            clCant.Border = 1;
                                            cltotalEsp.Border = 1;



                                            tblEspecifico.AddCell(clFechaEsp);
                                            //tblEspecifico.AddCell(clidprod);
                                            tblEspecifico.AddCell(clnombreprod);
                                            tblEspecifico.AddCell(clPrecioReal);
                                            tblEspecifico.AddCell(clCant);
                                            //tblEspecifico.AddCell(clTipoPag);
                                            tblEspecifico.AddCell(cltotalEsp);


                                            /////////////////////////////////////////////
                                            clFechaEsp = new PdfPCell(new Phrase("", _standardFont));
                                            //clidprod = new PdfPCell(new Phrase("", _standardFont));
                                            clnombreprod = new PdfPCell(new Phrase("", _standardFont));
                                            clCant = new PdfPCell(new Phrase("", _standardFont));
                                            clPrecioReal = new PdfPCell(new Phrase("", _standardFont));
                                            //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                            cltotalEsp = new PdfPCell(new Phrase("", _standardFont));
                                            clFechaEsp.Border = 0;
                                            //clidprod.Border = 0;
                                            clnombreprod.Border = 0;
                                            clPrecioReal.Border = 0;
                                            clCant.Border = 0;
                                            cltotalEsp.Border = 0;

                                            cltotalEsp.FixedHeight = 30f;
                                            clFechaEsp.FixedHeight = 30f;
                                            // clidprod.FixedHeight = 30f;
                                            clnombreprod.FixedHeight = 30f;
                                            clPrecioReal.FixedHeight = 30f;
                                            clCant.FixedHeight = 30f;
                                            cltotalEsp.FixedHeight = 30f;

                                            tblEspecifico.AddCell(clFechaEsp);
                                            // tblEspecifico.AddCell(clidprod);
                                            tblEspecifico.AddCell(clnombreprod);
                                            tblEspecifico.AddCell(clPrecioReal);
                                            tblEspecifico.AddCell(clCant);
                                            //tblEspecifico.AddCell(clTipoPag);
                                            tblEspecifico.AddCell(cltotalEsp);

                                        }
                                        //#######################################################
                                        //######            DETALLES GENERALES       ############
                                        //#######################################################

                                        PdfPTable tblGenerales = new PdfPTable(3);
                                        //doc.SetMargins(0f, 0f, 0f, 0f);
                                        tblGenerales.HorizontalAlignment = Element.ALIGN_LEFT;
                                        // Configuramos el título de las columnas de la tabla
                                        PdfPCell clFecha = new PdfPCell(new Phrase("Mes", _standardFont));
                                        PdfPCell clCat = new PdfPCell(new Phrase("Categoria", _standardFont));
                                        PdfPCell clSubtotal = new PdfPCell(new Phrase("Subtotal", _standardFont));
                                        tblGenerales.AddCell(clFecha);
                                        tblGenerales.AddCell(clCat);
                                        tblGenerales.AddCell(clSubtotal);

                                        categoriaFacade catFac = new categoriaFacade();


                                        int subtotal = 0;
                                        int total = 0;
                                        int posListG = 0;
                                        //Agrupar por categoria los idproducto

                                        foreach (var x in q)
                                        {
                                            for (int i = 0; i < x.Count; i++)
                                            {
                                                var v = listProductoConCategoria[posListG];


                                                subtotal = subtotal + v.total;
                                                posListG = posListG + 1;
                                            }
                                            total = total + subtotal;
                                            clFecha = new PdfPCell(new Phrase(Convert.ToDateTime(month).ToString("y"), _standardFont));
                                            clCat = new PdfPCell(new Phrase(catFac.getNombreCategoriaById(x.Value.ToString()), _standardFont));
                                            clSubtotal = new PdfPCell(new Phrase(subtotal.ToString(), _standardFont));
                                            tblGenerales.AddCell(clFecha);
                                            tblGenerales.AddCell(clCat);
                                            tblGenerales.AddCell(clSubtotal);
                                            subtotal = 0;
                                        }


                                        clFecha = new PdfPCell(new Phrase("", _standardFont));
                                        clCat = new PdfPCell(new Phrase("Total Costo  Producto Adquiridos", _standardFont));
                                        clSubtotal = new PdfPCell(new Phrase(total.ToString(), _standardFont));

                                        clFecha.Border = 0;
                                        tblGenerales.AddCell(clFecha);
                                        tblGenerales.AddCell(clCat);
                                        tblGenerales.AddCell(clSubtotal);



                                        doc.Add(dgeneral);
                                        doc.Add(Chunk.NEWLINE);
                                        doc.Add(tblGenerales);
                                        doc.Add(Chunk.NEWLINE);
                                        doc.Add(despecifico);
                                        doc.Add(new Chunk("\n"));
                                        doc.Add(tblEspecifico);
                                        doc.Add(new Chunk("\n"));






                                        doc.Close();
                                        writer.Close();




                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.ToString());
                                    }
                                    finally
                                    {
                                        doc.Close();
                                        writer.Close();
                                    }

                                }

                            }
                            System.Diagnostics.Process.Start(exportSaveFileDialog.FileName);
                        }




                    }
                    else
                    {
                        MessageBox.Show("No hay Productos ingresados", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Seleccionar mes para generar reporte", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Example #13
0
        //############################################################
        //################           Codigo barra       ##################
        //############################################################

        public void llenarTablaProductoCodBarra()
        {

            ProductoFacade prodF = new ProductoFacade();
            
            ListProductos.Clear();
            datagridProducto_Imprimir.ItemsSource = null;
            var ListProd = prodF.getProductos();

            if (ListProd.Count > 0)
            {
                foreach (var item in ListProd)
                {
                    int p1 = ToEntero(item.precio, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    string m1 = p1.ToString("#,#", CultureInfo.InvariantCulture);
                    int st = ToEntero(item.stock, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    string stp = st.ToString("#,#", CultureInfo.InvariantCulture);
                    ListProductos.Add(new Producto { idProducto = item.idProducto, nombre = item.nombre, stock = stp, precio = m1, idCategoria = item.idCategoria });
                }

                //CollectionViewSource itemCollectionViewSource;
                //itemCollectionViewSource = (CollectionViewSource)(FindResource("ItemCollectionViewSourceAllProductoImprimir"));
                datagridProducto_Imprimir.ItemsSource = ListProductos;

            }
            else
            {
                ListProductos.Add(new Producto { idProducto = "Sin productos", nombre = "", stock = "", precio = "", idCategoria = 0 });


                /*CollectionViewSource itemCollectionViewSource;
                itemCollectionViewSource = (CollectionViewSource)(FindResource("ItemCollectionViewSourceAllProductoImprimir"));
                itemCollectionViewSource.Source = ListProductos;*/
                datagridProducto_Imprimir.ItemsSource = ListProductos;



            }
        }
        //############################################################
        //################           CATEGORIA       ##################
        //############################################################
        public void llenarTablaProductoBynombreCat(string nombreCategoria)
        {
            ProductoFacade prodF = new ProductoFacade();
            var itemList = new List<Producto>();
            var listaProd = prodF.getProductosBynombreCategoria(nombreCategoria);
            ListProductos.Clear();
            datagridProducto.ItemsSource = null;
            if (listaProd.Count > 0)
            {
                foreach (var item in listaProd)
                {
                    int p = ToEntero(item.precioReal, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    string m = p.ToString("#,#", CultureInfo.InvariantCulture);
                    int p1 = ToEntero(item.precio, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    string m1 = p1.ToString("#,#", CultureInfo.InvariantCulture);
                    int st = ToEntero(item.stock, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    string stp = st.ToString("#,#", CultureInfo.InvariantCulture);
                    ListProductos.Add(new Producto { idProducto = item.idProducto, nombre = item.nombre, stock = stp, precioReal = m, precio = m1, idCategoria = item.idCategoria, fecha = item.fecha });
                }

                datagridProducto.ItemsSource = ListProductos;
                btnEditarProducto.IsEnabled = true;
                btnEliminarProducto.IsEnabled = true;
                btnEliminarTodoProducto.IsEnabled = true;
            }
            else
            {
                ListProductos.Add(new Producto { idProducto = "Categoria sin productos", nombre = "", stock = "", precioReal = "", precio = "", idCategoria = 0 });

                datagridProducto.ItemsSource = ListProductos;
                btnEditarProducto.IsEnabled = false;
                btnEliminarProducto.IsEnabled = false;
                btnEliminarTodoProducto.IsEnabled = false;

            }

        }
Example #15
0
        private string[] crearPdf(int numEtiq,string idcodigo)
        {
            string[] correct = new string[2] ;
            ProductoFacade prodF = new ProductoFacade();
            string nombreProd = prodF.getnombreProdbyidProd(idcodigo);
            try
            {
                //Etiqueta para rollo con 1 columnas de mica
                if (numEtiq == 0)
                {
                    // Creamos el documento con el tamaño de página tradicional
                    Document doc = new Document(PageSize.LETTER);
                    // Indicamos donde vamos a guardar el documento
                    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(urlpdf_1col+"//"+nombreProd+".pdf", FileMode.Create));
                    
                    doc.AddCreator("Magnolia");
                    doc.Open();
                    BaseFont serif = BaseFont.CreateFont(@"C:\Windows\Fonts\micross.ttf", "Identity-H", BaseFont.EMBEDDED);
                    iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(serif, Convert.ToInt32(txtTamanoFuente.Text), iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);

                    int col = 1;
                    int row = Convert.ToInt32(txtfila.Text);
                    PdfPTable tblPrueba = new PdfPTable(col);
                    doc.SetMargins(0f, 0f, 0f, 0f);
                    tblPrueba.HorizontalAlignment = Element.ALIGN_CENTER;
                    tblPrueba.WidthPercentage = 50;
                    iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlimagen);
                    imagen.Alignment = Element.ALIGN_CENTER;
                    imagen.ScaleToFit(140f, 120f);

                    string txtsobreBarra = "";
                    if (chkGenerateLabel.IsChecked.Value)
                    {
                        txtsobreBarra = txtSobreBarra.Text;
                    }

                    for (int c = 0; c < col; c++)
                    {
                        for (int f = 0; f < row; f++)
                        {
                            PdfPCell clLabel = new PdfPCell(new Phrase(txtsobreBarra, _standardFont));
                            clLabel.HorizontalAlignment = Element.ALIGN_CENTER;
                            clLabel.BorderWidth = 0;

                            PdfPCell clNombre = new PdfPCell(imagen);
                            clNombre.HorizontalAlignment = Element.ALIGN_CENTER;
                            clNombre.BorderWidth = 0;
                            clNombre.PaddingBottom = 15;
                            tblPrueba.AddCell(clLabel);
                            tblPrueba.AddCell(clNombre);
                        }
                    }
                    doc.Add(tblPrueba);
                    doc.Close();
                    //MessageBox.Show(urlpdf);
                    writer.Close();
                    //Etiqueta para rollo con 3 columnas de  mica
                    
                    correct[0] = urlpdf_1col + "//" + nombreProd + ".pdf";
                    correct[1] = urlpdf_1col;
                }
                else if (numEtiq == 1)
                {
                    Document doc = new Document(PageSize.LETTER, 10f, 10f, 10f, 0f);
                    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(urlpdf_3col + "//"+nombreProd+".pdf", FileMode.Create));
                    
                    doc.AddTitle("pdf");
                    doc.AddCreator("Magnolia");
                    doc.Open();
                    doc.Add(Chunk.NEWLINE);
                    BaseFont serif = BaseFont.CreateFont(@"C:\Windows\Fonts\micross.ttf", "Identity-H", BaseFont.EMBEDDED);
                    iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(serif, Convert.ToInt32(txtTamanoFuente.Text), iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);
                    int col = 3;
                    double fk = (double)Convert.ToInt32(txtfila.Text) / col;
                    int row = Convert.ToInt32(Math.Ceiling(fk));
                    PdfPTable tblPrueba = new PdfPTable(col);
                    tblPrueba.WidthPercentage = 100;
                    iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlimagen);
                    imagen.BorderWidth = 0;
                    imagen.Alignment = Element.ALIGN_CENTER;
                    imagen.ScaleToFit(150f, 150f);

                    string txtsobreBarra = "";
                    if (chkGenerateLabel.IsChecked.Value)
                    {
                        txtsobreBarra = txtSobreBarra.Text;
                    }

                    for (int c = 0; c < col; c++)
                    {
                        for (int f = 0; f < row; f++)
                        {

                            PdfPCell clNombre = new PdfPCell { };
                            clNombre.BorderWidth = 0;
                            clNombre.Padding = 13;
                            clNombre.HorizontalAlignment = Element.ALIGN_CENTER;
                            iTextSharp.text.Paragraph textsobre = new iTextSharp.text.Paragraph(new Phrase(txtsobreBarra, _standardFont));
                            textsobre.Alignment = 1;
                            clNombre.AddElement(textsobre);
                            clNombre.AddElement(imagen);
                            tblPrueba.AddCell(clNombre);
                        }
                    }
                    doc.Add(tblPrueba);
                    doc.Close();
                    writer.Close();
                    //MessageBox.Show(urlpdf);
                    correct[0] = urlpdf_3col + "//" + nombreProd + ".pdf";
                    correct[1] = urlpdf_3col;
                }
                else if (numEtiq == 2)
                {

                    if (!string.IsNullOrEmpty(txtleft.Text))
                    {
                        if (!string.IsNullOrEmpty(txtright.Text))
                        {
                            if (!string.IsNullOrEmpty(txttop.Text))
                            {
                                if (!string.IsNullOrEmpty(txtbotom.Text))
                                {
                                    float left = float.Parse(txtleft.Text);
                                    float right = float.Parse(txtright.Text);
                                    float top = float.Parse(txttop.Text);
                                    float bottom = float.Parse(txtbotom.Text);


                                    Document doc = new Document(PageSize.LETTER, left, right, top, bottom);
                                    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(urlpdf_pers + "//"+nombreProd+".pdf", FileMode.Create));
                                    //correct = urlpdf_pers + "//" + nombreProd + ".pdf";
                                    doc.AddTitle("pdf");
                                    doc.AddCreator("Magnolia");
                                    doc.Open();
                                    doc.Add(Chunk.NEWLINE);
                                    //System.Drawing.Font f=  new System.Drawing.Font("Microsoft Sans Serif", 10, System.Drawing.FontStyle.Regular);
                                    //FontFactory.GetFont("Microsoft Sans Serif", 10)
                                    BaseFont serif = BaseFont.CreateFont(@"C:\Windows\Fonts\micross.ttf", "Identity-H", BaseFont.EMBEDDED);
                                    iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(serif, Convert.ToInt32(txtTamanoFuente.Text), iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);

                                    int col = Convert.ToInt32(txtcolumnas.Text); ;
                                    double fk = (double)Convert.ToInt32(txtfila.Text) / col;
                                    int row = Convert.ToInt32(Math.Ceiling(fk));
                                    PdfPTable tblPrueba = new PdfPTable(col);
                                    tblPrueba.WidthPercentage = 100;

                                    iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlimagen);
                                    imagen.BorderWidth = 0;
                                    imagen.Alignment = Element.ALIGN_CENTER;
                                    imagen.ScaleToFit(150f, 150f);
                                    string txtsobreBarra = "";
                                    if (chkGenerateLabel.IsChecked.Value)
                                    {
                                        txtsobreBarra = txtSobreBarra.Text;
                                    }

                                    for (int c = 0; c < col; c++)
                                    {
                                        for (int f = 0; f < row; f++)
                                        {

                                            PdfPCell clNombre = new PdfPCell { };
                                            clNombre.BorderWidth = 0;
                                            clNombre.Padding = 13;
                                            clNombre.HorizontalAlignment = Element.ALIGN_CENTER;
                                            iTextSharp.text.Paragraph textsobre = new iTextSharp.text.Paragraph(new Phrase(txtsobreBarra, _standardFont));
                                            textsobre.Alignment = 1;
                                            clNombre.AddElement(textsobre);
                                            clNombre.AddElement(imagen);
                                            tblPrueba.AddCell(clNombre);
                                        }
                                    }
                                    doc.Add(tblPrueba);
                                    doc.Close();
                                    writer.Close();
                                    correct[0] = urlpdf_pers + "//" + nombreProd + ".pdf";
                                    correct[1] = urlpdf_pers;

                                }
                                else
                                {
                                    MessageBox.Show("Ingresar margen: Abajo", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                                }
                            }
                            else
                            {
                                MessageBox.Show("Ingresar margen: Arriba", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                            }
                        }
                        else
                        {
                            MessageBox.Show("Ingresar margen:Derecho", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                        }
                    }
                    else
                    {
                        MessageBox.Show("Ingresar margen:Izquierdo", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }

                }   return correct;
            }
            catch (Exception e)
            {
                MessageBox.Show("Cerrar PDf abierto:" + e.ToString(), "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                return correct;
            }
         
        }
Example #16
0
        private void btnGenerarCodBarra_Click(object sender, RoutedEventArgs e)
        {
            // MessageBox.Show(urlimagen);
            if (chboxNoAgrupada.IsChecked == true)
            {
                if (!string.IsNullOrEmpty(txtCodigoToImprimir.Text))
                {
                    int numeEti = listBoxEtiquetas.SelectedIndex;

                    if (numeEti == 0)
                    {
                        try
                        {
                            System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
                            folderDialog.SelectedPath = "C:\\";
                            folderDialog.Description = "Seleccionar carpeta donde se guardará el pdf con codigo generado";
                            System.Windows.Forms.DialogResult result = folderDialog.ShowDialog();

                            if (string.IsNullOrEmpty(urlpdf))
                            {
                                if (result.ToString() == "OK")
                                {
                                    urlpdf = folderDialog.SelectedPath + "\\pdf";
                                    if (!System.IO.Directory.Exists(urlpdf))
                                    {
                                        System.IO.Directory.CreateDirectory(urlpdf);
                                    }
                                    txtcolumnas.IsEnabled = false;
                                    txtcolumnas.Text = "1";
                                    GenerarCodBarra(0);

                                }
                            }
                            else 
                            {
                                txtcolumnas.IsEnabled = false;
                                txtcolumnas.Text = "1";
                                GenerarCodBarra(0);

                            }
                        

                           

                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error List etiqueta:" + ex.Message + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                        }

                    }
                    else if (numeEti == 1)
                    {
                        try
                        {
                            txtcolumnas.IsEnabled = false;
                            txtcolumnas.Text = "3";


                            GenerarCodBarra(1);

                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error List etiqueta:" + ex.Message + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                        }

                    }
                    else if (numeEti == 2)
                    {//Etiqueta personalizada
                        try
                        {
                            txtcolumnas.IsEnabled = true;

                            GenerarCodBarra(2);

                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error List etiqueta:" + ex.Message + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                        }

                    }
                }
                else
                {
                    MessageBox.Show("Ingresar codigo de producto para generar codigo de barra", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                }

            }else if(chboxAgrupada.IsChecked==true)
            {
                //verificar si hay productos en bd
                ProductoFacade prodFac = new ProductoFacade();
                List<Producto> listaProd = prodFac.getProductos();

                if (listaProd.Count>0)
                {
                    int numeEti = listBoxEtiquetas.SelectedIndex;

                    if (numeEti == 0)
                    {

                        System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
                        folderDialog.SelectedPath = "C:\\";
                        folderDialog.Description = "Seleccionar carpeta donde se guardarán los pdfs con codigos asociados a cada categoria";
                        System.Windows.Forms.DialogResult result = folderDialog.ShowDialog();
                        string urlG = "";
                        if (result.ToString() == "OK")
                        {

                            try
                            {
                                urlG = folderDialog.SelectedPath + "\\Codigos\\";
                                if (!System.IO.Directory.Exists(urlG))
                                {
                                    System.IO.Directory.CreateDirectory(urlG);
                                }

                                txtcolumnas.IsEnabled = false;
                                txtcolumnas.Text = "1";
                                //crear x pdf con nombre de categorias en la url seleccionadad

                                categoriaFacade catFac = new categoriaFacade();
                                //obtener listCategoria que tengan productos
                                List<Categoria> listCat = catFac.getCategoriaConProductosParaImprimirCodigos();
                                //MessageBox.Show(listCat.Count.ToString());
                                //RECORRER LISTA DE CATEGORIA Y OBTENER NOMBRE Y PRODUCTO ASOCIADO

                                int W = Convert.ToInt32(this.txtAncho.Text.Trim());
                                int H = Convert.ToInt32(this.txtAlto.Text.Trim());
                                b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
                                BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE128;
                                //b.LabelFont = new Font("Microsoft Sans Serif", 10, System.Drawing.FontStyle.Regular);
                                try
                                {
                                    foreach (var cat in listCat)
                                    {
                                        if (type != BarcodeLib.TYPE.UNSPECIFIED)
                                        {
                                            b.IncludeLabel = true;
                                            b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                                            //b.AlternateLabel = "Texto";
                                            List<Producto> listProductos = prodFac.getProductosBynombreCategoria(cat.nombreCategoria);


                                            if (crearPdfCategorizado(urlG + cat.nombreCategoria, listProductos, 0))
                                            {
                                                //Cargar Pdf en vista
                                                //pdfViewer.LoadFile(urlpdf);
                                            }


                                        }//if
                                    }//foreach


                                }//try
                                catch (Exception ex)
                                {
                                    MessageBox.Show("Error al crear CodigoBarra:" + ex.Message + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                }//catch

                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Error List etiqueta:" + ex.Message + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                            System.Diagnostics.Process.Start(@urlG);
                        }


                    }
                    else if (numeEti == 1)
                    {
                        
                        //string folderpath = "";
                        //FolderBrowserDialog fbd=new FolderBrowserDialog();
                        //DialogResult dr=fbd.ShowDialog();

                        System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
                        folderDialog.SelectedPath = "C:\\";
                        folderDialog.Description = "Seleccionar carpeta donde se guardarán los pdfs con codigos asociados a cada categoria";
                        System.Windows.Forms.DialogResult result = folderDialog.ShowDialog();
                        string urlG = "";
                        if (result.ToString() == "OK")
                        {
                            
                            try
                            {
                                urlG = folderDialog.SelectedPath + "\\Codigos\\";
                                if (!System.IO.Directory.Exists(urlG))
                                {
                                    System.IO.Directory.CreateDirectory(urlG);
                                }

                                txtcolumnas.IsEnabled = false;
                                txtcolumnas.Text = "3";
                                //crear x pdf con nombre de categorias en la url seleccionadad

                                categoriaFacade catFac = new categoriaFacade();
                                //obtener listCategoria que tengan productos
                                List<Categoria> listCat = catFac.getCategoriaConProductosParaImprimirCodigos();
                                //MessageBox.Show(listCat.Count.ToString());
                                //RECORRER LISTA DE CATEGORIA Y OBTENER NOMBRE Y PRODUCTO ASOCIADO

                                int W = Convert.ToInt32(this.txtAncho.Text.Trim());
                                int H = Convert.ToInt32(this.txtAlto.Text.Trim());
                                b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
                                BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE128;
                                //b.LabelFont = new Font("Microsoft Sans Serif", 10, System.Drawing.FontStyle.Regular);
                                try
                                {
                                    foreach (var cat in listCat)
                                    {
                                        if (type != BarcodeLib.TYPE.UNSPECIFIED)
                                        {
                                            b.IncludeLabel = true;
                                            b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                                            //b.AlternateLabel = "Texto";
                                            List<Producto> listProductos = prodFac.getProductosBynombreCategoria(cat.nombreCategoria);

                                            
                                            if (crearPdfCategorizado(urlG + cat.nombreCategoria,listProductos, 1))
                                            {
                                                //Cargar Pdf en vista
                                                //pdfViewer.LoadFile(urlpdf);
                                            }


                                        }//if
                                    }//foreach
                                

                                }//try
                                catch (Exception ex)
                                {
                                    MessageBox.Show("Error al crear CodigoBarra:" + ex.Message + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                }//catch
                                
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Error List etiqueta:" + ex.Message + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                            System.Diagnostics.Process.Start(@urlG);
                        }

                    }
                    else if (numeEti == 2)
                    {//Etiqueta personalizada

                        System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
                        folderDialog.SelectedPath = "C:\\";
                        folderDialog.Description = "Seleccionar carpeta donde se guardarán los pdfs con codigos asociados a cada categoria";
                        System.Windows.Forms.DialogResult result = folderDialog.ShowDialog();
                        string urlG = "";
                        if (result.ToString() == "OK")
                        {

                            try
                            {
                                urlG = folderDialog.SelectedPath + "\\Codigos\\";
                                if (!System.IO.Directory.Exists(urlG))
                                {
                                    System.IO.Directory.CreateDirectory(urlG);
                                }

                                txtcolumnas.IsEnabled = true;
                                
                                //crear x pdf con nombre de categorias en la url seleccionadad

                                categoriaFacade catFac = new categoriaFacade();
                                //obtener listCategoria que tengan productos
                                List<Categoria> listCat = catFac.getCategoriaConProductosParaImprimirCodigos();
                                //MessageBox.Show(listCat.Count.ToString());
                                //RECORRER LISTA DE CATEGORIA Y OBTENER NOMBRE Y PRODUCTO ASOCIADO

                                int W = Convert.ToInt32(this.txtAncho.Text.Trim());
                                int H = Convert.ToInt32(this.txtAlto.Text.Trim());
                                b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
                                BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE128;
                                //b.LabelFont = new Font("Microsoft Sans Serif", 10, System.Drawing.FontStyle.Regular);
                                try
                                {
                                    foreach (var cat in listCat)
                                    {
                                        if (type != BarcodeLib.TYPE.UNSPECIFIED)
                                        {
                                            b.IncludeLabel = true;
                                            b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                                            //b.AlternateLabel = "Texto";
                                            List<Producto> listProductos = prodFac.getProductosBynombreCategoria(cat.nombreCategoria);


                                            if (crearPdfCategorizado(urlG + cat.nombreCategoria, listProductos, 2))
                                            {
                                                //Cargar Pdf en vista
                                                //pdfViewer.LoadFile(urlpdf);
                                            }


                                        }//if
                                    }//foreach


                                }//try
                                catch (Exception ex)
                                {
                                    MessageBox.Show("Error al crear CodigoBarra:" + ex.Message + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                }//catch

                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Error List etiqueta:" + ex.Message + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                            System.Diagnostics.Process.Start(@urlG);
                        }


                    }
                }
                else
                {
                    MessageBox.Show("No hay productos registrados", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                }

            }
        }
Example #17
0
        private bool crearPdfCategorizadoSegunStock(string urlpdfcategorizado, List<Producto> listProducto, int numEtiq)
        {
            bool correct = false;
            try
            {
                /*CREAR UNA CARPETA CON CADA CATEGORIA Y DENTRO DE ELLA UN PDF CON CADA CODIGO SEGUN EL STOCK QUE TENGA */

                ProductoFacade prodFac = new ProductoFacade();
                //Etiqueta para rollo con 1 columnas de mica
                if (numEtiq == 0)
                {

                    //Debe ser dinamico para cada categoria
                    string urlCategoria = urlpdfcategorizado;
                    if (!System.IO.Directory.Exists(urlCategoria))
                    {
                        System.IO.Directory.CreateDirectory(urlCategoria);
                    }


                    //debe ir bucle de columnas y fila 
                    //mas nombre de cada producto como pdf

                    foreach (var prod in listProducto)
                    {
                        if (Convert.ToInt32(prod.stock) != 0)
                        {
                            string urlCategoriabyProd = urlCategoria + "\\" + prod.nombre;
                            Document doc = new Document(PageSize.LETTER);
                            // Indicamos donde vamos a guardar el documento
                           
                            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(urlCategoriabyProd + ".pdf", FileMode.Create));
                            doc.AddCreator("Magnolia");
                            doc.Open();
                            BaseFont serif = BaseFont.CreateFont(@"C:\Windows\Fonts\micross.ttf", "Identity-H", BaseFont.EMBEDDED);
                            iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(serif, Convert.ToInt32(txtTamanoFuente.Text), iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);

                            int col = 1;
                            int row = Convert.ToInt32(prod.stock);
                            PdfPTable tblPrueba = new PdfPTable(col);
                            doc.SetMargins(0f, 0f, 0f, 0f);
                            tblPrueba.HorizontalAlignment = Element.ALIGN_CENTER;
                            tblPrueba.WidthPercentage = 50;

                            for (int c = 0; c < col; c++)
                            {
                                int W = Convert.ToInt32(this.txtAncho.Text.Trim());
                                int H = Convert.ToInt32(this.txtAlto.Text.Trim());
                                b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
                                BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE128;
                                b.IncludeLabel = true;
                                b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                                b.Encode(type, prod.idProducto, W, H);
                                BarcodeLib.SaveTypes savetype = BarcodeLib.SaveTypes.PNG;
                                b.SaveImage(urlimagen, savetype);

                                iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlimagen);
                                imagen.BorderWidth = 0;
                                imagen.Alignment = Element.ALIGN_CENTER;
                                imagen.ScaleToFit(150f, 150f);

                                string txtsobreBarra = "";
                                if (chkGenerateLabel.IsChecked.Value)
                                {

                                    if (prod.nombre.Length > 25)
                                    {
                                        txtsobreBarra = prod.nombre.Substring(0, 25) + " $" + prod.precio;
                                    }
                                    else
                                    {
                                        txtsobreBarra = prod.nombre + " $" + prod.precio;
                                    }

                                }

                                for (int f = 0; f < row; f++)
                                {

                                    PdfPCell clNombre = new PdfPCell { };
                                    clNombre.BorderWidth = 0;
                                    clNombre.Padding = 13;
                                    clNombre.HorizontalAlignment = Element.ALIGN_CENTER;
                                    iTextSharp.text.Paragraph textsobre = new iTextSharp.text.Paragraph(new Phrase(txtsobreBarra, _standardFont));
                                    textsobre.Alignment = 1;
                                    clNombre.AddElement(textsobre);
                                    clNombre.AddElement(imagen);
                                    tblPrueba.AddCell(clNombre);
                                }


                            }


                            doc.Add(tblPrueba);
                            doc.Close();
                            writer.Close();
  correct = true;
                        }
                    }
                  

                }
                //Etiqueta para rollo con 3 columnas de  mica
                else if (numEtiq == 1)
                {
                    //Debe ser dinamico para cada categoria
                    string urlCategoria = urlpdfcategorizado;
                    if (!System.IO.Directory.Exists(urlCategoria))
                    {
                        System.IO.Directory.CreateDirectory(urlCategoria);
                    }


                    //debe ir bucle de columnas y fila 
                    //mas nombre de cada producto como pdf

                    foreach (var prod in listProducto)
                    {
                        if (Convert.ToInt32(prod.stock) != 0)
                        {
                            Document doc = new Document(PageSize.LETTER);
                            string urlCategoriabyProd = urlCategoria + "\\" + prod.nombre;
                            // Indicamos donde vamos a guardar el documento
                            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(urlCategoriabyProd + ".pdf", FileMode.Create));
                            doc.AddCreator("Magnolia");
                            doc.Open();
                            BaseFont serif = BaseFont.CreateFont(@"C:\Windows\Fonts\micross.ttf", "Identity-H", BaseFont.EMBEDDED);
                            iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(serif, Convert.ToInt32(txtTamanoFuente.Text), iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);

                            int col = 3;
                            double fk = (double)Convert.ToInt32(prod.stock) / 3;
                            int row = Convert.ToInt32(Math.Ceiling(fk));
                            //MessageBox.Show(fk.ToString()+":"+prod.stock + "/3=" + row.ToString());
                            PdfPTable tblPrueba = new PdfPTable(col);
                            doc.SetMargins(0f, 0f, 0f, 0f);
                            tblPrueba.HorizontalAlignment = Element.ALIGN_CENTER;
                            tblPrueba.WidthPercentage = 100;

                            for (int c = 0; c < col; c++)
                            {
                                int W = Convert.ToInt32(this.txtAncho.Text.Trim());
                                int H = Convert.ToInt32(this.txtAlto.Text.Trim());
                                b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
                                BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE128;
                                b.IncludeLabel = true;
                                b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                                b.Encode(type, prod.idProducto, W, H);
                                BarcodeLib.SaveTypes savetype = BarcodeLib.SaveTypes.PNG;
                                b.SaveImage(urlimagen, savetype);

                                iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlimagen);
                                imagen.BorderWidth = 0;
                                imagen.Alignment = Element.ALIGN_CENTER;
                                imagen.ScaleToFit(150f, 150f);

                                string txtsobreBarra = "";
                                if (chkGenerateLabel.IsChecked.Value)
                                {
                                    //MessageBox.Show(prod.nombre.Length.ToString() + ";" + prod.nombre);
                                    if (prod.nombre.Length > 25)
                                    {
                                        txtsobreBarra = prod.nombre.Substring(0, 25) + " $" + prod.precio;
                                    }
                                    else
                                    {
                                        txtsobreBarra = prod.nombre + " $" + prod.precio;
                                    }

                                }

                                for (int f = 0; f < row; f++)
                                {

                                    PdfPCell clNombre = new PdfPCell { };
                                    clNombre.BorderWidth = 0;
                                    clNombre.Padding = 13;
                                    clNombre.HorizontalAlignment = Element.ALIGN_CENTER;
                                    iTextSharp.text.Paragraph textsobre = new iTextSharp.text.Paragraph(new Phrase(txtsobreBarra, _standardFont));
                                    textsobre.Alignment = 1;
                                    clNombre.AddElement(textsobre);
                                    clNombre.AddElement(imagen);
                                    tblPrueba.AddCell(clNombre);
                                }


                            }


                            doc.Add(tblPrueba);
                            doc.Close();
                            writer.Close();
                            

                        }
                    }
                    correct = true;
                }
                else if (numEtiq == 2)
                {

                    if (!string.IsNullOrEmpty(txtleft.Text))
                    {
                        if (!string.IsNullOrEmpty(txtright.Text))
                        {
                            if (!string.IsNullOrEmpty(txttop.Text))
                            {
                                if (!string.IsNullOrEmpty(txtbotom.Text))
                                {
                                    float left = float.Parse(txtleft.Text);
                                    float right = float.Parse(txtright.Text);
                                    float top = float.Parse(txttop.Text);
                                    float bottom = float.Parse(txtbotom.Text);


                                    
                                    //Debe ser dinamico para cada categoria
                                    string urlCategoria = urlpdfcategorizado;
                                    if (!System.IO.Directory.Exists(urlCategoria))
                                    {
                                        System.IO.Directory.CreateDirectory(urlCategoria);
                                    }


                                    //debe ir bucle de columnas y fila 
                                    //mas nombre de cada producto como pdf

                                    foreach (var prod in listProducto)
                                    {
                                        if (Convert.ToInt32(prod.stock) != 0)
                                        {
                                            Document doc = new Document(PageSize.LETTER, left, right, top, bottom);
                                            string urlCategoriabyProd = urlCategoria + "\\" + prod.nombre;
                                            // Indicamos donde vamos a guardar el documento
                                            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(urlCategoriabyProd + ".pdf", FileMode.Create));
                                            doc.AddCreator("Magnolia");
                                            doc.Open();
                                            BaseFont serif = BaseFont.CreateFont(@"C:\Windows\Fonts\micross.ttf", "Identity-H", BaseFont.EMBEDDED);
                                            iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(serif, Convert.ToInt32(txtTamanoFuente.Text), iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);

                                            int col = Convert.ToInt32(txtcolumnas.Text);
                                            double fk = (double)Convert.ToInt32(prod.stock) / col;
                                            int row = Convert.ToInt32(Math.Ceiling(fk));
                                            //MessageBox.Show(fk.ToString() + ":" + prod.stock + "/3=" + row.ToString());
                                            PdfPTable tblPrueba = new PdfPTable(col);
                                            doc.SetMargins(0f, 0f, 0f, 0f);
                                            tblPrueba.HorizontalAlignment = Element.ALIGN_CENTER;
                                            tblPrueba.WidthPercentage = 100;

                                            for (int c = 0; c < col; c++)
                                            {
                                                int W = Convert.ToInt32(this.txtAncho.Text.Trim());
                                                int H = Convert.ToInt32(this.txtAlto.Text.Trim());
                                                b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
                                                BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE128;
                                                b.IncludeLabel = true;
                                                b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                                                b.Encode(type, prod.idProducto, W, H);
                                                BarcodeLib.SaveTypes savetype = BarcodeLib.SaveTypes.PNG;
                                                b.SaveImage(urlimagen, savetype);

                                                iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlimagen);
                                                imagen.BorderWidth = 0;
                                                imagen.Alignment = Element.ALIGN_CENTER;
                                                imagen.ScaleToFit(150f, 150f);

                                                string txtsobreBarra = "";
                                                if (chkGenerateLabel.IsChecked.Value)
                                                {
                                                    //MessageBox.Show(prod.nombre.Length.ToString() + ";" + prod.nombre);
                                                    if (prod.nombre.Length > 25)
                                                    {
                                                        txtsobreBarra = prod.nombre.Substring(0, 25) + " $" + prod.precio;
                                                    }
                                                    else
                                                    {
                                                        txtsobreBarra = prod.nombre + " $" + prod.precio;
                                                    }

                                                }

                                                for (int f = 0; f < row; f++)
                                                {

                                                    PdfPCell clNombre = new PdfPCell { };
                                                    clNombre.BorderWidth = 0;
                                                    clNombre.Padding = 13;
                                                    clNombre.HorizontalAlignment = Element.ALIGN_CENTER;
                                                    iTextSharp.text.Paragraph textsobre = new iTextSharp.text.Paragraph(new Phrase(txtsobreBarra, _standardFont));
                                                    textsobre.Alignment = 1;
                                                    clNombre.AddElement(textsobre);
                                                    clNombre.AddElement(imagen);
                                                    tblPrueba.AddCell(clNombre);
                                                }


                                            }


                                            doc.Add(tblPrueba);
                                            doc.Close();
                                            writer.Close();
 correct = true;
                                        }
                                    }
                                   

                                }
                                else
                                {
                                    MessageBox.Show("Ingresar margen: Abajo", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                                }
                            }
                            else
                            {
                                MessageBox.Show("Ingresar margen: Arriba", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                            }
                        }
                        else
                        {
                            MessageBox.Show("Ingresar margen:Derecho", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                        }
                    }
                    else
                    {
                        MessageBox.Show("Ingresar margen:Izquierdo", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }

                }
                return correct;
            }
            catch (IOException ex)
            {
                MessageBox.Show("IOO:" + ex.ToString(), "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                return correct;
            }
          
            catch (Exception e)
            {
                MessageBox.Show("Cerrar PDf abierto:" + e.ToString(), "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                return correct;
            }
            
        }
Example #18
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));
            }
        }
Example #19
0
        private void CantidadTotalRubrosyProductos(DateTime fecha)
        {
            ProductoFacade prodFac = new ProductoFacade();
            categoriaFacade catFac = new categoriaFacade();
            int p = prodFac.getTotalProductosbyMes(fecha);
            int c = catFac.getTotalCategoriabyMes(fecha);
            if (p == 0 || c == 0)
            {
                ltotalproduc.Content = p.ToString();
                ltotalrubros.Content = c.ToString();
            }
            else
            {
                ltotalproduc.Content = p.ToString("#,#", CultureInfo.InvariantCulture);
                ltotalrubros.Content = c.ToString("#,#", CultureInfo.InvariantCulture);
            }



        }
        private void btnEliminarProducto_Click(object sender, RoutedEventArgs e)
        {
            if (datagridProducto.SelectedItem != null)
            {
                if (datagridProducto.SelectedItem is Producto)
                {
                    var row = (Producto)datagridProducto.SelectedItem;

                    if (row != null)
                    {
                        ProductoFacade prodF = new ProductoFacade();
                        categoriaFacade catFac = new categoriaFacade();
                        string catcargar = catFac.getCategoriaById(prodF.getIdCatbyidProd(row.idProducto));
                        string res = prodF.borrarProductoByid(row.idProducto);
                        if (res.Equals(""))
                        {
                            MessageBox.Show("Producto borrado ", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                            btnGuardarProducto.Visibility = Visibility.Visible;
                            btncancelarEditarProd.Visibility = Visibility.Hidden;
                            btnGuardarActualizarProducto.Visibility = Visibility.Hidden;
                            limpiarTxtProducto();
                            //recargar tabla segun item de arbolseleccionado
                            /*string selcat = treeViewCategoria.SelectedValue.ToString();
                            if (catcargar.Equals("All"))
                            {
                                llenarTablaProducto();
                            }
                            else
                            {*/
                            //treeViewCategoria.item=catcargar;
                            llenarTablaProductoBynombreCat(catcargar);
                            tabCodigos.actualizarArbolyTablaProductos();
                            //}
                            // CantidadTotalRubrosyProductos();

                        }
                        else
                        {
                            MessageBox.Show("Error al borrar producto:" + res + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Seleccionar producto a borrar", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

        }
Example #21
0
        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);
                }

            }

        }
        private void btnEliminarTodoProducto_Click(object sender, RoutedEventArgs e)
        {
            ProductoFacade prodFtotal = new ProductoFacade();
            int totalProd = prodFtotal.getTotalProductos();
            if (MessageBox.Show("Esta seguro de borrar " + totalProd.ToString() + " Productos ", "Borrar", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                ProductoFacade prodF = new ProductoFacade();
                string res = prodF.borrarAllProducto();

                if (res.Equals(""))
                {
                    MessageBox.Show(totalProd + " Productos Eliminados" + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                    llenarTablaProducto();
                    btnGuardarProducto.Visibility = Visibility.Visible;
                    btncancelarEditarProd.Visibility = Visibility.Hidden;
                    btnGuardarActualizarProducto.Visibility = Visibility.Hidden;
                    limpiarTxtProducto();
                    tabCodigos.actualizarArbolyTablaProductos();
                    //CantidadTotalRubrosyProductos();
                }
                else
                {
                    MessageBox.Show("Error al borrar todos los productos:" + res + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }


        }
Example #23
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.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();
                }*/
            }

        }
        private void btnEliminarCategoria_Click(object sender, RoutedEventArgs e)
        {
            //borrar Categoria y productos asociados
            categoriaFacade catF = new categoriaFacade();
            ProductoFacade prodF = new ProductoFacade();

            string catBorrar = treeViewCategoria.SelectedValue.ToString();
            if (catBorrar.Length < 67 && !catBorrar.Equals("All"))
            {
                int totalProd = prodF.getTotalProductosBynombreCat(catBorrar);

                if (totalProd > 0)
                {
                    if (MessageBox.Show("Esta seguro de borrar categoria:" + catBorrar + " con (" + totalProd + ") Productos Asociados", "Borrar", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                    {

                        btnGuardaActProducto.Visibility = Visibility.Hidden;
                        btnNuevaCategoria.Visibility = Visibility.Visible;
                        btncancelarEditarcat.Visibility = Visibility.Hidden;
                        txtNuevaCat.Text = "";


                        bool res = prodF.borrarProductoYnombreCategoria(catBorrar);

                        if (res)
                        {
                            MessageBox.Show("Categoria  borrada", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                            llenarArbolCategoria();
                            llenarComboBCategoria();
                            tabCodigos.actualizarArbolyTablaProductos();
                            //CantidadTotalRubrosyProductos();
                        }
                    }
                }
                else
                {
                    if (MessageBox.Show("Esta seguro de borrar categoria:" + catBorrar, "Borrar", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                    {
                        btnGuardaActProducto.Visibility = Visibility.Hidden;
                        btnNuevaCategoria.Visibility = Visibility.Visible;
                        btncancelarEditarcat.Visibility = Visibility.Hidden;
                        txtNuevaCat.Text = "";

                        bool res = prodF.borrarProductoYnombreCategoria(catBorrar);

                        if (res)
                        {
                            MessageBox.Show("Categoria  borrada", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                            llenarArbolCategoria();
                            llenarComboBCategoria();
                            tabCodigos.actualizarArbolyTablaProductos();
                        }
                    }

                }

            }
            else
            {
                MessageBox.Show("Seleccionar categoria a borrar", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }








        }
Example #25
0
        private void btnReporteMes_Click(object sender, RoutedEventArgs e)
        {
            if (!lfechareporte.Content.Equals(""))
            {
                if (!lventasMes.Content.Equals("0"))
                {
                    DateTime date = Convert.ToDateTime(lfechareporte.Content);
                    //MessageBox.Show(date.Month.ToString() + "/" + date.Year.ToString());
                    ventasFacade vfac = new ventasFacade();
                    List<MVentas> listVentasMes = vfac.getVentasByFechaMes(date);

                    if (listVentasMes.Count > 0)
                    {
                        SaveFileDialog exportSaveFileDialog = new SaveFileDialog();

                        exportSaveFileDialog.Title = "Guardar reporte ventas mensuales";
                        exportSaveFileDialog.Filter = "PDF(*.pdf)|*.pdf";
                        exportSaveFileDialog.FileName = "ReporteVentasMensuales";
                        exportSaveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        if (exportSaveFileDialog.ShowDialog() == true)
                        {
                            // Creamos el documento con el tamaño de página tradicional
                            Document doc = new Document(PageSize.LETTER, 50, 50, 50, 50);
                            PdfWriter writer = null;
                            // Indicamos donde vamos a guardar el documento
                            try
                            {
                                writer = PdfWriter.GetInstance(doc, new FileStream(exportSaveFileDialog.FileName, FileMode.Create));
                                doc.AddCreator("Magnolia");
                                doc.Open();
                                iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlLogo, System.Drawing.Imaging.ImageFormat.Png);
                                imagen.Alignment = Element.ALIGN_CENTER;
                                imagen.ScaleToFit(120f, 120f);
                                doc.Add(imagen);
                                doc.Add(Chunk.NEWLINE);

                                iTextSharp.text.Font _fontTitulo = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 25, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);


                                iTextSharp.text.Paragraph titulo = new iTextSharp.text.Paragraph("Reporte de ventas mensual");
                                titulo.Alignment = Element.ALIGN_CENTER;
                                titulo.Font = _fontTitulo;
                                doc.Add(titulo);
                                doc.Add(Chunk.NEWLINE);

                                iTextSharp.text.Paragraph dgeneral = new iTextSharp.text.Paragraph("Detalles general");
                                dgeneral.Alignment = Element.ALIGN_LEFT;

                                //doc.AddTitle("Reporte de MVentas");
                                iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);


                                //////////////////////////////////////
                                ///////Tabla especificos    //////////
                                /////////////////////////////////////
                                iTextSharp.text.Paragraph despecifico = new iTextSharp.text.Paragraph("Detalles Especificos");
                                despecifico.Alignment = Element.ALIGN_LEFT;

                                // doc.Add(Chunk.NEWLINE);

                                categoriaFacade catFacEsp = new categoriaFacade();
                                ProductoFacade prodFacEsp = new ProductoFacade();
                                ventasFacade ventasFacEsp = new ventasFacade();
                                PdfPTable tblEspecifico = new PdfPTable(5);

                                string tempIdpro = "";

                                int dineroTotalbyCat = 0;
                                List<MVentas> listProductosinCatniInfoProd = new List<MVentas>();
                                List<MVentas> listProductoConCategoria = new List<MVentas>();

                                foreach (var item in listVentasMes)
                                {
                                    if (!tempIdpro.Equals(item.idProducto))
                                    {
                                        string IDCategoria = prodFacEsp.getIdCatbyidProd(item.idProducto);

                                        if (string.IsNullOrEmpty(IDCategoria))
                                        {
                                            //MessageBox.Show(item.idProducto + ":Sin categoria");
                                            //Agregar en celda distinta para obtener el total, no tienen categoria porque posiblemente se borra una categoria durante el mes o tiempo de uso.
                                            //Sin nombre de producto  ni categoria
                                            List<MVentas> listventaAgrupadabyFecha = ventasFacEsp.getVentasbyIdProdSinNombreGroupByFecha(item.idProducto, date);
                                            foreach (var i in listventaAgrupadabyFecha)
                                            {
                                                MVentas sinInfo = new MVentas(i.fecha, i.idProducto, i.nombreProducto, i.cantidad, i.total, i.idCategoria);
                                                bool exists = listProductosinCatniInfoProd.Any(x => x.fecha == sinInfo.fecha && x.idProducto == sinInfo.idProducto);
                                                if (!exists)
                                                {
                                                    listProductosinCatniInfoProd.Add(sinInfo);
                                                }

                                            }

                                            // existeSinCategoria = true;

                                        }
                                        else
                                        {
                                            //Con nombre de producto pero sin categoria
                                            string NombreCat = catFacEsp.getNombreCategoriaById(IDCategoria);
                                            if (string.IsNullOrEmpty(NombreCat))
                                            {

                                                List<MVentas> listventaAgrupadabyFecha = ventasFacEsp.getVentasbyIdProdGroupByFecha(item.idProducto, date);
                                                foreach (var i in listventaAgrupadabyFecha)
                                                {
                                                    MVentas sinInfo = new MVentas(i.fecha, i.idProducto, i.nombreProducto, i.cantidad, i.total, i.idCategoria);
                                                    listProductosinCatniInfoProd.Add(sinInfo);
                                                }

                                            }
                                            else
                                            {

                                                /*Agrupar por categoria los idproducto
                                                  Obtener todas las id categoria para obtener idprodudcto y buscar por idproducto en ventas 
                                                 * si no encuentra idproducto en ventas categoria no ha tenido ventas
                                                 * */
                                                //Obtiene el cantidadTotal , dineroTotal recaudado para producto agrupado por fecha
                                                List<MVentas> listVentaPorIdprod = ventasFacEsp.getVentasbyIdProdGroupByFecha(item.idProducto, date);
                                                foreach (var v in listVentaPorIdprod)
                                                {
                                                    //idcategoria que sera igual para distinto idproducto
                                                    MVentas ConInfo = new MVentas(v.fecha, v.idProducto, v.nombreProducto, v.cantidad, v.total, v.idCategoria);
                                                    bool exists = listProductoConCategoria.Any(x => x.fecha == ConInfo.fecha && x.idProducto == ConInfo.idProducto && x.idCategoria == ConInfo.idCategoria);
                                                    if (!exists)
                                                    {
                                                        listProductoConCategoria.Add(ConInfo);


                                                    }

                                                }

                                            }
                                        }
                                    }

                                }
                                //LLenar tabla especifico 
                                PdfPCell clFechaEsp = new PdfPCell();
                                PdfPCell clidprod = new PdfPCell();
                                PdfPCell clnombreprod = new PdfPCell();
                                PdfPCell clCant = new PdfPCell();
                                PdfPCell cltotalEsp = new PdfPCell();

                                listProductoConCategoria = listProductoConCategoria.OrderByDescending(i => i.idCategoria).ToList();

                                var q = from x in listProductoConCategoria
                                        group x.idCategoria by x.idCategoria into g
                                        let count = g.Count()
                                        /*orderby count descending*/
                                        select new { Value = g.Key, Count = count };


                                int posList = 0;
                                foreach (var x in q)
                                {
                                    tblEspecifico.WidthPercentage = 100;
                                    tblEspecifico.HorizontalAlignment = Element.ALIGN_LEFT;
                                    PdfPCell clnombreCat = new PdfPCell(new Phrase(catFacEsp.getNombreCategoriaById(x.Value.ToString()), _standardFont));
                                    clnombreCat.Colspan = 2;
                                    PdfPCell h1 = new PdfPCell(new Phrase(""));
                                    PdfPCell h2 = new PdfPCell(new Phrase(""));
                                    PdfPCell h3 = new PdfPCell(new Phrase(""));
                                    h1.Border = 0;
                                    h2.Border = 0;
                                    h3.Border = 0;
                                    tblEspecifico.AddCell(clnombreCat);
                                    tblEspecifico.AddCell(h1);
                                    tblEspecifico.AddCell(h2);
                                    tblEspecifico.AddCell(h3);

                                    clFechaEsp = new PdfPCell(new Phrase("Fecha", _standardFont));
                                    clidprod = new PdfPCell(new Phrase("IDProducto", _standardFont));
                                    clnombreprod = new PdfPCell(new Phrase("Nombre", _standardFont));
                                    clCant = new PdfPCell(new Phrase("Cantidad", _standardFont));
                                    //PdfPCell clTipoPag = new PdfPCell(new Phrase("Tipo Pago", _standardFont));
                                    cltotalEsp = new PdfPCell(new Phrase("Total", _standardFont));

                                    tblEspecifico.AddCell(clFechaEsp);
                                    tblEspecifico.AddCell(clidprod);
                                    tblEspecifico.AddCell(clnombreprod);
                                    tblEspecifico.AddCell(clCant);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblEspecifico.AddCell(cltotalEsp);

                                    for (int i = 0; i < x.Count; i++)
                                    {
                                        var v = listProductoConCategoria[posList];

                                        clFechaEsp = new PdfPCell(new Phrase(v.fecha.ToString("d"), _standardFont));
                                        //clidprod = new PdfPCell(new Phrase(x.Value.ToString(), _standardFont));
                                        clidprod = new PdfPCell(new Phrase(v.idProducto.ToString(), _standardFont));

                                        //clnombreprod = new PdfPCell(new Phrase(v.idCategoria.ToString() + ":" + v.nombreProducto, _standardFont));
                                        clnombreprod = new PdfPCell(new Phrase(v.nombreProducto.ToString(), _standardFont));
                                        //clnombreprod= new PdfPCell(new Phrase(prodFacEsp.getnombreProdbyidProd(v.idProducto), _standardFont));
                                        clCant = new PdfPCell(new Phrase(v.cantidad.ToString(), _standardFont));
                                        //clTipoPag = new PdfPCell(new Phrase("", _standardFont));
                                        cltotalEsp = new PdfPCell(new Phrase(v.total.ToString(), _standardFont));

                                        tblEspecifico.AddCell(clFechaEsp);
                                        tblEspecifico.AddCell(clidprod);
                                        tblEspecifico.AddCell(clnombreprod);
                                        tblEspecifico.AddCell(clCant);
                                        //tblEspecifico.AddCell(clTipoPag);
                                        tblEspecifico.AddCell(cltotalEsp);
                                        dineroTotalbyCat = dineroTotalbyCat + Convert.ToInt32(v.total);
                                        tempIdpro = v.idProducto;
                                        posList = posList + 1;
                                    }
                                    //#################################
                                    //en cada categoria 
                                    //#################################
                                    clFechaEsp = new PdfPCell(new Phrase("", _standardFont));
                                    clidprod = new PdfPCell(new Phrase("", _standardFont));
                                    clnombreprod = new PdfPCell(new Phrase("", _standardFont));
                                    clCant = new PdfPCell(new Phrase("Subtotal($)", _standardFont));
                                    //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                    cltotalEsp = new PdfPCell(new Phrase(dineroTotalbyCat.ToString(), _standardFont));
                                    dineroTotalbyCat = 0;

                                    clFechaEsp.Border = 0;
                                    clidprod.Border = 0;
                                    clnombreprod.Border = 0;
                                    clCant.Border = 1;
                                    cltotalEsp.Border = 1;



                                    tblEspecifico.AddCell(clFechaEsp);
                                    tblEspecifico.AddCell(clidprod);
                                    tblEspecifico.AddCell(clnombreprod);
                                    tblEspecifico.AddCell(clCant);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblEspecifico.AddCell(cltotalEsp);


                                    /////////////////////////////////////////////
                                    clFechaEsp = new PdfPCell(new Phrase("", _standardFont));
                                    clidprod = new PdfPCell(new Phrase("", _standardFont));
                                    clnombreprod = new PdfPCell(new Phrase("", _standardFont));
                                    clCant = new PdfPCell(new Phrase("", _standardFont));
                                    //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                    cltotalEsp = new PdfPCell(new Phrase("", _standardFont));
                                    clFechaEsp.Border = 0;
                                    clidprod.Border = 0;
                                    clnombreprod.Border = 0;
                                    clCant.Border = 0;
                                    cltotalEsp.Border = 0;

                                    cltotalEsp.FixedHeight = 30f;
                                    clFechaEsp.FixedHeight = 30f;
                                    clidprod.FixedHeight = 30f;
                                    clnombreprod.FixedHeight = 30f;
                                    clCant.FixedHeight = 30f;
                                    cltotalEsp.FixedHeight = 30f;

                                    tblEspecifico.AddCell(clFechaEsp);
                                    tblEspecifico.AddCell(clidprod);
                                    tblEspecifico.AddCell(clnombreprod);
                                    tblEspecifico.AddCell(clCant);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblEspecifico.AddCell(cltotalEsp);
                                    //}
                                    // catActual = prodFac.getIdCatbyidProd(v.idProducto);
                                    //MessageBox.Show(catActual);


                                }


                                //#######################################################
                                //###### PRODUCTOS QUE SE HALLAN ELIMINADO ############
                                //#######################################################
                                //Tabla para tabla otros que no tengan una categoria asociada pero que igualmente deben estar en reportes de ventas.
                                bool otros = false;
                                PdfPTable tblOtros = new PdfPTable(5);
                                int totalOtros = 0;
                                int subtotalCosto_otros = 0;
                                int totalCosto_otros = 0;
                                int diferenciaVenta_otros = 0;
                                int totalDiferencia_otros = 0;
                                if (listProductosinCatniInfoProd.Count > 0)
                                {
                                    otros = true;
                                    tblOtros.WidthPercentage = 100;
                                    tblOtros.HorizontalAlignment = Element.ALIGN_LEFT;
                                    PdfPCell clnombreCat_otros = new PdfPCell(new Phrase("Otros", _standardFont));
                                    clnombreCat_otros.Colspan = 2;
                                    PdfPCell h11 = new PdfPCell(new Phrase(""));
                                    PdfPCell h22 = new PdfPCell(new Phrase(""));
                                    PdfPCell h33 = new PdfPCell(new Phrase(""));
                                    h11.Border = 0;
                                    h22.Border = 0;
                                    h33.Border = 0;
                                    tblOtros.AddCell(clnombreCat_otros);
                                    tblOtros.AddCell(h11);
                                    tblOtros.AddCell(h22);
                                    tblOtros.AddCell(h33);

                                    PdfPCell clFechaEsp_otros = new PdfPCell(new Phrase("Fecha", _standardFont));
                                    PdfPCell clidprod_otros = new PdfPCell(new Phrase("IDProducto", _standardFont));
                                    PdfPCell clnombreprod_otros = new PdfPCell(new Phrase("Nombre", _standardFont));
                                    PdfPCell clCant_otros = new PdfPCell(new Phrase("Cantidad", _standardFont));

                                    //PdfPCell clTipoPag = new PdfPCell(new Phrase("Tipo Pago", _standardFont));
                                    PdfPCell cltotalEsp_otros = new PdfPCell(new Phrase("Total", _standardFont));

                                    tblOtros.AddCell(clFechaEsp_otros);
                                    tblOtros.AddCell(clidprod_otros);
                                    tblOtros.AddCell(clnombreprod_otros);
                                    tblOtros.AddCell(clCant_otros);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblOtros.AddCell(cltotalEsp_otros);


                                    foreach (var item in listProductosinCatniInfoProd)
                                    {
                                        clFechaEsp_otros = new PdfPCell(new Phrase(item.fecha.ToString("d"), _standardFont));
                                        clidprod_otros = new PdfPCell(new Phrase(item.idProducto, _standardFont));

                                        clnombreprod_otros = new PdfPCell(new Phrase(item.nombreProducto, _standardFont));
                                        //clnombreprod= new PdfPCell(new Phrase(prodFacEsp.getnombreProdbyidProd(v.idProducto), _standardFont));
                                        clCant_otros = new PdfPCell(new Phrase(item.cantidad.ToString(), _standardFont));
                                        //clTipoPag = new PdfPCell(new Phrase("", _standardFont));
                                        cltotalEsp_otros = new PdfPCell(new Phrase(item.total.ToString(), _standardFont));

                                        tblOtros.AddCell(clFechaEsp_otros);
                                        tblOtros.AddCell(clidprod_otros);
                                        tblOtros.AddCell(clnombreprod_otros);
                                        tblOtros.AddCell(clCant_otros);
                                        //tblEspecifico.AddCell(clTipoPag);
                                        tblOtros.AddCell(cltotalEsp_otros);
                                        totalOtros = totalOtros + Convert.ToInt32(item.total);

                                        if (string.IsNullOrEmpty(prodFacEsp.getPrecioCompraProducto(item.idProducto).ToString()))
                                        {
                                            subtotalCosto_otros = 0;
                                        }
                                        else
                                        {
                                            subtotalCosto_otros = item.cantidad * prodFacEsp.getPrecioCompraProducto(item.idProducto);
                                        }
                                        //MessageBox.Show("idProducto=" + item.idProducto);
                                        totalCosto_otros = totalCosto_otros + subtotalCosto_otros;
                                        diferenciaVenta_otros = totalOtros - subtotalCosto_otros; //subtotalCosto_otros - totalCosto_otros;
                                        totalDiferencia_otros = totalDiferencia_otros + diferenciaVenta_otros;


                                    }


                                    clFechaEsp_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clidprod_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clnombreprod_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clCant_otros = new PdfPCell(new Phrase("Subtotal($)", _standardFont));
                                    //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                    cltotalEsp_otros = new PdfPCell(new Phrase(totalOtros.ToString(), _standardFont));
                                    clFechaEsp_otros.Border = 0;
                                    clidprod_otros.Border = 0;
                                    clnombreprod_otros.Border = 0;
                                    clCant_otros.Border = 1;
                                    cltotalEsp_otros.Border = 1;

                                    tblOtros.AddCell(clFechaEsp_otros);
                                    tblOtros.AddCell(clidprod_otros);
                                    tblOtros.AddCell(clnombreprod_otros);
                                    tblOtros.AddCell(clCant_otros);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblOtros.AddCell(cltotalEsp_otros);
                                    clFechaEsp_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clidprod_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clnombreprod_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clCant_otros = new PdfPCell(new Phrase("", _standardFont));
                                    //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                    cltotalEsp_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clFechaEsp_otros.Border = 0;
                                    clidprod_otros.Border = 0;
                                    clnombreprod_otros.Border = 0;
                                    clCant_otros.Border = 0;
                                    cltotalEsp_otros.Border = 0;

                                    cltotalEsp_otros.FixedHeight = 50f;
                                    clFechaEsp_otros.FixedHeight = 50f;
                                    clidprod_otros.FixedHeight = 50f;
                                    clnombreprod_otros.FixedHeight = 50f;
                                    clCant_otros.FixedHeight = 50f;
                                    cltotalEsp_otros.FixedHeight = 50f;

                                    tblOtros.AddCell(clFechaEsp_otros);
                                    tblOtros.AddCell(clidprod_otros);
                                    tblOtros.AddCell(clnombreprod_otros);
                                    tblOtros.AddCell(clCant_otros);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblOtros.AddCell(cltotalEsp_otros);

                                }

                                //#######################################################
                                //######            DETALLES GENERALES       ############
                                //#######################################################

                                PdfPTable tblGenerales = new PdfPTable(5);
                                //doc.SetMargins(0f, 0f, 0f, 0f);
                                tblGenerales.HorizontalAlignment = Element.ALIGN_LEFT;
                                // Configuramos el título de las columnas de la tabla
                                PdfPCell clFecha = new PdfPCell(new Phrase("Mes", _standardFont));
                                PdfPCell clCat = new PdfPCell(new Phrase("Categoria", _standardFont));
                                PdfPCell clSubtotal = new PdfPCell(new Phrase("Subtotal ventas", _standardFont));
                                PdfPCell clSubtotalCosto = new PdfPCell(new Phrase("Subtotal costo", _standardFont));
                                PdfPCell clDiferencia = new PdfPCell(new Phrase("Diferencia", _standardFont));
                                tblGenerales.AddCell(clFecha);
                                tblGenerales.AddCell(clCat);
                                tblGenerales.AddCell(clSubtotal);
                                tblGenerales.AddCell(clSubtotalCosto);
                                tblGenerales.AddCell(clDiferencia);

                                categoriaFacade catFac = new categoriaFacade();
                                ProductoFacade prodFac = new ProductoFacade();

                                int subtotal = 0;
                                int total = 0;
                                int posListG = 0;
                                int subtotalCosto = 0;
                                int totalCosto = 0;
                                int totalCostoVenta = 0;
                                int diferenciaVenta = 0;
                                int totalDiferencia = 0;

                                //Agrupar por categoria los idproducto
                                List<MVentas> ListcatGeneral = new List<MVentas>();
                                foreach (var x in q)
                                {
                                    for (int i = 0; i < x.Count; i++)
                                    {
                                        var v = listProductoConCategoria[posListG];


                                        subtotal = subtotal + Convert.ToInt32(v.total);
                                        subtotalCosto = v.cantidad * prodFac.getPrecioCompraProducto(v.idProducto);
                                        posListG = posListG + 1;
                                        totalCosto = totalCosto + subtotalCosto;
                                        diferenciaVenta = subtotal - totalCosto;
                                        totalDiferencia = totalDiferencia + diferenciaVenta;
                                        //gananciaReal = gananciaReal + totalDiferencia;

                                    }
                                    total = total + subtotal;
                                    clFecha = new PdfPCell(new Phrase(date.ToString("y"), _standardFont));
                                    clCat = new PdfPCell(new Phrase(catFac.getNombreCategoriaById(x.Value.ToString()), _standardFont));
                                    clSubtotal = new PdfPCell(new Phrase(subtotal.ToString(), _standardFont));
                                    clSubtotalCosto = new PdfPCell(new Phrase(subtotalCosto.ToString(), _standardFont));
                                    clDiferencia = new PdfPCell(new Phrase(diferenciaVenta.ToString(), _standardFont));
                                    tblGenerales.AddCell(clFecha);
                                    tblGenerales.AddCell(clCat);
                                    tblGenerales.AddCell(clSubtotal);
                                    tblGenerales.AddCell(clSubtotalCosto);
                                    tblGenerales.AddCell(clDiferencia);
                                    subtotal = 0;
                                    subtotalCosto = 0;
                                    diferenciaVenta = 0;
                                    totalCostoVenta = totalCostoVenta + totalCosto;
                                    totalCosto = 0;

                                }
                                if (otros)
                                {
                                    clFecha = new PdfPCell(new Phrase(date.ToString("y"), _standardFont));
                                    clCat = new PdfPCell(new Phrase("Otros", _standardFont));
                                    clSubtotal = new PdfPCell(new Phrase(totalOtros.ToString(), _standardFont));
                                    clSubtotalCosto = new PdfPCell(new Phrase(subtotalCosto_otros.ToString(), _standardFont));
                                    clDiferencia = new PdfPCell(new Phrase(diferenciaVenta_otros.ToString(), _standardFont));
                                    tblGenerales.AddCell(clFecha);
                                    tblGenerales.AddCell(clCat);
                                    tblGenerales.AddCell(clSubtotal);
                                    tblGenerales.AddCell(clSubtotalCosto);
                                    tblGenerales.AddCell(clDiferencia);
                                    total = total + totalOtros;

                                    subtotalCosto = subtotalCosto + totalCosto_otros;
                                    totalCosto = totalCosto + subtotalCosto;
                                    totalDiferencia = totalDiferencia + diferenciaVenta_otros;
                                    totalCostoVenta = totalCostoVenta + totalCosto_otros;
                                    //diferenciaVenta_otros = diferenciaVenta + diferenciaVenta_otros;
                                    //totalDiferencia_otros = totalDiferencia + diferenciaVenta_otros;
                                }

                                clFecha = new PdfPCell(new Phrase("", _standardFont));
                                clCat = new PdfPCell(new Phrase("Total ", _standardFont));
                                clSubtotal = new PdfPCell(new Phrase(total.ToString(), _standardFont));
                                clSubtotalCosto = new PdfPCell(new Phrase(totalCostoVenta.ToString(), _standardFont));
                                clDiferencia = new PdfPCell(new Phrase("", _standardFont));

                                clFecha.Border = 0;
                                tblGenerales.AddCell(clFecha);
                                tblGenerales.AddCell(clCat);
                                tblGenerales.AddCell(clSubtotal);
                                tblGenerales.AddCell(clSubtotalCosto);
                                tblGenerales.AddCell(clDiferencia);

                                //Ganancia Real

                                clFecha = new PdfPCell(new Phrase("", _standardFont));
                                clCat = new PdfPCell(new Phrase("", _standardFont));
                                clSubtotal = new PdfPCell(new Phrase("", _standardFont));
                                clSubtotalCosto = new PdfPCell(new Phrase("Ganancia Real", _standardFont));
                                clDiferencia = new PdfPCell(new Phrase(totalDiferencia.ToString(), _standardFont));

                                clFecha.Border = 0;
                                clCat.Border = 0;
                                clSubtotal.Border = 0;

                                tblGenerales.AddCell(clFecha);
                                tblGenerales.AddCell(clCat);
                                tblGenerales.AddCell(clSubtotal);
                                tblGenerales.AddCell(clSubtotalCosto);
                                tblGenerales.AddCell(clDiferencia);


                                int vtotales = listVentasMes.Count;
                                iTextSharp.text.Font _fontDe = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);
                                iTextSharp.text.Paragraph ventasTotal = new iTextSharp.text.Paragraph("Total Ventas:" + vtotales.ToString(), _fontDe);
                                int efectivo = ventasFacEsp.getVentasByFechaMesPagoEfectivo(date);
                                int cuenta = ventasFacEsp.getVentasByFechaMesPagocuenta(date);
                                int debito = ventasFacEsp.getVentasByFechaMesPagodebito(date);
                                int cheque = ventasFacEsp.getVentasByFechaMesPagoCheque(date);
                                iTextSharp.text.Paragraph pago = new iTextSharp.text.Paragraph("Pago: Efectivo:" + efectivo.ToString() + "  Cuenta:" + cuenta.ToString() + "  Debito:" + debito.ToString() + "  Cheque:" + cheque.ToString(), _fontDe);
                                ventasTotal.Alignment = Element.ALIGN_LEFT;
                                if (otros)
                                {


                                    doc.Add(dgeneral);
                                    doc.Add(Chunk.NEWLINE);
                                    doc.Add(tblGenerales);
                                    doc.Add(ventasTotal);
                                    doc.Add(pago);
                                    doc.Add(Chunk.NEWLINE);
                                    doc.Add(despecifico);
                                    doc.Add(new Chunk("\n"));
                                    doc.Add(tblEspecifico);
                                    doc.Add(new Chunk("\n"));
                                    doc.Add(tblOtros);

                                }
                                else
                                {

                                    doc.Add(dgeneral);
                                    doc.Add(Chunk.NEWLINE);
                                    doc.Add(tblGenerales);
                                    doc.Add(ventasTotal);
                                    doc.Add(pago);
                                    doc.Add(Chunk.NEWLINE);
                                    doc.Add(despecifico);
                                    doc.Add(new Chunk("\n"));
                                    doc.Add(tblEspecifico);
                                    doc.Add(new Chunk("\n"));
                                }

                                int page = writer.PageNumber;
                                //iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(page.ToString(), _standardFont);
                                //doc.Add(p);

                                doc.Close();
                                writer.Close();

                                //MessageBox.Show("Pdf Creado!");
                            }
                            // }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                            finally
                            {
                                doc.Close();
                                writer.Close();
                            }
                            System.Diagnostics.Process.Start(exportSaveFileDialog.FileName);
                        }


                    }
                    else
                    {
                        MessageBox.Show("Mes no ha tenido ventas", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                    }


                }
                else
                {
                    MessageBox.Show("Mes no ha tenido ventas", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Seleccionar fecha", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

        }
Example #26
0
        private void CantidadTotalRubrosyProductos(DateTime fecha)
        {
            ProductoFacade prodFac = new ProductoFacade();
            categoriaFacade catFac = new categoriaFacade();
            ltotalproduc.Content = prodFac.getTotalProductosbyMes(fecha).ToString();
            ltotalrubros.Content = catFac.getTotalCategoriabyMes(fecha).ToString();


        }
Example #27
0
        public Boolean borrarCategoriaBynombre(string nombreCategoria)
        {
            Boolean borrar = false;
            try
            {
                //Borrar datos asociados a categoria 


                ProductoFacade prodf = new ProductoFacade();
                prodf.borrarProductoBynombreCategoria(nombreCategoria);

                categoriaFacade ctf = new categoriaFacade();
                string idCategoria = ctf.getCategoriaByNombre(nombreCategoria);




                MySqlCommand cmdCategoria = new MySqlCommand("DELETE FROM categoria WHERE idCategoria =@idcategoria", getconexion.getConexion());
                cmdCategoria.Parameters.AddWithValue("@idCategoria", idCategoria);
                cmdCategoria.ExecuteNonQuery();
                borrar = true;

            }
            catch (Exception e)
            {
                borrar = false;

            }
            return borrar;

        }
Example #28
0
        private void calendar1_DisplayDateChanged(object sender, CalendarDateChangedEventArgs e)
        {


            if (txtFechaReporte != null) //Because the calendar may render prior to the textbox
            {
                //year = calendarReportesPagoRubro.DisplayDate.Year.ToString();
                month = calendarReportesPagoRubro.DisplayDate.ToString("y");
                MesRubroProd = calendarReportesPagoRubro.DisplayDate;
                //CantidadTotalRubrosyProductos(MesRubroProd);
                ProductoFacade prodFac = new ProductoFacade();
                categoriaFacade catFac = new categoriaFacade();
                int p = prodFac.getTotalProductosbyMes(MesRubroProd);
                int r = catFac.getTotalCategoriabyMes(MesRubroProd);
                CantidadTotalRubrosyProductos(MesRubroProd);
                //MessageBox.Show(MesRubroProd.Month.ToString()+":rubro:"+r+"-producto:"+p);
                /*if (calendarReportesPagoRubro.DisplayDate.Month < 10)
                {
                    month = "0" + month;
                }*/
                txtFechaReporte.Text = month;
                //txtFechaReporte.Text = string.Format("{0}-{1}", year, month);
                //txtFechaReporte.Text = string.Format("{0}-{1}", year, month);
            }
        }
Example #29
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));
            }
        }
Example #30
0
        public List<MVentas> getCostoVentasbyIdProdSinNombreGroupByFechaAño(string idproducto, DateTime fecha)
        {
            MySqlDataReader rdr = null;
            List<MVentas> Listventas = new List<MVentas>();
            ProductoFacade prodFac = new ProductoFacade();
            string consulta = "";
            bool existe = prodFac.getExisteProductoByidProd(idproducto);
            if (existe)
            {
                //string consulta = "SELECT fecha, idProducto,sum(cantidad)as cantidad, sum(total) as total FROM db.venta  where idproducto=\"" + idproducto + "\" AND year(fecha)=" + fecha.Year + "  GROUP BY fecha;";
                consulta = "SELECT fecha,idproducto,(select precioReal from producto where idproducto=\"" + idproducto + "\")as precioReal,cantidad   FROM venta WHERE idproducto=\"" + idproducto + "\" AND year(fecha)=" + fecha.Year + "  GROUP BY fecha";
            }
            else
            {
                consulta = "SELECT fecha,idproducto,sum(cantidad)   FROM venta WHERE idproducto=\"" + idproducto + "\" AND year(fecha)=" + fecha.Year + "  GROUP BY fecha";
            }
            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                //Listventas.Add(new MVentas(rdr.GetDateTime(0), rdr.GetString(1), "Sin Nombre", rdr.GetString(2), rdr.GetInt32(3), Convert.ToInt32(rdr.GetInt32(2)) * rdr.GetInt32(3), 0));
                if (existe)
                {
                    Listventas.Add(new MVentas(rdr.GetDateTime(0), rdr.GetString(1), "Sin Nombre", rdr.GetString(2), rdr.GetInt32(3), Convert.ToInt32(rdr.GetInt32(2)) * rdr.GetInt32(3), 0));
                }
                else
                {
                    Listventas.Add(new MVentas(rdr.GetDateTime(0), rdr.GetString(1), "Sin Nombre", "0", rdr.GetInt32(2), 0, 0));

                }


            }
            getconexion.CerrarConexion();

            return Listventas;

        }
Example #31
0
        private void btnDevolver_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (datagridVentas.Items.Count > 0)
                {
                    if (datagridVentas.SelectedItem != null)
                    {
                        var row = GetDataGridRows(datagridVentas);
                        if (row != null)
                        {
                            VentaTemporal rv=new VentaTemporal();
                            foreach (DataGridRow r in row)
                            {
                                 rv = (VentaTemporal)r.Item;
                            }
                                int difDevo = Convert.ToInt32(rv.cantidad) - Convert.ToInt32(rv.devolver);
                                //MessageBox.Show("dif:" + difDevo.ToString());
                                if (difDevo == 0)
                                {//si cantidad devolucion es igul a cantidad venta, actualizar stock producto y borrar registro de venta
                                    int sumStock = Convert.ToInt32(rv.devolver);
                                    ProductoFacade prodFac = new ProductoFacade();
                                    string actStock = prodFac.actualizarStockProductoDevolucion(rv.idProducto, sumStock);
                                    ventasFacade ventFac = new ventasFacade();
                                    string borrar = ventFac.borrarventaByidVenta(Convert.ToDouble(txtidventa.Text), txtidProducto.Text, Convert.ToDateTime(fechaventa.Text));

                                    if (!string.IsNullOrEmpty(actStock))
                                    {
                                        MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else if (!string.IsNullOrEmpty(borrar))
                                    {
                                        MessageBox.Show("Error al borrar venta:" + borrar + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Devolucion ingresada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                        txtidventa.Text = "";
                                        txtidProducto.Text = "";
                                        fechaventa.Text = "";
                                        venta.Clear();
                                        datagridVentas.ItemsSource = venta;
                                        ltotal.Content = "0";
                                        Valor = 1;
                                        this.Close();
                                    }
                                }
                                else
                                {//si cantidad devolucion no es igual a cantidad en venta , actualizar venta e stock producto
                                    int sumStock = Convert.ToInt32(rv.devolver);
                                    ProductoFacade prodFac = new ProductoFacade();
                                    string actStock = prodFac.actualizarStockProductoDevolucion(rv.idProducto, sumStock);
                                    ventasFacade ventFac = new ventasFacade();
                                    string actVenta = ventFac.actualizarventaDevolucion(Convert.ToDouble(txtidventa.Text), txtidProducto.Text, Convert.ToDateTime(fechaventa.Text), difDevo, difDevo * Convert.ToInt32(rv.precio));

                                    if (!string.IsNullOrEmpty(actStock))
                                    {
                                        MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else if (!string.IsNullOrEmpty(actVenta))
                                    {
                                        MessageBox.Show("Error al actualizar venta:" + actVenta + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Devolucion ingresada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                        txtidventa.Text = "";
                                        txtidProducto.Text = "";
                                        fechaventa.Text = "";
                                        venta.Clear();
                                        datagridVentas.ItemsSource = venta;
                                        ltotal.Content = "0";
                                        Valor = 1;
                                        this.Close();
                                    }

                                }
                            

                        }
                    }



                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }
Example #32
0
        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 btnGuardarProducto_Click(object sender, RoutedEventArgs e)
        {

            if (!string.IsNullOrWhiteSpace(txtnombreproducto.Text))
            {
                if (!string.IsNullOrWhiteSpace(txtstock.Text))
                {
                    if (!string.IsNullOrWhiteSpace(txtprecioReal.Text))
                    {
                        if (!string.IsNullOrWhiteSpace(txtprecio.Text))
                        {
                            int compra = ToEntero(txtprecioReal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            int venta = ToEntero(txtprecio.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            if (compra < venta)
                            {


                                if (cbTipoCodigo.SelectedIndex == 1)
                                {
                                    if (!string.IsNullOrWhiteSpace(txtcodprod.Text))
                                    {
                                        //ingresar producto con id ingresado por usuario


                                        if (cbCategoria.Items.Count > 0)
                                        {
                                            ProductoFacade prodF = new ProductoFacade();

                                            string codProd = txtcodprod.Text;
                                            string nombreProd = txtnombreproducto.Text;
                                            string nombreCat = cbCategoria.SelectedValue.ToString();
                                            
                                            int st = ToEntero(txtstock.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                            string stock = st.ToString();

                                            int pR = ToEntero(txtprecioReal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                            string precioReal = pR.ToString();
                                            int p = ToEntero(txtprecio.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                            string precio = p.ToString();
                                            //string res=prodF.GuardarProducto()

                                            //Agregar idCategoria al idProducto + el numItem
                                            ProductoFacade prodFCod = new ProductoFacade();
                                            categoriaFacade catFCod = new categoriaFacade();
                                            List<Producto> listProducto = prodFCod.getProductosBynombreCategoria(nombreCat);

                                            //Verificar si producto con nombre y categoria existe
                                            ProductoFacade prodFExiste = new ProductoFacade();
                                            bool existeProd = prodFExiste.getExisteProductoBynombreYidCat(nombreProd, nombreCat);
                                            if (existeProd)
                                            {
                                                MessageBox.Show("Producto con nombre:\"" + nombreProd + "\" ya existe para categoria:\"" + nombreCat + "\"" + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                                            }
                                            else
                                            {

                                                DateTime fechaactual = DateTime.Now.Date;
                                                string res = prodF.GuardarProducto(txtcodprod.Text, nombreProd, stock, precioReal, precio, nombreCat, fechaactual, 1);
                                                if (res.Equals(""))
                                                {
                                                    MessageBox.Show("Producto guardado correctamente!", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                                    limpiarTxtProducto();
                                                    llenarTablaProductoBynombreCat(nombreCat);
                                                    cbTipoCodigo.SelectedIndex = 0;
                                                    tabCodigos.actualizarArbolyTablaProductos();
                                                }
                                                else
                                                {
                                                    MessageBox.Show("Error al guardar producto:" + res + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);

                                                }






                                            }


                                        }
                                        else
                                        {
                                            MessageBox.Show("Ingresar al menos 1 categoria!", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);


                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Ingresar idproducto a producto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);


                                    }
                                }
                                else
                                {
                                    //ingresar idproductogenerado

                                    Guid guid = Guid.NewGuid();
                                    string a = guid.ToString();

                                    string idPnuevo = string.Empty;
                                    long val = 0;

                                    for (int i = 0; i < a.Length; i++)
                                    {
                                        if (Char.IsDigit(a[i]))
                                            if (idPnuevo.Length < 8)
                                            {
                                                idPnuevo += a[i];
                                            }
                                            else
                                            {
                                                break;
                                            }
                                    }
                                    if (cbCategoria.Items.Count > 0)
                                    {
                                        ProductoFacade prodF = new ProductoFacade();


                                        string nombreProd = txtnombreproducto.Text;
                                        string nombreCat = cbCategoria.SelectedValue.ToString();
                                        int st = ToEntero(txtstock.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                        string stock = st.ToString();
                                        int pR = ToEntero(txtprecioReal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                        string precioReal = pR.ToString();
                                        int p = ToEntero(txtprecio.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                                        string precio = p.ToString();
                                        //string res=prodF.GuardarProducto()

                                        //Agregar idCategoria al idProducto + el numItem
                                        ProductoFacade prodFCod = new ProductoFacade();
                                        categoriaFacade catFCod = new categoriaFacade();
                                        List<Producto> listProducto = prodFCod.getProductosBynombreCategoria(nombreCat);

                                        //Verificar si producto con nombre y categoria existe
                                        ProductoFacade prodFExiste = new ProductoFacade();
                                        bool existeProd = prodFExiste.getExisteProductoBynombreYidCat(nombreProd, nombreCat);
                                        if (existeProd)
                                        {
                                            MessageBox.Show("Producto con nombre:\"" + nombreProd + "\" ya existe para categoria:\"" + nombreCat + "\"" + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                                        }
                                        else
                                        {
                                            //Producto ya tiene productos asociados a categoria agregar en la ultima posicion


                                            //Guardar producto con idproducto 
                                            DateTime fechaactual = DateTime.Now.Date;
                                            string res = prodF.GuardarProducto(idPnuevo, nombreProd, stock, precioReal, precio, nombreCat, fechaactual, 0);
                                            if (res.Equals(""))
                                            {
                                                MessageBox.Show("Producto guardado correctamente!", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                                limpiarTxtProducto();
                                                llenarTablaProductoBynombreCat(nombreCat);
                                                tabCodigos.actualizarArbolyTablaProductos();
                                                //llenarTablaProductoCodBarra();
                                                //CantidadTotalRubrosyProductos();
                                            }
                                            else
                                            {
                                                MessageBox.Show("Error al guardar producto:" + res + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);

                                            }


                                        }


                                    }
                                    else
                                    {
                                        MessageBox.Show("Ingresar al menos 1 categoria!", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);


                                    }
                                }

                            }
                            else
                            {
                                MessageBox.Show("Precio de venta debe ser mayor a precio de compra(?!)", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                            }
                        }
                        else
                        {
                            MessageBox.Show("Ingresar Precio Venta a producto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                        }
                    }
                    else
                    {
                        MessageBox.Show("Ingresar Precio Compra a producto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                    }
                }
                else
                {
                    MessageBox.Show("Ingresar Stock!", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

                }
            }
            else
            {
                MessageBox.Show("Ingresar nombre a producto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);

            }
        }