private void Add_Contact(object sender, RoutedEventArgs e) { if(ContactFirstName != null && ContactFirstName != "" && ContactLastName != null && ContactLastName != "") { FCS_DBModel db = new FCS_DBModel(); DonorContact d = new DonorContact(); d.ContactFirstName = ContactFirstName; d.ContactLastName = ContactLastName; d.ContactPhone = ContactPhone; d.ContactEmail = ContactEmail; d.DonorID = DonorID; db.DonorContacts.Add(d); if (ContactPhone.Length < 11) { db.SaveChanges(); this.Close(); } else { MessageBox.Show("The phone number entered is invalid."); } } //add both patient and household else { MessageBox.Show("Please check the data entered."); } }
private void DeleteDonation(object sender, RoutedEventArgs e) { System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Delete this Donation?", "Confirmation", System.Windows.Forms.MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.Yes) { FCS_Funding.Models.FCS_DBModel db = new FCS_Funding.Models.FCS_DBModel(); DeletePurposes delPurp = new DeletePurposes(); delPurp.deletePurpose(DonationID); //var purpose = (from p in db.Purposes // where p.PurposeID == PurposeID // select p).First(); var donation = (from d in db.Donations where d.DonationID == DonationID select d).First(); //db.Purposes.Remove(purpose); db.Donations.Remove(donation); db.SaveChanges(); MessageBox.Show("Donation Deleted."); this.Close(); } }
private void Add_Client(object sender, RoutedEventArgs e) { Patient tempPatient = new Patient(); Problem tempProblem = new Problem(); FCS_DBModel db = new FCS_DBModel(); Determine_AgeGroup(combobox_AgeGroup.SelectedIndex); Determine_EthnicGroup(combobox_ethnicity.SelectedIndex); Determine_Gender(combobox_Gender.SelectedIndex); var togglePatientProblems = PatientProblemsCheckBoxes.Children; try { // Check to see if there needs to be a new household made first if ((bool)check_FirstHouseholdMember.IsChecked) { Determine_Income(combobox_IncomeBracket.SelectedIndex); Determine_County(combobox_County.SelectedIndex); PatientHousehold household = new PatientHousehold(); household.HouseholdCounty = County; household.HouseholdIncomeBracket = Income; household.HouseholdPopulation = HouseholdPopulation; db.PatientHouseholds.Add(household); db.SaveChanges(); tempPatient.HouseholdID = household.HouseholdID; } else { tempPatient.HouseholdID = db.Patients.Where(x => x.PatientOQ == familyOQNumber).Select(x => x.HouseholdID).Distinct().First(); } bool isHeadOfHouse = (bool)check_HeadOfHousehold.IsChecked; tempPatient.PatientOQ = patientOQ; tempPatient.PatientFirstName = firstName; tempPatient.PatientLastName = lastName; tempPatient.PatientAgeGroup = ageGroup; tempPatient.PatientEthnicity = ethnicGroup; tempPatient.PatientGender = PatientGender; tempPatient.NewClientIntakeHour = DateTime.Now; tempPatient.IsHead = headOfHouse; tempPatient.RelationToHead = (headOfHouse) ? "Head" : relationToHead; db.Patients.Add(tempPatient); db.SaveChanges(); Determine_Problems(patientOQ, togglePatientProblems); this.Close(); } catch (Exception error) { MessageBox.Show("Something went wrong, please double check your entry values.\n\n"); MessageBox.Show("Error: " + error.ToString()); } }
private void Add_Contact(object sender, RoutedEventArgs e) { try { if (DonorFirstName != null && DonorFirstName != "" && DonorLastName != null && DonorLastName != "" && ContactPhone != null && ContactPhone != "" && ContactEmail != null && ContactEmail != "") { FCS_DBModel db = new FCS_DBModel(); //MessageBox.Show(DonorFirstName + "\n" + DonorLastName + "\n" + ContactPhone + "\n" + ContactEmail + "\n" + DonorAddress1 + "\n" + DonorAddress2 // + "\n" + DonorCity + "\n" + DonorState + "\n" + DonorZip + "\n" + DonorType + "\n" + OrganizationName); Donor d = new Donor(); DonorContact dc = new DonorContact(); d.DonorType = DonorType; d.OrganizationName = OrganizationName; d.DonorAddress1 = DonorAddress1; d.DonorAddress2 = DonorAddress2; d.DonorState = DonorState; d.DonorCity = DonorCity; d.DonorZip = DonorZip; db.Donors.Add(d); db.SaveChanges(); dc.ContactFirstName = DonorFirstName; dc.ContactLastName = DonorLastName; dc.ContactPhone = ContactPhone; dc.ContactEmail = ContactEmail; dc.DonorID = d.DonorID; db.DonorContacts.Add(dc); db.SaveChanges(); this.Close(); } else { MessageBox.Show("Add the correct fields."); } } catch(Exception ex) { MessageBox.Show("Make sure your phone number is 10 digits or less."); } }
public void deletePurpose(int DonationID) { FCS_DBModel db = new FCS_DBModel(); var donPurp = db.DonationPurposes.Where(x => x.DonationID == DonationID); if (donPurp != null) { foreach (var item in donPurp) { db.DonationPurposes.Remove(item); } db.SaveChanges(); } }
private void AddGrant(object sender, RoutedEventArgs e) { try { //MessageBox.Show(DonationAmount.ToString() + "\n" + DonationDate + "\n" + // PurposeName + "\n" + PurposeDescription); FCS_DBModel db = new FCS_DBModel(); Donation d = new Donation(); d.DonorID = DonorID; d.Restricted = false; d.InKind = false; d.DonationAmount = DonationAmount; d.DonationDate = Convert.ToDateTime(DonationDate.ToString()); d.DonationAmountRemaining = DonationAmount; d.GrantProposalID = GrantProposalID; db.Donations.Add(d); if (restrictedCheckBox.IsChecked == true) { Purpose p = new Purpose(); DonationPurpose dp = new DonationPurpose(); string purposeName = PurposeComboBox.SelectedValue.ToString(); int PurposeID = db.Purposes.Where(x => x.PurposeName == purposeName).Select(x => x.PurposeID).First(); d.Restricted = true; d.DonationExpirationDate = Convert.ToDateTime(DonationExpiration.ToString()); d.GrantProposalID = GrantProposalID; dp.DonationID = d.DonationID; dp.PurposeID = PurposeID; dp.DonationPurposeAmount = DonationAmount; db.DonationPurposes.Add(dp); db.Donations.Remove(d); db.Donations.Add(d); } db.SaveChanges(); this.Close(); } catch (Exception ex) { MessageBox.Show("Cannot add Grant" + "\n" + ex); } }
private void AddPurposeButton_Click(object sender, RoutedEventArgs e) { FCS_DBModel db = new FCS_DBModel(); Purpose purpose = db.Purposes.Create(); purpose.PurposeName = PurposeName.Text; purpose.PurposeDescription = PurposeDescription.Text; db.Purposes.Add(purpose); try { db.SaveChanges(); this.Close(); } catch { MessageBox.Show("Please make sure all fields are correct"); } }
private void button_DeletePatient_Click(object sender, RoutedEventArgs e) { try { string patientOQ = text_PatientOQ.Text; FCS_DBModel db = new FCS_DBModel(); int patID = db.Patients.Where(x => x.PatientOQ == patientOQ).Select(x => x.PatientID).Distinct().First(); var patient = (from p in db.Patients where p.PatientID == patID select p).First(); var patProblems = (from p in db.PatientProblems where p.PatientID == patID select p); db.Patients.Remove(patient); foreach (var item in patProblems) { db.PatientProblems.Remove(item); } db.SaveChanges(); } catch { } }
private void Update_Account(object sender, RoutedEventArgs e) { db = new FCS_DBModel(); try { string Role = UserRole.SelectedValue.ToString(); int usernameVerify = (from uv in db.Staff where uv.StaffUserName == UserName select uv).Count(); if (usernameVerify != 0 && UserName != helperUserName) { MessageBox.Show("The username selected is already taken"); } else { try { var staff = (from p in db.Staff where p.StaffID == StaffID select p).First(); staff.StaffFirstName = FirstName; staff.StaffLastName = LastName; staff.StaffTitle = StaffTitle; staff.StaffUserName = UserName; staff.StaffDBRole = Role; db.SaveChanges(); this.Close(); } catch { MessageBox.Show("Please check the data entered."); } } } catch { MessageBox.Show("Please check the data entered."); } }
private void Add_Household(object sender, RoutedEventArgs e) { Determine_County(this.HouseholdCounty.SelectedIndex); Determine_Income(this.HouseholdIncomeBracket.SelectedIndex); if (Income != null && HouseholdPopulation > 0 && County != null && County != "") { date = DateTime.Now; //MessageBox.Show(firstName + "\n" + lastName + "\n" + patientOQ + "\n" + gender + "\n" + headOfHouse + "\n" + ageGroup + "\n" + ethnicGroup // + "\n" + "\n" + date + "\n" + HouseholdPopulation + "\n" + County + "\n" + Income); FCS_DBModel db = new FCS_DBModel(); PatientHousehold p = new PatientHousehold(); p.HouseholdCounty = County; p.HouseholdPopulation = HouseholdPopulation; p.HouseholdIncomeBracket = Income; Patient pat = new Patient(); pat.PatientOQ = patientOQ; pat.HouseholdID = p.HouseholdID; pat.PatientFirstName = firstName; pat.PatientLastName = lastName; pat.PatientGender = gender; pat.PatientAgeGroup = ageGroup; pat.PatientEthnicity = ethnicGroup; pat.NewClientIntakeHour = date; pat.IsHead = headOfHouse; pat.RelationToHead = relationToHead; db.PatientHouseholds.Add(p); db.Patients.Add(pat); db.SaveChanges(); Determine_Problems(patientOQ, togglePatientProblems); MessageBox.Show("Successfully added Client and Household."); this.Close(); } //add both patient and household else { MessageBox.Show("Make sure to select an income, a household population, and input a county."); } }
private void UpdatePasword(object sender, RoutedEventArgs e) { db = new FCS_DBModel(); string password = Password.Password.ToString(); string verifiedPW = VerifyPassword.Password.ToString(); string hashedPassword = PasswordHashing.GetHashString(password); if (password.Length < 5) { MessageBox.Show("Please pick a longer password (Minimum length of 5)"); } else if (password != verifiedPW) { MessageBox.Show("Passwords do not match!"); } else { try { var staff = (from p in db.Staff where p.StaffID == StaffID select p).First(); staff.StaffPassword = hashedPassword; db.SaveChanges(); } catch { MessageBox.Show("Something went wrong. Please try again."); } this.Close(); } }
private void button_AddPatient_Click(object sender, RoutedEventArgs e) { try { Patient tempPatient = new Patient(); Problem tempProblem = new Problem(); FCS_DBModel db = new FCS_DBModel(); if ((bool)check_NewHousehold.IsChecked) { int HouseholdPopulation = int.Parse(text_HouseholdPop.Text); string Income = text_Income.Text; string County = text_county.Text; PatientHousehold household = new PatientHousehold(); household.HouseholdCounty = County; household.HouseholdIncomeBracket = Income; household.HouseholdPopulation = HouseholdPopulation; db.PatientHouseholds.Add(household); db.SaveChanges(); tempPatient.HouseholdID = household.HouseholdID; } else { tempPatient.HouseholdID = int.Parse(text_HouseholdID.Text); } tempPatient.PatientOQ = text_PatientOQ.Text; tempPatient.PatientAgeGroup = text_AgeGroup.Text; tempPatient.PatientEthnicity = text_Ethnicity.Text; tempPatient.PatientFirstName = text_FirstName.Text; tempPatient.PatientGender = text_Gender.Text; tempPatient.PatientLastName = text_LastName.Text; tempPatient.RelationToHead = text_RelationToHEad.Text; tempPatient.IsHead = (bool)check_IsHead.IsChecked; tempPatient.NewClientIntakeHour = DateTime.Now; db.Patients.Add(tempPatient); db.SaveChanges(); } catch (Exception error) { } }
private void Update_Grant(object sender, RoutedEventArgs e) { FCS_Funding.Models.FCS_DBModel db = new FCS_Funding.Models.FCS_DBModel(); //var purpose = (from p in db.Purposes // where p.PurposeID == PurposeID // select p).First(); //purpose.PurposeName = PurposeName; //purpose.PurposeDescription = PurposeDescription; var donation = (from d in db.Donations where d.DonationID == DonationID select d).First(); donation.DonationDate = Convert.ToDateTime(DonationDate.ToString()); if (DonationAmount - donation.DonationAmount < 0) { MessageBox.Show("This change would result in a\nnegative balance for this donation"); } else { if (restrictedCheckBox.IsChecked == true) { if (PurposeComboBox.Text != "" && PurposeComboBox.Text != null) { DeletePurposes delPurp = new DeletePurposes(); delPurp.deletePurpose(DonationID); Purpose p = new Purpose(); DonationPurpose dp = new DonationPurpose(); string purposeName = PurposeComboBox.SelectedItem.ToString(); int PurposeID = db.Purposes.Where(x => x.PurposeName == purposeName).Select(x => x.PurposeID).First(); donation.Restricted = true; if (DonationExpiration != null && DonationExpiration.ToString() != "") { donation.DonationExpirationDate = Convert.ToDateTime(DonationExpiration.ToString()); } else { donation.DonationExpirationDate = null; } dp.DonationID = donation.DonationID; dp.PurposeID = PurposeID; dp.DonationPurposeAmount = DonationAmount; db.DonationPurposes.Add(dp); decimal donationDiff = donation.DonationAmount - DonationAmount; donation.GrantProposalID = GrantProposalID; donation.DonationAmount = DonationAmount; donation.DonationAmountRemaining = donation.DonationAmountRemaining - donationDiff; db.Entry(donation); db.SaveChanges(); db.Entry(dp); db.SaveChanges(); } else { MessageBox.Show("Please enter a purpose if the donation is restrcted"); } } else { DeletePurposes delPurp = new DeletePurposes(); delPurp.deletePurpose(DonationID); donation.Restricted = false; donation.DonationExpirationDate = null; donation.GrantProposalID = GrantProposalID; decimal donationDiff = donation.DonationAmount - DonationAmount; donation.DonationAmount = DonationAmount; donation.DonationAmountRemaining = donation.DonationAmountRemaining - donationDiff; db.Entry(donation); db.SaveChanges(); } this.Close(); } }
private void UpdateProblems() { FCS_DBModel db = new FCS_DBModel(); int patID = db.Patients.Where(x => x.PatientOQ == pOQ).Select(x => x.PatientID).Distinct().First(); var toggle = PatientProblemsCheckBoxes.Children; var patProblems = (from p in db.PatientProblems where p.PatientID == patID select p); //CreateNewPatient cnp = new CreateNewPatient(); PatientProblem patProb = new PatientProblem(); string checkBoxContent = ""; int probID = 0; var problemTable = db.Problems; foreach (var item in toggle) { checkBoxContent = ((((ContentControl)item).Content).ToString()); //var distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID select p); if (((ToggleButton)item).IsChecked == true) { switch (checkBoxContent) { case "Depression": probID = 1; break; case "Bereavement/Loss": probID = 2; break; case "Communication": probID = 3; break; case "Domestic Violence": probID = 4; break; case "Hopelessness": probID = 5; break; case "Work Problems": probID = 6; break; case "Parent Problems": probID = 7; break; case "Substance Abuse": probID = 8; break; case "Problems w/ School": probID = 9; break; case "Marriage/Relationship/Family": probID = 10; break; case "Thoughts of Hurting Self": probID = 11; break; case "Angry Feelings": probID = 12; break; case "Sexual Abuse": probID = 13; break; case "Emotional Abuse": probID = 14; break; case "Physical Abuse": probID = 15; break; case "Problems with the Law": probID = 16; break; case "Unhappy with Life": probID = 17; break; case "Anxiety": probID = 18; break; case "Other": probID = 19; break; } patProb.PatientID = patID; patProb.ProblemID = probID; db.PatientProblems.Add(patProb); db.SaveChanges(); patProb = new PatientProblem(); } else { var distinctPatProblems = new List<PatientProblem>().AsQueryable(); switch (checkBoxContent) { case "Depression": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 1 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Bereavement/Loss": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 2 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Communication": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 3 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Domestic Violence": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 4 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Hopelessness": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 5 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Work Problems": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 6 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Parent Problems": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 7 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Substance Abuse": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 8 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Problems w/ School": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 9 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Marriage/Relationship/Family": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 10 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Thoughts of Hurting Self": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 11 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Angry Feelings": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 12 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Sexual Abuse": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 13 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Emotional Abuse": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 14 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Physical Abuse": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 15 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Problems with the Law": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 16 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Unhappy with Life": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 17 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Anxiety": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 18 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; case "Other": try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patID && p.ProblemID == 19 select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } db.SaveChanges(); } catch { } distinctPatProblems = new List<PatientProblem>().AsQueryable(); break; } } } GC.Collect(); }
private void Add_Client(object sender, RoutedEventArgs e) { Patient tempPatient = new Patient(); Problem tempProblem = new Problem(); FCS_DBModel db = new FCS_DBModel(); // Check to see if the OQ number is already taken try { string strPatientOQ = patientOQ.ToString(); string duplicateQO = db.Patients.Where(x => x.PatientOQ == patientOQ).Select(x => x.PatientOQ).Distinct().First(); if (!string.IsNullOrEmpty(duplicateQO)) { MessageBox.Show("The OQ Number is already taken, please enter a different OQ number."); return; } } catch { } ageGroup = combobox_AgeGroup.Text; ethnicGroup = combobox_ethnicity.Text; PatientGender = combobox_Gender.Text; try { // Check to see if there needs to be a new household made first if ((bool)check_FirstHouseholdMember.IsChecked) { Income = combobox_IncomeBracket.Text; County = combobox_County.Text; PatientHousehold household = new PatientHousehold(); household.HouseholdCounty = County; household.HouseholdIncomeBracket = Income; household.HouseholdPopulation = HouseholdPopulation; db.PatientHouseholds.Add(household); db.SaveChanges(); tempPatient.HouseholdID = household.HouseholdID; } else { try { tempPatient.HouseholdID = db.Patients.Where(x => x.PatientOQ == familyOQNumber).Select(x => x.HouseholdID).Distinct().First(); } catch (Exception error) { MessageBox.Show("The provided Family OQ Number does not exist. Please double-check the Family OQ Number.", "Family OQ Number Doesn't Exist", MessageBoxButton.OK, MessageBoxImage.Error); return; } } bool isHeadOfHouse = (bool)check_HeadOfHousehold.IsChecked; tempPatient.PatientOQ = patientOQ; tempPatient.PatientFirstName = firstName; tempPatient.PatientLastName = lastName; tempPatient.PatientAgeGroup = ageGroup; tempPatient.PatientEthnicity = ethnicGroup; tempPatient.PatientGender = PatientGender; DateTime ClientIntakeDateTime; bool result = DateTime.TryParse(date_ClientCreationDate.Text, out ClientIntakeDateTime); if (result == true) { tempPatient.NewClientIntakeHour = ClientIntakeDateTime; } else { MessageBox.Show("Please enter a valid Client Creation date"); return; } tempPatient.IsHead = headOfHouse; tempPatient.RelationToHead = (headOfHouse) ? "Head" : relationToHead; db.Patients.Add(tempPatient); db.SaveChanges(); Determine_Problems(patientOQ); this.Close(); } catch (Exception error) { MessageBox.Show("Something went wrong, please double check your entry values.\n\n"); MessageBox.Show("Error: " + error.ToString()); } }
private void CreateDonor(object sender, RoutedEventArgs e) { Determine_DonorType(this.dType.SelectedIndex); //DonorFirstName != null && DonorFirstName != "" && DonorLastName != null && DonorLastName != "" if (DonorType != null && DonorType != "") { FCS_DBModel db = new FCS_DBModel(); if (DonorType == "Organization" || DonorType == "Government" || DonorType == "Insurance") { var OrgName = from d in db.Donors where d.OrganizationName == OrganizationName select d; if (OrganizationName != null && OrganizationName != "") { //MessageBox.Show(DonorAddress1 + "\n" + DonorAddress2 + "\n" + DonorCity + "\n" + DonorState + "\n" + DonorZip // + "\n" + DonorType + "\n" + OrganizationName); Donor d = new Donor(); try { d.DonorState = DonorState; } catch { } try { d.DonorCity = DonorCity; } catch { } try { d.DonorZip = DonorZip; } catch { } try { d.DonorAddress2 = DonorAddress2; } catch { } try { d.DonorAddress1 = DonorAddress1; } catch { } d.DonorType = DonorType; d.OrganizationName = OrganizationName; db.Donors.Add(d); db.SaveChanges(); this.Close(); } else if (OrganizationName == null || OrganizationName == "") { MessageBox.Show("Make sure to add an Organization Name."); } else { MessageBox.Show("There is already an organization with the name selected. \nNote: Number the organizations if any organizations have the same name."); } } else if(DonorType == "Individual") { //MessageBox.Show(DonorAddress1 + "\n" + DonorAddress2 + "\n" + DonorCity + "\n" + DonorState + "\n" + DonorZip // + "\n" + DonorType + "\n" + OrganizationName); if(DonorZip == null) { DonorZip = ""; } if(DonorState == null) { DonorState = ""; } if(DonorZip.Length <= 5 && DonorState.Length <= 2) { Donor d = new Donor(); d.DonorType = DonorType; d.OrganizationName = OrganizationName; d.DonorAddress1 = DonorAddress1; d.DonorAddress2 = DonorAddress2; d.DonorState = DonorState; d.DonorCity = DonorCity; d.DonorZip = DonorZip; CreateIndividualContact cic = new CreateIndividualContact(d); this.Close(); cic.ShowDialog(); } else { MessageBox.Show("Make sure your state is two digits and your zip is 5 digits."); } } //its anonymous else if(DonorType == "Anonymous") { //"Anonymous" int anony = db.Donors.Where(x => x.DonorType == "Anonymous").Select(x => x.DonorType).Count(); //Distinct().First(); string Anon = "Anonymous"; if (anony < 1) { Donor d = new Donor(); d.DonorType = Anon; d.OrganizationName = Anon; d.DonorAddress1 = Anon; d.DonorAddress2 = Anon; d.DonorState = ""; d.DonorCity = Anon; d.DonorZip = ""; DonorContact dc = new DonorContact(); dc.ContactFirstName = Anon; dc.ContactLastName = Anon; dc.ContactPhone = Anon; dc.ContactEmail = Anon; dc.DonorID = d.DonorID; db.Donors.Add(d); db.DonorContacts.Add(dc); db.SaveChanges(); this.Close(); } else { MessageBox.Show("Anonymous donor already exists"); } } } //add both patient and household else { MessageBox.Show("Make sure to select Donor Type."); } }
private void Detete_Patient(object sender, RoutedEventArgs e) { System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Delete this Client?", "Confirmation" , System.Windows.Forms.MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.Yes) { FCS_DBModel db = new FCS_DBModel(); int patID = db.Patients.Where(x => x.PatientOQ == pOQ).Select(x => x.PatientID).Distinct().First(); var patient = (from p in db.Patients where p.PatientID == patID select p).First(); var patProblems = (from p in db.PatientProblems where p.PatientID == patID select p); db.Patients.Remove(patient); foreach (var item in patProblems) { db.PatientProblems.Remove(item); } db.SaveChanges(); MessageBox.Show("This client hass been deleted."); this.Close(); } }
private void Update_Client(object sender, RoutedEventArgs e) { FCS_DBModel db = new FCS_DBModel(); try { if ((bool)check_UpdateHousehold.IsChecked) { int householdID = db.Patients.Where(x => x.PatientOQ == patientOQ).Select(x => x.HouseholdID).Distinct().First(); var household = (from h in db.PatientHouseholds where h.HouseholdID == householdID select h).First(); County = combobox_County.Text; Income = combobox_IncomeBracket.Text; household.HouseholdCounty = County; household.HouseholdIncomeBracket = Income; household.HouseholdPopulation = HouseholdPopulation; db.SaveChanges(); } int patID = db.Patients.Where(x => x.PatientOQ == patientOQ).Select(x => x.PatientID).Distinct().First(); ageGroup = combobox_AgeGroup.Text; ethnicGroup = combobox_ethnicity.Text; PatientGender = combobox_Gender.Text; var patient = (from p in db.Patients where p.PatientID == patID select p).First(); if ((bool)check_ChangeHousehold.IsChecked) { string famPatientOQ = textbox_FamilyMemberOQ.Text; try { patient.HouseholdID = db.Patients.Where(x => x.PatientOQ == famPatientOQ).Select(x => x.HouseholdID).Distinct().First(); if (patient.HouseholdID == 0) { throw new Exception(); } } catch (Exception error) { MessageBox.Show("The provided Family OQ Number does not exist. Please double-check the Family OQ Number.", "Family OQ Number Doesn't Exist", MessageBoxButton.OK, MessageBoxImage.Error); return; } } try { patient.PatientOQ = patientOQ; patient.PatientFirstName = firstName; patient.PatientLastName = lastName; patient.RelationToHead = relationToHead; patient.PatientGender = PatientGender; patient.PatientAgeGroup = ageGroup; patient.PatientEthnicity = ethnicGroup; patient.NewClientIntakeHour = (System.DateTime)date_ClientCreationDate.SelectedDate; patient.IsHead = check_HeadOfHousehold.IsChecked.Value; UpdateProblems(); db.SaveChanges(); this.Close(); } catch (Exception error) { MessageBox.Show("Error: " + error.ToString()); } } catch { MessageBox.Show("Please make sure all fields are correct"); } }
private void Update_Patient(object sender, RoutedEventArgs e) { FCS_DBModel db = new FCS_DBModel(); try { int patID = db.Patients.Where(x => x.PatientOQ == pOQ).Select(x => x.PatientID).Distinct().First(); Determine_AgeGroup(this.AgeGroup.SelectedIndex); Determine_EthnicGroup(this.Ethnicity.SelectedIndex); Determine_Gender(this.Gender.SelectedIndex); var patient = (from p in db.Patients where p.PatientID == patID select p).First(); patient.PatientOQ = patientOQ; patient.PatientFirstName = firstName; patient.PatientLastName = lastName; patient.RelationToHead = relationToHead; patient.PatientGender = PatientGender; patient.PatientAgeGroup = ageGroup; patient.PatientEthnicity = ethnicGroup; patient.IsHead = TheHead.IsChecked.Value; UpdateProblems(); db.SaveChanges(); MessageBox.Show("Successfully Updated Client"); this.Close(); } catch { MessageBox.Show("Please make sure all fields are correct"); } //int householdID = db.Patients.Where(x => x.PatientOQ == patientOQ).Select(x => x.HouseholdID).Distinct().First(); //FCS_Funding.Models.Patient update = new FCS_Funding.Models.Patient(patientOQ, householdID, firstName, lastName, PatientGender, // ageGroup, ethnicGroup, date, TheHead.IsChecked.Value, relationToHead); //db.Patients.Attach(update); //var entry = db.Entry(update); }
public void Determine_Problems(string OQ) { FCS_DBModel db = new FCS_DBModel(); var toggle = PatientProblemsCheckBoxes.Children; var problemTable = db.Problems; foreach (var item in toggle) { string checkboxProblemName = (((ContentControl)item).Content).ToString(); if (((ToggleButton)item).IsChecked == true) { try { PatientProblem patProb = new PatientProblem(); int patID = db.Patients.Where(x => x.PatientOQ == OQ).Select(x => x.PatientID).Distinct().First(); patProb.PatientID = patID; patProb.ProblemID = GetProblemID(checkboxProblemName); db.PatientProblems.Add(patProb); db.SaveChanges(); //var problem = } catch (Exception error) { } } } }
private void Delete_Grant(object sender, RoutedEventArgs e) { FCS_DBModel db = new FCS_DBModel(); System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Delete this Grant?", "Confirmation", System.Windows.Forms.MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.Yes) { var donationPurposes = (from p in db.DonationPurposes where p.PurposeID == PurposeID select p); DeletePurposes delPurp = new DeletePurposes(); delPurp.deletePurpose(DonationID); } //var purpose = (from p in db.Purposes // where p.PurposeID == PurposeID // select p).First(); var donation = (from d in db.Donations where d.DonationID == DonationID select d).First(); //try { // var donationPurpose = (from dp in db.DonationPurposes // where dp.DonationID == donation.DonationID // select dp); // foreach (var item in donationPurpose) // { // db.DonationPurposes.Remove(item); // db.SaveChanges(); // } //} //catch //{ //} var grantProposal = (from d in db.GrantProposals where d.GrantProposalID == GrantProposalID select d).First(); grantProposal.GrantStatus = "Pending"; db.Donations.Remove(donation); db.SaveChanges(); MessageBox.Show("This grant has been deleted and its associated proposal has been set to Pending."); this.Close(); }
private void UpdateProblems() { FCS_DBModel db = new FCS_DBModel(); var toggle = PatientProblemsCheckBoxes.Children; var problemTable = db.Problems; foreach (var item in toggle) { string checkboxProblemName = (((ContentControl)item).Content).ToString(); if (((ToggleButton)item).IsChecked == true) { PatientProblem patProb = new PatientProblem(); patProb.PatientID = patientID; patProb.ProblemID = GetProblemID(checkboxProblemName); db.PatientProblems.Add(patProb); db.SaveChanges(); } else { var distinctPatProblems = new List<PatientProblem>().AsQueryable(); try { distinctPatProblems = (from p in db.PatientProblems where p.PatientID == patientID && p.ProblemID == GetProblemID(checkboxProblemName) select p); foreach (var thing in distinctPatProblems) { db.PatientProblems.Remove(thing); } } catch { } db.SaveChanges(); } } GC.Collect(); }
public void Determine_Problems(string OQ, UIElementCollection toggle) { PatientProblem patProb = new PatientProblem(); FCS_DBModel db = new FCS_DBModel(); string checkBoxContent = ""; int probID = 0; var problemTable = db.Problems; foreach (var item in toggle) { if (((ToggleButton)item).IsChecked == true) { int patID = db.Patients.Where(x => x.PatientOQ == OQ).Select(x => x.PatientID).Distinct().First(); checkBoxContent = ((((ContentControl)item).Content).ToString()); switch (checkBoxContent) { case "Depression": probID = 1; break; case "Bereavement/Loss": probID = 2; break; case "Communication": probID = 3; break; case "Domestic Violence": probID = 4; break; case "Hopelessness": probID = 5; break; case "Work Problems": probID = 6; break; case "Parent Problems": probID = 7; break; case "Substance Abuse": probID = 8; break; case "Problems w/ School": probID = 9; break; case "Marriage/Relationship/Family": probID = 10; break; case "Thoughts of Hurting Self": probID = 11; break; case "Angry Feelings": probID = 12; break; case "Sexual Abuse": probID = 13; break; case "Emotional Abuse": probID = 14; break; case "Physical Abuse": probID = 15; break; case "Problems with the Law": probID = 16; break; case "Unhappy with Life": probID = 17; break; case "Anxiety": probID = 18; break; case "Other": probID = 19; break; } patProb.PatientID = patID; patProb.ProblemID = probID; db.PatientProblems.Add(patProb); db.SaveChanges(); } } }
private void button_DeleteHousehold_Click(object sender, RoutedEventArgs e) { try { int householdID = int.Parse(text_HouseholdID.Text); FCS_DBModel db = new FCS_DBModel(); var household = (from h in db.PatientHouseholds where h.HouseholdID == householdID select h).First(); db.PatientHouseholds.Remove(household); db.SaveChanges(); } catch { } }
private void AddGrant(object sender, RoutedEventArgs e) { try { FCS_DBModel db = new FCS_DBModel(); Donation d = new Donation(); if (IsEvent) { d.DonorID = DonorID; d.Restricted = false; d.InKind = false; d.DonationAmount = DonationAmount; d.DonationDate = Convert.ToDateTime(DonationDate.ToString()); d.EventID = EventID; d.DonationAmountRemaining = DonationAmount; db.Donations.Add(d); } else { d.DonorID = DonorID; d.Restricted = false; d.InKind = false; d.DonationAmount = DonationAmount; d.DonationDate = Convert.ToDateTime(DonationDate.ToString()); d.DonationAmountRemaining = DonationAmount; db.Donations.Add(d); } if (restrictedCheckBox.IsChecked == true) { Purpose p = new Purpose(); DonationPurpose dp = new DonationPurpose(); string purposeName = PurposeComboBox.SelectedItem.ToString(); int PurposeID = db.Purposes.Where(x => x.PurposeName == purposeName).Select(x => x.PurposeID).First(); d.Restricted = true; d.DonationExpirationDate = Convert.ToDateTime(DonationExpiration.ToString()); dp.DonationID = d.DonationID; dp.PurposeID = PurposeID; dp.DonationPurposeAmount = DonationAmount; db.DonationPurposes.Add(dp); db.Donations.Remove(d); db.Donations.Add(d); } db.SaveChanges(); this.Close(); } catch { MessageBox.Show("Make sure to input all the correct data."); } }
private void DeleteAccount(object sender, RoutedEventArgs e) { System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Delete this Account?", "Confirmation", System.Windows.Forms.MessageBoxButtons.YesNo); db = new FCS_DBModel(); var staff = (from s in db.Staff where s.StaffID == StaffID select s).First(); db.Staff.Remove(staff); db.SaveChanges(); this.Close(); }