private void btnEliminar_Click(object sender, EventArgs e) { AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter taEjemplar = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter(); AccesodeDatos.DsSistemaBibliotecaTableAdapters.Tabla_LibrosTableAdapter taLibros = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.Tabla_LibrosTableAdapter(); AccesodeDatos.DsSistemaBiblioteca.Tabla_LibrosRow numEjemplar = taLibros.GetData()[0]; string ejemplarId; DataGridViewRow renglon = dataGridView1.SelectedRows[0]; ejemplarId = (string)renglon.Cells[0].Value; string isbn = (string)renglon.Cells[1].Value; DialogResult d = MessageBox.Show("¿Seguro que desea eliminar?", "Menesaje", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (DialogResult.Yes == d) { //taEjemplar.DeleteQueryByEjemplar(ejemplarId); taEjemplar.DeleteQueryByEjemplar(ejemplarId); dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index); MessageBox.Show("Ejemplar eliminado", "Exitoso", MessageBoxButtons.OK, MessageBoxIcon.Information); int intEjemplares = numEjemplar.Ejemplares-1; taLibros.UpdateQueryNumEjemplar(intEjemplares, isbn); formaFather.actualizarVentana(); } }
private void btGuardar_Click(object sender, EventArgs e) { AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter taEjemplares = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter(); decimal dcPrecio = 0; string strNombre = tbNombre.Text; string strEdicion = tbEdicion.Text; string strEditorial = tbEditorial.Text; string strClasficacion = tbClasificacion.Text; string strLugar = tbLugar.Text; string MensajeErrorSQL = string.Empty; valPrecio = decimal.TryParse(mtbPrecio.Text,out dcPrecio); int intEjemplares = (int)cbEjemplares.SelectedIndex+1; String strAñodeLibro = tbAño.Text; int intAñodeLibro = int.Parse(tbAño.Text); string strIsbn = tbISBN.Text; string strAutor = tbAutor.Text; TAlibro taLibro = new TAlibro(); valClasificar = validarCajaDeTexto(tbClasificacion); valLugar = validarCajaDeTexto(tbLugar); valPrecio = ValidarMaskedTextBox(mtbPrecio); valNombre = validarCajaDeTexto(tbNombre); valEditorial = validarCajaDeTexto(tbEdicion); valAutor = validarCajaDeTexto(tbAutor); valISBN = validarCajaDeTexto(tbISBN); valAño = validarCajaDeTexto(tbAño); validarPrecio(); if (valNombre&& valEditorial&&valLugar&&valClasificar&& valAño&& valAutor&&valISBN&&valClasificar ) { if (EstadoVentana == "Insertar") { try { taLibro.Insert1(strNombre, strEdicion, strEditorial, intAñodeLibro, strAutor, strLugar, intEjemplares, strClasficacion, dcPrecio, strIsbn); taEjemplares.InsertarEjemplares(strIsbn, intEjemplares); MessageBox.Show("El Libro " + strNombre + ", Fué Guardado Exitosamente", "Registro Almacenado Exitosamente", MessageBoxButtons.OK, MessageBoxIcon.Information); tbNombre.Clear(); tbEdicion.Clear(); tbEditorial.Clear(); tbClasificacion.Clear(); tbAño.Clear(); cbEjemplares.Text = ""; tbLugar.Clear(); tbISBN.Clear(); tbAutor.Clear(); mtbPrecio.Clear(); cbEjemplares.SelectedIndex = 0; } catch (SqlException exc) { SqlError error = exc.Errors[0]; if(error.Number==2627) { MensajeErrorSQL =MessageBox.Show( "Registro ya se encuentra en la base de datos","Error De Registro",MessageBoxButtons.OK,MessageBoxIcon.Error) + exc.Message; } } }else if(EstadoVentana=="Modificar") { //Se hace la modificación en la base de datos taLibro.UpdateQueryLibroID(strNombre, strEdicion, strEditorial, intAñodeLibro, strAutor, strLugar, intEjemplares, strClasficacion, dcPrecio, strIsbn, LibroID); //Se modifican los ejemplares en la base de datos for(int c=1; c<=intEjemplares; c++) { String strEjemplarIdNew = strIsbn + "_" + c; String strEjemplarIdNewAnt = LibroID + "_" + c; taEjemplares.modificarEjemplar(strIsbn, strEjemplarIdNew, strEjemplarIdNewAnt); } // taEjemplares.InsertarEjemplares(strIsbn, intEjemplares); FormaPadre.ActualizarVentana(); MessageBox.Show("El Libro " + strNombre + ", Fue Actualizado Correctamente", "Registro Actualizado Exitosamente", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { MessageBox.Show("Sus Campos No Estan Llenos Completamente", "Error De Validacion", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Nuevo_Prestamo(int UsuarioID, string Nombre, int prestamoID, Lista_De_Prestamos ActualizaPrestamo, string idEjemplar, DateTime FechaEntrega, DateTime FechaDePrestamo, string ISBN) { //Hacemos invisible los atributos que no se ocupan InitializeComponent(); this.PrestamoID = prestamoID; this.Text = "Devolver libro"; dataGridView1.Visible = false; dataGridView2.Visible = false; tbBuscarUsuario.Visible = false; // pictureBox1.Visible = false; btnBuscarUsuario.Visible = false; label3.Visible = false; btnSeleccionarUsuario.Visible = false; tbBuscarLibro.Visible = false; // pictureBox2.Visible = false; btnBuscarLibro.Visible = false; label4.Visible = false; btnSeleccionarLibro.Visible = false; this.Size = new System.Drawing.Size(480, 450); pNuevoPrestamo.Location = new Point(20, 20); this.FormaPadre = FormaPadre; this.UsuarioID = UsuarioID; this.Nombre = Nombre; EstadoDeLaVentana = "DevolverLibro"; btnGuardar.Text = "Devolver Libro"; dtpFechaDeDevolucion.Visible = true; tbDescripcion.Visible = true; label9.Visible = true; cbDias.Visible = false; label7.Visible = false; dtpFechaPrestamo.Enabled = false; dtpFechaEntrega.Enabled = false; AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter taEjemplares = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter(); AccesodeDatos.DsSistemaBibliotecaTableAdapters.Tabla_PrestamoTableAdapter taPrestamo = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.Tabla_PrestamoTableAdapter(); AccesodeDatos.DsSistemaBiblioteca.Tabla_PrestamoDataTable tabla = taPrestamo.GetDataBy2nocontrol(UsuarioID); AccesodeDatos.DsSistemaBiblioteca.Tabla_PrestamoRow Renglon = tabla[0]; AccesodeDatos.DsSistemaBiblioteca.EJEMPLARESDataTable tablaejemplares = taEjemplares.GetDataBy2ejemplarid(Renglon.Ejemplarid); try { AccesodeDatos.DsSistemaBiblioteca.EJEMPLARESRow RenglonEjemplares ; RenglonEjemplares = tablaejemplares[0]; isbn = ISBN; tbisbn.Text = ISBN; tbEjemplar.Text = idEjemplar; this.PrestamoID = prestamoID; tbUsuario.Text = UsuarioID.ToString(); tbLibro.Text = Nombre; FechaPrestamo = FechaDePrestamo; FechaEntregatiemmpo = FechaEntrega; dtpFechaDeDevolucion.Value = Renglon.FechaDevolucion; tbDescripcion.Text = RenglonEjemplares.Descripcion; Ejemplar = idEjemplar; } catch { MessageBox.Show("Este Alumno No Cuenta Con Libros Prestados", "Alumno Sin Libros", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }
private void btnGuardar_Click(object sender, EventArgs e) { AccesodeDatos.DsSistemaBibliotecaTableAdapters.Tabla_PrestamoTableAdapter taPrestamos = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.Tabla_PrestamoTableAdapter(); try { Ejemplares = (int)taPrestamos.ScalarQuerybyEjemplarID(EjemplarID); } catch { } DateTime dtFechaDevolucion = dtpFechaDeDevolucion.Value; DateTime dtFechaPrestamo = dtpFechaPrestamo.Value; DateTime dtFechaEntrega = dtpFechaEntrega.Value; ValLibro = validarCajaDeTexto(tbLibro); valUsuario = validarCajaDeTexto(tbUsuario); string strDescripcion=tbDescripcion.Text; AccesodeDatos.DsSistemaBibliotecaTableAdapters.HISTORIAL_DE_LIBROSTableAdapter taHistorial = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.HISTORIAL_DE_LIBROSTableAdapter(); AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter taEjemplares = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter(); if (EstadoDeLaVentana == "insertar") { // Contador = (int)taPrestamos.ScalarQuery(EjemplarID); if (valUsuario && ValLibro&&Ejemplares<=0) { taPrestamos.Insert(EjemplarID, UsuarioID, dtFechaPrestamo, dtFechaEntrega, dtFechaDevolucion); // taEjemplares.UpdateQuerybyEjemplarID(libro, strDescripcion, EstadoDelLibro, EjemplarID); taEjemplares.UpdateEjemplar(EstadoDelLibro, EjemplarID); //taEjemplares.Insert(libro,strDescripcion,""); MessageBox.Show("Se a Realizado un Prestamo al Alumno " + UsuarioID, "Prestamo Realizado", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); ////Limpia todos los campos //tbUsuario.Text = string.Empty; //tbLibro.Text = string.Empty; //tbisbn.Text = string.Empty; //cbDias.SelectedIndex = 0; //tbDescripcion.Text = string.Empty; } else { MessageBox.Show("Porfavor Verifique Que Todos Los Campos Esten LLenos Correctamente", "Error De Validacion", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (EstadoDeLaVentana == "DevolverLibro") { //try // { //taPrestamos.UpdateQuery(Ejemplar, UsuarioID, dtpFechaPrestamo.Text, dtpFechaEntrega.Text,dtpFechaDeDevolucion.Text, PrestamoID); DataGridViewRow renglon = dataGridView2.SelectedRows[0]; string strNOmbreLibro = (string)renglon.Cells[1].Value; taEjemplares.UpdateQuerybyEjemplarID(isbn, strDescripcion, null, Ejemplar); //taHistorial.Insert(UsuarioID, isbn, strDescripcion, dtFechaPrestamo, dtFechaDevolucion, Ejemplar, PrestamoID); taHistorial.InsertHistirialLibro(UsuarioID, isbn, strDescripcion, dtFechaPrestamo, dtFechaDevolucion, Ejemplar, strNOmbreLibro); taPrestamos.DeleteQuerybyPrestamoID(PrestamoID); MessageBox.Show("Se a Devuelto El libro correctamente del alumno " + UsuarioID, "Prestamo devuelto", MessageBoxButtons.OK, MessageBoxIcon.Information); // } //catch {} this.Close(); } }
private void btAgregar_Click(object sender, EventArgs e) { AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter taEjemplar = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter(); //Se accede a la tabla de libros para modifcar el número de ejemplares AccesodeDatos.DsSistemaBibliotecaTableAdapters.Tabla_LibrosTableAdapter taLibros = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.Tabla_LibrosTableAdapter(); AccesodeDatos.DsSistemaBiblioteca.Tabla_LibrosRow numEjemplar = taLibros.GetData()[0]; string ejemplarId; DataGridViewRow renglon = dataGridView1.SelectedRows[0]; ejemplarId = (string)renglon.Cells[0].Value; string isbn = (string)renglon.Cells[1].Value; int conteoR = dataGridView1.Rows.Count; int siguienteEjemplar = conteoR + 1; string isbnnuevo = isbn+"_"+siguienteEjemplar; DialogResult d = MessageBox.Show("¿Desea agregar ejemplar?", "Menesaje", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (DialogResult.Yes == d) { //El siguiente For vrifica que el ID del ejemplar no este repetido de lo contrario le asigna un nuevo ID int c; for( c = 1; c <= conteoR;c++) { int intNum = (int)taEjemplar.countWhereIDigualID(isbnnuevo); if (intNum == 1) { isbnnuevo = isbn + "_" + c; } } taEjemplar.InsertQueryEjemplar(isbn,null,null,isbnnuevo); this.inventarioTableAdapter.FillByNombre(this.dsSistemaBiblioteca.Inventario, NombreLibro); MessageBox.Show("El ejemplar con el ID: "+isbnnuevo+" agregado exitosamente","Registro exitoso", MessageBoxButtons.OK, MessageBoxIcon.Information); int intEjemplares = numEjemplar.Ejemplares + 1; taLibros.UpdateQueryNumEjemplar(intEjemplares, isbn); formaFather.actualizarVentana(); } }