ISEbd-21 Melnikov I. O. Lab Work 04 Advanced #28

Closed
Igor-Melnikov wants to merge 19 commits from lab4adv into lab3adv
11 changed files with 417 additions and 14 deletions
Showing only changes of commit a19fa632a7 - Show all commits

View File

@ -37,6 +37,7 @@
this.reportComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportManufactureComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportStoresToolStripMenuItem = 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();
@ -45,7 +46,7 @@
this.buttonRef = new System.Windows.Forms.Button();
this.buttonFillStore = new System.Windows.Forms.Button();
this.buttonSellManufacture = new System.Windows.Forms.Button();
this.reportStoresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportManufacturesInStoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -98,7 +99,8 @@
this.reportComponentsToolStripMenuItem,
this.reportManufactureComponentsToolStripMenuItem,
this.reportOrdersToolStripMenuItem,
this.reportStoresToolStripMenuItem});
this.reportStoresToolStripMenuItem,
this.reportManufacturesInStoreToolStripMenuItem});
this.reportToolStripMenuItem.Name = "reportToolStripMenuItem";
this.reportToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
this.reportToolStripMenuItem.Text = "Отчет";
@ -124,6 +126,13 @@
this.reportOrdersToolStripMenuItem.Text = "Список заказов";
this.reportOrdersToolStripMenuItem.Click += new System.EventHandler(this.ReportOrdersToolStripMenuItem_Click);
//
// reportStoresToolStripMenuItem
//
this.reportStoresToolStripMenuItem.Name = "reportStoresToolStripMenuItem";
this.reportStoresToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.reportStoresToolStripMenuItem.Text = "Список магазинов";
this.reportStoresToolStripMenuItem.Click += new System.EventHandler(this.ReportStoresToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
@ -210,12 +219,12 @@
this.buttonSellManufacture.UseVisualStyleBackColor = true;
this.buttonSellManufacture.Click += new System.EventHandler(this.ButtonSellManufacture_Click);
//
// reportStoresToolStripMenuItem
// reportManufacturesInStoreToolStripMenuItem
//
this.reportStoresToolStripMenuItem.Name = "reportStoresToolStripMenuItem";
this.reportStoresToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.reportStoresToolStripMenuItem.Text = "Список магазинов";
this.reportStoresToolStripMenuItem.Click += new System.EventHandler(this.ReportStoresToolStripMenuItem_Click);
this.reportManufacturesInStoreToolStripMenuItem.Name = "reportManufacturesInStoreToolStripMenuItem";
this.reportManufacturesInStoreToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.reportManufacturesInStoreToolStripMenuItem.Text = "Изделия в магазинах";
this.reportManufacturesInStoreToolStripMenuItem.Click += new System.EventHandler(this.ReportManufacturesInStoreToolStripMenuItem_Click);
//
// FormMain
//
@ -263,5 +272,6 @@
private ToolStripMenuItem reportManufactureComponentsToolStripMenuItem;
private ToolStripMenuItem reportOrdersToolStripMenuItem;
private ToolStripMenuItem reportStoresToolStripMenuItem;
private ToolStripMenuItem reportManufacturesInStoreToolStripMenuItem;
}
}

View File

@ -210,5 +210,15 @@ namespace BlacksmithWorkshopView
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void ReportManufacturesInStoreToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportManufacturesInStore));
if (service is FormReportManufacturesInStore form)
{
form.ShowDialog();
LoadData();
}
}
}
}

View File

@ -0,0 +1,103 @@
namespace BlacksmithWorkshopView
{
partial class FormReportManufacturesInStore
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonSaveToExcel = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ColumnStore = 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(12, 6);
this.buttonSaveToExcel.Name = "buttonSaveToExcel";
this.buttonSaveToExcel.Size = new System.Drawing.Size(188, 23);
this.buttonSaveToExcel.TabIndex = 3;
this.buttonSaveToExcel.Text = "Сохранить в Excel";
this.buttonSaveToExcel.UseVisualStyleBackColor = true;
this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click);
//
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ColumnStore,
this.ColumnManufacture,
this.ColumnCount});
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom;
this.dataGridView.Location = new System.Drawing.Point(0, 45);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(800, 405);
this.dataGridView.TabIndex = 2;
//
// ColumnStore
//
this.ColumnStore.HeaderText = "Магазин";
this.ColumnStore.Name = "ColumnStore";
//
// ColumnManufacture
//
this.ColumnManufacture.HeaderText = "Изделие";
this.ColumnManufacture.Name = "ColumnManufacture";
//
// ColumnCount
//
this.ColumnCount.HeaderText = "Количество";
this.ColumnCount.Name = "ColumnCount";
//
// FormReportManufacturesInStore
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonSaveToExcel);
this.Controls.Add(this.dataGridView);
this.Name = "FormReportManufacturesInStore";
this.Text = "Изделия в магазине";
this.Load += new System.EventHandler(this.FormReportManufacturesInStore_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button buttonSaveToExcel;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn ColumnStore;
private DataGridViewTextBoxColumn ColumnManufacture;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -0,0 +1,70 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopView
{
public partial class FormReportManufacturesInStore : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportManufacturesInStore(ILogger<FormReportManufacturesInStore> logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ButtonSaveToExcel_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveStoresToExcelFile(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);
}
}
}
private void FormReportManufacturesInStore_Load(object sender, EventArgs e)
{
try
{
var list = _logic.GetManufacturesInStore();
if (list != null)
{
dataGridView.Rows.Clear();
foreach (var elem in list)
{
dataGridView.Rows.Add(new object[] { elem.StoreName, "", "" });
foreach (var listElem in elem.Manufactures)
{
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2});
}
dataGridView.Rows.Add(new object[] {"Заполнено", $"{elem.HasManufactures} из {elem.MaxManufactures}", ""});
}
}
_logger.LogInformation("Загрузка списка изделий по компонентам");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка изделий по компонентам");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,69 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ColumnStore.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnManufacture.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -59,6 +59,7 @@ namespace BlacksmithWorkshopView
services.AddTransient<FormSellManufacture>();
services.AddTransient<FormReportManufactureComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormReportManufacturesInStore>();
}
}
}

View File

@ -59,6 +59,26 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
}
return list;
}
public List<ReportManufactureInStoreViewModel> GetManufacturesInStore()
{
var stores = _storeStorage.GetFullList();
var result = new List<ReportManufactureInStoreViewModel>();
foreach (var store in stores)
{
var record = new ReportManufactureInStoreViewModel()
{
StoreName = store.StoreName,
MaxManufactures = store.MaxManufactures,
HasManufactures = store.Manufactures.Select(x => x.Value.Item2).Sum()
};
foreach (var manufacture in store.Manufactures)
{
record.Manufactures.Add((manufacture.Value.Item1.ManufactureName.ToString(), manufacture.Value.Item2));
}
result.Add(record);
}
return result;
}
/// <summary>
/// Получение списка заказов за определенный период
/// </summary>
@ -121,10 +141,23 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
});
}
/// <summary>
/// Сохранение заказов в файл-Pdf
/// Сохранение информации о магазинах в файл-Excel
/// </summary>
/// <param name="model"></param>
public void SaveOrdersToPdfFile(ReportBindingModel model)
public void SaveStoresToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateStoresReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список магазинов",
ManufacturesInStore = GetManufacturesInStore()
});
}
/// <summary>
/// Сохранение заказов в файл-Pdf
/// </summary>
/// <param name="model"></param>
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{

View File

@ -1,5 +1,6 @@
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums;
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml.Drawing;
namespace BlacksmithWorkshopBusinessLogic.OfficePackage
{
@ -109,11 +110,95 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage
}
SaveExcel(info);
}
/// <summary>
/// Создание excel-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateExcel(ExcelInfo info);
/// <summary>
/// Создание отчета
/// </summary>
/// <param name="info"></param>
public void CreateStoresReport(ExcelInfo info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var MIS in info.ManufacturesInStore)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = MIS.StoreName,
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = "Изделие",
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = "Количество",
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
rowIndex++;
foreach (var rec in MIS.Manufactures)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = rec.Item1,
StyleInfo =
ExcelStyleInfoType.TextWithBorder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = rec.Item2.ToString(),
StyleInfo =
ExcelStyleInfoType.TextWithBorder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Заполнено",
StyleInfo =
ExcelStyleInfoType.TextWithBorder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = $"{MIS.HasManufactures} из {MIS.MaxManufactures}",
StyleInfo =
ExcelStyleInfoType.TextWithBorder
});
rowIndex++;
}
SaveExcel(info);
}
/// <summary>
/// Создание excel-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateExcel(ExcelInfo info);
/// <summary>
/// Добавляем новую ячейку в лист
/// </summary>

View File

@ -7,5 +7,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportManufactureComponentViewModel> ManufactureComponents { get; set; } = new();
public List<ReportManufactureInStoreViewModel> ManufacturesInStore { get; set; } = new();
}
}

View File

@ -17,6 +17,12 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
/// <returns></returns>
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
/// <summary>
/// Получение списка изделий в магазине
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
List<ReportManufactureInStoreViewModel> GetManufacturesInStore();
/// <summary>
/// Сохранение компонент в файл-Word
/// </summary>
/// <param name="model"></param>
@ -36,5 +42,10 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
/// </summary>
/// <param name="model"></param>
void SaveStoresToWordFile(ReportBindingModel model);
/// <summary>
/// Сохранение магазинов в файл-Excel
/// </summary>
/// <param name="model"></param>
void SaveStoresToExcelFile(ReportBindingModel model);
}
}

View File

@ -0,0 +1,10 @@
namespace BlacksmithWorkshopContracts.ViewModels
{
public class ReportManufactureInStoreViewModel
{
public string StoreName { get; set; } = string.Empty;
public int MaxManufactures { get; set; }
public int HasManufactures { get; set; }
public List<(string, int)> Manufactures { get; set; } = new();
}
}