예제 #1
0
        private void tsbDevolver_Click(object sender, EventArgs e)
        {
            int id = 0;

            try
            {
                id = (int)dgvPrestamos.SelectedRows[0].Cells[0].Value;
            }
            catch (Exception excep)
            {
                MessageBox.Show("Seleccione un prestamo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                tbFiltrar.Text = "";
            }

            if (id != 0)
            {
                DialogResult dialogResult = MessageBox.Show("¿Desea devolver el libro prestado?", "Devolver libro prestado", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    DataGridViewRow            row      = dgvPrestamos.CurrentRow;
                    AccesoDatos.Model.Prestamo prestamo = AccesoDatos.Logic.Prestamo.GetPrestamo().ListarPrestamos().Where(x => x.PrestamoId == int.Parse(row.Cells[0].Value.ToString())).FirstOrDefault();
                    prestamo.FechaDevolucion = DateTime.Today;
                    AccesoDatos.Logic.Prestamo.GetPrestamo().ActualizarPrestamo(prestamo);

                    AccesoDatos.Model.Libro libro = AccesoDatos.Logic.Libro.GetLibro().ListarLibro().Where(x => x.LibroId == prestamo.LibroLibroId).FirstOrDefault();
                    libro.StockDisponible = libro.StockDisponible + 1;
                    AccesoDatos.Logic.Libro.GetLibro().ActualizarLibro(libro);

                    cargarListaPrestamos();
                    ((FrmPpal)this.MdiParent).RefrescarTablas();
                }
            }
        }
예제 #2
0
        private void btAceptar_Click(object sender, EventArgs e)
        {
            AccesoDatos.Model.Prestamo prestamo = new AccesoDatos.Model.Prestamo();
            int stockLibro = ((AccesoDatos.Model.Libro)cbLibro.SelectedItem).StockDisponible.Value;

            if (!cbUsuario.SelectedValue.Equals("") || !cbLibro.SelectedValue.Equals(""))
            {
                if (stockLibro > 0)
                {
                    try
                    {
                        int numPrestamo = AccesoDatos.Logic.Prestamo.GetPrestamo().ListarPrestamos().Where(x => (x.UsuarioDNI == ((CBUsuarios)cbUsuario.SelectedItem).dni) && x.FechaDevolucion == null).Count();
                        //if (config.MaxPrestamoUsuario == ((AccesoDatos.Model.Usuario)cbUsuario.SelectedItem).Prestamo.Count)
                        if (config.MaxPrestamoUsuario == numPrestamo)
                        {
                            MessageBox.Show("El usuario " + cbUsuario.Text + " ha llegado al límite de préstamos", "Error al crear el préstamo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            prestamo.FechaInicio  = DateTime.Parse(tbFechaInicio.Text);
                            prestamo.FechaFin     = DateTime.Parse(tbFechaFin.Text);
                            prestamo.UsuarioDNI   = ((CBUsuarios)cbUsuario.SelectedItem).dni;
                            prestamo.LibroLibroId = ((AccesoDatos.Model.Libro)cbLibro.SelectedItem).LibroId;
                            AccesoDatos.Logic.Prestamo.GetPrestamo().InsertarPrestamo(prestamo);

                            AccesoDatos.Model.Libro libro = AccesoDatos.Logic.Libro.GetLibro().ListarLibro().Where(x => x.LibroId == prestamo.LibroLibroId).FirstOrDefault();
                            libro.StockDisponible = stockLibro - 1;
                            AccesoDatos.Logic.Libro.GetLibro().ActualizarLibro(libro);
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                    }
                    catch (Exception excepcion)
                    {
                        MessageBox.Show(excepcion.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("No hay stock disponible!", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("Faltan datos obligatorios!", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #3
0
        private void tsbAmpliar_Click(object sender, EventArgs e)
        {
            int id = 0;

            try
            {
                id = (int)dgvPrestamos.SelectedRows[0].Cells[0].Value;
            }
            catch (Exception excep)
            {
                MessageBox.Show("Seleccione un prestamo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                tbFiltrar.Text = "";
            }

            if (id != 0)
            {
                DialogResult dialogResult = MessageBox.Show("¿Desea ampliar la fecha de devolución?", "Ampliar fecha de devolución", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    DataGridViewRow row = dgvPrestamos.CurrentRow;
                    try
                    {
                        AccesoDatos.Model.Prestamo prestamo = AccesoDatos.Logic.Prestamo.GetPrestamo().ListarPrestamos().Where(x => x.PrestamoId == int.Parse(row.Cells[0].Value.ToString())).FirstOrDefault();
                        if (prestamo.FechaFin.AddDays((double)config.NumDiasPrestamo2).DayOfWeek == DayOfWeek.Saturday)
                        {
                            prestamo.FechaFin = prestamo.FechaFin.AddDays((double)config.NumDiasPrestamo2 + 2);
                        }
                        else if (prestamo.FechaFin.AddDays((double)config.NumDiasPrestamo2).DayOfWeek == DayOfWeek.Sunday)
                        {
                            prestamo.FechaFin = prestamo.FechaFin.AddDays((double)config.NumDiasPrestamo2 + 1);
                        }
                        else
                        {
                            prestamo.FechaFin = prestamo.FechaFin.AddDays((double)config.NumDiasPrestamo2);
                        }
                        AccesoDatos.Logic.Prestamo.GetPrestamo().ActualizarPrestamo(prestamo);
                        cargarListaPrestamos();
                    }
                    catch (Exception excepcion)
                    {
                        MessageBox.Show(excepcion.Message);
                    }
                }
            }
        }