Пример #1
0
//Eliminar

        public static int EliminarProveedor(int pId)
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("EliminarProveedor", _connection as SqlConnection);
                    _command.CommandType = CommandType.StoredProcedure;

                    _command.Parameters.AddWithValue("@Id", pId);

                    int _resultado = _command.ExecuteNonQuery();

                    _connection.Close();

                    return(_resultado);
                }
            }

            catch (IndexOutOfRangeException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }
Пример #2
0
        public static List <Cliente> ConsultarClientePorNumeroDeCompras(int pNumeroDeCompras)
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("ConsultarClientePorNumeroDeCompras", _connection as SqlConnection);

                    _command.CommandType = CommandType.StoredProcedure;

                    _command.Parameters.AddWithValue("@NumeroDeCompras", pNumeroDeCompras);

                    SqlDataReader _reader = _command.ExecuteReader();

                    List <Cliente> _listaCliente = new List <Cliente>();

                    while (_reader.Read())
                    {
                        Cliente _cliente = new Cliente();

                        _cliente.Id                = _reader.GetInt32(0);
                        _cliente.Nombre            = _reader.GetString(1);
                        _cliente.Apellido          = _reader.GetString(2);
                        _cliente.Telefono          = _reader.GetString(3);
                        _cliente.CorreoElectronico = _reader.GetString(4);
                        _cliente.Genero            = _reader.GetString(5);
                        _cliente.DUI               = _reader.GetString(6);
                        _cliente.NIT               = _reader.GetString(7);
                        _cliente.ConsumidorFinal   = _reader.GetString(8);
                        _cliente.SalonDeBelleza    = _reader.GetString(9);
                        _cliente.NumeroDeCompras   = _reader.GetInt32(10);

                        _listaCliente.Add(_cliente);
                    }

                    _reader.Close();

                    _connection.Close();

                    return(_listaCliente);
                }
            }

            catch (IndexOutOfRangeException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }
Пример #3
0
        //Buscar

        public static List <Producto> ConsultarProductoPorFechaIngreso(DateTime pFechaIngreso)
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("ConsultarPoducto", _connection as SqlConnection);

                    _command.CommandType = CommandType.StoredProcedure;

                    _command.Parameters.AddWithValue("@FechaIngresp", pFechaIngreso);

                    SqlDataReader _reader = _command.ExecuteReader();

                    List <Producto> _listaProducto = new List <Producto>();

                    while (_reader.Read())
                    {
                        Producto _Producto = new Producto();


                        _Producto.Nombre          = _reader.GetString(1); //Empieza de 0
                        _Producto.Marca           = _reader.GetString(2);
                        _Producto.FamiliaProducto = _reader.GetString(3);
                        _Producto.FechaCaducacion = _reader.GetDateTime(4);
                        _Producto.FechaIngreso    = _reader.GetDateTime(5);
                        _Producto.Precio          = _reader.GetFloat(6); //Es float
                        _Producto.Categoria       = _reader.GetString(7);
                        _Producto.Unidades        = _reader.GetInt32(8); //es int
                        _Producto.Disponibilidad  = _reader.GetString(9);

                        _listaProducto.Add(_Producto);
                    }

                    _reader.Close();

                    _connection.Close();

                    return(_listaProducto);
                }
            }

            catch (IndexOutOfRangeException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }
Пример #4
0
        public static List <Proveedor> BuscarProveedorPorNombre(string pNombre)
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("BuscarProveedorPorNombre", _connection as SqlConnection);

                    _command.CommandType = CommandType.StoredProcedure;

                    _command.Parameters.AddWithValue("@Nombre", pNombre);

                    SqlDataReader _reader = _command.ExecuteReader();

                    List <Proveedor> _listaProveedor = new List <Proveedor>();

                    while (_reader.Read())
                    {
                        Proveedor _proveedor = new Proveedor();

                        _proveedor.Id                = _reader.GetInt32(0);
                        _proveedor.Nombre            = _reader.GetString(1);
                        _proveedor.Empresa           = _reader.GetString(2);
                        _proveedor.Direccion         = _reader.GetString(3);
                        _proveedor.Telefono          = _reader.GetString(4);
                        _proveedor.CorreoElectronico = _reader.GetString(5);
                        _proveedor.NIT               = _reader.GetString(6);
                        _proveedor.NumeroDeRegistro  = _reader.GetInt32(7);

                        _listaProveedor.Add(_proveedor);
                    }

                    _reader.Close();

                    _connection.Close();

                    return(_listaProveedor);
                }
            }

            catch (IndexOutOfRangeException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }
Пример #5
0
        //Obtener

        public static List <Producto> ObtenerProducto()
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("ObtenerProducto", _connection as SqlConnection);

                    _command.CommandType = CommandType.StoredProcedure;

                    SqlDataReader _reader = _command.ExecuteReader();

                    List <Producto> _listaProducto = new List <Producto>();

                    while (_reader.Read())
                    {
                        Producto _producto = new Producto();             //minuscula ok

                        _producto.Id              = _reader.GetInt32(0); //
                        _producto.Nombre          = _reader.GetString(1);
                        _producto.Marca           = _reader.GetString(2);
                        _producto.FamiliaProducto = _reader.GetString(3);
                        _producto.FechaCaducacion = _reader.GetDateTime(4);
                        _producto.FechaIngreso    = _reader.GetDateTime(5);
                        _producto.Precio          = _reader.GetFloat(6);
                        _producto.Categoria       = _reader.GetString(7);
                        _producto.Unidades        = _reader.GetInt32(8);
                        _producto.Disponibilidad  = _reader.GetString(9);

                        _listaProducto.Add(_producto);
                    }

                    _reader.Close();

                    _connection.Close();

                    return(_listaProducto);
                }
            }

            catch (IndexOutOfRangeException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }
Пример #6
0
//Buscar

        public static List <Venta> ConsultarVenta(int pId)
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("BuscarVenta", _connection as SqlConnection);

                    _command.CommandType = CommandType.StoredProcedure;

                    _command.Parameters.AddWithValue("@Id", pId);

                    SqlDataReader _reader = _command.ExecuteReader();

                    List <Venta> _listaVenta = new List <Venta>();

                    while (_reader.Read())
                    {
                        Venta _Venta = new Venta();

                        _Venta.Id         = _reader.GetInt32(0);
                        _Venta.Fecha      = _reader.GetDateTime(1);
                        _Venta.Total      = _reader.GetFloat(2);
                        _Venta.EmpleadoId = _reader.GetInt32(3);
                        _Venta.ClienteId  = _reader.GetInt32(4);



                        _listaVenta.Add(_Venta);
                    }

                    _reader.Close();

                    _connection.Close();

                    return(_listaVenta);
                }
            }

            catch (IndexOutOfRangeException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }
Пример #7
0
        //Modificar

        public static int ModificarCliente(Cliente pCliente)
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("ModificarCliente", _connection as SqlConnection);
                    _command.CommandType = CommandType.StoredProcedure;

                    _command.Parameters.AddWithValue("@Nombre", pCliente.Nombre);
                    _command.Parameters.AddWithValue("@Apellido", pCliente.Apellido);
                    _command.Parameters.AddWithValue("@Telefono", pCliente.Telefono);
                    _command.Parameters.AddWithValue("@CorreoElectronic", pCliente.CorreoElectronico);
                    _command.Parameters.AddWithValue("@Genero", pCliente.Genero);
                    _command.Parameters.AddWithValue("@DUI", pCliente.DUI);
                    _command.Parameters.AddWithValue("@NIT", pCliente.NIT);
                    _command.Parameters.AddWithValue("@ConsumidorFinal", pCliente.ConsumidorFinal);
                    _command.Parameters.AddWithValue("@SalonDeBelleza", pCliente.SalonDeBelleza);
                    _command.Parameters.AddWithValue("@NumeroDeCompras", pCliente.NumeroDeCompras);
                    _command.Parameters.AddWithValue("@Id", pCliente.Id);



                    int _resultado = _command.ExecuteNonQuery();

                    _connection.Close();

                    return(_resultado);
                }
            }

            catch (IndexOutOfRangeException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }
Пример #8
0
        public static int AgregarProducto(Producto pProducto)
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("AgregarProducto", _connection as SqlConnection);
                    _command.CommandType = CommandType.StoredProcedure;

                    _command.Parameters.AddWithValue("@Nombre", pProducto.Nombre);
                    _command.Parameters.AddWithValue("@Marca", pProducto.Marca);
                    _command.Parameters.AddWithValue("@FamiliaProducto", pProducto.FamiliaProducto);
                    _command.Parameters.AddWithValue("@FechaCaducacion", pProducto.FechaCaducacion);
                    _command.Parameters.AddWithValue("@FechaIngreso", pProducto.FechaIngreso);
                    _command.Parameters.AddWithValue("@Precio", pProducto.Precio);
                    _command.Parameters.AddWithValue("@Categoria", pProducto.Categoria);
                    _command.Parameters.AddWithValue("@Unidades", pProducto.Unidades);
                    _command.Parameters.AddWithValue("@Disponibilidad", pProducto.Disponibilidad);



                    int _resultado = _command.ExecuteNonQuery();

                    _connection.Close();

                    return(_resultado);
                }
            }

            catch (NullReferenceException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }
Пример #9
0
//Modificar

        public static int ModificarProveedor(Proveedor pProveedor)
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("ModificarProveedor", _connection as SqlConnection);
                    _command.CommandType = CommandType.StoredProcedure;

                    _command.Parameters.AddWithValue("@Nombre", pProveedor.Nombre);
                    _command.Parameters.AddWithValue("@Apellido", pProveedor.Apellido);
                    _command.Parameters.AddWithValue("@Empresa", pProveedor.Empresa);
                    _command.Parameters.AddWithValue("@Direccion", pProveedor.Direccion);
                    _command.Parameters.AddWithValue("@Telefono", pProveedor.Telefono);
                    _command.Parameters.AddWithValue("@CorreoElectronico", pProveedor.CorreoElectronico);
                    _command.Parameters.AddWithValue("@Nit", pProveedor.NIT);
                    _command.Parameters.AddWithValue("@NumeroDeRegistro", pProveedor.NumeroDeRegistro);


                    int _resultado = _command.ExecuteNonQuery();

                    _connection.Close();

                    return(_resultado);
                }
            }

            catch (IndexOutOfRangeException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }
Пример #10
0
//Modificar

        public static int ModificarVenta(Venta pVenta)
        {
            try
            {
                using (IDbConnection _connection = DBComun.ObtenerConexion())
                {
                    _connection.Open();

                    SqlCommand _command = new SqlCommand("ModificarVenta", _connection as SqlConnection);
                    _command.CommandType = CommandType.StoredProcedure;

                    _command.Parameters.AddWithValue("@Fecha", pVenta.Fecha);
                    _command.Parameters.AddWithValue("@Total", pVenta.Total);
                    _command.Parameters.AddWithValue("@Empleadoid", pVenta.EmpleadoId);
                    _command.Parameters.AddWithValue("@Clienteid", pVenta.ClienteId);



                    int _resultado = _command.ExecuteNonQuery();

                    _connection.Close();

                    return(_resultado);
                }
            }

            catch (IndexOutOfRangeException ex1)
            {
                throw;
            }
            catch (FormatException ex2)
            {
                throw;
            }
            catch (Exception ex3)
            {
                throw;
            }
        }