private void Add_Expense(object sender, RoutedEventArgs e) { Models.FCS_DBModel db = new Models.FCS_DBModel(); try { //Taking the money from a grant if (DonorDeduction.IsChecked.Value) { string grant = Grant.SelectedValue.ToString(); var grantproposalID = (from g in db.GrantProposals where g.GrantName == grant select g.GrantProposalID).Distinct().FirstOrDefault(); var grantDonation = (from d in db.Donations where d.GrantProposalID == grantproposalID select d).First(); if (grantDonation.DonationAmountRemaining >= DonorBill) { Models.Expense expense = new Models.Expense(); var donationID = (from d in db.Donations where d.GrantProposalID == grantproposalID select d.DonationID).Distinct().FirstOrDefault(); expense.DonationID = donationID; expense.ExpenseTypeID = ExpenseTypeID; expense.PatientID = Individual.PatientID; expense.AppointmentID = AppointmentID; expense.ExpenseDueDate = ExpenseDueDate; expense.DonorBill = DonorBill; expense.PatientBill = PatientBill; expense.TotalExpenseAmount = DonorBill + PatientBill; if (IsPaid.IsChecked.Value == true) { expense.ExpensePaidDate = Convert.ToDateTime(ExpensePaidDate.ToString()); } db.Expenses.Add(expense); db.SaveChanges(); grantDonation.DonationAmountRemaining = grantDonation.DonationAmountRemaining - DonorBill; db.SaveChanges(); this.Close(); } else { MessageBox.Show("That grant does not have enough money."); } } //taking the money from a money donation. else { string[] separators = new string[] { ", " }; string Don = MoneyDonation.SelectedValue.ToString(); //MessageBox.Show(ItemName + "\n" + ItemDescription + "\n" + DateRecieved + "\n" + Indiv); string[] words = Don.Split(separators, StringSplitOptions.None); int donationID = Convert.ToInt32(words[0]); var donation = (from d in db.Donations where d.DonationID == donationID select d).First(); if (donation.DonationAmountRemaining >= DonorBill) { Models.Expense expense = new Models.Expense(); expense.ExpenseTypeID = ExpenseTypeID; expense.DonationID = donationID; expense.PatientID = Individual.PatientID; expense.AppointmentID = AppointmentID; expense.ExpenseDueDate = ExpenseDueDate; expense.DonorBill = DonorBill; expense.PatientBill = PatientBill; expense.TotalExpenseAmount = DonorBill + PatientBill; if (IsPaid.IsChecked.Value == true) { expense.ExpensePaidDate = Convert.ToDateTime(ExpensePaidDate.ToString()); } db.Expenses.Add(expense); db.SaveChanges(); var donor = (from d in db.Donors where d.DonorID == donation.DonorID select d).First(); if (donor.DonorType != "Insurance") { donation.DonationAmountRemaining = donation.DonationAmountRemaining - DonorBill; } db.SaveChanges(); this.Close(); } else { MessageBox.Show("That donation does not have enough money."); } } } catch { //MessageBox.Show(DonorBill.ToString()); if (DonorBill == 0) { try { Models.Expense expense = new Models.Expense(); expense.ExpenseTypeID = ExpenseTypeID; expense.PatientID = Individual.PatientID; expense.AppointmentID = AppointmentID; expense.ExpenseDueDate = ExpenseDueDate; expense.DonorBill = DonorBill; expense.PatientBill = PatientBill; expense.TotalExpenseAmount = DonorBill + PatientBill; if (IsPaid.IsChecked.Value == true) { expense.ExpensePaidDate = Convert.ToDateTime(ExpensePaidDate.ToString()); } db.Expenses.Add(expense); db.SaveChanges(); this.Close(); } catch (Exception exc) { MessageBox.Show("Please make sure all fields are correct: " + exc); } } else { MessageBox.Show("Make sure to select a grant"); } } }
private void Add_Appointment(object sender, RoutedEventArgs e) { if (AMPM_Start.SelectedValue.ToString() == "PM" && Convert.ToInt32(BeginHour) != 12) { BeginHour = (Convert.ToInt32(BeginHour) + 12).ToString(); } if (AMPM_End.SelectedValue.ToString() == "PM" && Convert.ToInt32(EndHour) != 12) { EndHour = (Convert.ToInt32(EndHour) + 12).ToString(); } if (AMPM_Start.SelectedValue.ToString() == "AM" && Convert.ToInt32(BeginHour) == 12) { BeginHour = (Convert.ToInt32(BeginHour) - 12).ToString(); } if (AMPM_End.SelectedValue.ToString() == "AM" && Convert.ToInt32(EndHour) == 12) { EndHour = (Convert.ToInt32(EndHour) - 12).ToString(); } try { DateTime expenseDueDate = Convert.ToDateTime(ExpenseDueDate.ToString()); DateTime help = Convert.ToDateTime(DateRecieved.ToString()); DateTime startDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(BeginHour), Convert.ToInt32(BeginMinute), 0); DateTime endDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(EndHour), Convert.ToInt32(EndMinute), 0); string[] separators = new string[] { ", " }; string staff = Staff.SelectedValue.ToString(); string grant = Grant.SelectedValue.ToString(); Models.FCS_DBModel db = new Models.FCS_DBModel(); //MessageBox.Show(PatientBill + "\n" + DonorBill + "\n" + startDateTime + "\n" + endDateTime + "\n" + expenseDueDate + "\n" + staff, grant); string[] words = staff.Split(separators, StringSplitOptions.None); string FName = words[0]; string LName = words[1]; string username = words[2]; var staffID = (from dc in db.Staff where dc.StaffFirstName == FName && dc.StaffLastName == LName && dc.StaffUserName == username select dc.StaffID).Distinct().FirstOrDefault(); var grantproposalID = (from g in db.GrantProposals where g.GrantName == grant select g.GrantProposalID).Distinct().FirstOrDefault(); var donationID = (from d in db.Donations where d.GrantProposalID == grantproposalID select d.DonationID).Distinct().FirstOrDefault(); var donation = (from d in db.Donations where d.GrantProposalID == grantproposalID select d).First(); if (donation.DonationAmountRemaining >= DonorBill) { Models.Appointment a = new Models.Appointment(); a.StaffID = staffID; a.AppointmentStartDate = startDateTime; a.AppointmentEndDate = endDateTime; db.Appointments.Add(a); db.SaveChanges(); Models.Expense expense = new Models.Expense(); expense.ExpenseTypeID = 1; expense.DonationID = donationID; expense.PatientID = PatientID; expense.AppointmentID = a.AppointmentID; expense.ExpenseDueDate = expenseDueDate; expense.DonorBill = DonorBill; expense.PatientBill = PatientBill; expense.TotalExpenseAmount = DonorBill + PatientBill; if (ExpensePaidDate.IsEnabled == true) { expense.ExpensePaidDate = Convert.ToDateTime(ExpensePaidDate.ToString()); } db.Expenses.Add(expense); db.SaveChanges(); donation.DonationAmountRemaining = donation.DonationAmountRemaining - DonorBill; db.SaveChanges(); this.Close(); } else { MessageBox.Show("This would result in a negative balance."); } } catch (Exception ex) { MessageBox.Show("Please check the data entered."); } }
private void Update_Expense(object sender, RoutedEventArgs e) { try { //Database for use throughout Update_Expense Models.FCS_DBModel db = new Models.FCS_DBModel(); //Update Appointment Type //individual (1st option) (ExpenseTypeID = 1 in database) //group (3rd option) (ExpenseTypeID = 2 in database) int newExpenseTypeID = 0; switch (ApptType.SelectedIndex) { case 0: newExpenseTypeID = 1; break; case 1: newExpenseTypeID = 3; break; case 2: newExpenseTypeID = 2; break; } if ((Grant.SelectedValue != null && (bool)DonorDeduction.IsChecked) || (MoneyDonation.SelectedValue != null && !(bool)DonorDeduction.IsChecked)) { //Update Donor/Insurance Deduction newDonorBill = Decimal.Parse(Deduction.Text); //Update Client Copay in Update All //Update Grant/MoneyDonation and Donation var oldDonation = (from d in db.Donations where d.DonationID == oldDonationID select d).FirstOrDefault(); var newDonationQuery = (from d in db.Donations select d); var expense = (from exp in db.Expenses where exp.ExpenseID == Session.ExpenseID select exp).FirstOrDefault(); if ((bool)DonorDeduction.IsChecked) { string newGrant = Grant.SelectedValue.ToString(); var newGrantproposalID = (from g in db.GrantProposals where g.GrantName == newGrant select g.GrantProposalID).Distinct().FirstOrDefault(); newDonationQuery = newDonationQuery.Where(x => x.GrantProposalID == newGrantproposalID); } else { string[] monDonSeparators = new string[] { ", " }; string monDon = MoneyDonation.SelectedValue.ToString(); //MessageBox.Show(ItemName + "\n" + ItemDescription + "\n" + DateRecieved + "\n" + Indiv); string[] monDonWords = monDon.Split(monDonSeparators, StringSplitOptions.None); int newDonationID = Convert.ToInt32(monDonWords[0]); newDonationQuery = newDonationQuery.Where(x => x.DonationID == newDonationID); } var newDonation = newDonationQuery.FirstOrDefault(); // If the new donation is different, check to see if the amount is enough decimal amountRemaining = 0; if (newDonation.DonationID != oldDonation.DonationID) { amountRemaining = newDonation.DonationAmountRemaining; } else { amountRemaining = newDonation.DonationAmountRemaining + oldDonorBill; } if (amountRemaining < newDonorBill) { MessageBox.Show("That donation does not have enough money."); return; } oldDonation.DonationAmountRemaining += oldDonorBill; newDonation.DonationAmountRemaining -= newDonorBill; expense.DonationID = newDonation.DonationID; } //Update Therapist string[] therSeparators = new string[] { ", ", " " }; string staff = Staff.SelectedValue.ToString(); string[] therWords = staff.Split(therSeparators, StringSplitOptions.None); string FName = therWords[0]; string LName = therWords[1]; string username = therWords[2]; var newStaffID = (from dc in db.Staff where dc.StaffFirstName == FName && dc.StaffLastName == LName && dc.StaffUserName == username select dc.StaffID).Distinct().FirstOrDefault(); //Update PaidBill and Date is done when everything is updated //Update Appointment Time and Date BeginHour = StartHour.Text; EndHour = End_Hour.Text; BeginMinute = StartMinute.Text; EndMinute = End_Minute.Text; if (AMPM_Start.SelectedValue.ToString() == "PM" && Convert.ToInt32(BeginHour) != 12) { BeginHour = (Convert.ToInt32(BeginHour) + 12).ToString(); } if (AMPM_End.SelectedValue.ToString() == "PM" && Convert.ToInt32(EndHour) != 12) { EndHour = (Convert.ToInt32(EndHour) + 12).ToString(); } if (AMPM_Start.SelectedValue.ToString() == "AM" && Convert.ToInt32(BeginHour) == 12) { BeginHour = (Convert.ToInt32(BeginHour) - 12).ToString(); } if (AMPM_End.SelectedValue.ToString() == "AM" && Convert.ToInt32(EndHour) == 12) { EndHour = (Convert.ToInt32(EndHour) - 12).ToString(); } DateTime help = Convert.ToDateTime(DateRecieved.ToString()); DateTime newStartDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(BeginHour), Convert.ToInt32(BeginMinute), 0); DateTime newEndDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(EndHour), Convert.ToInt32(EndMinute), 0); DateTime newExpenseDueDate = newStartDateTime.AddDays(30); //Update Cancellation Type string newCancellationType; switch (CancellationType.SelectedIndex) { case 0: newCancellationType = "Not Cxl"; break; case 1: newCancellationType = "No Show"; break; case 2: newCancellationType = "Late Cxl"; break; case 3: newCancellationType = "Cxl"; break; default: newCancellationType = "Not Cxl"; break; } //Update All Changes var newExpense = (from exp in db.Expenses where exp.ExpenseID == Session.ExpenseID select exp).First(); var newAppointmentID = newExpense.AppointmentID; newExpense.ExpenseTypeID = newExpenseTypeID; newExpense.ExpenseDueDate = newExpenseDueDate; decimal temp = 0; Decimal.TryParse(Copay.Text, out temp); newExpense.PatientBill = temp; decimal temp2 = 0; Decimal.TryParse(Deduction.Text, out temp2); newExpense.DonorBill = temp2; newExpense.TotalExpenseAmount = temp + temp2; if (IsPaid.IsChecked.Value == true) { newExpense.ExpensePaidDate = Convert.ToDateTime(ExpensePaidDate.ToString()); } else { newExpense.ExpensePaidDate = null; } var newAppointment = (from a in db.Appointments where a.AppointmentID == newAppointmentID select a).First(); newAppointment.StaffID = newStaffID; newAppointment.AppointmentStartDate = newStartDateTime; newAppointment.AppointmentEndDate = newEndDateTime; newAppointment.AppointmentCancelationType = newCancellationType; db.SaveChanges(); this.Close(); } catch (Exception error) { MessageBox.Show("Something went wrong. Please check the fields and try again."); } }