Exemple #1
0
        private void TransactionEntry_Load(object sender, EventArgs e)
        {
            //connStr = MainForm.ReturnConnectionString();
            conn = new MySqlConnection(connStr);
            cmd  = new MySqlCommand();
            List <string> budgetLst = new List <string>();

            //Populate listview with current budget entries.
            myBudget.BudgetTableGetExpenseCategoryCurrentMonth(ref budgetLst);
            cmbo_BudgetName.DataSource = budgetLst;

            //Determine if modify or add btn was pressed for transaction entries
            if (isModifyTransactionEntry)
            {
                int selectedIndex;
                selectedIndex = cmbo_BudgetName.FindString(myTransaction.SelectedTransaction.transactionName);
                cmbo_BudgetName.SelectedIndex = selectedIndex;
                cmbo_BudgetName.Enabled       = false;

                //TODO add modification of Transaction Entry
                //if modify
                //get selected item from the transaction listview and show it in the
                //list box on the transaction entry form
            }
        }
Exemple #2
0
        private void FillBudgetDataGridView()
        {
            //https://stackoverflow.com/questions/29148568/filling-a-liststring-with-mysql-query
            //https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-bind-objects-to-windows-forms-datagridview-controls

            BindingSource bindingSource = new BindingSource();
            List <string> budgetLst     = new List <string>();
            BudgetDB      myBudget      = new BudgetDB();
            TransactionDB myTransaction = new TransactionDB();
            int           errNbr        = 0;
            decimal       budgetAmount  = 0;
            decimal       budgetSpent   = 0;
            decimal       budgetRemaing = 0;

            //Get list of budgets that money is spent from
            errNbr = myBudget.BudgetTableGetExpenseCategoryCurrentMonth(ref budgetLst);

            //For each budget item get the budget amount, budget spent, and budget remaining
            if (errNbr == 0)
            {
                foreach (string budgetName in budgetLst)
                {
                    //Get budget amount from budget table
                    errNbr = myBudget.BudgetTableGetBudgetAmtForCategory(ref budgetAmount, budgetName);
                    //Get budget spent from transaction table
                    errNbr = myTransaction.TransactionTableGetTotalBudgetAmtSpent(ref budgetSpent, budgetName);
                    //Get budget remaining by subtracting total spent from total budget amount
                    budgetRemaing = budgetAmount - budgetSpent;
                    //Create new BudgetTable object initialized with above values
                    BudgetTableEntry tmpEntry = new BudgetTableEntry(budgetName, budgetAmount.ToString(), budgetSpent.ToString(), budgetRemaing.ToString());
                    //Add BudgetTable to Binding source
                    bindingSource.Add(tmpEntry);
                }
                dgv_BudgetReport.DataSource = bindingSource;
            }
        }