99using System . Threading . Tasks ;
1010using System . Windows . Forms ;
1111
12+
1213namespace Lab_6
1314{
1415 public partial class fBiblioteca : Form
@@ -43,6 +44,20 @@ private void btMostrarLibro_Click(object sender, EventArgs e)
4344
4445 private void btEliminarLibro_Click ( object sender , EventArgs e )
4546 {
47+ if ( dgvLibro . SelectedRows . Count == 0 )
48+ {
49+ MessageBox . Show ( "Seleccione los libros que desea eliminar." ) ;
50+ return ;
51+ }
52+
53+ DialogResult confirmResult = MessageBox . Show ( "¿Está seguro de que desea eliminar los libros seleccionados?" ,
54+ "Confirmar eliminación" ,
55+ MessageBoxButtons . YesNo ) ;
56+ if ( confirmResult == DialogResult . No )
57+ {
58+ return ;
59+ }
60+
4661 string connectionString = "your_connection_string_here" ;
4762 List < int > idsEliminar = new List < int > ( ) ;
4863
@@ -52,14 +67,7 @@ private void btEliminarLibro_Click(object sender, EventArgs e)
5267 idsEliminar . Add ( id ) ;
5368 }
5469
55- if ( idsEliminar . Count == 0 )
56- {
57- MessageBox . Show ( "Seleccione al menos un libro para eliminar." ) ;
58- return ;
59- }
60-
6170 string ids = string . Join ( "," , idsEliminar ) ;
62-
6371 string query = $ "DELETE FROM Libros WHERE id IN ({ ids } )";
6472
6573 using ( SqlConnection connection = new SqlConnection ( connectionString ) )
@@ -134,10 +142,27 @@ private void btActualizar_Click(object sender, EventArgs e)
134142
135143 private void btAgregarLibro_Click ( object sender , EventArgs e )
136144 {
137- // Datos del nuevo libro (pueden ser recogidos desde un formulario)
138- string titulo = txtTitulo . Text ; // TextBox en tu formulario
139- string autor = txtAutor . Text ;
140- int cantidadDisponible = Convert . ToInt32 ( txtCantidadDisponible . Text ) ;
145+ // Mensaje para solicitar datos del nuevo libro
146+ string titulo = Microsoft . VisualBasic . Interaction . InputBox ( "Ingrese el título del libro:" , "Agregar libro" ) ;
147+ if ( string . IsNullOrEmpty ( titulo ) )
148+ {
149+ MessageBox . Show ( "Debe ingresar un título." ) ;
150+ return ;
151+ }
152+
153+ string autor = Microsoft . VisualBasic . Interaction . InputBox ( "Ingrese el autor del libro:" , "Agregar libro" ) ;
154+ if ( string . IsNullOrEmpty ( autor ) )
155+ {
156+ MessageBox . Show ( "Debe ingresar un autor." ) ;
157+ return ;
158+ }
159+
160+ string cantidadStr = Microsoft . VisualBasic . Interaction . InputBox ( "Ingrese la cantidad disponible:" , "Agregar libro" ) ;
161+ if ( ! int . TryParse ( cantidadStr , out int cantidadDisponible ) )
162+ {
163+ MessageBox . Show ( "Debe ingresar una cantidad válida." ) ;
164+ return ;
165+ }
141166
142167 string connectionString = "your_connection_string_here" ;
143168 string query = "INSERT INTO Libros (Titulo, Autor, CantidadDisponible) VALUES (@Titulo, @Autor, @Cantidad)" ;
@@ -165,14 +190,14 @@ private void btAgregarLibro_Click(object sender, EventArgs e)
165190 }
166191 }
167192
168- private void dgvLibro_CellContentClick ( object sender , DataGridViewCellEventArgs e )
193+ private void fBiblioteca_Load ( object sender , EventArgs e )
169194 {
170-
195+ // Aquí podrías cargar la lista de libros al iniciar la aplicación
171196 }
172197
173- private void fBiblioteca_Load ( object sender , EventArgs e )
198+ private void dgvLibro_CellContentClick ( object sender , DataGridViewCellEventArgs e )
174199 {
175-
200+ // Evento del DataGridView, si necesitas alguna funcionalidad aquí
176201 }
177202 }
178203}
0 commit comments