private void SetValue() { foreach (var label in Controls.OfType <Label>(). Where(x => x.Name.ToLowerInvariant().Contains("value"))) { label.Text = (_prisoner.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance).SingleOrDefault( x => x.Name.ToLowerInvariant().Contains(label.Tag.ToString().ToLowerInvariant()) )).GetValue(_prisoner).ToString(); } }
/// <summary> /// Метод для заполнения формы полями обьекта Prisoner (ПКМ - change) /// </summary> private void FillingControls() { if (_addPrisoner != null) { foreach (Control control in Controls) { if (control is PictureBox) { PictureBox pictureBox = control as PictureBox; if (pictureBox.Tag.ToString().Contains("Photo1")) { pictureBox.Load(_addPrisoner.Photos.firstPhoto); photos.firstPhoto = _addPrisoner.Photos.firstPhoto; } else { pictureBox.Load(_addPrisoner.Photos.secondPhoto); photos.secondPhoto = _addPrisoner.Photos.secondPhoto; } this.progressBar1.Value += pointsPB; } else if (control is MonthCalendar) { MonthCalendar monthCalendar = control as MonthCalendar; monthCalendar.SelectionStart = Convert.ToDateTime(_addPrisoner.DateOfBirth); monthCalendar.SelectionEnd = monthCalendar.SelectionStart; monthCalendar.Select(); this.progressBar1.Value += 4; } else if (control is TextBox || control is ComboBox) { lockerForPB = true; control.Text = (_addPrisoner.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance).SingleOrDefault( p => control.Name.Contains(p.Name))).GetValue(_addPrisoner).ToString(); } } } }