Example #1
0
        private void librosPrestadosDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int posicion = librosPrestadosBindingSource.Position;
            int id       = dS_LibrosPrestados.LibrosPrestados[posicion].id_lib;


            if (e.ColumnIndex == 4 && id_lecLabel1.Text != "")
            {
                DS_Configuracion.configuracionDataTable configuracion            = new DS_Configuracion.configuracionDataTable();
                DS_ConfiguracionTableAdapters.configuracionTableAdapter configTa = new DS_ConfiguracionTableAdapters.configuracionTableAdapter();
                configTa.Fill(configuracion);

                DS_Historico_prestamos.historico_prestamosDataTable historicoPrestamos          = new DS_Historico_prestamos.historico_prestamosDataTable();
                DS_Historico_prestamosTableAdapters.historico_prestamosTableAdapter historicoTa = new DS_Historico_prestamosTableAdapters.historico_prestamosTableAdapter();
                DS_Historico_prestamos.historico_prestamosRow fila = historicoPrestamos.Newhistorico_prestamosRow();
                fila.fecha_devol_his  = DateTime.Now;
                fila.fecha_presta_his = dS_LibrosPrestados.LibrosPrestados[posicion].fecha_presta_pre;
                fila.id_lec_his       = int.Parse(id_lecLabel1.Text);
                fila.id_lib_his       = dS_LibrosPrestados.LibrosPrestados[posicion].id_lib;
                historicoPrestamos.Addhistorico_prestamosRow(fila);
                historicoTa.Update(historicoPrestamos);


                DS_Prestamos.prestamosDataTable prestamos = new DS_Prestamos.prestamosDataTable();
                DS_PrestamosTableAdapters.prestamosTableAdapter prestamosTa = new DS_PrestamosTableAdapters.prestamosTableAdapter();
                prestamosTa.Fill(prestamos);


                if (DateTime.Now > dS_LibrosPrestados.LibrosPrestados[posicion].fecha_devol_pre)
                {
                    int numeroLectores = dS_Lectores.lectores.Count;
                    for (int i = 0; i < numeroLectores; i++)
                    {
                        if (dS_Lectores.lectores[i].id_lec == int.Parse(id_lecLabel1.Text))
                        {
                            DateTime fechaPenal = DateTime.Now.AddDays(DateTime.Now.DayOfYear - dS_LibrosPrestados.LibrosPrestados[posicion].fecha_devol_pre.DayOfYear);
                            if (fechaPenal.DayOfYear > configuracion[0].dias_penalizacion_cnf)
                            {
                                dS_Lectores.lectores[i].fecha_penalizacion_lec = DateTime.Now.AddDays(configuracion[0].dias_penalizacion_cnf);
                                lectoresBindingSource.EndEdit();
                                lectoresTableAdapter.Update(dS_Lectores.lectores);
                            }
                            else
                            {
                                dS_Lectores.lectores[i].fecha_penalizacion_lec = DateTime.Now.AddDays(fechaPenal.DayOfYear);
                            }
                            lectoresBindingSource.EndEdit();
                            lectoresTableAdapter.Update(dS_Lectores.lectores);
                        }
                    }
                }
                else
                {
                    fila.fecha_devol_his = DateTime.Now;
                }


                if (librosTableAdapter.FillById(dS_Libros.libros, dS_LibrosPrestados.LibrosPrestados[posicion].id_lib) == 1)
                {
                    dS_Libros.libros[0].prestado_sn_lib.Remove(0);
                    dS_Libros.libros[0].prestado_sn_lib = "N";
                    librosBindingSource.EndEdit();
                    librosTableAdapter.Update(dS_Libros.libros);
                }

                for (int i = 0; i < prestamos.Count; i++)
                {
                    if (prestamos[i].id_lib_pre == dS_Libros.libros[posicion].id_lib)
                    {
                        prestamos[i].Delete();
                        prestamosTa.Update(prestamos);
                        MessageBox.Show("El libro se ha devuelto correctamente");
                    }
                }
                librosPrestadosTableAdapter.FillById(dS_LibrosPrestados.LibrosPrestados, int.Parse(id_lecLabel1.Text));
            }
            else
            {
                MessageBox.Show("Busque un lector.");
            }
            id_lecLabel1.Focus();
        }
Example #2
0
        private void bPrestamo_Click(object sender, EventArgs e)
        {
            int posicionLibros = librosBindingSource.Position;
            //int idLector = int.Parse(id_lecLabel1.Text);
            DateTime fechaActual = DateTime.Today;
            //DateTime? fechaPenalizacion = dS_Lectores.lectores[0].fecha_penalizacion_lec;
            string fecha = fechaActual.ToShortDateString();

            //int dias = dS_Configuracion.configuracion[0].dias_prestamo_cnf;
            Prestado = dS_Libros.libros[posicionLibros].prestado_sn_lib;

            if (id_lecLabel1.Text != "")
            {
                if (Prestado.Contains("N") && librosPrestadosDataGridView.RowCount <= 5)
                {
                    if (dS_Lectores.lectores[0].Isfecha_penalizacion_lecNull() || dS_Lectores.lectores[0].fecha_penalizacion_lec < DateTime.Today)
                    {
                        DS_Configuracion.configuracionDataTable configuracion = new DS_Configuracion.configuracionDataTable();
                        DS_ConfiguracionTableAdapters.configuracionTableAdapter configuracionTa = new DS_ConfiguracionTableAdapters.configuracionTableAdapter();
                        configuracionTa.Fill(configuracion);

                        int diasPrestamo = configuracion[0].dias_prestamo_cnf;
                        DS_Prestamos.prestamosDataTable prestamos = new DS_Prestamos.prestamosDataTable();
                        DS_PrestamosTableAdapters.prestamosTableAdapter prestamosTa = new DS_PrestamosTableAdapters.prestamosTableAdapter();
                        DS_Prestamos.prestamosRow fila = prestamos.NewprestamosRow();
                        fila.id_lec_pre       = dS_Lectores.lectores[0].id_lec;
                        fila.id_lib_pre       = dS_Libros.libros[posicionLibros].id_lib;
                        fila.fecha_presta_pre = DateTime.Now;
                        fila.fecha_devol_pre  = DateTime.Now.AddDays(configuracion[0].dias_prestamo_cnf);

                        prestamos.AddprestamosRow(fila);
                        prestamosTa.Update(prestamos);


                        dS_Libros.libros[posicionLibros].prestado_sn_lib.Remove(0, dS_Libros.libros[posicionLibros].prestado_sn_lib.Length);
                        dS_Libros.libros[posicionLibros].prestado_sn_lib = "S";
                        librosBindingSource.EndEdit();
                        librosTableAdapter.Update(dS_Libros.libros);
                        librosDataGridView.Update();

                        //dS_Lectores.lectores[0].Setfecha_penalizacion_lecNull();
                        //lectoresBindingSource.EndEdit();
                        //lectoresTableAdapter.Update(dS_Lectores.lectores);
                        //lectoresTableAdapter.FillById(dS_Lectores.lectores,int.Parse(tbIDLector.Text));

                        librosPrestadosTableAdapter.FillByIdLector(dS_LibrosPrestados.LibrosPrestados, int.Parse(tbIDLector.Text));

                        MessageBox.Show("El préstamo se ha realizado correctamente.");
                    }
                    else
                    {
                        MessageBox.Show("El usuario está penalizado y no puede realizar préstamos.");
                    }
                }
                else
                {
                    MessageBox.Show("No se puede prestar el libro porque ya está prestado o la persona tiene 5 libros prestados.");
                }
            }
            else
            {
                MessageBox.Show("Debes buscar primero un lector.");
            }
        }