question

rowlandsfca avatar image
0 Votes"
rowlandsfca asked DanielZhang-MSFT answered

accessing multiple databases and calculate interest in windows forms using sqlite

i'm on a college course and part of it is studying programming, my current assignment is to create a basic application for a user to view customer, accounts, products and transfer databases. We are using windows forms app in visual studio and sqlite. i have it set up so you can view each table in a datagridview. i am able to update,add,delete each one. Part of the accounts table includes ISA balance and the daily accrued amount and the product able includes the interest rate for each product. What i need to do now is be able to update the accrued column for each account when the table is loaded. I have created method for calculating the number of days passed since the start of financial year and store it into a variable. I need now to go through the accounts table to get the balance and product type they have and the go through the product table to find the interest rate of each product and then calculate the accrued and update the accrued table with the new value.

     private void days()
     {
         year = DateTime.Now.Year - 1;
         DateTime start = new DateTime(year, 03, 13);
         DateTime end = DateTime.Today;
    
         TimeSpan span = end - start;
    
         difference = span.Days;
     }

I have a variable setup to store the product i and a method ready to run make the calulations based on what the product id is.

 if(Global.productID == "1")
         {
             interestRate = 0.03/365;
             Global.accrued = (interestRate * double.Parse(Global.balance))* difference;
                
         }
         if (Global.productID == "2")
         {
             interestRate = 0.07/365;
             Global.accrued = (interestRate * double.Parse(Global.balance)) * difference;
         }

I'm at a loss as to where to go from here so any help or guidance would be appreciated

 foreach (DataRow row in dt_Accounts.Rows)
             {
                 Global.productID = row["prodid"].ToString();
                 Global.balance = row["balance"].ToString();
                 interest();
                 row["accrued"] = Global.accrued.ToString();
                    
             }

i have tried the code above but that didnt work


dotnet-csharpwindows-formsdotnet-sqlite
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

Hi rowlandsfca,
>>What i need to do now is be able to update the accrued column for each account when the table is loaded
I suggest you can update the accrued column in DataGridView.DataBindingComplete event which occurs after a data-binding operation has finished.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.