private void BtnInsertar_Click(object sender, EventArgs e) { try { string Rpta = ""; if (CboRol.Text == string.Empty || txtNombre.Text == string.Empty || txtEmail.Text == string.Empty || txtClave.Text == string.Empty) { this.MensajeError("Falta ingresa algunos datos, seran remarcados."); Erroricono.SetError(CboRol, "Seleccione un rol."); Erroricono.SetError(txtNombre, "Ingrese un nombre"); Erroricono.SetError(txtEmail, "Ingrese un email."); Erroricono.SetError(txtClave, "Ingrese una clave de acceso"); } else { Rpta = NUsuario.Insertar(Convert.ToInt32(CboRol.SelectedValue), txtNombre.Text.Trim(), CboTipoDocumento.Text, txtNumDocumento.Text.Trim(), txtDireccion.Text.Trim(), txtTelefono.Text.Trim(), txtEmail.Text.Trim(), txtClave.Text.Trim()); if (Rpta.Equals("OK")) { this.MensajeOK("Se inserto de forma correcta el registro"); this.Listar(); } else { this.MensajeError(Rpta); } } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
private void button1_Click(object sender, EventArgs e) { try { string rpta = ""; if (cmbrol.Text == string.Empty || txtusuario.Text == string.Empty || txtpass.Text == string.Empty) { this.MensajeError("Ingrese los datos faltantes"); errorIcono.SetError(cmbrol, "Seleccione un rol"); errorIcono.SetError(txtusuario, "Ingrese un nombre"); errorIcono.SetError(txtpass, "Ingrese una contraseña"); } else { rpta = NUsuario.Insertar(Convert.ToInt32(cmbrol.SelectedValue), txtusuario.Text.Trim(), txtpass.Text.Trim()); if (rpta.Equals("OK")) { this.MensajeOk("Se ha creado el usuario correctamente"); this.Limpiar(); this.Listar(); TabGral.SelectedIndex = 0; } else { this.MensajeError(rpta); } } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
private void BtnInsertar_Click(object sender, EventArgs e) { try { string Rpta = ""; if (CboRol.Text == String.Empty || TxtNombre.Text == string.Empty || TxtEmail.Text == string.Empty || TxtClave.Text == string.Empty) { this.MensajeError("Falta ingresar unos datos"); ErrorIcono.SetError(CboRol, "Tienes que elegir un rol"); ErrorIcono.SetError(TxtNombre, "Ingresa un nombre"); ErrorIcono.SetError(TxtEmail, "Ingresa un email"); ErrorIcono.SetError(CboRol, "Ingresa una clave"); } else { Rpta = NUsuario.Insertar(Convert.ToInt32(CboRol.SelectedValue), TxtNombre.Text.Trim(), CboTipoDoc.Text, TxtNumDoc.Text.Trim(), TxtDireccion.Text.Trim(), TxtTelefono.Text.Trim(), TxtEmail.Text.Trim(), TxtClave.Text.Trim()); if (Rpta.Equals("OK")) { this.MensajeOK("Se insertaron los datos de manera correcta"); this.Listar(); } else { this.MensajeError(Rpta); } } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
private void GuardarUSuario() { int contador = 0; foreach (Control ctrl in this.groupBox1.Controls) { if (ctrl is TextBox) { TextBox text = ctrl as TextBox; if (text.TextLength > 3) { contador++; } else { } } } if (contador == 4) { try { string rpta = ""; string Nombre = this.txtNombre.Text; string NombreUsuario = this.txtUsuario.Text; string password = this.txtContrasenha.Text; string TipoUsuario = this.comboTipoUsuario.SelectedItem.ToString(); int EstadoUsuario = 1; if (comboEstado.SelectedItem.ToString() == "HABILITADO") { EstadoUsuario = 1; } else { EstadoUsuario = 2; } byte[] salt = Cryptographic.GenerateSalt(); var hashedPassword = Cryptographic.HashPasswordWithSalt(Encoding.UTF8.GetBytes(password), salt); rpta = NUsuario.Insertar(Nombre, NombreUsuario, salt, hashedPassword, EstadoUsuario, TipoUsuario); MessageBox.Show("Usuario creado existosamente", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception) { MessageBox.Show("El usuario ya esta creado", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); /* throw; */ } } else { MessageBox.Show("Existen campos no llenados, o incumplen el mínimo de 4 caracteres y máx 12", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void BtnInsertar_Click(object sender, EventArgs e) { try { string Rpta = ""; if (string.IsNullOrEmpty(TxtTelefonoFijo.Text)) { TxtTelefonoFijo.Text = "0"; } if (TxtRut.Text == string.Empty || TxtNombre.Text == string.Empty || TxtApPaterno.Text == string.Empty || TxtApMaterno.Text == string.Empty || TxtDireccion.Text == string.Empty || TxtEmail.Text == string.Empty || TxtTelefonoMovil.Text == string.Empty || CboComuna.Text == string.Empty || CboRol.Text == string.Empty || CboContrato.Text == string.Empty || TxtClave.Text == string.Empty) { this.MensajeError("Debe rellenar todos los datos obligatorios (*), seran remarcados."); ErrorIcono.SetError(TxtRut, "Ingrese un rut."); ErrorIcono.SetError(TxtNombre, "Ingrese su Nombre."); ErrorIcono.SetError(TxtApPaterno, "Ingrese un Apellido Paterno."); ErrorIcono.SetError(TxtApMaterno, "Ingrese su Apellido Materno."); ErrorIcono.SetError(TxtDireccion, "Ingrese su Direccion."); ErrorIcono.SetError(TxtEmail, "Ingrese un Email."); ErrorIcono.SetError(TxtTelefonoMovil, "Ingrese un Telefono Movil."); ErrorIcono.SetError(CboComuna, "Ingrese una Comuna."); ErrorIcono.SetError(CboRol, "Ingrese un Rol."); ErrorIcono.SetError(CboContrato, "Ingrese un Contrato."); ErrorIcono.SetError(TxtClave, "Ingrese una Clave"); } else { Rpta = NUsuario.Insertar(TxtRut.Text.Trim(), TxtNombre.Text.Trim(), TxtApPaterno.Text.Trim(), TxtApMaterno.Text.Trim(), TxtDireccion.Text.Trim(), TxtEmail.Text.Trim(), Convert.ToInt32(TxtTelefonoMovil.Text), Convert.ToInt32(TxtTelefonoFijo.Text.Trim()), Convert.ToInt32(CboComuna.SelectedValue), Convert.ToInt32(CboRol.SelectedValue), Convert.ToInt32(CboContrato.SelectedValue), TxtClave.Text.Trim()); if (Rpta.Equals("OK")) { this.MensajeOk("Se inserto de forma correcta el registro"); this.Listar(); this.Limpiar(); } else { this.MensajeError(Rpta); } } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
private void bntGuardar_Click(object sender, EventArgs e) { try { string rpta = ""; if (this.txtNombre.Text == string.Empty) { MensajeError("Falta Datos"); } else { if (this.IsNuevo) { rpta = NUsuario.Insertar(this.txtNombre.Text.Trim().ToUpper(), this.txtApellido.Text.Trim().ToUpper(), this.txtCi.Text.Trim().ToUpper(), this.txtCorreo.Text.Trim().ToUpper(), this.txtEdad.Text.Trim().ToUpper(), this.cbAcceso.Text, this.txtUsuario.Text, this.txtPassword.Text, this.txtEstado.Text.Trim().ToUpper()); } else { rpta = NUsuario.Editar(Convert.ToInt32(this.txtIdusuario.Text), this.txtNombre.Text.Trim().ToUpper(), this.txtApellido.Text.Trim().ToUpper(), this.txtCi.Text.Trim().ToUpper(), this.txtCorreo.Text.Trim().ToUpper(), this.txtEdad.Text.Trim().ToUpper(), this.cbAcceso.Text, this.txtUsuario.Text, this.txtPassword.Text, this.txtEstado.Text.Trim().ToUpper()); } if (rpta.Equals("OK")) { if (this.IsNuevo) { this.MensajeOK("Se Inserto"); } else { this.MensajeOK("Se Actualizo"); } } else { this.MensajeError(rpta); } this.IsNuevo = false; this.IsEditar = false; this.Botones(); this.Limpiar(); this.Mostrar(); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
private void btnGuardar_Click(object sender, EventArgs e) { SqlConnection SqlCon = new SqlConnection(); SqlCon.ConnectionString = Conexion.ConexionDB; SqlCon.Open(); try { if (txtNombre.Text == string.Empty || txtApellido.Text == string.Empty || txtMatricula.Text == string.Empty) { errorIcono.SetError(txtMatricula, "Ingrese la matricula"); errorIcono.SetError(txtNombre, "Ingrese el nombre"); errorIcono.SetError(txtApellido, "Ingrese apellido"); } else { /* * SqlCommand cmd = new SqlCommand("SPInsertarUsuario", SqlCon); * cmd.CommandType = CommandType.StoredProcedure; * cmd.Parameters.Add("@idusuario", SqlDbType.Int).Value = Convert.ToInt32(txtIdUser.Text); * cmd.Parameters.Add("@matricula", SqlDbType.VarChar).Value = txtMatricula.Text; * cmd.Parameters.Add("@nombre", SqlDbType.VarChar).Value = txtNombre.Text; * cmd.Parameters.Add("@apellidos", SqlDbType.VarChar).Value = txtApellido.Text; * cmd.Parameters.Add("@carrera", SqlDbType.VarChar).Value = txtcbCarrera.Text; * cmd.Parameters.Add("@sexo", SqlDbType.VarChar).Value = txtcbSexo.Text; * cmd.Parameters.Add("@tipousuario", SqlDbType.VarChar).Value = txtcbTipoUsuario.Text; * cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = txtEmail.Text; * * cmd.ExecuteNonQuery(); */ NUsuario.Insertar(this.txtMatricula.Text, this.txtNombre.Text, this.txtApellido.Text, this.txtcbCarrera.Text, this.txtcbSexo.Text, this.txtcbTipoUsuario.Text, this.txtEmail.Text); Limpiar(); MessageBox.Show("Registro guardado"); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
//Boton para insertar registro private void BtnInsertar_Click(object sender, EventArgs e) { try { string Rpta = ""; //Validamos que los campos necesarios esten llenos if (CboRol.Text == string.Empty || TxtNombre.Text == string.Empty || CboTipoDocumento.Text == string.Empty || TxtNumeroDocumento.Text == string.Empty || TxtTelefono.Text == string.Empty || TxtDireccion.Text == string.Empty || TxtDireccion.Text == string.Empty || TxtEmail.Text == string.Empty || TxtClave.Text == string.Empty) { this.MensajeError("Falta Ingresar Algunos Datos, Seran marcados."); Erroricono.SetError(CboRol, "Ingrese un Rol."); Erroricono.SetError(TxtNombre, "Ingrese un nombre."); Erroricono.SetError(CboTipoDocumento, "Ingrese un tipo de documento."); Erroricono.SetError(TxtNumeroDocumento, "Ingrese un numero de documento."); Erroricono.SetError(TxtTelefono, "Ingrese un numero de telefono."); Erroricono.SetError(TxtDireccion, "Ingrese una Direecion"); Erroricono.SetError(TxtEmail, "Ingrese un Email"); Erroricono.SetError(TxtClave, "Ingrese una Clave."); } //En caso de que no Ejecutamos el metodo Insertar else { Rpta = NUsuario.Insertar(Convert.ToInt32(CboRol.SelectedValue), TxtNombre.Text.Trim(), CboTipoDocumento.Text.Trim(), TxtNumeroDocumento.Text.Trim(), TxtDireccion.Text.Trim(), TxtTelefono.Text.Trim(), TxtEmail.Text.Trim(), TxtClave.Text.Trim()); if (Rpta.Equals("OK")) { this.MensajeOK("Usuario Creado Exitosamente"); this.Listar(); } else { this.MensajeError(Rpta); } } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
private void botonInsertar_Click(object sender, EventArgs e) { try { string respuesta = ""; if (comboRol.Text == string.Empty || textoNombre.Text == string.Empty || textoEmail.Text == string.Empty || textoClave.Text == string.Empty) { this.MensajeError("Falta ingresar algunos datos, seran remarcados"); errorIcono.SetError(textoNombre, "ingrese nombre"); errorIcono.SetError(comboRol, "ingrese rol"); errorIcono.SetError(textoEmail, "ingrese email"); errorIcono.SetError(textoClave, "ingrese clave"); } else { respuesta = NUsuario.Insertar(Convert.ToInt32(comboRol.SelectedValue), textoNombre.Text.Trim(), comboTipoDocumento.Text, textoNumeroDocumento.Text.Trim(), textoDireccion.Text.Trim(), textoTelefono.Text.Trim(), textoEmail.Text.Trim(), textoEmail.Text.Trim(), textoClave.Text.Trim()); if (respuesta.Equals("Ok")) { this.MensajeOk("Se Registro correctamente"); this.Listar(); } else { this.MensajeError(respuesta); } } } catch (Exception exepcion) { MessageBox.Show(exepcion.Message + exepcion.StackTrace); } }
private void btnGuardar_Click(object sender, EventArgs e) { if (Editar == true) { if (Comprobar_Campos()) { if (Obtener_Id(AuxiliarNombre) == 0) { MessageBox.Show("Error: id no encontrado!"); } else { if (AuxiliarNombre == tbUsuario.Text) { MessageBox.Show(NUsuario.Editar(Obtener_Id(tbUsuario.Text), tbUsuario.Text, tbContraseña.Text, cbNivelAcceso.Text)); Limpiar_Campos(); Editar = false; HabilitarCampos(false); HabilitarGuardarLimpiar(false); } else if (NombreExistente(tbUsuario.Text)) { MessageBox.Show(string.Format("Error: el nombre '{0}' ya se encuentra en uso!", tbUsuario.Text)); } else { MessageBox.Show(NUsuario.Editar(Obtener_Id(AuxiliarNombre), tbUsuario.Text, tbContraseña.Text, cbNivelAcceso.Text)); Limpiar_Campos(); Editar = false; HabilitarCampos(false); HabilitarGuardarLimpiar(false); } } } else { } } else { if (Comprobar_Campos()) { if (NombreExistente(tbUsuario.Text)) { MessageBox.Show(string.Format("Error: el nombre '{0}' ya se encuentra en uso!", tbUsuario.Text)); } else { MessageBox.Show(NUsuario.Insertar(tbUsuario.Text, tbContraseña.Text, cbNivelAcceso.Text)); Limpiar_Campos(); HabilitarCampos(false); HabilitarGuardarLimpiar(false); } } else { Comprobar_Campos(); } } Mostrar(); }
private void btnGuardar_Click(object sender, EventArgs e) { try { string Rpta = ""; if (this.txtNombre.Text == string.Empty || this.txtApellidos.Text == string.Empty || this.txtTelefono.Text == string.Empty || this.txtUsuario.Text == string.Empty || this.txtPassword.Text == string.Empty || this.txtCodigoCargo.Text == string.Empty) { MensajeError("Falta ingresar algunos datos, serán remarcados"); errorIcono.SetError(txtNombre, "Ingrese el nombre"); errorIcono.SetError(txtApellidos, "Ingrese el apellido"); errorIcono.SetError(txtPassword, "Ingrese el password"); errorIcono.SetError(txtUsuario, "Ingrese el usuaurio"); errorIcono.SetError(txtTelefono, "Ingrese el telefono"); errorIcono.SetError(cbSexo, "Ingrese el sexo"); errorIcono.SetError(cbCargo, "Ingrese el telefono"); } else { if (this.IsNuevo) { Rpta = NUsuario.Insertar(Convert.ToInt32(txtCodigoCargo.Text), this.txtNombre.Text, this.txtApellidos.Text, txtDireccion.Text, Convert.ToDateTime(DateTime.Now.ToShortTimeString()), Convert.ToInt32(txtTelefono.Text), cbSexo.Text, "ACTIVO", txtUsuario.Text, txtPassword.Text ); } else { Rpta = NUsuario.Editar(Convert.ToInt32(txtCodigo.Text), Convert.ToInt32(txtCodigoCargo.Text), this.txtNombre.Text, this.txtApellidos.Text, txtDireccion.Text, Convert.ToInt32(txtTelefono.Text), cbSexo.Text, cbEstado.Text, txtUsuario.Text, txtPassword.Text ); } if (Rpta.Equals("OK")) { if (this.IsNuevo) { this.MensajeOk("Se insertó de forma correcta el registro"); errorIcono.Clear(); txtCodigo.Visible = true; label10.Visible = true; } else { this.MensajeOk("Se actualizó de forma correcta el registro"); errorIcono.Clear(); } } else { this.MensajeError(Rpta); } this.IsNuevo = false; this.IsEditar = false; this.Botones(); this.Limpiar(); this.Mostrar(); dgvRegistros.Enabled = true; label14.Visible = true; l.Visible = true; txtDescripcion.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
private void btnGuardar_Click(object sender, EventArgs e) { this.BorrarErrorProvider(); try { string rpta = ""; //verificamos que no haya texbox o comboBox vacios if (this.txtNombre.Text == string.Empty || this.txtCuit.Text == string.Empty || this.cbSexo.Text == string.Empty || this.cbAcceso.Text == string.Empty) { MensajeError("Falta ingresar algunos datos, serán remarcados"); //recorremos los comboBox verificando cuales estan vacios foreach (Control c in groupBox1.Controls.OfType <ComboBox>()) { if (c is ComboBox & c.Text.Trim() == "") { errorIcono.SetError(c, "Ingrese un Valor"); } } //recorremos los texbox verificando cuales estan vacios foreach (Control c in groupBox1.Controls) { if (c is TextBox & c.Text.Trim() == "") { errorIcono.SetError(c, "Ingrese un Valor"); } } errorIcono.SetError(txtIdusuario, String.Empty); } else { if (this.IsNuevo) { rpta = NUsuario.Insertar(this.txtNombre.Text.Trim().ToUpper(), this.txtApellidos.Text.Trim().ToUpper(), this.cbSexo.Text, dtFechaNac.Value, txtCuit.Text, txtDireccion.Text.ToUpper(), txtTelefono.Text, txtEmail.Text, cbAcceso.Text, txtUsuarios.Text.ToUpper(), txtClave.Text); this.BorrarErrorProvider(); } else { rpta = NUsuario.Editar(Convert.ToInt32(this.txtIdusuario.Text), this.txtNombre.Text.Trim().ToUpper(), this.txtApellidos.Text.Trim().ToUpper(), this.cbSexo.Text, dtFechaNac.Value, txtCuit.Text, txtDireccion.Text.ToUpper(), txtTelefono.Text, txtEmail.Text, cbAcceso.Text, txtUsuarios.Text.ToUpper(), txtClave.Text); this.BorrarErrorProvider(); } if (rpta.Equals("OK")) { if (this.IsNuevo) { this.MensajeOk("Se Insertó de forma correcta el registro"); } else { this.MensajeOk("Se Actualizó de forma correcta el registro"); } } else { this.MensajeError(rpta); } this.IsNuevo = false; this.IsEditar = false; this.Botones(); this.Limpiar(); this.Mostrar(); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }