Exemplo n.º 1
0
        public void Agregar_producto(Producto product)
        {
            try
            {
                    connServ.Abrir();

                    using (SqlCommand command = new SqlCommand())
                    {
                        command.CommandText = "INSERT INTO Productos (Id,Nombre,Categoria,Precio,PrecioOferta,Foto,Stock,StockComprometido) values (" + product.Codigo + ",'" + product.Nombre + "'," + product.Cat.Codigo + "," + product.Precio.ToString(this.cultura) + "," + product.PrecioOferta + ",@img," + product.StockActual + "," + product.StockComprometido.ToString(this.cultura) + ")";
                        command.Parameters.Add("@img", SqlDbType.Image);
                        command.Connection = connServ.Conexion();
                        if (product.FotoPath != null)
                        {
                            MemoryStream ms = new MemoryStream();
                            product.FotoPath.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                            command.Parameters["@img"].Value = ms.GetBuffer();
                        }

                        command.ExecuteNonQuery();
                    }
                    connServ.Cerrar();

            }
            catch
            {
                throw new ArgumentException("Error Agregando Producto");
            }
        }
Exemplo n.º 2
0
 public Producto leer_unproducto(int codigoproducto)
 {
     Producto p=new Producto();
     foreach (Producto UnProducto in ListaProductos)
     {
         if (UnProducto.Codigo == codigoproducto)
         {
             p = UnProducto;
         }
     }
     return p;
 }
Exemplo n.º 3
0
 //---------------------------------------------------------------------------
 public bool ModificarProducto(Producto UnProducto)
 {
     int Encontrado = 0;
     int x = 0;
     while ((x < ListaProductos.Count) && (Encontrado == 0))
     {
         Producto Product = (Producto)ListaProductos[x];
         if (Product.Codigo == UnProducto.Codigo)
         {
             Product = UnProducto;
             Encontrado = 1;
         }
         x++;
     }
     if (Encontrado == 1)
     {
         return true;
     }
     else { return false; }
 }
Exemplo n.º 4
0
        public void EliminarProducto(Producto UnProducto)
        {
            try
            {

                    connServ.Abrir();

                    using (SqlCommand command = new SqlCommand())
                    {
                        command.CommandText = "DELETE Productos WHERE Id=" + UnProducto.Codigo + "";
                        command.Connection = connServ.Conexion();

                        command.ExecuteNonQuery();
                    }
                    connServ.Cerrar();

            }
            catch
            {
                throw new ArgumentException("Error Eliminando Producto");
            }
        }
Exemplo n.º 5
0
        public bool AgregarProducto(Categoria categoria, string codigo,Image Foto, string nombre, string precio, string preciooferta, string stockactual, string stockcomprometido)
        {
            bool Exito = false;

            try
            {

                double Precio = double.Parse(precio,this.cultura);
                int Codigo = Convert.ToInt32(codigo);
                Categoria Categoria = categoria;
                int StockActual = Convert.ToInt32(stockactual);
                int StockComprometido = Convert.ToInt32(stockcomprometido);
                double PrecioOferta = double.Parse(preciooferta,this.cultura);
                Producto Producto = new Producto(Codigo, nombre, Precio, Categoria, PrecioOferta, Foto, StockActual, StockComprometido);
                //this.miDao.agregar_producto(Producto);
                this.DaoProducto.Agregar_producto(Producto);
                Exito = true;
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Error Agregando Producto",ex);
            }
            return Exito;
        }
Exemplo n.º 6
0
 public void ModificarUnStock(Producto Prod, int Cant)
 {
     this.ModificarProducto(Prod.Cat, Prod.Codigo.ToString(), Prod.FotoPath, Prod.Nombre.ToString(), Prod.Precio.ToString(), Prod.PrecioOferta.ToString(), Convert.ToString((Prod.StockActual - Cant)), Prod.StockComprometido.ToString());
 }
Exemplo n.º 7
0
        public ArrayList leer_productos(int Categoria1)
        {
            string string1 = "", string2 = "";
            if (Categoria1 > -1)
            {
                string1 = "where Categoria = ";
                string2 = Convert.ToString(Categoria1);
            }

            try
            {
                ListaProductos = new ArrayList();
                ListaProductos.Clear();

                    Producto producto = null;
                    connServ.Abrir();

                    using (SqlCommand command = new SqlCommand())
                    {//                                0    1        2      3         4        5     6          7
                        command.CommandText = "SELECT Id,Nombre,Categoria,Precio,PrecioOferta,Foto,Stock,StockComprometido FROM Productos " + string1 + string2;
                        command.Connection = connServ.Conexion();

                        SqlDataReader rdr = command.ExecuteReader();

                        while (rdr.Read())
                        {

                            DAOSQL.DAOSQLCategorias miDAOSQLCat = DAOSQL.DAOSQLCategorias.Instancia();

                            /*
                             byte[] image = (byte[])command.ExecuteScalar();
                             MemoryStream ms1 = new MemoryStream(image);
                             exceptionPictureBox.Image = Bitmap.FromStream (ms1);  //this is how it should be.  I was using Image.FromStream and was getting error.
                             */
                            byte[] image = (byte[])rdr.GetValue(5);
                            MemoryStream ms1 = new MemoryStream(image);
                            Image Foto = Bitmap.FromStream(ms1);
                            int Id = Convert.ToInt32(rdr.GetValue(0));
                            string Nombre = rdr.GetValue(1).ToString();
                            Categoria Cat = miDAOSQLCat.UnObjetoCategoria((int)rdr.GetValue(2));
                            double Precio = Convert.ToDouble(rdr.GetValue(3));
                            double PrecioOferta = Convert.ToDouble(rdr.GetValue(4));
                            int Stock = Convert.ToInt32(rdr.GetValue(6));
                            int StockComprometido = Convert.ToInt32(rdr.GetValue(7));

                            producto = new Producto(Id, Nombre, Precio, Cat, PrecioOferta, Foto, Stock, StockComprometido);
                            ListaProductos.Add(producto);
                        }
                        rdr.Close();
                    }
                    connServ.Cerrar();

            }
            catch
            {
                throw new ArgumentException("Error Cargando Productos");
            }
            return ListaProductos;
        }
Exemplo n.º 8
0
        public void modificar_producto(Producto product)
        {
            try
            {

                    connServ.Abrir();

                    using (SqlCommand command = new SqlCommand())
                    {
                        command.CommandText = "UPDATE Productos SET Id=" + product.Codigo + ",Nombre ='" + product.Nombre + "',Categoria=" + product.Cat.Codigo + ",Precio=" + product.Precio.ToString(this.cultura) + ",PrecioOferta=" + product.PrecioOferta.ToString(this.cultura) + ",Foto= @img,Stock= " + product.StockActual + ",StockComprometido=" + product.StockComprometido + " where Id="+product.Codigo;
                        command.Parameters.Add("@img", SqlDbType.Image);
                        command.Connection = connServ.Conexion();
                        if (product.FotoPath != null)
                        {
                            MemoryStream ms = new MemoryStream();
                            product.FotoPath.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                            command.Parameters["@img"].Value = ms.GetBuffer();
                        }
                        command.ExecuteNonQuery();
                    }
                    connServ.Cerrar();

            }
            catch
            {
                throw new ArgumentException("Error Modificando Producto");
            }
        }
Exemplo n.º 9
0
 public void EliminarProducto(Producto UnProducto)
 {
     ListaProductos.Remove(UnProducto);
 }
Exemplo n.º 10
0
 public void Agregar_producto(Producto product)
 {
     ListaProductos.Add(product);
 }
Exemplo n.º 11
0
 //devuelve el stock de un producto
 public int StockComprometido(Producto UnProducto)
 {
     int Cantidad = -1;//devuelve -1 si no lo encuentra
     int Encontrado = 0;
     int x = 0;
     while ((x < ListaProductos.Count) && (Encontrado == 0))
     {
         Producto Product = (Producto)ListaProductos[x];
         if (Product.Codigo == UnProducto.Codigo)
         {
             Cantidad = Product.StockComprometido;
             Encontrado = 1;
         }
         x++;
     }
     return (Cantidad);
 }
Exemplo n.º 12
0
 public void modificar_producto(Producto product)
 {
     foreach (Producto p in ListaProductos)
     {
         if (p.Codigo == product.Codigo)
         {
             p.Nombre = product.Nombre;
             p.Cat = product.Cat;
             p.FotoPath = product.FotoPath;
             p.Precio = product.Precio;
             p.PrecioOferta = product.PrecioOferta;
             p.StockActual = product.StockActual;
             p.StockComprometido = product.StockComprometido;
             break;
         }
     }
 }
Exemplo n.º 13
0
 // modifica stock de un producto
 public void ModificarStockComprometido(Producto UnProducto, int cant)
 {
     int Encontrado = 0;
     int x = 0;
     while ((x < ListaProductos.Count) && (Encontrado == 0))
     {
         Producto Product = (Producto)ListaProductos[x];
         if (Product.Codigo == UnProducto.Codigo)
         {
             Product.StockComprometido= cant;
             Encontrado = 1;
         }
         x++;
     }
 }
Exemplo n.º 14
0
 public Item(Producto UnProducto,int Cantidad)
 {
     this._Cantidad = Cantidad;
     this._UnProducto = UnProducto;
     //this.Total = UnProducto.Precio * Cantidad;
 }