protected void txtAp_OnTextChanged(object sender, EventArgs e) { try { if (txtNombre.Text.Trim().Length <= 0) { return; } string username = (txtNombre.Text.Substring(0, 1).ToLower() + txtAp.Text.Trim().ToLower()).Replace(" ", string.Empty); int limite = 2; if (_servicioUsuarios.ValidaUserName(username)) { for (int i = 1; i < limite; i++) { string tmpUsername = username + i; if (!_servicioUsuarios.ValidaUserName(tmpUsername)) { username = tmpUsername; break; } limite++; } } txtUserName.Text = username; } catch (Exception ex) { if (_lstError == null) { _lstError = new List <string>(); } _lstError.Add(ex.Message); AlertaGeneral = _lstError; } }
private string GeneraNombreUsuario() { string result = null; try { string username = (txtNombreRapido.Text.Substring(0, 1).ToLower() + txtApRapido.Text.Trim().ToLower()).Replace(" ", string.Empty); username = username.PadRight(30).Substring(0, 30).Trim(); int limite = 10; if (_servicioUsuario.ValidaUserName(username)) { for (int i = 1; i < limite; i++) { string tmpUsername = username + i; if (!_servicioUsuario.ValidaUserName(tmpUsername.PadRight(30).Substring(0, 30).Trim())) { username = tmpUsername; break; } limite++; } } result = username; } catch (Exception ex) { if (_lstError == null) { _lstError = new List <string>(); } _lstError.Add(ex.Message); Alerta = _lstError; } return(result); }