From 5da801ce3462778f7979bfa1a42823f086d5ac9d Mon Sep 17 00:00:00 2001 From: Yourdax Date: Tue, 12 Nov 2024 03:11:10 +0400 Subject: [PATCH] just start --- KopLab1/KopLab1.sln | 8 +- KopLab1/Lab3Form/FormMain.Designer.cs | 265 ++++++----- KopLab1/Lab3Form/FormMain.cs | 435 +++++------------- KopLab1/Lab3Form/FormMain.resx | 12 - KopLab1/Lab3Form/FormOrders.Designer.cs | 175 +++++++ KopLab1/Lab3Form/FormOrders.cs | 343 ++++++++++++++ KopLab1/Lab3Form/FormOrders.resx | 135 ++++++ KopLab1/Lab3Form/Lab3Form.csproj | 1 + KopLab1/Lab3Form/PluginsManager.cs | 47 ++ .../Plugins/IPluginsConvention.cs | 68 +++ .../Plugins/PluginsConventionElement.cs | 7 + .../Plugins/PluginsConventionSaveDocument.cs | 7 + .../PluginsConventionLibrary.csproj | 24 + 13 files changed, 1070 insertions(+), 457 deletions(-) create mode 100644 KopLab1/Lab3Form/FormOrders.Designer.cs create mode 100644 KopLab1/Lab3Form/FormOrders.cs create mode 100644 KopLab1/Lab3Form/FormOrders.resx create mode 100644 KopLab1/Lab3Form/PluginsManager.cs create mode 100644 KopLab1/PluginsConventionLibrary/Plugins/IPluginsConvention.cs create mode 100644 KopLab1/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs create mode 100644 KopLab1/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs create mode 100644 KopLab1/PluginsConventionLibrary/PluginsConventionLibrary.csproj diff --git a/KopLab1/KopLab1.sln b/KopLab1/KopLab1.sln index 53e75fd..44ff65d 100644 --- a/KopLab1/KopLab1.sln +++ b/KopLab1/KopLab1.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InternetShopOrdersContracts EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InternetShopOrdersBusinessLogic", "InternetShopOrdersBusinessLogic\InternetShopOrdersBusinessLogic.csproj", "{148CAD37-ECDC-4B97-9AD0-1D0990B1B8BE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab3Form", "Lab3Form\Lab3Form.csproj", "{3329D6FC-A78D-46A7-9EA3-C0ECD21143CB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3Form", "Lab3Form\Lab3Form.csproj", "{3329D6FC-A78D-46A7-9EA3-C0ECD21143CB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginsConventionLibrary", "PluginsConventionLibrary\PluginsConventionLibrary.csproj", "{B8173741-064A-41C8-83C1-1E2A5B91B0D3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {3329D6FC-A78D-46A7-9EA3-C0ECD21143CB}.Debug|Any CPU.Build.0 = Debug|Any CPU {3329D6FC-A78D-46A7-9EA3-C0ECD21143CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {3329D6FC-A78D-46A7-9EA3-C0ECD21143CB}.Release|Any CPU.Build.0 = Release|Any CPU + {B8173741-064A-41C8-83C1-1E2A5B91B0D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B8173741-064A-41C8-83C1-1E2A5B91B0D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B8173741-064A-41C8-83C1-1E2A5B91B0D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B8173741-064A-41C8-83C1-1E2A5B91B0D3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/KopLab1/Lab3Form/FormMain.Designer.cs b/KopLab1/Lab3Form/FormMain.Designer.cs index dec5284..3973da6 100644 --- a/KopLab1/Lab3Form/FormMain.Designer.cs +++ b/KopLab1/Lab3Form/FormMain.Designer.cs @@ -28,148 +28,147 @@ /// private void InitializeComponent() { - components = new System.ComponentModel.Container(); - menuStrip = new MenuStrip(); - заказыToolStripMenuItem = new ToolStripMenuItem(); - создатьToolStripMenuItem = new ToolStripMenuItem(); - редактироватьToolStripMenuItem = new ToolStripMenuItem(); - удалитьToolStripMenuItem = new ToolStripMenuItem(); - отчётыToolStripMenuItem = new ToolStripMenuItem(); - документToolStripMenuItem = new ToolStripMenuItem(); - документСТаблицейToolStripMenuItem = new ToolStripMenuItem(); - документСДиаграммойToolStripMenuItem = new ToolStripMenuItem(); - выбранныеТоварыToolStripMenuItem = new ToolStripMenuItem(); - controlDataTable = new ControlsLibraryNet60.Data.ControlDataTableTable(); - pdfTable1 = new FormLibrary.PDFTable(components); - excelTableComponent1 = new WinFormsLibraryVolkov.NonVisualComponents.ExcelTableComponent(components); - componentDocumentWithChartLineWord1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartLineWord(components); - menuStrip.SuspendLayout(); - SuspendLayout(); + this.panelControl = new System.Windows.Forms.Panel(); + this.ControlsStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ActionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.AddElementToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.UpdElementToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.DelElementToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.DocsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SimpleDocToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.TableDocToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ChartDocToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // panelControl + // + this.panelControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panelControl.BackColor = System.Drawing.SystemColors.Info; + this.panelControl.Location = new System.Drawing.Point(12, 27); + this.panelControl.Name = "panelControl"; + this.panelControl.Size = new System.Drawing.Size(896, 177); + this.panelControl.TabIndex = 2; + // + // ControlsStripMenuItem + // + this.ControlsStripMenuItem.Name = "ControlsStripMenuItem"; + this.ControlsStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.ControlsStripMenuItem.Text = "Directories"; + // + // ActionsToolStripMenuItem + // + this.ActionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.AddElementToolStripMenuItem, + this.UpdElementToolStripMenuItem, + this.DelElementToolStripMenuItem}); + this.ActionsToolStripMenuItem.Name = "ActionsToolStripMenuItem"; + this.ActionsToolStripMenuItem.Size = new System.Drawing.Size(70, 20); + this.ActionsToolStripMenuItem.Text = "Actions"; + // + // AddElementToolStripMenuItem + // + this.AddElementToolStripMenuItem.Name = "AddElementToolStripMenuItem"; + this.AddElementToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.A))); + this.AddElementToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + this.AddElementToolStripMenuItem.Text = "Add"; + this.AddElementToolStripMenuItem.Click += new System.EventHandler(this.AddElementToolStripMenuItem_Click); + // + // UpdElementToolStripMenuItem + // + this.UpdElementToolStripMenuItem.Name = "UpdElementToolStripMenuItem"; + this.UpdElementToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U))); + this.UpdElementToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + this.UpdElementToolStripMenuItem.Text = "Edit"; + this.UpdElementToolStripMenuItem.Click += new System.EventHandler(this.UpdElementToolStripMenuItem_Click); + // + // DelElementToolStripMenuItem + // + this.DelElementToolStripMenuItem.Name = "DelElementToolStripMenuItem"; + this.DelElementToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D))); + this.DelElementToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + this.DelElementToolStripMenuItem.Text = "Delete"; + this.DelElementToolStripMenuItem.Click += new System.EventHandler(this.DelElementToolStripMenuItem_Click); + // + // DocsToolStripMenuItem + // + this.DocsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.SimpleDocToolStripMenuItem, + this.TableDocToolStripMenuItem, + this.ChartDocToolStripMenuItem}); + this.DocsToolStripMenuItem.Name = "DocsToolStripMenuItem"; + this.DocsToolStripMenuItem.Size = new System.Drawing.Size(82, 20); + this.DocsToolStripMenuItem.Text = "Documnets"; + // + // SimpleDocToolStripMenuItem + // + this.SimpleDocToolStripMenuItem.Name = "SimpleDocToolStripMenuItem"; + this.SimpleDocToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); + this.SimpleDocToolStripMenuItem.Size = new System.Drawing.Size(233, 22); + this.SimpleDocToolStripMenuItem.Text = "Excel"; + this.SimpleDocToolStripMenuItem.Click += new System.EventHandler(this.WordDocToolStripMenuItem_Click); + // + // TableDocToolStripMenuItem + // + this.TableDocToolStripMenuItem.Name = "TableDocToolStripMenuItem"; + this.TableDocToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T))); + this.TableDocToolStripMenuItem.Size = new System.Drawing.Size(233, 22); + this.TableDocToolStripMenuItem.Text = "Word"; + this.TableDocToolStripMenuItem.Click += new System.EventHandler(this.PdfDocToolStripMenuItem_Click); + // + // ChartDocToolStripMenuItem + // + this.ChartDocToolStripMenuItem.Name = "ChartDocToolStripMenuItem"; + this.ChartDocToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C))); + this.ChartDocToolStripMenuItem.Size = new System.Drawing.Size(233, 22); + this.ChartDocToolStripMenuItem.Text = "Pdf"; + this.ChartDocToolStripMenuItem.Click += new System.EventHandler(this.ExcelDocToolStripMenuItem_Click); // // menuStrip // - menuStrip.ImageScalingSize = new Size(18, 18); - menuStrip.Items.AddRange(new ToolStripItem[] { заказыToolStripMenuItem, отчётыToolStripMenuItem, выбранныеТоварыToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Padding = new Padding(5, 2, 0, 2); - menuStrip.Size = new Size(853, 24); - menuStrip.TabIndex = 0; - menuStrip.Text = "menuStrip"; - // - // заказыToolStripMenuItem - // - заказыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьToolStripMenuItem, редактироватьToolStripMenuItem, удалитьToolStripMenuItem }); - заказыToolStripMenuItem.Name = "заказыToolStripMenuItem"; - заказыToolStripMenuItem.Size = new Size(58, 20); - заказыToolStripMenuItem.Text = "Заказы"; - // - // создатьToolStripMenuItem - // - создатьToolStripMenuItem.Name = "создатьToolStripMenuItem"; - создатьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; - создатьToolStripMenuItem.Size = new Size(196, 22); - создатьToolStripMenuItem.Text = "Создать"; - создатьToolStripMenuItem.Click += создатьToolStripMenuItem_Click; - // - // редактироватьToolStripMenuItem - // - редактироватьToolStripMenuItem.Name = "редактироватьToolStripMenuItem"; - редактироватьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U; - редактироватьToolStripMenuItem.Size = new Size(196, 22); - редактироватьToolStripMenuItem.Text = "Редактировать"; - редактироватьToolStripMenuItem.Click += редактироватьToolStripMenuItem_Click; - // - // удалитьToolStripMenuItem - // - удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem"; - удалитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D; - удалитьToolStripMenuItem.Size = new Size(196, 22); - удалитьToolStripMenuItem.Text = "Удалить"; - удалитьToolStripMenuItem.Click += удалитьToolStripMenuItem_Click; - // - // отчётыToolStripMenuItem - // - отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документToolStripMenuItem, документСТаблицейToolStripMenuItem, документСДиаграммойToolStripMenuItem }); - отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; - отчётыToolStripMenuItem.Size = new Size(60, 20); - отчётыToolStripMenuItem.Text = "Отчёты"; - // - // документToolStripMenuItem - // - документToolStripMenuItem.Name = "документToolStripMenuItem"; - документToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; - документToolStripMenuItem.Size = new Size(309, 22); - документToolStripMenuItem.Text = "Документ с простой таблицей"; - документToolStripMenuItem.Click += GeneratePdfButton_Click; - // - // документСТаблицейToolStripMenuItem - // - документСТаблицейToolStripMenuItem.Name = "документСТаблицейToolStripMenuItem"; - документСТаблицейToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T; - документСТаблицейToolStripMenuItem.Size = new Size(309, 22); - документСТаблицейToolStripMenuItem.Text = "Отчет по всем заказам Excel"; - документСТаблицейToolStripMenuItem.Click += buttonCreateOrderReport_Click; - // - // документСДиаграммойToolStripMenuItem - // - документСДиаграммойToolStripMenuItem.Name = "документСДиаграммойToolStripMenuItem"; - документСДиаграммойToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C; - документСДиаграммойToolStripMenuItem.Size = new Size(309, 22); - документСДиаграммойToolStripMenuItem.Text = "Документ с линейной диаграммой"; - документСДиаграммойToolStripMenuItem.Click += CreateDocumentButton_Click; - // - // выбранныеТоварыToolStripMenuItem - // - выбранныеТоварыToolStripMenuItem.Name = "выбранныеТоварыToolStripMenuItem"; - выбранныеТоварыToolStripMenuItem.Size = new Size(125, 20); - выбранныеТоварыToolStripMenuItem.Text = "Города назначения"; - выбранныеТоварыToolStripMenuItem.Click += выбранныеТоварыToolStripMenuItem_Click; - // - // controlDataTable - // - controlDataTable.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - controlDataTable.AutoSize = true; - controlDataTable.Location = new Point(0, 24); - controlDataTable.Margin = new Padding(4, 3, 4, 3); - controlDataTable.Name = "controlDataTable"; - controlDataTable.SelectedRowIndex = -1; - controlDataTable.Size = new Size(853, 419); - controlDataTable.TabIndex = 1; + this.menuStrip.AutoSize = false; + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ControlsStripMenuItem, + this.ActionsToolStripMenuItem, + this.DocsToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(920, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "Menu"; // // FormMain // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(853, 442); - Controls.Add(controlDataTable); - Controls.Add(menuStrip); - MainMenuStrip = menuStrip; - Margin = new Padding(3, 2, 3, 2); - Name = "FormMain"; - Text = "Заказы"; - Load += FormMain_Load; - menuStrip.ResumeLayout(false); - menuStrip.PerformLayout(); - ResumeLayout(false); - PerformLayout(); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(920, 216); + this.Controls.Add(this.panelControl); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Main Form"; + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormMain_KeyDown); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + } #endregion - + private Panel panelControl; + private ToolStripMenuItem ControlsStripMenuItem; + private ToolStripMenuItem ActionsToolStripMenuItem; + private ToolStripMenuItem AddElementToolStripMenuItem; + private ToolStripMenuItem UpdElementToolStripMenuItem; + private ToolStripMenuItem DelElementToolStripMenuItem; + private ToolStripMenuItem DocsToolStripMenuItem; + private ToolStripMenuItem SimpleDocToolStripMenuItem; + private ToolStripMenuItem TableDocToolStripMenuItem; + private ToolStripMenuItem ChartDocToolStripMenuItem; private MenuStrip menuStrip; - private ToolStripMenuItem заказыToolStripMenuItem; - private ToolStripMenuItem создатьToolStripMenuItem; - private ToolStripMenuItem редактироватьToolStripMenuItem; - private ToolStripMenuItem удалитьToolStripMenuItem; - private ToolStripMenuItem отчётыToolStripMenuItem; - private ToolStripMenuItem документToolStripMenuItem; - private ToolStripMenuItem документСТаблицейToolStripMenuItem; - private ToolStripMenuItem выбранныеТоварыToolStripMenuItem; - private ToolStripMenuItem документСДиаграммойToolStripMenuItem; - private ControlsLibraryNet60.Data.ControlDataTableTable controlDataTable; - private FormLibrary.PDFTable pdfTable1; - private WinFormsLibraryVolkov.NonVisualComponents.ExcelTableComponent excelTableComponent1; - private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartLineWord componentDocumentWithChartLineWord1; } } \ No newline at end of file diff --git a/KopLab1/Lab3Form/FormMain.cs b/KopLab1/Lab3Form/FormMain.cs index 6ef61ae..ec81ce8 100644 --- a/KopLab1/Lab3Form/FormMain.cs +++ b/KopLab1/Lab3Form/FormMain.cs @@ -1,343 +1,156 @@ -using InternetShopOrdersBusinessLogic.BusinessLogics; -using InternetShopOrdersContracts.BusinessLogicContracts; -using InternetShopOrdersContracts.ViewModels; -using InternetShopOrdersContracts.BindingModels; -using InternetShopOrdersContracts.SearchModels; -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 PluginsConventionLibrary.Plugins; using System.Windows.Forms; -using ControlsLibraryNet60.Models; -using Microsoft.EntityFrameworkCore.Diagnostics; -using WinFormsLibraryVolkov.NonVisualComponents; -using ComponentsLibraryNet60.Core; -using ComponentsLibraryNet60.DocumentWithTable; -using ComponentsLibraryNet60.Models; -using FormLibrary.HelperClasses; -using FormLibrary; -using ComponentsLibraryNet60.DocumentWithChart; -using Microsoft.Win32; namespace Lab3Form { public partial class FormMain : Form { - private IOrderLogic _logic; + private readonly Dictionary _plugins; + private string _selectedPlugin; - public FormMain(IOrderLogic logic) + public FormMain() { InitializeComponent(); - _logic = logic; - controlDataTable.LoadColumns(new List - { - new DataTableColumnConfig { ColumnHeader = "Идентификатор", PropertyName = "Id", Visible = true, Width = 100 }, - new DataTableColumnConfig { ColumnHeader = "ФИО заказчика", PropertyName = "Fullname", Visible = true, Width = 200 }, - new DataTableColumnConfig { ColumnHeader = "Город назначения", PropertyName = "DestinationCityName", Visible = true, Width = 150 }, - new DataTableColumnConfig { ColumnHeader = "История передвижения", PropertyName = "OrderStatusHistory", Visible = true, Width = 250 }, - new DataTableColumnConfig { ColumnHeader = "Дата выдачи", PropertyName = "ExpectedDeliveryDate", Visible = true, Width = 125 }, - }); - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + _plugins = LoadPlugins(); + _selectedPlugin = string.Empty; } - private void LoadData() + private Dictionary LoadPlugins() { - controlDataTable.Clear(); - var orders = _logic.ReadList(null); - if (orders != null) + PluginsManager manager = new PluginsManager(); + var plugins = manager.plugins_dictionary; + + ToolStripItem[] toolStripItems = new ToolStripItem[plugins.Count]; + int i = 0; + if (plugins.Count > 0) { - var displayOrders = orders.Select(order => new + foreach (var plugin in plugins) { - order.Id, - order.Fullname, - order.DestinationCityName, - OrderStatusHistory = string.Join(", ", order.OrderStatusHistory), - order.ExpectedDeliveryDate - }).ToList(); - controlDataTable.AddTable(displayOrders); - } - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void создатьToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormOrder)); - if (service is FormOrder form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - - private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormOrder)); - if (service is FormOrder form) - { - form._id = controlDataTable.GetSelectedObject().Id; - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - - private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) - { - var selectedOrder = controlDataTable.GetSelectedObject(); - if (selectedOrder == null) - { - MessageBox.Show("Не выбрана запись для удаления."); - return; - } - if (MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - var isDeleted = _logic.Delete(new OrderBindingModel { Id = selectedOrder.Id ?? 0 }); - if (isDeleted) - { - LoadData(); - MessageBox.Show("Запись успешно удалена."); - } - else - { - MessageBox.Show("Ошибка при удалении записи."); - } - } - } - - private void GeneratePdfButton_Click(object sender, EventArgs e) - { - try - { - - var orders = _logic.ReadList(null); - - - var orderTables = new List(); - - foreach (var order in orders) - { - - int rowCount = order.OrderStatusHistory.Count; - - - string[,] orderTable = new string[rowCount+1, 4]; - - - orderTable[0, 0] = "Статус"; - orderTable[0, 1] = "Идентификатор заказа"; - orderTable[0, 2] = "Город назначения"; - orderTable[0, 3] = "Дата доставки"; - - - for (int i = 0; i < rowCount; i++) + ToolStripMenuItem itemMenu = new() { - orderTable[i+1, 0] = order.OrderStatusHistory[i]; - orderTable[i+1, 1] = order.Id.ToString(); - orderTable[i+1, 2] = order.DestinationCityName; - orderTable[i+1, 3] = order.ExpectedDeliveryDate.ToString("yyyy-MM-dd"); - } - - - orderTables.Add(orderTable); - } - - - using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()) - { - saveFileDialog.Filter = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*"; - saveFileDialog.Title = "Сохранить PDF-документ"; - saveFileDialog.FileName = "Отчет1.pdf"; - - if (saveFileDialog.ShowDialog() == DialogResult.OK) + Text = plugin.Value.PluginName + }; + itemMenu.Click += (sender, e) => { - - var pdfData = new PdfDocumentData( - saveFileDialog.FileName, - "Отчет по заказам", - orderTables - ); - - var documentGenerator = new PDFTable(); - documentGenerator.GeneratePdf(pdfData); - - MessageBox.Show("PDF-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + _selectedPlugin = plugin.Value.PluginName; + panelControl.Controls.Clear(); + panelControl.Controls.Add(_plugins[_selectedPlugin].GetControl); + panelControl.Controls[0].Dock = DockStyle.Fill; + }; + toolStripItems[i] = itemMenu; + i++; } + ControlsStripMenuItem.DropDownItems.AddRange(toolStripItems); } - catch (Exception ex) + return plugins; + } + + private void AddNewElement() + { + var form = _plugins[_selectedPlugin].GetForm(null); + if (form != null && form.ShowDialog() == DialogResult.OK) { - MessageBox.Show($"Произошла ошибка: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _plugins[_selectedPlugin].ReloadData(); } } - private void buttonCreateOrderReport_Click(object sender, EventArgs e) + private void UpdateElement() { - - var orders = _logic.ReadList(null); - if (orders == null || orders.Count == 0) + var element = _plugins[_selectedPlugin].GetElement; + if (element == null) + { + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + var form = _plugins[_selectedPlugin].GetForm(element); + if (form != null && form.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + + private void DeleteElement() + { + if (MessageBox.Show(" ", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } + var element = _plugins[_selectedPlugin].GetElement; + if (element == null) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_plugins[_selectedPlugin].DeleteElement(element)) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + + private void CreateWord() + { + if (_plugins[_selectedPlugin].GetElement == null) return; + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() != DialogResult.OK) return; + if (!_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument { FileName = dialog.FileName })) + { + MessageBox.Show("Error", "!", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CreatePdf() + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() != DialogResult.OK) return; + if (!_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument { FileName = dialog.FileName })) + { + MessageBox.Show("Error", "!", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CreateExcel() + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (dialog.ShowDialog() != DialogResult.OK) return; + if (!_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument { FileName = dialog.FileName })) + { + MessageBox.Show("Error", "!", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormMain_KeyDown(object sender, KeyEventArgs e) + { + if (!e.Control) { - MessageBox.Show("Нет заказов для отчета.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - - var tableData = new List(); - foreach (var order in orders) + switch (e.KeyCode) { - if (order != null) - { - tableData.Add(new OrderExcelViewModel( - order.Id, - order.Fullname, - order.DestinationCityName, - order.ExpectedDeliveryDate - )); - } - } - string path = AppDomain.CurrentDomain.BaseDirectory + "OrderReport.xlsx"; - - using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()) - { - saveFileDialog.Title = "Сохранить Excel-документ"; - saveFileDialog.FileName = "Отчет2.xlsx"; - - if (saveFileDialog.ShowDialog() == DialogResult.OK) - { - path = saveFileDialog.FileName; - - MessageBox.Show("Excel-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - - - List<(int, int)> merges = new List<(int, int)> - { - (0,1), - (2, 3) - }; - - List heights = Enumerable.Repeat(20, 4).ToList(); - - - List<(string, string)> headers = new List<(string, string)> - { - - ("","Данные"), - ("Id", "Идентификатор"), - ("Fullname", "ФИО заказчика"), - ("", "Заказ"), - ("DestinationCityName", "Город назначения"), - ("ExpectedDeliveryDate", "Дата получения заказа") - }; - - if (merges.Count == 0 || heights.Count == 0 || headers.Count == 0 || tableData.Count == 0) - { - MessageBox.Show("Недостаточно данных для создания отчета.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - Console.WriteLine($"Merges Count: {merges.Count}"); - Console.WriteLine($"Heights Count: {heights.Count}"); - Console.WriteLine($"Headers Count: {headers.Count}"); - Console.WriteLine($"TableData Count: {tableData.Count}"); - if (excelTableComponent1.createWithTable(path, "Отчет по заказам", merges, heights, headers, tableData)) - { - MessageBox.Show("Отчет успешно создан!"); - } - else - { - MessageBox.Show("Ошибка при создании отчета.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + case Keys.A: + AddNewElement(); + break; + case Keys.U: + UpdateElement(); + break; + case Keys.D: + DeleteElement(); + break; + case Keys.S: + CreateWord(); + break; + case Keys.T: + CreatePdf(); + break; + case Keys.C: + CreateExcel(); + break; } } - - private void CreateDocumentButton_Click(object sender, EventArgs e) - { - - var orders = _logic.ReadList(null).Cast().ToList(); - - - var chartData = new Dictionary>(); - - foreach (var order in orders) - { - if (!chartData.ContainsKey(order.DestinationCityName)) - { - chartData[order.DestinationCityName] = new List<(DateTime Date, int Count)>(); - } - - - var existingData = chartData[order.DestinationCityName] - .FirstOrDefault(d => d.Date.Date == order.ExpectedDeliveryDate.Date); - - if (existingData.Date == default) - { - chartData[order.DestinationCityName].Add((order.ExpectedDeliveryDate.Date, 1)); - } - else - { - - int index = chartData[order.DestinationCityName].FindIndex(d => d.Date.Date == order.ExpectedDeliveryDate.Date); - var updatedValue = chartData[order.DestinationCityName][index]; - chartData[order.DestinationCityName][index] = (updatedValue.Date, updatedValue.Count + 1); - } - } - - string filePath = "Отчет3.docx"; - - using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()) - { - saveFileDialog.Title = "Сохранить Word-документ"; - saveFileDialog.FileName = "Отчет3.docx"; - - if (saveFileDialog.ShowDialog() == DialogResult.OK) - { - filePath = saveFileDialog.FileName; - - MessageBox.Show("Docx-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - var config = new ComponentDocumentWithChartConfig - { - ChartTitle = "Отчет по заказам", - LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom, - Data = chartData.ToDictionary( - entry => entry.Key, - entry => entry.Value.Select(d => (DateTimeToInt(d.Date), (double)d.Count)).ToList()), - FilePath = filePath, - Header = "Заголовок отчета" - - }; - - - var documentComponent = new ComponentDocumentWithChartLineWord(); - - - documentComponent.CreateDoc(config); - - MessageBox.Show("Документ создан успешно!"); - } - private int DateTimeToInt(DateTime date) - { - return date.Day; - } - - - private void выбранныеТоварыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCities)); - if (service is FormCities form) - { - form.ShowDialog(); - } - } + private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement(); + private void UpdElementToolStripMenuItem_Click(object sender, EventArgs e) => UpdateElement(); + private void DelElementToolStripMenuItem_Click(object sender, EventArgs e) => DeleteElement(); + private void WordDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateExcel(); + private void PdfDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateWord(); + private void ExcelDocToolStripMenuItem_Click(object sender, EventArgs e) => CreatePdf(); } -} +} \ No newline at end of file diff --git a/KopLab1/Lab3Form/FormMain.resx b/KopLab1/Lab3Form/FormMain.resx index 6f2a6fb..31084d5 100644 --- a/KopLab1/Lab3Form/FormMain.resx +++ b/KopLab1/Lab3Form/FormMain.resx @@ -120,16 +120,4 @@ 17, 17 - - 126, 17 - - - 231, 17 - - - 409, 17 - - - 177 - \ No newline at end of file diff --git a/KopLab1/Lab3Form/FormOrders.Designer.cs b/KopLab1/Lab3Form/FormOrders.Designer.cs new file mode 100644 index 0000000..5453a5d --- /dev/null +++ b/KopLab1/Lab3Form/FormOrders.Designer.cs @@ -0,0 +1,175 @@ +namespace Lab3Form +{ + partial class FormOrders + { + /// + /// 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() + { + components = new System.ComponentModel.Container(); + menuStrip = new MenuStrip(); + заказыToolStripMenuItem = new ToolStripMenuItem(); + создатьToolStripMenuItem = new ToolStripMenuItem(); + редактироватьToolStripMenuItem = new ToolStripMenuItem(); + удалитьToolStripMenuItem = new ToolStripMenuItem(); + отчётыToolStripMenuItem = new ToolStripMenuItem(); + документToolStripMenuItem = new ToolStripMenuItem(); + документСТаблицейToolStripMenuItem = new ToolStripMenuItem(); + документСДиаграммойToolStripMenuItem = new ToolStripMenuItem(); + выбранныеТоварыToolStripMenuItem = new ToolStripMenuItem(); + controlDataTable = new ControlsLibraryNet60.Data.ControlDataTableTable(); + pdfTable1 = new FormLibrary.PDFTable(components); + excelTableComponent1 = new WinFormsLibraryVolkov.NonVisualComponents.ExcelTableComponent(components); + componentDocumentWithChartLineWord1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartLineWord(components); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(18, 18); + menuStrip.Items.AddRange(new ToolStripItem[] { заказыToolStripMenuItem, отчётыToolStripMenuItem, выбранныеТоварыToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Padding = new Padding(5, 2, 0, 2); + menuStrip.Size = new Size(853, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip"; + // + // заказыToolStripMenuItem + // + заказыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьToolStripMenuItem, редактироватьToolStripMenuItem, удалитьToolStripMenuItem }); + заказыToolStripMenuItem.Name = "заказыToolStripMenuItem"; + заказыToolStripMenuItem.Size = new Size(58, 20); + заказыToolStripMenuItem.Text = "Заказы"; + // + // создатьToolStripMenuItem + // + создатьToolStripMenuItem.Name = "создатьToolStripMenuItem"; + создатьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; + создатьToolStripMenuItem.Size = new Size(196, 22); + создатьToolStripMenuItem.Text = "Создать"; + создатьToolStripMenuItem.Click += создатьToolStripMenuItem_Click; + // + // редактироватьToolStripMenuItem + // + редактироватьToolStripMenuItem.Name = "редактироватьToolStripMenuItem"; + редактироватьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U; + редактироватьToolStripMenuItem.Size = new Size(196, 22); + редактироватьToolStripMenuItem.Text = "Редактировать"; + редактироватьToolStripMenuItem.Click += редактироватьToolStripMenuItem_Click; + // + // удалитьToolStripMenuItem + // + удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem"; + удалитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D; + удалитьToolStripMenuItem.Size = new Size(196, 22); + удалитьToolStripMenuItem.Text = "Удалить"; + удалитьToolStripMenuItem.Click += удалитьToolStripMenuItem_Click; + // + // отчётыToolStripMenuItem + // + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документToolStripMenuItem, документСТаблицейToolStripMenuItem, документСДиаграммойToolStripMenuItem }); + отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + отчётыToolStripMenuItem.Size = new Size(60, 20); + отчётыToolStripMenuItem.Text = "Отчёты"; + // + // документToolStripMenuItem + // + документToolStripMenuItem.Name = "документToolStripMenuItem"; + документToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + документToolStripMenuItem.Size = new Size(309, 22); + документToolStripMenuItem.Text = "Документ с простой таблицей"; + документToolStripMenuItem.Click += GeneratePdfButton_Click; + // + // документСТаблицейToolStripMenuItem + // + документСТаблицейToolStripMenuItem.Name = "документСТаблицейToolStripMenuItem"; + документСТаблицейToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T; + документСТаблицейToolStripMenuItem.Size = new Size(309, 22); + документСТаблицейToolStripMenuItem.Text = "Отчет по всем заказам Excel"; + документСТаблицейToolStripMenuItem.Click += buttonCreateOrderReport_Click; + // + // документСДиаграммойToolStripMenuItem + // + документСДиаграммойToolStripMenuItem.Name = "документСДиаграммойToolStripMenuItem"; + документСДиаграммойToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C; + документСДиаграммойToolStripMenuItem.Size = new Size(309, 22); + документСДиаграммойToolStripMenuItem.Text = "Документ с линейной диаграммой"; + документСДиаграммойToolStripMenuItem.Click += CreateDocumentButton_Click; + // + // выбранныеТоварыToolStripMenuItem + // + выбранныеТоварыToolStripMenuItem.Name = "выбранныеТоварыToolStripMenuItem"; + выбранныеТоварыToolStripMenuItem.Size = new Size(125, 20); + выбранныеТоварыToolStripMenuItem.Text = "Города назначения"; + выбранныеТоварыToolStripMenuItem.Click += выбранныеТоварыToolStripMenuItem_Click; + // + // controlDataTable + // + controlDataTable.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + controlDataTable.AutoSize = true; + controlDataTable.Location = new Point(0, 24); + controlDataTable.Margin = new Padding(4, 3, 4, 3); + controlDataTable.Name = "controlDataTable"; + controlDataTable.SelectedRowIndex = -1; + controlDataTable.Size = new Size(853, 419); + controlDataTable.TabIndex = 1; + // + // FormOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(853, 442); + Controls.Add(controlDataTable); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Margin = new Padding(3, 2, 3, 2); + Name = "FormOrders"; + Text = "Заказы"; + Load += FormOrders_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem заказыToolStripMenuItem; + private ToolStripMenuItem создатьToolStripMenuItem; + private ToolStripMenuItem редактироватьToolStripMenuItem; + private ToolStripMenuItem удалитьToolStripMenuItem; + private ToolStripMenuItem отчётыToolStripMenuItem; + private ToolStripMenuItem документToolStripMenuItem; + private ToolStripMenuItem документСТаблицейToolStripMenuItem; + private ToolStripMenuItem выбранныеТоварыToolStripMenuItem; + private ToolStripMenuItem документСДиаграммойToolStripMenuItem; + private ControlsLibraryNet60.Data.ControlDataTableTable controlDataTable; + private FormLibrary.PDFTable pdfTable1; + private WinFormsLibraryVolkov.NonVisualComponents.ExcelTableComponent excelTableComponent1; + private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartLineWord componentDocumentWithChartLineWord1; + } +} \ No newline at end of file diff --git a/KopLab1/Lab3Form/FormOrders.cs b/KopLab1/Lab3Form/FormOrders.cs new file mode 100644 index 0000000..2f231c6 --- /dev/null +++ b/KopLab1/Lab3Form/FormOrders.cs @@ -0,0 +1,343 @@ +using InternetShopOrdersBusinessLogic.BusinessLogics; +using InternetShopOrdersContracts.BusinessLogicContracts; +using InternetShopOrdersContracts.ViewModels; +using InternetShopOrdersContracts.BindingModels; +using InternetShopOrdersContracts.SearchModels; +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; +using ControlsLibraryNet60.Models; +using Microsoft.EntityFrameworkCore.Diagnostics; +using WinFormsLibraryVolkov.NonVisualComponents; +using ComponentsLibraryNet60.Core; +using ComponentsLibraryNet60.DocumentWithTable; +using ComponentsLibraryNet60.Models; +using FormLibrary.HelperClasses; +using FormLibrary; +using ComponentsLibraryNet60.DocumentWithChart; +using Microsoft.Win32; + +namespace Lab3Form +{ + public partial class FormOrders : Form + { + private IOrderLogic _logic; + + public FormOrders(IOrderLogic logic) + { + InitializeComponent(); + _logic = logic; + controlDataTable.LoadColumns(new List + { + new DataTableColumnConfig { ColumnHeader = "Идентификатор", PropertyName = "Id", Visible = true, Width = 100 }, + new DataTableColumnConfig { ColumnHeader = "ФИО заказчика", PropertyName = "Fullname", Visible = true, Width = 200 }, + new DataTableColumnConfig { ColumnHeader = "Город назначения", PropertyName = "DestinationCityName", Visible = true, Width = 150 }, + new DataTableColumnConfig { ColumnHeader = "История передвижения", PropertyName = "OrderStatusHistory", Visible = true, Width = 250 }, + new DataTableColumnConfig { ColumnHeader = "Дата выдачи", PropertyName = "ExpectedDeliveryDate", Visible = true, Width = 125 }, + }); + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + } + + private void LoadData() + { + controlDataTable.Clear(); + var orders = _logic.ReadList(null); + if (orders != null) + { + var displayOrders = orders.Select(order => new + { + order.Id, + order.Fullname, + order.DestinationCityName, + OrderStatusHistory = string.Join(", ", order.OrderStatusHistory), + order.ExpectedDeliveryDate + }).ToList(); + controlDataTable.AddTable(displayOrders); + } + } + private void FormOrders_Load(object sender, EventArgs e) + { + LoadData(); + } + private void создатьToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormOrder)); + if (service is FormOrder form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormOrder)); + if (service is FormOrder form) + { + form._id = controlDataTable.GetSelectedObject().Id; + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) + { + var selectedOrder = controlDataTable.GetSelectedObject(); + if (selectedOrder == null) + { + MessageBox.Show("Не выбрана запись для удаления."); + return; + } + if (MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + var isDeleted = _logic.Delete(new OrderBindingModel { Id = selectedOrder.Id ?? 0 }); + if (isDeleted) + { + LoadData(); + MessageBox.Show("Запись успешно удалена."); + } + else + { + MessageBox.Show("Ошибка при удалении записи."); + } + } + } + + private void GeneratePdfButton_Click(object sender, EventArgs e) + { + try + { + + var orders = _logic.ReadList(null); + + + var orderTables = new List(); + + foreach (var order in orders) + { + + int rowCount = order.OrderStatusHistory.Count; + + + string[,] orderTable = new string[rowCount+1, 4]; + + + orderTable[0, 0] = "Статус"; + orderTable[0, 1] = "Идентификатор заказа"; + orderTable[0, 2] = "Город назначения"; + orderTable[0, 3] = "Дата доставки"; + + + for (int i = 0; i < rowCount; i++) + { + orderTable[i+1, 0] = order.OrderStatusHistory[i]; + orderTable[i+1, 1] = order.Id.ToString(); + orderTable[i+1, 2] = order.DestinationCityName; + orderTable[i+1, 3] = order.ExpectedDeliveryDate.ToString("yyyy-MM-dd"); + } + + + orderTables.Add(orderTable); + } + + + using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()) + { + saveFileDialog.Filter = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*"; + saveFileDialog.Title = "Сохранить PDF-документ"; + saveFileDialog.FileName = "Отчет1.pdf"; + + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + + var pdfData = new PdfDocumentData( + saveFileDialog.FileName, + "Отчет по заказам", + orderTables + ); + + var documentGenerator = new PDFTable(); + documentGenerator.GeneratePdf(pdfData); + + MessageBox.Show("PDF-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show($"Произошла ошибка: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCreateOrderReport_Click(object sender, EventArgs e) + { + + var orders = _logic.ReadList(null); + if (orders == null || orders.Count == 0) + { + MessageBox.Show("Нет заказов для отчета.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + + var tableData = new List(); + foreach (var order in orders) + { + if (order != null) + { + tableData.Add(new OrderExcelViewModel( + order.Id, + order.Fullname, + order.DestinationCityName, + order.ExpectedDeliveryDate + )); + } + } + string path = AppDomain.CurrentDomain.BaseDirectory + "OrderReport.xlsx"; + + using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()) + { + saveFileDialog.Title = "Сохранить Excel-документ"; + saveFileDialog.FileName = "Отчет2.xlsx"; + + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + path = saveFileDialog.FileName; + + MessageBox.Show("Excel-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + + List<(int, int)> merges = new List<(int, int)> + { + (0,1), + (2, 3) + }; + + List heights = Enumerable.Repeat(20, 4).ToList(); + + + List<(string, string)> headers = new List<(string, string)> + { + + ("","Данные"), + ("Id", "Идентификатор"), + ("Fullname", "ФИО заказчика"), + ("", "Заказ"), + ("DestinationCityName", "Город назначения"), + ("ExpectedDeliveryDate", "Дата получения заказа") + }; + + if (merges.Count == 0 || heights.Count == 0 || headers.Count == 0 || tableData.Count == 0) + { + MessageBox.Show("Недостаточно данных для создания отчета.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + Console.WriteLine($"Merges Count: {merges.Count}"); + Console.WriteLine($"Heights Count: {heights.Count}"); + Console.WriteLine($"Headers Count: {headers.Count}"); + Console.WriteLine($"TableData Count: {tableData.Count}"); + if (excelTableComponent1.createWithTable(path, "Отчет по заказам", merges, heights, headers, tableData)) + { + MessageBox.Show("Отчет успешно создан!"); + } + else + { + MessageBox.Show("Ошибка при создании отчета.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + private void CreateDocumentButton_Click(object sender, EventArgs e) + { + + var orders = _logic.ReadList(null).Cast().ToList(); + + + var chartData = new Dictionary>(); + + foreach (var order in orders) + { + if (!chartData.ContainsKey(order.DestinationCityName)) + { + chartData[order.DestinationCityName] = new List<(DateTime Date, int Count)>(); + } + + + var existingData = chartData[order.DestinationCityName] + .FirstOrDefault(d => d.Date.Date == order.ExpectedDeliveryDate.Date); + + if (existingData.Date == default) + { + chartData[order.DestinationCityName].Add((order.ExpectedDeliveryDate.Date, 1)); + } + else + { + + int index = chartData[order.DestinationCityName].FindIndex(d => d.Date.Date == order.ExpectedDeliveryDate.Date); + var updatedValue = chartData[order.DestinationCityName][index]; + chartData[order.DestinationCityName][index] = (updatedValue.Date, updatedValue.Count + 1); + } + } + + string filePath = "Отчет3.docx"; + + using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()) + { + saveFileDialog.Title = "Сохранить Word-документ"; + saveFileDialog.FileName = "Отчет3.docx"; + + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + filePath = saveFileDialog.FileName; + + MessageBox.Show("Docx-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + var config = new ComponentDocumentWithChartConfig + { + ChartTitle = "Отчет по заказам", + LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom, + Data = chartData.ToDictionary( + entry => entry.Key, + entry => entry.Value.Select(d => (DateTimeToInt(d.Date), (double)d.Count)).ToList()), + FilePath = filePath, + Header = "Заголовок отчета" + + }; + + + var documentComponent = new ComponentDocumentWithChartLineWord(); + + + documentComponent.CreateDoc(config); + + MessageBox.Show("Документ создан успешно!"); + } + private int DateTimeToInt(DateTime date) + { + return date.Day; + } + + + private void выбранныеТоварыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCities)); + if (service is FormCities form) + { + form.ShowDialog(); + } + } + } +} diff --git a/KopLab1/Lab3Form/FormOrders.resx b/KopLab1/Lab3Form/FormOrders.resx new file mode 100644 index 0000000..6f2a6fb --- /dev/null +++ b/KopLab1/Lab3Form/FormOrders.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + + 126, 17 + + + 231, 17 + + + 409, 17 + + + 177 + + \ No newline at end of file diff --git a/KopLab1/Lab3Form/Lab3Form.csproj b/KopLab1/Lab3Form/Lab3Form.csproj index 45d1f18..3bc16c1 100644 --- a/KopLab1/Lab3Form/Lab3Form.csproj +++ b/KopLab1/Lab3Form/Lab3Form.csproj @@ -25,6 +25,7 @@ + \ No newline at end of file diff --git a/KopLab1/Lab3Form/PluginsManager.cs b/KopLab1/Lab3Form/PluginsManager.cs new file mode 100644 index 0000000..cec9f83 --- /dev/null +++ b/KopLab1/Lab3Form/PluginsManager.cs @@ -0,0 +1,47 @@ +using PluginsConventionLibrary.Plugins; +using System; +using System.Collections.Generic; +using System.ComponentModel.Composition.Hosting; +using System.ComponentModel.Composition; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lab3Form +{ + public class PluginsManager + { + [ImportMany(typeof(IPluginsConvention))] + IEnumerable Plugins { get; set; } + + public readonly Dictionary plugins_dictionary = new(); + + public PluginsManager() + { + AggregateCatalog catalog = new AggregateCatalog(); + catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory)); + catalog.Catalogs.Add(new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"))); + + //Контейнер композиции + CompositionContainer container = new CompositionContainer(catalog); + try + { + container.ComposeParts(this); + } + catch (CompositionException compositionException) + { + MessageBox.Show(compositionException.ToString()); + } + if (Plugins.Any()) + { + Plugins + .ToList() + .ForEach(p => + { + if (!plugins_dictionary.Keys.Contains(p.PluginName)) + plugins_dictionary.Add(p.PluginName, p); + }); + } + } + } +} diff --git a/KopLab1/PluginsConventionLibrary/Plugins/IPluginsConvention.cs b/KopLab1/PluginsConventionLibrary/Plugins/IPluginsConvention.cs new file mode 100644 index 0000000..4809182 --- /dev/null +++ b/KopLab1/PluginsConventionLibrary/Plugins/IPluginsConvention.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PluginsConventionLibrary.Plugins +{ + public interface IPluginsConvention + { + /// + /// Название плагина + /// + string PluginName { get; } + + /// + /// Получение контрола для вывода набора данных + /// + UserControl GetControl { get; } + + /// + /// Получение элемента, выбранного в контроле + /// + PluginsConventionElement GetElement { get; } + + /// + /// Получение формы для создания/редактирования объекта + /// + /// + /// + Form GetForm(PluginsConventionElement element); + + /// + /// Удаление элемента + /// + /// + /// + bool DeleteElement(PluginsConventionElement element); + + /// + /// Обновление набора данных в контроле + /// + void ReloadData(); + + /// + /// Создание простого документа + /// + /// + /// + bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument); + + /// + /// Создание простого документа + /// + /// + /// + bool CreateTableDocument(PluginsConventionSaveDocument saveDocument); + + /// + /// Создание документа с диаграммой + /// + /// + /// + bool CreateChartDocument(PluginsConventionSaveDocument saveDocument); + } +} + diff --git a/KopLab1/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs b/KopLab1/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs new file mode 100644 index 0000000..99f7ef9 --- /dev/null +++ b/KopLab1/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary.Plugins +{ + public class PluginsConventionElement + { + public int Id { get; set; } + } +} diff --git a/KopLab1/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs b/KopLab1/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs new file mode 100644 index 0000000..a0a7ce1 --- /dev/null +++ b/KopLab1/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary.Plugins +{ + public class PluginsConventionSaveDocument + { + public string FileName { get; set; } + } +} diff --git a/KopLab1/PluginsConventionLibrary/PluginsConventionLibrary.csproj b/KopLab1/PluginsConventionLibrary/PluginsConventionLibrary.csproj new file mode 100644 index 0000000..7414864 --- /dev/null +++ b/KopLab1/PluginsConventionLibrary/PluginsConventionLibrary.csproj @@ -0,0 +1,24 @@ + + + + net8.0-windows7.0 + enable + enable + + + + + + + + + + + + + + + + + +