public EmployeeSetup(Guid selectedDepartmentId, decimal id) { InitializeComponent(); _db = Main.Db; _selectedDepartmentId = selectedDepartmentId; AddButton.Visible = false; _selectedEmployee = _db.Empoyee.First(l => l.ID == id); empoyeeBindingSource.DataSource = _selectedEmployee; var age = (DateTime.Today.Year - _selectedEmployee.DateOfBirth.Year); if (_selectedEmployee.DateOfBirth.AddYears(age) > DateTime.Today) { age--; } AgeValueLabel.Text = "" + age; }
private void AddButton_Click(object sender, EventArgs e) { if (!ValidValue()) { StateLabel.Text = "Не корректные данные"; return; } var newEmployee = new Empoyee() { FirstName = NameTextBox.Text, SurName = SurNameTextBox.Text, Patronymic = PatronymicTextBox.Text, DocNumber = DocNumberTextBox.Text, DocSeries = DocSeriesTextBox.Text, DepartmentID = _selectedDepartmentId, DateOfBirth = BirthDayDateTimePicker.Value, Position = PositionTextBox.Text }; _db.Empoyee.Add(newEmployee); _db.SaveChanges(); Changed?.Invoke(); }