diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs index d724dc4..744e48a 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -27,14 +27,15 @@ namespace BlacksmithWorkshopFileImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return new(); - } return source.Orders - .Where(x => x.Id == model.Id) - .Select(x => AccessManufactureStorage(x.GetViewModel)) - .ToList(); + .Where(x => ( + (!model.Id.HasValue || x.Id == model.Id) && + (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && + (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) + ) + ) + .Select(x => AccessManufactureStorage(x.GetViewModel)) + .ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 96c1b49..c88f4e0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -15,7 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImple EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopFileImplement", "BlackcmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{63C0A1A4-FA76-4F7C-8144-A33085F7DF08}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{ABAA2D01-0221-4DA6-BF09-6A5BB177A04D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{07550D11-E516-44E1-88A4-5B21E3EE72CC}" + ProjectSection(ProjectDependencies) = postProject + {40A50297-20F6-4F73-834D-0902F6F7965B} = {40A50297-20F6-4F73-834D-0902F6F7965B} + {96E8CFC7-A9D8-438B-AE8C-184ED25D5AAC} = {96E8CFC7-A9D8-438B-AE8C-184ED25D5AAC} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -47,10 +51,10 @@ Global {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Debug|Any CPU.Build.0 = Debug|Any CPU {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Release|Any CPU.ActiveCfg = Release|Any CPU {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Release|Any CPU.Build.0 = Release|Any CPU - {ABAA2D01-0221-4DA6-BF09-6A5BB177A04D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ABAA2D01-0221-4DA6-BF09-6A5BB177A04D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ABAA2D01-0221-4DA6-BF09-6A5BB177A04D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ABAA2D01-0221-4DA6-BF09-6A5BB177A04D}.Release|Any CPU.Build.0 = Release|Any CPU + {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index a1fa5e8..1cfdfbd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -9,13 +9,7 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -33,6 +27,13 @@ + + + + + + Always + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 4cec9c5..9a04e3d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -32,8 +32,10 @@ GuidesToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem = new ToolStripMenuItem(); ManufacturesToolStripMenuItem = new ToolStripMenuItem(); - ShopsToolStripMenuItem = new ToolStripMenuItem(); - SupplyToolStripMenuItem = new ToolStripMenuItem(); + ReportsToolStripMenuItem = new ToolStripMenuItem(); + ComponentsListToolStripMenuItem = new ToolStripMenuItem(); + ManufacturesListToolStripMenuItem = new ToolStripMenuItem(); + OrdersListToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonRefresh = new Button(); @@ -46,7 +48,7 @@ // // menuStrip // - menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem, ReportsToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1011, 24); @@ -63,17 +65,45 @@ // ComponentsToolStripMenuItem // ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(198, 22); + ComponentsToolStripMenuItem.Size = new Size(181, 22); ComponentsToolStripMenuItem.Text = "Компоненты"; ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; // // ManufacturesToolStripMenuItem // ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(198, 22); + ManufacturesToolStripMenuItem.Size = new Size(181, 22); ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; - // + // + // ReportsToolStripMenuItem + // + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsListToolStripMenuItem, ManufacturesListToolStripMenuItem, OrdersListToolStripMenuItem }); + ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; + ReportsToolStripMenuItem.Size = new Size(60, 20); + ReportsToolStripMenuItem.Text = "Отчёты"; + // + // ComponentsListToolStripMenuItem + // + ComponentsListToolStripMenuItem.Name = "ComponentsListToolStripMenuItem"; + ComponentsListToolStripMenuItem.Size = new Size(225, 22); + ComponentsListToolStripMenuItem.Text = "Список кузнечных изделий"; + ComponentsListToolStripMenuItem.Click += ComponentsListToolStripMenuItem_Click; + // + // ManufacturesListToolStripMenuItem + // + ManufacturesListToolStripMenuItem.Name = "ManufacturesListToolStripMenuItem"; + ManufacturesListToolStripMenuItem.Size = new Size(225, 22); + ManufacturesListToolStripMenuItem.Text = "Компоненты по изделиям"; + ManufacturesListToolStripMenuItem.Click += ManufacturesListToolStripMenuItem_Click; + // + // OrdersListToolStripMenuItem + // + OrdersListToolStripMenuItem.Name = "OrdersListToolStripMenuItem"; + OrdersListToolStripMenuItem.Size = new Size(225, 22); + OrdersListToolStripMenuItem.Text = "Список заказов"; + OrdersListToolStripMenuItem.Click += OrdersListToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -169,7 +199,9 @@ private Button buttonIssued; private Button buttonReady; private Button buttonTakeInWork; - private ToolStripMenuItem ShopsToolStripMenuItem; - private ToolStripMenuItem SupplyToolStripMenuItem; + private ToolStripMenuItem ReportsToolStripMenuItem; + private ToolStripMenuItem ComponentsListToolStripMenuItem; + private ToolStripMenuItem ManufacturesListToolStripMenuItem; + private ToolStripMenuItem OrdersListToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index a36bd2e..e3c4bdd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -18,11 +18,13 @@ namespace BlacksmithWorkshop { private readonly ILogger _logger; 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 ComponentsStripMenuItem_Click(object sender, EventArgs e) { @@ -163,21 +165,34 @@ namespace BlacksmithWorkshop { LoadData(); } - //private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - // if (service is FormShops form) - // { - // form.ShowDialog(); - // } - //} - //private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); - // if (service is FormSupply form) - // { - // form.ShowDialog(); - // } - //} + private void ComponentsListToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveComponentsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + private void ManufacturesListToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportManufactureComponents)); + if (service is FormReportManufactureComponents form) + { + form.ShowDialog(); + } + } + private void OrdersListToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.Designer.cs new file mode 100644 index 0000000..488743d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.Designer.cs @@ -0,0 +1,106 @@ +namespace BlacksmithWorkshop +{ + partial class FormReportManufactureComponents + { + /// + /// 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(); + SaveButton = new Button(); + ComponentColumn = new DataGridViewTextBoxColumn(); + ManufactureColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ComponentColumn, ManufactureColumn, CountColumn }); + dataGridView.Location = new Point(14, 61); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(651, 523); + dataGridView.TabIndex = 0; + // + // SaveButton + // + SaveButton.Location = new Point(14, 23); + SaveButton.Margin = new Padding(3, 4, 3, 4); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(193, 31); + SaveButton.TabIndex = 1; + SaveButton.Text = "Сохранить в Excel"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // ComponentColumn + // + ComponentColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ComponentColumn.HeaderText = "Компьютер"; + ComponentColumn.MinimumWidth = 6; + ComponentColumn.Name = "ComponentColumn"; + // + // ManufactureColumn + // + ManufactureColumn.HeaderText = "Компонент"; + ManufactureColumn.MinimumWidth = 6; + ManufactureColumn.Name = "ManufactureColumn"; + ManufactureColumn.Width = 200; + // + // CountColumn + // + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + CountColumn.Width = 130; + // + // FormReportManufactureComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(679, 600); + Controls.Add(SaveButton); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormReportManufactureComponents"; + Text = "Компоненты по компьютерам"; + Load += ReportManufactureComponentForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button SaveButton; + private DataGridViewTextBoxColumn ComponentColumn; + private DataGridViewTextBoxColumn ManufactureColumn; + private DataGridViewTextBoxColumn CountColumn; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.cs new file mode 100644 index 0000000..708682b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.cs @@ -0,0 +1,84 @@ +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 FormReportManufactureComponents : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + public FormReportManufactureComponents( + ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + + } + private void ReportManufactureComponentForm_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetManufactureComponent(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ManufactureName, "", "" }); + foreach (var listElem in elem.Components) + { + 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 SaveButton_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveManufactureComponentToExcelFile( + 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/FormReportManufactureComponents.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.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/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.Designer.cs new file mode 100644 index 0000000..a45a2e1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.Designer.cs @@ -0,0 +1,151 @@ +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() + { + panelTop = new Panel(); + ToPdfButton = new Button(); + MakeButton = new Button(); + labelUntill = new Label(); + labelFrom = new Label(); + dateTimePickerTo = new DateTimePicker(); + dateTimePickerFrom = new DateTimePicker(); + panelReport = new Panel(); + panelTop.SuspendLayout(); + SuspendLayout(); + // + // panelTop + // + panelTop.Controls.Add(ToPdfButton); + panelTop.Controls.Add(MakeButton); + panelTop.Controls.Add(labelUntill); + panelTop.Controls.Add(labelFrom); + panelTop.Controls.Add(dateTimePickerTo); + panelTop.Controls.Add(dateTimePickerFrom); + panelTop.Location = new Point(18, 20); + panelTop.Margin = new Padding(4, 5, 4, 5); + panelTop.Name = "panelTop"; + panelTop.Size = new Size(1109, 71); + panelTop.TabIndex = 0; + //panelTop.Paint += panelTop_Paint; + // + // ToPdfButton + // + ToPdfButton.Location = new Point(890, 29); + ToPdfButton.Margin = new Padding(4, 5, 4, 5); + ToPdfButton.Name = "ToPdfButton"; + ToPdfButton.Size = new Size(214, 39); + ToPdfButton.TabIndex = 5; + ToPdfButton.Text = "В Pdf"; + ToPdfButton.UseVisualStyleBackColor = true; + ToPdfButton.Click += ButtonToPdf_Click; + // + // MakeButton + // + MakeButton.Location = new Point(671, 29); + MakeButton.Margin = new Padding(4, 5, 4, 5); + MakeButton.Name = "MakeButton"; + MakeButton.Size = new Size(210, 39); + MakeButton.TabIndex = 4; + MakeButton.Text = "Сформировать"; + MakeButton.UseVisualStyleBackColor = true; + MakeButton.Click += MakeButton_Click; + // + // labelUntill + // + labelUntill.AutoSize = true; + labelUntill.Location = new Point(336, 39); + labelUntill.Margin = new Padding(4, 0, 4, 0); + labelUntill.Name = "labelUntill"; + labelUntill.Size = new Size(36, 25); + labelUntill.TabIndex = 3; + labelUntill.Text = "По"; + // + // labelFrom + // + labelFrom.AutoSize = true; + labelFrom.Location = new Point(11, 39); + labelFrom.Margin = new Padding(4, 0, 4, 0); + labelFrom.Name = "labelFrom"; + labelFrom.Size = new Size(23, 25); + labelFrom.TabIndex = 2; + labelFrom.Text = "С"; + // + // dateTimePickerTo + // + dateTimePickerTo.Location = new Point(378, 29); + dateTimePickerTo.Margin = new Padding(4, 5, 4, 5); + dateTimePickerTo.Name = "dateTimePickerTo"; + dateTimePickerTo.Size = new Size(284, 31); + dateTimePickerTo.TabIndex = 1; + // + // dateTimePickerFrom + // + dateTimePickerFrom.Location = new Point(41, 29); + dateTimePickerFrom.Margin = new Padding(4, 5, 4, 5); + dateTimePickerFrom.Name = "dateTimePickerFrom"; + dateTimePickerFrom.Size = new Size(284, 31); + dateTimePickerFrom.TabIndex = 0; + //dateTimePickerFrom.ValueChanged += dateTimePickerFrom_ValueChanged; + // + // panelReport + // + panelReport.Location = new Point(18, 100); + panelReport.Margin = new Padding(4); + panelReport.Name = "panelReport"; + panelReport.Size = new Size(1110, 635); + panelReport.TabIndex = 1; + //panelReport.Paint += panelReport_Paint; + // + // FormReportOrders + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1142, 750); + Controls.Add(panelReport); + Controls.Add(panelTop); + Margin = new Padding(4, 5, 4, 5); + Name = "FormReportOrders"; + Text = "Заказы"; + panelTop.ResumeLayout(false); + panelTop.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private Panel panelTop; + private Button ToPdfButton; + private Button MakeButton; + private Label labelUntill; + private Label labelFrom; + private DateTimePicker dateTimePickerTo; + private DateTimePicker dateTimePickerFrom; + private Panel panelReport; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.cs new file mode 100644 index 0000000..7d6df8f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.cs @@ -0,0 +1,100 @@ +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("ReportOrders.rdlc", FileMode.Open)); + panelReport.Controls.Add(reportViewer); + } + + private void MakeButton_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..28e1061 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 25 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 78a7aa8..0ca1e1b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -1,4 +1,6 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogics; +using BlacksmithWorkshopBusinessLogic.OfficePackage.Implements; +using BlacksmithWorkshopBusinessLogic.OfficePackage; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopDatabaseImplement.Implements; @@ -40,6 +42,10 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -47,6 +53,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..d4882e1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ReportOrders.rdlc @@ -0,0 +1,599 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 47cb53f0-7dde-4717-ba03-866a0bc4f4dd + + + + + + BlacksmithWorkshopContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + DateCreate + System.DateTime + + + ManufactureName + System.String + + + Sum + System.Decimal + + + OrderStatus + BlacksmithWorkshopDataModels.OrderStatus + + + + BlacksmithWorkshopContracts.ViewModels + ReportOrderViewModel + BlacksmithWorkshopContracts.ViewModels.ReportOrderViewModel, 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 + + + 2.5cm + + + 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 + 18.94755cm + 2 + + + + + + true + true + + + + + Итого: + + + + + + + 4cm + 12cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + 4cm + 14.5cm + 0.6cm + 2.5cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm +