Esempio n. 1
0
        public Boolean borrarProductoYnombreCategoria(string nombreCategoria)
        {
            Boolean borrar = false;

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

                MySqlDataAdapter adapter = new MySqlDataAdapter();



                MySqlCommand cmdCategoria = new MySqlCommand("DELETE FROM producto WHERE idCategoria =\"" + idCategoria + "\"", getconexion.getConexion());
                cmdCategoria.ExecuteNonQuery();

                borrar = true;
            }
            catch (Exception e)
            {
                borrar = false;
            }
            return(borrar);
        }
Esempio n. 2
0
        public string actualizarCategoria(string nombreCategoriaN, string nombreCategoria)
        {
            string res      = "";
            string consulta = "";

            try
            {
                DateTime        fechaactual = DateTime.Now.Date;
                categoriaFacade ctf         = new categoriaFacade();
                string          idCategoria = ctf.getCategoriaByNombre(nombreCategoria);
                consulta = "UPDATE categoria set nombreCategoria=\"" + nombreCategoriaN + "\"" + ",fecha=@fecha WHERE idCategoria =\"" + idCategoria + "\";";
                MySqlCommand cmdCategoria = new MySqlCommand(consulta, getconexion.getConexion());
                cmdCategoria.Parameters.AddWithValue("@fecha", fechaactual);
                MySqlDataReader MyReader2 = cmdCategoria.ExecuteReader();
            }
            catch (Exception e)
            {
                res = e.ToString();
                getconexion.CerrarConexion();
            }
            finally
            {
                getconexion.CerrarConexion();
            }


            return(res);
        }
Esempio n. 3
0
        public List <Producto> getProductosBynombre(string nombre, string nombreCategoria)
        {
            DataTable       dtDatos     = new DataTable();
            MySqlDataReader rdr         = null;
            List <Producto> producto    = new List <Producto>();
            categoriaFacade ctf         = new categoriaFacade();
            string          idCategoria = ctf.getCategoriaByNombre(nombreCategoria);
            string          consulta    = "SELECT*FROM producto WHERE nombre=\"" + nombre + "\" AND idCategoria=\"" + idCategoria + "\"";
            //MySqlDataAdapter mdaDatos = new MySqlDataAdapter("SELECT*FROM producto", conexion.getConexion());
            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());

            rdr = cmd.ExecuteReader();
            dtDatos.Columns.Add("Nombre");
            dtDatos.Columns.Add("Stock");
            dtDatos.Columns.Add("precioReal");
            dtDatos.Columns.Add("Precio");
            dtDatos.Columns.Add("Categoria");

            while (rdr.Read())
            {
                producto.Add(new Producto(rdr.GetString(0), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3), rdr.GetString(4), rdr.GetInt32(5), rdr.GetDateTime(6)));
            }
            getconexion.CerrarConexion();

            return(producto);
        }
Esempio n. 4
0
        public int getPrecioCompraProducto(string idProducto)
        {
            categoriaFacade catF = new categoriaFacade();

            string consulta = "SELECT precioReal FROM producto WHERE idProducto=\"" + idProducto + "\"";
            int    res      = 0;

            try
            {
                MySqlCommand    cmd   = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    res = Convert.ToInt32(read2.GetString(0));
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return(res);
        }
Esempio n. 5
0
        public int getTotalProductosbyMes(DateTime mes)
        {
            categoriaFacade catF = new categoriaFacade();

            string consulta = "SELECT*FROM producto where month(fecha)=" + mes.Month;
            int    res      = 0;

            try
            {
                MySqlCommand    cmd   = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    if (!read2.Equals(""))
                    {
                        res = res + 1;
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return(res);
        }
Esempio n. 6
0
        public string GuardarProducto(string idProducto, string nombre, string stock, string precioReal, string precio, string nombreCategoria, DateTime fecha, int idGenerado)
        {
            //Boolean guardar = false;
            string i = "";

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

                string consultinsert = "INSERT INTO producto(idProducto,nombre,stock,precioReal,precio,idCategoria,fecha,idGenerado) VALUES(@idProducto, @nombre,@stock,@precioReal,@precio,@idCategoria,@fecha,@idGenerado)";

                //  string consultinsert  = "INSERT INTO producto(idProducto,nombre,stock,precio,idCategoria) VALUES("+idProducto+","+nombre+","+stock+","+precio+","+idCategoria+")";
                MySqlCommand comm = new MySqlCommand(consultinsert, getconexion.getConexion());
                comm.Parameters.AddWithValue("@idProducto", idProducto);
                comm.Parameters.AddWithValue("@nombre", nombre);
                comm.Parameters.AddWithValue("@stock", stock);
                comm.Parameters.AddWithValue("@precioReal", precioReal);
                comm.Parameters.AddWithValue("@precio", precio);
                comm.Parameters.AddWithValue("@idCategoria", idCategoria);
                comm.Parameters.AddWithValue("@fecha", fecha);
                comm.Parameters.AddWithValue("@idGenerado", idGenerado);

                comm.ExecuteNonQuery();
                getconexion.CerrarConexion();
            }
            catch (Exception e)
            {
                //guardar = false;
                i = e.ToString();
            }
            return(i);
        }
Esempio n. 7
0
        public int getTotalProductosBynombreCat(string nombreCategoria)
        {
            categoriaFacade catF        = new categoriaFacade();
            string          idCategoria = catF.getCategoriaByNombre(nombreCategoria);

            string consulta = "SELECT*FROM producto WHERE idCategoria=\"" + idCategoria + "\";";
            int    res      = 0;

            try
            {
                MySqlCommand    cmd   = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    if (!read2.Equals(""))
                    {
                        res = res + 1;
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return(res);
        }
Esempio n. 8
0
        public string getStockProductoByidProd(string idProd)
        {
            categoriaFacade catF = new categoriaFacade();

            string consulta = "SELECT stock FROM producto WHERE idProducto=\"" + idProd + "\"";
            string res      = "";

            try
            {
                MySqlCommand    cmd   = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    res = read2.GetInt32(0).ToString();
                }
            }
            catch (Exception e)
            {
                res = e.ToString();
            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return(res);
        }
Esempio n. 9
0
        public bool getExisteProductoByidProd(string idProd)
        {
            categoriaFacade catF = new categoriaFacade();

            string consulta = "SELECT*FROM producto WHERE idProducto=\"" + idProd + "\"";
            bool   res      = false;

            try
            {
                MySqlCommand    cmd   = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    if (!read2.Equals(""))
                    {
                        res = true;
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return(res);
        }
Esempio n. 10
0
        public int getTotalCategoria()
        {
            categoriaFacade catF = new categoriaFacade();

            string consulta = "SELECT*FROM categoria";
            int    res      = 0;

            try
            {
                MySqlCommand    cmd   = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    res = res + 1;
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return(res);
        }
Esempio n. 11
0
        public bool getExisteProductoBynombreYidCat(string nombreProducto, string nombreCategoria)
        {
            categoriaFacade catF        = new categoriaFacade();
            string          idCategoria = catF.getCategoriaByNombre(nombreCategoria);

            string consulta = "SELECT*FROM producto WHERE nombre=\"" + nombreProducto + "\"AND idCategoria=\"" + idCategoria + "\";";
            bool   res      = false;

            try
            {
                MySqlCommand    cmd   = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    if (!read2.Equals(""))
                    {
                        res = true;
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return(res);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public string borrarProductoByid(string idproducto)
        {
            string borrar = "";

            try
            {
                categoriaFacade ctf = new categoriaFacade();


                MySqlCommand cmdCategoria = new MySqlCommand("DELETE FROM producto WHERE idProducto =\"" + idproducto + "\"", getconexion.getConexion());
                cmdCategoria.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                borrar = e.ToString();
            }
            return(borrar);
        }
Esempio n. 14
0
        public string borrarAllVendedor()
        {
            string borrar = "";

            try
            {
                categoriaFacade ctf = new categoriaFacade();


                MySqlCommand cmdCategoria = new MySqlCommand("TRUNCATE TABLE vendedor ", getconexion.getConexion());
                cmdCategoria.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                borrar = e.ToString();
            }
            return(borrar);
        }
Esempio n. 15
0
        public string getnombreProdbyidProd(string idProducto)
        {
            categoriaFacade ctf = new categoriaFacade();

            string consulta = "SELECT nombre FROM producto WHERE idProducto=\"" + idProducto + "\"";


            MySqlCommand    cmd   = new MySqlCommand(consulta, getconexion.getConexion());
            MySqlDataReader read2 = cmd.ExecuteReader();
            string          res   = "";

            while (read2.Read())
            {
                res = read2.GetString(0);
            }
            getconexion.CerrarConexion();

            return(res);
        }
Esempio n. 16
0
        public string getIdCatbyidProd(string idProducto)
        {
            categoriaFacade ctf = new categoriaFacade();

            string consulta = "SELECT idCategoria FROM producto WHERE idProducto=\"" + idProducto + "\"";


            MySqlCommand    cmd   = new MySqlCommand(consulta, getconexion.getConexion());
            MySqlDataReader read2 = cmd.ExecuteReader();
            string          res   = "";

            while (read2.Read())
            {
                res = read2.GetInt32(0).ToString();
            }
            getconexion.CerrarConexion();

            //return ctf.getNombreCategoriaById(res);
            return(res);
        }
Esempio n. 17
0
        public string getIdProductosBynombreCategoria(string nombreCategoria)
        {
            MySqlDataReader rdr         = null;
            string          producto    = "";
            categoriaFacade ctf         = new categoriaFacade();
            string          idCategoria = ctf.getCategoriaByNombre(nombreCategoria);

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

            rdr = cmd.ExecuteReader();


            while (rdr.Read())
            {
                producto = rdr.GetString(0);
            }
            getconexion.CerrarConexion();

            return(producto);
        }
Esempio n. 18
0
        public string ActualizarProducto(string idProdAnt, string idProdNuevo, string nombre, string stock, string precioReal, string precio, string nombreCategoria, DateTime fecha)
        {
            //Boolean guardar = false;
            string res = "";

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

                string consultinsert = "UPDATE  producto SET idProducto=@idProdNuevo,nombre=@nombre,stock=@stock,precioReal=@precioReal,precio=@precio,idCategoria=@idCategoria,fecha=@fecha WHERE idProducto=@idProdAnt";


                MySqlCommand comm = new MySqlCommand(consultinsert, getconexion.getConexion());
                comm.Parameters.AddWithValue("@idProdNuevo", idProdNuevo);
                comm.Parameters.AddWithValue("@nombre", nombre);
                comm.Parameters.AddWithValue("@stock", stock);
                comm.Parameters.AddWithValue("@PrecioReal", precioReal);
                comm.Parameters.AddWithValue("@precio", precio);
                comm.Parameters.AddWithValue("@idCategoria", idCategoria);
                comm.Parameters.AddWithValue("@fecha", fecha);
                comm.Parameters.AddWithValue("@idProdAnt", idProdAnt);

                MySqlDataReader MyReader2 = comm.ExecuteReader();
            }
            catch (Exception e)
            {
                res = e.ToString();
                getconexion.CerrarConexion();
            }
            finally
            {
                getconexion.CerrarConexion();
            }


            return(res);
        }
Esempio n. 19
0
        //Devuelve ultimo registro de producto asociado a categoria
        public string getMayorIdProdbyNombCat(string nombreCategoria)
        {
            categoriaFacade ctf         = new categoriaFacade();
            string          idCategoria = ctf.getCategoriaByNombre(nombreCategoria);
            string          consulta    = "SELECT idProducto FROM producto WHERE idCategoria=\"" + idCategoria + "\"";


            MySqlCommand    cmd     = new MySqlCommand(consulta, getconexion.getConexion());
            MySqlDataReader read2   = cmd.ExecuteReader();
            long            mayorid = 0;

            while (read2.Read())
            {
                long idCat = read2.GetInt64(0);
                if (idCat > mayorid)
                {
                    mayorid = idCat;
                }
            }
            getconexion.CerrarConexion();

            return(mayorid.ToString());
        }
Esempio n. 20
0
        public string GuardarProducto(string idProducto, string nombre, string stock, string precioReal, string precio, string nombreCategoria, DateTime fecha, int idGenerado)
        {
            //Boolean guardar = false;
            string i = "";

            try
            {

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

                string consultinsert = "INSERT INTO producto(idProducto,nombre,stock,precioReal,precio,idCategoria,fecha,idGenerado) VALUES(@idProducto, @nombre,@stock,@precioReal,@precio,@idCategoria,@fecha,@idGenerado)";

                //  string consultinsert  = "INSERT INTO producto(idProducto,nombre,stock,precio,idCategoria) VALUES("+idProducto+","+nombre+","+stock+","+precio+","+idCategoria+")";
                MySqlCommand comm = new MySqlCommand(consultinsert, getconexion.getConexion());
                comm.Parameters.AddWithValue("@idProducto", idProducto);
                comm.Parameters.AddWithValue("@nombre", nombre);
                comm.Parameters.AddWithValue("@stock", stock);
                comm.Parameters.AddWithValue("@precioReal", precioReal);
                comm.Parameters.AddWithValue("@precio", precio);
                comm.Parameters.AddWithValue("@idCategoria", idCategoria);
                comm.Parameters.AddWithValue("@fecha", fecha);
                comm.Parameters.AddWithValue("@idGenerado", idGenerado);

                comm.ExecuteNonQuery();
                getconexion.CerrarConexion();

            }
            catch (Exception e)
            {
                //guardar = false;
                i = e.ToString();

            }
            return i;

        }
Esempio n. 21
0
        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);

            }
        }
Esempio n. 22
0
        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);
            }

        }
Esempio n. 23
0
        private void llenarArbolCategoria()
        {

            treeViewCategoria.Items.Clear();
            TreeViewItem parent = new TreeViewItem();
            parent.Header = "Categorias";
            parent.IsSelected = true;
            treeViewCategoria.Items.Add(parent);


            TreeViewItem nuevoChild = new TreeViewItem();
            nuevoChild.Header = "All";
            nuevoChild.IsSelected = true;
            //newChild.Items.Add(newSubChild1);
            List<string> nombrecat = new List<string>();
            nombrecat.Add("All");

            categoriaFacade catFlista = new categoriaFacade();
            List<Categoria> listaCategoria = catFlista.getCategoria();
            foreach (Categoria v in listaCategoria)
            {
                nombrecat.Add(v.nombreCategoria);

            }


            parent.ItemsSource = nombrecat;


        }
Esempio n. 24
0
        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);

            }
        }
Esempio n. 25
0
        public string ActualizarProducto(string idProdAnt, string idProdNuevo, string nombre, string stock, string precioReal, string precio, string nombreCategoria, DateTime fecha)
        {
            //Boolean guardar = false;
            string res = "";

            try
            {

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

                string consultinsert = "UPDATE  producto SET idProducto=@idProdNuevo,nombre=@nombre,stock=@stock,precioReal=@precioReal,precio=@precio,idCategoria=@idCategoria,fecha=@fecha WHERE idProducto=@idProdAnt";


                MySqlCommand comm = new MySqlCommand(consultinsert, getconexion.getConexion());
                comm.Parameters.AddWithValue("@idProdNuevo", idProdNuevo);
                comm.Parameters.AddWithValue("@nombre", nombre);
                comm.Parameters.AddWithValue("@stock", stock);
                comm.Parameters.AddWithValue("@PrecioReal", precioReal);
                comm.Parameters.AddWithValue("@precio", precio);
                comm.Parameters.AddWithValue("@idCategoria", idCategoria);
                comm.Parameters.AddWithValue("@fecha", fecha);
                comm.Parameters.AddWithValue("@idProdAnt", idProdAnt);

                MySqlDataReader MyReader2 = comm.ExecuteReader();

            }
            catch (Exception e)
            {
                res = e.ToString();
                getconexion.CerrarConexion();
            }
            finally
            {
                getconexion.CerrarConexion();
            }


            return res;

        }
Esempio n. 26
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);
                }

            }
        }
Esempio n. 27
0
        public string getIdCatbyidProd(string idProducto)
        {
            categoriaFacade ctf = new categoriaFacade();

            string consulta = "SELECT idCategoria FROM producto WHERE idProducto=\"" + idProducto + "\"";


            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
            MySqlDataReader read2 = cmd.ExecuteReader();
            string res = "";
            while (read2.Read())
            {
                res = read2.GetInt32(0).ToString();
            }
            getconexion.CerrarConexion();

            //return ctf.getNombreCategoriaById(res);
            return res;
        }
Esempio n. 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);
            }
        }
Esempio n. 29
0
        public string borrarAllProducto()
        {
            string borrar = "";
            try
            {
                categoriaFacade ctf = new categoriaFacade();


                MySqlCommand cmdCategoria = new MySqlCommand("TRUNCATE TABLE producto ", getconexion.getConexion());
                cmdCategoria.ExecuteNonQuery();


            }
            catch (Exception e)
            {
                borrar = e.ToString();
            }
            return borrar;


        }
Esempio n. 30
0
        public string getnombreProdbyidProd(string idProducto)
        {
            categoriaFacade ctf = new categoriaFacade();

            string consulta = "SELECT nombre FROM producto WHERE idProducto=\"" + idProducto + "\"";


            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
            MySqlDataReader read2 = cmd.ExecuteReader();
            string res = "";
            while (read2.Read())
            {
                res = read2.GetString(0);
            }
            getconexion.CerrarConexion();

            return res;
        }
Esempio n. 31
0
        private void btnGuardaActProducto_Click(object sender, RoutedEventArgs e)
        {
            string nombrenuevaCat = txtNuevaCat.Text;
            if (!string.IsNullOrWhiteSpace(txtNuevaCat.Text))
            {

                string catActualizar = treeViewCategoria.SelectedValue.ToString();
                categoriaFacade catF = new categoriaFacade();
                string res = catF.actualizarCategoria(nombrenuevaCat, catActualizar);
                if (res.Equals(""))
                {
                    MessageBox.Show("Categoria actualizada", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                    btnGuardaActProducto.Visibility = Visibility.Hidden;
                    btnNuevaCategoria.Visibility = Visibility.Visible;
                    btncancelarEditarcat.Visibility = Visibility.Hidden;
                    txtNuevaCat.Text = "";
                    llenarArbolCategoria();
                    llenarComboBCategoria();
                    tabCodigos.actualizarArbolyTablaProductos();
                }
                else
                {
                    MessageBox.Show("Error al actualizar categoria:" + res + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Ingresar nombre a categoria", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);

            }

        }
Esempio n. 32
0
        public string actualizarCategoria(string nombreCategoriaN, string nombreCategoria)
        {
            string res = "";
            string consulta = "";
            try
            {
             
                categoriaFacade ctf = new categoriaFacade();
                string idCategoria = ctf.getCategoriaByNombre(nombreCategoria);
                consulta = "UPDATE categoria set nombreCategoria=\"" + nombreCategoriaN + "\"" + " WHERE idCategoria =\"" + idCategoria + "\";";
                MySqlCommand cmdCategoria = new MySqlCommand(consulta, getconexion.getConexion());
                
                MySqlDataReader MyReader2 = cmdCategoria.ExecuteReader();

            }
            catch (Exception e)
            {
                res = e.ToString();
                getconexion.CerrarConexion();
            }
            finally
            {
                getconexion.CerrarConexion();
            }


            return res;
        }
Esempio n. 33
0
        public int getTotalCategoriabyMes(DateTime fecha )
        {
            categoriaFacade catF = new categoriaFacade();

            string consulta = "SELECT*FROM categoria where month(fecha)="+fecha.Month;
            int res = 0;

            try
            {
                MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    if (!read2.Equals(""))
                    {
                        res = res + 1;
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e);

            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return res;

        }
Esempio n. 34
0
        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);
            }

        }
Esempio n. 35
0
        //Devuelve ultimo registro de producto asociado a categoria
        public string getMayorIdProdbyNombCat(string nombreCategoria)
        {
            categoriaFacade ctf = new categoriaFacade();
            string idCategoria = ctf.getCategoriaByNombre(nombreCategoria);
            string consulta = "SELECT idProducto FROM producto WHERE idCategoria=\"" + idCategoria + "\"";


            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
            MySqlDataReader read2 = cmd.ExecuteReader();
            long mayorid = 0;
            while (read2.Read())
            {
                long idCat = read2.GetInt64(0);
                if (idCat > mayorid)
                {
                    mayorid = idCat;
                }
            }
            getconexion.CerrarConexion();

            return mayorid.ToString();
        }
Esempio n. 36
0
        private void llenarComboBCategoria()
        {
            categoriaFacade catFlista = new categoriaFacade();
            List<Categoria> listaCategoria = catFlista.getCategoria();

            cbCategoria.Items.Clear();
            foreach (Categoria v in listaCategoria)
            {
                cbCategoria.Items.Add(v.nombreCategoria);

            }
            cbCategoria.SelectedIndex = 0;

        }
Esempio n. 37
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();


        }
Esempio n. 38
0
        private void btnNuevaCategoria_Click(object sender, RoutedEventArgs e)
        {

            if (!string.IsNullOrWhiteSpace(txtNuevaCat.Text))
            {
                categoriaFacade catF = new categoriaFacade();
                categoriaFacade catFexiste = new categoriaFacade();

                string nombreCategoria = txtNuevaCat.Text;

                bool existe = catFexiste.getExisteCategoria(nombreCategoria);

                if (existe)
                {
                    MessageBox.Show("Categoria con nombre:" + nombreCategoria + " existe" + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {

                    string res = catF.GuardarCategoria(nombreCategoria);

                    if (res.Equals(""))
                    {
                        MessageBox.Show("Categoria Guardada", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                        txtNuevaCat.Text = "";
                        llenarArbolCategoria();
                        llenarComboBCategoria();
                        tabCodigos.actualizarArbolyTablaProductos();
                        //llenarArbolCategoriaCodBarra();
                        //llenarTablaProductoCodBarra();

                        //CantidadTotalRubrosyProductos();

                    }
                    else
                    {
                        MessageBox.Show("Error al guardar categoria:" + res + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }

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

        }
Esempio n. 39
0
        public int getTotalProductosBynombreCat(string nombreCategoria)
        {
            categoriaFacade catF = new categoriaFacade();
            string idCategoria = catF.getCategoriaByNombre(nombreCategoria);

            string consulta = "SELECT*FROM producto WHERE idCategoria=\"" + idCategoria + "\";";
            int res = 0;

            try
            {
                MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    if (!read2.Equals(""))
                    {
                        res = res + 1;
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e);

            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return res;

        }
Esempio n. 40
0
        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);
            }








        }
Esempio n. 41
0
        public int getPrecioCompraProducto(string idProducto)
        {
            categoriaFacade catF = new categoriaFacade();

            string consulta = "SELECT precioReal FROM producto WHERE idProducto=\"" + idProducto + "\"";
            int res = 0;

            try
            {
                MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                    res = Convert.ToInt32(read2.GetString(0));
                }
            }
            catch (Exception e)
            {
                Console.Write(e);

            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return res;

        }
Esempio n. 42
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);
            }
        }
Esempio n. 43
0
        public string getIdProductosBynombreCategoria(string nombreCategoria)
        {

            MySqlDataReader rdr = null;
            string producto = "";
            categoriaFacade ctf = new categoriaFacade();
            string idCategoria = ctf.getCategoriaByNombre(nombreCategoria);

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


            while (rdr.Read())
            {
                producto = rdr.GetString(0);


            }
            getconexion.CerrarConexion();

            return producto;
        }
Esempio n. 44
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);
            }

        }
Esempio n. 45
0
        public List<Producto> getProductosBynombre(string nombre, string nombreCategoria)
        {
            DataTable dtDatos = new DataTable();
            MySqlDataReader rdr = null;
            List<Producto> producto = new List<Producto>();
            categoriaFacade ctf = new categoriaFacade();
            string idCategoria = ctf.getCategoriaByNombre(nombreCategoria);
            string consulta = "SELECT*FROM producto WHERE nombre=\"" + nombre + "\" AND idCategoria=\"" + idCategoria + "\"";
            //MySqlDataAdapter mdaDatos = new MySqlDataAdapter("SELECT*FROM producto", conexion.getConexion());
            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
            rdr = cmd.ExecuteReader();
            dtDatos.Columns.Add("Nombre");
            dtDatos.Columns.Add("Stock");
            dtDatos.Columns.Add("precioReal");
            dtDatos.Columns.Add("Precio");
            dtDatos.Columns.Add("Categoria");

            while (rdr.Read())
            {
                producto.Add(new Producto(rdr.GetString(0), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3), rdr.GetString(4), rdr.GetInt32(5), rdr.GetDateTime(6)));

            }
            getconexion.CerrarConexion();

            return producto;
        }
Esempio n. 46
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;

        }
Esempio n. 47
0
        public Boolean borrarProductoYnombreCategoria(string nombreCategoria)
        {
            Boolean borrar = false;
            try
            {
                categoriaFacade ctf = new categoriaFacade();
                string idCategoria = ctf.getCategoriaByNombre(nombreCategoria);
                ctf.borrarCategoriaBynombre(nombreCategoria);

                MySqlDataAdapter adapter = new MySqlDataAdapter();



                MySqlCommand cmdCategoria = new MySqlCommand("DELETE FROM producto WHERE idCategoria =\"" + idCategoria + "\"", getconexion.getConexion());
                cmdCategoria.ExecuteNonQuery();

                borrar = true;
            }
            catch (Exception e)
            {
                borrar = false;
            }
            return borrar;


        }
Esempio n. 48
0
        public int getTotalCategoria()
        {
            categoriaFacade catF = new categoriaFacade();

            string consulta = "SELECT*FROM categoria";
            int res = 0;

            try
            {
                MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
                MySqlDataReader read2 = cmd.ExecuteReader();
                while (read2.Read())
                {
                        res = res + 1;
                }
            }
            catch (Exception e)
            {
                Console.Write(e);

            }
            finally
            {
                getconexion.CerrarConexion();
            }

            return res;

        }
Esempio n. 49
0
        public string borrarProductoByid(string idproducto)
        {
            string borrar = "";
            try
            {
                categoriaFacade ctf = new categoriaFacade();


                MySqlCommand cmdCategoria = new MySqlCommand("DELETE FROM producto WHERE idProducto =\"" + idproducto + "\"", getconexion.getConexion());
                cmdCategoria.ExecuteNonQuery();


            }
            catch (Exception e)
            {
                borrar = e.ToString();
            }
            return borrar;


        }