private void btnModificar_Click(object sender, RoutedEventArgs e) { try { User _datoUsuario = DatosUsuarios(); _datoUsuario.UserID = ID; if (txtNombre.Text != string.Empty && txtApellido.Text != string.Empty && txtUserName.Text != string.Empty && Password.Password != string.Empty && PasswordConfirmar.Password != string.Empty && txtEmail.Text != string.Empty) { var verificar = from u in _Accion.User.GetAll() where u.Email.ToUpper() == txtEmail.Text.ToUpper() || u.UserName.ToUpper() == txtUserName.Text.ToUpper() select u; if (verificar.Count() > 0) { if (verificar.FirstOrDefault().UserID == _datoUsuario.UserID) { if (Password.Password == PasswordConfirmar.Password) { if (!Regex.IsMatch(txtEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Ingrese un correo electrónico valido", "Alerta CRVA-UM", MessageBoxButton.OK, MessageBoxImage.Exclamation); txtEmail.Focus(); } else { _Accion.User.UpdateItem(_datoUsuario); //abrir y cerrar ventana MantenimientoUsuario _window = new MantenimientoUsuario(); _window.Show(); Close(); MessageBox.Show("Registro guardado exitosamente", "Exito CRVA-UM", MessageBoxButton.OK, MessageBoxImage.Information); } } else { MessageBox.Show("Las contraseñas no coinciden", "Alerta CRVA-UM", MessageBoxButton.OK, MessageBoxImage.Exclamation); Password.Focus(); } } else { MessageBox.Show("Ya existe un usuario con ese e-mail y/o user name", "Alerta CRVA-UM", MessageBoxButton.OK, MessageBoxImage.Exclamation); txtEmail.Focus(); } } else { if (Password.Password == Password.Password) { if (!Regex.IsMatch(txtEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Ingrese un correo electrónico valido", "Alerta CRVA-UM", MessageBoxButton.OK, MessageBoxImage.Exclamation); txtEmail.Focus(); } else { _Accion.User.UpdateItem(_datoUsuario); //abrir y cerrar ventana MantenimientoUsuario _window = new MantenimientoUsuario(); _window.Show(); MessageBox.Show("Registro guardado exitosamente", "Exito CRVA-UM", MessageBoxButton.OK, MessageBoxImage.Information); } } else { MessageBox.Show("Las contraseñas no coinciden", "Alerta HM-1001", MessageBoxButton.OK, MessageBoxImage.Exclamation); Password.Focus(); } } //EstadoBotones(0); } else if (txtNombre.Text == string.Empty) { txtNombre.Focus(); } else if (txtApellido.Text == string.Empty) { txtApellido.Focus(); } else if (txtUserName.Text == string.Empty) { txtUserName.Focus(); } else if (txtEmail.Text == string.Empty) { txtEmail.Focus(); } else if (Password.Password == string.Empty) { Password.Focus(); } else { PasswordConfirmar.Focus(); } } catch (Exception ex) { MessageBox.Show("Algo anda mal : " + ex.Message, "Error CRVA-UM", MessageBoxButton.OK, MessageBoxImage.Error); } }
private async void btnGuardar_Click(object sender, RoutedEventArgs e) { try { if (txtNombre.Text.Trim() != string.Empty && txtApellido.Text.Trim() != string.Empty && txtUserName.Text.Trim() != string.Empty && Password.Password.Trim() != string.Empty && PasswordConfirmar.Password.Trim() != string.Empty && txtEmail.Text.Trim() != string.Empty) { User _datoUsuario = DatosUsuarios(); var verificar = from u in _Accion.User.GetAllData() where u.Email.ToUpper() == txtEmail.Text.ToUpper() || u.UserName.ToUpper() == txtUserName.Text.ToUpper() select u; if (verificar.Count() > 0) { MessageBox.Show("Ya existe un usuario con ese e-mail y/o nombre de usuario", "Alerta CRVA-UG", MessageBoxButton.OK, MessageBoxImage.Exclamation); txtEmail.Focus(); } else { if (Password.Password == PasswordConfirmar.Password) { if (!Regex.IsMatch(txtEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Ingrese un correo electrónico valido", "Alerta CRVA-UG", MessageBoxButton.OK, MessageBoxImage.Exclamation); txtEmail.Focus(); } else { _Accion.User.Create(_datoUsuario); MessageBox.Show("Registro guardado exitosamente", "Exito CRVA-UG", MessageBoxButton.OK, MessageBoxImage.Information); Limpiar(); } } else { MessageBox.Show("Las contraseñas no coinciden", "Alerta CRVA-UX", MessageBoxButton.OK, MessageBoxImage.Exclamation); Password.Focus(); } } EstadoBotones(0); //lista a paginar list = await GetPagedListAsync(); //Determinamos el estado de los botones btnPrevius.IsEnabled = list.HasPreviousPage; btnSiguiente.IsEnabled = list.HasNextPage; //Cargamos la lista al DataGrid dgvUsuario.ItemsSource = list.ToList(); //Establecemos el numero de paginas del DataGrid tbPaginacion.Text = string.Format("Pagina {0}/{1}", pageNumber, list.PageCount); } else if (txtNombre.Text.Trim() == string.Empty) { txtNombre.Focus(); } else if (txtApellido.Text.Trim() == string.Empty) { txtApellido.Focus(); } else if (txtUserName.Text.Trim() == string.Empty) { txtUserName.Focus(); } else if (txtEmail.Text.Trim() == string.Empty) { txtEmail.Focus(); } else if (Password.Password.Trim() == string.Empty) { Password.Focus(); } else { PasswordConfirmar.Focus(); } } catch (Exception ex) { MessageBox.Show("Algo anda mal : " + ex.Message, "Error CRVA-UG", MessageBoxButton.OK, MessageBoxImage.Error); } }