예제 #1
0
        //======================================================================
        private void rewrite_Click(object sender, EventArgs e)
        //======================================================================
        {
            string output = "";

            if (notes.Text == "" || AccountNumber.Text == "" || AccountBalance.Text == "" || OpenDate.Text == "" || Interest.Text == "" || custno.Text == "")
            {
                MessageBox.Show("One or more data items are Empty - All fields must be completed before saving it ..." +
                                "\nRecommeded action is to use the DropDown list to reselect a valid Bank Account", "Data Validation ERROR");
                info.Text = "One or more data items are Empty - All fields must be completed before saving it ..."; return;
            }
            string stat;

            if (status.Text == "Active")
            {
                stat = "1";
            }
            else
            {
                stat = "0";
            }
            int type = AccountType.SelectedIndex + 1;

            // format is "Bank A/c #  + "," + Customer A/c # + "," + A/c Type + "," + Balance + "," + Date Opened (short) + "," + Date Closed (short) + "," + Interest + "," + Status (0/1)+ "\r\n"
            output  = AccountNumber.Text + "," + custno.Text + "," + type.ToString() + "," + AccountBalance.Text + ",";
            output += Convert.ToDateTime(OpenDate.Text).ToShortDateString() + "," + Convert.ToDateTime("01/01/0001").ToShortDateString() + "," + Interest.Text;
            output += "," + stat + "\r\n";
            string path = BankAccount.ReadBankFilePath();

            path += "Textfiles\\BankObject" + AccountNumber.Text + ".txt";
            if (File.Exists(path))
            {
                File.Delete(path);      // you gotta delete them first, else it appends the data constantly
            }
            File.AppendAllText(path, output);

            // update the bank object
            path  = BankAccount.ReadBankFilePath();
            path += "Bankobject" + AccountNumber.Text + ".bnk";

            // read the bank a/c in fresh from disk so it is clean
            BankAccount Bank = SerializeData.ReadBankAccountFromDisk(path);

            if (Bank == null)
            {
                MessageBox.Show("Bank Account Object file cannot be loaded (or saved)!", "Bank Object Error"); return;
            }
            Int32 bankno = Bank.BankAccountNumber;

            // update the Bank object
            Bank.AccountType = Convert.ToInt16(AccountType.SelectedIndex);
            Bank.AccountType++;// cos th reindex starts at ZERO !!
            Bank.Balance      = Convert.ToDecimal(AccountBalance.Text);
            Bank.InterestRate = Convert.ToDecimal(Interest.Text);
            string banknostring = Bank.BankAccountNumber.ToString();

            //Update the version in Bank Array
            int index = DataArray.ArrayFindBank(Bank);

            DataArray.BankNo[index] = Bank;

            // Update the version in our Bank LinkedList
            foreach (var B in BankAccount.BankAccountsLinkedList)
            {
                if (B.BankAccountNumber == bankno)
                {   // got it, rpelace with our new one
                    BankAccount.BankAccountsLinkedList.Remove(B);
                    BankAccount.BankAccountsLinkedList.AddLast(Bank);
                    break;
                }
            }
            // This saves the bank LinkedList to both an object file and a Text file
            Lists.SaveAllBankAccountListData();
            // write theBank object to disk
            SerializeData.WriteBankAccountToDiskAndText(Bank, path);
            // Add a bank Transaction
            BankTransaction newbankaccount = new BankTransaction(Bank.DateOpened, Bank.AccountType, Bank.CustAccountNumber,
                                                                 Bank.BankAccountNumber, Bank.Balance, "Bank details edited from Textfile input", Bank.Status);

            BankTransaction.allBankTransactions.AddLast(newbankaccount);
            // that's it ***ALL***all Bank Data structures have been updated
            info.Text = "Bank Account data has been fully updated throughout System";
        }
예제 #2
0
        // Go ahead and make bank account deposit
        //******************************************************************************************************************************
        private void MakeDeposit_Click_1(object sender, EventArgs e)
        //******************************************************************************************************************************
        {
            // Caution, this bank account may be one of several for this customer,
            // so make NO assumptions
            // Bank is already the correct record
            Int32 bankaccountno = 0;

            if (accountnumber.Text.Length == 0 || textBox2.Text.Length == 0)
            {
                info.Text = "Please complete both fields before pressing Go";
                MessageBox.Show("Please complete both fields before pressing Go", "Data Input Error");
                return;
            }
            if (notes.Text == "")
            {
                MessageBox.Show("You have not entered a reason for this deposit ?\nDo you want to continue without doing so ?",
                                "Data Input Error", MessageBoxButtons.YesNo);
                if (DialogResult == DialogResult.No)
                {
                    return;
                }
            }

            // This is the bank account #
            bankaccountno = Convert.ToInt32(accountnumber.Text);
            string acnostring = accountnumber.Text;
            string amountstr  = textBox2.Text.Trim( );

            if (!amountstr.Contains("."))
            {
                amountstr += ".00";
            }
            decimal amount = Convert.ToDecimal(amountstr);

            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), "Amount of Deposit [" + amount + "] must be positive");
            }

            // Update the Bank ArrayList
            Bank = DataArray.ArrayGetBank(bankaccountno);
            if (Bank == null)
            {
                MessageBox.Show("Unable to Find Bank  Account in LinkedList??..\nDeposit transaction aborted.", "Fatal Error"); return;
            }
            string custnostring = Bank.CustAccountNumber.ToString( );


            // This call updates BOTH  the Bank A/c and the entry in the LinkedList
            if (!BankAccount.UpdateBankLinkedList(bankaccountno, amount))
            {
                MessageBox.Show("Failed to update BankAccount Linked List for Account " + acnostring, "Bank Account Deposit");
            }
            // Also save the updated bank account back to disk
            SerializeData.WriteBankAccountToDiskAndText(Bank, Bank.FullFileName);
            // now add a new transaction for this operation
            BankTransaction Deposit = new BankTransaction( );

            Deposit.TransDate         = DateTime.Now;
            Deposit.AccountType       = Bank.AccountType;
            Deposit.CustAccountNumber = Bank.CustAccountNumber;
            Deposit.BankAccountNumber = Bank.BankAccountNumber;
            Deposit.Transamount       = amount;
            Deposit.Notes             = "New Deposit : " + notes.Text;
            Deposit.Status            = Bank.Status;
            BankTransaction.allBankTransactions.AddLast(Deposit);

            // update the Customer Balance Hash Table cos it holds the balance value
            CustomerBalanceHashTable.DeleteHashCustBalEntry(custnostring);
            CustomerBalanceHashTable.AddHashCustBalEntry(custnostring, Bank.Balance);

            MessageBox.Show("Deposit of " + amount.ToString( ) + " has been added to account  # " + custnostring + "\nThe new balance is £" + Bank.Balance.ToString( ), "Bank Account Deposit");
            textBox2.Text = "";
            notes.Text    = "";
            accountnumber.Focus( );
            return;
        }