diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/Vacation.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/Vacation.cs index 3f1ccfa..1c803e4 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/Vacation.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/Vacation.cs @@ -8,18 +8,17 @@ public class Vacation public int DirectorId { get; private set; } public int EmployeeId { get; private set; } - public DateTime StartDate { get; private set; } public DateTime EndDate { get; private set; } - public static Vacation CreateOpeartion(int id, int directorId, int EmployeeId, DateTime startDate, DateTime endDate) + public static Vacation CreateOpeartion(int id, int directorId, int employeeId, DateTime startDate, DateTime endDate) { return new Vacation { Id = id, DirectorId = directorId, - EmployeeId = EmployeeId, + EmployeeId = employeeId, StartDate = startDate, EndDate = endDate }; diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormTypeJob.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormTypeJob.cs index 7ac7cd9..aaa8a69 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormTypeJob.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormTypeJob.cs @@ -1,6 +1,7 @@ using Accounting_Time_It_Company.Entities; using Accounting_Time_It_Company.Entities.Enums; using Accounting_Time_It_Company.Repositories; +using Accounting_Time_It_Company.Repositories.Implementations; using System.Data; namespace Accounting_Time_It_Company.Forms @@ -10,7 +11,7 @@ namespace Accounting_Time_It_Company.Forms private readonly ITypeJobRepositories _typeJobRepositories; public FormTypeJob(ITypeJobRepositories typeJobRepositories, IProductRepositories productRepositories, - IEmployeeRepositories employeeRepositories) + IEmployeeRepositories employeeRepositories, IPostRepositories postRepositories) { InitializeComponent(); _typeJobRepositories = typeJobRepositories ?? throw new ArgumentNullException(nameof(typeJobRepositories)); @@ -19,15 +20,19 @@ namespace Accounting_Time_It_Company.Forms comboBoxProduct.DisplayMember = "Name"; comboBoxProduct.ValueMember = "Id"; - comboBoxDirector.DataSource = employeeRepositories.ReadEmployees().Where(x => x.PostId == (int)TypePost.Director).ToList(); + List DirectorId = postRepositories.ReadPosts().Where(y => y.NamePost == TypePost.Director).Select(y => y.Id).ToList(); + List ManagerId = postRepositories.ReadPosts().Where(y => y.NamePost == TypePost.Manager).Select(y => y.Id).ToList(); + List DeveloperId = postRepositories.ReadPosts().Where(y => y.NamePost == TypePost.Developer).Select(y => y.Id).ToList(); + + comboBoxDirector.DataSource = employeeRepositories.ReadEmployees().Where(x => DirectorId.Any(z => z == x.PostId)).ToList(); comboBoxDirector.DisplayMember = "Name"; comboBoxDirector.ValueMember = "Id"; - ColumnDevelop.DataSource = employeeRepositories.ReadEmployees().Where(x => x.PostId == (int)TypePost.Developer).ToList(); + ColumnDevelop.DataSource = employeeRepositories.ReadEmployees().Where(x => DeveloperId.Any(z => z == x.PostId)).ToList(); ColumnDevelop.DisplayMember = "Name"; ColumnDevelop.ValueMember = "Id"; - ColumnManager.DataSource = employeeRepositories.ReadEmployees().Where(x => x.PostId == (int)TypePost.Manager).ToList(); + ColumnManager.DataSource = employeeRepositories.ReadEmployees().Where(x => ManagerId.Any(z => z == x.PostId)).ToList(); ColumnManager.DisplayMember = "Name"; ColumnManager.ValueMember = "Id"; } diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormVacation.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormVacation.cs index 14fa628..a1ee55f 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormVacation.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormVacation.cs @@ -1,6 +1,7 @@ using Accounting_Time_It_Company.Entities; using Accounting_Time_It_Company.Entities.Enums; using Accounting_Time_It_Company.Repositories; +using Accounting_Time_It_Company.Repositories.Implementations; namespace Accounting_Time_It_Company.Forms { @@ -8,25 +9,28 @@ namespace Accounting_Time_It_Company.Forms { private readonly IVacationRepositories _vacationRepositories; - public FormVacation(IVacationRepositories vacationRepositories, IEmployeeRepositories employeeRepositories) + public FormVacation(IVacationRepositories vacationRepositories, IEmployeeRepositories employeeRepositories, IPostRepositories postRepositories) { InitializeComponent(); _vacationRepositories = vacationRepositories ?? throw new ArgumentNullException(nameof(vacationRepositories)); - comboBoxDirector.DataSource = employeeRepositories.ReadEmployees().Where(x => x.PostId == (int)TypePost.Director).ToList(); - comboBoxDirector.DisplayMember = "Name"; - comboBoxDirector.ValueMember = "Id"; + List DirectorId = postRepositories.ReadPosts().Where(y => y.NamePost == TypePost.Director).Select(y => y.Id).ToList(); - comboBoxEmployee.DataSource = employeeRepositories.ReadEmployees().Where(x => x.PostId != (int)TypePost.Director).ToList(); + comboBoxEmployee.DataSource = employeeRepositories.ReadEmployees().Where(x => DirectorId.Any(z => z != x.PostId)).ToList(); comboBoxEmployee.DisplayMember = "Name"; comboBoxEmployee.ValueMember = "Id"; + + comboBoxDirector.DataSource = employeeRepositories.ReadEmployees().Where(x => DirectorId.Any(z => z == x.PostId)).ToList(); + comboBoxDirector.DisplayMember = "Name"; + comboBoxDirector.ValueMember = "Id"; } private void ButtonSave_Click(object sender, EventArgs e) { try { - if (comboBoxEmployee.SelectedIndex < 0) + if (comboBoxEmployee.SelectedIndex < 0 || comboBoxDirector.SelectedIndex < 0 || + dateTimePickerStartDate.Value >= dateTimePickerEndDate.Value) { throw new Exception("Имеются незаполненные поля"); }