diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index 99ddb32..6dfd051 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -9,13 +9,17 @@ - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 018e907..3a5ea42 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -34,12 +34,16 @@ this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); this.toolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.workPieceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.manufactureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.workPiecesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.workPieceManufacturesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.menuStrip1.SuspendLayout(); + this.menuStrip.SuspendLayout(); this.SuspendLayout(); // // dataGridView @@ -102,16 +106,17 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // - // menuStrip1 + // menuStrip // - this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1297, 28); - this.menuStrip1.TabIndex = 6; - this.menuStrip1.Text = "menuStrip1"; + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem, + this.reportsToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1297, 28); + this.menuStrip.TabIndex = 6; + this.menuStrip.Text = "menuStrip1"; // // toolStripMenuItem // @@ -136,6 +141,37 @@ this.manufactureToolStripMenuItem.Text = "Изделия"; this.manufactureToolStripMenuItem.Click += new System.EventHandler(this.ManufactureToolStripMenuItem_Click); // + // reportsToolStripMenuItem + // + this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.workPiecesToolStripMenuItem, + this.workPieceManufacturesToolStripMenuItem, + this.ordersToolStripMenuItem}); + this.reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; + this.reportsToolStripMenuItem.Size = new System.Drawing.Size(73, 24); + this.reportsToolStripMenuItem.Text = "Отчёты"; + // + // workPiecesToolStripMenuItem + // + this.workPiecesToolStripMenuItem.Name = "workPiecesToolStripMenuItem"; + this.workPiecesToolStripMenuItem.Size = new System.Drawing.Size(256, 26); + this.workPiecesToolStripMenuItem.Text = "Список заготовок"; + this.workPiecesToolStripMenuItem.Click += new System.EventHandler(this.WorkPiecesToolStripMenuItem_Click); + // + // workPieceManufacturesToolStripMenuItem + // + this.workPieceManufacturesToolStripMenuItem.Name = "workPieceManufacturesToolStripMenuItem"; + this.workPieceManufacturesToolStripMenuItem.Size = new System.Drawing.Size(256, 26); + this.workPieceManufacturesToolStripMenuItem.Text = "Заготовки по изделиям"; + this.workPieceManufacturesToolStripMenuItem.Click += new System.EventHandler(this.WorkPieceManufacturesToolStripMenuItem_Click); + // + // ordersToolStripMenuItem + // + this.ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; + this.ordersToolStripMenuItem.Size = new System.Drawing.Size(256, 26); + this.ordersToolStripMenuItem.Text = "Список заказов"; + this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -147,14 +183,14 @@ this.Controls.Add(this.buttonTakeOrderInWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip1); - this.MainMenuStrip = this.menuStrip1; + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; this.Name = "FormMain"; this.Text = "Кузнечная мастерская"; this.Load += new System.EventHandler(this.FormMain_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -168,9 +204,13 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; - private MenuStrip menuStrip1; + private MenuStrip menuStrip; private ToolStripMenuItem toolStripMenuItem; private ToolStripMenuItem workPieceToolStripMenuItem; private ToolStripMenuItem manufactureToolStripMenuItem; + private ToolStripMenuItem reportsToolStripMenuItem; + private ToolStripMenuItem workPiecesToolStripMenuItem; + private ToolStripMenuItem workPieceManufacturesToolStripMenuItem; + private ToolStripMenuItem ordersToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 879038a..95d8437 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopDataModels.Enums; using Microsoft.Extensions.Logging; @@ -20,12 +21,15 @@ namespace BlacksmithWorkshop private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) + private readonly IReportLogic _reportLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; + _reportLogic= reportLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -45,6 +49,7 @@ namespace BlacksmithWorkshop { dataGridView.DataSource = list; dataGridView.Columns["ManufactureId"].Visible = false; + dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); @@ -177,6 +182,41 @@ namespace BlacksmithWorkshop } } + private void WorkPiecesToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveManufacturesToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void WorkPieceManufacturesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportManufactureWorkPieces)); + + if (service is FormReportManufactureWorkPieces form) + { + form.ShowDialog(); + } + } + + private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } + private void ButtonRef_Click(object sender, EventArgs e) { LoadData(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx index 938108a..81a9e3d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx @@ -57,7 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureWorkPieces.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureWorkPieces.Designer.cs new file mode 100644 index 0000000..5892651 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureWorkPieces.Designer.cs @@ -0,0 +1,108 @@ +namespace BlacksmithWorkshop +{ + partial class FormReportManufactureWorkPieces + { + /// + /// 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() + { + this.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumWorkPiece = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnManufacture = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(33, 25); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(256, 29); + this.buttonSaveToExcel.TabIndex = 0; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumWorkPiece, + this.ColumnManufacture, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; + this.dataGridView.Location = new System.Drawing.Point(0, 73); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(800, 395); + this.dataGridView.TabIndex = 1; + // + // ColumWorkPiece + // + this.ColumWorkPiece.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumWorkPiece.HeaderText = "Заготовка"; + this.ColumWorkPiece.MinimumWidth = 6; + this.ColumWorkPiece.Name = "ColumWorkPiece"; + // + // ColumnManufacture + // + this.ColumnManufacture.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnManufacture.HeaderText = "Изделие"; + this.ColumnManufacture.MinimumWidth = 6; + this.ColumnManufacture.Name = "ColumnManufacture"; + // + // ColumnCount + // + this.ColumnCount.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + // + // FormReportManufactureWorkPieces + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 468); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonSaveToExcel); + this.Name = "FormReportManufactureWorkPieces"; + this.Text = "Заготовки по изделиям"; + this.Load += new System.EventHandler(this.FormReportManufactureWorkPieces_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumWorkPiece; + private DataGridViewTextBoxColumn ColumnManufacture; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureWorkPieces.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureWorkPieces.cs new file mode 100644 index 0000000..0001b09 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureWorkPieces.cs @@ -0,0 +1,94 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 BlacksmithWorkshop +{ + public partial class FormReportManufactureWorkPieces : Form + { + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportManufactureWorkPieces(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + + _logger = logger; + _logic = logic; + } + + private void FormReportManufactureWorkPieces_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetManufactureWorkPiece(); + + if (dict != null) + { + dataGridView.Rows.Clear(); + + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ManufactureName, "", "" }); + + foreach (var listElem in elem.WorkPieces) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + + _logger.LogInformation("Загрузка списка изделий по заготовкам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий по заготовкам"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSaveToExcel_Click(object sender, EventArgs e) + { + //фильтрация файлов для диалогового окна + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveManufactureWorkPieceToExcelFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + + _logger.LogInformation("Сохранение списка изделий по заготовкам"); + + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка изделий по заготовкам"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureWorkPieces.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureWorkPieces.resx new file mode 100644 index 0000000..c9ea820 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureWorkPieces.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.Designer.cs new file mode 100644 index 0000000..a463e3b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.Designer.cs @@ -0,0 +1,131 @@ +namespace BlacksmithWorkshop +{ + partial class FormReportOrders + { + /// + /// 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() + { + this.panel = new System.Windows.Forms.Panel(); + this.buttonToPdf = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); + this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPdf); + this.panel.Controls.Add(this.buttonMake); + this.panel.Controls.Add(this.label2); + this.panel.Controls.Add(this.label1); + this.panel.Controls.Add(this.dateTimePickerTo); + this.panel.Controls.Add(this.dateTimePickerFrom); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(1112, 51); + this.panel.TabIndex = 0; + // + // buttonToPdf + // + this.buttonToPdf.Location = new System.Drawing.Point(894, 10); + this.buttonToPdf.Name = "buttonToPdf"; + this.buttonToPdf.Size = new System.Drawing.Size(157, 29); + this.buttonToPdf.TabIndex = 5; + this.buttonToPdf.Text = "В Pdf"; + this.buttonToPdf.UseVisualStyleBackColor = true; + this.buttonToPdf.Click += new System.EventHandler(this.ButtonToPdf_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(612, 10); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(157, 29); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(263, 17); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(27, 20); + this.label2.TabIndex = 3; + this.label2.Text = "по"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(25, 17); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(18, 20); + this.label1.TabIndex = 2; + this.label1.Text = "С"; + // + // dateTimePickerTo + // + this.dateTimePickerTo.Location = new System.Drawing.Point(313, 12); + this.dateTimePickerTo.Name = "dateTimePickerTo"; + this.dateTimePickerTo.Size = new System.Drawing.Size(169, 27); + this.dateTimePickerTo.TabIndex = 1; + // + // dateTimePickerFrom + // + this.dateTimePickerFrom.Location = new System.Drawing.Point(65, 12); + this.dateTimePickerFrom.Name = "dateTimePickerFrom"; + this.dateTimePickerFrom.Size = new System.Drawing.Size(176, 27); + this.dateTimePickerFrom.TabIndex = 0; + // + // FormReportOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1112, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportOrders"; + this.Text = "Заказы"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button buttonMake; + private Label label2; + private Label label1; + private DateTimePicker dateTimePickerTo; + private DateTimePicker dateTimePickerFrom; + private Button buttonToPdf; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.cs new file mode 100644 index 0000000..24fb6e0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.cs @@ -0,0 +1,122 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +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 BlacksmithWorkshop +{ + //форма с отчётом + public partial class FormReportOrders : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + + _logger = logger; + _logic = logic; + + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + + reportViewer.LocalReport.LoadReportDefinition(new FileStream("C:\\Users\\Programmist73\\Desktop\\Практика\\2-й курс\\4-й семестр\\PIbd-21_Eliseev_E.E._BlacksmithWorkshop\\BlacksmithWorkshop\\BlacksmithWorkshop\\ReportOrders.rdlc", FileMode.Open)); + + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + try + { + var dataSource = _logic.GetOrders(new ReportBindingModel + { + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + + var source = new ReportDataSource("DataSetOrders", dataSource); + + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + + var parameters = new[] { new ReportParameter("ReportParameterPeriod", + $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; + + reportViewer.LocalReport.SetParameters(parameters); + reportViewer.RefreshReport(); + + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), + dateTimePickerTo.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonToPdf_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + + using var dialog = new SaveFileDialog + { + Filter = "pdf|*.pdf" + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + + _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", + dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index a42137a..69c39d2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -1,4 +1,6 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopBusinessLogic.OfficePackage; +using BlacksmithWorkshopBusinessLogic.OfficePackage.Implements; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopDatabaseImplement.Implements; @@ -44,6 +46,11 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -52,7 +59,8 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } - } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ReportOrders.rdlc b/BlacksmithWorkshop/BlacksmithWorkshop/ReportOrders.rdlc new file mode 100644 index 0000000..a3c5a15 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ReportOrders.rdlc @@ -0,0 +1,599 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + BlacksmithWorkshopContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + DateCreate + System.DateTime + + + ManufactureName + System.String + + + Sum + System.Decimal + + + OrderStatus + System.String + + + + BlacksmithWorkshopContracts.ViewModels + ReportOrdersViewModel + BlacksmithWorkshopContracts.ViewModels.ReportOrdersViewModel, BlacksmithWorkshopContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 1cm + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + Заказы + + + + + + + 1cm + 21cm + 1 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 2.5cm + + + 3.21438cm + + + 8.23317cm + + + 3.21438cm + + + 2.5cm + + + + + 0.6cm + + + + + true + true + + + + + Номер + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Дата создания + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Изделие + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Статус заказа + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Id.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!DateCreate.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!ManufactureName.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrderStatus.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 2.48391cm + 0.55245cm + 1.2cm + 19.66193cm + 2 + + + + + + true + true + + + + + Итого: + + + + + + + 4cm + 15.21438cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + 4cm + 17.71438cm + 0.6cm + 2.5cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm +