예제 #1
0
        public static void Deposit(ref Transaction T)
        {
            string[] Transaction = { "transactionid ", "Transaction" };

            OracleConnection conn = new OracleConnection(DBConnect.oradb);

            conn.Open();
            T.TransactionID = Reusable.GetNextId(Transaction).ToString("D14");
            T.timestamp     = DateTime.Now.ToString("dd/MM/yyyy/HH:mm:ss");

            String CustSQL = "INSERT INTO Transaction(transactionid,accountid,Type,amount,note,timestamp) " +
                             "VALUES('" + T.TransactionID + "', '" + T.account + "', '" + T.type + "', '" + T.amount + "', '" + T.note + "', TO_DATE('" + T.timestamp + "', 'DD/MM/YYYY HH24:MI:SS'))";

            OracleCommand Custcmd = new OracleCommand(CustSQL, conn);

            Custcmd.ExecuteNonQuery();


            string[] findbalance = { "balance", "account where accountid = " + T.account };
            string   balance     = Reusable.stringfromDB(findbalance);
            decimal  d1          = decimal.Parse(balance);
            decimal  d2          = decimal.Parse(T.amount);
            string   newbalance  = (d1 + d2).ToString("F2");

            String LogSQL = "UPDATE Account SET BALANCE = '" + newbalance + "' where accountid = " + T.account;

            OracleCommand Logcmd = new OracleCommand(LogSQL, conn);

            Logcmd.ExecuteNonQuery();

            conn.Close();
        }
예제 #2
0
        public static bool CheckBalance(ref Transaction T)
        {
            string[] Checkbalance = { "balance", "account where accountid = " + T.account };

            string balance = Reusable.stringfromDB(Checkbalance);

            decimal d1 = decimal.Parse(balance);
            decimal d2 = decimal.Parse(T.amount);

            if (d1 >= d2)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        public static void Transfer(ref Transaction T)
        {
            string[] Transaction = { "transactionid ", "Transaction" };

            OracleConnection conn = new OracleConnection(DBConnect.oradb);

            conn.Open();
            T.TransactionID = Reusable.GetNextId(Transaction).ToString("D14");
            T.timestamp     = DateTime.Now.ToString("dd/MM/yyyy/HH:mm:ss");

            String transferSQL = "INSERT INTO Transaction(transactionid,accountid,Type,amount,note,timestamp) " +
                                 "VALUES('" + T.TransactionID + "', '" + T.account + "', '" + T.type + "', '" + T.amount + "', '" + T.note + "', TO_DATE('" + T.timestamp + "', 'DD/MM/YYYY HH24:MI:SS'))";

            OracleCommand Transfercmd = new OracleCommand(transferSQL, conn);

            Transfercmd.ExecuteNonQuery();

            string[] creditorarr = { "balance", "account where accountid = " + T.account };
            string[] debtorarr   = { "balance", "account where accountid = " + T.debtor };
            string   creditorbal = Reusable.stringfromDB(creditorarr);
            string   debtorbal   = Reusable.stringfromDB(debtorarr);

            decimal Cbal   = decimal.Parse(creditorbal);
            decimal amount = decimal.Parse(T.amount);
            decimal Dbal   = decimal.Parse(debtorbal);

            string newCreditorbal = (Cbal - amount).ToString("F2");
            string newDebtorbal   = (Dbal + amount).ToString("F2");

            String removebal = "UPDATE Account SET BALANCE = '" + newCreditorbal + "' where accountid = " + T.account;
            String addbal    = "UPDATE Account SET BALANCE = '" + newDebtorbal + "' where accountid = " + T.debtor;

            OracleCommand removebalance = new OracleCommand(removebal, conn);

            removebalance.ExecuteNonQuery();

            OracleCommand addbalance = new OracleCommand(addbal, conn);

            addbalance.ExecuteNonQuery();

            conn.Close();
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            string[] findbalance = { "balance", "account where accountid = " + cboAccount.SelectedValue.ToString() };
            string   balance     = Reusable.stringfromDB(findbalance);

            if (balance.Equals("0.00"))
            {
                if (MessageBox.Show("Are you sure you want to close this account?", "Close Account", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    AccountSQL.CloseAccount(cboAccount.SelectedValue.ToString());
                    MessageBox.Show("You Closed " + cboAccount.SelectedText.ToString() + " has been closed");
                    FrmDisplayAccounts back = new FrmDisplayAccounts();
                    back.Show();
                    this.Hide();
                }
                else
                {
                }
            }
            else
            {
                MessageBox.Show("Please empty your account of money before closing your account");
            }
        }
예제 #5
0
        private void btnDeposit_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();
            Transaction T = new Transaction();

            T.amount  = txtDepositAmount.Text;
            T.note    = txtDepositNote.Text;
            T.account = cboAccount.SelectedValue.ToString();
            T.type    = "D";
            Validation v     = new Validation();
            bool       valid = true;

            if (!v.IsAmount(T.amount) || decimal.Parse(T.amount).Equals(0))
            {
                errorProvider1.SetError(txtDepositAmount, "Amount must only be numbers and in the format 0.00 and greater then 0.01");
                valid = false;
            }
            if ((!v.IsAccount(T.note)) && (!T.note.Equals("")))
            {
                errorProvider1.SetError(txtDepositNote, "Note must not contain any special characters");
                valid = false;
            }

            if (valid)
            {
                string[] findbalance = { "balance", "account where accountid = " + cboAccount.SelectedValue.ToString() };
                try
                {
                    string  balance = Reusable.stringfromDB(findbalance);
                    decimal d1      = decimal.Parse(balance);
                    decimal d2      = decimal.Parse(txtDepositAmount.Text);
                    decimal d4      = decimal.Parse("9999999.99");
                    decimal d3      = d1 + d2;
                    if (d3 <= d4)
                    {
                        if (MessageBox.Show("Are you sure you want to Deposit €" + T.amount, "Confirm Deposit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            try
                            {
                                TransactionSQL.Deposit(ref T);
                                MessageBox.Show("You deposited €" + T.amount);
                                FrmDisplayAccounts Display = new FrmDisplayAccounts();
                                Display.Show();
                                this.Hide();
                            }
                            catch
                            {
                                MessageBox.Show("Error 013: Could not connect to database. Please contact an administratior");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Woah there! with this deposit you'll have too much money in your account.\nPlease deposit that into another Account");
                    }
                }
                catch
                {
                    MessageBox.Show("Error 012: Could not connect to database. Please contact an administratior");
                }
            }
        }