public void AddPerson(Person person) { OpenConnection(); using (DbCommand command = _dbProviderFactory.CreateCommand()) { command.Connection = _sqlConnection; command.CommandText = "INSERT INTO Persons(FirstName, LastName, DateOfBirth, Address, PolicyNumber) VALUES(@FirstName, @LastName, @DateOfBirth, @Address, @PolicyNumber)"; command.Parameters.Add(GetParam("@FirstName", person.FirstName)); command.Parameters.Add(GetParam("@LastName", person.LastName)); command.Parameters.Add(GetParam("@Address", person.Address)); command.Parameters.Add(GetParam("@DateOfBirth", person.DateOfBirth)); command.Parameters.Add(GetParam("@PolicyNumber", person.PolicyNumber)); try { command.ExecuteNonQuery(); } catch (SqlException) { throw new InvalidOperationException("This person already exists!"); } catch (Exception) { throw new InvalidOperationException("Can't add person!"); } finally { _sqlConnection.Close(); } } }
public void AddandGetPerson_ThreeDifferentPersons_ShouldPass(Person person) { var dataStorage = new HospitalDAL(_dataProvider, _connectionString); dataStorage.AddPerson(person); int personsCount = dataStorage.GetPersons(person.FirstName, person.LastName, person.PolicyNumber).Count; Assert.True(personsCount >= 1); }
public void AddPerson(Person person) { OpenConnection(); _command.CommandText = "INSERT INTO Persons(FirstName, LastName, DateOfBirth, Address, PolicyNumber) VALUES(@FirstName, @LastName, @DateOfBirth, @Address, @PolicyNumber)"; _command.Parameters.Add(GetParam("@FirstName", person.FirstName)); _command.Parameters.Add(GetParam("@LastName", person.LastName)); _command.Parameters.Add(GetParam("@Address", person.Address)); _command.Parameters.Add(GetParam("@DateOfBirth", person.DateOfBirth)); _command.Parameters.Add(GetParam("@PolicyNumber", person.PolicyNumber)); try { _command.ExecuteNonQuery(); //LOGGING Logger.Info("Person was added in database"); } catch (SqlException ex) { //LOGGING Logger.Error("This person already exists!",ex); throw new InvalidOperationException("This person already exists!"); } catch (Exception ex) { //LOGGING Logger.Error("Can't add person!",ex); throw new InvalidOperationException("Can't add person!"); } finally { CloseConnection(); } }
public void FillTemplate_HtmlTemplate_ShouldPass() { var template = new Template(new List<string> {"hemoglobin", "erythrocytes"}, "BloodTest"); var person = new Person("Igor", "Shein", new DateTime(1994, 4, 20), "Yaroslavl", "123456789"); var analysis = new Analysis(new List<string> {"20", "50"}, "Blood Test", new DateTime(2014, 08, 3)); var templateFiller = new TemplateFiller("Blood Test.html"); string actual = templateFiller.FillTemplate(person, analysis, template); //File.WriteAllText("expected.html", actual); string expected = File.ReadAllText("expected.html"); Assert.Equal(expected, actual); }
public string FillTemplate(Person person, Analysis analysis, Template template) { InitSubstitutions(person); StringBuilder templateContent = GetTemplateContent(); FillTemplateTitle(template, templateContent); FillPersonFields(templateContent); FillAnalysisFields(analysis, template, templateContent); return templateContent.ToString(); }
static void Main(string[] args) { try { var person = new Person(new DateTime(1978, 01, 01)); var account = person.OpenAccount(AccountTypeEnum.Investment, 50); account.DepositMoney(50); account.WithDrawMoney(90); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
private void InitSubstitutions(Person person) { PropertyInfo[] personProperties = typeof (Person).GetProperties(); foreach (PropertyInfo personProperty in personProperties) { _substitutions[personProperty.Name + "Value"] = personProperty.GetValue(person).ToString(); } //LOGGING Logger.Info("Subtitutions were initiated"); }
public override void ViewDidLoad() { base.ViewDidLoad (); string imgurl = "http://41.185.30.19/Indemnities/" + MarriedRelationshipID.ToString () + ".jpg"; //if(RemoteFileExists(imgurl) == false) { // Put alternative content/message here btnSaveIndemnity.SetTitle ("Snap Indemnity", UIControlState.Normal); btnSaveIndemnity.SetTitleColor (UIColor.Red, UIControlState.Normal); //} //else //{ // // Put Internet Required Code here // btnSaveIndemnity.SetTitle ("View Indemnity", UIControlState.Normal); // btnSaveIndemnity.SetTitleColor (UIColor.Green, UIControlState.Normal); //} if (MarriedRelationshipID == 0) { DataLayer dl = new DataLayer (); dl.Sync (); MarriedRelationshipID = dl.createMarriedRelationship (0, 0); } btnSpouse1Detail.TouchUpInside += (object sender, EventArgs e) => { UINavigationController parent = this.NavigationController; PersonViewController pdvc = parent.Storyboard.InstantiateViewController("PersonViewController") as PersonViewController; pdvc.PersonID = Spouse1ID; parent.PushViewController(pdvc,true); }; btnSpouse2Detail.TouchUpInside += (object sender, EventArgs e) => { UINavigationController parent = this.NavigationController; PersonViewController pdvc = parent.Storyboard.InstantiateViewController("PersonViewController") as PersonViewController; pdvc.PersonID = Spouse2ID; parent.PushViewController(pdvc,true); }; btnChild1Detail.TouchUpInside += (object sender, EventArgs e) => { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = Child1ID; parent.PushViewController(pdvc,true); }; btnChild2Detail.TouchUpInside += (object sender, EventArgs e) => { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = Child2ID; parent.PushViewController(pdvc,true); }; btnChild3Detail.TouchUpInside += (object sender, EventArgs e) => { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = Child3ID; parent.PushViewController(pdvc,true); }; btnChild4Detail.TouchUpInside += (object sender, EventArgs e) => { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = Child4ID; parent.PushViewController(pdvc,true); }; btnChild5Detail.TouchUpInside += (object sender, EventArgs e) => { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = Child5ID; parent.PushViewController(pdvc,true); }; btnSpouse1.TouchUpInside += (object sender, EventArgs e) => { if (Spouse1ID == 0) { UINavigationController parent = this.NavigationController; PersonViewController pdvc = parent.Storyboard.InstantiateViewController("PersonViewController") as PersonViewController; pdvc.PersonID = 0; pdvc.MarriedRelionshipID = MarriedRelationshipID; pdvc.Relationship = 1; parent.PushViewController(pdvc,true); } else { if (Spouse2ID == 0) { DataLayer db = new DataLayer(); db.deleteSpouse1(MarriedRelationshipID); this.Title = "Add Household"; loadHousehold(); } else { UIAlertView alert = new UIAlertView("Can't delete","Delete the second spouse before deleting the first",null,"OK",null); alert.Show(); } } }; btnSpouse2.TouchUpInside += (object sender, EventArgs e) => { if (Spouse2ID == 0) { UINavigationController parent = this.NavigationController; PersonViewController pdvc = parent.Storyboard.InstantiateViewController("PersonViewController") as PersonViewController; pdvc.PersonID = 0; pdvc.MarriedRelionshipID = MarriedRelationshipID; pdvc.Relationship = 2; parent.PushViewController(pdvc,true); } else { DataLayer db = new DataLayer(); db.deleteSpouse2(MarriedRelationshipID); loadHousehold(); } }; btnChild1.TouchUpInside += (object sender, EventArgs e) => { if (Child1ID == 0) { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = 0; pdvc.MarriedRelionshipID = MarriedRelationshipID; pdvc.Relationship = 3; parent.PushViewController(pdvc,true); } else { DataLayer db = new DataLayer(); db.deleteChild(MarriedRelationshipID, Child1ID); loadHousehold(); } }; btnChild2.TouchUpInside += (object sender, EventArgs e) => { if (Child2ID == 0) { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = 0; pdvc.MarriedRelionshipID = MarriedRelationshipID; pdvc.Relationship = 4; parent.PushViewController(pdvc,true); } else { DataLayer db = new DataLayer(); db.deleteChild(MarriedRelationshipID, Child2ID); loadHousehold(); } }; btnChild3.TouchUpInside += (object sender, EventArgs e) => { if (Child3ID == 0) { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = 0; pdvc.MarriedRelionshipID = MarriedRelationshipID; pdvc.Relationship = 5; parent.PushViewController(pdvc,true); } else { DataLayer db = new DataLayer(); db.deleteChild(MarriedRelationshipID, Child3ID); loadHousehold(); } }; btnChild4.TouchUpInside += (object sender, EventArgs e) => { if (Child4ID == 0) { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = 0; pdvc.MarriedRelionshipID = MarriedRelationshipID; pdvc.Relationship = 6; parent.PushViewController(pdvc,true); } else { DataLayer db = new DataLayer(); db.deleteChild(MarriedRelationshipID, Child4ID); loadHousehold(); } }; btnChild5.TouchUpInside += (object sender, EventArgs e) => { if (Child5ID == 0) { UINavigationController parent = this.NavigationController; ChildViewController pdvc = parent.Storyboard.InstantiateViewController("ChildViewController") as ChildViewController; pdvc.PersonID = 0; pdvc.MarriedRelionshipID = MarriedRelationshipID; pdvc.Relationship = 7; parent.PushViewController(pdvc,true); } else { DataLayer db = new DataLayer(); db.deleteChild(MarriedRelationshipID, Child5ID); loadHousehold(); } }; btnCheck1.TouchUpInside += (object sender, EventArgs e) => { if (Child1Selected == false) { btnCheck1.SetImage (UIImage.FromFile ("1040-checkmark-selected.png"), UIControlState.Normal); Child1Selected = true; } else { btnCheck1.SetImage (UIImage.FromFile ("1040-checkmark.png"), UIControlState.Normal); Child1Selected = false; } }; btnCheck2.TouchUpInside += (object sender, EventArgs e) => { if (Child2Selected == false) { btnCheck2.SetImage (UIImage.FromFile ("1040-checkmark-selected.png"), UIControlState.Normal); Child2Selected = true; } else { btnCheck2.SetImage (UIImage.FromFile ("1040-checkmark.png"), UIControlState.Normal); Child2Selected = false; } }; btnCheck3.TouchUpInside += (object sender, EventArgs e) => { if (Child3Selected == false) { btnCheck3.SetImage (UIImage.FromFile ("1040-checkmark-selected.png"), UIControlState.Normal); Child3Selected = true; } else { btnCheck3.SetImage (UIImage.FromFile ("1040-checkmark.png"), UIControlState.Normal); Child3Selected = false; } }; btnCheck4.TouchUpInside += (object sender, EventArgs e) => { if (Child4Selected == false) { btnCheck4.SetImage (UIImage.FromFile ("1040-checkmark-selected.png"), UIControlState.Normal); Child4Selected = true; } else { btnCheck4.SetImage (UIImage.FromFile ("1040-checkmark.png"), UIControlState.Normal); Child4Selected = false; } }; btnCheck5.TouchUpInside += (object sender, EventArgs e) => { if (Child5Selected == false) { btnCheck5.SetImage (UIImage.FromFile ("1040-checkmark-selected.png"), UIControlState.Normal); Child5Selected = true; } else { btnCheck5.SetImage (UIImage.FromFile ("1040-checkmark.png"), UIControlState.Normal); Child5Selected = false; } }; btnPrint.TouchUpInside += (object sender, EventArgs e) => { Kidz.PrintService.Linc printService = new Kidz.PrintService.Linc(); Database db = new Database(); db.Initialize(); int parentLabelId = 0; string printer = db.getPrinter(); try { Shared.Person parent1 = dl.getPerson(Spouse1ID); PrintService.Person parent1New = new Kidz.PrintService.Person(); parent1New.CampusID = parent1.CampusID; parent1New.Comments = parent1.Comments; parent1New.DoB = parent1.DoB; parent1New.EMail = parent1.EMail; parent1New.FirstName = parent1.FirstName; parent1New.Gender = parent1.Gender; parent1New.ID = parent1.ID; parent1New.IsTemporary = parent1.IsTemporary; parent1New.LastName = parent1.LastName; parent1New.Mobile = parent1.Mobile; parentLabelId = parent1.ID; Shared.Person parent2; try { parent2 = dl.getPerson(Spouse2ID); } catch { parent2 = new Shared.Person(); } PrintService.Person parent2New = new Kidz.PrintService.Person(); parent2New.CampusID = parent2.CampusID; parent2New.Comments = parent2.Comments; parent2New.DoB = parent2.DoB; parent2New.EMail = parent2.EMail; parent2New.FirstName = parent2.FirstName; parent2New.Gender = parent2.Gender; parent2New.ID = parent2.ID; parent2New.IsTemporary = parent2.IsTemporary; parent2New.LastName = parent2.LastName; parent2New.Mobile = parent2.Mobile; printService.PrintParentLabel_New(parent1New, parent2New, printer); } catch {} if (Child1Selected) { try { Shared.Person child1 = dl.getPerson(Child1ID); Kidz.PrintService.Person childNew = new Kidz.PrintService.Person(); childNew.CampusID = child1.CampusID; childNew.Comments = child1.Comments; childNew.DoB = child1.DoB; childNew.EMail = child1.EMail; childNew.FirstName = child1.FirstName; childNew.Gender = child1.Gender; childNew.ID = child1.ID; childNew.IsTemporary = child1.IsTemporary; childNew.LastName = child1.LastName; childNew.Mobile = child1.Mobile; childNew.Grade = child1.Grade; childNew.MarriedRelationshipID = parentLabelId; printService.PrintChildLabel_New(childNew, printer); DateTime kidBDay = child1.DoB; kidBDay = new DateTime(DateTime.Now.Year, kidBDay.Month, kidBDay.Day); if (DateTime.Now > kidBDay.AddDays(-3) && DateTime.Now < kidBDay.AddDays(3)) { try { printService.PrintBirthdayLabel_New(childNew, printer); } catch {} } } catch {} } if (Child2Selected) { try { Shared.Person child2 = dl.getPerson(Child2ID); Kidz.PrintService.Person childNew = new Kidz.PrintService.Person(); childNew.CampusID = child2.CampusID; childNew.Comments = child2.Comments; childNew.DoB = child2.DoB; childNew.EMail = child2.EMail; childNew.FirstName = child2.FirstName; childNew.Gender = child2.Gender; childNew.ID = child2.ID; childNew.IsTemporary = child2.IsTemporary; childNew.LastName = child2.LastName; childNew.Mobile = child2.Mobile; childNew.Grade = child2.Grade; childNew.MarriedRelationshipID = parentLabelId; printService.PrintChildLabel_New(childNew, printer); DateTime kidBDay = child2.DoB; kidBDay = new DateTime(DateTime.Now.Year, kidBDay.Month, kidBDay.Day); if (DateTime.Now > kidBDay.AddDays(-3) && DateTime.Now < kidBDay.AddDays(3)) { try { printService.PrintBirthdayLabel_New(childNew, printer); } catch {} } } catch {} } if (Child3Selected) { try { Shared.Person child3 = dl.getPerson(Child3ID); Kidz.PrintService.Person childNew = new Kidz.PrintService.Person(); childNew.CampusID = child3.CampusID; childNew.Comments = child3.Comments; childNew.DoB = child3.DoB; childNew.EMail = child3.EMail; childNew.FirstName = child3.FirstName; childNew.Gender = child3.Gender; childNew.ID = child3.ID; childNew.IsTemporary = child3.IsTemporary; childNew.LastName = child3.LastName; childNew.Mobile = child3.Mobile; childNew.Grade = child3.Grade; childNew.MarriedRelationshipID = parentLabelId; printService.PrintChildLabel_New(childNew, printer); DateTime kidBDay = child3.DoB; kidBDay = new DateTime(DateTime.Now.Year, kidBDay.Month, kidBDay.Day); if (DateTime.Now > kidBDay.AddDays(-3) && DateTime.Now < kidBDay.AddDays(3)) { try { printService.PrintBirthdayLabel_New(childNew, printer); } catch {} } } catch {} } if (Child4Selected) { try { Shared.Person child4 = dl.getPerson(Child4ID); Kidz.PrintService.Person childNew = new Kidz.PrintService.Person(); childNew.CampusID = child4.CampusID; childNew.Comments = child4.Comments; childNew.DoB = child4.DoB; childNew.EMail = child4.EMail; childNew.FirstName = child4.FirstName; childNew.Gender = child4.Gender; childNew.ID = child4.ID; childNew.IsTemporary = child4.IsTemporary; childNew.LastName = child4.LastName; childNew.Mobile = child4.Mobile; childNew.Grade = child4.Grade; childNew.MarriedRelationshipID = parentLabelId; printService.PrintChildLabel_New(childNew, printer); DateTime kidBDay = child4.DoB; kidBDay = new DateTime(DateTime.Now.Year, kidBDay.Month, kidBDay.Day); if (DateTime.Now > kidBDay.AddDays(-3) && DateTime.Now < kidBDay.AddDays(3)) { try { printService.PrintBirthdayLabel_New(childNew, printer); } catch {} } } catch {} } if (Child5Selected) { try { Shared.Person child5 = dl.getPerson(Child5ID); Kidz.PrintService.Person childNew = new Kidz.PrintService.Person(); childNew.CampusID = child5.CampusID; childNew.Comments = child5.Comments; childNew.DoB = child5.DoB; childNew.EMail = child5.EMail; childNew.FirstName = child5.FirstName; childNew.Gender = child5.Gender; childNew.ID = child5.ID; childNew.IsTemporary = child5.IsTemporary; childNew.LastName = child5.LastName; childNew.Mobile = child5.Mobile; childNew.Grade = child5.Grade; childNew.MarriedRelationshipID = parentLabelId; printService.PrintChildLabel_New(childNew, printer); DateTime kidBDay = child5.DoB; kidBDay = new DateTime(DateTime.Now.Year, kidBDay.Month, kidBDay.Day); if (DateTime.Now > kidBDay.AddDays(-3) && DateTime.Now < kidBDay.AddDays(3)) { try { printService.PrintBirthdayLabel_New(childNew, printer); } catch {} } } catch {} } UIAlertView alert = new UIAlertView("Labels", "Barcoded labels have been sent to '" + printer + "'",null,"OK",null); alert.Show(); }; btnSaveIndemnity.TouchUpInside += (object sender, EventArgs e) => { UINavigationController parent = this.NavigationController; if (btnSaveIndemnity.TitleLabel.Text == "Snap Indemnity") { UIImagePickerController picker = new UIImagePickerController(); picker.SourceType = UIImagePickerControllerSourceType.Camera; picker.FinishedPickingMedia += (object senderPic, UIImagePickerMediaPickedEventArgs ePic) => { // Create a new WebClient instance. WebClient myWebClient = new WebClient(); var documentsDirectory = Environment.GetFolderPath (Environment.SpecialFolder.Personal); string jpgFilename = System.IO.Path.Combine (documentsDirectory, MarriedRelationshipID.ToString() + ".jpg"); // hardcoded filename, overwritten each time NSData imgData = ePic.OriginalImage.AsJPEG(); NSError err = null; if (imgData.Save(jpgFilename, false, out err)) { Console.WriteLine("saved as " + jpgFilename); // Upload the file to the URI. // The 'UploadFile(uriString,fileName)' method implicitly uses HTTP POST method. var url = "http://41.185.30.19/fileupload.aspx"; Uri uri = new Uri (url); myWebClient.UploadFile (uri, jpgFilename); //byte[] responseArray = myWebClient.UploadFile("http://41.185.30.157/fileupload.aspx",jpgFilename); } else { Console.WriteLine("NOT saved as " + jpgFilename + " because" + err.LocalizedDescription); } picker.DismissViewController(true, null); }; parent.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; parent.PresentViewController(picker, true, null); } else { ImageViewController pdvc = parent.Storyboard.InstantiateViewController("ImageViewController") as ImageViewController; pdvc.MarriedRelationshipID = MarriedRelationshipID; parent.PushViewController(pdvc,true); } }; }
private void InitSubstitutions(Person person) { PropertyInfo[] personProperties = typeof (Person).GetProperties(); foreach (PropertyInfo personProperty in personProperties) { _substitutions[personProperty.Name + "Value"] = personProperty.GetValue(person).ToString(); } }