Example #1
0
        private void saveAccount()
        {
            if (password.Text != confirmationPassword.Text)
            {
                MessageBox.Show("Password Mismatch, please ensure the two passwords provided match.");
                return;
            }

            String accountName = "";

            try {
                accountName = accountTypeListBox.SelectedItem.ToString();
            }catch (Exception e) {
                MessageBox.Show("Please select an account name from the Account Name dropdown.");
                return;
            }

            Account account = new Account {
                AccountName = accountName,
                Password    = password.Text
            };

            ValidationHelper helper = new ValidationHelper(account);

            if (!helper.IsValid)
            {
                MessageBox.Show(helper.Message());
                return;
            }

            ISessionFactory sessionFactory = DataBaseConnection.CreateSessionFactory();

            using (ISession session = sessionFactory.OpenSession()) {
                using (ITransaction transaction = session.BeginTransaction()) {
                    session.Save(account);
                    transaction.Commit();
                    parentForm.EnableFormOKButton();
                    MessageBox.Show("Account Created");
                }
            }
        }
        private void changePassword()
        {
            String accountText     = "";
            String oldPasswordText = oldPassword.Text;
            String newPasswordText = newPassword.Text;

            try {
                accountText = accountNameListBox.SelectedItem.ToString();
            }
            catch (Exception e) {
                MessageBox.Show("Please select an account name from the Account Name dropdown.");
                return;
            }

            ISessionFactory sessionfactory = DataBaseConnection.CreateSessionFactory();

            using (var session = sessionfactory.OpenSession()) {
                Account account = session.CreateCriteria <Account>().Add(NHibernate.Criterion.Expression
                                                                         .And(NHibernate.Criterion.Expression.Eq("AccountName", accountText),
                                                                              NHibernate.Criterion.Expression.Eq("Password", oldPasswordText)))
                                  .UniqueResult <Account>();
                if (account != null)
                {
                    using (var transaction = session.BeginTransaction()) {
                        account.Password = newPasswordText;
                        session.Update(account);
                        transaction.Commit();
                        MessageBox.Show("Password successfully changed.");
                        parentForm.EnableFormOKButton();
                    }
                }
                else
                {
                    MessageBox.Show("An account with the current details does not exist.");
                }
            }
        }