Пример #1
0
        //Hvis brugeren klikker log ud, spørg om de vil, så log ud og åben ny start form.
        private void BtnLogOut_Click(object sender, EventArgs e)
        {
            FormYesNo customMessage = new FormYesNo("Would you like to log out?");

            if (customMessage.DialogResult == DialogResult.Yes)
            {
                var t = new Thread(() => Application.Run(new FormLogSign()));
                t.Start();
                Application.OpenForms["FormMain"].Close();
            }
            else if (customMessage.DialogResult == DialogResult.No)
            {
                customMessage.Hide();
            }
        }
        //Hvis bruger vil fjerne konto
        private void BtnDeleteAccount_Click(object sender, EventArgs e)
        {
            //Bekræft
            FormYesNo ConfirmDelete = new FormYesNo("Confirm deletion of account");

            if (ConfirmDelete.DialogResult == DialogResult.Yes)
            {
                //Fjern konto
                FormMessage InfoMessage = new FormMessage("You've successfully deleted your account!");
                File.Delete(Settings.UsersPath + "/" + Settings.CurrentUser.ID + ".json");
                //Start ny start form
                var t = new Thread(() => Application.Run(new FormLogSign()));
                t.Start();
                Application.OpenForms["FormMain"].Close();
            }
        }
        //Hvis bruger vil have alt konto info
        private void BtnCollectAccInfo_Click(object sender, EventArgs e)
        {
            FormYesNo confirmCollection = new FormYesNo("Would you like to save all\naccount information?");

            if (confirmCollection.DialogResult == DialogResult.Yes)
            {
                try {
                    //Tjekker om fil eksisterer
                    if (File.Exists(@Settings.AccountInfoPath + "/Account info for ID " + Settings.CurrentUser.ID + ".json"))
                    {
                        //Fjerner fil så vi kan erstatte den
                        File.Delete(@Settings.AccountInfoPath + "/Account info for ID " + Settings.CurrentUser.ID + ".json");
                    }
                    //Kopierer fil på personen
                    File.Copy(@Settings.UsersPath + "/" + Settings.CurrentUser.ID + ".json", @Settings.AccountInfoPath + "/Account info for ID " + Settings.CurrentUser.ID + ".json");
                    new FormMessage("File has been saved in the\nOOProject file");
                    //Hvis noget går galt
                } catch (Exception) {
                    new FormMessage("Something went wrong whilst\ntrying to save the file");
                    Utils.Shake(Settings.FormMain);
                }
            }
        }
Пример #4
0
        //Hvis brugeren bekræfter
        private void BtnConfirm2_Click(object sender, EventArgs e)
        {
            FormYesNo ConfirmForm = new FormYesNo("Confirm transaction");

            if (ConfirmForm.DialogResult == DialogResult.Yes)
            {
                //Gennemfør transaktionen

                String FromAccount    = cmbFromOther.Text;
                int    ToOtherAccount = int.Parse(txtRecipient.Text);
                String amount         = txtAmountOther.Text;

                //TJekker om alt er i orden
                if (decimal.TryParse(amount, out decimal amountParsed))
                {
                    if (amountParsed > 0)
                    {
                        Account fromAccount = null;
                        foreach (Account acc in Settings.CurrentUser.Accounts)
                        {
                            if (acc.Name.ToString().Equals(FromAccount))
                            {
                                fromAccount = acc;
                                break;
                            }
                        }

                        //Loop igennem alle brugere for at se om der er en account i et user object
                        Account toAccount = null;

                        foreach (string path in Directory.GetFiles(Settings.UsersPath))
                        {
                            User    _tempUser = Utils.GetUserByPath(path);
                            Boolean breakUL   = false;
                            foreach (Account _tempAccount in _tempUser.Accounts)
                            {
                                if (_tempAccount.Number == ToOtherAccount)
                                {
                                    toAccount = _tempAccount;

                                    breakUL = true;
                                    break;
                                }
                            }
                            if (breakUL == true)
                            {
                                break;
                            }
                        }

                        if (toAccount != null && fromAccount != null)
                        {
                            Transaction TAction = new Transaction(fromAccount, toAccount, amountParsed, DateTime.Now);
                            if (TAction.CanTransfer() == true)
                            {
                                TAction.Transfer();
                                Settings.CurrentUser.Save();
                                UpdateLists();
                                cmbFromAccount.SelectedIndex = cmbFromAccount.Items.IndexOf(fromAccount.Name);
                                cmbToAccount.SelectedIndex   = cmbToAccount.Items.IndexOf(toAccount.Name);
                                //Hvis transaktionen går i gennem
                                new FormMessage("Transaction has been completed");
                            }
                            else
                            {
                                //Hvis kontoen ikke har nok penge
                                new FormMessage("Insufficient funding");
                                Utils.Shake(Settings.FormMain);
                            }
                        }
                        else
                        {
                            //Hvis kontoen ikke kan findes
                            new FormMessage("Account not found");
                            Utils.Shake(Settings.FormMain);
                        }
                    }
                    else
                    {
                        //Hvis brugeren sender beløb under 0
                        new FormMessage("Du kan ikke sende et beløb under 0!");
                        Utils.Shake(Settings.FormMain);
                    }
                }
                else
                {
                    //Hvis bruger sender andet end tal
                    new FormMessage("Dit beløb kan kun indeholde et tal!");
                    Utils.Shake(Settings.FormMain);
                }
            }
        }
Пример #5
0
        //Hvis brugeren bekræfter
        private void BtnConfirm1_Click(object sender, EventArgs e)
        {
            FormYesNo ConfirmForm = new FormYesNo("Confirm transaction");

            if (ConfirmForm.DialogResult == DialogResult.Yes)
            {
                //Gennemfør transaktionen

                String FromAccount = cmbFromAccount.Text;
                String ToAccount   = cmbToAccount.Text;
                String amount      = txtAmountOwn.Text;

                //Tjekker om alt er i orden
                if (decimal.TryParse(amount, out decimal amountParsed))
                {
                    if (amountParsed > 0)
                    {
                        Account fromAccount = null;
                        foreach (Account acc in Settings.CurrentUser.Accounts)
                        {
                            if (acc.Name.ToString().Equals(FromAccount))
                            {
                                fromAccount = acc;
                                break;
                            }
                        }

                        Account toAccount = null;
                        foreach (Account acc in Settings.CurrentUser.Accounts)
                        {
                            if (acc.Name.ToString().Equals(ToAccount))
                            {
                                toAccount = acc;
                                break;
                            }
                        }

                        if (toAccount != null && fromAccount != null)
                        {
                            Transaction TAction = new Transaction(fromAccount, toAccount, amountParsed, DateTime.Now);
                            if (TAction.CanTransfer() == true)
                            {
                                TAction.Transfer();
                                Settings.CurrentUser.Save();
                                UpdateLists();
                                cmbFromAccount.SelectedIndex = cmbFromAccount.Items.IndexOf(fromAccount.Name);
                                cmbToAccount.SelectedIndex   = cmbToAccount.Items.IndexOf(toAccount.Name);
                                //Hvis transaktionen går igennem
                                new FormMessage("Transaction has been completed");
                            }
                            else
                            {
                                //Hvis brugeren ikke har nok penge
                                new FormMessage("Insufficient funding");
                                Utils.Shake(Settings.FormMain);
                            }
                        }
                        else
                        {
                            //Hvis kontoen ikke findes
                            new FormMessage("Account not found");
                            Utils.Shake(Settings.FormMain);
                        }
                    }
                    else
                    {
                        //Hvis man prøver at sende mindre end 0
                        new FormMessage("Du kan ikke sende et beløb under 0!");
                        Utils.Shake(Settings.FormMain);
                    }
                }
                else
                {
                    //Hvis man prøver at sende andet end tal
                    new FormMessage("Dit beløb kan kun indeholde et tal!");
                    Utils.Shake(Settings.FormMain);
                }
            }
        }
Пример #6
0
        //Hvis der trykkes på bekræft for at sign up
        private void BtnSignUpConfirm_Click(object sender, EventArgs e)
        {
            //Gem al given information
            String   FullName = txtFullNameInput.Text;
            String   Password = Utils.CalculateMD5Hash(txtPasswordInput.Text);
            String   Email    = txtEmailInput.Text;
            String   Mobile   = txtMobileInput.Text;
            Boolean  Admin    = chkAdmin.Checked;
            DateTime Birth    = dtpBirthdate.Value;
            long     ree      = Birth.ToBinary();

            //MessageBox.Show(ree + "");
            signSuccess = true;
            //Tjekker om email er valid
            if (!Utils.IsValidEmail(Email))
            {
                pnlEmail.BackColor = Color.FromArgb(255, 0, 0); //Sæt panel farven for email = rød
                goingToShake       = true;                      //Sørger for at formen ryster hvis fejl
            }
            //Tjekker om password er over 8 eller bare er "Password"
            if (txtPasswordInput.Text.Length < 8 || txtPasswordInput.Text == "Password")
            {
                pnlPassword.BackColor = Color.FromArgb(255, 0, 0); //Sæt panel farven for password = rød
                goingToShake          = true;                      //Sørger for at formen ryster hvis fejl
            }
            //Tjekker om fulde navn indeholder noget som ikke er "Full Name"
            if (txtFullNameInput.Text.Length == 0 || txtFullNameInput.Text == "Full name")
            {
                pnlFullName.BackColor = Color.FromArgb(255, 0, 0); //Sæt panel farven for fulde navn = rød
                goingToShake          = true;                      //Sørger for at formen ryster hvis fejl
            }
            //Tjekker om mobil nummeret ikke er lig med 8, om der står "Mobile", eller hvis det ikke er tal
            if (txtMobileInput.Text.Length != 8 || txtMobileInput.Text == "Mobile" || !txtMobileInput.Text.All(char.IsDigit))
            {
                pnlMobile.BackColor = Color.FromArgb(255, 0, 0); //Sæt panel farven for mobil nummer = rød
                goingToShake        = true;                      //Sørger for at formen ryster hvis fejl
            }
            //Hvis formen skal ryste
            if (goingToShake)
            {
                Utils.Shake(this);
                goingToShake = false;
                signSuccess  = false;
            }
            //Hvis sign up er en success
            if (signSuccess)
            {
                User user = new User(Utils.GenerateID(), FullName, Password, Email, Mobile, false, Admin, new List <Account>()); //Her laver vi et nyt user objekt til vores nye bruger
                user.Save();                                                                                                     //Her gemmer vi vores nye bruger i vores system så han ikke mister sin bruger
                FormYesNo customMessage = new FormYesNo("Your account was created successfully!\nYour ID is: " + user.ID + ", write this down!\nVery important - You need it to login!\n\n\nWould you like to be logged in?");
                //Hvis brugeren vil logges ind med det samme
                if (customMessage.DialogResult == DialogResult.Yes)
                {
                    Settings.CurrentUser = user;
                    var t = new Thread(() => Application.Run(new FormMain()));
                    t.Start();
                    //Luk Sign Up og LogSign da man nu er inde i main form
                    Application.OpenForms["FormSignUp"].Close();
                    Application.OpenForms["FormLogSign"].Close();
                    //Ellers bare luk sign up
                }
                else if (customMessage.DialogResult == DialogResult.No)
                {
                    this.Hide();
                }
            }
            else
            {
                return;
            }
        }