diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ReportLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ReportLogic.cs index 5eb06d8..79de255 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ReportLogic.cs @@ -13,14 +13,16 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics private readonly IComponentStorage _componentStorage; private readonly ICarStorage _carStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(ICarStorage carStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(ICarStorage carStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _carStorage = carStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; @@ -113,5 +115,62 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics Orders = GetOrders(model) }); } + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateTableDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + public void SaveShopCarsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopCars = GetShopCars() + }); + } + public List GetShopCars() + { + var shops = _shopStorage.GetFullList(); + var list = new List(); + foreach (var shop in shops) + { + var record = new ReportShopCarsViewModel + { + ShopName = shop.Name, + Cars = new List>(), + Count = 0 + }; + foreach (var carCount in shop.ShopCars.Values) + { + record.Cars.Add(new Tuple(carCount.Item1.CarName, carCount.Item2)); + record.Count += carCount.Item2; + } + list.Add(record); + } + return list; + } + public List GetDateOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel + { + DateCreate = x.Key, + CountOrders = x.Count(), + SumOrders = x.Sum(y => y.Sum) + }).ToList(); + } + public void SaveDateOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateReportDateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Заказы по датам", + DateOrders = GetDateOrders() + }); + } } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 38421ea..5d35947 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -71,6 +71,68 @@ namespace AutomobilePlantBusinessLogic.OfficePackage } SaveExcel(info); } + public void CreateShopReport(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 pc in info.ShopCars) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var (CarName, Count) in pc.Cars) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = CarName, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.Count.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } /// /// Создание excel-файла /// diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 4320267..72fc6f2 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -44,6 +44,39 @@ namespace AutomobilePlantBusinessLogic.OfficePackage }); SavePdf(info); } + public void CreateReportDateDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "3cm", "3cm", "7cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата", "Количество", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var order in info.DateOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.DateCreate.ToShortDateString(), order.CountOrders.ToString(), order.SumOrders.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {info.DateOrders.Sum(x => x.SumOrders)}\t", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + SavePdf(info); + } /// /// Создание doc-файла /// diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 0149bf4..5393c82 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -35,6 +35,27 @@ namespace AutomobilePlantBusinessLogic.OfficePackage } SaveWord(info); } + public void CreateTableDoc(WordInfo wordInfo) + { + CreateWord(wordInfo); + var list = new List(); + foreach (var shop in wordInfo.Shops) + { + list.Add(shop.Name); + list.Add(shop.Address); + list.Add(shop.OpeningDate.ToString()); + } + var wordTable = new WordTable + { + Headers = new List { + "Название", + "Адрес", + "Дата открытия"}, + Texts = list + }; + CreateTable(wordTable); + SaveWord(wordInfo); + } /// /// Создание doc-файла /// @@ -51,5 +72,10 @@ namespace AutomobilePlantBusinessLogic.OfficePackage /// /// protected abstract void SaveWord(WordInfo info); + /// + /// создание таблицы + /// + /// + protected abstract void CreateTable(WordTable info); } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index f587f16..89f09fa 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -11,5 +11,10 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels get; set; } = new(); + public List ShopCars + { + get; + set; + } = new(); } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 7717d1a..9488cc9 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -9,5 +9,6 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } public List Orders { get; set; } = new(); + public List DateOrders { get; set; } = new(); } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index ce24a8c..456f30b 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -7,5 +7,6 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List Cars { get; set; } = new(); + public List Shops { get; set; } = new(); } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordTable.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..bc1da0b --- /dev/null +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordTable.cs @@ -0,0 +1,8 @@ +namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels +{ + public class WordTable + { + public List Headers { get; set; } = new(); + public List Texts { get; set; } = new(); + } +} diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 5f41504..ad98545 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -120,5 +120,85 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.Implements _wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.Close(); } + protected override void CreateTable(WordTable table) + { + if (_docBody == null || table == null) + { + return; + } + Table tab = new Table(); + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + ) + ); + tab.AppendChild(props); + TableGrid tableGrid = new TableGrid(); + for (int i = 0; i < table.Headers.Count; i++) + { + tableGrid.AppendChild(new GridColumn()); + } + tab.AppendChild(tableGrid); + TableRow tableRow = new TableRow(); + foreach (var text in table.Headers) + { + tableRow.AppendChild(CreateTableCell(text)); + } + tab.AppendChild(tableRow); + int height = table.Texts.Count / table.Headers.Count; + int width = table.Headers.Count; + for (int i = 0; i < height; i++) + { + tableRow = new TableRow(); + for (int j = 0; j < width; j++) + { + var element = table.Texts[i * table.Headers.Count + j]; + tableRow.AppendChild(CreateTableCell(element)); + } + tab.AppendChild(tableRow); + } + + _docBody.AppendChild(tab); + + } + private TableCell CreateTableCell(string element) + { + var tableParagraph = new Paragraph(); + var run = new Run(); + run.AppendChild(new Text { Text = element }); + tableParagraph.AppendChild(run); + var tableCell = new TableCell(); + tableCell.AppendChild(tableParagraph); + return tableCell; + } } } diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IReportLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IReportLogic.cs index 34ec38b..c72a1dc 100644 --- a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IReportLogic.cs @@ -31,6 +31,31 @@ namespace AutomobilePlantContracts.BusinessLogicsContracts /// /// void SaveOrdersToPdfFile(ReportBindingModel model); + /// + /// Сохранение магазинов в файл-Word + /// + /// + void SaveShopsToWordFile(ReportBindingModel model); + /// + /// Сохранение магазинов с указаеним продуктов в файл-Excel + /// + /// + void SaveShopCarsToExcelFile(ReportBindingModel model); + /// + /// Получение списка магазинов + /// + /// + List GetShopCars(); + /// + /// Получение списка заказов с группировкой по датам + /// + /// + List GetDateOrders(); + /// + /// Сохранение заказов с группировкой по датам в файл-Pdf + /// + /// + void SaveDateOrdersToPdfFile(ReportBindingModel model); } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportDateOrdersViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportDateOrdersViewModel.cs new file mode 100644 index 0000000..d47dfea --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportDateOrdersViewModel.cs @@ -0,0 +1,9 @@ +namespace AutomobilePlantContracts.ViewModels +{ + public class ReportDateOrdersViewModel + { + public DateTime DateCreate { get; set; } + public int CountOrders { get; set; } + public double SumOrders { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportShopCarsViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportShopCarsViewModel.cs new file mode 100644 index 0000000..62deabf --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportShopCarsViewModel.cs @@ -0,0 +1,9 @@ +namespace AutomobilePlantContracts.ViewModels +{ + public class ReportShopCarsViewModel + { + public string ShopName { get; set; } = string.Empty; + public int Count { get; set; } + public List> Cars { get; set; } = new(); + } +} diff --git a/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj b/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj index dc9eee4..5be27a0 100644 --- a/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj +++ b/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj @@ -33,6 +33,9 @@ Always + + Always + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs index 73b7750..0e29fb5 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs @@ -32,19 +32,22 @@ toolStripMenuItemCatalogs = new ToolStripMenuItem(); toolStripMenuItemComponents = new ToolStripMenuItem(); toolStripMenuItemCars = new ToolStripMenuItem(); + shopsToolStripMenuItem = new ToolStripMenuItem(); + shopsSupplyToolStripMenuItem = new ToolStripMenuItem(); + sellCarsToolStripMenuItem = new ToolStripMenuItem(); reportsToolStripMenuItem = new ToolStripMenuItem(); carsListToolStripMenuItem = new ToolStripMenuItem(); componentsByCarsToolStripMenuItem = new ToolStripMenuItem(); ordersListToolStripMenuItem = new ToolStripMenuItem(); - shopsToolStripMenuItem = new ToolStripMenuItem(); - shopsSupplyToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRefresh = new Button(); - sellCarsToolStripMenuItem = new ToolStripMenuItem(); + shopsListToolStripMenuItem = new ToolStripMenuItem(); + storeCongestionToolStripMenuItem = new ToolStripMenuItem(); + listOdOrdersByDatesToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -68,20 +71,41 @@ // toolStripMenuItemComponents // toolStripMenuItemComponents.Name = "toolStripMenuItemComponents"; - toolStripMenuItemComponents.Size = new Size(143, 22); + toolStripMenuItemComponents.Size = new Size(147, 22); toolStripMenuItemComponents.Text = "Components"; toolStripMenuItemComponents.Click += ComponentsToolStripMenuItem_Click; // // toolStripMenuItemCars // toolStripMenuItemCars.Name = "toolStripMenuItemCars"; - toolStripMenuItemCars.Size = new Size(143, 22); + toolStripMenuItemCars.Size = new Size(147, 22); toolStripMenuItemCars.Text = "Cars"; toolStripMenuItemCars.Click += CarsToolStripMenuItem_Click; // + // shopsToolStripMenuItem + // + shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + shopsToolStripMenuItem.Size = new Size(147, 22); + shopsToolStripMenuItem.Text = "Shops"; + shopsToolStripMenuItem.Click += shopsToolStripMenuItem_Click; + // + // shopsSupplyToolStripMenuItem + // + shopsSupplyToolStripMenuItem.Name = "shopsSupplyToolStripMenuItem"; + shopsSupplyToolStripMenuItem.Size = new Size(147, 22); + shopsSupplyToolStripMenuItem.Text = "Shop's supply"; + shopsSupplyToolStripMenuItem.Click += shopsSupplyToolStripMenuItem_Click; + // + // sellCarsToolStripMenuItem + // + sellCarsToolStripMenuItem.Name = "sellCarsToolStripMenuItem"; + sellCarsToolStripMenuItem.Size = new Size(147, 22); + sellCarsToolStripMenuItem.Text = "Sell Cars"; + sellCarsToolStripMenuItem.Click += sellCarsToolStripMenuItem_Click; + // // reportsToolStripMenuItem // - reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { carsListToolStripMenuItem, componentsByCarsToolStripMenuItem, ordersListToolStripMenuItem }); + reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { carsListToolStripMenuItem, componentsByCarsToolStripMenuItem, ordersListToolStripMenuItem, shopsListToolStripMenuItem, storeCongestionToolStripMenuItem, listOdOrdersByDatesToolStripMenuItem }); reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; reportsToolStripMenuItem.Size = new Size(59, 20); reportsToolStripMenuItem.Text = "Reports"; @@ -107,20 +131,6 @@ ordersListToolStripMenuItem.Text = "Orders' list"; ordersListToolStripMenuItem.Click += ordersListToolStripMenuItem_Click; // - // shopsToolStripMenuItem - // - shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; - shopsToolStripMenuItem.Size = new Size(180, 22); - shopsToolStripMenuItem.Text = "Shops"; - shopsToolStripMenuItem.Click += shopsToolStripMenuItem_Click; - // - // shopsSupplyToolStripMenuItem - // - shopsSupplyToolStripMenuItem.Name = "shopsSupplyToolStripMenuItem"; - shopsSupplyToolStripMenuItem.Size = new Size(180, 22); - shopsSupplyToolStripMenuItem.Text = "Shop's supply"; - shopsSupplyToolStripMenuItem.Click += shopsSupplyToolStripMenuItem_Click; - // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -180,12 +190,26 @@ buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRef_Click; // - // sellCarsToolStripMenuItem + // shopsListToolStripMenuItem // - sellCarsToolStripMenuItem.Name = "sellCarsToolStripMenuItem"; - sellCarsToolStripMenuItem.Size = new Size(180, 22); - sellCarsToolStripMenuItem.Text = "Sell Cars"; - sellCarsToolStripMenuItem.Click += sellCarsToolStripMenuItem_Click; + shopsListToolStripMenuItem.Name = "shopsListToolStripMenuItem"; + shopsListToolStripMenuItem.Size = new Size(192, 22); + shopsListToolStripMenuItem.Text = "Shops' list"; + shopsListToolStripMenuItem.Click += shopsListToolStripMenuItem_Click; + // + // storeCongestionToolStripMenuItem + // + storeCongestionToolStripMenuItem.Name = "storeCongestionToolStripMenuItem"; + storeCongestionToolStripMenuItem.Size = new Size(192, 22); + storeCongestionToolStripMenuItem.Text = "Store congestion"; + storeCongestionToolStripMenuItem.Click += storeCongestionToolStripMenuItem_Click; + // + // listOdOrdersByDatesToolStripMenuItem + // + listOdOrdersByDatesToolStripMenuItem.Name = "listOdOrdersByDatesToolStripMenuItem"; + listOdOrdersByDatesToolStripMenuItem.Size = new Size(192, 22); + listOdOrdersByDatesToolStripMenuItem.Text = "List od orders by dates"; + listOdOrdersByDatesToolStripMenuItem.Click += listOdOrdersByDatesToolStripMenuItem_Click; // // FormMain // @@ -228,5 +252,8 @@ private ToolStripMenuItem shopsToolStripMenuItem; private ToolStripMenuItem shopsSupplyToolStripMenuItem; private ToolStripMenuItem sellCarsToolStripMenuItem; + private ToolStripMenuItem shopsListToolStripMenuItem; + private ToolStripMenuItem storeCongestionToolStripMenuItem; + private ToolStripMenuItem listOdOrdersByDatesToolStripMenuItem; } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.cs b/AutomobilePlant/AutomobilePlantView/FormMain.cs index 361fd02..64b3e9a 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.cs @@ -125,6 +125,37 @@ namespace AutomobilePlantView } } + private void shopsListToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void storeCongestionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopCars)); + if (service is FormReportShopCars form) + { + form.ShowDialog(); + } + } + + private void listOdOrdersByDatesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportDateOrders)); + if (service is FormReportDateOrders form) + { + form.ShowDialog(); + } + } + // управление заказами private void ButtonCreateOrder_Click(object sender, EventArgs e) { diff --git a/AutomobilePlant/AutomobilePlantView/FormReportDateOrders.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormReportDateOrders.Designer.cs new file mode 100644 index 0000000..7ef1816 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormReportDateOrders.Designer.cs @@ -0,0 +1,86 @@ +namespace AutomobilePlantView +{ + partial class FormReportDateOrders + { + /// + /// 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() + { + panel = new Panel(); + ButtonToPdf = new Button(); + buttonMake = new Button(); + panel.SuspendLayout(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(ButtonToPdf); + panel.Controls.Add(buttonMake); + panel.Dock = DockStyle.Top; + panel.Location = new Point(0, 0); + panel.Name = "panel"; + panel.Size = new Size(800, 46); + panel.TabIndex = 0; + // + // ButtonToPdf + // + ButtonToPdf.Location = new Point(93, 12); + ButtonToPdf.Name = "ButtonToPdf"; + ButtonToPdf.Size = new Size(75, 23); + ButtonToPdf.TabIndex = 7; + ButtonToPdf.Text = "To PDF"; + ButtonToPdf.UseVisualStyleBackColor = true; + ButtonToPdf.Click += buttonToPDF_Click; + // + // buttonMake + // + buttonMake.Location = new Point(12, 12); + buttonMake.Name = "buttonMake"; + buttonMake.Size = new Size(75, 23); + buttonMake.TabIndex = 6; + buttonMake.Text = "Make"; + buttonMake.UseVisualStyleBackColor = true; + buttonMake.Click += buttonMake_Click; + // + // FormReportDateOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(panel); + Name = "FormReportDateOrders"; + Text = "FormReportDateOrders"; + FormClosed += FormReportDateOrders_FormClosed; + panel.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button ButtonToPdf; + private Button buttonMake; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormReportDateOrders.cs b/AutomobilePlant/AutomobilePlantView/FormReportDateOrders.cs new file mode 100644 index 0000000..b6cc8c0 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormReportDateOrders.cs @@ -0,0 +1,75 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; + +namespace AutomobilePlantView +{ + public partial class FormReportDateOrders : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + private readonly FileStream _fileStream; + public FormReportDateOrders(ILogger logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + _fileStream = new FileStream("ReportOrdersByDate.rdlc", FileMode.Open); + reportViewer.LocalReport.LoadReportDefinition(_fileStream); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void buttonMake_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetDateOrders(); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на весь период по датам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonToPDF_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveDateOrdersToPdfFile(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 FormReportDateOrders_FormClosed(object sender, FormClosedEventArgs e) + { + _fileStream.Close(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormReportDateOrders.resx b/AutomobilePlant/AutomobilePlantView/FormReportDateOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormReportDateOrders.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/AutomobilePlant/AutomobilePlantView/FormReportShopCars.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormReportShopCars.Designer.cs new file mode 100644 index 0000000..8afbc8a --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormReportShopCars.Designer.cs @@ -0,0 +1,99 @@ +namespace AutomobilePlantView +{ + partial class FormReportShopCars + { + /// + /// 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() + { + buttonSaveToExcel = new Button(); + dataGridView = new DataGridView(); + Shop = new DataGridViewTextBoxColumn(); + Car = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(12, 12); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(128, 23); + buttonSaveToExcel.TabIndex = 0; + buttonSaveToExcel.Text = "Save to Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += buttonSaveToExcel_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Shop, Car, Count }); + dataGridView.Location = new Point(12, 41); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(776, 397); + dataGridView.TabIndex = 1; + // + // Shop + // + Shop.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + Shop.HeaderText = "Shop"; + Shop.Name = "Shop"; + // + // Car + // + Car.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + Car.HeaderText = "Car"; + Car.Name = "Car"; + // + // Count + // + Count.HeaderText = "Count"; + Count.Name = "Count"; + // + // FormReportShopCars + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(buttonSaveToExcel); + Name = "FormReportShopCars"; + Text = "FormReportShopCars"; + Load += FormReportShopCars_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Shop; + private DataGridViewTextBoxColumn Car; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormReportShopCars.cs b/AutomobilePlant/AutomobilePlantView/FormReportShopCars.cs new file mode 100644 index 0000000..a479be3 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormReportShopCars.cs @@ -0,0 +1,72 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantView +{ + public partial class FormReportShopCars : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShopCars(ILogger logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + } + + private void buttonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopCarsToExcelFile(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 FormReportShopCars_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopCars(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Cars) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Всего:", "", elem.Count }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка магазинов с авто в них"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов с авто в них"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormReportShopCars.resx b/AutomobilePlant/AutomobilePlantView/FormReportShopCars.resx new file mode 100644 index 0000000..a92e9e3 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormReportShopCars.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/AutomobilePlant/AutomobilePlantView/Program.cs b/AutomobilePlant/AutomobilePlantView/Program.cs index 36c9a7f..4fddd7d 100644 --- a/AutomobilePlant/AutomobilePlantView/Program.cs +++ b/AutomobilePlant/AutomobilePlantView/Program.cs @@ -56,6 +56,8 @@ namespace AutomobilePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AutomobilePlant/AutomobilePlantView/ReportOrdersByDate.rdlc b/AutomobilePlant/AutomobilePlantView/ReportOrdersByDate.rdlc new file mode 100644 index 0000000..523ad30 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/ReportOrdersByDate.rdlc @@ -0,0 +1,424 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + AutomobilePlantContractsViewModels + /* Local Query */ + + + + DateCreate + System.DateTime + + + CountOrders + System.Decimal + + + SumOrders + System.Double + + + + AutomobilePlantContracts.ViewModels + ReportDateOrdersViewModel + AutomobilePlantContracts.ViewModels.ReportDateOrdersViewModel, AutomobilePlantContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Заказы + + + + + + + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 6.01401cm + + + 6.56042cm + + + 6.12687cm + + + + + 0.6cm + + + + + true + true + + + + + Дата + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!DateCreate.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!CountOrders.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!SumOrders.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 1.95474cm + 1.16099cm + 1.2cm + 18.7013cm + 1 + + + + + + true + true + + + + + Всего: + + + + + + + 4cm + 11.23542cm + 0.6cm + 2.5cm + 2 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!SumOrders.Value, "DataSetOrders") + + + + + + + 4cm + 13.73542cm + 0.6cm + 6.12687cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm +