Esempio n. 1
0
        private Boolean doLogin() {
            String accountText = "";
            String passwordText = password.Password;

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

            
            ISessionFactory sessionfactory = DataBaseConnection.CreateSessionFactory();
            using (var session = sessionfactory.OpenSession()) {

                if (DataBaseConnection.overwriteSchema()) {

                    Account newAccount = new Account {
                        AccountName = "Administrator",
                        Password = "******"
                    };
                    using(var transaction = session.BeginTransaction()){
                        session.Save(newAccount);
                        transaction.Commit();
                    }
                    DataBaseConnection.saveCurrentSchema();
                }

                Account account = session.CreateCriteria<Account>().Add(NHibernate.Criterion.Expression
                        .And(NHibernate.Criterion.Expression.Eq("AccountName", accountText),
                             NHibernate.Criterion.Expression.Eq("Password", passwordText)))
                    .UniqueResult<Account>();
                if (account != null) {
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.SetAccountType(accountText);
                    mainWindow.Show();
                    this.Close();
                } else {
                    MessageBox.Show("An account with the current details does not exist.");
                    password.Clear();
                    loginButton.Content = "Login";
                }
            }

            return false;
        }
Esempio n. 2
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");
                }
            }
            
        }