Пример #1
0
        private TransactionHistory LoadFromFile(string filename, string ID)
        {
            TransactionHistory history = new TransactionHistory(ID);

            if (File.Exists(filename))
            {
                StreamReader file = new StreamReader(filename);
                history.SetKey(file.ReadLine());
                string entry = file.ReadLine();
                while (String.IsNullOrEmpty(entry) == false)
                {
                    BankTransaction transaction = ParseEntry(entry);
                    if (transaction.IsActive)
                    {
                        history.AddEntry(transaction);
                    }

                    entry = file.ReadLine();
                }
                history.Activate();

                file.Close();

                Console.WriteLine($"Loaded history details for {history.Key} (count:{history.Count})");
            }
            else
            {
                Console.WriteLine("File not found: " + filename);
            }

            return(history);
        }
Пример #2
0
 private void RecordToHistory(BankTransaction transaction)
 {
     if (transaction.TransactionType != BankTransactionType.NONE)
     {
         TransactionHistoryDao historyDao = new TransactionHistoryDao();
         TransactionHistory    history    = historyDao.Load(_account.Key);
         history.AddEntry(transaction);
         historyDao.Save(history);
     }
 }
Пример #3
0
        public ChoresCompletion(User user)
        {
            ResultTransaction = BankTransaction.Empty;
            _user             = user;

            InitializeComponent();

            LoadAvailableChores();
            PopulateListView();
            UpdateTotal(0);
        }
Пример #4
0
        public TypingGameForm()
        {
            ResultTransaction = BankTransaction.Empty;

            InitializeComponent();

            SetupVessels();
            SetupSprites();
            UpdateLabel();
            SetupKeys();
        }
Пример #5
0
        public MathGameForm()
        {
            InitializeComponent();

            ResultTransaction = BankTransaction.Empty;
            problemList       = new List <MathProblem>();
            ChooseMathType();
            RestartClock();
            SetupProblems();
            SetupSounds();
            FocusOnFirstProblem();
        }
Пример #6
0
        private void InformUserOfChangeToBalance(BankTransaction resultTransaction)
        {
            if (resultTransaction.TransactionAmount > 0)
            {
                string amount = resultTransaction.TransactionAmount.ToString("N2");

                if (resultTransaction.TransactionType == BankTransactionType.DEPOSIT)
                {
                    MessageBox.Show($"You've earned {amount} more Family Bucks!");
                }
                else
                {
                    MessageBox.Show($"You've spent {amount} Family Bucks.");
                }
            }
        }
Пример #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            ParentalSignoff signoff = new ParentalSignoff(_user, SelectedChores());

            if (signoff.ShowDialog() == DialogResult.Yes)
            {
                StringBuilder choreNamesBuilder = new StringBuilder();
                foreach (Chore chore in SelectedChores())
                {
                    choreNamesBuilder.Append(chore.Name);
                    choreNamesBuilder.Append(";");
                }

                string choresCompletedReason = $"Chores completed:{choreNamesBuilder.ToString()}";
                ResultTransaction = new BankTransaction(BankTransactionType.DEPOSIT, talliedTotal, choresCompletedReason);
                DialogResult      = DialogResult.OK;
            }
        }
Пример #8
0
        private void FinalizeTransaction(BankTransaction transaction)
        {
            switch (transaction.TransactionType)
            {
            case BankTransactionType.NONE:
                break;

            case BankTransactionType.WITHDRAW:
                WithdrawFamilyBucks(transaction.TransactionAmount);
                break;

            case BankTransactionType.DEPOSIT:
                DepositFamilyBucks(transaction.TransactionAmount);
                break;

            default:
                break;
            }
        }
Пример #9
0
        private static BankTransaction ParseEntry(string entry)
        {
            BankTransaction transaction = new BankTransaction();

            string[] fields = entry.Split(',');
            if (fields.Length >= 4)
            {
                string key = fields[0].Trim();
                BankTransactionType tranType = (BankTransactionType)Enum.Parse(typeof(BankTransactionType), fields[1]);
                double   amount   = double.Parse(fields[2]);
                string   reason   = fields[3].Trim();
                DateTime dateTime = DateTime.Parse(fields[4]);

                transaction = new BankTransaction(tranType, amount, reason);
                transaction.SetKey(key);
                transaction.SetCreationTime(dateTime);
                transaction.Activate();
            }
            return(transaction);
        }
Пример #10
0
        private void RunProgram(FamilyBucksProgram program)
        {
            BankTransaction resultTransaction = BankTransaction.Empty;

            if (programManager.PermitsPlaying(program))
            {
                programManager.RecordAsPlayed(program);

                switch (program.Name)
                {
                case "Math Game":
                    resultTransaction = PlayMathGame();
                    break;

                case "Free Family Buck":
                    resultTransaction = PlayFreeFamilyBuck();
                    break;

                case "Chores Completion":
                    resultTransaction = RunChoresCompletion(programManager.SessionUser);
                    break;

                case "Typing Game":
                    resultTransaction = PlayTypingGame();
                    break;

                default:
                    break;
                }

                programManager.ProcessTransaction(resultTransaction);
                InformUserOfChangeToBalance(resultTransaction);
                UpdateBalance();
            }
            else
            {
                MessageBox.Show("You have already played this game up to the limit!", "No more playing this today");
            }
        }
Пример #11
0
        private static void WriteEntry(BankTransaction transaction, StreamWriter file)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(transaction.Key);

            builder.Append(",");
            builder.Append(transaction.TransactionType.ToString());

            builder.Append(",");
            builder.Append(transaction.TransactionAmount.ToString("N3"));

            builder.Append(",");
            builder.Append(transaction.ReasonFor);

            builder.Append(",");
            builder.Append(transaction.CreationTime.ToShortDateString());
            builder.Append(" ");
            builder.Append(transaction.CreationTime.ToShortTimeString());


            file.WriteLine(builder.ToString());
        }
Пример #12
0
 public void ProcessTransaction(BankTransaction transaction)
 {
     FinalizeTransaction(transaction);
     RecordToHistory(transaction);
 }
Пример #13
0
 private void MathGameForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     ResultTransaction = new BankTransaction(BankTransactionType.DEPOSIT, totalEarnings, "Math Game Winnings");
 }
Пример #14
0
 private void button1_Click(object sender, EventArgs e)
 {
     ResultTransaction = new BankTransaction(BankTransactionType.DEPOSIT, 1, "Free Family Buck!");
     MessageBox.Show("Transfer Complete", "1 Family Buck recieved.");
     DialogResult = DialogResult.OK;
 }