Beispiel #1
0
        public void GuardarPrestamo(PrestamoLibros prestamo)
        {
            using (var Comando = Conexion.CreateCommand())
            {
                Comando.CommandText = "insert into LibroPrestado values(@FechaPrestamo, @FechaEntrega, @TipoUsuario, @TipoIdentidad, @identidad, @Nombre, @Apellido, @codigo)";

                Comando.Parameters.AddWithValue("@FechaPrestamo", prestamo.Fechaprestamo);
                Comando.Parameters.AddWithValue("@FechaEntrega", prestamo.Fechaentrega);
                Comando.Parameters.AddWithValue("@TipoUsuario", prestamo.TipoUsuario);;
                Comando.Parameters.AddWithValue("@TipoIdentidad", prestamo.TipoIdentidad);
                Comando.Parameters.AddWithValue("@identidad", prestamo.Identificacion);
                Comando.Parameters.AddWithValue("@Nombre", prestamo.Nombre);
                Comando.Parameters.AddWithValue("@Apellido", prestamo.Apellido);
                Comando.Parameters.AddWithValue("@codigo", prestamo.Codigo);

                /*              Comando.Parameters.Add("FechaPrestamo", SqlDbType.VarChar).Value = prestamo.Fechaprestamo;
                 *            Comando.Parameters.Add("FechaEntrega", SqlDbType.VarChar).Value = prestamo.Fechaentrega;
                 *            Comando.Parameters.Add("TipoUsuario", SqlDbType.VarChar).Value = prestamo.TipoUsuario;
                 *            Comando.Parameters.Add("TipoIdentidad", SqlDbType.VarChar).Value = prestamo.TipoIdentidad;
                 *            Comando.Parameters.Add("identidad", SqlDbType.VarChar).Value = prestamo.Identificacion;
                 *            Comando.Parameters.Add("Nombre", SqlDbType.VarChar).Value = prestamo.Nombre;
                 *            Comando.Parameters.Add("Apellido", SqlDbType.VarChar).Value = prestamo.Apellido;
                 *            Comando.Parameters.Add("Codigo", SqlDbType.VarChar).Value = prestamo.Codigo;
                 */
                Comando.ExecuteNonQuery();
            }
        }
Beispiel #2
0
        public PrestamoLibros BuscarIdentificacion(string identidad)
        {
            using (var comando = Conexion.CreateCommand())
            {
                PrestamoLibros ConsulLibro = new PrestamoLibros();
                comando.CommandText = "select * from LibroPrestado Where identidad ='" + identidad + "' ";

                Reader = comando.ExecuteReader();
                string prueba;
                if (Reader.Read() == true)
                {
                    ConsulLibro.Identificacion = Reader["identidad"].ToString();
                    ConsulLibro.Fechaprestamo  = Reader["FechaPrestamo"].ToString();
                    ConsulLibro.Fechaentrega   = Reader["FechaEntrega"].ToString();
                    ConsulLibro.TipoUsuario    = Reader["TipoUsuario"].ToString();
                    ConsulLibro.TipoIdentidad  = Reader["TipoIdentidad"].ToString();
                    ConsulLibro.Nombre         = Reader["Nombre"].ToString();
                    ConsulLibro.Apellido       = Reader["Apellido"].ToString();
                    prueba             = Reader["Codigo"].ToString();           // codigo
                    ConsulLibro.Codigo = Convert.ToString(prueba);
                    // ConsulLibro.Estado = (string)Reader["Estado"].ToString();

                    return(ConsulLibro);
                }
                else
                {
                    ConsulLibro = null;
                    return(ConsulLibro);
                }
            }
        }
Beispiel #3
0
        public string Eliminar(PrestamoLibros prestamo)
        {
            try
            {
                conexion.Open();

                if (database.Validar(prestamo.Codigo) == true)
                {
                    libros.ActualizarCantidadEliminar(prestamo.Codigo);
                    database.CambiarEstadoDisponible(prestamo.Codigo);
                    database.Eliminar(prestamo);
                    conexion.Close();
                    return("Se elimino el prestamo ");
                }
                else
                {
                    conexion.Close();
                    return(dato.ToString());
                }
            }
            catch (Exception ex)
            {
                conexion.Close();
                return("error de base de datos" + ex.Message.ToString());
            }
        }
Beispiel #4
0
        public PrestamoLibros BuscarCodigo(string codigo)
        {
            using (var comando = Conexion.CreateCommand())
            {
                PrestamoLibros consultar = new PrestamoLibros();
                comando.CommandText = "select * from LibroPrestado where Codigo ='" + codigo + "' ";

                Reader = comando.ExecuteReader();

                string prueba;
                if (Reader.Read())
                {
                    //     consultar.Fechaprestamo = Reader["FechaPrestamo"].ToString();
                    //     consultar.Fechaentrega = Reader["FechaEntrega"].ToString();
                    prueba = Reader["Codigo"].ToString();                      // codigo

                    consultar.Codigo         = Convert.ToString(prueba);
                    consultar.Identificacion = Reader["identidad"].ToString();
                    consultar.Nombre         = Reader["Nombre"].ToString();
                    consultar.Apellido       = Reader["Apellido"].ToString();
                    consultar.TipoIdentidad  = Reader["TipoIdentidad"].ToString();
                    consultar.TipoUsuario    = Reader["TipoUsuario"].ToString();

                    return(consultar);
                }
                else
                {
                    consultar = null;
                    return(consultar);
                }
            }
        }
Beispiel #5
0
        public PrestamoLibros BuscarCodigoPrestado(string codigo)
        {
            conexion.Open();
            prestamo = database.BuscarCodigo(codigo);
            conexion.Close();

            return(prestamo);
        }
Beispiel #6
0
        public PrestamoLibros BuscarIdentidad(string dato)
        {
            conexion.Open();
            prestamo = database.BuscarIdentificacion(dato);
            conexion.Close();

            return(prestamo);
        }
Beispiel #7
0
        public void Eliminar(PrestamoLibros prestamo)
        {
            using (var comando = Conexion.CreateCommand())
            {
                comando.CommandText = "delete from LibroPrestado where identidad ='" + prestamo.Identificacion + "'";

                comando.ExecuteNonQuery();
            }
        }
Beispiel #8
0
        public string GuardarPrestamo(PrestamoLibros prestamo)
        {
            try
            {
                conexion.Open();

                if (database.Validar(prestamo.Codigo) == true)
                {
                    if (libros.ActualizarCantidadGuardar(prestamo.Codigo) == true)
                    {
                        Datox = libros.BuscarCodigo(prestamo.Codigo);

                        if (Datox.Cantidad == 0)
                        {
                            database.CambiarEstado(prestamo.Codigo);
                            database.GuardarPrestamo(prestamo);
                        }
                        else
                        {
                            database.GuardarPrestamo(prestamo);
                        }

                        conexion.Close();
                        return("Se registro el prestamo");
                    }

                    else
                    {
                        conexion.Close();
                        return("No hay libros disponibles");
                    }
                }
                else
                {
                    conexion.Close();
                    return("Error, no existe el libro");
                }
            }
            catch (SqlException ex)
            {
                if (ex.Number == 2627)
                {
                    libros.ActualizarCantidadEliminar(prestamo.Codigo);
                    conexion.Close();
                    return("Error, un usuario solo puede tener un libro prestado");
                }
                else
                {
                    conexion.Close();
                    return(ex.Message.ToString());
                }
            }
        }
Beispiel #9
0
        public Boolean prueba(PrestamoLibros prestamo)
        {
            ValidaCantidad = libros.BuscarCodigo(prestamo.Codigo);

            if (ValidaCantidad.Cantidad >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #10
0
 public string Actualizar(PrestamoLibros prestamo)
 {
     try
     {
         conexion.Open();
         database.Actualizar(prestamo);
         conexion.Close();
         return("Se actualizo el prestamo ");
     }
     catch (Exception ex)
     {
         conexion.Close();
         return("error de base de datos" + ex.Message.ToString());
     }
 }
Beispiel #11
0
        public PrestamoLibros Map(SqlDataReader reader)
        {
            PrestamoLibros libros = new PrestamoLibros();

            libros.Identificacion = (string)reader["identidad"];
            libros.Fechaprestamo  = (string)reader["FechaPrestamo"];
            libros.Fechaentrega   = (string)reader["FechaEntrega"];
            libros.TipoUsuario    = (string)reader["TipoUsuario"];
            libros.TipoIdentidad  = (string)reader["TipoIdentidad"];
            libros.Nombre         = (string)reader["Nombre"];
            libros.Apellido       = (string)reader["Apellido"];
            libros.Codigo         = (string)reader["Codigo"];
            libros.Estado         = "Prestado";

            return(libros);
        }
Beispiel #12
0
        public IList <PrestamoLibros> Consultar()
        {
            using (var Comando = Conexion.CreateCommand())
            {
                Comando.CommandText = "Select * from LibroPrestado";
                Reader = Comando.ExecuteReader();

                while (Reader.Read())
                {
                    PrestamoLibros prestamo = new PrestamoLibros();
                    prestamo = Map(Reader);
                    listaPrestamo.Add(prestamo);
                }
            }
            return(listaPrestamo);
        }
Beispiel #13
0
        public void Actualizar(PrestamoLibros prestamo)
        {
            using (var Comando = Conexion.CreateCommand())
            {
                Comando.CommandText = "update LibroPrestado set Nombre = @Nombre, Apellido = @Apellido";


                Comando.Parameters.Add("@identidad", SqlDbType.VarChar).Value     = prestamo.Identificacion;
                Comando.Parameters.Add("@FechaPrestamo", SqlDbType.VarChar).Value = prestamo.Fechaprestamo;
                Comando.Parameters.Add("@FechaEntrega", SqlDbType.VarChar).Value  = prestamo.Fechaentrega;
                Comando.Parameters.Add("@TipoUsuario", SqlDbType.VarChar).Value   = prestamo.TipoUsuario;
                Comando.Parameters.Add("@TipoIdentidad", SqlDbType.VarChar).Value = prestamo.TipoIdentidad;
                Comando.Parameters.Add("@Nombre", SqlDbType.VarChar).Value        = prestamo.Nombre;
                Comando.Parameters.Add("@Apellido", SqlDbType.VarChar).Value      = prestamo.Apellido;
                Comando.Parameters.Add("@Codigo", SqlDbType.VarChar).Value        = prestamo.Codigo;

                Comando.ExecuteNonQuery();
            }
        }
Beispiel #14
0
        public void ActualizarCantidadEliminar(PrestamoLibros prestamo)
        {
            ValidaCantidad = libros.BuscarCodigo(prestamo.Codigo);

            cantidad.Codigo          = ValidaCantidad.Codigo;
            cantidad.Area            = ValidaCantidad.Area;
            cantidad.Autor           = ValidaCantidad.Autor;
            cantidad.Autor2          = ValidaCantidad.Autor2;
            cantidad.Nombre          = ValidaCantidad.Nombre;
            cantidad.Ciudad          = ValidaCantidad.Ciudad;
            cantidad.Pais            = ValidaCantidad.Pais;
            cantidad.NumeroPaginas   = ValidaCantidad.NumeroPaginas;
            cantidad.FechaImpresion  = ValidaCantidad.FechaImpresion;
            cantidad.Id              = ValidaCantidad.Id;
            cantidad.NombreEditorial = ValidaCantidad.NombreEditorial;
            cantidad.Direccion       = ValidaCantidad.Direccion;
            cantidad.Telefono        = ValidaCantidad.Telefono;
            cantidad.Cantidad        = ValidaCantidad.Cantidad - 1;
            cantidad.Estado          = ValidaCantidad.Estado;

            libros.Actualizar(cantidad);
        }
Beispiel #15
0
        private void pictureBox5_Click(object sender, EventArgs e)
        {
            string dato   = TxtIdentificacion.Text;
            string codigo = TxtCodigo.Text;

            try
            {
                if ((TxtCodigo.Text != "") && (TxtIdentificacion.Text != ""))
                {
                    MessageBox.Show("Eliga la opcion con la que desea buscar los datos");
                    limpiar();
                    Bloquear();
                }
                else if (TxtIdentificacion.Text != "")
                {
                    mostrarDatos = servicio.BuscarUsuario(dato);

                    if (Mostrar != null)
                    {
                        //      Desbloquer();

                        TxtTipoIdenti.Text     = mostrarDatos.TipoIdentidad;
                        TxtTipoUsu.Text        = mostrarDatos.TipoUsuario;
                        TxtNombre.Text         = mostrarDatos.Nombre;
                        TxtIdentificacion.Text = mostrarDatos.Identificacion;
                        TxtApellido.Text       = mostrarDatos.Apellido;
                    }
                    else
                    {
                        MessageBox.Show("No se encontraron los datos de el usuario", "titulo", MessageBoxButtons.OK, MessageBoxIcon.Question);
                        limpiar(); //Bloquear();
                    }
                }
                else if (TxtCodigo.Text != "")
                {
                    Mostrar = servicio.BuscarCodigoPrestado(codigo);
                    if (Mostrar != null)
                    {
                        //  Desbloquer();

                        TxtCodigo.Text         = Convert.ToString(Mostrar.Codigo);
                        TxtIdentificacion.Text = Mostrar.Identificacion;
                        TxtNombre.Text         = Mostrar.Nombre;
                        TxtApellido.Text       = Mostrar.Apellido;
                        TxtTipoIdenti.Text     = Mostrar.TipoIdentidad;
                        TxtTipoUsu.Text        = Mostrar.TipoUsuario;


                        Eliminar.Visible = true;
                        Editar.Visible   = true;
                        Guardar.Visible  = false;
                    }
                    else
                    {
                        MessageBox.Show("No se encontro registro del prestamo", "titulo", MessageBoxButtons.OK, MessageBoxIcon.Question);
                        limpiar();  //    Bloquear();
                    }
                }
                else
                {
                    MessageBox.Show("Digite un codigo", "titulo", MessageBoxButtons.OK, MessageBoxIcon.Question);
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("Error, dato no encontrado " + error.Message.ToString());
            }
        }