Example #1
0
 public AddDebtPayment(ExpenseManager inExpenseManager, Debt inDebt, DebtPayment inDebtPayment)
 {
     this._expenseManager = inExpenseManager;
     this._debt = inDebt;
     this._debtPayment = inDebtPayment;
     // ### Call here to load the form
 }
Example #2
0
 public void AddToListDebt(Debt newDebt)
 {
     _lstDebts.Add(newDebt);
 }
Example #3
0
        private void LoadData()
        {
            // SQL Queries
            string selectExpenses = "SELECT dbo.GeneralExpense.*, dbo.Bill.* FROM GeneralExpense LEFT JOIN Bill ON GeneralExpense.Id = Bill.ExpenseId";
            string selectDebts = "SELECT dbo.Debt.* FROM dbo.Debt";
            using (SqlConnection loadConn = new SqlConnection(_connectionString))
            {
                try
                {
                    loadConn.Open();
                    SqlCommand cmdGetValues = new SqlCommand(selectExpenses, loadConn);
                    SqlDataReader dataReader = cmdGetValues.ExecuteReader();
                    while (dataReader.Read())
                    {
                        // Determine if data is general expense or bill
                        if (dataReader.IsDBNull(8))
                        {
                            // Create expense objects
                            GeneralExpense expense = new GeneralExpense();
                            expense.Id = dataReader.GetInt32(0);
                            expense.Name = dataReader.GetString(1);
                            expense.Description = dataReader.GetString(2);
                            expense.Value = dataReader.GetDouble(3);
                            expense.DateReceived = dataReader.GetDateTime(4);
                            expense.IsPaid = dataReader.GetBoolean(5);
                            expense.DatePaid = dataReader.IsDBNull(6) ? _dtNullDate : dataReader.GetDateTime(6);
                            expense.IsOutstanding = dataReader.GetBoolean(7);
                            _lstGeneralExpenses.Add(expense);
                        }
                        else
                        {
                            // Create bill objects
                            Bill bill = new Bill();
                            bill.Id = dataReader.GetInt32(0);
                            bill.Name = dataReader.GetString(1);
                            bill.Description = dataReader.GetString(2);
                            bill.Value = dataReader.GetDouble(3);
                            bill.DateReceived = dataReader.GetDateTime(4);
                            bill.IsPaid = dataReader.GetBoolean(5);
                            bill.DatePaid = dataReader.IsDBNull(6) ? _dtNullDate : dataReader.GetDateTime(6);
                            bill.IsOutstanding = dataReader.GetBoolean(7);
                            bill.BillId = dataReader.GetInt32(8);
                            bill.Issuer = dataReader.GetString(10);
                            bill.ReferenceNo = dataReader.GetString(11);
                            _lstBills.Add(bill);
                        }
                    }
                    dataReader.Close();
                    cmdGetValues.CommandText = selectDebts;
                    dataReader = cmdGetValues.ExecuteReader();
                    while (dataReader.Read())
                    {
                        // Create debt objects
                        Debt debt = new Debt();
                        debt.Id = dataReader.GetInt32(0);
                        debt.ExpenseId = dataReader.GetInt32(1);
                        debt.PersonOwing = dataReader.GetString(2);
                        debt.AmountOutstanding = dataReader.GetDouble(3);
                        debt.IsPaid = dataReader.GetBoolean(4);
                        debt.DatePaid = dataReader.IsDBNull(5) ? _dtNullDate : dataReader.GetDateTime(5);
                        _lstDebts.Add(debt);
                    }

                    dataReader.Dispose();
                    cmdGetValues.Dispose();
                    loadConn.Close();
                }
                catch (Exception e)
                {
                    // ### Exception details find someway to pass this to the form
                    string exceptionMessage = "The following error occured while trying to connect to the database:\n\n";
                    exceptionMessage += "Name: " + e.Message + "\n\n";
                    exceptionMessage += "Details: " + e.StackTrace;

                    // ### Debug
                    Console.WriteLine(exceptionMessage);
                }
            }
        }
Example #4
0
        private static void AddNewDebt(ExpenseManager inEM)
        {
            ExpenseManager em = inEM;
            Debt debt = new Debt();
            int dExpenseId = 0;
            string dPersonOwing = string.Empty;
            double dAmountOutstanding = 0;
            bool dIsPaid = false;
            DateTime dDatePaid = new DateTime(9999, 01, 01);
            bool isValid = false;
            string input = string.Empty;
            string invalid = "\t\tInvalid Value.";

            List<int> expenseIdList = new List<int>();
            List<GeneralExpense> expenseList = em.GetListGeneralExpense();
            List<Bill> billList = em.GetListBill();

            // Get Expenses
            Console.WriteLine("Expenses:");
            foreach (GeneralExpense expense in expenseList)
            {
                Console.WriteLine(expense.GetShortDetails());
                expenseIdList.Add(expense.Id);
            }

            // Get Bills
            Console.WriteLine();
            Console.WriteLine("Bills:");
            foreach (Bill bill in billList)
            {
                Console.WriteLine(bill.GetShortDetails());
                expenseIdList.Add(bill.Id);
            }
            Console.WriteLine();

            // Get Expense Id
            while (!isValid)
            {
                Console.Write("Expense Id: ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    Console.WriteLine(invalid);
                    Console.ReadLine();
                }
                else
                {
                    if (input.Equals(_cancelChar))
                        return;
                    if (int.TryParse(input, out dExpenseId))
                    {
                        if (expenseIdList.Contains(dExpenseId))
                        {
                            isValid = true;
                        }
                        else
                        {
                            Console.WriteLine("\t\tNot a valid expense id.");
                            Console.ReadLine();
                        }
                    }
                    else
                    {
                        Console.WriteLine(invalid);
                        Console.ReadLine();
                    }
                }
            }

            isValid = false;

            // Get Person Owing
            while (!isValid)
            {
                Console.Write("Person Owing: ");
                dPersonOwing = Console.ReadLine();
                if (string.IsNullOrEmpty(dPersonOwing))
                {
                    Console.WriteLine(invalid);
                    Console.ReadLine();
                }
                else
                {
                    if (dPersonOwing.Equals(_cancelChar))
                        return;
                    isValid = true;
                }
            }

            isValid = false;
            input = string.Empty;

            // Get Amount
            while (!isValid)
            {
                Console.Write("Amount: ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    Console.WriteLine(invalid);
                    Console.ReadLine();
                }
                else
                {
                    if (input.Equals(_cancelChar))
                        return;
                    if (double.TryParse(input, out dAmountOutstanding))
                    {
                        isValid = true;
                    }
                    else
                    {
                        Console.WriteLine(invalid);
                        Console.ReadLine();
                    }
                }
            }

            isValid = false;
            input = string.Empty;

            // Is Paid
            while (!isValid)
            {
                Console.Write("Is Debt Paid (Y/N): ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    Console.WriteLine(invalid);
                    Console.ReadLine();
                }
                else
                {
                    switch (input.ToUpper())
                    {
                        case "Y":
                            if (input.Equals(_cancelChar))
                                return;
                            isValid = true;
                            dIsPaid = true;
                            break;
                        case "N":
                            if (input.Equals(_cancelChar))
                                return;
                            isValid = true;
                            dIsPaid = false;
                            break;
                        default:
                            Console.WriteLine(invalid);
                            Console.ReadLine();
                            break;
                    }
                }
            }

            isValid = false;
            input = string.Empty;

            if (dIsPaid)
            {
                // Date paid
                while (!isValid)
                {
                    Console.Write("Date Paid: ");
                    input = Console.ReadLine();
                    if (string.IsNullOrEmpty(input))
                    {
                        Console.WriteLine(invalid);
                        Console.ReadLine();
                    }
                    else
                    {
                        if (input.Equals(_cancelChar))
                            return;
                        if (DateTime.TryParse(input, out dDatePaid))
                        {
                            isValid = true;
                        }
                        else
                        {
                            Console.WriteLine(invalid);
                            Console.ReadLine();
                        }
                    }
                }
            }
            else
            {
                dDatePaid = new DateTime(9999, 01, 01);
            }

            debt.ExpenseId = dExpenseId;
            debt.PersonOwing = dPersonOwing;
            debt.AmountOutstanding = dAmountOutstanding;
            debt.IsPaid = dIsPaid;
            debt.DatePaid = dDatePaid;

            AddDebt addDebt = new AddDebt(em);
            addDebt.InsertValues(debt);
        }