From afbdd5205dfd9e29fee6fa24bccba7f59bf7a3b2 Mon Sep 17 00:00:00 2001 From: Arslan Date: Tue, 24 Dec 2024 17:10:38 +0400 Subject: [PATCH] =?UTF-8?q?3=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BuildingMaterials.cs | 23 ++ .../Entities/MaterialProcurement.cs | 26 ++ ProjectRepairWork/Entities/Repair.cs | 5 +- ProjectRepairWork/Entities/RepairRepair.cs | 3 +- .../Entities/TempRepairRepair.cs | 16 + ProjectRepairWork/FormRepairWork.Designer.cs | 64 +++- ProjectRepairWork/FormRepairWork.cs | 60 ++++ .../Forms/FormBuildingMaterial.Designer.cs | 95 ++++++ .../Forms/FormBuildingMaterial.cs | 82 +++++ .../Forms/FormBuildingMaterial.resx | 120 +++++++ .../Forms/FormBuildingMaterials.Designer.cs | 125 +++++++ .../Forms/FormBuildingMaterials.cs | 108 ++++++ .../Forms/FormBuildingMaterials.resx | 120 +++++++ .../Forms/FormDirectoryReport.Designer.cs | 99 ++++++ .../Forms/FormDirectoryReport.cs | 64 ++++ .../Forms/FormDirectoryReport.resx | 120 +++++++ .../Forms/FormMaterialProcurement.Designer.cs | 142 ++++++++ .../Forms/FormMaterialProcurement.cs | 55 +++ .../Forms/FormMaterialProcurement.resx | 120 +++++++ .../FormMaterialProcurements.Designer.cs | 97 ++++++ .../Forms/FormMaterialProcurements.cs | 57 ++++ .../Forms/FormMaterialProcurements.resx | 120 +++++++ .../Forms/FormMaterialsReport.Designer.cs | 107 ++++++ .../Forms/FormMaterialsReport.cs | 61 ++++ .../Forms/FormMaterialsReport.resx | 120 +++++++ .../Forms/FormRepair.Designer.cs | 22 ++ ProjectRepairWork/Forms/FormRepair.cs | 13 +- ProjectRepairWork/Forms/FormRepair.resx | 6 + .../Forms/FormRepairReport.Designer.cs | 164 +++++++++ ProjectRepairWork/Forms/FormRepairReport.cs | 72 ++++ ProjectRepairWork/Forms/FormRepairReport.resx | 120 +++++++ ProjectRepairWork/Program.cs | 2 + ProjectRepairWork/ProjectRepairWork.csproj | 4 + ProjectRepairWork/Reports/ChartReport.cs | 74 ++++ ProjectRepairWork/Reports/DocReport.cs | 93 ++++++ ProjectRepairWork/Reports/ExcelBuilder.cs | 316 ++++++++++++++++++ ProjectRepairWork/Reports/PdfBuilder.cs | 76 +++++ ProjectRepairWork/Reports/TableReport.cs | 95 ++++++ ProjectRepairWork/Reports/WordBuilder.cs | 131 ++++++++ .../IBuildingMaterialsRepository.cs | 18 + .../IMaterialProcurementRepository.cs | 15 + .../Repositories/IRepairRepository.cs | 1 + .../BuildingMaterialsRepository.cs | 127 +++++++ .../MaterialProcurementRepository.cs | 88 +++++ .../Implementation/RepairRepository.cs | 24 +- 45 files changed, 3453 insertions(+), 17 deletions(-) create mode 100644 ProjectRepairWork/Entities/BuildingMaterials.cs create mode 100644 ProjectRepairWork/Entities/MaterialProcurement.cs create mode 100644 ProjectRepairWork/Entities/TempRepairRepair.cs create mode 100644 ProjectRepairWork/Forms/FormBuildingMaterial.Designer.cs create mode 100644 ProjectRepairWork/Forms/FormBuildingMaterial.cs create mode 100644 ProjectRepairWork/Forms/FormBuildingMaterial.resx create mode 100644 ProjectRepairWork/Forms/FormBuildingMaterials.Designer.cs create mode 100644 ProjectRepairWork/Forms/FormBuildingMaterials.cs create mode 100644 ProjectRepairWork/Forms/FormBuildingMaterials.resx create mode 100644 ProjectRepairWork/Forms/FormDirectoryReport.Designer.cs create mode 100644 ProjectRepairWork/Forms/FormDirectoryReport.cs create mode 100644 ProjectRepairWork/Forms/FormDirectoryReport.resx create mode 100644 ProjectRepairWork/Forms/FormMaterialProcurement.Designer.cs create mode 100644 ProjectRepairWork/Forms/FormMaterialProcurement.cs create mode 100644 ProjectRepairWork/Forms/FormMaterialProcurement.resx create mode 100644 ProjectRepairWork/Forms/FormMaterialProcurements.Designer.cs create mode 100644 ProjectRepairWork/Forms/FormMaterialProcurements.cs create mode 100644 ProjectRepairWork/Forms/FormMaterialProcurements.resx create mode 100644 ProjectRepairWork/Forms/FormMaterialsReport.Designer.cs create mode 100644 ProjectRepairWork/Forms/FormMaterialsReport.cs create mode 100644 ProjectRepairWork/Forms/FormMaterialsReport.resx create mode 100644 ProjectRepairWork/Forms/FormRepairReport.Designer.cs create mode 100644 ProjectRepairWork/Forms/FormRepairReport.cs create mode 100644 ProjectRepairWork/Forms/FormRepairReport.resx create mode 100644 ProjectRepairWork/Reports/ChartReport.cs create mode 100644 ProjectRepairWork/Reports/DocReport.cs create mode 100644 ProjectRepairWork/Reports/ExcelBuilder.cs create mode 100644 ProjectRepairWork/Reports/PdfBuilder.cs create mode 100644 ProjectRepairWork/Reports/TableReport.cs create mode 100644 ProjectRepairWork/Reports/WordBuilder.cs create mode 100644 ProjectRepairWork/Repositories/IBuildingMaterialsRepository.cs create mode 100644 ProjectRepairWork/Repositories/IMaterialProcurementRepository.cs create mode 100644 ProjectRepairWork/Repositories/Implementation/BuildingMaterialsRepository.cs create mode 100644 ProjectRepairWork/Repositories/Implementation/MaterialProcurementRepository.cs diff --git a/ProjectRepairWork/Entities/BuildingMaterials.cs b/ProjectRepairWork/Entities/BuildingMaterials.cs new file mode 100644 index 0000000..413466e --- /dev/null +++ b/ProjectRepairWork/Entities/BuildingMaterials.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Entities; + +public class BuildingMaterials +{ + public int Id { get; private set; } + public string MaterialsType { get; private set; } = string.Empty; + + public static BuildingMaterials CreatEntity(int id, string materialType) + { + return new BuildingMaterials + { + Id = id, + MaterialsType = materialType, + }; + } +} + diff --git a/ProjectRepairWork/Entities/MaterialProcurement.cs b/ProjectRepairWork/Entities/MaterialProcurement.cs new file mode 100644 index 0000000..aee19ca --- /dev/null +++ b/ProjectRepairWork/Entities/MaterialProcurement.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Entities; + +public class MaterialProcurement +{ + public int Id { get; private set; } + public int MaterialsId { get; private set; } + public DateTime ProcurmentDate { get; private set; } + public int MaterialsPrice { get; private set; } + + public static MaterialProcurement CreatOpertions(int id, int materialsId, int materialsPrice) + { + return new MaterialProcurement + { + Id = id, + MaterialsId = materialsId, + ProcurmentDate = DateTime.Now, + MaterialsPrice = materialsPrice, + }; + } +} diff --git a/ProjectRepairWork/Entities/Repair.cs b/ProjectRepairWork/Entities/Repair.cs index 81d3774..5371b42 100644 --- a/ProjectRepairWork/Entities/Repair.cs +++ b/ProjectRepairWork/Entities/Repair.cs @@ -11,17 +11,20 @@ public class Repair public int Id { get; private set; } public int ContractorsId { get; private set; } public int PremisesId { get; private set; } + + public DateTime DateRepair { get; private set; } public IEnumerable RepairRepair { get; private set; } = []; - public static Repair CreatOpertions(int id, int contractorsId, int premisesId, IEnumerable repairRepair) + public static Repair CreatOpertions(int id, int contractorsId, DateTime dateRepair, int premisesId, IEnumerable repairRepair) { return new Repair { Id = id, ContractorsId = contractorsId, PremisesId = premisesId, + DateRepair = dateRepair, RepairRepair = repairRepair, }; diff --git a/ProjectRepairWork/Entities/RepairRepair.cs b/ProjectRepairWork/Entities/RepairRepair.cs index f8b5675..f346605 100644 --- a/ProjectRepairWork/Entities/RepairRepair.cs +++ b/ProjectRepairWork/Entities/RepairRepair.cs @@ -10,7 +10,7 @@ public class RepairRepair { public int Id { get; private set; } public int WorkId { get; private set; } - public int Count { get; private set; } + public int Count { get; set; } public static RepairRepair CreatElement(int id, int workId, int count) @@ -20,7 +20,6 @@ public class RepairRepair Id = id, WorkId = workId, Count = count, - }; } diff --git a/ProjectRepairWork/Entities/TempRepairRepair.cs b/ProjectRepairWork/Entities/TempRepairRepair.cs new file mode 100644 index 0000000..a0fa4f3 --- /dev/null +++ b/ProjectRepairWork/Entities/TempRepairRepair.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Entities; + +public class TempRepairRepair +{ + public int Id { get; private set; } + public int ContractorsId { get; private set; } + public int PremisesId { get; private set; } + public DateTime DateRepair { get; private set; } + public int Count { get; private set; } +} diff --git a/ProjectRepairWork/FormRepairWork.Designer.cs b/ProjectRepairWork/FormRepairWork.Designer.cs index 9b22dfb..47337e8 100644 --- a/ProjectRepairWork/FormRepairWork.Designer.cs +++ b/ProjectRepairWork/FormRepairWork.Designer.cs @@ -34,9 +34,14 @@ PremisesToolStripMenuItem = new ToolStripMenuItem(); CostToolStripMenuItem = new ToolStripMenuItem(); WorksToolStripMenuItem = new ToolStripMenuItem(); + BuildingMaterialsToolStripMenuItem = new ToolStripMenuItem(); операцииToolStripMenuItem = new ToolStripMenuItem(); RepairToolStripMenuItem = new ToolStripMenuItem(); + MaterialProcurementToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); + directoryReportToolStripMenuItem = new ToolStripMenuItem(); + ContractorReportToolStripMenuItem = new ToolStripMenuItem(); + ReceiptMaterialsToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -52,7 +57,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ContractorsToolStripMenuItem, PremisesToolStripMenuItem, CostToolStripMenuItem, WorksToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ContractorsToolStripMenuItem, PremisesToolStripMenuItem, CostToolStripMenuItem, WorksToolStripMenuItem, BuildingMaterialsToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -60,34 +65,41 @@ // ContractorsToolStripMenuItem // ContractorsToolStripMenuItem.Name = "ContractorsToolStripMenuItem"; - ContractorsToolStripMenuItem.Size = new Size(224, 26); + ContractorsToolStripMenuItem.Size = new Size(212, 26); ContractorsToolStripMenuItem.Text = "Подрядчики"; ContractorsToolStripMenuItem.Click += ContractorsToolStripMenuItem_Click; // // PremisesToolStripMenuItem // PremisesToolStripMenuItem.Name = "PremisesToolStripMenuItem"; - PremisesToolStripMenuItem.Size = new Size(224, 26); + PremisesToolStripMenuItem.Size = new Size(212, 26); PremisesToolStripMenuItem.Text = "Помещения"; PremisesToolStripMenuItem.Click += PremisesToolStripMenuItem_Click; // // CostToolStripMenuItem // CostToolStripMenuItem.Name = "CostToolStripMenuItem"; - CostToolStripMenuItem.Size = new Size(224, 26); + CostToolStripMenuItem.Size = new Size(212, 26); CostToolStripMenuItem.Text = "Затраты"; CostToolStripMenuItem.Click += CostToolStripMenuItem_Click; // // WorksToolStripMenuItem // WorksToolStripMenuItem.Name = "WorksToolStripMenuItem"; - WorksToolStripMenuItem.Size = new Size(224, 26); + WorksToolStripMenuItem.Size = new Size(212, 26); WorksToolStripMenuItem.Text = "Работы"; WorksToolStripMenuItem.Click += WorksToolStripMenuItem_Click; // + // BuildingMaterialsToolStripMenuItem + // + BuildingMaterialsToolStripMenuItem.Name = "BuildingMaterialsToolStripMenuItem"; + BuildingMaterialsToolStripMenuItem.Size = new Size(212, 26); + BuildingMaterialsToolStripMenuItem.Text = "Стройматериалы"; + BuildingMaterialsToolStripMenuItem.Click += BuildingMaterialsToolStripMenuItem_Click; + // // операцииToolStripMenuItem // - операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { RepairToolStripMenuItem }); + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { RepairToolStripMenuItem, MaterialProcurementToolStripMenuItem }); операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; операцииToolStripMenuItem.Size = new Size(95, 24); операцииToolStripMenuItem.Text = "Операции"; @@ -95,16 +107,49 @@ // RepairToolStripMenuItem // RepairToolStripMenuItem.Name = "RepairToolStripMenuItem"; - RepairToolStripMenuItem.Size = new Size(224, 26); + RepairToolStripMenuItem.Size = new Size(234, 26); RepairToolStripMenuItem.Text = "Ремонт"; RepairToolStripMenuItem.Click += RepairToolStripMenuItem_Click; // + // MaterialProcurementToolStripMenuItem + // + MaterialProcurementToolStripMenuItem.Name = "MaterialProcurementToolStripMenuItem"; + MaterialProcurementToolStripMenuItem.Size = new Size(234, 26); + MaterialProcurementToolStripMenuItem.Text = "Закупка материалов"; + MaterialProcurementToolStripMenuItem.Click += MaterialProcurementToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { directoryReportToolStripMenuItem, ContractorReportToolStripMenuItem, ReceiptMaterialsToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.E; отчетыToolStripMenuItem.Size = new Size(73, 24); отчетыToolStripMenuItem.Text = "Отчеты"; // + // directoryReportToolStripMenuItem + // + directoryReportToolStripMenuItem.Name = "directoryReportToolStripMenuItem"; + directoryReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W; + directoryReportToolStripMenuItem.Size = new Size(346, 26); + directoryReportToolStripMenuItem.Text = "Документ со справочником "; + directoryReportToolStripMenuItem.Click += directoryReportToolStripMenuItem_Click; + // + // ContractorReportToolStripMenuItem + // + ContractorReportToolStripMenuItem.Name = "ContractorReportToolStripMenuItem"; + ContractorReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.E; + ContractorReportToolStripMenuItem.Size = new Size(346, 26); + ContractorReportToolStripMenuItem.Text = "Отчет по подрядчикам"; + ContractorReportToolStripMenuItem.Click += ContractorReportToolStripMenuItem_Click; + // + // ReceiptMaterialsToolStripMenuItem + // + ReceiptMaterialsToolStripMenuItem.Name = "ReceiptMaterialsToolStripMenuItem"; + ReceiptMaterialsToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P; + ReceiptMaterialsToolStripMenuItem.Size = new Size(346, 26); + ReceiptMaterialsToolStripMenuItem.Text = "Поступление материалов"; + ReceiptMaterialsToolStripMenuItem.Click += ReceiptMaterialsToolStripMenuItem_Click; + // // FormRepairWork // AutoScaleDimensions = new SizeF(8F, 20F); @@ -134,5 +179,10 @@ private ToolStripMenuItem RepairToolStripMenuItem; private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem WorksToolStripMenuItem; + private ToolStripMenuItem directoryReportToolStripMenuItem; + private ToolStripMenuItem BuildingMaterialsToolStripMenuItem; + private ToolStripMenuItem MaterialProcurementToolStripMenuItem; + private ToolStripMenuItem ContractorReportToolStripMenuItem; + private ToolStripMenuItem ReceiptMaterialsToolStripMenuItem; } } diff --git a/ProjectRepairWork/FormRepairWork.cs b/ProjectRepairWork/FormRepairWork.cs index 2762be8..57d560d 100644 --- a/ProjectRepairWork/FormRepairWork.cs +++ b/ProjectRepairWork/FormRepairWork.cs @@ -72,5 +72,65 @@ namespace ProjectRepairWork MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void directoryReportToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void BuildingMaterialsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void MaterialProcurementToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ContractorReportToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ReceiptMaterialsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/ProjectRepairWork/Forms/FormBuildingMaterial.Designer.cs b/ProjectRepairWork/Forms/FormBuildingMaterial.Designer.cs new file mode 100644 index 0000000..ea8462f --- /dev/null +++ b/ProjectRepairWork/Forms/FormBuildingMaterial.Designer.cs @@ -0,0 +1,95 @@ +namespace ProjectRepairWork.Forms +{ + partial class FormBuildingMaterial + { + /// + /// 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() + { + textBoxBuildingMaterial = new TextBox(); + labelBuildingMaterial = new Label(); + ButtonCancel = new Button(); + ButtonSave = new Button(); + SuspendLayout(); + // + // textBoxBuildingMaterial + // + textBoxBuildingMaterial.Location = new Point(203, 49); + textBoxBuildingMaterial.Name = "textBoxBuildingMaterial"; + textBoxBuildingMaterial.Size = new Size(225, 27); + textBoxBuildingMaterial.TabIndex = 0; + // + // labelBuildingMaterial + // + labelBuildingMaterial.AutoSize = true; + labelBuildingMaterial.Location = new Point(12, 52); + labelBuildingMaterial.Name = "labelBuildingMaterial"; + labelBuildingMaterial.Size = new Size(156, 20); + labelBuildingMaterial.TabIndex = 1; + labelBuildingMaterial.Text = "Название материала"; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(244, 106); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(169, 29); + ButtonCancel.TabIndex = 22; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // ButtonSave + // + ButtonSave.Location = new Point(33, 106); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(169, 29); + ButtonSave.TabIndex = 21; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // FormBuildingMaterial + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(468, 147); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(labelBuildingMaterial); + Controls.Add(textBoxBuildingMaterial); + Name = "FormBuildingMaterial"; + Text = "Строительный материалы"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxBuildingMaterial; + private Label labelBuildingMaterial; + private Button ButtonCancel; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormBuildingMaterial.cs b/ProjectRepairWork/Forms/FormBuildingMaterial.cs new file mode 100644 index 0000000..39487ad --- /dev/null +++ b/ProjectRepairWork/Forms/FormBuildingMaterial.cs @@ -0,0 +1,82 @@ +using ProjectRepairWork.Entities; +using ProjectRepairWork.Repositories; +using ProjectRepairWork.Repositories.Implementation; +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; + +namespace ProjectRepairWork.Forms +{ + public partial class FormBuildingMaterial : Form + { + private readonly IBuildingMaterialsRepository _buildingMaterialsRepository; + private int? _buildingMaterialsId; + + public int Id + { + set + { + try + { + var buildingMaterials = _buildingMaterialsRepository.ReadBuildingMaterialsById(value); + if (buildingMaterials == null) + { + throw new InvalidDataException(nameof(buildingMaterials)); + } + textBoxBuildingMaterial.Text = buildingMaterials.MaterialsType; + _buildingMaterialsId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormBuildingMaterial(IBuildingMaterialsRepository buildingMaterialsRepository) + { + InitializeComponent(); + _buildingMaterialsRepository = buildingMaterialsRepository ?? throw new ArgumentNullException(nameof(buildingMaterialsRepository)); + } + private void Cancel_Click(object sender, EventArgs e) => Close(); + private BuildingMaterials CreateBuildingMaterials(int id) => BuildingMaterials.CreatEntity( + id, + textBoxBuildingMaterial.Text); + + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxBuildingMaterial.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_buildingMaterialsId.HasValue) + { + _buildingMaterialsRepository.UpdateBuildingMaterials(CreateBuildingMaterials(_buildingMaterialsId.Value)); + } + else + { + _buildingMaterialsRepository.CreateBuildingMaterials(CreateBuildingMaterials(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + } +} diff --git a/ProjectRepairWork/Forms/FormBuildingMaterial.resx b/ProjectRepairWork/Forms/FormBuildingMaterial.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectRepairWork/Forms/FormBuildingMaterial.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/ProjectRepairWork/Forms/FormBuildingMaterials.Designer.cs b/ProjectRepairWork/Forms/FormBuildingMaterials.Designer.cs new file mode 100644 index 0000000..67d28f7 --- /dev/null +++ b/ProjectRepairWork/Forms/FormBuildingMaterials.Designer.cs @@ -0,0 +1,125 @@ +namespace ProjectRepairWork.Forms +{ + partial class FormBuildingMaterials + { + /// + /// 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() + { + dataGridView = new DataGridView(); + panel1 = new Panel(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(633, 450); + dataGridView.TabIndex = 5; + // + // panel1 + // + panel1.Controls.Add(ButtonDel); + panel1.Controls.Add(ButtonUpd); + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(633, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(167, 450); + panel1.TabIndex = 4; + // + // ButtonDel + // + ButtonDel.BackgroundImage = Properties.Resources.free_icon_font_cross; + ButtonDel.BackgroundImageLayout = ImageLayout.Stretch; + ButtonDel.Location = new Point(32, 252); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(105, 92); + ButtonDel.TabIndex = 2; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.BackgroundImage = Properties.Resources.free_icon_font_pencil_3917376; + ButtonUpd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonUpd.Location = new Point(32, 137); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(105, 92); + ButtonUpd.TabIndex = 1; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.free_icon_font_plus; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(32, 12); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(105, 92); + ButtonAdd.TabIndex = 0; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // FormBuildingMaterials + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormBuildingMaterials"; + Text = "Строительные материалы"; + Load += FormBuildingMaterials_Load_1; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Panel panel1; + private Button ButtonDel; + private Button ButtonUpd; + private Button ButtonAdd; + } +} \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormBuildingMaterials.cs b/ProjectRepairWork/Forms/FormBuildingMaterials.cs new file mode 100644 index 0000000..c99e2d5 --- /dev/null +++ b/ProjectRepairWork/Forms/FormBuildingMaterials.cs @@ -0,0 +1,108 @@ +using ProjectRepairWork.Repositories; +using ProjectRepairWork.Repositories.Implementation; +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 ProjectRepairWork.Forms +{ + public partial class FormBuildingMaterials : Form + { + private readonly IUnityContainer _container; + private readonly IBuildingMaterialsRepository _buildingMaterialsRepository; + public FormBuildingMaterials(IUnityContainer container, IBuildingMaterialsRepository buildingMaterialsRepository) + { + InitializeComponent(); + + _container = container ?? throw new ArgumentNullException(nameof(container)); + _buildingMaterialsRepository = buildingMaterialsRepository ?? throw new ArgumentNullException(nameof(buildingMaterialsRepository)); + } + + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _buildingMaterialsRepository.DeletedBuildingMaterials(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _buildingMaterialsRepository.ReadBuildingMaterials(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value); + return true; + } + + private void FormBuildingMaterials_Load_1(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ProjectRepairWork/Forms/FormBuildingMaterials.resx b/ProjectRepairWork/Forms/FormBuildingMaterials.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectRepairWork/Forms/FormBuildingMaterials.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/ProjectRepairWork/Forms/FormDirectoryReport.Designer.cs b/ProjectRepairWork/Forms/FormDirectoryReport.Designer.cs new file mode 100644 index 0000000..02c9b63 --- /dev/null +++ b/ProjectRepairWork/Forms/FormDirectoryReport.Designer.cs @@ -0,0 +1,99 @@ +namespace ProjectRepairWork.Forms +{ + partial class FormDirectoryReport + { + /// + /// 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() + { + checkBoxWorks = new CheckBox(); + checkBoxContractors = new CheckBox(); + checkBoxPremises = new CheckBox(); + buttonFormulate = new Button(); + SuspendLayout(); + // + // checkBoxWorks + // + checkBoxWorks.AutoSize = true; + checkBoxWorks.Location = new Point(27, 30); + checkBoxWorks.Name = "checkBoxWorks"; + checkBoxWorks.Size = new Size(82, 24); + checkBoxWorks.TabIndex = 0; + checkBoxWorks.Text = "Работы"; + checkBoxWorks.UseVisualStyleBackColor = true; + // + // checkBoxContractors + // + checkBoxContractors.AutoSize = true; + checkBoxContractors.Location = new Point(27, 81); + checkBoxContractors.Name = "checkBoxContractors"; + checkBoxContractors.Size = new Size(117, 24); + checkBoxContractors.TabIndex = 1; + checkBoxContractors.Text = "Подрядчики"; + checkBoxContractors.UseVisualStyleBackColor = true; + // + // checkBoxPremises + // + checkBoxPremises.AutoSize = true; + checkBoxPremises.Location = new Point(27, 139); + checkBoxPremises.Name = "checkBoxPremises"; + checkBoxPremises.Size = new Size(116, 24); + checkBoxPremises.TabIndex = 2; + checkBoxPremises.Text = "Помещения"; + checkBoxPremises.UseVisualStyleBackColor = true; + // + // buttonFormulate + // + buttonFormulate.Location = new Point(204, 81); + buttonFormulate.Name = "buttonFormulate"; + buttonFormulate.Size = new Size(173, 29); + buttonFormulate.TabIndex = 3; + buttonFormulate.Text = "Сформировать"; + buttonFormulate.UseVisualStyleBackColor = true; + buttonFormulate.Click += ButtonFormulate_Click; + // + // FormDirectoryReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(405, 189); + Controls.Add(buttonFormulate); + Controls.Add(checkBoxPremises); + Controls.Add(checkBoxContractors); + Controls.Add(checkBoxWorks); + Name = "FormDirectoryReport"; + Text = "Выгрузка справочников"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox checkBoxWorks; + private CheckBox checkBoxContractors; + private CheckBox checkBoxPremises; + private Button buttonFormulate; + } +} \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormDirectoryReport.cs b/ProjectRepairWork/Forms/FormDirectoryReport.cs new file mode 100644 index 0000000..b89c785 --- /dev/null +++ b/ProjectRepairWork/Forms/FormDirectoryReport.cs @@ -0,0 +1,64 @@ +using ProjectRepairWork.Reports; +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 ProjectRepairWork.Forms +{ + public partial class FormDirectoryReport : Form + { + private readonly IUnityContainer _container; + public FormDirectoryReport(IUnityContainer container) + { + _container = container ?? throw new ArgumentNullException(nameof(container)); + InitializeComponent(); + } + + private void ButtonFormulate_Click(object sender, EventArgs e) + { + try + { + if (!checkBoxContractors.Checked && !checkBoxPremises.Checked && !checkBoxWorks.Checked) + { + throw new Exception("Не выбран ни один справочник для выгрузки"); + } + + var sfd = new SaveFileDialog() + { + Filter = "Docx Files | *.docx" + }; + + if (sfd.ShowDialog() != DialogResult.OK) + { + throw new Exception("Не выбран айл для отчета"); + } + + if (_container.Resolve().CreateDoc(sfd.FileName, checkBoxContractors.Checked, + checkBoxPremises.Checked, checkBoxWorks.Checked)) + { + MessageBox.Show("Документ сформирован", "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах", + "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch(Exception ex) + + { + MessageBox.Show(ex.Message, "Ошибки при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + } +} diff --git a/ProjectRepairWork/Forms/FormDirectoryReport.resx b/ProjectRepairWork/Forms/FormDirectoryReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectRepairWork/Forms/FormDirectoryReport.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/ProjectRepairWork/Forms/FormMaterialProcurement.Designer.cs b/ProjectRepairWork/Forms/FormMaterialProcurement.Designer.cs new file mode 100644 index 0000000..3dbaf71 --- /dev/null +++ b/ProjectRepairWork/Forms/FormMaterialProcurement.Designer.cs @@ -0,0 +1,142 @@ +namespace ProjectRepairWork.Forms +{ + partial class FormMaterialProcurement + { + /// + /// 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() + { + comboBoxMaterialRrocurement = new ComboBox(); + dateTimePickerMaterialRrocurement = new DateTimePicker(); + numericUpDownMaterialRrocurement = new NumericUpDown(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + ButtonCancel = new Button(); + ButtonSave = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownMaterialRrocurement).BeginInit(); + SuspendLayout(); + // + // comboBoxMaterialRrocurement + // + comboBoxMaterialRrocurement.FormattingEnabled = true; + comboBoxMaterialRrocurement.Location = new Point(169, 44); + comboBoxMaterialRrocurement.Name = "comboBoxMaterialRrocurement"; + comboBoxMaterialRrocurement.Size = new Size(151, 28); + comboBoxMaterialRrocurement.TabIndex = 0; + // + // dateTimePickerMaterialRrocurement + // + dateTimePickerMaterialRrocurement.Location = new Point(153, 94); + dateTimePickerMaterialRrocurement.Name = "dateTimePickerMaterialRrocurement"; + dateTimePickerMaterialRrocurement.Size = new Size(250, 27); + dateTimePickerMaterialRrocurement.TabIndex = 1; + // + // numericUpDownMaterialRrocurement + // + numericUpDownMaterialRrocurement.Location = new Point(153, 161); + numericUpDownMaterialRrocurement.Name = "numericUpDownMaterialRrocurement"; + numericUpDownMaterialRrocurement.Size = new Size(150, 27); + numericUpDownMaterialRrocurement.TabIndex = 2; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(55, 47); + label1.Name = "label1"; + label1.Size = new Size(89, 20); + label1.TabIndex = 3; + label1.Text = "Материалы"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(55, 99); + label2.Name = "label2"; + label2.Size = new Size(41, 20); + label2.TabIndex = 4; + label2.Text = "Дата"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(55, 168); + label3.Name = "label3"; + label3.Size = new Size(45, 20); + label3.TabIndex = 5; + label3.Text = "Цена"; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(244, 230); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(169, 29); + ButtonCancel.TabIndex = 22; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // ButtonSave + // + ButtonSave.Location = new Point(33, 230); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(169, 29); + ButtonSave.TabIndex = 21; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // FormMaterialProcurement + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(434, 278); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(numericUpDownMaterialRrocurement); + Controls.Add(dateTimePickerMaterialRrocurement); + Controls.Add(comboBoxMaterialRrocurement); + Name = "FormMaterialProcurement"; + Text = "Закупка материала"; + ((System.ComponentModel.ISupportInitialize)numericUpDownMaterialRrocurement).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxMaterialRrocurement; + private DateTimePicker dateTimePickerMaterialRrocurement; + private NumericUpDown numericUpDownMaterialRrocurement; + private Label label1; + private Label label2; + private Label label3; + private Button ButtonCancel; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormMaterialProcurement.cs b/ProjectRepairWork/Forms/FormMaterialProcurement.cs new file mode 100644 index 0000000..c3c484a --- /dev/null +++ b/ProjectRepairWork/Forms/FormMaterialProcurement.cs @@ -0,0 +1,55 @@ +using ProjectRepairWork.Entities.Enums; +using ProjectRepairWork.Entities; +using ProjectRepairWork.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 ProjectRepairWork.Repositories.Implementation; + +namespace ProjectRepairWork.Forms; + +public partial class FormMaterialProcurement : Form +{ + private readonly IMaterialProcurementRepository _materialProcurementRepository; + + public FormMaterialProcurement(IMaterialProcurementRepository materialProcurementRepository, IBuildingMaterialsRepository buildingMaterialsRepository) + { + InitializeComponent(); + _materialProcurementRepository = materialProcurementRepository ?? throw new ArgumentNullException(nameof(materialProcurementRepository)); + + comboBoxMaterialRrocurement.DataSource = buildingMaterialsRepository.ReadBuildingMaterials(); + comboBoxMaterialRrocurement.DisplayMember = "MaterialsType"; + comboBoxMaterialRrocurement.ValueMember = "Id"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxMaterialRrocurement.SelectedIndex <0) + + { + throw new Exception("Имеются незаполненные поля"); + } + + _materialProcurementRepository.CreateMaterialProcurement(MaterialProcurement.CreatOpertions(0, + (int)comboBoxMaterialRrocurement.SelectedValue!, (int)numericUpDownMaterialRrocurement.Value!)); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + +} diff --git a/ProjectRepairWork/Forms/FormMaterialProcurement.resx b/ProjectRepairWork/Forms/FormMaterialProcurement.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectRepairWork/Forms/FormMaterialProcurement.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/ProjectRepairWork/Forms/FormMaterialProcurements.Designer.cs b/ProjectRepairWork/Forms/FormMaterialProcurements.Designer.cs new file mode 100644 index 0000000..ee481f0 --- /dev/null +++ b/ProjectRepairWork/Forms/FormMaterialProcurements.Designer.cs @@ -0,0 +1,97 @@ +namespace ProjectRepairWork.Forms +{ + partial class FormMaterialProcurements + { + /// + /// 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() + { + dataGridView = new DataGridView(); + panel1 = new Panel(); + ButtonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(633, 450); + dataGridView.TabIndex = 5; + // + // panel1 + // + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(633, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(167, 450); + panel1.TabIndex = 4; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.free_icon_font_plus; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(32, 12); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(105, 92); + ButtonAdd.TabIndex = 0; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // FormMaterialProcurements + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormMaterialProcurements"; + Text = "Закупка материалов "; + Load += FormMaterialProcurements_Load_1; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Panel panel1; + private Button ButtonAdd; + } +} \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormMaterialProcurements.cs b/ProjectRepairWork/Forms/FormMaterialProcurements.cs new file mode 100644 index 0000000..ff54796 --- /dev/null +++ b/ProjectRepairWork/Forms/FormMaterialProcurements.cs @@ -0,0 +1,57 @@ +using ProjectRepairWork.Repositories; +using ProjectRepairWork.Repositories.Implementation; +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 ProjectRepairWork.Forms +{ + public partial class FormMaterialProcurements : Form + { + private readonly IUnityContainer _container; + private readonly IMaterialProcurementRepository _materialProcurementRepository; + public FormMaterialProcurements(IUnityContainer container, IMaterialProcurementRepository materialProcurementRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _materialProcurementRepository = materialProcurementRepository ?? throw new ArgumentNullException(nameof(materialProcurementRepository)); + } + + + private void LoadList() => dataGridView.DataSource = _materialProcurementRepository.ReadMaterialProcurement(); + + + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormMaterialProcurements_Load_1(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ProjectRepairWork/Forms/FormMaterialProcurements.resx b/ProjectRepairWork/Forms/FormMaterialProcurements.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectRepairWork/Forms/FormMaterialProcurements.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/ProjectRepairWork/Forms/FormMaterialsReport.Designer.cs b/ProjectRepairWork/Forms/FormMaterialsReport.Designer.cs new file mode 100644 index 0000000..4c00e96 --- /dev/null +++ b/ProjectRepairWork/Forms/FormMaterialsReport.Designer.cs @@ -0,0 +1,107 @@ +namespace ProjectRepairWork.Forms +{ + partial class FormMaterialsReport + { + /// + /// 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() + { + buttonCreate = new Button(); + dateTimePickerDate = new DateTimePicker(); + labelDate = new Label(); + buttonSelect = new Button(); + labelFileName = new Label(); + SuspendLayout(); + // + // buttonCreate + // + buttonCreate.Location = new Point(24, 120); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(140, 28); + buttonCreate.TabIndex = 9; + buttonCreate.Text = "Сформировать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(62, 72); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(202, 27); + dateTimePickerDate.TabIndex = 8; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(12, 72); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(44, 20); + labelDate.TabIndex = 7; + labelDate.Text = "Дата:"; + // + // buttonSelect + // + buttonSelect.Location = new Point(12, 12); + buttonSelect.Name = "buttonSelect"; + buttonSelect.Size = new Size(84, 28); + buttonSelect.TabIndex = 5; + buttonSelect.Text = "Выбрать"; + buttonSelect.UseVisualStyleBackColor = true; + buttonSelect.Click += buttonSelect_Click; + // + // labelFileName + // + labelFileName.AutoSize = true; + labelFileName.Location = new Point(102, 20); + labelFileName.Name = "labelFileName"; + labelFileName.Size = new Size(45, 20); + labelFileName.TabIndex = 10; + labelFileName.Text = "Файл"; + // + // FormMaterialsReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(274, 174); + Controls.Add(labelFileName); + Controls.Add(buttonCreate); + Controls.Add(dateTimePickerDate); + Controls.Add(labelDate); + Controls.Add(buttonSelect); + Name = "FormMaterialsReport"; + Text = "Пополнение матреиалов"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCreate; + private DateTimePicker dateTimePickerDate; + private Label labelDate; + private Button buttonSelect; + private Label labelFileName; + } +} \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormMaterialsReport.cs b/ProjectRepairWork/Forms/FormMaterialsReport.cs new file mode 100644 index 0000000..a658812 --- /dev/null +++ b/ProjectRepairWork/Forms/FormMaterialsReport.cs @@ -0,0 +1,61 @@ +using ProjectRepairWork.Reports; +using Unity; + + +namespace ProjectRepairWork.Forms +{ + public partial class FormMaterialsReport : Form + { + private string _fileName = string.Empty; + + private readonly IUnityContainer _container; + + public FormMaterialsReport(IUnityContainer container) + { + InitializeComponent(); + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void buttonSelect_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Pdf Files | *.pdf" + }; + + if (sfd.ShowDialog() == DialogResult.OK) + { + _fileName = sfd.FileName; + labelFileName.Text = Path.GetFileName(_fileName); + } + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(_fileName)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + + if + (_container.Resolve().CreateChart(_fileName, dateTimePickerDate.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); + } + } + + + } +} diff --git a/ProjectRepairWork/Forms/FormMaterialsReport.resx b/ProjectRepairWork/Forms/FormMaterialsReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectRepairWork/Forms/FormMaterialsReport.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/ProjectRepairWork/Forms/FormRepair.Designer.cs b/ProjectRepairWork/Forms/FormRepair.Designer.cs index f157cfc..cb4f334 100644 --- a/ProjectRepairWork/Forms/FormRepair.Designer.cs +++ b/ProjectRepairWork/Forms/FormRepair.Designer.cs @@ -37,6 +37,8 @@ dataGridViewWorks = new DataGridView(); ColumnWork = new DataGridViewComboBoxColumn(); ColumnCount = new DataGridViewTextBoxColumn(); + DateRepair = new Label(); + dateTimePickerRepair = new DateTimePicker(); ((System.ComponentModel.ISupportInitialize)dataGridViewWorks).BeginInit(); SuspendLayout(); // @@ -127,11 +129,29 @@ ColumnCount.MinimumWidth = 6; ColumnCount.Name = "ColumnCount"; // + // DateRepair + // + DateRepair.AutoSize = true; + DateRepair.Location = new Point(7, 131); + DateRepair.Name = "DateRepair"; + DateRepair.Size = new Size(86, 20); + DateRepair.TabIndex = 32; + DateRepair.Text = "Дата работ"; + // + // dateTimePickerRepair + // + dateTimePickerRepair.Location = new Point(152, 126); + dateTimePickerRepair.Name = "dateTimePickerRepair"; + dateTimePickerRepair.Size = new Size(200, 27); + dateTimePickerRepair.TabIndex = 31; + // // FormRepair // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(490, 462); + Controls.Add(DateRepair); + Controls.Add(dateTimePickerRepair); Controls.Add(dataGridViewWorks); Controls.Add(comboBoxPremises); Controls.Add(comboBoxContractors); @@ -156,5 +176,7 @@ private DataGridView dataGridViewWorks; private DataGridViewComboBoxColumn ColumnWork; private DataGridViewTextBoxColumn ColumnCount; + private Label DateRepair; + private DateTimePicker dateTimePickerRepair; } } \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormRepair.cs b/ProjectRepairWork/Forms/FormRepair.cs index a23c794..942ae7e 100644 --- a/ProjectRepairWork/Forms/FormRepair.cs +++ b/ProjectRepairWork/Forms/FormRepair.cs @@ -9,7 +9,7 @@ namespace ProjectRepairWork.Forms public partial class FormRepair : Form { private readonly IRepairRepository _repairRepository; - + public FormRepair(IRepairRepository repairRepository, IContractorsRepository contractorsRepository, IPremisesRepository premisesRepository, IWorksRepository worksRepository) { InitializeComponent(); @@ -37,7 +37,7 @@ namespace ProjectRepairWork.Forms { try { - if (dataGridViewWorks.RowCount < 1|| comboBoxContractors.SelectedIndex < 0 || + if (dataGridViewWorks.RowCount < 1 || comboBoxContractors.SelectedIndex < 0 || comboBoxPremises.SelectedIndex < 0) { @@ -45,7 +45,7 @@ namespace ProjectRepairWork.Forms } _repairRepository.CraeteRepair(Repair.CreatOpertions(0, - (int)comboBoxContractors.SelectedValue!, + (int)comboBoxContractors.SelectedValue!, dateTimePickerRepair.Value, (int)comboBoxPremises.SelectedValue!, CreateRepairFromDataGrid())); Close(); @@ -61,7 +61,7 @@ namespace ProjectRepairWork.Forms private List CreateRepairFromDataGrid() { var list = new List(); - foreach(DataGridViewRow row in dataGridViewWorks.Rows) + foreach (DataGridViewRow row in dataGridViewWorks.Rows) { if (row.Cells["ColumnWork"].Value == null || row.Cells["ColumnCount"].Value == null) @@ -72,7 +72,10 @@ namespace ProjectRepairWork.Forms Convert.ToInt32(row.Cells["ColumnWork"].Value), Convert.ToInt32(row.Cells["ColumnCount"].Value))); } - return list; + + return list.GroupBy(x => x.WorkId, x => x.Count, (id, counts) => RepairRepair.CreatElement(0, id, counts.Sum())).ToList(); ; } + + } } \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormRepair.resx b/ProjectRepairWork/Forms/FormRepair.resx index 6c3a593..a334293 100644 --- a/ProjectRepairWork/Forms/FormRepair.resx +++ b/ProjectRepairWork/Forms/FormRepair.resx @@ -123,4 +123,10 @@ True + + True + + + True + \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormRepairReport.Designer.cs b/ProjectRepairWork/Forms/FormRepairReport.Designer.cs new file mode 100644 index 0000000..54c757c --- /dev/null +++ b/ProjectRepairWork/Forms/FormRepairReport.Designer.cs @@ -0,0 +1,164 @@ +namespace ProjectRepairWork.Forms +{ + partial class FormRepairReport + { + /// + /// 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() + { + buttonMakeReport = new Button(); + labelDateEnd = new Label(); + labelDateBegin = new Label(); + labelContractor = new Label(); + labelPath = new Label(); + comboBoxContractor = new ComboBox(); + buttonSelectFilePath = new Button(); + textBoxFilePath = new TextBox(); + dateTimePickerDateEnd = new DateTimePicker(); + dateTimePickerDateBegin = new DateTimePicker(); + SuspendLayout(); + // + // buttonMakeReport + // + buttonMakeReport.Location = new Point(156, 245); + buttonMakeReport.Name = "buttonMakeReport"; + buttonMakeReport.Size = new Size(122, 28); + buttonMakeReport.TabIndex = 19; + buttonMakeReport.Text = "Сформировать"; + buttonMakeReport.UseVisualStyleBackColor = true; + buttonMakeReport.Click += buttonMakeReport_Click; + // + // labelDateEnd + // + labelDateEnd.AutoSize = true; + labelDateEnd.Location = new Point(36, 186); + labelDateEnd.Name = "labelDateEnd"; + labelDateEnd.Size = new Size(90, 20); + labelDateEnd.TabIndex = 18; + labelDateEnd.Text = "Дата конца:"; + // + // labelDateBegin + // + labelDateBegin.AutoSize = true; + labelDateBegin.Location = new Point(36, 137); + labelDateBegin.Name = "labelDateBegin"; + labelDateBegin.Size = new Size(97, 20); + labelDateBegin.TabIndex = 17; + labelDateBegin.Text = "Дата начала:"; + // + // labelContractor + // + labelContractor.AutoSize = true; + labelContractor.Location = new Point(36, 84); + labelContractor.Name = "labelContractor"; + labelContractor.Size = new Size(86, 20); + labelContractor.TabIndex = 16; + labelContractor.Text = "Подрядчик"; + // + // labelPath + // + labelPath.AutoSize = true; + labelPath.Location = new Point(36, 33); + labelPath.Name = "labelPath"; + labelPath.Size = new Size(112, 20); + labelPath.TabIndex = 15; + labelPath.Text = "Путь до файла:"; + // + // comboBoxContractor + // + comboBoxContractor.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxContractor.FormattingEnabled = true; + comboBoxContractor.Location = new Point(175, 81); + comboBoxContractor.Name = "comboBoxContractor"; + comboBoxContractor.Size = new Size(223, 28); + comboBoxContractor.TabIndex = 14; + // + // buttonSelectFilePath + // + buttonSelectFilePath.Location = new Point(365, 30); + buttonSelectFilePath.Name = "buttonSelectFilePath"; + buttonSelectFilePath.Size = new Size(32, 28); + buttonSelectFilePath.TabIndex = 13; + buttonSelectFilePath.Text = ". ."; + buttonSelectFilePath.UseVisualStyleBackColor = true; + buttonSelectFilePath.Click += buttonSelectFilePath_Click; + // + // textBoxFilePath + // + textBoxFilePath.Location = new Point(175, 30); + textBoxFilePath.Name = "textBoxFilePath"; + textBoxFilePath.ReadOnly = true; + textBoxFilePath.Size = new Size(173, 27); + textBoxFilePath.TabIndex = 12; + // + // dateTimePickerDateEnd + // + dateTimePickerDateEnd.Location = new Point(175, 180); + dateTimePickerDateEnd.Name = "dateTimePickerDateEnd"; + dateTimePickerDateEnd.Size = new Size(223, 27); + dateTimePickerDateEnd.TabIndex = 11; + // + // dateTimePickerDateBegin + // + dateTimePickerDateBegin.Location = new Point(175, 131); + dateTimePickerDateBegin.Name = "dateTimePickerDateBegin"; + dateTimePickerDateBegin.Size = new Size(223, 27); + dateTimePickerDateBegin.TabIndex = 10; + // + // FormRepairReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(429, 330); + Controls.Add(buttonMakeReport); + Controls.Add(labelDateEnd); + Controls.Add(labelDateBegin); + Controls.Add(labelContractor); + Controls.Add(labelPath); + Controls.Add(comboBoxContractor); + Controls.Add(buttonSelectFilePath); + Controls.Add(textBoxFilePath); + Controls.Add(dateTimePickerDateEnd); + Controls.Add(dateTimePickerDateBegin); + Name = "FormRepairReport"; + Text = "Отчет по ремонтам "; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonMakeReport; + private Label labelDateEnd; + private Label labelDateBegin; + private Label labelContractor; + private Label labelPath; + private ComboBox comboBoxContractor; + private Button buttonSelectFilePath; + private TextBox textBoxFilePath; + private DateTimePicker dateTimePickerDateEnd; + private DateTimePicker dateTimePickerDateBegin; + } +} \ No newline at end of file diff --git a/ProjectRepairWork/Forms/FormRepairReport.cs b/ProjectRepairWork/Forms/FormRepairReport.cs new file mode 100644 index 0000000..179392b --- /dev/null +++ b/ProjectRepairWork/Forms/FormRepairReport.cs @@ -0,0 +1,72 @@ +using ProjectRepairWork.Repositories; +using ProjectRepairWork.Reports; +using Unity; + +namespace ProjectRepairWork.Forms +{ + public partial class FormRepairReport : Form + { + private readonly IUnityContainer _container; + + + public FormRepairReport(IUnityContainer container, IContractorsRepository contractorRepository) + { + _container = container ?? throw new ArgumentNullException(nameof(container)); + InitializeComponent(); + + comboBoxContractor.DataSource = contractorRepository.ReadContractors(); + comboBoxContractor.DisplayMember = "CompanyName"; + comboBoxContractor.ValueMember = "Id"; + } + + private void buttonMakeReport_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFilePath.Text)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + + if (comboBoxContractor.SelectedIndex < 0) + { + throw new Exception("Не выбран подрядчик"); + } + + if (dateTimePickerDateEnd.Value <= dateTimePickerDateBegin.Value) + { + throw new Exception("Дата начала должна быть раньше даты окончания"); + } + + if (_container.Resolve().CreateTable(textBoxFilePath.Text, (int)comboBoxContractor.SelectedValue!, + dateTimePickerDateBegin.Value, dateTimePickerDateEnd.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 buttonSelectFilePath_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Excel Files | *.xlsx" + }; + + if (sfd.ShowDialog() != DialogResult.OK) + { + return; + } + + textBoxFilePath.Text = sfd.FileName; + } + } +} diff --git a/ProjectRepairWork/Forms/FormRepairReport.resx b/ProjectRepairWork/Forms/FormRepairReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectRepairWork/Forms/FormRepairReport.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/ProjectRepairWork/Program.cs b/ProjectRepairWork/Program.cs index 947f6d1..365288f 100644 --- a/ProjectRepairWork/Program.cs +++ b/ProjectRepairWork/Program.cs @@ -34,6 +34,8 @@ namespace ProjectRepairWork container.RegisterType(); container.RegisterType(); container.RegisterType(); + container.RegisterType(); + container.RegisterType(); return container; } diff --git a/ProjectRepairWork/ProjectRepairWork.csproj b/ProjectRepairWork/ProjectRepairWork.csproj index ebed082..36fb29b 100644 --- a/ProjectRepairWork/ProjectRepairWork.csproj +++ b/ProjectRepairWork/ProjectRepairWork.csproj @@ -10,11 +10,15 @@ + + + + diff --git a/ProjectRepairWork/Reports/ChartReport.cs b/ProjectRepairWork/Reports/ChartReport.cs new file mode 100644 index 0000000..3f3423d --- /dev/null +++ b/ProjectRepairWork/Reports/ChartReport.cs @@ -0,0 +1,74 @@ +using Microsoft.Extensions.Logging; +using ProjectRepairWork.Repositories; +using ProjectRepairWork.Repositories.Implementation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Reports; + +public class ChartReport +{ + private readonly IMaterialProcurementRepository _materialProcurementRepository; + private readonly IBuildingMaterialsRepository _buildingMaterialsRepository; + private readonly ILogger _logger; + + public ChartReport(IMaterialProcurementRepository materialProcurementRepository, IBuildingMaterialsRepository buildingMaterialsRepository, ILogger logger) + { + _buildingMaterialsRepository = buildingMaterialsRepository ?? throw new ArgumentNullException(nameof(buildingMaterialsRepository)); + _materialProcurementRepository = materialProcurementRepository ?? throw new ArgumentNullException(nameof(materialProcurementRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateChart(string filePath, DateTime dateTime) + { + try + { + new PdfBuilder(filePath) + .AddHeader("Поступление материалов") + .AddPieChart("Виды материала", GetData(dateTime)) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + private List<(string Caption, double Value)> GetData(DateTime dateTime) + { + var materialProcurement = _materialProcurementRepository.ReadMaterialProcurement() + .Where(x => x.ProcurmentDate.Date == dateTime.Date).ToList(); + + var materials = _buildingMaterialsRepository.ReadBuildingMaterials(); + + + var data = from materialProc in materialProcurement + join material in materials on materialProc.MaterialsId equals material.Id + select new + { + material.MaterialsType, + materialProc.MaterialsPrice + }; + + + var groupedData = data + .GroupBy(x => x.MaterialsType) + .Select(g => new + { + MaterialsName = g.Key, + TotalCount = g.Sum(x => x.MaterialsPrice) + }) + .ToList(); + + + var result = groupedData + .Select(x => (x.MaterialsName.ToString(), (double)x.TotalCount)) + .ToList(); + + return result; + } +} diff --git a/ProjectRepairWork/Reports/DocReport.cs b/ProjectRepairWork/Reports/DocReport.cs new file mode 100644 index 0000000..d3469d6 --- /dev/null +++ b/ProjectRepairWork/Reports/DocReport.cs @@ -0,0 +1,93 @@ + +using Microsoft.Extensions.Logging; +using ProjectRepairWork.Repositories; +using ProjectRepairWork.Repositories.Implementation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Reports; + +public class DocReport +{ + + private readonly IContractorsRepository _contractorsRepository; + private readonly IPremisesRepository _premisesRepository; + private readonly IWorksRepository _worksRepository; + private readonly ILogger _logger; + + public DocReport(ILogger logger, IContractorsRepository contractorsRepository, IPremisesRepository premisesRepository, IWorksRepository worksRepository) + { + + _contractorsRepository = contractorsRepository ?? throw new ArgumentNullException(nameof(contractorsRepository)); + _premisesRepository = premisesRepository ?? throw new ArgumentNullException(nameof(premisesRepository)); + _worksRepository = worksRepository ?? throw new ArgumentNullException(nameof(worksRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateDoc(string filePath, bool includeContractors, bool includePremises, bool includeWork) + { + try + { + var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками"); + + + if (includeContractors) + { + builder.AddParagraph("Подрядчики").AddTable([2400, 2400], GetContractors()); + } + + if (includePremises) + { + builder.AddParagraph("Помещения").AddTable([2400, 2400, 2400, 2400, 2400, 2400], GetPremises()); + } + + if (includeWork) + { + builder.AddParagraph("Работы").AddTable([2400, 2400], GetWork()); + } + + builder.Build(); + + return true; + } + + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List GetContractors() + { + return [ + ["Название компании", "Контакты"], + .. _contractorsRepository + .ReadContractors() + .Select(x => new string[] { x.CompanyName, x.Contacts}), + ]; + } + + private List GetPremises() + { + return [ + ["Имя клиента", "Адрес", "Площадь", "Тип помещения","Дата начала","Дата конца"], + .. _premisesRepository + .ReadPremises() + .Select(x => new string[] { x.ClientName, x.Address, x.Area.ToString(), x.PremisesType.ToString(), x.DateStart.ToString(), x.DateEnd.ToString()}), + ]; + } + + private List GetWork() + { + return [ + ["Название работы", "Материалы"], + .. _worksRepository + .ReadWorks() + .Select(x => new string[] { x.WorkName, x.MaterialsName.ToString()}), + ]; + } +} diff --git a/ProjectRepairWork/Reports/ExcelBuilder.cs b/ProjectRepairWork/Reports/ExcelBuilder.cs new file mode 100644 index 0000000..2f79eeb --- /dev/null +++ b/ProjectRepairWork/Reports/ExcelBuilder.cs @@ -0,0 +1,316 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Spreadsheet; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Reports; + +internal class ExcelBuilder +{ + private readonly string _filePath; + private readonly SheetData _sheetData; + private readonly MergeCells _mergeCells; + private readonly Columns _columns; + private uint _rowIndex = 0; + + public ExcelBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _sheetData = new SheetData(); + _mergeCells = new MergeCells(); + _columns = new Columns(); + _rowIndex = 1; + } + + public ExcelBuilder AddHeader(string header, int startIndex, int count) + { + CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithoutBorder); + for (int i = startIndex + 1; i < startIndex + count; ++i) + { + CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder); + } + _mergeCells.Append(new MergeCell() + { + Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}") + }); + _rowIndex++; + return this; + } + + public ExcelBuilder AddParagraph(string text, int columnIndex) + { + CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithoutBorder); + return this; + } + + public ExcelBuilder AddTable(int[] columnsWidths, List data) + { + if (columnsWidths == null || columnsWidths.Length == 0) + { + throw new ArgumentNullException(nameof(columnsWidths)); + } + if (data == null || data.Count == 0) + { + throw new ArgumentNullException(nameof(data)); + } + if (data.Any(x => x.Length != columnsWidths.Length)) + { + throw new InvalidOperationException("widths.Length != data.Length"); + } + + uint counter = 1; + int coef = 2; + _columns.Append(columnsWidths.Select(x => new Column + { + Min = counter, + Max = counter++, + Width = x * coef, + CustomWidth = true + })); + for (var j = 0; j < data.First().Length; ++j) + { + CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder); + } + _rowIndex++; + + for (var i = 1; i < data.Count - 1; ++i) + { + for (var j = 0; j < data[i].Length; ++j) + { + CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder); + } + _rowIndex++; + } + for (var j = 0; j < data.Last().Length; ++j) + { + CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder); + } + _rowIndex++; + return this; + } + + public void Build() + { + using var spreadsheetDocument = SpreadsheetDocument.Create(_filePath, SpreadsheetDocumentType.Workbook); + var workbookpart = spreadsheetDocument.AddWorkbookPart(); + GenerateStyle(workbookpart); + workbookpart.Workbook = new Workbook(); + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(); + + if (_columns.HasChildren) + { + worksheetPart.Worksheet.Append(_columns); + } + + worksheetPart.Worksheet.Append(_sheetData); + var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист 1" + }; + sheets.Append(sheet); + if (_mergeCells.HasChildren) + { + worksheetPart.Worksheet.InsertAfter(_mergeCells, + worksheetPart.Worksheet.Elements().First()); + } + } + + private static void GenerateStyle(WorkbookPart workbookPart) + { + var workbookStylesPart = workbookPart.AddNewPart(); + workbookStylesPart.Stylesheet = new Stylesheet(); + + var fonts = new Fonts() + { + Count = 2, + KnownFonts = BooleanValue.FromBoolean(true) + }; + fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font + { + FontSize = new FontSize() { Val = 11 }, + FontName = new FontName() { Val = "Calibri" }, + FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, + FontScheme = new FontScheme() + { + Val = new EnumValue(FontSchemeValues.Minor) + } + }); + fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font + { + FontSize = new FontSize() { Val = 11 }, + FontName = new FontName() { Val = "Calibri" }, + FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, + FontScheme = new FontScheme() + { + Val = new EnumValue(FontSchemeValues.Minor) + }, + Bold = new Bold() { Val = true } + }); + workbookStylesPart.Stylesheet.Append(fonts); + + // Default Fill + var fills = new Fills() { Count = 1 }; + fills.Append(new Fill + { + PatternFill = new PatternFill() + { + PatternType = new EnumValue(PatternValues.None) + } + }); + workbookStylesPart.Stylesheet.Append(fills); + + // Default Border + var borders = new Borders() { Count = 2 }; + borders.Append(new Border + { + LeftBorder = new LeftBorder(), + RightBorder = new RightBorder(), + TopBorder = new TopBorder(), + BottomBorder = new BottomBorder(), + DiagonalBorder = new DiagonalBorder() + }); + borders.Append(new Border + { + LeftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }, + RightBorder = new RightBorder() { Style = BorderStyleValues.Thin }, + TopBorder = new TopBorder() { Style = BorderStyleValues.Thin }, + BottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }, + DiagonalBorder = new DiagonalBorder() + }); + workbookStylesPart.Stylesheet.Append(borders); + + // Default cell format and a date cell format + var cellFormats = new CellFormats() { Count = 4 }; + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 0, + BorderId = 0, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Left, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 0, + BorderId = 1, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Right, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 1, + BorderId = 0, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Center, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 1, + BorderId = 1, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Center, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + workbookStylesPart.Stylesheet.Append(cellFormats); + } + + private enum StyleIndex + { + SimpleTextWithoutBorder = 0, + SimpleTextWithBorder = 1, + BoldTextWithoutBorder = 2, + BoldTextWithBorder = 3, + } + + private void CreateCell(int columnIndex, uint rowIndex, string text, StyleIndex styleIndex) + { + var columnName = GetExcelColumnName(columnIndex); + var cellReference = columnName + rowIndex; + var row = _sheetData.Elements().FirstOrDefault(r => r.RowIndex! == rowIndex); + if (row == null) + { + row = new Row() { RowIndex = rowIndex }; + _sheetData.Append(row); + } + var newCell = row.Elements().FirstOrDefault(c => c.CellReference != null && + c.CellReference.Value == columnName + rowIndex); + if (newCell == null) + { + Cell? refCell = null; + foreach (Cell cell in row.Elements()) + { + if (cell.CellReference?.Value != null && + cell.CellReference.Value.Length == cellReference.Length) + { + if (string.Compare(cell.CellReference.Value, cellReference, true) > 0) + { + refCell = cell; + break; + } + } + } + newCell = new Cell() { CellReference = cellReference }; + row.InsertBefore(newCell, refCell); + } + newCell.CellValue = new CellValue(text); + newCell.DataType = CellValues.String; + newCell.StyleIndex = (uint)styleIndex; + } + + private static string GetExcelColumnName(int columnNumber) + { + columnNumber += 1; + int dividend = columnNumber; + string columnName = string.Empty; + int modulo; + while (dividend > 0) + { + modulo = (dividend - 1) % 26; + columnName = Convert.ToChar(65 + modulo).ToString() + columnName; + dividend = (dividend - modulo) / 26; + } + return columnName; + } +} \ No newline at end of file diff --git a/ProjectRepairWork/Reports/PdfBuilder.cs b/ProjectRepairWork/Reports/PdfBuilder.cs new file mode 100644 index 0000000..66e53f3 --- /dev/null +++ b/ProjectRepairWork/Reports/PdfBuilder.cs @@ -0,0 +1,76 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes.Charts; +using MigraDoc.Rendering; +using System.Text; + +namespace ProjectRepairWork.Reports; + +internal class PdfBuilder +{ + private readonly string _filePath; + private readonly Document _document; + + public PdfBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _document = new Document(); + DefineStyles(); + } + + public PdfBuilder AddHeader(string header) + { + _document.AddSection().AddParagraph(header, "NormalBold"); + return this; + } + + public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) + { + if (data == null || data.Count == 0) + { + return this; + } + var chart = new Chart(ChartType.Pie2D); + var series = chart.SeriesCollection.AddSeries(); + series.Add(data.Select(x => x.Value).ToArray()); + var xseries = chart.XValues.AddXSeries(); + xseries.Add(data.Select(x => x.Caption).ToArray()); + chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Position = DataLabelPosition.OutsideEnd; + chart.Width = Unit.FromCentimeter(16); + chart.Height = Unit.FromCentimeter(12); + chart.TopArea.AddParagraph(title); + chart.XAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.HasMajorGridlines = true; + chart.PlotArea.LineFormat.Width = 1; + chart.PlotArea.LineFormat.Visible = true; + chart.TopArea.AddLegend(); + _document.LastSection.Add(chart); + return this; + } + + public void Build() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(_filePath); + } + private void DefineStyles() + { + var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal"); + headerStyle.Font.Bold = true; + headerStyle.Font.Size = 14; + } +} \ No newline at end of file diff --git a/ProjectRepairWork/Reports/TableReport.cs b/ProjectRepairWork/Reports/TableReport.cs new file mode 100644 index 0000000..ba01109 --- /dev/null +++ b/ProjectRepairWork/Reports/TableReport.cs @@ -0,0 +1,95 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectRepairWork.Repositories; +using ProjectRepairWork.Repositories.Implementation; +using ProjectRepairWork.Entities; + +namespace ProjectRepairWork.Reports; + +internal class TableReport +{ + private readonly IRepairRepository _repairRepository; + private readonly IWorksRepository _worksRepository; + private readonly ILogger _logger; + + internal static readonly string[] Headers = { "Работа", "Дата", "Количество" }; + + public TableReport(IRepairRepository repairRepository, IWorksRepository worksRepository, ILogger logger) + { + _repairRepository = repairRepository ?? throw new ArgumentNullException(nameof(repairRepository)); + _worksRepository = worksRepository ?? throw new ArgumentNullException(nameof(worksRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateTable(string filePath, int contractorsId, DateTime startDate, DateTime endDate) + { + try + { + var data = GetData(contractorsId, startDate, endDate); + new ExcelBuilder(filePath) + .AddHeader("Сводка по подрядчикам", 0, 3) + .AddParagraph("за период", 0) + .AddTable(new int[] { 10, 15, 15 }, data) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List GetData(int contractorsId, DateTime startDate, DateTime endDate) + { + var repairs = _repairRepository.ReadRepair() + .Where(x => x.DateRepair >= startDate && x.DateRepair <= endDate && x.ContractorsId == contractorsId) + .ToList(); + + var repairRepairs = _repairRepository.ReadRepairRepair(); + var works = _worksRepository.ReadWorks(); + + var data = from repair in repairs + join repairRepair in repairRepairs on repair.Id equals repairRepair.Id + join work in works on repairRepair.WorkId equals work.Id + select new + { + work.WorkName, + repairRepair.Count, + repair.DateRepair + }; + + + var groupedData = data + .GroupBy(x => new { x.WorkName, x.DateRepair }) + .Select(g => new + { + WorksName = g.Key.WorkName, + Date = g.Key.DateRepair, + Quantity = g.Sum(x => x.Count) + }) + .OrderBy(x => x.Date) + .ToList(); + + var totalQuantity = groupedData.Sum(x => x.Quantity); + + var result = new List() { Headers } + .Union( + groupedData + .Select(x => new string[] { + x.WorksName.ToString(), x.Date.ToString(), x.Quantity.ToString() + })) + .Union( + new List() { new string[] { "Всего", "", totalQuantity.ToString() } }) + .ToList(); + + return result; + } + +} + + diff --git a/ProjectRepairWork/Reports/WordBuilder.cs b/ProjectRepairWork/Reports/WordBuilder.cs new file mode 100644 index 0000000..c978113 --- /dev/null +++ b/ProjectRepairWork/Reports/WordBuilder.cs @@ -0,0 +1,131 @@ +using DocumentFormat.OpenXml.Drawing.Charts; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml.Packaging; + +namespace ProjectRepairWork.Reports; + +public class WordBuilder +{ + private readonly string _filePath; + private readonly Document _document; + private readonly Body _body; + + public WordBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _document = new Document(); + _body = _document.AppendChild(new Body()); + } + + public WordBuilder AddHeader(string header) + { + var paragraph = _body.AppendChild(new Paragraph()); + var run = paragraph.AppendChild(new Run()); + var runProperties = run.AppendChild(new RunProperties()); + runProperties.AppendChild(new Bold()); + run.AppendChild(new Text(header)); + return this; + } + + public WordBuilder AddParagraph(string text) + { + var paragraph = _body.AppendChild(new Paragraph()); + var run = paragraph.AppendChild(new Run()); + run.AppendChild(new Text(text)); + return this; + } + + public WordBuilder AddTable(int[] widths, List data) + { + if (widths == null || widths.Length == 0) + { + throw new ArgumentNullException(nameof(widths)); + } + if (data == null || data.Count == 0) + { + throw new ArgumentNullException(nameof(data)); + } + if (data.Any(x => x.Length != widths.Length)) + { + throw new InvalidOperationException("widths.Length != data.Length"); + } + var table = new Table(); + table.AppendChild(new TableProperties( + new TableBorders( + new TopBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + } + ) + )); + + var tr = new TableRow(); + for (var j = 0; j < widths.Length; ++j) + { + tr.Append(new TableCell( + new TableCellProperties(new TableCellWidth() + { + Width = + widths[j].ToString() + }), + new Paragraph(new Run(new RunProperties(new Bold()), new + Text(data.First()[j]))))); + } + table.Append(tr); + + table.Append(data.Skip(1).Select(x => + new TableRow(x.Select(y => new TableCell(new Paragraph(new Run(new Text(y)))))))); + _body.Append(table); + return this; + } + + public void Build() + { + using var wordDocument = WordprocessingDocument.Create(_filePath, +WordprocessingDocumentType.Document); + var mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = _document; + } +} + diff --git a/ProjectRepairWork/Repositories/IBuildingMaterialsRepository.cs b/ProjectRepairWork/Repositories/IBuildingMaterialsRepository.cs new file mode 100644 index 0000000..0dfcdcb --- /dev/null +++ b/ProjectRepairWork/Repositories/IBuildingMaterialsRepository.cs @@ -0,0 +1,18 @@ +using ProjectRepairWork.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Repositories; + +public interface IBuildingMaterialsRepository +{ + IEnumerable ReadBuildingMaterials(); + + BuildingMaterials ReadBuildingMaterialsById(int id); + void CreateBuildingMaterials(BuildingMaterials buildingMaterials); + void UpdateBuildingMaterials(BuildingMaterials buildingMaterials); + void DeletedBuildingMaterials(int id); +} diff --git a/ProjectRepairWork/Repositories/IMaterialProcurementRepository.cs b/ProjectRepairWork/Repositories/IMaterialProcurementRepository.cs new file mode 100644 index 0000000..c44ba19 --- /dev/null +++ b/ProjectRepairWork/Repositories/IMaterialProcurementRepository.cs @@ -0,0 +1,15 @@ +using ProjectRepairWork.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Repositories; + +public interface IMaterialProcurementRepository +{ + IEnumerable ReadMaterialProcurement(); + MaterialProcurement ReadMaterialProcurementById(int id); + void CreateMaterialProcurement(MaterialProcurement materialProcurement); +} diff --git a/ProjectRepairWork/Repositories/IRepairRepository.cs b/ProjectRepairWork/Repositories/IRepairRepository.cs index 6b8e90c..2ab91fc 100644 --- a/ProjectRepairWork/Repositories/IRepairRepository.cs +++ b/ProjectRepairWork/Repositories/IRepairRepository.cs @@ -10,5 +10,6 @@ namespace ProjectRepairWork.Repositories; public interface IRepairRepository { IEnumerable ReadRepair(int? contractorsId = null, int? costId = null, int? worksId = null, int? premisesId = null); + IEnumerable ReadRepairRepair(); void CraeteRepair(Repair repair); } diff --git a/ProjectRepairWork/Repositories/Implementation/BuildingMaterialsRepository.cs b/ProjectRepairWork/Repositories/Implementation/BuildingMaterialsRepository.cs new file mode 100644 index 0000000..bdd4dcd --- /dev/null +++ b/ProjectRepairWork/Repositories/Implementation/BuildingMaterialsRepository.cs @@ -0,0 +1,127 @@ +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using ProjectRepairWork.Entities; +using ProjectRepairWork.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Repositories.Implementation; + +public class BuildingMaterialsRepository : IBuildingMaterialsRepository +{ + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + public BuildingMaterialsRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateBuildingMaterials(BuildingMaterials buildingMaterials) + { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(buildingMaterials)); + + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" +INSERT INTO BuildingMaterials (MaterialsType) +VALUES (@MaterialsType)"; + connection.Execute(queryInsert, buildingMaterials); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } + public void UpdateBuildingMaterials(BuildingMaterials buildingMaterials) + { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(buildingMaterials)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" + UPDATE BuildingMaterials + SET + BuildingMaterials=@BuildingMaterials + WHERE Id=@Id"; + connection.Execute(queryUpdate, buildingMaterials); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } + } + + public void DeletedBuildingMaterials(int id) + { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" + DELETE FROM BuildingMaterials + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + + public IEnumerable ReadBuildingMaterials() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM buildingmaterials"; + var buildingMaterials = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(buildingMaterials)); + return buildingMaterials; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } + + public BuildingMaterials ReadBuildingMaterialsById(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" + SELECT * FROM BuildingMaterials + WHERE Id=@id"; + var buildingMaterials = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(buildingMaterials)); + return buildingMaterials; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + + +} diff --git a/ProjectRepairWork/Repositories/Implementation/MaterialProcurementRepository.cs b/ProjectRepairWork/Repositories/Implementation/MaterialProcurementRepository.cs new file mode 100644 index 0000000..8f900ae --- /dev/null +++ b/ProjectRepairWork/Repositories/Implementation/MaterialProcurementRepository.cs @@ -0,0 +1,88 @@ +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using ProjectRepairWork.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRepairWork.Repositories.Implementation; + +public class MaterialProcurementRepository : IMaterialProcurementRepository +{ + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public MaterialProcurementRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateMaterialProcurement(MaterialProcurement materialProcurement) + { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(materialProcurement)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" + INSERT INTO MaterialProcurement (MaterialsId, MaterialsPrice, ProcurmentDate) + VALUES (@MaterialsId, @MaterialsPrice, @ProcurmentDate)"; + connection.Execute(queryInsert, materialProcurement); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } + + public MaterialProcurement ReadMaterialProcurementById(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" + SELECT * FROM MaterialProcurement + WHERE Id=@id"; + var materialProcurement = connection.QueryFirst(querySelect, new + { + id + }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(materialProcurement)); + return materialProcurement; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + public IEnumerable ReadMaterialProcurement() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM MaterialProcurement"; + var materialProcurement = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(materialProcurement)); + return materialProcurement; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } + +} diff --git a/ProjectRepairWork/Repositories/Implementation/RepairRepository.cs b/ProjectRepairWork/Repositories/Implementation/RepairRepository.cs index 5612bc4..abdf7c0 100644 --- a/ProjectRepairWork/Repositories/Implementation/RepairRepository.cs +++ b/ProjectRepairWork/Repositories/Implementation/RepairRepository.cs @@ -33,8 +33,8 @@ public class RepairRepository : IRepairRepository connection.Open(); using var transaction = connection.BeginTransaction(); var queryInsert = @" - INSERT INTO Repair (ContractorsId, PremisesId) - VALUES (@ContractorsId, @PremisesId); + INSERT INTO Repair (ContractorsId, PremisesId, DateRepair) + VALUES (@ContractorsId, @PremisesId, @DateRepair); SELECT MAX(Id) FROM Repair"; var repairId = connection.QueryFirst(queryInsert, repair, transaction); @@ -77,4 +77,24 @@ public class RepairRepository : IRepairRepository throw; } } + + public IEnumerable ReadRepairRepair() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM RepairRepair"; + var repairRepairs = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(repairRepairs)); + return repairRepairs; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } } -- 2.25.1