예제 #1
0
        private void btnAnnualInterest_Click(object sender, EventArgs e)
        {
            foreach (DataRow rowInterest in dtAccounts.Rows)                                                                                                   //iterates through each row in accounts table
            {
                balancePlusAccruedInterest = Math.Round(double.Parse(rowInterest["balance"].ToString()) + double.Parse(rowInterest["accrued"].ToString()), 2); //adds accrued to balance and rounds to
                //2sf to prevent adding issue that causes excessive sf
                using (SQLiteCommand cmd = conn.CreateCommand())                                                                                               //runs command to update an accounts by opening a connection, running the query and closing the connection
                {
                    cmd.CommandText = @"UPDATE account Set balance = @balance, accrued = @accrued Where accid = @accID";
                    cmd.Parameters.AddWithValue("balance", balancePlusAccruedInterest);
                    cmd.Parameters.AddWithValue("accrued", "0");
                    cmd.Parameters.AddWithValue("accid", rowInterest["accid"].ToString());

                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
                using (SQLiteCommand cmd = conn.CreateCommand())        //runs command to insert the transaction for the above account balance update by opening a connection,
                {                                                       //running the query and closing the connection
                    cmd.CommandText = @"Insert into tranx(accid, action, amnt, event) values (@accid, @action, @amnt, @event)";
                    cmd.Parameters.AddWithValue("accid", rowInterest["accid"].ToString());
                    cmd.Parameters.AddWithValue("action", "interest");
                    cmd.Parameters.AddWithValue("amnt", rowInterest["accrued"].ToString());
                    cmd.Parameters.AddWithValue("event", System.DateTime.Now.ToString());

                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
            Form form = new AllAccounts();      //refresh() not working, using new form load

            form.Show();
            this.Dispose();
        }
예제 #2
0
        private void btnBalAccruedCalc_Click(object sender, EventArgs e)
        {
            foreach (DataRow rowAccounts in dtAccounts.Rows)                                  //foreach loop runs through account table
            {
                foreach (DataRow rowProducts in dtProducts.Rows)                              //foreach loop runs through product table
                {
                    if (rowAccounts["prodid"].ToString() == rowProducts["prodid"].ToString()) //if statement that checks is account table prodid and product table prodid
                    {
                        accountID          = rowAccounts["accid"].ToString();                 //if above is true, 120 - 124 sets values to variables from table
                        customerID         = rowAccounts["custid"].ToString();
                        balance            = double.Parse(rowAccounts["balance"].ToString());
                        accrued            = double.Parse(rowAccounts["accrued"].ToString());
                        annualInterestRate = double.Parse(rowProducts["intrate"].ToString());
                        accrued            = accrued + ((balance * annualInterestRate) / 365); //sets accrued to new values based on calculation
                        accrued            = Math.Round(accrued, 2);                           //rounds accrued to 2 significant figures
                        using (SQLiteCommand cmd = conn.CreateCommand())                       //runs command to update an accounts by opening a connection, running the query and closing the connection
                        {
                            cmd.CommandText = @"UPDATE account Set accrued = @accrued Where accid = @accid AND custid = @custid";
                            cmd.Parameters.AddWithValue("accrued", accrued);
                            cmd.Parameters.AddWithValue("accid", accountID);
                            cmd.Parameters.AddWithValue("custid", customerID);

                            conn.Open();
                            cmd.ExecuteNonQuery();
                            conn.Close();
                        }
                        break;      //breaks foreach rowProducts loop
                    }
                }
            }
            Form form = new AllAccounts();      //refresh() not working, using new form load

            form.Show();
            this.Dispose();
        }
예제 #3
0
        private void btnAccounts_Click(object sender, EventArgs e)
        {
            Form form = new AllAccounts();

            form.Show();
        }