public void AddNewGeneralExpense() { AddGeneralExpense addGeneralExpense = new AddGeneralExpense(this); }
private static void AddNewExpense(ExpenseManager inEM, bool isBill) { ExpenseManager em = inEM; GeneralExpense ge = new GeneralExpense(); string eName = string.Empty; string eDesc = string.Empty; double eValue = 0; DateTime eDateRec = new DateTime(9999, 01, 01); bool eIsPaid = false; DateTime eDatePaid = new DateTime(9999, 01, 01); bool eIsOutstanding = false; string input = string.Empty; bool isValid = false; string invalid = "\t\tInvalid Value."; // Get Name while (!isValid) { Console.Write("Name: "); eName = Console.ReadLine(); if (string.IsNullOrEmpty(eName)) { Console.WriteLine(invalid); Console.ReadLine(); } else { if (eName.Equals(_cancelChar)) return; isValid = true; } } isValid = false; // Get Desc while (!isValid) { Console.Write("Description: "); eDesc = Console.ReadLine(); if (string.IsNullOrEmpty(eDesc)) { Console.WriteLine(invalid); Console.ReadLine(); } else { if (eDesc.Equals(_cancelChar)) return; isValid = true; } } isValid = false; // Get value while (!isValid) { Console.Write("Value: "); input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { Console.WriteLine(invalid); Console.ReadLine(); } else { if (input.Equals(_cancelChar)) return; if (double.TryParse(input, out eValue)) { isValid = true; } else { Console.WriteLine(invalid); Console.ReadLine(); } } } isValid = false; input = string.Empty; // Date recieved while (!isValid) { Console.Write("Date Received: "); input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { Console.WriteLine(invalid); Console.ReadLine(); } else { if (input.Equals(_cancelChar)) return; if (DateTime.TryParse(input, out eDateRec)) { isValid = true; } else { Console.WriteLine(invalid); Console.ReadLine(); } } } isValid = false; input = string.Empty; // Get isPaid while (!isValid) { Console.Write("Has this expense been paid (Y/N): "); input = Console.ReadLine(); switch (input.ToUpper()) { case "Y": eIsPaid = true; isValid = true; break; case "N": eIsPaid = false; isValid = true; break; default: if (input.Equals(_cancelChar)) return; Console.WriteLine(invalid); Console.ReadLine(); break; } } isValid = false; input = string.Empty; if (eIsPaid) { // 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 eDatePaid)) { isValid = true; } else { Console.WriteLine(invalid); Console.ReadLine(); } } } } else { eDatePaid = new DateTime(9999, 01, 01); } isValid = false; input = string.Empty; // Get isOutstanding while (!isValid) { Console.Write("Is this expense outstanding (Y/N): "); input = Console.ReadLine(); switch (input.ToUpper()) { case "Y": eIsOutstanding = true; isValid = true; break; case "N": eIsOutstanding = false; isValid = true; break; default: if (input.Equals(_cancelChar)) return; Console.WriteLine(invalid); Console.ReadLine(); break; } } ge.Name = eName; ge.Description = eDesc; ge.Value = eValue; ge.DateReceived = eDateRec; ge.IsPaid = eIsPaid; ge.DatePaid = eDatePaid; ge.IsOutstanding = eIsOutstanding; if (isBill) { AddNewBill(em, ge); } else { AddGeneralExpense addExpense = new AddGeneralExpense(em); addExpense.InsertValues(ge); } }