Esempio n. 1
0
 private void BtnConfirm_Click(object sender, EventArgs e)
 {
     if (StringsAreEqual(txtNewPassword.Text, txtConfirmPassword.Text))
     {
         if (!StringsAreEqual(txtOldPassword.Text, txtNewPassword.Text))
         {
             try
             {
                 var dbPassword = db.Logins.FirstOrDefault();
                 if (StringsAreEqual(dbPassword.password, txtOldPassword.Text))
                 {
                     dbPassword.password = txtNewPassword.Text;
                     db.SaveChanges();
                     MessageBox.Show("Password changed successfully.");
                 }
                 else
                 {
                     MessageBox.Show("Incorrect Password!");
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Error: " + ex.Message);
             }
         }
         else
         {
             MessageBox.Show("Old password and new password should not be same!");
         }
     }
     else
     {
         MessageBox.Show("New password and confirm password does not match!");
     }
 }
Esempio n. 2
0
        private void UpdateOldRecord()
        {
            if (ValidateFormInputs())
            {
                try
                {
                    var voter = db.Voters.Where(x => x.id == voterID).FirstOrDefault();

                    if (voter != null)
                    {
                        voter.name = txtName.Text;

                        if (!String.IsNullOrEmpty(txtFather.Text))
                        {
                            voter.father_name = txtFather.Text;
                        }

                        string cnic = txtCNIC1.Text + txtCNIC2.Text + txtCNIC3.Text;
                        voter.CNIC = cnic;

                        if (!String.IsNullOrEmpty(txtVoteNo.Text))
                        {
                            voter.voter_no = txtVoteNo.Text;
                        }
                        if (!String.IsNullOrEmpty(txtFamily.Text))
                        {
                            voter.family = txtFamily.Text;
                        }
                        if (!String.IsNullOrEmpty(txtPhoneNo.Text))
                        {
                            voter.phone = txtPhoneNo.Text;
                        }
                        if (!String.IsNullOrEmpty(txtAddress.Text))
                        {
                            voter.address = txtAddress.Text;
                        }
                        if (!String.IsNullOrEmpty(txtPollingStation.Text))
                        {
                            voter.polling_station = txtPollingStation.Text;
                        }
                        if (!String.IsNullOrEmpty(txtCaste.Text))
                        {
                            voter.Caste = txtCaste.Text;
                        }

                        db.SaveChanges();

                        ResetFormFields();

                        MessageBox.Show("Success");
                    }
                    else
                    {
                        MessageBox.Show("Record not found");
                        GoBack();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
            }
        }