/// <summary> /// add the nanny that have enter /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddNannyButton_Click(object sender, RoutedEventArgs e) { if (errorMessages.Any()) //errorMessages.Count > 0 { string err = "Exception:"; foreach (var item in errorMessages) { err += "\n" + item; } System.Windows.MessageBox.Show(err); return; } try { nanny.Address = addressPlaceAutoCompleteUC.Text; bl.AddNanny(nanny); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); return; } this.Close(); }
private void addButton_Click(object sender, RoutedEventArgs e) { try { if (errorMessages.Any()) { string err = "Exception:"; foreach (var item in errorMessages) { err += "\n" + item; } MessageBox.Show(err); return; } else { nanny._NumberOfphone = this.numberFonComboBox.SelectedItem.ToString() + this.FonNannyTaxtBox.Text; nanny.workHours = this.userWorkHours.update(); bl.AddNanny(nanny); MessageBox.Show(bl.GetNannyList().LastOrDefault().ToString(), "This nanny has been added:"); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void AddNannyButton_Click(object sender, RoutedEventArgs e) { try { if (this.enanblePayForHourCheckBox.IsChecked == true && this.hourlyRateTextBox.Text == "") { throw new Exception("Must enter hourly rate"); } if (errorMessages.Any()) //errorMessages.Count > 0 { string err = "Exception:"; foreach (var item in errorMessages) { err += "\n" + item; } MessageBox.Show(err); return; } else { MessageBoxResult result = MessageBox.Show( "Are the details correct?\n\n" + nanny.ToString(), "Confirm Nanny Details", MessageBoxButton.OKCancel, MessageBoxImage.Information); if (result == MessageBoxResult.OK) { bl.AddNanny(nanny); MessageBox.Show( nanny.FirstName + " " + nanny.LastName + " was added successfully!\n" + nanny.ToString(), "Add New Nanny"); refreshData(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void addButton_Click(object sender, RoutedEventArgs e) { if (IsTimes(sunS.Text) || IsTimes(monS.Text) || IsTimes(tueS.Text) || IsTimes(wedS.Text) || IsTimes(thuS.Text) || IsTimes(friS.Text) || IsTimes(sunE.Text) || IsTimes(monE.Text) || IsTimes(sueE.Text) || IsTimes(wedE.Text) || IsTimes(thuE.Text) || IsTimes(friE.Text)) { MessageBox.Show("cannot add this nanny"); } else { contractNanny.Days = new bool[6]; for (int i = 0; i < 6; i++) { contractNanny.Times[i] = new string[2]; } if (chsun.IsChecked == true) { contractNanny.Days[0] = true; contractNanny.Times[0][0] = sunS.Text; contractNanny.Times[0][1] = sunE.Text; } else { contractNanny.Days[0] = false; contractNanny.Times[0][0] = "00:00"; contractNanny.Times[0][1] = "00:00"; } if (chmon.IsChecked == true) { contractNanny.Days[1] = true; contractNanny.Times[1][0] = monS.Text; contractNanny.Times[1][1] = monE.Text; } else { contractNanny.Days[1] = false; contractNanny.Times[1][0] = "00:00"; contractNanny.Times[1][1] = "00:00"; } if (chthu.IsChecked == true) { contractNanny.Days[2] = true; contractNanny.Times[2][0] = tueS.Text; contractNanny.Times[2][1] = sueE.Text; } else { contractNanny.Days[2] = false; contractNanny.Times[2][0] = "00:00"; contractNanny.Times[2][1] = "00:00"; } if (chwed.IsChecked == true) { contractNanny.Days[3] = true; contractNanny.Times[3][0] = wedS.Text; contractNanny.Times[3][1] = wedE.Text; } else { contractNanny.Days[3] = false; contractNanny.Times[3][0] = "00:00"; contractNanny.Times[3][1] = "00:00"; } if (chthu.IsChecked == true) { contractNanny.Days[4] = true; contractNanny.Times[4][0] = thuS.Text; contractNanny.Times[4][1] = thuE.Text; } else { contractNanny.Days[4] = false; contractNanny.Times[4][0] = "00:00"; contractNanny.Times[4][1] = "00:00"; } if (thfri.IsChecked == true) { contractNanny.Days[5] = true; contractNanny.Times[5][0] = friS.Text; contractNanny.Times[5][1] = friE.Text; } else { contractNanny.Days[5] = false; contractNanny.Times[5][0] = "00:00"; contractNanny.Times[5][1] = "00:00"; } try { myBL.AddNanny(contractNanny); contractNanny = new BE.Nanny(); this.DataContext = contractNanny; MessageBox.Show("succeed!"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
static void Main(string[] args) { BL.IBL mybl = BL.FactoryBL.GetInstance; Dictionary <DayOfWeek, KeyValuePair <int, int> > Need = new Dictionary <DayOfWeek, KeyValuePair <int, int> >(); DateTime d = new DateTime(1994, 4, 21); DateTime d2 = new DateTime(2016, 4, 21); BankAccount bank = new BankAccount { AccountNumber = 1, BankName = BankName.Discont, BranchNumber = 10, BankAdress = new Address { Number = 12, Street = "Hadekel", City = "Eilat", Country = "Israel" } }; Address A = new Address { Street = "beit hadfus", Number = 7, City = "JERUSALEM", Country = "ISRAEL" }; Address B = new Address { Street = "beit hadfus", Number = 11, City = "JERUSALEM", Country = "ISRAEL" }; Address C = new Address { Street = "beit hadfus", Number = 21, City = "JERUSALEM", Country = "ISRAEL" }; List <string> s = new List <string>(); Mother m = new Mother { ID = "333", PersonAddress = A, FirstName = "asa", Lastname = "faf", GoalAddress = B, HoursNeed = Need, MotherAccount = bank, Tel = "30484", TelHome = "39853" }; Mother m1 = new Mother { ID = "888", PersonAddress = B, FirstName = "asa", Lastname = "faf", GoalAddress = B, HoursNeed = Need, MotherAccount = bank, Tel = "30484", TelHome = "39853" }; Mother m2 = new Mother { ID = "777", PersonAddress = C, FirstName = "asa", Lastname = "faf", GoalAddress = B, HoursNeed = Need, MotherAccount = bank, Tel = "30484", TelHome = "39853" }; mybl.AddMother(m); mybl.AddMother(m1); mybl.AddMother(m2); Nanny n = new Nanny { ID = "355", PersonAddress = C, VacationDays = true, Birthday = d, Elevator = false, Experience = 4, FirstName = "nana", Floor = 2, SalaryForMonth = 300, Lastname = "poly", MaxChildrens = 12, MaxChildrensAge = 12, MinChildrensAge = 2, MyBankAccount = bank, MyRecommendations = "very good", range = "2-12", RateForHour = 34, Tel = "24769786", WorkHours = Need }; Nanny n2 = new Nanny { ID = "385", PersonAddress = A, VacationDays = true, Birthday = d, Elevator = false, Experience = 5, FirstName = "nana", Floor = 2, SalaryForMonth = 300, Lastname = "poly", MaxChildrens = 12, MaxChildrensAge = 12, MinChildrensAge = 2, MyBankAccount = bank, MyRecommendations = "very good", range = "2-12", RateForHour = 34, Tel = "24769786", WorkHours = Need }; Nanny n3 = new Nanny { ID = "395", PersonAddress = B, VacationDays = true, Birthday = d, Elevator = false, Experience = 3, FirstName = "nana", Floor = 2, SalaryForMonth = 300, Lastname = "poly", MaxChildrens = 12, MaxChildrensAge = 18, MinChildrensAge = 5, MyBankAccount = bank, MyRecommendations = "very good", range = "5-18", RateForHour = 34, Tel = "24769786", WorkHours = Need }; mybl.AddNanny(n); mybl.AddNanny(n2); mybl.AddNanny(n3); Child CH = new Child { ID = "555", Allergy = false, Birthday = d2, SpecialNeeds = false, MyMotherID = "333", FirstName = "BABY", Needs = "s", MyAllergy = "nuts", MyNutrition = "materna" }; Child CH1 = new Child { ID = "790", Allergy = false, Birthday = d2, SpecialNeeds = false, MyMotherID = "333", FirstName = "BABY", Needs = "s" }; Child CH2 = new Child { ID = "476", Allergy = false, Birthday = d2, SpecialNeeds = false, MyMotherID = "333", FirstName = "BABY", Needs = "s" }; mybl.AddChild(CH); mybl.AddChild(CH1); mybl.AddChild(CH2); Contract C1 = new Contract { NannyID = "355", ChildID = "555", MotherID = "333", EmploymentHours = Need, Payment = true }; Contract C2 = new Contract { NannyID = "385", ChildID = "790", MotherID = "888", EmploymentHours = Need, Payment = true }; Contract C3 = new Contract { NannyID = "395", ChildID = "476", MotherID = "777", EmploymentHours = Need, Payment = true }; mybl.AddContract(C1); mybl.AddContract(C2); mybl.AddContract(C3); List <Nanny> nannys = mybl.SelectedNannys(22, Need, 400, 4, 14, 5); // List<Contract> list = mybl.SelectedContracts(c => c.ChildID == "555"); // int num = mybl.NumOfSelectedContracts(c => c.ChildID == "555"); //IEnumerable<IGrouping<string, Nanny>> range = mybl.GroupNannyByChildAge(false); //IEnumerable<IGrouping<int, Contract>> cont = mybl.GroupContractByDistanceBetweenNannyAndChild(true); //mybl.SelectedNanniesByAddress(A,10,false,19, Need,400,30,2,12,10); //bool dis=mybl.Distance(A, B,10) ; }
static void Main(string[] args) { BL.IBL bl = BL.FactoryBL.GetBL(); bl.Init(); #region Nanny Functions Nanny myNanny = new Nanny { Id = 1237, FirstName = "Shir", LastName = "Tevet", BirthDate = DateTime.Parse("12.12.1997"), PhoneNumber = "0541234567", Address = "Yaffo,Jerusalem,Israel", IsElevator = true, Floor = 3, MaxNumOfChildren = 10, MinAge = 3, MaxAge = 7, EnanblePayForHour = true, HourlyRate = 10, MonthlyRate = 2000, IsVacationAsTMT = true, Recommendations = "Recommendations", SpecialActivities = "SpecialActivities", IsKosherFood = true, IsReligiousEducation = true, Comments = "Comments", //BankAccount = new Bank(), }; myNanny.NannySchedule[0].IsWorkDay = true; myNanny.NannySchedule[1].IsWorkDay = true; myNanny.NannySchedule[2].IsWorkDay = true; myNanny.NannySchedule[0].StartHour += new TimeSpan(10, 0, 0); myNanny.NannySchedule[0].EndHour += new TimeSpan(16, 0, 0); myNanny.NannySchedule[1].StartHour += new TimeSpan(9, 0, 0); myNanny.NannySchedule[1].EndHour += new TimeSpan(14, 0, 0); myNanny.NannySchedule[2].StartHour += new TimeSpan(8, 0, 0); myNanny.NannySchedule[2].EndHour += new TimeSpan(14, 0, 0); try { Console.WriteLine("-----add nanny-----"); bl.AddNanny(myNanny); foreach (Nanny n in bl.GetNannyList()) { Console.WriteLine(n); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----remove nanny-----"); //bl.RemoveNanny(1236); foreach (Nanny n in bl.GetNannyList()) { Console.WriteLine(n); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----update nanny-----"); Nanny nannyToUpdate = new Nanny { Id = 1237, FirstName = "Shir", LastName = "Tevet", BirthDate = DateTime.Parse("12.12.1997"), PhoneNumber = "0541234567", Address = "Yaffo,Jerusalem,Israel", IsElevator = true, Floor = 3, MaxNumOfChildren = 10, MinAge = 3, MaxAge = 7, EnanblePayForHour = true, HourlyRate = 10, MonthlyRate = 2000, IsVacationAsTMT = true, Recommendations = "Recommendations", SpecialActivities = "SpecialActivities", IsKosherFood = true, IsReligiousEducation = true, Comments = "Comments", //BankAccount = new Bank(), }; nannyToUpdate.NannySchedule[0].IsWorkDay = true; nannyToUpdate.NannySchedule[1].IsWorkDay = true; nannyToUpdate.NannySchedule[2].IsWorkDay = true; nannyToUpdate.NannySchedule[0].StartHour += new TimeSpan(10, 0, 0); nannyToUpdate.NannySchedule[0].EndHour += new TimeSpan(16, 0, 0); nannyToUpdate.NannySchedule[1].StartHour += new TimeSpan(9, 0, 0); nannyToUpdate.NannySchedule[1].EndHour += new TimeSpan(17, 0, 0); nannyToUpdate.NannySchedule[2].StartHour += new TimeSpan(7, 0, 0); nannyToUpdate.NannySchedule[2].EndHour += new TimeSpan(17, 0, 0); bl.UpdateNannyDetails(nannyToUpdate); foreach (Nanny n in bl.GetNannyList()) { Console.WriteLine(n); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----get nanny-----"); Console.WriteLine(bl.GetNanny(1237)); } catch (Exception e) { Console.WriteLine(e.Message); } #endregion #region Mother Functions Mother myMother = new Mother { Id = 3237, LastName = "Ben-David", FirstName = "Tal", PhoneNumber = "054444444", HomeAddress = "Ben-Tzion,Jerusalem,Israel", Comments = "Comments", Status = MotherStatus.HouseWife, IsSingleMother = true, }; for (int i = 0; i < 3; i++) { myMother.WantedNannySchedule[i].IsWorkDay = true; } myMother.WantedNannySchedule[0].StartHour += new TimeSpan(8, 30, 0); myMother.WantedNannySchedule[0].EndHour += new TimeSpan(16, 0, 0); myMother.WantedNannySchedule[1].StartHour += new TimeSpan(9, 0, 0); myMother.WantedNannySchedule[1].EndHour += new TimeSpan(14, 0, 0); myMother.WantedNannySchedule[2].StartHour += new TimeSpan(8, 0, 0); myMother.WantedNannySchedule[2].EndHour += new TimeSpan(14, 0, 0); try { Console.WriteLine("-----add mother-----"); bl.AddMother(myMother); foreach (Mother m in bl.GetMotherList()) { Console.WriteLine(m); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----remove mother-----"); // bl.RemoveMother(3236); foreach (Mother m in bl.GetMotherList()) { Console.WriteLine(m); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----update mother-----"); Mother motherToUpdate = new Mother { Id = 3237, LastName = "Ben-David", FirstName = "Tal", PhoneNumber = "054444444", HomeAddress = "Ben-Tzion,Jerusalem,Israel", Comments = "Comments", Status = MotherStatus.Worker, IsSingleMother = false, }; for (int i = 0; i < 3; i++) { motherToUpdate.WantedNannySchedule[i].IsWorkDay = true; } motherToUpdate.WantedNannySchedule[0].StartHour += new TimeSpan(8, 30, 0); motherToUpdate.WantedNannySchedule[0].EndHour += new TimeSpan(16, 0, 0); motherToUpdate.WantedNannySchedule[1].StartHour += new TimeSpan(9, 0, 0); motherToUpdate.WantedNannySchedule[1].EndHour += new TimeSpan(17, 0, 0); motherToUpdate.WantedNannySchedule[2].StartHour += new TimeSpan(8, 0, 0); motherToUpdate.WantedNannySchedule[2].EndHour += new TimeSpan(20, 0, 0); bl.UpdateMotherDetails(motherToUpdate); foreach (Mother m in bl.GetMotherList()) { Console.WriteLine(m); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----get mother-----"); Console.WriteLine(bl.GetMother(2237)); } catch (Exception e) { Console.WriteLine(e.Message); } #endregion #region Child Functions Child myChild = new Child { Id = 2237, MotherId = 3237, FirstName = "Chen", BirthDate = DateTime.Parse("3.4.2017"), IsSpecialNeedsChild = true, SpecialNeeds = "SpecialNeeds", IsFoodAllergy = true, FoodAllergy = "FoodAllergy", IsMedicinesAllergy = true, MedicinesAllergy = "IsMedicinesAllergy", IsBreastMilk = true, Comments = "Comments" }; try { Console.WriteLine("-----add child-----"); bl.AddChild(myChild); foreach (Child c in bl.GetChildList()) { Console.WriteLine(c); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----remove child-----"); //bl.RemoveChild(2234); foreach (Child c in bl.GetChildList()) { Console.WriteLine(c); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----update child-----"); Child childToUpdate = new Child { Id = 2237, MotherId = 3237, FirstName = "Chen", BirthDate = DateTime.Parse("3.7.2017"), IsSpecialNeedsChild = false, SpecialNeeds = "", IsFoodAllergy = true, FoodAllergy = "FoodAllergy", IsMedicinesAllergy = true, MedicinesAllergy = "IsMedicinesAllergy", IsBreastMilk = true, Comments = "Comments" }; bl.UpdateChildDetails(childToUpdate); foreach (Child c in bl.GetChildList()) { Console.WriteLine(c); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----get child-----"); Console.WriteLine(bl.GetChild(2237)); } catch (Exception e) { Console.WriteLine(e.Message); } #endregion #region Contract Functions Contract myContract = new Contract { NannyId = 1237, ChildId = 2237, IsIntroductoryMeeting = false, IsSignedContract = false, PayPerHourOrMonth = PaymentPer.Hour, StartContractDate = new DateTime(2017, 9, 1), EndContractDate = new DateTime(2018, 9, 1), PaidBy = WayOfPayment.BankTransfer }; try { Console.WriteLine("-----add contract-----"); bl.AddContract(myContract); foreach (Contract c in bl.GetContractList()) { Console.WriteLine(c); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----remove contract-----"); //bl.RemoveContract(10000003); foreach (Contract c in bl.GetContractList()) { Console.WriteLine(c); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----update contract-----"); Contract contractToUpdate = new Contract { NannyId = 1234, ChildId = 2236, IsIntroductoryMeeting = false, IsSignedContract = false, PayPerHourOrMonth = PaymentPer.Month, StartContractDate = new DateTime(2017, 9, 1), EndContractDate = new DateTime(2018, 9, 1), PaidBy = WayOfPayment.BankTransfer }; bl.UpdateContractDetails(contractToUpdate); foreach (Contract c in bl.GetContractList()) { Console.WriteLine(c); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("-----get contract-----"); Console.WriteLine(bl.GetContract(10000004)); } catch (Exception e) { Console.WriteLine(e.Message); } #endregion try { Console.WriteLine("\n----GetAllNannyByDistance----"); var nanniesByDistance = bl.GetAllNannyByDistance(3234, 40); foreach (var n in nanniesByDistance) { Console.WriteLine("nannyId: {0}", n.Id); } } catch (Exception e) { Console.WriteLine(e.Message); } try { var matchNannies = bl.GetAllMatchHoursNanny(3234); Console.WriteLine("\n----NannyHours----"); string result; foreach (Nanny n in bl.GetNannyList()) { result = "\n"; for (int i = 0; i < n.NannySchedule.Length; i++) { if (n.NannySchedule[i].IsWorkDay) { result += n.NannySchedule[i].Day + ": "; //print the days that nanny works result += n.NannySchedule[i].StartHour.ToString() + " - " + n.NannySchedule[i].EndHour.ToString() + "\n"; //print the hours per a day that nanny works } } Console.WriteLine(result); } Console.WriteLine("\n----MotherHours----"); result = "\n"; for (int i = 0; i < bl.GetMother(3234).WantedNannySchedule.Length; i++) { if (bl.GetMother(3234).WantedNannySchedule[i].IsWorkDay) { result += bl.GetMother(3234).WantedNannySchedule[i].Day + ": "; //print the days that nanny works result += bl.GetMother(3234).WantedNannySchedule[i].StartHour.ToString() + " - " + bl.GetMother(3234).WantedNannySchedule[i].EndHour.ToString() + "\n"; //print the hours per a day that nanny works } } Console.WriteLine(result); Console.WriteLine("\n----GetAllMatchHoursNanny----"); foreach (Nanny n in matchNannies) { Console.WriteLine(n); } } catch (Exception e) { Console.WriteLine(e.Message); } try { var noNannyChildren = bl.GetNoNannyChildrenList(); Console.WriteLine("\n----AllContractsList----"); foreach (Contract c in bl.GetContractList()) { Console.WriteLine(c); } Console.WriteLine("\n----GetNoNannyChildrenList----"); foreach (Child c in noNannyChildren) { Console.WriteLine(c); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("\n----AllNannyList----"); foreach (Nanny n in bl.GetNannyList()) { Console.WriteLine("nannyId: {0}, isTMT: {1}", n.Id, n.IsVacationAsTMT); } Console.WriteLine("\n----GetNannyWithTMTList----"); var TMTNannyList = bl.GetNannyWithTMTList(); foreach (Nanny n in TMTNannyList) { Console.WriteLine("nannyId: {0}, isTMT: {1}", n.Id, n.IsVacationAsTMT); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("\n----AllNannyList----"); foreach (Nanny n in bl.GetNannyList()) { Console.WriteLine("nannyId: {0}, minAge: {1}, maxAge: {2}", n.Id, n.MinAge, n.MaxAge); } Console.WriteLine("\n----GroupNannyByChildAge----"); var maxAgeNannyGroups = bl.GroupNannyByChildAge(true, true); var minAgeNannyGroups = bl.GroupNannyByChildAge(true, false); foreach (var g in maxAgeNannyGroups) { //switch(g.Key) //{ // case 1: // Console.WriteLine("maxAge: 3-5:"); // break; // case 2: // Console.WriteLine("maxAge: 6-8:"); // break; // case 3: // Console.WriteLine("maxAge: 9-11:"); // break; // default: // Console.WriteLine("maxAge: 1 year+: "); // break; //} foreach (var n in g) { Console.WriteLine("nannyId: {0}", n.Id); } } } catch (Exception e) { Console.WriteLine(e.Message); } try { var minAgeNannyGroups = bl.GroupNannyByChildAge(true, false); foreach (var g in minAgeNannyGroups) { //switch (g.Key) //{ // case 1: // Console.WriteLine("minAge: 3-5:"); // break; // case 2: // Console.WriteLine("minAge: 6-8:"); // break; // case 3: // Console.WriteLine("minAge: 9-11:"); // break; // default: // Console.WriteLine("minAge: 1 year+: "); // break; //} foreach (var n in g) { Console.WriteLine("nannyId: {0}", n.Id); } } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("\n----GroupContractByDistance----"); var distanceGroups = bl.GroupContractByDistance(false); var orderDistanceGroups = bl.GroupContractByDistance(true); foreach (var g in orderDistanceGroups) { //switch ((int)g.Key) //{ // case 0: // Console.WriteLine("Distance: 0-1:"); // break; // case 1: // Console.WriteLine("Distance: 2-3:"); // break; // case 2: // Console.WriteLine("Distance: 4-5:"); // break; // case 3: // Console.WriteLine("Distance: 5-6:"); // break; // case 4: // Console.WriteLine("Distance: 7-8:"); // break; // case 5: // Console.WriteLine("Distance: 9-10:"); // break; // default: // break; //} foreach (var c in g) { Console.WriteLine("contractId: {0}", c.ContractId); } } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("\n----AllContractsList----"); foreach (Contract c in bl.GetContractList()) { Console.WriteLine(c); } Console.WriteLine("\n----GroupContractByRate----"); var rateGroups = bl.GroupContractByRate(true); foreach (var g in rateGroups) { //switch ((int)g.Key) //{ // case 0: // Console.WriteLine("up to 1000:"); // break; // case 1: // Console.WriteLine("1000-2000:"); // break; //case 2: // Console.WriteLine("2000-3000:"); // break; //default: // Console.WriteLine("3000+:"); // break; //} foreach (var c in g) { Console.WriteLine("contractId: {0}, NetoRate: {1}", c.ContractId, bl.CalculateContractRate(c)); } } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("\n----AllChildInNannyList----"); foreach (Contract c in bl.GetContractList(c => c.NannyId == 1237)) { Console.WriteLine("childId: {0}, BreastMilk: {1}", c.ChildId, bl.GetChild(c.ChildId).IsBreastMilk); } Console.WriteLine("\n----GroupChildrenByBreastMilk----"); var milkGroups = bl.GroupChildrenByBreastMilk(1237); foreach (var g in milkGroups) { //switch (g.Key) //{ // case true: // Console.WriteLine("BreastMilk:"); // break; // case false: // Console.WriteLine("NoBreastMilk:"); // break; // // default: // // break; //} // foreach (var c in g) // { // Console.WriteLine("childId: {0}", c.Id, c.IsBreastMilk); // } } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("\n----AllMothersStatus----"); foreach (Mother m in bl.GetMotherList()) { Console.WriteLine("motherId: {0}, status: {1}", m.Id, m.Status); } Console.WriteLine("\n----GroupMotherByStatus----"); var statusGroups = bl.GroupMotherByStatus(); foreach (var g in statusGroups) { switch (g.Key) { case MotherStatus.HouseWife: Console.WriteLine("HouseWife:"); break; case MotherStatus.MaternityLeave: Console.WriteLine("MaternityLeave:"); break; case MotherStatus.Student: Console.WriteLine("Student:"); break; case MotherStatus.Worker: Console.WriteLine("Worker:"); break; default: break; } foreach (var m in g) { Console.WriteLine("motherId: {0}", m.Id); } } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("\n----GetChildAge----"); foreach (Child c in bl.GetChildList()) { Console.WriteLine("childId: {0}, birthDate: {1}, Age: {2}", c.Id, c.BirthDate.ToShortDateString(), bl.GetChildAge(c.Id)); } } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("\n----AllContractsList----"); foreach (Contract c in bl.GetContractList()) { Console.WriteLine("contractId: {0}, nannyId: {1} , childId: {2}", c.ContractId, c.NannyId, c.ChildId); } Console.WriteLine("\n----SearchContract----"); Console.WriteLine(bl.SearchContract(1239, 2237)); } catch (Exception e) { Console.WriteLine(e.Message); } try { Console.WriteLine("\n----AllChildList----"); foreach (Child c in bl.GetChildList()) { Console.WriteLine("childId: {0}, IsFoodAllergy: {1}, IsMedicinesAllergy: {2}", c.Id, c.IsFoodAllergy, c.IsMedicinesAllergy); } Console.WriteLine("\n----GetAllergyChildren----"); foreach (Nanny n in bl.GetNannyList()) { Console.WriteLine("nannyId: {0}", n.Id); foreach (Child c in bl.GetAllergyChildren(n.Id)) { Console.WriteLine("childId: {0}, IsFoodAllergy: {1}, IsMedicinesAllergy: {2}", c.Id, c.IsFoodAllergy, c.IsMedicinesAllergy); } } } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadKey(); }
/// <summary> /// checks exceptions and adding the nanny /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Click_ok(object sender, RoutedEventArgs e) { #region check exceptions bool isChecked = false; try { // checks empty fields if (string.IsNullOrEmpty(idTextBox.Text)) { throw new Exception("fill the id!"); } if (!int.TryParse(idTextBox.Text, out int i)) { throw new Exception("enter id in numbers!"); } bool alreadyExist = myBl.NanniesByPredicate().Any(x => x.Id == int.Parse(idTextBox.Text)); if (alreadyExist) { throw new Exception("The nanny already exist!"); } if (string.IsNullOrEmpty(firstNameTextBox.Text)) { throw new Exception("fill the first name!"); } if (int.TryParse(firstNameTextBox.Text, out i)) { throw new Exception("invalid first name!"); } if (string.IsNullOrEmpty(lastNameTextBox.Text)) { throw new Exception("fill the last name!"); } if (int.TryParse(lastNameTextBox.Text, out i)) { throw new Exception("invalid last name!"); } if (string.IsNullOrEmpty(dateOfBirthDatePicker.Text)) { throw new Exception("fill the date!"); } if (dateOfBirthDatePicker.SelectedDate > DateTime.Now) { throw new Exception("invalid date!"); } if (string.IsNullOrEmpty(experienceTextBox.Text)) { throw new Exception("fill the experience!"); } if (!int.TryParse(experienceTextBox.Text, out i)) { throw new Exception("enter experience in numbers!"); } if (string.IsNullOrEmpty(cellphoneTextBox.Text)) { throw new Exception("fill the cellphone!"); } if (int.TryParse(cellphoneTextBox.Text, out i)) { throw new Exception("invalid cellphone!"); } if (cellphoneTextBox.Text == "like: 052-1234578") { throw new Exception("fill real cellphone!"); } if (string.IsNullOrEmpty(floorTextBox.Text)) { throw new Exception("fill the floor!"); } if (!int.TryParse(floorTextBox.Text, out i)) { throw new Exception("enter floor in numbers!"); } if (string.IsNullOrEmpty(hourlyWageTextBox.Text)) { throw new Exception("fill the hourly wage!"); } if (!int.TryParse(hourlyWageTextBox.Text, out i)) { throw new Exception("enter hourly wage in numbers!"); } if (string.IsNullOrEmpty(addressTextBox.Text)) { throw new Exception("fill the address!"); } if (int.TryParse(addressTextBox.Text, out i)) { throw new Exception("invalid address!"); } if (string.IsNullOrEmpty(maxChildAgeTextBox.Text)) { throw new Exception("fill the max child age!"); } if (!int.TryParse(maxChildAgeTextBox.Text, out i)) { throw new Exception("enter max child age in numbers!"); } if (string.IsNullOrEmpty(maxChildNumberTextBox.Text)) { throw new Exception("fill the max child number!"); } if (!int.TryParse(maxChildNumberTextBox.Text, out i)) { throw new Exception("enter max child number in numbers!"); } if (string.IsNullOrEmpty(minChildAgeTextBox.Text)) { throw new Exception("fill the min child age!"); } if (!int.TryParse(minChildAgeTextBox.Text, out i)) { throw new Exception("enter min child age in numbers!"); } int min = int.Parse(minChildAgeTextBox.Text); int max = int.Parse(maxChildAgeTextBox.Text); if (max < min) { throw new Exception("max child age can't be less than min child age"); } if (string.IsNullOrEmpty(monthlyWageTextBox.Text)) { throw new Exception("fill the monthly wage!"); } if (!int.TryParse(monthlyWageTextBox.Text, out i)) { throw new Exception("enter monthly wage in numbers!"); } if (string.IsNullOrEmpty(recommendationTextBox.Text)) { throw new Exception("fill the recommendation!"); } if (int.TryParse(recommendationTextBox.Text, out i)) { throw new Exception("invalid recommendation !"); } int enter, exit; // help variables if ((bool)checkSun.IsChecked) { if (string.IsNullOrEmpty(enterSun.Text)) { throw new Exception("fill the enter box!"); } if (!int.TryParse(enterSun.Text, out i)) { throw new Exception("invalid enter box!"); } if (string.IsNullOrEmpty(exitSun.Text)) { throw new Exception("fill the exit box!"); } if (!int.TryParse(exitSun.Text, out i)) { throw new Exception("invalid exit box!"); } enter = int.Parse(enterSun.Text); exit = int.Parse(exitSun.Text); if (exit < enter) { throw new Exception("exit time is earlier than the enter time!"); } } if ((bool)checkMon.IsChecked) { if (string.IsNullOrEmpty(enterMon.Text)) { throw new Exception("fill the enter box!"); } if (!int.TryParse(enterMon.Text, out i)) { throw new Exception("invalid enter box!"); } if (string.IsNullOrEmpty(exitMon.Text)) { throw new Exception("fill the exit box!"); } if (!int.TryParse(exitMon.Text, out i)) { throw new Exception("invalid exit box!"); } enter = int.Parse(enterMon.Text); exit = int.Parse(exitMon.Text); if (exit < enter) { throw new Exception("exit time is earlier than the enter time!"); } } if ((bool)checkTue.IsChecked) { if (string.IsNullOrEmpty(enterTue.Text)) { throw new Exception("fill the enter box!"); } if (!int.TryParse(enterTue.Text, out i)) { throw new Exception("invalid enter box!"); } if (string.IsNullOrEmpty(exitTue.Text)) { throw new Exception("fill the exit box!"); } if (!int.TryParse(exitTue.Text, out i)) { throw new Exception("invalid exit box!"); } enter = int.Parse(enterTue.Text); exit = int.Parse(exitTue.Text); if (exit < enter) { throw new Exception("exit time is earlier than the enter time!"); } } if ((bool)checkWed.IsChecked) { if (string.IsNullOrEmpty(enterWed.Text)) { throw new Exception("fill the enter box!"); } if (!int.TryParse(enterWed.Text, out i)) { throw new Exception("invalid enter box!"); } if (string.IsNullOrEmpty(exitWed.Text)) { throw new Exception("fill the exit box!"); } if (!int.TryParse(exitWed.Text, out i)) { throw new Exception("invalid exit box!"); } enter = int.Parse(enterWed.Text); exit = int.Parse(exitWed.Text); if (exit < enter) { throw new Exception("exit time is earlier than the enter time!"); } } if ((bool)checkThu.IsChecked) { if (string.IsNullOrEmpty(enterThu.Text)) { throw new Exception("fill the enter box!"); } if (!int.TryParse(enterThu.Text, out i)) { throw new Exception("invalid enter box!"); } if (string.IsNullOrEmpty(exitThu.Text)) { throw new Exception("fill the exit box!"); } if (!int.TryParse(exitThu.Text, out i)) { throw new Exception("invalid exit box!"); } enter = int.Parse(enterThu.Text); exit = int.Parse(exitThu.Text); if (exit < enter) { throw new Exception("exit time is earlier than the enter time!"); } } if ((bool)checkFri.IsChecked) { if (string.IsNullOrEmpty(enterFri.Text)) { throw new Exception("fill the enter box!"); } if (!int.TryParse(enterFri.Text, out i)) { throw new Exception("invalid enter box!"); } if (string.IsNullOrEmpty(exitFri.Text)) { throw new Exception("fill the exit box!"); } if (!int.TryParse(exitFri.Text, out i)) { throw new Exception("invalid exit box!"); } enter = int.Parse(enterFri.Text); exit = int.Parse(exitFri.Text); if (exit < enter) { throw new Exception("exit time is earlier than the enter time!"); } } isChecked = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "DATA ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } if (!isChecked) { return; } #endregion #region adding the nanny BE.Nanny myNanny = new BE.Nanny() // create the new nanny for ading { Address = addressTextBox.Text, Cellphone = cellphoneTextBox.Text, DateOfBirth = (DateTime)dateOfBirthDatePicker.SelectedDate, ElevatorExist = (bool)elevatorExistCheckBox.IsChecked, Experience = int.Parse(experienceTextBox.Text), FirstName = firstNameTextBox.Text, Floor = int.Parse(floorTextBox.Text), HolidaysByTMT = (bool)holidaysByTMTCheckBox.IsChecked, HourlyWage = int.Parse(hourlyWageTextBox.Text), Id = int.Parse(idTextBox.Text), LastName = lastNameTextBox.Text, MaxChildAge = int.Parse(maxChildAgeTextBox.Text), MaxChildNumber = int.Parse(maxChildNumberTextBox.Text), MinChildAge = int.Parse(minChildAgeTextBox.Text), MonthlyWage = int.Parse(monthlyWageTextBox.Text), NumOfContract = 0, PerHourSalary = (bool)perHourSalaryCheckBox.IsChecked, Recommendation = recommendationTextBox.Text }; myNanny.WorkDays[0] = (bool)checkSun.IsChecked; myNanny.WorkDays[1] = (bool)checkMon.IsChecked; myNanny.WorkDays[2] = (bool)checkTue.IsChecked; myNanny.WorkDays[3] = (bool)checkWed.IsChecked; myNanny.WorkDays[4] = (bool)checkThu.IsChecked; myNanny.WorkDays[5] = (bool)checkFri.IsChecked; myNanny.WorkDays[6] = (bool)checkSat.IsChecked; if ((bool)checkSun.IsChecked) { myNanny.Schedule[0, 0] = int.Parse(enterSun.Text); myNanny.Schedule[1, 0] = int.Parse(exitSun.Text); } if ((bool)checkMon.IsChecked) { myNanny.Schedule[0, 1] = int.Parse(enterMon.Text); myNanny.Schedule[1, 1] = int.Parse(exitMon.Text); } if ((bool)checkTue.IsChecked) { myNanny.Schedule[0, 2] = int.Parse(enterTue.Text); myNanny.Schedule[1, 2] = int.Parse(exitTue.Text); } if ((bool)checkWed.IsChecked) { myNanny.Schedule[0, 3] = int.Parse(enterWed.Text); myNanny.Schedule[1, 3] = int.Parse(exitWed.Text); } if ((bool)checkThu.IsChecked) { myNanny.Schedule[0, 4] = int.Parse(enterThu.Text); myNanny.Schedule[1, 4] = int.Parse(exitThu.Text); } if ((bool)checkFri.IsChecked) { myNanny.Schedule[0, 5] = int.Parse(enterFri.Text); myNanny.Schedule[1, 5] = int.Parse(exitFri.Text); } try { myBl.AddNanny(myNanny); } catch (Exception ex) { MessageBox.Show(ex.Message, "ADD NANNY ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return; } #endregion MessageBox.Show("The nanny added successfully :)", "SUCCESS", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); }
private void Button_Click(object sender, RoutedEventArgs e) { try { if (N.NannyId > 999999999) { throw new Exception("your id is not valid"); } if (N.NannyId == 0) { throw new Exception("your id is not valid"); } bool[] NannyWorks = new bool[6]; for (int i = 0; i < 6; i++) { //defaults the array NannyWorks[i] = false; } double[,] NannyWorks2 = new double[6, 2]; if (this.day1.IsChecked == true)//for each check box will check if its checked if so places true in NannyWorks and the times frm text into NannyWorks2 { NannyWorks[0] = true; NannyWorks2[0, 0] = switctTimeToDouble(daystart1.Text); NannyWorks2[0, 1] = switctTimeToDouble(dayend1.Text); } if (this.day2.IsChecked == true) { NannyWorks[1] = true; NannyWorks2[1, 0] = switctTimeToDouble(daystart2.Text); NannyWorks2[1, 1] = switctTimeToDouble(dayend2.Text); } if (this.day3.IsChecked == true) { NannyWorks[2] = true; NannyWorks2[2, 0] = switctTimeToDouble(daystart3.Text); NannyWorks2[2, 1] = switctTimeToDouble(dayend3.Text); } if (this.day4.IsChecked == true) { NannyWorks[3] = true; NannyWorks2[3, 0] = switctTimeToDouble(daystart4.Text); NannyWorks2[3, 1] = switctTimeToDouble(dayend4.Text); } if (this.day5.IsChecked == true) { NannyWorks[4] = true; NannyWorks2[4, 0] = switctTimeToDouble(daystart5.Text); NannyWorks2[4, 1] = switctTimeToDouble(dayend5.Text); } if (this.day6.IsChecked == true) { NannyWorks[5] = true; NannyWorks2[5, 0] = switctTimeToDouble(daystart6.Text); NannyWorks2[5, 1] = switctTimeToDouble(dayend6.Text); } N.NannyIsWorkingOnDay = NannyWorks; //places the context of both arrays into arrays in N N.NannyTimeIsWorkingOnDay = NannyWorks2; bl.AddNanny(N); //adds Nanny to program N = new BE.Nanny(); this.DataContext = N; //puts default context into all context on window } catch (Exception ex) { MessageBox.Show(ex.Message); } }