Чутка подправил

This commit is contained in:
Pipiaka 2024-12-22 21:22:33 +04:00
parent 43d383e34a
commit 71e7a114de
5 changed files with 61 additions and 18 deletions

View File

@ -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
};

View File

@ -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<int> DirectorId = postRepositories.ReadPosts().Where(y => y.NamePost == TypePost.Director).Select(y => y.Id).ToList();
List<int> ManagerId = postRepositories.ReadPosts().Where(y => y.NamePost == TypePost.Manager).Select(y => y.Id).ToList();
List<int> 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";
}

View File

@ -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;
}
}

View File

@ -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<int> 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();

View File

@ -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)