Ejemplo n.º 1
0
        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;
                    }
                }
            }
        }