From 718ef76f20682c88fafa54040a504df69cff3a2f Mon Sep 17 00:00:00 2001 From: Pipiaka Date: Mon, 16 Dec 2024 21:10:06 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=88=D0=B0?= =?UTF-8?q?=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/TempWorkTime.cs | 17 ++ .../Entities/TypeJob.cs | 22 ++- .../Entities/Vacation.cs | 5 +- .../FormCompany.Designer.cs | 15 +- .../Accounting-Time-It-Company/FormCompany.cs | 14 ++ .../Forms/FormEmployeeReport.Designer.cs | 162 ++++++++++++++++++ .../Forms/FormEmployeeReport.cs | 82 +++++++++ .../Forms/FormEmployeeReport.resx | 120 +++++++++++++ .../Forms/FormTypeJob.cs | 2 +- .../Forms/FormVacation.Designer.cs | 42 ++++- .../Forms/FormVacation.cs | 9 +- .../Reports/TableReport.cs | 33 ++-- .../Repositories/IVacationRepositories.cs | 2 +- .../Implementations/TypeJobRepositories.cs | 19 +- .../Implementations/VacationRepositories.cs | 5 +- 15 files changed, 505 insertions(+), 44 deletions(-) create mode 100644 Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/TempWorkTime.cs create mode 100644 Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.Designer.cs create mode 100644 Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.cs create mode 100644 Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.resx diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/TempWorkTime.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/TempWorkTime.cs new file mode 100644 index 0000000..24a5ca2 --- /dev/null +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/TempWorkTime.cs @@ -0,0 +1,17 @@ + +using Accounting_Time_It_Company.Entities.Enums; + +namespace Accounting_Time_It_Company.Entities; + +public class TempWorkTime +{ + public int Id { get; private set; } + public int ProductId { get; private set; } + public int DirectorId { get; private set; } + public string Description { get; private set; } = string.Empty; + public int AllowanceForJob { get; private set; } + public DateTime Date { get; private set; } + public int EmployeeId { get; private set; } + public int Hours { get; private set; } + public TypePost NamePost { get; private set; } +} diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/TypeJob.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/TypeJob.cs index 84379ab..55c4f03 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/TypeJob.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Entities/TypeJob.cs @@ -7,7 +7,7 @@ public class TypeJob public int ProductId { get; private set; } - public int Director { get; private set; } + public int DirectorId { get; private set; } public string Description { get; private set; } = string.Empty; @@ -19,14 +19,14 @@ public class TypeJob public IEnumerable WorkTimesManager { get; private set; } = []; - public static TypeJob CreateOperation(int id, int productId, int director, string discription, int allowanceForJob, + public static TypeJob CreateOperation(int id, int productId, int directorId, string discription, int allowanceForJob, IEnumerable workTimesDevelop, IEnumerable workTimesManager) { return new TypeJob { Id = id, ProductId = productId, - Director = director, + DirectorId = directorId, Description = discription, AllowanceForJob = allowanceForJob, Date = DateTime.Now, @@ -34,4 +34,20 @@ public class TypeJob WorkTimesManager = workTimesManager }; } + + public static TypeJob CreateOperation(TempWorkTime tempWorkTime, + IEnumerable workTimesDevelop, IEnumerable workTimesManager) + { + return new TypeJob + { + Id = tempWorkTime.Id, + ProductId = tempWorkTime.ProductId, + DirectorId = tempWorkTime.DirectorId, + Description = tempWorkTime.Description, + AllowanceForJob = tempWorkTime.AllowanceForJob, + Date = tempWorkTime.Date, + WorkTimesDevelop = workTimesDevelop, + WorkTimesManager = workTimesManager + }; + } } 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..3f1ccfa 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 @@ -5,17 +5,20 @@ public class Vacation { public int Id { get; private set; } + 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 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, StartDate = startDate, EndDate = endDate diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/FormCompany.Designer.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/FormCompany.Designer.cs index 7dabb14..06a8224 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/FormCompany.Designer.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/FormCompany.Designer.cs @@ -39,6 +39,7 @@ typeJobsРаботуToolStripMenuItem = new ToolStripMenuItem(); reportsToolStripMenuItem = new ToolStripMenuItem(); DirectoryReportToolStripMenuItem = new ToolStripMenuItem(); + WorkAndCheelEmpToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -110,7 +111,7 @@ // // reportsToolStripMenuItem // - reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem }); + reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, WorkAndCheelEmpToolStripMenuItem }); reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; reportsToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W; reportsToolStripMenuItem.Size = new Size(73, 24); @@ -119,10 +120,19 @@ // DirectoryReportToolStripMenuItem // DirectoryReportToolStripMenuItem.Name = "DirectoryReportToolStripMenuItem"; - DirectoryReportToolStripMenuItem.Size = new Size(294, 26); + DirectoryReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W; + DirectoryReportToolStripMenuItem.Size = new Size(350, 26); DirectoryReportToolStripMenuItem.Text = "Документ со справочниками"; DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click; // + // WorkAndCheelEmpToolStripMenuItem + // + WorkAndCheelEmpToolStripMenuItem.Name = "WorkAndCheelEmpToolStripMenuItem"; + WorkAndCheelEmpToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.E; + WorkAndCheelEmpToolStripMenuItem.Size = new Size(350, 26); + WorkAndCheelEmpToolStripMenuItem.Text = "Работа и отдых сотрудников"; + WorkAndCheelEmpToolStripMenuItem.Click += WorkAndCheelEmpToolStripMenuItem_Click; + // // FormCompany // AutoScaleDimensions = new SizeF(8F, 20F); @@ -154,5 +164,6 @@ private ToolStripMenuItem reportsToolStripMenuItem; private ToolStripMenuItem EmployeesToolStripMenuItem; private ToolStripMenuItem DirectoryReportToolStripMenuItem; + private ToolStripMenuItem WorkAndCheelEmpToolStripMenuItem; } } diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/FormCompany.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/FormCompany.cs index 0074f60..ce20805 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/FormCompany.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/FormCompany.cs @@ -1,4 +1,5 @@ using Accounting_Time_It_Company.Forms; +using Accounting_Time_It_Company.Reports; using Unity; namespace Accounting_Time_It_Company @@ -103,5 +104,18 @@ namespace Accounting_Time_It_Company MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void WorkAndCheelEmpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.Designer.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.Designer.cs new file mode 100644 index 0000000..b818716 --- /dev/null +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.Designer.cs @@ -0,0 +1,162 @@ +namespace Accounting_Time_It_Company.Forms +{ + partial class FormEmployeeReport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonPath = new Button(); + buttonBuild = new Button(); + comboBoxEmployee = new ComboBox(); + dateTimePickerEndDate = new DateTimePicker(); + dateTimePickerStartDate = new DateTimePicker(); + textBoxPath = new TextBox(); + labelEmployee = new Label(); + labelStartDate = new Label(); + labelEndDate = new Label(); + labelPath = new Label(); + SuspendLayout(); + // + // buttonPath + // + buttonPath.Location = new Point(275, 39); + buttonPath.Name = "buttonPath"; + buttonPath.Size = new Size(29, 29); + buttonPath.TabIndex = 0; + buttonPath.Text = "..."; + buttonPath.UseVisualStyleBackColor = true; + buttonPath.Click += ButtonPath_Click; + // + // buttonBuild + // + buttonBuild.Location = new Point(112, 193); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(125, 29); + buttonBuild.TabIndex = 1; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += ButtonBuild_Click; + // + // comboBoxEmployee + // + comboBoxEmployee.FormattingEnabled = true; + comboBoxEmployee.Location = new Point(144, 74); + comboBoxEmployee.Name = "comboBoxEmployee"; + comboBoxEmployee.Size = new Size(160, 28); + comboBoxEmployee.TabIndex = 2; + // + // dateTimePickerEndDate + // + dateTimePickerEndDate.Location = new Point(144, 150); + dateTimePickerEndDate.Name = "dateTimePickerEndDate"; + dateTimePickerEndDate.Size = new Size(160, 27); + dateTimePickerEndDate.TabIndex = 3; + // + // dateTimePickerStartDate + // + dateTimePickerStartDate.Location = new Point(144, 112); + dateTimePickerStartDate.Name = "dateTimePickerStartDate"; + dateTimePickerStartDate.Size = new Size(160, 27); + dateTimePickerStartDate.TabIndex = 4; + // + // textBoxPath + // + textBoxPath.Location = new Point(144, 41); + textBoxPath.Name = "textBoxPath"; + textBoxPath.Size = new Size(125, 27); + textBoxPath.TabIndex = 5; + // + // labelEmployee + // + labelEmployee.AutoSize = true; + labelEmployee.Location = new Point(12, 79); + labelEmployee.Name = "labelEmployee"; + labelEmployee.Size = new Size(74, 20); + labelEmployee.TabIndex = 6; + labelEmployee.Text = "Работник"; + // + // labelStartDate + // + labelStartDate.AutoSize = true; + labelStartDate.Location = new Point(12, 114); + labelStartDate.Name = "labelStartDate"; + labelStartDate.Size = new Size(28, 20); + labelStartDate.TabIndex = 7; + labelStartDate.Text = "С -"; + // + // labelEndDate + // + labelEndDate.AutoSize = true; + labelEndDate.Location = new Point(12, 152); + labelEndDate.Name = "labelEndDate"; + labelEndDate.Size = new Size(43, 20); + labelEndDate.TabIndex = 8; + labelEndDate.Text = "По - "; + // + // labelPath + // + labelPath.AutoSize = true; + labelPath.Location = new Point(12, 41); + labelPath.Name = "labelPath"; + labelPath.Size = new Size(109, 20); + labelPath.TabIndex = 9; + labelPath.Text = "Путь до файла"; + // + // FormEmployeeReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(380, 248); + Controls.Add(labelPath); + Controls.Add(labelEndDate); + Controls.Add(labelStartDate); + Controls.Add(labelEmployee); + Controls.Add(textBoxPath); + Controls.Add(dateTimePickerStartDate); + Controls.Add(dateTimePickerEndDate); + Controls.Add(comboBoxEmployee); + Controls.Add(buttonBuild); + Controls.Add(buttonPath); + Name = "FormEmployeeReport"; + Text = "FormEmployeeReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonPath; + private Button buttonBuild; + private ComboBox comboBoxEmployee; + private DateTimePicker dateTimePickerEndDate; + private DateTimePicker dateTimePickerStartDate; + private TextBox textBoxPath; + private Label labelEmployee; + private Label labelStartDate; + private Label labelEndDate; + private Label labelPath; + } +} \ No newline at end of file diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.cs new file mode 100644 index 0000000..9a182eb --- /dev/null +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.cs @@ -0,0 +1,82 @@ +using Accounting_Time_It_Company.Entities.Enums; +using Accounting_Time_It_Company.Reports; +using Accounting_Time_It_Company.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace Accounting_Time_It_Company.Forms +{ + public partial class FormEmployeeReport : Form + { + private readonly IUnityContainer _container; + + public FormEmployeeReport(IUnityContainer container, IEmployeeRepositories employeeRepositories) + { + InitializeComponent(); + _container = container; + + comboBoxEmployee.DataSource = employeeRepositories.ReadEmployees().Where(x => x.PostId != (int)TypePost.Director).ToList(); + comboBoxEmployee.DisplayMember = "Name"; + comboBoxEmployee.ValueMember = "Id"; + } + + private void ButtonBuild_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxPath.Text)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + if (comboBoxEmployee.SelectedIndex < 0) + { + throw new Exception("Не выбран работник"); + } + if (dateTimePickerEndDate.Value <= dateTimePickerStartDate.Value) + { + throw new Exception("Дата начала должна быть раньше даты окончания"); + } + if + (_container.Resolve().CreateTable(textBoxPath.Text, + (int)comboBoxEmployee.SelectedValue!, + dateTimePickerStartDate.Value, dateTimePickerEndDate.Value)) + { + MessageBox.Show("Документ сформирован", "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании очета", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonPath_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Excel Files | *.xlsx" + }; + if (sfd.ShowDialog() != DialogResult.OK) + { + return; + } + textBoxPath.Text = sfd.FileName; + } + } +} + diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.resx b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Forms/FormEmployeeReport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file 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..7ac7cd9 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 @@ -67,7 +67,7 @@ namespace Accounting_Time_It_Company.Forms } list.Add(WorkTime.CreateElement(0, Convert.ToInt32(row.Cells[0].Value), Convert.ToInt32(row.Cells[1].Value))); } - return list; + return list.GroupBy(x => x.EmployeeId, x => x.Hours, (id, hours) => WorkTime.CreateElement(0, id, hours.Sum())).ToList(); } } } 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..77a67d5 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,12 +36,14 @@ dateTimePickerEndDate = new DateTimePicker(); buttonCansle = new Button(); buttonSave = new Button(); + comboBoxDirector = new ComboBox(); + labelDirector = new Label(); SuspendLayout(); // // labelEmployee // labelEmployee.AutoSize = true; - labelEmployee.Location = new Point(12, 9); + labelEmployee.Location = new Point(12, 43); labelEmployee.Name = "labelEmployee"; labelEmployee.Size = new Size(77, 20); labelEmployee.TabIndex = 0; @@ -51,14 +53,14 @@ // comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxEmployee.FormattingEnabled = true; - comboBoxEmployee.Location = new Point(112, 6); + comboBoxEmployee.Location = new Point(179, 40); comboBoxEmployee.Name = "comboBoxEmployee"; comboBoxEmployee.Size = new Size(203, 28); comboBoxEmployee.TabIndex = 1; // // dateTimePickerStartDate // - dateTimePickerStartDate.Location = new Point(112, 40); + dateTimePickerStartDate.Location = new Point(179, 74); 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, 79); 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, 113); 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(179, 108); dateTimePickerEndDate.Name = "dateTimePickerEndDate"; dateTimePickerEndDate.Size = new Size(203, 27); dateTimePickerEndDate.TabIndex = 5; // // buttonCansle // - buttonCansle.Location = new Point(221, 123); + buttonCansle.Location = new Point(288, 157); 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(179, 157); 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(179, 6); + comboBoxDirector.Name = "comboBoxDirector"; + comboBoxDirector.Size = new Size(203, 28); + comboBoxDirector.TabIndex = 26; + // + // labelDirector + // + labelDirector.AutoSize = true; + labelDirector.Location = new Point(12, 9); + labelDirector.Name = "labelDirector"; + labelDirector.Size = new Size(118, 20); + labelDirector.TabIndex = 25; + labelDirector.Text = "Ответственный:"; + // // FormVacation // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(321, 157); + ClientSize = new Size(383, 192); + 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..14fa628 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,4 +1,5 @@ using Accounting_Time_It_Company.Entities; +using Accounting_Time_It_Company.Entities.Enums; using Accounting_Time_It_Company.Repositories; namespace Accounting_Time_It_Company.Forms @@ -12,7 +13,11 @@ namespace Accounting_Time_It_Company.Forms InitializeComponent(); _vacationRepositories = vacationRepositories ?? throw new ArgumentNullException(nameof(vacationRepositories)); - comboBoxEmployee.DataSource = employeeRepositories.ReadEmployees(); + comboBoxDirector.DataSource = employeeRepositories.ReadEmployees().Where(x => x.PostId == (int)TypePost.Director).ToList(); + comboBoxDirector.DisplayMember = "Name"; + comboBoxDirector.ValueMember = "Id"; + + comboBoxEmployee.DataSource = employeeRepositories.ReadEmployees().Where(x => x.PostId != (int)TypePost.Director).ToList(); comboBoxEmployee.DisplayMember = "Name"; comboBoxEmployee.ValueMember = "Id"; } @@ -26,7 +31,7 @@ namespace Accounting_Time_It_Company.Forms 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/Reports/TableReport.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Reports/TableReport.cs index 0aa09ea..637d3b0 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/Reports/TableReport.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Reports/TableReport.cs @@ -2,6 +2,8 @@ using Accounting_Time_It_Company.Entities; using Accounting_Time_It_Company.Repositories; using Microsoft.Extensions.Logging; +using System.Diagnostics.Metrics; +using System.Linq; namespace Accounting_Time_It_Company.Reports; @@ -11,7 +13,7 @@ internal class TableReport private readonly IVacationRepositories _vacationRepositories; private readonly ILogger _logger; - internal static readonly string[] item = ["Сотрудник", "Дата", "Количество пришло", "Количество ушло"]; + internal static readonly string[] item = ["Ответственный", "Дата", "Отработано часов", "Дней отпуска"]; public TableReport(ITypeJobRepositories typeJobRepositories, IVacationRepositories vacationRepositories, ILogger logger) @@ -25,14 +27,14 @@ internal class TableReport _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } - public bool CreateTable(string filePath, int feedId, DateTime startDate, DateTime endDate) + public bool CreateTable(string filePath, int employeeId, DateTime startDate, DateTime endDate) { try { new ExcelBuilder(filePath) - .AddHeader("Сводка по работе сотрудников", 0, 4) + .AddHeader("Сводка по работе сотрудников", 0, 6) .AddParagraph("за период", 0) - .AddTable([10, 10, 15, 15], GetData(feedId, startDate, endDate)).Build(); + .AddTable([10, 10, 15, 15], GetData(employeeId, startDate, endDate)).Build(); return true; } catch (Exception ex) @@ -44,18 +46,17 @@ internal class TableReport private List GetData(int employeeId, DateTime startDate, DateTime endDate) { + // бяда var data = _typeJobRepositories .ReadTypeJobs() .Where(x => x.Date >= startDate && x.Date <= endDate && (x.WorkTimesDevelop.Any(y => y.EmployeeId == employeeId) || x.WorkTimesManager.Any(y => y.EmployeeId == employeeId))) .Select(x => new { - x.ProductId, + x.DirectorId, x.Date, - CountInManager = x.WorkTimesManager.FirstOrDefault(y => y.EmployeeId == employeeId)?.Hours, - CountOutManager = (int?)null, - CountInDevelop = x.WorkTimesDevelop.FirstOrDefault(y => y.EmployeeId == employeeId)?.Hours, - CountOutDevelop = (int?)null + CountIn = x.WorkTimesManager.Concat(x.WorkTimesDevelop).FirstOrDefault(y => y.EmployeeId == employeeId)?.Hours, + CountOut = (int?)null, }) .Union(_vacationRepositories .ReadVacations() @@ -63,21 +64,19 @@ internal class TableReport && x.StartDate <= endDate && x.EmployeeId == employeeId) .Select(x => new { - x.EmployeeId, + x.DirectorId, Date = x.StartDate, CountIn = (int?)null, - CountOut = (int?)x.Ration + CountOut = (int?)(x.EndDate - x.StartDate).TotalDays, })) .OrderBy(x => x.Date); - return - new List() { item } + return new List() { item } .Union(data.Select(x => new string[] { - x.EmployeeId.ToString(), x.Date.ToString(), x.CountIn?.ToString() ?? - string.Empty, x.CountOut?.ToString() ?? string.Empty})) + x.DirectorId.ToString(), x.Date.ToString(), + x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty})) .Union( - [["Всего", "", data.Sum(x => x.CountIn ?? 0).ToString(), - data.Sum(x => x.CountOut ?? 0).ToString()]]) + [["Всего", "", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) .ToList(); } } diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/IVacationRepositories.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/IVacationRepositories.cs index 8e7274e..b7fc9c7 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/IVacationRepositories.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/IVacationRepositories.cs @@ -6,7 +6,7 @@ public interface IVacationRepositories { IEnumerable ReadVacations(DateTime? startDateFrom = null, DateTime? startDateTo = null, DateTime? endDateFrom = null, DateTime? endtDateTo = null, - int? employeeId = null); + int? employeeId = null, int? directorId = null); void CreateVacation(Vacation vacation); } diff --git a/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/Implementations/TypeJobRepositories.cs b/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/Implementations/TypeJobRepositories.cs index 06be784..3226b9d 100644 --- a/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/Implementations/TypeJobRepositories.cs +++ b/Accounting-Time-It-Company/Accounting-Time-It-Company/Repositories/Implementations/TypeJobRepositories.cs @@ -1,4 +1,5 @@ using Accounting_Time_It_Company.Entities; +using Accounting_Time_It_Company.Entities.Enums; using Dapper; using Microsoft.Extensions.Logging; using Newtonsoft.Json; @@ -30,7 +31,7 @@ public class TypeJobRepositories : ITypeJobRepositories using var transaction = connection.BeginTransaction(); var queryInsert = @" INSERT INTO TypeJob - VALUES (DEFAULT, @ProductId, @Director, @Description, @AllowanceForJob, @Date); + VALUES (DEFAULT, @ProductId, @DirectorId, @Description, @AllowanceForJob, @Date); SELECT MAX(Id) FROM TypeJob"; var typeJobId = connection.QueryFirst(queryInsert, typeJob, transaction); var querySubInsert = @" @@ -92,11 +93,17 @@ public class TypeJobRepositories : ITypeJobRepositories { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); connection.Open(); - var querySelect = @"SELECT * FROM TypeJob"; - var typeJobs = connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", - JsonConvert.SerializeObject(typeJobs)); - return typeJobs; + var querySelect = @"SELECT tj.*, wt.EmployeeId, wt.Hours, p.namepost + FROM TypeJob tj + INNER JOIN WorkTime wt ON wt.typejobid = tj.id + INNER JOIN Employee e ON e.id = wt.employeeid + INNER JOIN Post p ON p.id = e.PostId;"; + var typeJobs = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(typeJobs)); + return typeJobs.GroupBy(x => x.Id, y => y, + (key, value) => TypeJob.CreateOperation(value.First(), + value.Where(z => z.NamePost == TypePost.Developer).Select(h => WorkTime.CreateElement(0, h.EmployeeId, h.Hours)).ToList(), + value.Where(z => z.NamePost == TypePost.Manager).Select(h => WorkTime.CreateElement(0, h.EmployeeId, h.Hours)).ToList())).ToList(); } catch (Exception ex) { 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..317f494 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, @DirectorId, @EmployeeId, @StartDate, @EndDate)"; connection.Execute(queryInsert, vacation); } catch (Exception ex) @@ -40,7 +40,8 @@ public class VacationRepositories : IVacationRepositories } public IEnumerable ReadVacations(DateTime? startDateFrom = null, DateTime? startDateTo = null, - DateTime? endDateFrom = null, DateTime? endtDateTo = null, int? employeeId = null) + DateTime? endDateFrom = null, DateTime? endtDateTo = null, + int? employeeId = null, int? directorId = null) { _logger.LogInformation("Получение всех объектов"); try