private bool CanSaveExecute() { if (PersonalNo == PreviousEmployeeData.PersonalNo && GivenName == PreviousEmployeeData.GivenName && Surname == PreviousEmployeeData.Surname && Location.LocationID == PreviousEmployeeData.LocationID && Sex.ToLower() == PreviousEmployeeData.Sex.ToLower() && Telephone == PreviousEmployeeData.Telephone && Employee.SectorID == PreviousEmployeeData.SectorID && Manager == PreviousEmployeeData.Manager && SectorName == GetPreviousEmployeeSectorName() && Employee.RegistrationNumber == PreviousEmployeeData.RegistrationNumber) { return(false); } if (string.IsNullOrWhiteSpace(GivenName) || string.IsNullOrWhiteSpace(Surname) || string.IsNullOrWhiteSpace(Telephone) || string.IsNullOrWhiteSpace(RegistrationNumber) || string.IsNullOrWhiteSpace(PersonalNo) || string.IsNullOrWhiteSpace(Sex)) { return(false); } if (CanSave == false) { return(false); } return(true); }
public IUser ToEntity(IUser user) { user.UserName = Email; user.Email = Email; user.FullName = FullName; user.Birthday = Birthday; user.Sex = !string.IsNullOrEmpty(Sex) ? Sex.ToLower() : string.Empty; user.Status = Status; user.CreateDate = CreateDate; return(user); }
private void SaveExecute() { try { var db = new DataAccess(); Employee.Surname = Surname; Employee.GivenName = GivenName; Employee.LocationID = Location.LocationID; Employee.Sex = Sex.ToLower(); Employee.PersonalNo = PersonalNo; Employee.DateOfBirth = GeneratingData.GenerateBirthdate(Employee.PersonalNo); EmployeeAge = GeneratingData.CalculateAge(Employee.DateOfBirth); Employee.Manager = Manager; Employee.Telephone = Telephone; Employee.RegistrationNumber = RegistrationNumber; if (Sectors.Any(s => s.Name == SectorName)) { Employee.SectorID = Sectors.First(s => s.Name == SectorName).SectorID; } else { var newSector = new tblSector() { Name = SectorName }; //adding new sector to database db.AddNewSector(newSector); Sectors = LoadSectors(); Employee.SectorID = Sectors.FirstOrDefault(s => s.Name == SectorName).SectorID; } //updating employee db.UpdateEmployee(Employee.EmployeeID, Employee); workerUpdate.RunWorkerAsync(); IsUpdatedEmployee = true; updateEmployeeView.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void SaveExecute() { try { var db = new DataAccess(); Employee.Sex = Sex.ToLower(); Employee.RegistrationNumber = RegistrationNumber; Employee.PersonalNo = PersonalNo; Employee.LocationID = Location.LocationID; Employee.DateOfBirth = GeneratingData.GenerateBirthdate(Employee.PersonalNo); if (Sectors.Any(s => s.Name == SectorName)) { Employee.SectorID = Sectors.First(s => s.Name == SectorName).SectorID; } else { var newSector = new tblSector() { Name = SectorName }; //adding new sector to database db.AddNewSector(newSector); Sectors = LoadSectors(); Employee.SectorID = Sectors.FirstOrDefault(s => s.Name == SectorName).SectorID; } //adding new employee to database db.AddNewEmployee(Employee); workerAddNew.RunWorkerAsync(); IsAddedNewEmployee = true; addNewEmployeeView.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private async Task <bool> CheckSuspectPicture(DetectiveBotContext context) { if (context.Request.Attachments?.Count > 0) { try { var match = 0; var face = await faceRecognitionService.GetFaceAttributes(context.Request.Attachments[0].ContentUrl); if (face != null) { //check sex if (face.FaceAttributes.Gender.ToLower() == Sex.ToLower()) { match += 25; } //check age switch ((int)Math.Round(face.FaceAttributes.Age)) { case int n when(n <= 20): if (Age == "<20") { match += 25; } break; case int n when(n > 20 && n <= 30): if (Age == "20-30") { match += 25; } break; case int n when(n > 30 && n <= 40): if (Age == "31-40") { match += 25; } break; case int n when(n > 40 && n <= 50): if (Age == "41-50") { match += 25; } break; case int n when(n > 50): if (Age == ">50") { match += 25; } break; } //check hair color if (HairColor.ToLower() == "bald" && (face.FaceAttributes.Hair.Bald > 0.7)) { match += 25; } else { if (face.FaceAttributes.Hair.HairColor != null && face.FaceAttributes.Hair.HairColor.Any(color => color.Color == (HairColorType)Enum.Parse(typeof(HairColorType), HairColor) && color.Confidence > 0.7)) { match += 25; } } //check facial hair if (FacialHair && (face.FaceAttributes.FacialHair.Beard > 0.7 || face.FaceAttributes.FacialHair.Moustache > 0.7 || face.FaceAttributes.FacialHair.Sideburns > 0.7)) { match += 25; } else { if (!FacialHair && (face.FaceAttributes.FacialHair.Beard < 0.5 && face.FaceAttributes.FacialHair.Moustache < 0.5 && face.FaceAttributes.FacialHair.Sideburns < 0.5)) { match += 25; } } } await context.SendActivity(context.Request.CreateReply($"This person matches the description for {match.ToString()}%")); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Exception: {ex.Message}"); await context.SendActivity(context.Request.CreateReply($"Error processing this image. Are you sure it contained a face?")); } } await context.SendActivity(context.Request.CreateReply($"Take a picture of a suspect and i'll check how far it matches the description")); State = TopicState.checkSuspectPicture; return(true); }
public string this[string name] { get { CanSave = true; var validate = new Validation(); var db = new DataAccess(); string validationMessage = string.Empty; if (name == nameof(PersonalNo)) { if (!validate.IsValidPersonalNoFormat(PersonalNo)) { validationMessage = "Invalid personal number format!"; CanSave = false; } if (!validate.IsUniquePersonalNo(PersonalNo, db.LoadPersonalNumbers())) { validationMessage = "Personal number must be unique!"; CanSave = false; } //if peronal number is valid we can check the age of user if (validationMessage == string.Empty) { EmployeeAge = GeneratingData.CalculateAge(GeneratingData.GenerateBirthdate(PersonalNo)); if (EmployeeAge < 16) { validationMessage = "Persons younger than 16 years old can not be employed."; CanSave = false; } } } else if (name == nameof(Sex)) { if (!string.IsNullOrWhiteSpace(Sex)) { var sexToLower = Sex.ToLower(); if (sexToLower != "m" && sexToLower != "f" && sexToLower != "x") { validationMessage = "Please use letter 'm' for male,'f' for female sex or 'x' for other!"; CanSave = false; } } } else if (name == nameof(RegistrationNumber)) { if (RegistrationNumber.Length != 9 || !validate.IsDigitsOnly(RegistrationNumber)) { validationMessage = "Invalid registration number format!"; CanSave = false; } if (!validate.IsUniqueRegistrationNo(RegistrationNumber, db.LoadRegistrationNumbers())) { validationMessage = "Registartion number must be unique!"; CanSave = false; } } if (string.IsNullOrEmpty(validationMessage)) { CanSave = true; } return(validationMessage); } }
public void SetBMIClass(DataTable bmiData) { //get the last bmi observation if (BMIs.Count() > 0 && (Sex.ToLower() == "male" || Sex.ToLower() == "female")) { //determine the age at the last observation var lastObs = BMIs.Last(); double ageInMonths = (lastObs.Date.Subtract(Date_Of_Birth).TotalDays / 365.25) * 12; //if over 20 use standard bmi if (ageInMonths > 20 * 12) { if (lastObs.Measurement < (decimal)18.5) { BMIClass = BMIClassification.Underweight; } else if (lastObs.Measurement < (decimal)25.0) { BMIClass = BMIClassification.Normal; } else if (lastObs.Measurement < (decimal)25.0) { BMIClass = BMIClassification.Overweight; } else { BMIClass = BMIClassification.Obese; } } else if (ageInMonths > 24) { //otherwise use the childhood chart //round the age in months to the nearest .5 ageInMonths = Math.Round(ageInMonths) + .5; //select the data rows that are relevant var results = from myRow in bmiData.AsEnumerable() where myRow.Field <string>("age_in_months") == ageInMonths.ToString() && Sex.ToLower() == myRow.Field <string>("gender") select myRow; //if var underweight = from row in results where row.Field <string>("bmi_percentile") == "0.5" select row; var normal = from row in results where row.Field <string>("bmi_percentile") == "0.85" select row; var overweight = from row in results where row.Field <string>("bmi_percentile") == "0.95" select row; if (lastObs.Measurement < Decimal.Parse(underweight.First().Field <string>("bmi"))) { BMIClass = BMIClassification.Underweight; } else if (lastObs.Measurement < Decimal.Parse(normal.First().Field <string>("bmi"))) { BMIClass = BMIClassification.Normal; } else if (lastObs.Measurement < Decimal.Parse(overweight.First().Field <string>("bmi"))) { BMIClass = BMIClassification.Overweight; } else { BMIClass = BMIClassification.Obese; } } else { BMIClass = BMIClassification.Normal; } } else { //if there are no observations just set it to normal BMIClass = BMIClassification.Normal; } }
public override string ToString() { StringBuilder sb = new StringBuilder(base.ToString()); sb.Append("USR"); if (IsOnline.HasValue) { sb.AppendFormat("-A{0}", IsOnline.Value ? "1" : "0"); } if (!string.IsNullOrEmpty(Vorname)) { sb.AppendFormat("-B{0}", Vorname.ToLower()); } if (!string.IsNullOrEmpty(Name)) { sb.AppendFormat("-C{0}", Name.ToLower()); } if (!string.IsNullOrEmpty(Sex)) { sb.AppendFormat("-D{0}", Sex.ToLower()); } if (!string.IsNullOrEmpty(RelationStatus)) { sb.AppendFormat("-E{0}", RelationStatus.ToLower()); } if (!string.IsNullOrEmpty(AttractedTo)) { sb.AppendFormat("-F{0}", AttractedTo.ToLower()); } if (!string.IsNullOrEmpty(EyeColor)) { sb.AppendFormat("-G{0}", EyeColor.ToLower()); } if (!string.IsNullOrEmpty(HairColor)) { sb.AppendFormat("-H{0}", HairColor.ToLower()); } if (BodyHeightFrom.HasValue) { sb.AppendFormat("-I{0}", BodyHeightFrom.Value); } if (BodyHeightTo.HasValue) { sb.AppendFormat("-J{0}", BodyHeightTo.Value); } if (BodyWeightFrom.HasValue) { sb.AppendFormat("-K{0}", BodyWeightFrom.Value); } if (BodyWeightTo.HasValue) { sb.AppendFormat("-L{0}", BodyWeightTo.Value); } if (AgeFrom.HasValue) { sb.AppendFormat("-M{0}", AgeFrom.Value); } if (AgeTo.HasValue) { sb.AppendFormat("-N{0}", AgeTo.Value); } if (CommunityIDMember.HasValue) { sb.AppendFormat("-O{0}", CommunityIDMember.Value); } if (!string.IsNullOrEmpty(AddressCity)) { sb.AppendFormat("-P{0}", AddressCity.ToLower()); } if (!string.IsNullOrEmpty(AddressZip)) { sb.AppendFormat("-Q{0}", AddressZip.ToLower()); } if (!string.IsNullOrEmpty(AddressLand)) { sb.AppendFormat("-R0}", AddressLand.ToLower()); } if (AddressRangeKM.HasValue) { sb.AppendFormat("-S{0}", AddressRangeKM.Value); } if (!string.IsNullOrEmpty(InterestTopic)) { sb.AppendFormat("-T0}", InterestTopic.ToLower()); } if (!string.IsNullOrEmpty(Interesst)) { sb.AppendFormat("-U0}", Interesst.ToLower()); } if (!string.IsNullOrEmpty(Talent)) { sb.AppendFormat("-V0}", Talent.ToLower()); } if (ForObjectType.HasValue) { sb.AppendFormat("-W{0}", ForObjectType.Value); } if (LoadVisits.HasValue) { sb.AppendFormat("-X{0}", LoadVisits.Value ? "1" : "0"); } return(sb.ToString()); }