diff --git a/Pizzeria/PizzeriaBusinessLogic/ReportLogic.cs b/Pizzeria/PizzeriaBusinessLogic/ReportLogic.cs index 13013f6..c326ec3 100644 --- a/Pizzeria/PizzeriaBusinessLogic/ReportLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/ReportLogic.cs @@ -3,7 +3,7 @@ using PizzeriaBusinessLogic.OfficePackage; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.SearchModels; -using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.StorageContracts; using PizzeriaContracts.ViewModels; using System; using System.Collections.Generic; diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs index 4acf003..06e44e9 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs @@ -17,12 +17,12 @@ namespace PizzeriaDatabaseImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.DateFrom.HasValue || !model.DateTo.HasValue) { return new(); } using var context = new PizzeriaDatabase(); - return context.Orders.Include(x => x.Pizza).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Pizza).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) diff --git a/Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs index 1ef42e6..fe96028 100644 --- a/Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs @@ -16,13 +16,11 @@ namespace PizzeriaFileImplement.Implements public List GetFullList() => source.Orders.Select(x => AttachPizzaName(x.GetViewModel)).ToList(); public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.DateFrom.HasValue || !model.DateTo.HasValue) { return new(); } - return source.Orders.Where(x => x.Id == model.Id) - .Select(x => AttachPizzaName(x.GetViewModel)) - .ToList(); + return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => AttachPizzaName(x.GetViewModel)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs index b594b9b..c37fa3e 100644 --- a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs @@ -30,13 +30,13 @@ namespace PizzeriaListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (model == null || !model.Id.HasValue) + if (model == null || !model.DateFrom.HasValue || !model.DateFrom.HasValue) { return result; } foreach (var order in _source.Orders) { - if (order.Id == model.Id) + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) { result.Add(AttachPizzaName(order.GetViewModel)); } diff --git a/Pizzeria/PizzeriaView/FormMain.Designer.cs b/Pizzeria/PizzeriaView/FormMain.Designer.cs index 572f0a2..932d4a8 100644 --- a/Pizzeria/PizzeriaView/FormMain.Designer.cs +++ b/Pizzeria/PizzeriaView/FormMain.Designer.cs @@ -32,6 +32,10 @@ this.bookToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ingridientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pizzasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ингредиентыПоПиццамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); @@ -46,7 +50,8 @@ // this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.bookToolStripMenuItem}); + this.bookToolStripMenuItem, + this.отчётыToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); @@ -66,17 +71,48 @@ // ingridientsToolStripMenuItem // this.ingridientsToolStripMenuItem.Name = "ingridientsToolStripMenuItem"; - this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.ingridientsToolStripMenuItem.Text = "Ингредиенты"; this.ingridientsToolStripMenuItem.Click += new System.EventHandler(this.IngridentsToolStripMenuItem_Click); // // pizzasToolStripMenuItem // this.pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem"; - this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.pizzasToolStripMenuItem.Text = "Пиццы"; this.pizzasToolStripMenuItem.Click += new System.EventHandler(this.PizzasToolStripMenuItem_Click); // + // отчётыToolStripMenuItem + // + this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ингредиентыToolStripMenuItem, + this.ингредиентыПоПиццамToolStripMenuItem, + this.списокЗаказовToolStripMenuItem}); + this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); + this.отчётыToolStripMenuItem.Text = "Отчёты"; + // + // ингредиентыToolStripMenuItem + // + this.ингредиентыToolStripMenuItem.Name = "ингредиентыToolStripMenuItem"; + this.ингредиентыToolStripMenuItem.Size = new System.Drawing.Size(211, 22); + this.ингредиентыToolStripMenuItem.Text = "Ингредиенты"; + this.ингредиентыToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + // + // ингредиентыПоПиццамToolStripMenuItem + // + this.ингредиентыПоПиццамToolStripMenuItem.Name = "ингредиентыПоПиццамToolStripMenuItem"; + this.ингредиентыПоПиццамToolStripMenuItem.Size = new System.Drawing.Size(211, 22); + this.ингредиентыПоПиццамToolStripMenuItem.Text = "Ингредиенты по пиццам"; + this.ингредиентыПоПиццамToolStripMenuItem.Click += new System.EventHandler(this.ComponentPizzaToolStripMenuItem_Click); + // + // списокЗаказовToolStripMenuItem + // + this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(211, 22); + this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; + this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.AllowUserToAddRows = false; @@ -183,5 +219,9 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; + private ToolStripMenuItem отчётыToolStripMenuItem; + private ToolStripMenuItem ингредиентыToolStripMenuItem; + private ToolStripMenuItem ингредиентыПоПиццамToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormMain.cs b/Pizzeria/PizzeriaView/FormMain.cs index 7138a9a..358cb95 100644 --- a/Pizzeria/PizzeriaView/FormMain.cs +++ b/Pizzeria/PizzeriaView/FormMain.cs @@ -17,11 +17,13 @@ namespace PizzeriaView { 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 FormMain_Load(object sender, EventArgs e) { @@ -152,5 +154,32 @@ namespace PizzeriaView { LoadData(); } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SavePizzasToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void ComponentPizzaToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportPizzaComponents)); + if (service is FormReportPizzaComponents 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(); + } + } } } diff --git a/Pizzeria/PizzeriaView/FormReportOrders.Designer.cs b/Pizzeria/PizzeriaView/FormReportOrders.Designer.cs new file mode 100644 index 0000000..855b952 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportOrders.Designer.cs @@ -0,0 +1,131 @@ +namespace PizzeriaView +{ + 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.labelFrom = new System.Windows.Forms.Label(); + this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); + this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); + this.labelTo = new System.Windows.Forms.Label(); + this.buttonMake = new System.Windows.Forms.Button(); + this.buttonToPDF = new System.Windows.Forms.Button(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPDF); + this.panel.Controls.Add(this.buttonMake); + this.panel.Controls.Add(this.dateTimePickerTo); + this.panel.Controls.Add(this.labelTo); + this.panel.Controls.Add(this.dateTimePickerFrom); + this.panel.Controls.Add(this.labelFrom); + 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(958, 52); + this.panel.TabIndex = 0; + // + // labelFrom + // + this.labelFrom.AutoSize = true; + this.labelFrom.Location = new System.Drawing.Point(12, 14); + this.labelFrom.Name = "labelFrom"; + this.labelFrom.Size = new System.Drawing.Size(18, 20); + this.labelFrom.TabIndex = 0; + this.labelFrom.Text = "C"; + // + // dateTimePickerFrom + // + this.dateTimePickerFrom.Location = new System.Drawing.Point(36, 9); + this.dateTimePickerFrom.Name = "dateTimePickerFrom"; + this.dateTimePickerFrom.Size = new System.Drawing.Size(199, 27); + this.dateTimePickerFrom.TabIndex = 1; + // + // dateTimePickerTo + // + this.dateTimePickerTo.Location = new System.Drawing.Point(300, 9); + this.dateTimePickerTo.Name = "dateTimePickerTo"; + this.dateTimePickerTo.Size = new System.Drawing.Size(199, 27); + this.dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + this.labelTo.AutoSize = true; + this.labelTo.Location = new System.Drawing.Point(254, 14); + this.labelTo.Name = "labelTo"; + this.labelTo.Size = new System.Drawing.Size(27, 20); + this.labelTo.TabIndex = 2; + this.labelTo.Text = "по"; + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(542, 10); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(165, 29); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // buttonToPDF + // + this.buttonToPDF.Location = new System.Drawing.Point(781, 9); + this.buttonToPDF.Name = "buttonToPDF"; + this.buttonToPDF.Size = new System.Drawing.Size(165, 29); + this.buttonToPDF.TabIndex = 5; + this.buttonToPDF.Text = "В PDF"; + this.buttonToPDF.UseVisualStyleBackColor = true; + this.buttonToPDF.Click += new System.EventHandler(this.ButtonToPdf_Click); + // + // FormReportOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(958, 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 buttonToPDF; + private Button buttonMake; + private DateTimePicker dateTimePickerTo; + private Label labelTo; + private DateTimePicker dateTimePickerFrom; + private Label labelFrom; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormReportOrders.cs b/Pizzeria/PizzeriaView/FormReportOrders.cs new file mode 100644 index 0000000..92f4a0f --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportOrders.cs @@ -0,0 +1,96 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +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 PizzeriaView +{ + 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("ReportOrder.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/Pizzeria/PizzeriaView/FormReportOrders.resx b/Pizzeria/PizzeriaView/FormReportOrders.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Pizzeria/PizzeriaView/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/Pizzeria/PizzeriaView/FormReportPizzaComponents.Designer.cs b/Pizzeria/PizzeriaView/FormReportPizzaComponents.Designer.cs new file mode 100644 index 0000000..9814d04 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportPizzaComponents.Designer.cs @@ -0,0 +1,118 @@ +namespace PizzeriaView +{ + partial class FormReportPizzaComponents + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnPizza = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AllowUserToOrderColumns = true; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnComponent, + this.ColumnPizza, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(0, 36); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(494, 302); + this.dataGridView.TabIndex = 0; + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 10); + this.buttonSaveToExcel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(243, 22); + this.buttonSaveToExcel.TabIndex = 1; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); + // + // ColumnComponent + // + this.ColumnComponent.FillWeight = 130F; + this.ColumnComponent.HeaderText = "Ингредиент"; + this.ColumnComponent.MinimumWidth = 6; + this.ColumnComponent.Name = "ColumnComponent"; + this.ColumnComponent.ReadOnly = true; + // + // ColumnPizza + // + this.ColumnPizza.FillWeight = 140F; + this.ColumnPizza.HeaderText = "Пиццы"; + this.ColumnPizza.MinimumWidth = 6; + this.ColumnPizza.Name = "ColumnPizza"; + this.ColumnPizza.ReadOnly = true; + // + // ColumnCount + // + this.ColumnCount.FillWeight = 90F; + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + // + // FormReportPizzaComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(494, 338); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormReportPizzaComponents"; + this.Text = "Пицца с ингридиентами"; + this.Load += new System.EventHandler(this.FormReportPizzaComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonSaveToExcel; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnPizza; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormReportPizzaComponents.cs b/Pizzeria/PizzeriaView/FormReportPizzaComponents.cs new file mode 100644 index 0000000..d98ff93 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportPizzaComponents.cs @@ -0,0 +1,77 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +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 PizzeriaView +{ + public partial class FormReportPizzaComponents : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportPizzaComponents(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormReportPizzaComponents_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetPizzaComponents(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.PizzaName, "", "" }); + 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 ButtonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SavePizzaComponentToExcelFile(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/Pizzeria/PizzeriaView/FormReportPizzaComponents.resx b/Pizzeria/PizzeriaView/FormReportPizzaComponents.resx new file mode 100644 index 0000000..e43288b --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportPizzaComponents.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/PizzeriaView.csproj b/Pizzeria/PizzeriaView/PizzeriaView.csproj index ca9fa0b..c7a8d17 100644 --- a/Pizzeria/PizzeriaView/PizzeriaView.csproj +++ b/Pizzeria/PizzeriaView/PizzeriaView.csproj @@ -16,6 +16,7 @@ + diff --git a/Pizzeria/PizzeriaView/Program.cs b/Pizzeria/PizzeriaView/Program.cs index a981fd8..07c4005 100644 --- a/Pizzeria/PizzeriaView/Program.cs +++ b/Pizzeria/PizzeriaView/Program.cs @@ -2,6 +2,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using PizzeriaBusinessLogic; +using PizzeriaBusinessLogic.BusinessLogics; +using PizzeriaBusinessLogic.Implements; +using PizzeriaBusinessLogic.OfficePackage; using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.StorageContracts; using PizzeriaDatabaseImplement.Implements; @@ -42,12 +45,20 @@ namespace PizzeriaView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file