private void btnGuardar_Click(object sender, EventArgs e) { using ( var context = new EntidadesLibreria() ) { try { if (txtCedulaUsuario.Text != string.Empty && txtNombreUsuario.Text != string.Empty && txtApellidoUsuario.Text != string.Empty && txtDireccionUsuario.Text != string.Empty && txtCelularUsuario.Text != string.Empty && cbLibroSeleccionado.Text != string.Empty) { context.INSERTAR_USUARIO(txtCedulaUsuario.Text, txtNombreUsuario.Text, txtApellidoUsuario.Text, txtDireccionUsuario.Text, Convert.ToDecimal(txtCelularUsuario.Text), Convert.ToDecimal(cbLibroSeleccionado.SelectedValue)); context.SaveChanges(); txtCedulaUsuario.Text = string.Empty; txtNombreUsuario.Text = string.Empty; txtApellidoUsuario.Text = string.Empty; txtDireccionUsuario.Text = string.Empty; txtCelularUsuario.Text = string.Empty; cbLibroSeleccionado.SelectedIndex = 0; MessageBox.Show(this, "Usuario registrado correctamente"); } else { MessageBox.Show(this, "No pueden existir campos vacios"); } } catch (Exception ex) { MessageBox.Show(this, "Error: " + ex.Message); } } }
private void btnGuardarLibro_Click(object sender, EventArgs e) { using (var context = new EntidadesLibreria()) { var libro = context.INSERTAR_LIBRO(txtNombreLibro.Text, txtNombreAutor.Text); try { if (txtNombreAutor.Text != string.Empty && txtNombreLibro.Text != string.Empty) { context.SaveChanges(); txtNombreAutor.Text = string.Empty; txtNombreLibro.Text = string.Empty; MessageBox.Show(this, "El libro ha sido guardado correctamente"); } else { MessageBox.Show(this, "No puede dejar los campos vacios"); } } catch (Exception ex) { MessageBox.Show(this, "Error: " + ex.Message); } } }
private void btnGuardarLibro_Click(object sender, EventArgs e) { using ( var context = new EntidadesLibreria() ) { var libro = context.INSERTAR_LIBRO(txtNombreLibro.Text, txtNombreAutor.Text); try { if (txtNombreAutor.Text != string.Empty && txtNombreLibro.Text != string.Empty) { context.SaveChanges(); txtNombreAutor.Text = string.Empty; txtNombreLibro.Text = string.Empty; MessageBox.Show(this, "El libro ha sido guardado correctamente"); } else { MessageBox.Show(this, "No puede dejar los campos vacios"); } } catch (Exception ex) { MessageBox.Show(this, "Error: " + ex.Message); } } }
private void btnGuardar_Click(object sender, EventArgs e) { using (var context = new EntidadesLibreria()) { try { if (txtCedulaUsuario.Text != string.Empty && txtNombreUsuario.Text != string.Empty && txtApellidoUsuario.Text != string.Empty && txtDireccionUsuario.Text != string.Empty && txtCelularUsuario.Text != string.Empty && cbLibroSeleccionado.Text != string.Empty) { context.INSERTAR_USUARIO(txtCedulaUsuario.Text, txtNombreUsuario.Text, txtApellidoUsuario.Text, txtDireccionUsuario.Text, Convert.ToDecimal(txtCelularUsuario.Text), Convert.ToDecimal(cbLibroSeleccionado.SelectedValue)); context.SaveChanges(); txtCedulaUsuario.Text = string.Empty; txtNombreUsuario.Text = string.Empty; txtApellidoUsuario.Text = string.Empty; txtDireccionUsuario.Text = string.Empty; txtCelularUsuario.Text = string.Empty; cbLibroSeleccionado.SelectedIndex = 0; MessageBox.Show(this, "Usuario registrado correctamente"); } else { MessageBox.Show(this, "No pueden existir campos vacios"); } } catch (Exception ex) { MessageBox.Show(this, "Error: " + ex.Message); } } }