private void btnGuardar_Click(object sender, EventArgs e) { try { this.ValidateForm(); int idUsuario = this.UsuarioService.Save(this.GetUsuario()); MessageBox.Show("El usuario fue guardado correctamente", "Success", MessageBoxButtons.OK); var form = new UsuarioForm(idUsuario); form.Location = this.Location; form.StartPosition = FormStartPosition.Manual; form.FormClosing += delegate { this.Show(); }; form.Show(); this.Close(); } catch (FormException formException) { MessageBox.Show(formException.Message, "Error", MessageBoxButtons.OK); } catch { MessageBox.Show("Ocurrio un error", "Error", MessageBoxButtons.OK); } }
private void dgvUsuario_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { DataGridViewRow row = dgvUsuario.Rows[e.RowIndex]; DataGridViewCell cell = row.Cells["Id"]; var form = new UsuarioForm((int)cell.Value); this.DisplayForm(form); } }
private void button1_Click(object sender, EventArgs e) { if (comboBoxFuncionalidad.Text.Length == 0) { MessageBox.Show("Primero debes elegir una opción."); } else if (comboBoxFuncionalidad.Text == "Editar Usuario Existente" && textBoxUsuario.Text.Length == 0) { MessageBox.Show("Primero debes ingresar un usuario valido."); } else if (comboBoxFuncionalidad.Text == "Crear Usuario Nuevo") { this.Hide(); UsuarioForm abm_usuario = new UsuarioForm(); abm_usuario.nombre_usuario = ""; abm_usuario.StartPosition = FormStartPosition.CenterScreen; abm_usuario.ShowDialog(); } else { connection = new System.Data.SqlClient.SqlConnection(); try { connection.ConnectionString = Variables.connectionStr; connection.Open(); string query = "select * from GITAR_HEROES.Usuario where username = '******'"; command = new SqlCommand(query); command.Connection = connection; adapter = new SqlDataAdapter(command); dataTable = new DataTable(); adapter.Fill(dataTable); // validar usuario valido if (dataTable.Rows.Count > 0 && textBoxUsuario.Text != "guest" && textBoxUsuario.Text != "Guest") { this.Hide(); UsuarioForm abm_usuario = new UsuarioForm(); abm_usuario.nombre_usuario = textBoxUsuario.Text; abm_usuario.StartPosition = FormStartPosition.CenterScreen; abm_usuario.ShowDialog(); } else { MessageBox.Show("Error: No existe ningún usuario con dicho nombre."); } } catch (Exception exc) { MessageBox.Show("Error: " + exc); } } }
private void btnNuevo_Click(object sender, EventArgs e) { var form = new UsuarioForm(); this.DisplayForm(form); }