Exemplo n.º 1
0
        /*
         * This inserts all expenses in a report into Expenses table.
         * The expenses in the same report will have the same value reportId
         * while inserting values into Expenses table, this will calculate total amount
         * of expenses in a report and call updateReportToTalAmount method will total amount.
         */
        public void AddExpenses(int reportId)
        {
            ExpensesTableAdapter adapter = new ExpensesTableAdapter();
            Reports.ExpensesDataTable expensesTable = new Reports.ExpensesDataTable();
            double totalExpenses = 0;

            adapter.Fill(expensesTable);
            foreach (Expense expense in Expenses)
            {
                adapter.Insert(expense.Date, expense.Location, expense.Description, expense.Amount, expense.Currency, expense.Amount_aud, expense.Receipt, reportId);
                totalExpenses += expense.Amount_aud;
            }
            UpdateReportTotalAmount(reportId, totalExpenses);
        }
        private int GetCurrentRowOfExpensesTable()
        {
            ExpensesTableAdapter adapter = new ExpensesTableAdapter();
            Reports.ExpensesDataTable expensesTable = new Reports.ExpensesDataTable();

            adapter.Fill(expensesTable);

            int lastId = 0;

            foreach (Reports.ExpensesRow expense in expensesTable)
            {
                lastId = expense.Id;
            }
            return lastId;
        }