private void buttonLogIn2_Click(object sender, EventArgs e) { try { //UserDonator user = service.GetUserDonator(txtUsername.Text); if (service.LogInUserDonator(txtUsername.Text, txtPassw.Text)) { FormDonator formDonator = new FormDonator(service, txtUsername.Text); this.Hide(); formDonator.Closed += (s, args) => this.Close(); formDonator.Show(); if (DonatorService.NeedsToBeNotified(service.GetUserDonator(txtUsername.Text).Id)) { MessageBox.Show("E nevoie de sangele tau!!! Sangele tau poate salva vieti. Doneaza acum"); } } else { MessageBox.Show("Username or password incorect!!"); } } catch (Exception err) { MessageBox.Show("Username or password incorect!!"); } }
public void ValidateDonator(string username, string password, string rePassword, string nume, string prenume, string domiciliu, string localitate, string judet, string Email, string telefon) { string error = ""; try { UserDonator donator2 = service.GetUserDonator(username); error += " username"; } catch (ValidationException err) { } if (txtUsername.Text == null || txtUsername.Text == string.Empty) { error += " username"; } if (domiciliu == string.Empty || domiciliu == null) { error += " domiciliu"; } if (nume == string.Empty || nume == null) { error += " nume"; } if (prenume == string.Empty || prenume == null) { error += " prenume"; } if (password == null || password == string.Empty) { error += " password"; } if (password != rePassword || rePassword == string.Empty || rePassword == null) { error += " reconfirm"; } if (localitate == string.Empty || localitate == null) { error += " localitate"; } if (judet == string.Empty || judet == null) { error += " judet"; } if (Email == string.Empty || Email == null) { error += " email"; } if (telefon == string.Empty || telefon == null || telefon.Length != 10) { error += " telefon"; } if (error != "") { throw new System.ComponentModel.DataAnnotations.ValidationException(error); } }
private void btnUpdate_Click(object sender, EventArgs e) { Donator donator = service.GetDonator(Username); UserDonator user = service.GetUserDonator(Username); string message = string.Empty; if (textBoxUserName.Text != null && textBoxUserName.Text != "") { if (textBoxUserName.Text != user.Username) { try { service.GetUserDonator(textBoxUserName.Text); message += ",username"; } catch (Exception ex) { user.Username = textBoxUserName.Text; } } } else { message += ",username"; } if (textBoxSetariNume.Text != null && textBoxSetariNume.Text != "") { donator.Nume = textBoxSetariNume.Text; } else { message += ",nume"; } if (textBoxSetariPrenume.Text != null && textBoxSetariPrenume.Text != "") { donator.Prenume = textBoxSetariPrenume.Text; } else { message += ",prenume"; } if (textAdresa.Text != null && textAdresa.Text != "") { donator.Domiciliu = textAdresa.Text; } else { message += ",adresa"; } if (cmbLoc.Text != null && cmbLoc.Text != "") { donator.Localitate = cmbLoc.Text; } else { message += ",localitate"; } if (cmbJud.Text != null && cmbJud.Text != "") { donator.Judet = cmbJud.Text; } else { message += ",judet"; } if (textEmail.Text != null && textEmail.Text != "" && textEmail.Text.Contains("@") && textEmail.Text.Contains(".")) { donator.Email = textEmail.Text; } else { message += ",E-mail"; } try { Int64.Parse(textTelefon.Text); if (donator.Telefon != textTelefon.Text) { donator.Telefon = textTelefon.Text; } } catch (Exception ex) { message += ",telefon"; } if (service.Encrypt(textBoxParola.Text) == user.Parola) { if (textPswNew.Text == textPswNewR.Text) { user.Parola = service.Encrypt(textPswNew.Text); } } else { message += ",parola"; } if (message == string.Empty) { service.UpdateDonator(donator); service.UpdateUserDonator(user); this.Username = textBoxUserName.Text; MessageBox.Show("Modificarile au avut loc cu succes"); textBoxParola.Clear(); textPswNew.Clear(); textPswNewR.Clear(); } else { MessageBox.Show($"Am gasit probleme la: {message}"); var msg = message.Split(','); foreach (var i in msg) { switch (i) { case "username": textBoxUserName.Text = user.Username; break; case "nume": textBoxSetariNume.Text = donator.Nume; break; case "prenume": textBoxSetariPrenume.Text = donator.Prenume; break; case "adresa": textAdresa.Text = donator.Domiciliu; break; case "judet": cmbJud.Text = donator.Judet; break; case "localitate": cmbLoc.Text = donator.Localitate; break; case "telefon": textTelefon.Text = donator.Telefon; break; case "E-mail": textEmail.Text = donator.Email; break; } } } }