private void buttonGuardarSocio_Click(object sender, EventArgs e) { var hayError = false; if (txtNombreSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtNombreSocio, "El nombre del socio debe contener entre 3 y 50 caracteres"); } else { errorProvider1.SetError(txtNombreSocio, ""); } if (txtApellidoSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtApellidoSocio, "El apellido del socio debe contener entre 3 y 50 caracteres"); } else { errorProvider1.SetError(txtApellidoSocio, ""); } if (txtDocumentoSocio.Text.Length < 6 || (Convert.ToInt32(txtDocumentoSocio.Text) + "").Length < 6) { hayError = true; errorProvider1.SetError(txtDocumentoSocio, "El DNI debe ser un número entre 6 y 8 dígitos"); } else { errorProvider1.SetError(txtDocumentoSocio, ""); } if (txtDireccionSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtDireccionSocio, "La direccion del socio debe contener entre 3 y 50 caracteres"); } else { errorProvider1.SetError(txtDireccionSocio, ""); } if (txtLocalidadSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtLocalidadSocio, "La localidad del socio debe contener entre 3 y 50 caracteres"); } else { errorProvider1.SetError(txtLocalidadSocio, ""); } if (txtTelefonoSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtTelefonoSocio, "El teléfono del socio debe contener entre 3 y 50 caracteres"); } else { errorProvider1.SetError(txtTelefonoSocio, ""); } if (dtFechaNacimientoSocio.Value.CompareTo(DateTime.Now) >= 0) { hayError = true; errorProvider1.SetError(dtFechaNacimientoSocio, "La fecha de nacimiento debe ser inferior al dia de hoy."); } else { errorProvider1.SetError(dtFechaNacimientoSocio, ""); } if (hayError) { return; } Enum.TryParse <EnumTipoDocumento>(cbxTipoDocumentoSocio.SelectedValue.ToString(), out EnumTipoDocumento tipoDocumento); Enum.TryParse <EnumCategoriaSocio>(cbxCategoria.SelectedValue.ToString(), out EnumCategoriaSocio categoria); ControladorSocio Csocio = new ControladorSocio(); int resultado = Csocio.CrearSocio(txtNombreSocio.Text, txtApellidoSocio.Text, dtFechaNacimientoSocio.Value, Convert.ToInt32(txtDocumentoSocio.Text), txtDireccionSocio.Text, txtLocalidadSocio.Text, txtTelefonoSocio.Text, tipoDocumento, categoria); if (resultado > 0) { Padre.ModificarMensaje("El SOCIO ha sido creado con ÉXITO"); Padre.Actualizar(); Dispose(); } else if (resultado == -1) { Padre.ModificarMensaje("Se ha recuperado el SOCIO"); Padre.Actualizar(); Dispose(); } else if (resultado == -2) { MyMessageBox.Show(this, "Ya existe el SOCIO", "Socio"); } else if (resultado == -3) { MyMessageBox.Show(this, "No se ha definido un monto inicial de la cuota mensual del club, ir a las configuraciones del sistema", "Socio"); } }
private void buttonGuardarSocio_Click(object sender, EventArgs e) { var hayError = false; if (txtNombreSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtNombreSocio, "El nombre del socio debe contener entre 3 y 50 caracteres"); } else { errorProvider1.SetError(txtNombreSocio, ""); } if (txtApellidoSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtApellidoSocio, "El apelido del socio debe contener entre 3 y 50 caracteres"); } else { errorProvider1.SetError(txtApellidoSocio, ""); } if (txtDocumentoSocio.Text.Length < 6) { hayError = true; errorProvider1.SetError(txtDocumentoSocio, "El DNI debe ser un número entre 6 y 8 dígitos"); } else { errorProvider1.SetError(txtDocumentoSocio, ""); } if (txtDireccionSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtDireccionSocio, "La direccíon del socio debe contener entre 3 y 50 caracteres"); } else { errorProvider1.SetError(txtDireccionSocio, ""); } if (txtLocalidadSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtLocalidadSocio, "La localidad del socio debe contener entre 3 y 50 caracteres"); } else { errorProvider1.SetError(txtLocalidadSocio, ""); } if (txtTelefonoSocio.Text.Length < 3) { hayError = true; errorProvider1.SetError(txtTelefonoSocio, "El teléfono del socio debe contener entre 3 y 50 caracteres"); } if (dtFechaNacimientoSocio.Value.CompareTo(DateTime.Now) >= 0) { hayError = true; errorProvider1.SetError(dtFechaNacimientoSocio, "La fecha de nacimiento debe ser inferior al dia de hoy."); } else { errorProvider1.SetError(txtTelefonoSocio, ""); } if (hayError) { return; } ControladorSocio Csocio = new ControladorSocio(); Enum.TryParse <EnumCategoriaSocio>(cbxCategoria.SelectedValue.ToString(), out EnumCategoriaSocio categoria); var resultado = Csocio.ModificarSocio(Socio.MiPersona.IdPersona, Socio.MiSocio.IdSocio, txtNombreSocio.Text, txtApellidoSocio.Text, dtFechaNacimientoSocio.Value, Convert.ToInt32(txtDocumentoSocio.Text), txtDireccionSocio.Text, txtLocalidadSocio.Text, txtTelefonoSocio.Text, categoria); if (resultado > 0) { Padre.ModificarMensaje("El SOCIO ha sido modificado con ÉXITO"); Padre.Actualizar(); Dispose(); } else if (resultado == -2) { MyMessageBox.Show(this, "Ya existe el SOCIO", "Socio"); } }