public void PopulateChart(string s)
        {
            String    MonthlyInSQL  = "SELECT to_Char(TIMESTAMP,'MM') AS MONTH,SUM(to_number(Amount, '9999999.99')) From Transaction WHERE (Accountid = '" + cboAccount.SelectedValue + "' AND TYPE = 'D') OR debtorid = '" + cboAccount.SelectedValue + "' AND to_Char(TIMESTAMP,'DD/MM/YYYY') LIKE '%2021' GROUP BY to_Char(TIMESTAMP,'MM') ORDER BY to_Char(TIMESTAMP,'MM')";
            String    MonthlyOutSQL = "SELECT SUM(to_number(Amount, '9999999.99')) From Transaction WHERE (TYPE = 'W' OR Type = 'T') AND Accountid = '" + cboAccount.SelectedValue + "' AND to_Char(TIMESTAMP,'DD/MM/YYYY') LIKE '%2020' GROUP BY to_Char(TIMESTAMP,'MM') ORDER BY to_Char(TIMESTAMP,'MM')";
            DataTable MonthlyIn     = new DataTable();
            DataTable MonthlyOut    = new DataTable();

            MonthlyIn  = TransactionSQL.dtForChart(MonthlyInSQL);
            MonthlyOut = TransactionSQL.dtForChart(MonthlyOutSQL);
            string[]  N = new string[MonthlyIn.Rows.Count];
            decimal[] M = new decimal[MonthlyIn.Rows.Count];
            for (int i = 0; i < MonthlyIn.Rows.Count; i++)
            {
                N[i] = getMonth(Convert.ToInt32(MonthlyIn.Rows[i][0]));
                try
                {
                    M[i] = Convert.ToDecimal(MonthlyIn.Rows[i][1]) - Convert.ToDecimal(MonthlyOut.Rows[i][0]);
                }
                catch
                {
                    M[i] = Convert.ToDecimal(MonthlyIn.Rows[i][1]) - Convert.ToDecimal(0.00);
                }
            }
            chtTransactions.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
            chtTransactions.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
            chtTransactions.Series[0].LegendText = "Income in €"; chtTransactions.Series[0].Points.DataBindXY(N, M);
            chtTransactions.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "C";
            chtTransactions.Series[0].Label = "#VALY";
            chtTransactions.Visible         = true;
        }
        private void btnWithdraw_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();
            Transaction T = new Transaction();

            T.amount  = txtWithdrawAmount.Text;
            T.note    = txtWithdrawNote.Text;
            T.account = cboAccount.SelectedValue.ToString();
            T.type    = "W";
            Validation v     = new Validation();
            bool       valid = true;

            if (!v.IsAmount(T.amount) || decimal.Parse(T.amount).Equals(0))
            {
                errorProvider1.SetError(txtWithdrawAmount, "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(txtWithdrawNote, "Note must not contain any special characters");
                valid = false;
            }

            if (valid)
            {
                try
                {
                    if (TransactionSQL.CheckBalance(ref T))
                    {
                        try
                        {
                            TransactionSQL.Withdraw(ref T);
                            MessageBox.Show("You just withdrew €" + T.amount);

                            FrmDisplayAccounts Display = new FrmDisplayAccounts();
                            Display.Show();
                            this.Hide();
                        }
                        catch
                        {
                            MessageBox.Show("Error 017: Could not connect to database. Your Withdrawal Has not been processed \nPlease contact an administratior");
                        }
                    }
                    else
                    {
                        MessageBox.Show("You do not have enough money in your account to process this Withdrawal");
                    }
                }
                catch
                {
                    MessageBox.Show("Error 016: Could not connect to database. Please contact an administratior");
                }
            }
        }
        private void btnTransfer_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();
            Validation  v     = new Validation();
            Transaction T     = new Transaction();
            bool        valid = true;

            T.account = cboCreditorAccount.SelectedValue.ToString();
            T.amount  = txtCreditorAmount.Text;
            T.note    = txtCreditorNote.Text;
            T.debtor  = txtDebtorAccount.Text;

            if (!v.IsAmount(T.amount))
            {
                valid = false;
                errorProvider1.SetError(txtCreditorAmount, "Amount must only be numbers and in the format 0.00 and greater then 0.01");
            }

            if (!v.IsEmpty(T.note) && !v.IsAccount(T.note))
            {
                valid = false;
                errorProvider1.SetError(txtCreditorNote, "Note must not contain special characters");
            }
            if (!v.isAccountNumber(T.debtor) && !v.isIBAN(T.debtor))
            {
                valid = false;
                errorProvider1.SetError(txtDebtorAccount, "Please enter a valid account number or IBAN");
            }
            else if (T.debtor == T.account)
            {
                valid = false;
                errorProvider1.SetError(txtDebtorAccount, "Please select a different account");
            }
            if (valid)
            {
                if (TransactionSQL.CheckBalance(ref T))
                {
                    if (v.isIBAN(T.debtor))
                    {
                        try
                        {
                            if (MessageBox.Show("Are you sure?", "Pay", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                T.type = "P";
                                TransactionSQL.Pay(ref T);
                                MessageBox.Show("You just made a payment too " + T.debtor);

                                FrmDisplayAccounts Display = new FrmDisplayAccounts();
                                Display.Show();
                                this.Hide();
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Error 007: Could not connect to database. Please contact an administratior");
                        }
                    }
                    else if (v.isAccountNumber(T.debtor) && AccountSQL.AccountExists(T.debtor))
                    {
                        if (MessageBox.Show("Are you sure?", "Transfer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            try
                            {
                                T.type = "T";
                                TransactionSQL.Transfer(ref T);
                                MessageBox.Show("You transfered money too " + T.debtor);

                                FrmDisplayAccounts Display = new FrmDisplayAccounts();
                                Display.Show();
                                this.Hide();
                            }
                            catch
                            {
                                MessageBox.Show("Error 007: Could not connect to database. Please contact an administratior");
                            }
                        }
                    }
                    else
                    {
                        errorProvider1.SetError(txtDebtorAccount, "That Account doesn't exist or has been closed");
                    }
                }
                else
                {
                    errorProvider1.SetError(txtCreditorAmount, "You do not currently have enough money in your account to make that transaction");
                }
            }
        }
Exemple #4
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");
                }
            }
        }