예제 #1
0
        public void searchCurrentAccount(string An)
        {
            accountFile           obj      = new accountFile();
            List <currentAccount> accounts = obj.readAllCurrentAccount(); //simple list: saves same type of objects
            int  totalAccounts             = accounts.Count;              //built-in count list function
            bool found = false;

            for (int i = 0; i < totalAccounts; i++)
            {
                if (accounts[i].accountNoProperty == An)
                {
                    found = true;
                    Console.WriteLine("\nAccount Found.\n");
                    return;
                }
            }
            Console.WriteLine("\nAccount Not Found.\n");
        }
예제 #2
0
        public void transaction()
        {
            Console.Write("\nChoose Account Type:\n");
            Console.Write("1.Current Account.   2.Saving Account.\n");
            int num = int.Parse(Console.ReadLine());

            if (num == 1)
            {
                Console.WriteLine("\nEnter Account Number:");
                string accnum = Console.ReadLine();

                accountFile           obj      = new accountFile();
                List <currentAccount> accounts = obj.readAllCurrentAccount(); //simple list: saves same type of objects
                int  totalAccounts             = accounts.Count;              //built-in count list function
                bool found = false;

                for (int i = 0; i < totalAccounts; i++)
                {
                    if (accounts[i].accountNoProperty == accnum)
                    {
                        found = true;
                        Console.WriteLine("\nAccount Found.\n");

                        Console.Write("\nChoose Transaction Type:\n");
                        Console.Write("1.Deposit Amount.   2.Withdraw Amount.\n");
                        int option = int.Parse(Console.ReadLine());

                        if (option == 1)
                        {
                            Console.Write("Enter Deposit Amount:\n");
                            int depositAmount = int.Parse(Console.ReadLine());
                            accounts[i].balanceProperty = (accounts[i].balanceProperty + depositAmount);
                            accounts[i].deposit(depositAmount);
                        }
                        if (option == 2)
                        {
                            Console.Write("Enter Withdrawal Amount:\n");
                            int withdrawalAmount = int.Parse(Console.ReadLine());
                            if (withdrawalAmount <= accounts[i].withdrawalLimitProperty)
                            {
                                accounts[i].balanceProperty = (accounts[i].balanceProperty + withdrawalAmount);
                                accounts[i].withdraw(withdrawalAmount);
                            }
                            else
                            {
                                Console.Write("ERROR!!! Amount more than Withdrawal Limit.\n");
                            }
                        }
                    }
                }

                StreamWriter writeCurrent = new StreamWriter("CurrentAccount.txt"); //write to file object

                for (int j = 0; j < totalAccounts; j++)
                {
                    currentAccount account = accounts[j];
                    writeCurrent.WriteLine(account.accountNoProperty);
                    writeCurrent.WriteLine(account.accountTitleProperty);
                    writeCurrent.WriteLine(account.balanceProperty);
                    writeCurrent.WriteLine(account.cnicProperty);
                    writeCurrent.WriteLine(account.contactNoProperty);
                    writeCurrent.WriteLine(account.withdrawalLimitProperty);
                }
                writeCurrent.Close();
                return;
            }

            else if (num == 2)
            {
                Console.WriteLine("\nEnter Account Number:");
                string accnum = Console.ReadLine();

                accountFile obj      = new accountFile();
                ArrayList   accounts = obj.readAllSavingAccount(); //array list: saves diffeent types of objects

                int  totalAccounts = accounts.Count;               //built-in count list function
                bool found         = false;

                for (int i = 0; i < totalAccounts; i++)
                {
                    if ((accounts[i] as savingAccount).accountNoProperty == accnum)
                    {
                        found = true;
                        Console.WriteLine("\nAccount Found.\n");

                        Console.Write("\nChoose Transaction Type:\n");
                        Console.Write("1.Deposit Amount.   2.Withdraw Amount.\n");
                        int option = int.Parse(Console.ReadLine());

                        if (option == 1)
                        {
                            Console.Write("Enter Deposit Amount:\n");
                            int depositAmount = int.Parse(Console.ReadLine());
                            (accounts[i] as savingAccount).balanceProperty = ((accounts[i] as savingAccount).balanceProperty + depositAmount);
                            (accounts[i] as savingAccount).deposit(depositAmount);
                        }
                        if (option == 2)
                        {
                            Console.Write("Enter Withdrawal Amount:\n");
                            int withdrawalAmount = int.Parse(Console.ReadLine());
                            (accounts[i] as savingAccount).balanceProperty = ((accounts[i] as savingAccount).balanceProperty + withdrawalAmount);
                            (accounts[i] as savingAccount).withdraw(withdrawalAmount);
                        }
                    }
                }

                StreamWriter writeSaving = new StreamWriter("SavingAccount.txt"); //write to file object

                for (int j = 0; j < totalAccounts; j++)
                {
                    savingAccount account = accounts[j] as savingAccount;
                    writeSaving.WriteLine(account.accountNoProperty);
                    writeSaving.WriteLine(account.accountTitleProperty);
                    writeSaving.WriteLine(account.balanceProperty);
                    writeSaving.WriteLine(account.cnicProperty);
                    writeSaving.WriteLine(account.contactNoProperty);
                    writeSaving.WriteLine(account.profitPercentageProperty);
                }
                writeSaving.Close();
                return;
            }
            else
            {
                Console.WriteLine("Invalid Input\n");
            }
        }
예제 #3
0
        public void displayAccount()
        {
            Console.Write("\nChoose Account Type:\n");
            Console.Write("1.Current Account.   2.Saving Account.\n");
            int num = int.Parse(Console.ReadLine());

            if (num == 1)
            {
                Console.WriteLine("\nEnter Account Number:");
                string accnum = Console.ReadLine();

                accountFile           obj      = new accountFile();
                List <currentAccount> accounts = obj.readAllCurrentAccount(); //simple list: saves same type of objects
                int  totalAccounts             = accounts.Count;              //built-in count list function
                bool found = false;

                for (int i = 0; i < totalAccounts; i++)
                {
                    if (accounts[i].accountNoProperty == accnum)
                    {
                        found = true;
                        Console.WriteLine("\nAccount Found.\n");

                        Console.Write("\nAccount Number:    ");
                        Console.Write(accounts[i].accountNoProperty);

                        Console.Write("\nAccount Title: ");
                        Console.Write(accounts[i].accountTitleProperty);

                        Console.Write("\nCNIC:  ");
                        Console.Write(accounts[i].cnicProperty);

                        Console.Write("\nContact Number:    ");
                        Console.Write(accounts[i].contactNoProperty);

                        Console.Write("\nAccount Balance:   ");
                        Console.Write(accounts[i].balanceProperty);

                        Console.WriteLine("\nWithdrawal Limit:  ");
                        Console.Write(accounts[i].withdrawalLimitProperty);
                    }
                }
            }

            else if (num == 2)
            {
                Console.WriteLine("\nEnter Account Number:");
                string accnum = Console.ReadLine();

                accountFile obj      = new accountFile();
                ArrayList   accounts = obj.readAllSavingAccount(); //array list: saves diffeent types of objects

                int  totalAccounts = accounts.Count;               //built-in count list function
                bool found         = false;

                for (int i = 0; i < totalAccounts; i++)
                {
                    if ((accounts[i] as savingAccount).accountNoProperty == accnum)
                    {
                        found = true;
                        Console.WriteLine("\nAccount Found.\n");

                        Console.Write("\nAccount Number:");
                        Console.Write((accounts[i] as savingAccount).accountNoProperty);

                        Console.Write("\nAccount Title:");
                        Console.Write((accounts[i] as savingAccount).accountTitleProperty);

                        Console.Write("\nCNIC:");
                        Console.Write((accounts[i] as savingAccount).cnicProperty);

                        Console.Write("\nContact Number:");
                        Console.Write((accounts[i] as savingAccount).contactNoProperty);

                        Console.Write("\nAccount Balance:");
                        Console.Write((accounts[i] as savingAccount).balanceProperty);

                        Console.WriteLine("\nProfit Percentage:");
                        Console.Write((accounts[i] as savingAccount).profitPercentageProperty);
                    }
                }
            }
            else
            {
                Console.WriteLine("Invalid Input\n");
            }
        }
예제 #4
0
        public void deleteAccount()
        {
            Console.Write("\nChoose Account Type:\n");
            Console.Write("1.Current Account.   2.Saving Account.\n");
            int num = int.Parse(Console.ReadLine());

            if (num == 1)
            {
                Console.WriteLine("\nEnter Account Number:");
                string                accnum   = Console.ReadLine();
                accountFile           obj      = new accountFile();
                List <currentAccount> accounts = obj.readAllCurrentAccount(); //simple list: saves same type of objects
                int  totalAccounts             = accounts.Count;              //built-in count list function
                bool found = false;

                for (int i = 0; i < totalAccounts; i++)
                {
                    if (accounts[i].accountNoProperty == accnum)
                    {
                        found = true;
                        Console.WriteLine("\nAccount Found.\n");

                        accounts.Remove(accounts[i]); //deletes that object with i index
                        totalAccounts--;
                    }
                }

                StreamWriter writeCurrent = new StreamWriter("CurrentAccount.txt"); //write to file object

                for (int j = 0; j < totalAccounts; j++)
                {
                    currentAccount account = accounts[j];
                    writeCurrent.WriteLine(account.accountNoProperty);
                    writeCurrent.WriteLine(account.accountTitleProperty);
                    writeCurrent.WriteLine(account.balanceProperty);
                    writeCurrent.WriteLine(account.cnicProperty);
                    writeCurrent.WriteLine(account.contactNoProperty);
                    writeCurrent.WriteLine(account.withdrawalLimitProperty);
                }
                writeCurrent.Close();
                return;
            }

            else if (num == 2)
            {
                Console.WriteLine("\nEnter Account Number:");
                string      accnum        = Console.ReadLine();
                accountFile obj           = new accountFile();
                ArrayList   accounts      = obj.readAllSavingAccount(); //array list: saves diffeent types of objects
                int         totalAccounts = accounts.Count;             //built-in count list function
                bool        found         = false;

                for (int i = 0; i < totalAccounts; i++)
                {
                    if ((accounts[i] as savingAccount).accountNoProperty == accnum)
                    {
                        found = true;
                        Console.WriteLine("\nAccount Found.\n");

                        accounts.Remove(accounts[i]); //deletes that object with i index
                        totalAccounts--;
                    }
                }

                StreamWriter writeSaving = new StreamWriter("SavingAccount.txt"); //write to file object

                for (int j = 0; j < totalAccounts; j++)
                {
                    savingAccount account = accounts[j] as savingAccount;
                    writeSaving.WriteLine(account.accountNoProperty);
                    writeSaving.WriteLine(account.accountTitleProperty);
                    writeSaving.WriteLine(account.balanceProperty);
                    writeSaving.WriteLine(account.cnicProperty);
                    writeSaving.WriteLine(account.contactNoProperty);
                    writeSaving.WriteLine(account.profitPercentageProperty);
                }
                writeSaving.Close();
                return;
            }
            else
            {
                Console.WriteLine("Invalid Input\n");
            }
        }