public void OnUpdatePersonCliked(object sender, EventArgs e) { if (_view.SelectedPersonIndex >= 0 && _view.SelectedPersonIndex < FirstPageView.persons.Count) { if (DateTime.Compare(_view.BirthDate, _view.MissingDate) <= 0) { _model.FindPerson(_view.SelectedPersonName); _model.CurrentPerson.BirthDate = _view.BirthDate.ToString(); _model.CurrentPerson.MissingDate = _view.MissingDate.ToString(); _model.CurrentPerson.AdditionalInfo = _view.AdditionalInfo; string updateMessage = Properties.Resources.AddPersonInfoUpdatedMsg; // to do: class with method 'checkphotosvalidation' if (picSelected) { int viablePicsCount = 0; picSelected = false; foreach (string filename in picFilenames) { tempImage = new Image <Bgr, byte>(filename); if (ImageHandler.GetFaceFromImage(tempImage) != null) { var face = ImageHandler.GetFaceFromImage(tempImage); var grayFace = face.Convert <Gray, Byte>(); ImageHandler.SaveGrayFacetoFile(_view.SelectedPersonName, grayFace); viablePicsCount++; } } updateMessage = String.Format(Properties.Resources.AddPersonPicturesUpdated, viablePicsCount, picFilenames.Count, Properties.Resources.AddPersonInfoUpdatedMsg); } _view.ShowMessage(updateMessage); } else { _view.ShowMessage(Properties.Resources.AddPersonNotValidDatesError); } } else { _view.ShowMessage(Properties.Resources.AddPersonNoSelectedPersonError); } }
public void OnUpdatePersonCliked(object sender, EventArgs e) { if (_view.SelectedPersonIndex >= 0 && _view.SelectedPersonIndex < _data.GetPersonsCount()) { if (DateTime.Compare(_view.BirthDate, _view.MissingDate) <= 0) { _model.CurrentPerson = _view.SelectedPerson; _model.CurrentPerson.BirthDate = _view.BirthDate.ToString(); _model.CurrentPerson.MissingDate = _view.MissingDate.ToString(); _model.CurrentPerson.AdditionalInfo = _view.AdditionalInfo; string updateMessage = Properties.Resources.AddPersonInfoUpdatedMsg; // to do: class with method 'checkphotosvalidation' if (picSelected) { int viablePicsCount = 0; picSelected = false; string personName = _model.CurrentPerson.Name; personName = personName.Replace(" ", "_"); foreach (string filename in picFilenames) { tempImage = new Image <Bgr, byte>(filename); var faceImage = PersonRecognizer.Instance.GetFaceFromImage(tempImage); if (faceImage != null) { Image <Gray, byte> grayFace = PersonRecognizer.Instance.ConvertFaceToGray(faceImage); string faceFile = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + Settings.Default.DataFolderPath + Settings.Default.ImagesFolderPath + personName + "/"; if (!Directory.Exists(faceFile)) { Directory.CreateDirectory(faceFile); } int picNumber = 1; while (File.Exists(faceFile + picNumber + ".bmp")) { picNumber++; } grayFace.Save(faceFile + picNumber + ".bmp"); viablePicsCount++; } } updateMessage = String.Format(Properties.Resources.AddPersonPicturesUpdated, viablePicsCount, picFilenames.Count, Properties.Resources.AddPersonInfoUpdatedMsg); } _view.ShowMessage(updateMessage); } else { _view.ShowMessage(Properties.Resources.AddPersonNotValidDatesError); } } else { _view.ShowMessage(Properties.Resources.AddPersonNoSelectedPersonError); } }