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 757ab0a..e2eafdd 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 @@ -1,4 +1,6 @@  +using System.IO; + namespace Accounting_Time_It_Company.Entities; public class Vacation @@ -7,16 +9,19 @@ public class Vacation public int EmployeeId { get; private set; } + public int Director { get; private set; } + public DateTime StartDate { get; private set; } public DateTime EndDate { get; private set; } - public static Vacation CreateOpeartion(int id, int EmployeeId, DateTime startDate, DateTime endDate) + public static Vacation CreateOpeartion(int id, int director, int employeeId, DateTime startDate, DateTime endDate) { return new Vacation { Id = id, - EmployeeId = EmployeeId, + Director = director, + 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 d055226..892b2ba 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.Designer.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormVacation.Designer.cs index e9e6149..e9ff6b0 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormVacation.Designer.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormVacation.Designer.cs @@ -36,6 +36,8 @@ dateTimePickerEndDate = new DateTimePicker(); buttonCansle = new Button(); buttonSave = new Button(); + comboBoxDirector = new ComboBox(); + labelDirector = new Label(); SuspendLayout(); // // labelEmployee @@ -58,7 +60,7 @@ // // dateTimePickerStartDate // - dateTimePickerStartDate.Location = new Point(112, 40); + dateTimePickerStartDate.Location = new Point(112, 75); dateTimePickerStartDate.Name = "dateTimePickerStartDate"; dateTimePickerStartDate.Size = new Size(203, 27); dateTimePickerStartDate.TabIndex = 2; @@ -66,7 +68,7 @@ // labelStartDate // labelStartDate.AutoSize = true; - labelStartDate.Location = new Point(12, 45); + labelStartDate.Location = new Point(12, 80); labelStartDate.Name = "labelStartDate"; labelStartDate.Size = new Size(64, 20); labelStartDate.TabIndex = 3; @@ -75,7 +77,7 @@ // labelEndDate // labelEndDate.AutoSize = true; - labelEndDate.Location = new Point(12, 79); + labelEndDate.Location = new Point(12, 114); labelEndDate.Name = "labelEndDate"; labelEndDate.Size = new Size(56, 20); labelEndDate.TabIndex = 4; @@ -83,14 +85,14 @@ // // dateTimePickerEndDate // - dateTimePickerEndDate.Location = new Point(112, 74); + dateTimePickerEndDate.Location = new Point(112, 109); dateTimePickerEndDate.Name = "dateTimePickerEndDate"; dateTimePickerEndDate.Size = new Size(203, 27); dateTimePickerEndDate.TabIndex = 5; // // buttonCansle // - buttonCansle.Location = new Point(221, 123); + buttonCansle.Location = new Point(221, 158); buttonCansle.Name = "buttonCansle"; buttonCansle.Size = new Size(94, 29); buttonCansle.TabIndex = 24; @@ -100,7 +102,7 @@ // // buttonSave // - buttonSave.Location = new Point(112, 123); + buttonSave.Location = new Point(112, 158); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); buttonSave.TabIndex = 23; @@ -108,11 +110,31 @@ buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += ButtonSave_Click; // + // comboBoxDirector + // + comboBoxDirector.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxDirector.FormattingEnabled = true; + comboBoxDirector.Location = new Point(112, 40); + comboBoxDirector.Name = "comboBoxDirector"; + comboBoxDirector.Size = new Size(203, 28); + comboBoxDirector.TabIndex = 26; + // + // labelDirector + // + labelDirector.AutoSize = true; + labelDirector.Location = new Point(12, 43); + labelDirector.Name = "labelDirector"; + labelDirector.Size = new Size(79, 20); + labelDirector.TabIndex = 25; + labelDirector.Text = "Директор:"; + // // FormVacation // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(321, 157); + ClientSize = new Size(321, 194); + Controls.Add(comboBoxDirector); + Controls.Add(labelDirector); Controls.Add(buttonCansle); Controls.Add(buttonSave); Controls.Add(dateTimePickerEndDate); @@ -138,5 +160,7 @@ private DateTimePicker dateTimePickerEndDate; private Button buttonCansle; private Button buttonSave; + private ComboBox comboBoxDirector; + private Label labelDirector; } } \ No newline at end of file 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 86adb0f..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,5 +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 { @@ -7,26 +9,33 @@ 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)); - comboBoxEmployee.DataSource = employeeRepositories.ReadEmployees(); + List DirectorId = postRepositories.ReadPosts().Where(y => y.NamePost == TypePost.Director).Select(y => y.Id).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("Имеются незаполненные поля"); } - _vacationRepositories.CreateVacation(Vacation.CreateOpeartion(0, (int)comboBoxEmployee.SelectedValue!, + _vacationRepositories.CreateVacation(Vacation.CreateOpeartion(0, (int)comboBoxDirector.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, dateTimePickerStartDate.Value, dateTimePickerEndDate.Value)); Close(); diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/Implementations/VacationRepositories.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/Implementations/VacationRepositories.cs index 55a4544..c91083e 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/Implementations/VacationRepositories.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/Implementations/VacationRepositories.cs @@ -29,7 +29,7 @@ public class VacationRepositories : IVacationRepositories connection.Open(); var queryInsert = @" INSERT INTO Vacation - VALUES (DEFAULT, @EmployeeId, @StartDate, @EndDate)"; + VALUES (DEFAULT, @Director, @EmployeeId, @StartDate, @EndDate)"; connection.Execute(queryInsert, vacation); } catch (Exception ex)