private void Update_InKind_Service(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(); } 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); decimal timeDiff = (decimal)(endDateTime - startDateTime).TotalHours; try { Models.FCS_DBModel db = new Models.FCS_DBModel(); var inkindservice = (from p in db.In_Kind_Service where p.ServiceID == ServiceID select p).FirstOrDefault(); inkindservice.ServiceDescription = ServiceDescription; inkindservice.RatePerHour = RatePerHour; inkindservice.StartDateTime = startDateTime; inkindservice.EndDateTime = endDateTime; inkindservice.ServiceValue = Math.Round(RatePerHour * timeDiff, 2); inkindservice.ServiceLength = (double)Math.Round(timeDiff, 2); var donation2 = (from d in db.Donations where d.DonationID == DonationID select d).FirstOrDefault(); donation2.DonationDate = Convert.ToDateTime(DateRecieved.ToString()); db.SaveChanges(); this.Close(); } catch { MessageBox.Show("Please check the data entered."); } }
private void Add_Event(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 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); decimal timeDiff = (decimal)(endDateTime - startDateTime).TotalHours; if (EventName != null && EventName != "" && timeDiff > 0) { Models.FCS_DBModel db = new Models.FCS_DBModel(); //MessageBox.Show(EventName + "\n" + EventDescription + "\n" + startDateTime + "\n" + endDateTime + "\n" + timeDiff ); Models.FundRaisingEvent event1 = new Models.FundRaisingEvent(); event1.EventStartDateTime = startDateTime; event1.EventEndDateTime = endDateTime; event1.EventName = EventName; event1.EventDescription = EventDescription; db.FundRaisingEvents.Add(event1); db.SaveChanges(); this.Close(); } else { MessageBox.Show("Please check the data entered."); } } catch (Exception ex) { MessageBox.Show("Please check the data entered."); } }
private void Update_InKind_Item(object sender, RoutedEventArgs e) { Models.FCS_DBModel db = new Models.FCS_DBModel(); var inkinditem = (from p in db.In_Kind_Item where p.ItemID == ItemID select p).First(); inkinditem.ItemName = ItemName; inkinditem.ItemDescription = ItemDescription; var donation = (from d in db.Donations where d.DonationID == DonationID select d).First(); donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString()); db.SaveChanges(); this.Close(); }
private void Add_InKind_Service(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 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); decimal timeDiff = (decimal)(endDateTime - startDateTime).TotalHours; if (ServiceDescription != null && ServiceDescription != "" && RatePerHour > 0 && timeDiff > 0 && Individual.SelectedIndex != -1) { string[] separators = new string[] { ", " }; string Indiv = Individual.SelectedValue.ToString(); Models.FCS_DBModel db = new Models.FCS_DBModel(); //MessageBox.Show(ServiceDescription + "\n" + RatePerHour + "\n" + startDateTime + "\n" + endDateTime + "\n" + timeDiff + "\n" + Indiv); string[] words = Indiv.Split(separators, StringSplitOptions.None); string FName = words[0]; string LName = words[1]; string FNumber = words[2]; var donorID = (from dc in db.DonorContacts join d in db.Donors on dc.DonorID equals d.DonorID where dc.ContactFirstName == FName && dc.ContactLastName == LName && dc.ContactPhone == FNumber && (d.DonorType == "Individual" || d.DonorType == "Anonymous") select dc.DonorID).Distinct().FirstOrDefault(); if (IsEvent) { Models.Donation donation = new Models.Donation(); donation.DonorID = donorID; donation.Restricted = false; donation.InKind = true; donation.DonationAmount = 0M; donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString()); donation.EventID = EventID; db.Donations.Add(donation); db.SaveChanges(); Models.In_Kind_Service inKind = new Models.In_Kind_Service(); inKind.DonationID = donation.DonationID; inKind.StartDateTime = startDateTime; inKind.EndDateTime = endDateTime; inKind.RatePerHour = RatePerHour; inKind.ServiceDescription = ServiceDescription; inKind.ServiceLength = (double)timeDiff; inKind.ServiceValue = RatePerHour * timeDiff; db.In_Kind_Service.Add(inKind); db.SaveChanges(); } else { Models.Donation donation = new Models.Donation(); donation.DonorID = donorID; donation.InKind = false; donation.Restricted = true; donation.DonationAmount = 0M; donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString()); db.Donations.Add(donation); db.SaveChanges(); Models.In_Kind_Service inKind = new Models.In_Kind_Service(); inKind.DonationID = donation.DonationID; inKind.StartDateTime = startDateTime; inKind.EndDateTime = endDateTime; inKind.RatePerHour = RatePerHour; inKind.ServiceDescription = ServiceDescription; inKind.ServiceLength = (double)timeDiff; inKind.ServiceValue = RatePerHour * timeDiff; db.In_Kind_Service.Add(inKind); db.SaveChanges(); } this.Close(); } else { MessageBox.Show("Please check the data entered."); } } catch (Exception ex) { MessageBox.Show("Please check the data entered."); } }
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 Add_InKind_Item(object sender, RoutedEventArgs e) { if (ItemName != null && ItemName != "" && ItemDescription != null && ItemDescription != "" && DateRecieved.ToString() != null && DateRecieved.ToString() != "") { Models.FCS_DBModel db = new Models.FCS_DBModel(); //Then its an organization if (OrgOrIndividual.IsChecked.Value && Organization.SelectedIndex != -1) { string Organiz = Organization.SelectedValue.ToString(); //MessageBox.Show(ItemName + "\n" + ItemDescription + "\n" + DateRecieved + "\n" + Organiz + "\n" + "You got HERE"); var donorID = (from d in db.Donors where d.OrganizationName == Organiz select d.DonorID).Distinct().First(); //MessageBox.Show(donorID.ToString()); if (IsEvent) { Models.Donation donation = new Models.Donation(); donation.DonorID = donorID; donation.Restricted = false; donation.InKind = true; donation.DonationAmount = 0M; donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString()); donation.EventID = EventID; db.Donations.Add(donation); db.SaveChanges(); Models.In_Kind_Item inKind = new Models.In_Kind_Item(); inKind.DonationID = donation.DonationID; inKind.ItemName = ItemName; inKind.ItemDescription = ItemDescription; db.In_Kind_Item.Add(inKind); db.SaveChanges(); } else { Models.Donation donation = new Models.Donation(); donation.DonorID = donorID; donation.Restricted = false; donation.InKind = true; donation.DonationAmount = 0M; donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString()); db.Donations.Add(donation); db.SaveChanges(); Models.In_Kind_Item inKind = new Models.In_Kind_Item(); inKind.DonationID = donation.DonationID; inKind.ItemName = ItemName; inKind.ItemDescription = ItemDescription; db.In_Kind_Item.Add(inKind); db.SaveChanges(); } } //then its an individual else if (Individual.SelectedIndex != -1) { string[] separators = new string[] { ", " }; string Indiv = Individual.SelectedValue.ToString(); //MessageBox.Show(ItemName + "\n" + ItemDescription + "\n" + DateRecieved + "\n" + Indiv); string[] words = Indiv.Split(separators, StringSplitOptions.None); string FName = words[0]; string LName = words[1]; string FNumber = words[2]; var donorID = (from dc in db.DonorContacts join d in db.Donors on dc.DonorID equals d.DonorID where dc.ContactFirstName == FName && dc.ContactLastName == LName && dc.ContactPhone == FNumber && (d.DonorType == "Individual" || d.DonorType == "Anonymous") select dc.DonorID).Distinct().FirstOrDefault(); if (IsEvent) { Models.Donation donation = new Models.Donation(); donation.DonorID = donorID; donation.Restricted = false; donation.InKind = true; donation.DonationAmount = 0M; donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString()); donation.EventID = EventID; db.Donations.Add(donation); db.SaveChanges(); Models.In_Kind_Item inKind = new Models.In_Kind_Item(); inKind.DonationID = donation.DonationID; inKind.ItemName = ItemName; inKind.ItemDescription = ItemDescription; db.In_Kind_Item.Add(inKind); db.SaveChanges(); } else { Models.Donation donation = new Models.Donation(); donation.DonorID = donorID; donation.Restricted = false; donation.InKind = true; donation.DonationAmount = 0M; donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString()); db.Donations.Add(donation); db.SaveChanges(); Models.In_Kind_Item inKind = new Models.In_Kind_Item(); inKind.DonationID = donation.DonationID; inKind.ItemName = ItemName; inKind.ItemDescription = ItemDescription; db.In_Kind_Item.Add(inKind); db.SaveChanges(); } } else { MessageBox.Show("Make sure to select an organization or an individual"); return; } this.Close(); } //add both patient and household else { MessageBox.Show("Make sure the data is correct."); } }
private void Select_AppointmentType(object sender, RoutedEventArgs e) { try { 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 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); DateTime expenseDueDate = startDateTime.AddDays(30); string[] separators = new string[] { ", " }; string staff = Staff.SelectedValue.ToString(); string cancellationType = "Not Cxl"; switch (CancellationType.SelectedIndex) { case 0: cancellationType = "Not Cxl"; break; case 1: cancellationType = "No Show"; break; case 2: cancellationType = "Late Cxl"; break; case 3: cancellationType = "Cxl"; break; default: cancellationType = "Not Cxl"; break; } Models.FCS_DBModel db = new Models.FCS_DBModel(); string[] words = staff.Split(separators, StringSplitOptions.None); string FName = words[0]; string LName = words[1]; string usertitle = words[2]; string username = words[3]; var staffID = (from dc in db.Staff where dc.StaffFirstName == FName && dc.StaffLastName == LName && dc.StaffUserName == username select dc.StaffID).Distinct().FirstOrDefault(); if (TotalGroup.Count == 0) { MessageBox.Show("Please add at least one client."); return; } if (TotalGroup.Count > 1 && (String)ApptType.SelectedItem == "Individual") { MessageBox.Show("Individual appointment may only have one client."); return; } //individual (1st option) (ExpenseTypeID = 1 in database) //group (3rd option) (ExpenseTypeID = 2 in database) if (ApptType.SelectedIndex == 0 || ApptType.SelectedIndex == 2) { if (ApptType.SelectedIndex == 0) { ExpenseTypeID = 1; } else { ExpenseTypeID = 2; } Models.Appointment a = new Models.Appointment(); a.StaffID = staffID; a.AppointmentStartDate = startDateTime; a.AppointmentEndDate = endDateTime; a.AppointmentCancelationType = cancellationType; db.Appointments.Add(a); db.SaveChanges(); foreach (var item in TotalGroup) { AddGroupSession ags = new AddGroupSession(ExpenseTypeID, item, staffID, expenseDueDate, startDateTime, endDateTime, a.AppointmentID); ags.ShowDialog(); ags.ExpensePaidDate.IsEnabled = false; ags.FN.IsEnabled = false; ags.LN.IsEnabled = false; ags.OQ.IsEnabled = false; ags.MoneyDonation.IsEnabled = true; ags.Grant.IsEnabled = false; } this.Close(); } //family (2nd option) (ExpenseTypeID = 3 in database) else if (ApptType.SelectedIndex == 1) { ExpenseTypeID = 3; foreach (var item in TotalGroup) { Models.Appointment a = new Models.Appointment(); a.StaffID = staffID; a.AppointmentStartDate = startDateTime; a.AppointmentEndDate = endDateTime; a.AppointmentCancelationType = cancellationType; db.Appointments.Add(a); db.SaveChanges(); AddGroupSession ags = new AddGroupSession(ExpenseTypeID, item, staffID, expenseDueDate, startDateTime, endDateTime, a.AppointmentID); ags.Show(); ags.ExpensePaidDate.IsEnabled = false; ags.FN.IsEnabled = false; ags.LN.IsEnabled = false; ags.OQ.IsEnabled = false; ags.MoneyDonation.IsEnabled = true; ags.Grant.IsEnabled = false; } this.Close(); } } catch { if (GroupGrid.Items.Count == 0) { MessageBox.Show("Please select atleast one client prior to clicking on Select Appointment Type"); } else if (Staff.SelectedIndex == -1) { MessageBox.Show("Please select a Therapist prior to clicking Select on Appointment Type"); } else if (DateRecieved.Text.Equals("") || DateRecieved == null) { MessageBox.Show("Please select a Date prior to clicking Select Appointment Type"); } else { MessageBox.Show("Something went wrong. Please check the fields and try again."); } } }
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."); } }