private void Edit_Expense(object sender, MouseButtonEventArgs e) { DataGrid dg = sender as DataGrid; SessionsGrid p = (SessionsGrid)dg.SelectedItems[0]; // OR: Patient p = (Patient)dg.SelectedItem; UpdateSession up = new UpdateSession(p); up.ShowDialog(); // Refresh the grid Refresh_SessionsGrid(sender, e); }
public UpdateSession(SessionsGrid sg) { try { Session = sg; // Initialize the variables and such staffFirstName = sg.StaffFirstName; staffLastName = sg.StaffLastName; clientFirstName = sg.ClientFirstName; clientLastName = sg.ClientLastName; appointmentStart = sg.AppointmentStart; appointmentEnd = sg.AppointmentEnd; expenseDueDate = sg.ExpenseDueDate; expensePaidDate = sg.ExpensePaidDate; donorBill = sg.DonorBill; patientBill = sg.PatientBill; totalExpense = sg.TotalExpense; expenseType = sg.ExpenseType; expenseDescription = sg.ExpenseDescription; expenseID = sg.ExpenseID; cancellationType = sg.CancellationType; oldDonorBill = donorBill; newDonorBill = donorBill; // Initialize the UI InitializeComponent(); // Disable the patient's first and last name fields FN.IsEnabled = false; LN.IsEnabled = false; // Select the appointment type ApptType.SelectedItem = sg.ExpenseType; // Fill out the information in the form FN.Text = sg.ClientFirstName; LN.Text = sg.ClientLastName; Copay.Text = Math.Round(sg.PatientBill, 2).ToString(); Deduction.Text = Math.Round(sg.DonorBill, 2).ToString(); Models.FCS_DBModel db = new Models.FCS_DBModel(); oldDonationID = (from d in db.Expenses where d.ExpenseID == expenseID select d.DonationID).Distinct().FirstOrDefault(); var oldDonation = (from d in db.Donations where d.DonationID == oldDonationID select d).FirstOrDefault(); // If there is a grant if (oldDonation != null) { if (oldDonation.GrantProposalID != null) { MoneyDonation.Visibility = Visibility.Hidden; var oldGrantName = (from d in db.GrantProposals where d.GrantProposalID == oldDonation.GrantProposalID select d.GrantName).Distinct().FirstOrDefault(); DonorDeduction.IsChecked = true; Grant.SelectedItem = oldGrantName; } // If it is a money donation else { // UI Updates for the money donation DonorDeduction.IsChecked = false; Grant.Visibility = Visibility.Hidden; // Get the money donation var oldDonorType = (from d in db.Donors where d.DonorID == oldDonation.DonorID select d.DonorType).Distinct().FirstOrDefault(); if (oldDonorType == "Organization" || oldDonorType == "Government") { MoneyDonation.SelectedItem = (from d in db.Donations join dn in db.Donors on d.DonorID equals dn.DonorID where d.DonationID == oldDonationID && dn.DonorID == oldDonation.DonorID select d.DonationID.ToString() + ", " + dn.OrganizationName + ", " + d.DonationAmountRemaining.ToString()).Distinct().FirstOrDefault(); } else if (oldDonorType == "Anonymous" || oldDonorType == "Individual") { MoneyDonation.SelectedItem = (from d in db.Donations join dn in db.Donors on d.DonorID equals dn.DonorID join c in db.DonorContacts on dn.DonorID equals c.DonorID where d.DonationID == oldDonationID && dn.DonorID == oldDonation.DonorID select d.DonationID + ", " + d.DonationAmountRemaining + ", " + c.ContactFirstName + ", " + c.ContactLastName).Distinct().FirstOrDefault(); } } } else { // Hide grant stuffz for consistency DonorDeduction.IsChecked = false; Grant.Visibility = Visibility.Hidden; } Staff.SelectedItem = (from o in db.Staff where o.StaffFirstName == staffFirstName && o.StaffLastName == staffLastName select o.StaffFirstName + " " + o.StaffLastName + ", " + o.StaffUserName).Distinct().FirstOrDefault(); // If the patient's due is paid if (expensePaidDate != null) { IsPaid.IsChecked = true; ExpensePaidDate.IsEnabled = true; ExpensePaidDate.Text = sg.ExpensePaidDate.ToString(); } // Set the date stuff DateRecieved.Text = sg.AppointmentStart.ToString(); // Start Hour Stuff if (sg.AppointmentStart.Hour >= 12) { if (sg.AppointmentStart.Hour % 12 != 0) { StartHour.Text = (sg.AppointmentStart.Hour - 12).ToString(); } else { StartHour.Text = sg.AppointmentStart.Hour.ToString(); } AMPM_Start.SelectedItem = "PM"; } else { if (sg.AppointmentStart.Hour == 0) { StartHour.Text = (sg.AppointmentStart.Hour + 12).ToString(); } else { StartHour.Text = sg.AppointmentStart.Hour.ToString(); } AMPM_Start.SelectedItem = "AM"; } // End Hour Stuff if (sg.AppointmentEnd.Hour >= 12) { if (sg.AppointmentEnd.Hour % 12 != 0) { End_Hour.Text = (sg.AppointmentEnd.Hour - 12).ToString(); } else { End_Hour.Text = sg.AppointmentEnd.Hour.ToString(); } AMPM_End.SelectedItem = "PM"; } else { if (sg.AppointmentEnd.Hour == 0) { End_Hour.Text = (sg.AppointmentEnd.Hour + 12).ToString(); } else { End_Hour.Text = sg.AppointmentEnd.Hour.ToString(); } AMPM_End.SelectedItem = "AM"; } // Setting the minutes StartMinute.Text = DisplayMinuteConversion(sg.AppointmentStart.Minute.ToString()); End_Minute.Text = DisplayMinuteConversion(sg.AppointmentEnd.Minute.ToString()); // Setting the cancellation type switch (sg.CancellationType) { case "Not Cxl": CancellationType.SelectedIndex = 0; break; case "No Show": CancellationType.SelectedIndex = 1; break; case "Late Cxl": CancellationType.SelectedIndex = 2; break; case "Cxl": CancellationType.SelectedIndex = 3; break; default: CancellationType.SelectedIndex = 0; break; } } catch (Exception error) { MessageBox.Show("Something went wrong, please try again."); } }