From 7ac053add759e33cb074d02b43ba0fa6c8a25258 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Mon, 25 Nov 2024 19:32:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A7=D1=82=D0=BE-=D1=82=D0=BE=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=D0=BB=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ExecForm/ExecForm1.csproj | 15 - ExecForm/Form1.Designer.cs | 80 ----- ExecForm/Form1.cs | 39 --- ExecForm/Form1.resx | 120 ------- ExecForm/Program.cs | 17 - ExexForm2/ExexForm2.csproj | 15 - ExexForm2/Form1.Designer.cs | 152 --------- ExexForm2/Form1.cs | 169 ---------- ExexForm2/Form1.resx | 129 -------- ExexForm2/Program.cs | 17 - Laba3/FormMain.Designer.cs | 173 ++++++++++ Laba3/FormMain.cs | 256 +++++++++++++++ Laba3/{ProductForm.resx => FormMain.resx} | 50 +-- Laba3/MainForm.Designer.cs | 178 ---------- Laba3/MainForm.cs | 284 ---------------- Laba3/MainForm.resx | 141 -------- Laba3/MainPluginConvention.cs | 304 ++++++++++++++++++ Laba3/ManufacturerForm.Designer.cs | 64 ---- Laba3/ManufacturerForm.cs | 95 ------ Laba3/ManufacturerForm.resx | 120 ------- Laba3/PluginsManager.cs | 50 +++ Laba3/ProductForm.Designer.cs | 121 ------- Laba3/ProductForm.cs | 116 ------- Laba3/Program.cs | 8 +- Laba3/View.csproj | 4 +- Library14Petrushin/Library14Petrushin.sln | 2 +- Plugins/PluginsConvention14.dll | Bin 0 -> 20480 bytes .../Forms/MainForm.Designer.cs | 178 ---------- PluginsConvention14/Forms/MainForm.cs | 284 ---------------- PluginsConvention14/Forms/MainForm.resx | 141 -------- .../Forms/ManufacturerForm.Designer.cs | 2 +- PluginsConvention14/Forms/ManufacturerForm.cs | 11 +- PluginsConvention14/Forms/ProductForm.cs | 15 +- .../MyPlugin/MainPluginConvention.cs | 120 +++---- .../MyPlugin/MainPluginsConventionElement.cs | 12 +- .../Plugins/IPluginsConvention.cs | 8 +- .../Plugins/PluginsConventionElement.cs | 8 +- .../Plugins/PluginsConventionSaveDocument.cs | 8 +- .../PluginsConvention14.csproj | 5 +- .../Forms/MainForm.Designer.cs | 178 ---------- PluginsConventionLibrary/Forms/MainForm.cs | 284 ---------------- PluginsConventionLibrary/Forms/MainForm.resx | 141 -------- .../Forms/ManufacturerForm.Designer.cs | 64 ---- .../Forms/ManufacturerForm.cs | 95 ------ .../Forms/ManufacturerForm.resx | 120 ------- .../Forms/ProductForm.Designer.cs | 121 ------- PluginsConventionLibrary/Forms/ProductForm.cs | 116 ------- .../Forms/ProductForm.resx | 120 ------- .../Plugins/IPluginsConvention.cs | 66 ---- .../Plugins/PluginsConventionElement.cs | 13 - .../Plugins/PluginsConventionSaveDocument.cs | 13 - .../PluginsConventionLibrary.csproj | 30 -- 52 files changed, 890 insertions(+), 3982 deletions(-) delete mode 100644 ExecForm/ExecForm1.csproj delete mode 100644 ExecForm/Form1.Designer.cs delete mode 100644 ExecForm/Form1.cs delete mode 100644 ExecForm/Form1.resx delete mode 100644 ExecForm/Program.cs delete mode 100644 ExexForm2/ExexForm2.csproj delete mode 100644 ExexForm2/Form1.Designer.cs delete mode 100644 ExexForm2/Form1.cs delete mode 100644 ExexForm2/Form1.resx delete mode 100644 ExexForm2/Program.cs create mode 100644 Laba3/FormMain.Designer.cs create mode 100644 Laba3/FormMain.cs rename Laba3/{ProductForm.resx => FormMain.resx} (93%) delete mode 100644 Laba3/MainForm.Designer.cs delete mode 100644 Laba3/MainForm.cs delete mode 100644 Laba3/MainForm.resx create mode 100644 Laba3/MainPluginConvention.cs delete mode 100644 Laba3/ManufacturerForm.Designer.cs delete mode 100644 Laba3/ManufacturerForm.cs delete mode 100644 Laba3/ManufacturerForm.resx create mode 100644 Laba3/PluginsManager.cs delete mode 100644 Laba3/ProductForm.Designer.cs delete mode 100644 Laba3/ProductForm.cs create mode 100644 Plugins/PluginsConvention14.dll delete mode 100644 PluginsConvention14/Forms/MainForm.Designer.cs delete mode 100644 PluginsConvention14/Forms/MainForm.cs delete mode 100644 PluginsConvention14/Forms/MainForm.resx delete mode 100644 PluginsConventionLibrary/Forms/MainForm.Designer.cs delete mode 100644 PluginsConventionLibrary/Forms/MainForm.cs delete mode 100644 PluginsConventionLibrary/Forms/MainForm.resx delete mode 100644 PluginsConventionLibrary/Forms/ManufacturerForm.Designer.cs delete mode 100644 PluginsConventionLibrary/Forms/ManufacturerForm.cs delete mode 100644 PluginsConventionLibrary/Forms/ManufacturerForm.resx delete mode 100644 PluginsConventionLibrary/Forms/ProductForm.Designer.cs delete mode 100644 PluginsConventionLibrary/Forms/ProductForm.cs delete mode 100644 PluginsConventionLibrary/Forms/ProductForm.resx delete mode 100644 PluginsConventionLibrary/Plugins/IPluginsConvention.cs delete mode 100644 PluginsConventionLibrary/Plugins/PluginsConventionElement.cs delete mode 100644 PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs delete mode 100644 PluginsConventionLibrary/PluginsConventionLibrary.csproj diff --git a/ExecForm/ExecForm1.csproj b/ExecForm/ExecForm1.csproj deleted file mode 100644 index b3e737e..0000000 --- a/ExecForm/ExecForm1.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - WinExe - net8.0-windows - enable - true - enable - - - - - - - \ No newline at end of file diff --git a/ExecForm/Form1.Designer.cs b/ExecForm/Form1.Designer.cs deleted file mode 100644 index ce66285..0000000 --- a/ExecForm/Form1.Designer.cs +++ /dev/null @@ -1,80 +0,0 @@ -namespace ExecForm -{ - partial class Form1 - { - /// - /// 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() - { - chooseList1 = new Library14Petrushin.ChooseList(); - hierarchicalTreeView1 = new Library14Petrushin.HierarchicalTreeView(); - textBoxRange1 = new Library14Petrushin.TextBoxRange(); - SuspendLayout(); - // - // chooseList1 - // - chooseList1.Location = new Point(12, 12); - chooseList1.Name = "chooseList1"; - chooseList1.SelectedValue = ""; - chooseList1.Size = new Size(185, 190); - chooseList1.TabIndex = 0; - // - // hierarchicalTreeView1 - // - hierarchicalTreeView1.Location = new Point(567, 2); - hierarchicalTreeView1.Name = "hierarchicalTreeView1"; - hierarchicalTreeView1.SelectedNodeIndex = -1; - hierarchicalTreeView1.Size = new Size(266, 504); - hierarchicalTreeView1.TabIndex = 2; - // - // textBoxRange1 - // - textBoxRange1.Location = new Point(254, 21); - textBoxRange1.MaxLength = null; - textBoxRange1.MinLength = null; - textBoxRange1.Name = "textBoxRange1"; - textBoxRange1.Size = new Size(259, 118); - textBoxRange1.TabIndex = 3; - // - // Form1 - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(834, 507); - Controls.Add(textBoxRange1); - Controls.Add(hierarchicalTreeView1); - Controls.Add(chooseList1); - Name = "Form1"; - Text = "Form1"; - ResumeLayout(false); - } - - #endregion - - private Library14Petrushin.ChooseList chooseList1; - private Library14Petrushin.HierarchicalTreeView hierarchicalTreeView1; - private Library14Petrushin.TextBoxRange textBoxRange1; - } -} diff --git a/ExecForm/Form1.cs b/ExecForm/Form1.cs deleted file mode 100644 index 61e1daa..0000000 --- a/ExecForm/Form1.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Library14Petrushin.Classes; -using Library14Petrushin; - -namespace ExecForm -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - - - // - chooseList1.AddItemToList("Item 1"); - chooseList1.AddItemToList("Item 2"); - chooseList1.AddItemToList("Item 3"); - - textBoxRange1.MinLength = 3; - textBoxRange1.MaxLength = 10; - - var hierarchy = new List { "Department", "Position", "FullName" }; - var alwaysNewBranch = new Dictionary { { "FullName", true } }; - hierarchicalTreeView1.SetHierarchy(hierarchy, alwaysNewBranch); - - var employees = new List - { - new Employee { Department = "IT", Position = "Developer", FullName = "John Doe" }, - new Employee { Department = "HR", Position = "Manager", FullName = "Jane Smith" } - }; - - // AddObjectToTree - foreach (var employee in employees) - { - hierarchicalTreeView1.AddObjectToTree(employee, hierarchy.Last()); - } - - } - } -} diff --git a/ExecForm/Form1.resx b/ExecForm/Form1.resx deleted file mode 100644 index af32865..0000000 --- a/ExecForm/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/ExecForm/Program.cs b/ExecForm/Program.cs deleted file mode 100644 index af90307..0000000 --- a/ExecForm/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace ExecForm -{ - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); - } - } -} \ No newline at end of file diff --git a/ExexForm2/ExexForm2.csproj b/ExexForm2/ExexForm2.csproj deleted file mode 100644 index b3e737e..0000000 --- a/ExexForm2/ExexForm2.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - WinExe - net8.0-windows - enable - true - enable - - - - - - - \ No newline at end of file diff --git a/ExexForm2/Form1.Designer.cs b/ExexForm2/Form1.Designer.cs deleted file mode 100644 index 6947beb..0000000 --- a/ExexForm2/Form1.Designer.cs +++ /dev/null @@ -1,152 +0,0 @@ -namespace ExexForm2 -{ - partial class Form1 - { - /// - /// 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(); - pdfImg1 = new Library14Petrushin.PdfImg(components); - btnSelectImages = new Button(); - btnSelectDirectory = new Button(); - btnCreatePdf = new Button(); - txtDocumentTitle = new TextBox(); - lstImages = new ListBox(); - lblDirectory = new Label(); - btnCrTb = new Button(); - pdfColGroupTable1 = new Library14Petrushin.PdfColGroupTable(); - pdfCirclDiagr1 = new Library14Petrushin.PdfCirclDiagr(); - btnCircl = new Button(); - SuspendLayout(); - // - // btnSelectImages - // - btnSelectImages.Location = new Point(24, 28); - btnSelectImages.Name = "btnSelectImages"; - btnSelectImages.Size = new Size(116, 50); - btnSelectImages.TabIndex = 0; - btnSelectImages.Text = "выбор изображения"; - btnSelectImages.UseVisualStyleBackColor = true; - btnSelectImages.Click += btnSelectImages_Click; - // - // btnSelectDirectory - // - btnSelectDirectory.Location = new Point(24, 89); - btnSelectDirectory.Name = "btnSelectDirectory"; - btnSelectDirectory.Size = new Size(116, 49); - btnSelectDirectory.TabIndex = 1; - btnSelectDirectory.Text = "выбор директории"; - btnSelectDirectory.UseVisualStyleBackColor = true; - btnSelectDirectory.Click += btnSelectDirectory_Click; - // - // btnCreatePdf - // - btnCreatePdf.Location = new Point(24, 158); - btnCreatePdf.Name = "btnCreatePdf"; - btnCreatePdf.Size = new Size(101, 48); - btnCreatePdf.TabIndex = 2; - btnCreatePdf.Text = "Создать"; - btnCreatePdf.UseVisualStyleBackColor = true; - btnCreatePdf.Click += btnCreatePdf_Click; - // - // txtDocumentTitle - // - txtDocumentTitle.Location = new Point(24, 224); - txtDocumentTitle.Name = "txtDocumentTitle"; - txtDocumentTitle.Size = new Size(101, 27); - txtDocumentTitle.TabIndex = 3; - // - // lstImages - // - lstImages.FormattingEnabled = true; - lstImages.Location = new Point(146, 28); - lstImages.Name = "lstImages"; - lstImages.Size = new Size(179, 404); - lstImages.TabIndex = 4; - // - // lblDirectory - // - lblDirectory.AutoSize = true; - lblDirectory.Location = new Point(24, 280); - lblDirectory.Name = "lblDirectory"; - lblDirectory.Size = new Size(50, 20); - lblDirectory.TabIndex = 5; - lblDirectory.Text = "label1"; - // - // btnCrTb - // - btnCrTb.Location = new Point(349, 28); - btnCrTb.Name = "btnCrTb"; - btnCrTb.Size = new Size(142, 29); - btnCrTb.TabIndex = 6; - btnCrTb.Text = "Создать таблицу"; - btnCrTb.UseVisualStyleBackColor = true; - btnCrTb.Click += btnCreatePdfTable_Click; - // - // btnCircl - // - btnCircl.Location = new Point(606, 28); - btnCircl.Name = "btnCircl"; - btnCircl.Size = new Size(161, 29); - btnCircl.TabIndex = 7; - btnCircl.Text = "Создать диаграмму"; - btnCircl.UseVisualStyleBackColor = true; - btnCircl.Click += btnCreatePdfCircl_Click; - // - // Form1 - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(btnCircl); - Controls.Add(btnCrTb); - Controls.Add(lblDirectory); - Controls.Add(lstImages); - Controls.Add(txtDocumentTitle); - Controls.Add(btnCreatePdf); - Controls.Add(btnSelectDirectory); - Controls.Add(btnSelectImages); - Name = "Form1"; - Text = "Form1"; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Library14Petrushin.PdfImg pdfImg1; - private Button btnSelectImages; - private Button btnSelectDirectory; - private Button btnCreatePdf; - private TextBox txtDocumentTitle; - private ListBox lstImages; - private Label lblDirectory; - private Button btnCrTb; - private Library14Petrushin.PdfColGroupTable pdfColGroupTable1; - private Library14Petrushin.PdfCirclDiagr pdfCirclDiagr1; - private Button btnCircl; - } -} diff --git a/ExexForm2/Form1.cs b/ExexForm2/Form1.cs deleted file mode 100644 index 82861c0..0000000 --- a/ExexForm2/Form1.cs +++ /dev/null @@ -1,169 +0,0 @@ -using Library14Petrushin; -using Library14Petrushin.Classes; - -namespace ExexForm2 -{ - public partial class Form1 : Form - { - private PdfImg pdfImg; - private List selectedImages; - private string selectedDirectory; - private PdfColGroupTable pdfTable; - private PdfCirclDiagr pdfCirclDiagr; - - public Form1() - { - InitializeComponent(); - pdfImg = new PdfImg(); - selectedImages = new List(); - pdfTable = new PdfColGroupTable(); - pdfCirclDiagr = new PdfCirclDiagr(); - } - - private void btnSelectImages_Click(object sender, EventArgs e) - { - using (OpenFileDialog openFileDialog = new OpenFileDialog()) - { - openFileDialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp;*.gif"; - openFileDialog.Multiselect = true; - - if (openFileDialog.ShowDialog() == DialogResult.OK) - { - foreach (string fileName in openFileDialog.FileNames) - { - selectedImages.Add(new ImageData { ImagePath = fileName }); - lstImages.Items.Add(fileName); - } - } - } - } - - private void btnSelectDirectory_Click(object sender, EventArgs e) - { - using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) - { - if (folderBrowserDialog.ShowDialog() == DialogResult.OK) - { - selectedDirectory = folderBrowserDialog.SelectedPath; - lblDirectory.Text = "Selected Directory: " + selectedDirectory; - } - } - } - - private void btnCreatePdf_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(txtDocumentTitle.Text) || selectedImages.Count == 0 || string.IsNullOrEmpty(selectedDirectory)) - { - MessageBox.Show("Please select images, directory, and enter a document title."); - return; - } - - string fileName = Path.Combine(selectedDirectory, "output1.pdf"); - pdfImg.CreatePdfDocument(fileName, txtDocumentTitle.Text, selectedImages); - MessageBox.Show("PDF document created successfully!"); - } - - - // 2 ------------------------------------------- - - - private void btnCreatePdfTable_Click(object sender, EventArgs e) - { - string selectDirTable = ""; - string fileName = ""; - - using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) - { - if (folderBrowserDialog.ShowDialog() == DialogResult.OK) - { - selectDirTable = folderBrowserDialog.SelectedPath; - } - } - - using (SaveFileDialog saveFileDialog = new SaveFileDialog()) - { - saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf"; - saveFileDialog.DefaultExt = "pdf"; - saveFileDialog.InitialDirectory = selectDirTable; - saveFileDialog.FileName = "output2.pdf"; - - if (saveFileDialog.ShowDialog() == DialogResult.OK) - { - fileName = saveFileDialog.FileName; - } - } - - if (!string.IsNullOrEmpty(fileName)) - { - var generator = new PdfColGroupTable(); - - var data1 = new List - { - new Person { FirstName = "John", LastName = "Doe", Age = 30 }, - new Person { FirstName = "Jane", LastName = "Smith", Age = 25 } - }; - - var commonHeaders = new List { "Name", "", "" }; - var headersNames = new List<(string, string)> { - ("First Name","FirstName"), - ("Last Name", "LastName"), - ("Age", "Age") - }; - var rowHeights = new List { 20, 20 }; - var mergeCells = new List<(int startRow, int endRow, int startColumn, int endColumn)> - { - (0, 1, 0, 0), // 0 1 - (2, 2, 0, 1) - }; - - generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headersNames, commonHeaders, data1); - } - } - - - // 3 ------------------------------------------- - - - private void btnCreatePdfCircl_Click(object sender, EventArgs e) - { - string selectDir = ""; - string fileName = ""; - - using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) - { - if (folderBrowserDialog.ShowDialog() == DialogResult.OK) - { - selectDir = folderBrowserDialog.SelectedPath; - } - } - - using (SaveFileDialog saveFileDialog = new SaveFileDialog()) - { - saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf"; - saveFileDialog.DefaultExt = "pdf"; - saveFileDialog.InitialDirectory = selectDir; - saveFileDialog.FileName = "output3.pdf"; - - if (saveFileDialog.ShowDialog() == DialogResult.OK) - { - fileName = saveFileDialog.FileName; - } - } - - if (!string.IsNullOrEmpty(fileName)) - { - var pdfCirclDiagr = new PdfCirclDiagr(); - - List chartData = new List - { - new ChartData { SeriesName = "Series 1", Value = 10 }, - new ChartData { SeriesName = "Series 2", Value = 20 }, - new ChartData { SeriesName = "Series 3", Value = 30 }, - new ChartData { SeriesName = "Series 4", Value = 40 } - }; - - pdfCirclDiagr.GeneratePdf(fileName, "Document Title", "Chart Title", LegendPosition.Right, chartData); - } - } - } -} \ No newline at end of file diff --git a/ExexForm2/Form1.resx b/ExexForm2/Form1.resx deleted file mode 100644 index 4e594b6..0000000 --- a/ExexForm2/Form1.resx +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - 130, 17 - - - 315, 17 - - \ No newline at end of file diff --git a/ExexForm2/Program.cs b/ExexForm2/Program.cs deleted file mode 100644 index 9dac8de..0000000 --- a/ExexForm2/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace ExexForm2 -{ - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); - } - } -} \ No newline at end of file diff --git a/Laba3/FormMain.Designer.cs b/Laba3/FormMain.Designer.cs new file mode 100644 index 0000000..495830c --- /dev/null +++ b/Laba3/FormMain.Designer.cs @@ -0,0 +1,173 @@ +using DocumentFormat.OpenXml.Office2010.CustomUI; +using Microsoft.Vbe.Interop; +using System.Windows.Forms; + +namespace View +{ + partial class FormMain + { + /// + /// 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() + { + panelControl = new Panel(); + ControlsStripMenuItem = new ToolStripMenuItem(); + ActionsToolStripMenuItem = new ToolStripMenuItem(); + AddElementToolStripMenuItem = new ToolStripMenuItem(); + UpdElementToolStripMenuItem = new ToolStripMenuItem(); + DelElementToolStripMenuItem = new ToolStripMenuItem(); + DocsToolStripMenuItem = new ToolStripMenuItem(); + WordDocToolStripMenuItem = new ToolStripMenuItem(); + TableDocToolStripMenuItem = new ToolStripMenuItem(); + ChartDocToolStripMenuItem = new ToolStripMenuItem(); + menuStrip = new MenuStrip(); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // panelControl + // + panelControl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + panelControl.BackColor = SystemColors.Info; + panelControl.Location = new Point(14, 36); + panelControl.Margin = new Padding(3, 4, 3, 4); + panelControl.Name = "panelControl"; + panelControl.Size = new Size(1024, 236); + panelControl.TabIndex = 2; + // + // ControlsStripMenuItem + // + ControlsStripMenuItem.Name = "ControlsStripMenuItem"; + ControlsStripMenuItem.Size = new Size(113, 26); + ControlsStripMenuItem.Text = "Компоненты"; + // + // ActionsToolStripMenuItem + // + ActionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AddElementToolStripMenuItem, UpdElementToolStripMenuItem, DelElementToolStripMenuItem }); + ActionsToolStripMenuItem.Name = "ActionsToolStripMenuItem"; + ActionsToolStripMenuItem.Size = new Size(88, 26); + ActionsToolStripMenuItem.Text = "Действия"; + // + // AddElementToolStripMenuItem + // + AddElementToolStripMenuItem.Name = "AddElementToolStripMenuItem"; + AddElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; + AddElementToolStripMenuItem.Size = new Size(213, 26); + AddElementToolStripMenuItem.Text = "Добавить"; + AddElementToolStripMenuItem.Click += AddElementToolStripMenuItem_Click; + // + // UpdElementToolStripMenuItem + // + UpdElementToolStripMenuItem.Name = "UpdElementToolStripMenuItem"; + UpdElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U; + UpdElementToolStripMenuItem.Size = new Size(213, 26); + UpdElementToolStripMenuItem.Text = "Изменить"; + UpdElementToolStripMenuItem.Click += UpdElementToolStripMenuItem_Click; + // + // DelElementToolStripMenuItem + // + DelElementToolStripMenuItem.Name = "DelElementToolStripMenuItem"; + DelElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D; + DelElementToolStripMenuItem.Size = new Size(213, 26); + DelElementToolStripMenuItem.Text = "Удалить"; + DelElementToolStripMenuItem.Click += DelElementToolStripMenuItem_Click; + // + // DocsToolStripMenuItem + // + DocsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { WordDocToolStripMenuItem, TableDocToolStripMenuItem, ChartDocToolStripMenuItem }); + DocsToolStripMenuItem.Name = "DocsToolStripMenuItem"; + DocsToolStripMenuItem.Size = new Size(101, 26); + DocsToolStripMenuItem.Text = "Документы"; + // + // WordDocToolStripMenuItem + // + WordDocToolStripMenuItem.Name = "WordDocToolStripMenuItem"; + WordDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + WordDocToolStripMenuItem.Size = new Size(291, 26); + WordDocToolStripMenuItem.Text = "Диаграмма ворд"; + WordDocToolStripMenuItem.Click += WordDocToolStripMenuItem_Click; + // + // TableDocToolStripMenuItem + // + TableDocToolStripMenuItem.Name = "TableDocToolStripMenuItem"; + TableDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T; + TableDocToolStripMenuItem.Size = new Size(291, 26); + TableDocToolStripMenuItem.Text = "Документ с таблицой"; + TableDocToolStripMenuItem.Click += TableDocToolStripMenuItem_Click; + // + // ChartDocToolStripMenuItem + // + ChartDocToolStripMenuItem.Name = "ChartDocToolStripMenuItem"; + ChartDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C; + ChartDocToolStripMenuItem.Size = new Size(291, 26); + ChartDocToolStripMenuItem.Text = "Текст пдф"; + ChartDocToolStripMenuItem.Click += ChartDocToolStripMenuItem_Click; + // + // menuStrip + // + menuStrip.AutoSize = false; + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { ControlsStripMenuItem, ActionsToolStripMenuItem, DocsToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Padding = new Padding(7, 3, 0, 3); + menuStrip.Size = new Size(1051, 32); + menuStrip.TabIndex = 0; + menuStrip.Text = "Меню"; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1051, 288); + Controls.Add(panelControl); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Margin = new Padding(3, 4, 3, 4); + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Главная форма"; + KeyDown += FormMain_KeyDown; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + 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 WordDocToolStripMenuItem; + private ToolStripMenuItem TableDocToolStripMenuItem; + private ToolStripMenuItem ChartDocToolStripMenuItem; + private MenuStrip menuStrip; + private Library14Petrushin.PdfImg pdfImg; + private Library15Gerimovich.WordDiagramComponent wordDiagramComponent; + private WinFormsLibrary1.ComponentTable componentTable; + } +} \ No newline at end of file diff --git a/Laba3/FormMain.cs b/Laba3/FormMain.cs new file mode 100644 index 0000000..de3b99c --- /dev/null +++ b/Laba3/FormMain.cs @@ -0,0 +1,256 @@ +using Data.Models; +using Library14Petrushin; +using Library15Gerimovich.OfficePackage.HelperModels; +using Library15Gerimovich; +using WinFormsLibrary1; +using WinFormsLibrary1.Models; +using View.ViewModels; +using PluginsConventionLibrary.Plugins; +using System.Reflection; + +namespace View +{ + public partial class FormMain : Form + { + private readonly Dictionary _plugins; + private string _selectedPlugin; + private ContextMenuStrip contextMenu = new ContextMenuStrip(); + + public FormMain() + { + InitializeComponent(); + + _plugins = LoadPlugins(); + _selectedPlugin = string.Empty; + } + + /*private Dictionary LoadPlugins() + { + PluginsManager manager = new PluginsManager(); + var plugins = manager.plugins_dictionary; + + ToolStripItem[] toolStripItems = new ToolStripItem[plugins.Count]; + int i = 0; + if (plugins.Count > 0) + { + foreach (var plugin in plugins) + { + ToolStripMenuItem itemMenu = new ToolStripMenuItem(); + itemMenu.Text = plugin.Value.PluginName; + itemMenu.Click += (sender, e) => + { + _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); + } + return plugins; + }*/ + + private Dictionary LoadPlugins() + { + var plugins = new Dictionary(); + + string pluginsDir = Directory.GetParent(Directory.GetCurrentDirectory())!.Parent!.Parent!.Parent!.FullName + "\\Plugins"; + + string[] dllFiles = Directory.GetFiles(pluginsDir, "*.dll", SearchOption.AllDirectories); + + foreach (string dllFile in dllFiles) + { + try + { + + Assembly assembly = Assembly.LoadFrom(dllFile); + Type[] types = assembly.GetTypes(); + + foreach (var type in types) + { + + if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface) + { + var plugin = (IPluginsConvention)Activator.CreateInstance(type)!; + plugins.Add(plugin.PluginName, plugin); + CreateMenuItem(plugin.PluginName); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"Ошибка при загрузке сборки {dllFile}: {ex.Message}"); + } + } + + return plugins; + } + + private void CreateMenuItem(string pluginName) + { + ToolStripMenuItem menuItem = new(pluginName); + menuItem.Click += (object? sender, EventArgs e) => + { + UserControl userControl = _plugins[pluginName].GetControl; + if (userControl != null) + { + panelControl.Controls.Clear(); + userControl.Dock = DockStyle.Fill; + _plugins[pluginName].ReloadData(); + _selectedPlugin = pluginName; + panelControl.Controls.Add(userControl); + } + }; + ControlsStripMenuItem.DropDownItems.Add(menuItem); + } + + private void FormMain_KeyDown(object sender, KeyEventArgs e) + { + if (!e.Control) + { + return; + } + + switch (e.KeyCode) + { + 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 AddNewElement() + { + var form = _plugins[_selectedPlugin].GetForm(null); + if (form != null && form.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + + private void UpdateElement() + { + 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() + { + using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" }) + { + if (_plugins[_selectedPlugin].CreateWord(new PluginsConventionSaveDocument { FileName = dialog.FileName })) + { + //MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + + private void CreateExcel() + { + using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) + { + if (_plugins[_selectedPlugin].CreateExcel(new PluginsConventionSaveDocument { FileName = dialog.FileName })) + { + //MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void CreatePdf() + { + using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }) + { + if (_plugins[_selectedPlugin].CreatePdf(new PluginsConventionSaveDocument { FileName = dialog.FileName })) + { + //MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + 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) + { + CreateWord(); + } + + private void TableDocToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateExcel(); + } + + private void ChartDocToolStripMenuItem_Click(object sender, EventArgs e) + { + CreatePdf(); + } + } +} diff --git a/Laba3/ProductForm.resx b/Laba3/FormMain.resx similarity index 93% rename from Laba3/ProductForm.resx rename to Laba3/FormMain.resx index af32865..1af7de1 100644 --- a/Laba3/ProductForm.resx +++ b/Laba3/FormMain.resx @@ -1,17 +1,17 @@  - diff --git a/Laba3/MainForm.Designer.cs b/Laba3/MainForm.Designer.cs deleted file mode 100644 index 3533038..0000000 --- a/Laba3/MainForm.Designer.cs +++ /dev/null @@ -1,178 +0,0 @@ -namespace View -{ - partial class MainForm - { - /// - /// 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(); - menuStrip1 = new MenuStrip(); - createToolStripMenuItem = new ToolStripMenuItem(); - updateToolStripMenuItem = new ToolStripMenuItem(); - deleteToolStripMenuItem = new ToolStripMenuItem(); - manufacturerToolStripMenuItem = new ToolStripMenuItem(); - documentsToolStripMenuItem = new ToolStripMenuItem(); - pdfImageToolStripMenuItem = new ToolStripMenuItem(); - exelTableToolStripMenuItem = new ToolStripMenuItem(); - wordGistToolStripMenuItem = new ToolStripMenuItem(); - outputTableResults = new Library15Gerimovich.OutputTableResults(); - pdfImg = new Library14Petrushin.PdfImg(components); - wordDiagramComponent = new Library15Gerimovich.WordDiagramComponent(components); - componentTable = new WinFormsLibrary1.ComponentTable(components); - saveFileDialogPdf = new SaveFileDialog(); - saveFileDialogWord = new SaveFileDialog(); - saveFileDialogExel = new SaveFileDialog(); - menuStrip1.SuspendLayout(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { createToolStripMenuItem, updateToolStripMenuItem, deleteToolStripMenuItem, manufacturerToolStripMenuItem, documentsToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(480, 28); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; - // - // createToolStripMenuItem - // - createToolStripMenuItem.Name = "createToolStripMenuItem"; - createToolStripMenuItem.Size = new Size(66, 24); - createToolStripMenuItem.Text = "Create"; - createToolStripMenuItem.Click += addToolStripMenuItem_Click; - // - // updateToolStripMenuItem - // - updateToolStripMenuItem.Name = "updateToolStripMenuItem"; - updateToolStripMenuItem.Size = new Size(72, 24); - updateToolStripMenuItem.Text = "Update"; - updateToolStripMenuItem.Click += editToolStripMenuItem_Click; - // - // deleteToolStripMenuItem - // - deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; - deleteToolStripMenuItem.Size = new Size(67, 24); - deleteToolStripMenuItem.Text = "Delete"; - deleteToolStripMenuItem.Click += deleteToolStripMenuItem_Click; - // - // manufacturerToolStripMenuItem - // - manufacturerToolStripMenuItem.Name = "manufacturerToolStripMenuItem"; - manufacturerToolStripMenuItem.Size = new Size(111, 24); - manufacturerToolStripMenuItem.Text = "Manufacturer"; - manufacturerToolStripMenuItem.Click += manufacturersToolStripMenuItem_Click; - // - // documentsToolStripMenuItem - // - documentsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pdfImageToolStripMenuItem, exelTableToolStripMenuItem, wordGistToolStripMenuItem }); - documentsToolStripMenuItem.Name = "documentsToolStripMenuItem"; - documentsToolStripMenuItem.Size = new Size(98, 24); - documentsToolStripMenuItem.Text = "Documents"; - // - // pdfImageToolStripMenuItem - // - pdfImageToolStripMenuItem.Name = "pdfImageToolStripMenuItem"; - pdfImageToolStripMenuItem.Size = new Size(159, 26); - pdfImageToolStripMenuItem.Text = "Pdf Image"; - pdfImageToolStripMenuItem.Click += createSimpleDocumentToolStripMenuItem_Click; - // - // exelTableToolStripMenuItem - // - exelTableToolStripMenuItem.Name = "exelTableToolStripMenuItem"; - exelTableToolStripMenuItem.Size = new Size(159, 26); - exelTableToolStripMenuItem.Text = "Exel table"; - exelTableToolStripMenuItem.Click += createCustomTableDocumentToolStripMenuItem_Click; - // - // wordGistToolStripMenuItem - // - wordGistToolStripMenuItem.Name = "wordGistToolStripMenuItem"; - wordGistToolStripMenuItem.Size = new Size(159, 26); - wordGistToolStripMenuItem.Text = "Word gist"; - wordGistToolStripMenuItem.Click += createChartDocumentToolStripMenuItem_Click; - // - // outputTableResults - // - outputTableResults.Location = new Point(12, 32); - outputTableResults.Margin = new Padding(3, 4, 3, 4); - outputTableResults.Name = "outputTableResults"; - outputTableResults.SelectedRow = -1; - outputTableResults.Size = new Size(467, 308); - outputTableResults.TabIndex = 1; - // - // saveFileDialogPdf - // - saveFileDialogPdf.FileName = "Products.pdf"; - saveFileDialogPdf.Filter = "PDF Files (*.pdf)|*.pdf"; - saveFileDialogPdf.Title = "Save PDF Document"; - // - // saveFileDialogWord - // - saveFileDialogWord.FileName = "Diagram.docx"; - saveFileDialogWord.Filter = "Word Files (*.docx)|*.docx"; - saveFileDialogWord.Title = "Save Word Document"; - // - // saveFileDialogExel - // - saveFileDialogExel.FileName = "ProductReport.xlsx"; - saveFileDialogExel.Filter = "Excel Files (*.xlsx)|*.xlsx"; - saveFileDialogExel.Title = "Save Excel Document"; - // - // MainForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(480, 351); - Controls.Add(outputTableResults); - Controls.Add(menuStrip1); - KeyPreview = true; - MainMenuStrip = menuStrip1; - Name = "MainForm"; - Text = "Form1"; - KeyDown += MainForm_KeyDown; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private MenuStrip menuStrip1; - private ToolStripMenuItem createToolStripMenuItem; - private ToolStripMenuItem updateToolStripMenuItem; - private Library15Gerimovich.OutputTableResults outputTableResults; - private ToolStripMenuItem deleteToolStripMenuItem; - private ToolStripMenuItem manufacturerToolStripMenuItem; - private ToolStripMenuItem documentsToolStripMenuItem; - private ToolStripMenuItem pdfImageToolStripMenuItem; - private ToolStripMenuItem exelTableToolStripMenuItem; - private ToolStripMenuItem wordGistToolStripMenuItem; - private Library14Petrushin.PdfImg pdfImg; - private Library15Gerimovich.WordDiagramComponent wordDiagramComponent; - private WinFormsLibrary1.ComponentTable componentTable; - } -} diff --git a/Laba3/MainForm.cs b/Laba3/MainForm.cs deleted file mode 100644 index 0c27a46..0000000 --- a/Laba3/MainForm.cs +++ /dev/null @@ -1,284 +0,0 @@ -using Data; -using Data.Repositories; -using View; -using System.Windows.Forms; -using Data.Models; -using Library14Petrushin; -using Library15Gerimovich.OfficePackage.HelperModels; -using Library15Gerimovich; -using WinFormsLibrary1; -using WinFormsLibrary1.Models; -using View.ViewModels; - -namespace View -{ - public partial class MainForm : Form - { - private readonly IProductRepository _productRepository; - private readonly IManufacturerRepository _manufacturerRepository; - private SaveFileDialog saveFileDialogPdf; - private SaveFileDialog saveFileDialogWord; - private SaveFileDialog saveFileDialogExel; - - public MainForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository) - { - InitializeComponent(); - _productRepository = productRepository; - _manufacturerRepository = manufacturerRepository; - InitializeOutputTableResults(); - LoadProducts(); - } - - private void InitializeOutputTableResults() - { - outputTableResults.ConfigureColumns(new List - { - new ColumnInfo("", 0, false, "Id"), - new ColumnInfo("Name", 150, true, "Name"), - new ColumnInfo("ManufacturerNameManufacturerName", 150, true, "ManufacturerName"), - new ColumnInfo("DeliveryDate", 50, true, "DeliveryDate"), - }); - - } - - private void LoadProducts() - { - var products = _productRepository.GetAllProducts(); - outputTableResults.ClearGrid(); - foreach (var product in products) - { - outputTableResults.InsertValue(product); - } - } - - private void addToolStripMenuItem_Click(object sender, EventArgs e) - { - var productForm = new ProductForm(_productRepository, _manufacturerRepository); - if (productForm.ShowDialog() == DialogResult.OK) - { - LoadProducts(); - } - } - - private void editToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - var selectedProductId = outputTableResults.GetSelectedObject().Id; - var selectedProduct = _productRepository.GetProductById(selectedProductId); - var productForm = new ProductForm(_productRepository, _manufacturerRepository, selectedProduct); - if (productForm.ShowDialog() == DialogResult.OK) - { - LoadProducts(); - } - } - catch (Exception ex) { - MessageBox.Show(ex.ToString()); - } - } - - private void deleteToolStripMenuItem_Click(object sender, EventArgs e) - { - var selectedProductId = outputTableResults.GetSelectedObject().Id; - if (MessageBox.Show("Are you sure you want to delete this product?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - _productRepository.DeleteProduct(selectedProductId); - LoadProducts(); - } - } - - private void manufacturersToolStripMenuItem_Click(object sender, EventArgs e) - { - var manufacturerForm = new ManufacturerForm(_manufacturerRepository); - manufacturerForm.ShowDialog(); - } - - private void createSimpleDocumentToolStripMenuItem_Click(object sender, EventArgs e) - { - // Получаем изображения из базы данных - var images = GetImagesFromDatabase(); - - if (images.Count > 0) - { - // Показываем диалоговое окно для выбора пути сохранения - if (saveFileDialogPdf.ShowDialog() == DialogResult.OK) - { - // Создаем компонент PdfImg - var pdfImg = new Library14Petrushin.PdfImg(); - - // Путь для сохранения PDF-документа - string fileName = saveFileDialogPdf.FileName; - - // Заголовок документа - string documentTitle = "Product Images"; - - // Создаем PDF-документ - pdfImg.CreatePdfDocument(fileName, documentTitle, images); - - // Уведомление об успешной загрузке - MessageBox.Show("PDF document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - MessageBox.Show("No images found in the database."); - } - } - - private void createCustomTableDocumentToolStripMenuItem_Click(object sender, EventArgs e) - { - // Получаем все продукты из базы данных - var products = GetAllProducts(); - - if (products.Count > 0) - { - // Показываем диалоговое окно для выбора пути сохранения - if (saveFileDialogExel.ShowDialog() == DialogResult.OK) - { - // Создаем объекты MergeCell и Column - var mergeCells = new List - { - new MergeCell("Product", new int[] {1, 2}) - }; - - var columns = new List - { - new Column("Id", "Id", 10), - new Column("Name", "Name", 20), - new Column("ManufacturerName", "ManufacturerName", 20), - new Column("DeliveryDate", "DeliveryDate", 20) - }; - - // Создаем компонент ComponentTable - var componentTable = new ComponentTable(); - - // Конвертируем продукты в представление для таблицы - var tableItems = ProductTableItem.ConvertProductsToTableItems(products); - - // Создаем документ Excel - componentTable.CreateDocument(saveFileDialogExel.FileName, "Product Report", mergeCells, columns, tableItems); - - // Уведомление об успешной загрузке - MessageBox.Show("Excel document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - MessageBox.Show("No products found in the database."); - } - } - - private void createChartDocumentToolStripMenuItem_Click(object sender, EventArgs e) - { - // Получаем данные о количестве продукции каждого производителя - var productCounts = GetProductCountsByManufacturer(); - - if (productCounts.Count > 0) - { - // Показываем диалоговое окно для выбора пути сохранения - if (saveFileDialogWord.ShowDialog() == DialogResult.OK) - { - // Создаем объект WordDiagramInfo - var diagramInfo = new WordDiagramInfo - { - FileName = saveFileDialogWord.FileName, - Title = "Product Count by Manufacturer", - ChartTitle = "Product Count", - LegendLocation = Library15Gerimovich.OfficePackage.HelperEnums.WordDiagramLegendLocation.Top, - Series = new WordDiagramSeries - { - SeriesName = "Product Count", - Data = productCounts - } - }; - - // Создаем диаграмму в Word - wordDiagramComponent.CreateDiagram(diagramInfo); - - // Уведомление об успешной загрузке - MessageBox.Show("Word document with chart created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - MessageBox.Show("No products found in the database."); - } - } - - // бизнес логика - - private void MainForm_KeyDown(object sender, KeyEventArgs e) - { - if (e.Control) - { - switch (e.KeyCode) - { - case Keys.A: - addToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.U: - editToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.D: - deleteToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.S: - createSimpleDocumentToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.T: - createCustomTableDocumentToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.C: - createChartDocumentToolStripMenuItem_Click(null, EventArgs.Empty); - break; - } - } - } - - private List GetImagesFromDatabase() - { - var images = new List(); - var products = _productRepository.GetAllProducts(); - - foreach (var product in products) - { - if (product.Image != null) - { - // Создаем временный файл для сохранения изображения - string tempFilePath = Path.GetTempFileName(); - File.WriteAllBytes(tempFilePath, product.Image); - - // Добавляем путь к временному файлу в список - images.Add(new ImageData { ImagePath = tempFilePath }); - } - } - - return images; - } - - private Dictionary GetProductCountsByManufacturer() - { - var productCounts = new Dictionary(); - var products = _productRepository.GetAllProducts(); - - foreach (var product in products) - { - if (productCounts.ContainsKey(product.ManufacturerName)) - { - productCounts[product.ManufacturerName]++; - } - else - { - productCounts[product.ManufacturerName] = 1; - } - } - - return productCounts; - } - - private List GetAllProducts() - { - return _productRepository.GetAllProducts().ToList(); - } - } -} diff --git a/Laba3/MainForm.resx b/Laba3/MainForm.resx deleted file mode 100644 index 6ce8bc4..0000000 --- a/Laba3/MainForm.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - 572, 17 - - - 708, 17 - - - 813, 17 - - - 1039, 17 - - - 17, 17 - - - 195, 17 - - - 388, 17 - - \ No newline at end of file diff --git a/Laba3/MainPluginConvention.cs b/Laba3/MainPluginConvention.cs new file mode 100644 index 0000000..3062662 --- /dev/null +++ b/Laba3/MainPluginConvention.cs @@ -0,0 +1,304 @@ +using Data; +using Data.Models; +using Data.Repositories; +using Library15Gerimovich; +using Library15Gerimovich.OfficePackage.HelperModels; +using PluginsConventionLibrary.Plugins; +using PluginsConvention14; +using PluginsConvention14.MyPlugin; +using System.Composition; +using WinFormsLibrary1; + +namespace View +{ + [Export(typeof(IPluginsConvention))] + public class MainPluginConvention : IPluginsConvention + { + + private OutputTableResults оutputTableResults; + private readonly IProductRepository _productRepository; + private readonly IManufacturerRepository _manufacturerRepository; + public string PluginName { get; set; } = "Products"; + + public MainPluginConvention() + { + var dbContext = new ApplicationDbContext(); + _productRepository = new ProductRepository(dbContext); + _manufacturerRepository = new ManufacturerRepository(dbContext); + + оutputTableResults = new OutputTableResults(); + var menu = new ContextMenuStrip(); + var skillMenuItem = new ToolStripMenuItem("Forms"); + menu.Items.Add(skillMenuItem); + skillMenuItem.Click += (sender, e) => + { + var formSkill = new ManufacturerForm(_manufacturerRepository); + formSkill.ShowDialog(); + }; + оutputTableResults.ContextMenuStrip = menu; + ReloadData(); + } + + /// Название плагина + /*string IPluginsConvention.PluginName => PluginName(); + public string PluginName() + { + return "Products"; + }*/ + + public UserControl GetControl => оutputTableResults; + + PluginsConventionElement IPluginsConvention.GetElement => GetElement(); + + public PluginsConventionElement GetElement() + { + var product = оutputTableResults.GetSelectedObject(); ; + MainPluginConventionElement element = null; + if (оutputTableResults != null) + { + element = new MainPluginConventionElement + { + Id = product.Id, + Name = product.Name, + ManufacturerName = product.ManufacturerName, + DeliveryDate = product.DeliveryDate, + }; + } + return (new PluginsConventionElement { Id = element.Id }); + } + + public Form GetForm(PluginsConventionElement element) + { + if (element != null) + { + var formOrder = new ProductForm(_productRepository, _manufacturerRepository, _productRepository.GetProductById(Convert.ToInt32(element.Id))); + return formOrder; + } + else + { + var formOrder = new ProductForm(_productRepository, _manufacturerRepository); + return formOrder; + } + } + + public bool DeleteElement(PluginsConventionElement element) + { + try + { + _productRepository.DeleteProduct(Convert.ToInt32(element.Id)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + return true; + } + + public void ReloadData() + { + var products = _productRepository.GetAllProducts(); + + оutputTableResults.ClearGrid(); + foreach (var product in products) + { + оutputTableResults.InsertValue(product); + } + } + public bool CreatePdf(PluginsConventionSaveDocument saveDocument) + { + try + { + // Получаем изображения из базы данных + var images = GetImagesFromDatabase(); + + if (images.Count > 0) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + } + } + // Создаем компонент PdfImg + var pdfImg = new Library14Petrushin.PdfImg(); + + // Заголовок документа + string documentTitle = "Product Images"; + + // Создаем PDF-документ + pdfImg.CreatePdfDocument(fileName, documentTitle, images); + + // Уведомление об успешной загрузке + MessageBox.Show("PDF document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); + + } + } + catch (Exception) + { + return false; + } + return true; + } + + private List GetImagesFromDatabase() + { + var images = new List(); + var products = _productRepository.GetAllProducts(); + + foreach (var product in products) + { + if (product.Image != null) + { + // Создаем временный файл для сохранения изображения + string tempFilePath = Path.GetTempFileName(); + File.WriteAllBytes(tempFilePath, product.Image); + + // Добавляем путь к временному файлу в список + images.Add(new Library14Petrushin.ImageData { ImagePath = tempFilePath }); + } + } + + return images; + } + + public bool CreateExcel(PluginsConventionSaveDocument saveDocument) + { + try + { + + + // Получаем все продукты из базы данных + var products = GetAllProducts(); + + if (products.Count > 0) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + } + } + // Создаем объекты MergeCell и Column + var mergeCells = new List + { + new WinFormsLibrary1.Models.MergeCell("Product", new int[] {1, 2}) + }; + + var columns = new List + { + new WinFormsLibrary1.Models.Column("Id", "Id", 10), + new WinFormsLibrary1.Models.Column("Name", "Name", 20), + new WinFormsLibrary1.Models.Column("ManufacturerName", "ManufacturerName", 20), + new WinFormsLibrary1.Models.Column("DeliveryDate", "DeliveryDate", 20) + }; + + // Создаем компонент ComponentTable + var componentTable = new ComponentTable(); + + // Конвертируем продукты в представление для таблицы + var tableItems = MainPluginConventionElement.ConvertProductsToTableItems(products); + + // Создаем документ Excel + componentTable.CreateDocument(fileName, "Product Report", mergeCells, columns, tableItems); + + // Уведомление об успешной загрузке + MessageBox.Show("Excel document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("No products found in the database."); + } + } + + catch (Exception) + { + return false; + } + return true; + } + + private List GetAllProducts() + { + return _productRepository.GetAllProducts().ToList(); + } + + public bool CreateWord(PluginsConventionSaveDocument saveDocument) + { + try + { + + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + } + } + + // Получаем данные о количестве продукции каждого производителя + var productCounts = GetProductCountsByManufacturer(); + + if (productCounts.Count > 0) + { + // Создаем объект WordDiagramInfo + var diagramInfo = new WordDiagramInfo + { + FileName = fileName, + Title = "Product Count by Manufacturer", + ChartTitle = "Product Count", + LegendLocation = Library15Gerimovich.OfficePackage.HelperEnums.WordDiagramLegendLocation.Top, + Series = new WordDiagramSeries + { + SeriesName = "Product Count", + Data = productCounts + } + }; + + var wordDiagramComponent = new WordDiagramComponent(); + + // Создаем диаграмму в Word + wordDiagramComponent.CreateDiagram(diagramInfo); + + // Уведомление об успешной загрузке + MessageBox.Show("Word document with chart created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("No products found in the database."); + } + + } + catch (Exception) + { + return false; + } + return true; + } + + private Dictionary GetProductCountsByManufacturer() + { + var productCounts = new Dictionary(); + var products = _productRepository.GetAllProducts(); + + foreach (var product in products) + { + if (productCounts.ContainsKey(product.ManufacturerName)) + { + productCounts[product.ManufacturerName]++; + } + else + { + productCounts[product.ManufacturerName] = 1; + } + } + + return productCounts; + } + } +} diff --git a/Laba3/ManufacturerForm.Designer.cs b/Laba3/ManufacturerForm.Designer.cs deleted file mode 100644 index 89fec90..0000000 --- a/Laba3/ManufacturerForm.Designer.cs +++ /dev/null @@ -1,64 +0,0 @@ -namespace View -{ - partial class ManufacturerForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - dataGridView = new DataGridView(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 12); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.Size = new Size(711, 426); - dataGridView.TabIndex = 0; - dataGridView.CellValueChanged += dataGridView_CellValueChanged; - dataGridView.UserAddedRow += dataGridView_UserAddedRow; - dataGridView.UserDeletingRow += dataGridView_UserDeletingRow; - dataGridView.KeyDown += dataGridView_KeyDown; - // - // ManufacturerForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(731, 450); - Controls.Add(dataGridView); - Name = "ManufacturerForm"; - Text = "ManufacturerForm"; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - } - - #endregion - - private DataGridView dataGridView; - } -} \ No newline at end of file diff --git a/Laba3/ManufacturerForm.cs b/Laba3/ManufacturerForm.cs deleted file mode 100644 index 23638fb..0000000 --- a/Laba3/ManufacturerForm.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Data.Models; -using Data.Repositories; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace View -{ - public partial class ManufacturerForm : Form - { - private readonly IManufacturerRepository _manufacturerRepository; - - public ManufacturerForm(IManufacturerRepository manufacturerRepository) - { - InitializeComponent(); - _manufacturerRepository = manufacturerRepository; - LoadManufacturers(); - } - - private void LoadManufacturers() - { - var manufacturers = _manufacturerRepository.GetAllManufacturers().ToList(); - dataGridView.DataSource = manufacturers; - } - - private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) - { - if (e.RowIndex >= 0) - { - var manufacturer = dataGridView.Rows[e.RowIndex].DataBoundItem as Manufacturer; - if (manufacturer != null) - { - _manufacturerRepository.UpdateManufacturer(manufacturer); - } - } - } - - private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) - { - var manufacturer = e.Row.DataBoundItem as Manufacturer; - if (manufacturer != null) - { - if (MessageBox.Show("Are you sure you want to delete this manufacturer?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - _manufacturerRepository.DeleteManufacturer(manufacturer.Id); - } - else - { - e.Cancel = true; - } - } - } - - private void dataGridView_UserAddedRow(object sender, DataGridViewRowEventArgs e) - { - var manufacturer = new Manufacturer { Name = "" }; - _manufacturerRepository.AddManufacturer(manufacturer); - LoadManufacturers(); - } - - - // реализация через нажатие клавишь - - private void dataGridView_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Insert) - { - var manufacturer = new Manufacturer { Name = "" }; - _manufacturerRepository.AddManufacturer(manufacturer); - LoadManufacturers(); - } - else if (e.KeyCode == Keys.Delete) - { - if (dataGridView.SelectedRows.Count > 0) - { - var selectedManufacturer = dataGridView.SelectedRows[0].DataBoundItem as Manufacturer; - if (selectedManufacturer != null) - { - if (MessageBox.Show("Are you sure you want to delete this manufacturer?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - _manufacturerRepository.DeleteManufacturer(selectedManufacturer.Id); - LoadManufacturers(); - } - } - } - } - } - } -} diff --git a/Laba3/ManufacturerForm.resx b/Laba3/ManufacturerForm.resx deleted file mode 100644 index af32865..0000000 --- a/Laba3/ManufacturerForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/Laba3/PluginsManager.cs b/Laba3/PluginsManager.cs new file mode 100644 index 0000000..c8f9274 --- /dev/null +++ b/Laba3/PluginsManager.cs @@ -0,0 +1,50 @@ +using PluginsConventionLibrary.Plugins; +using System; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.ComponentModel.Composition.Hosting; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace View +{ + public class PluginsManager + { + //Тег, указывающий, что plugins должны быть заполнены CompositionContainer + [ImportMany(typeof(IPluginsConvention))] + IEnumerable Plugins { get; set; } + + public readonly Dictionary plugins_dictionary = new Dictionary(); + + 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/Laba3/ProductForm.Designer.cs b/Laba3/ProductForm.Designer.cs deleted file mode 100644 index 247f34f..0000000 --- a/Laba3/ProductForm.Designer.cs +++ /dev/null @@ -1,121 +0,0 @@ -namespace PluginsConvention14 -{ - partial class ProductForm - { - /// - /// 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() - { - dtpDeliveryDate = new WinFormsLibrary1.DateInputControl(); - cmbManufacturer = new WinFormsLibrary1.ComboBoxUserControl(); - txtName = new Library14Petrushin.TextBoxRange(); - pbImage = new PictureBox(); - button1 = new Button(); - button2 = new Button(); - ((System.ComponentModel.ISupportInitialize)pbImage).BeginInit(); - SuspendLayout(); - // - // dtpDeliveryDate - // - dtpDeliveryDate.DateFormat = null; - dtpDeliveryDate.Location = new Point(13, 137); - dtpDeliveryDate.Margin = new Padding(4, 5, 4, 5); - dtpDeliveryDate.Name = "dtpDeliveryDate"; - dtpDeliveryDate.Size = new Size(186, 110); - dtpDeliveryDate.TabIndex = 0; - // - // cmbManufacturer - // - cmbManufacturer.Location = new Point(12, 218); - cmbManufacturer.Margin = new Padding(4, 5, 4, 5); - cmbManufacturer.Name = "cmbManufacturer"; - cmbManufacturer.SelectedValue = ""; - cmbManufacturer.Size = new Size(201, 40); - cmbManufacturer.TabIndex = 1; - // - // txtName - // - txtName.Location = new Point(12, 12); - txtName.MaxLength = null; - txtName.MinLength = null; - txtName.Name = "txtName"; - txtName.Size = new Size(315, 108); - txtName.TabIndex = 2; - // - // pbImage - // - pbImage.Location = new Point(320, 32); - pbImage.Name = "pbImage"; - pbImage.Size = new Size(451, 344); - pbImage.TabIndex = 3; - pbImage.TabStop = false; - // - // button1 - // - button1.Location = new Point(320, 399); - button1.Name = "button1"; - button1.Size = new Size(110, 29); - button1.TabIndex = 4; - button1.Text = "Choose img"; - button1.UseVisualStyleBackColor = true; - button1.Click += btnBrowse_Click; - // - // button2 - // - button2.Location = new Point(12, 326); - button2.Name = "button2"; - button2.Size = new Size(94, 29); - button2.TabIndex = 5; - button2.Text = "Save"; - button2.UseVisualStyleBackColor = true; - button2.Click += btnSave_Click; - // - // ProductForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(button2); - Controls.Add(button1); - Controls.Add(pbImage); - Controls.Add(txtName); - Controls.Add(cmbManufacturer); - Controls.Add(dtpDeliveryDate); - Name = "ProductForm"; - Text = "ProductForm"; - ((System.ComponentModel.ISupportInitialize)pbImage).EndInit(); - ResumeLayout(false); - } - - #endregion - - private WinFormsLibrary1.DateInputControl dtpDeliveryDate; - private WinFormsLibrary1.ComboBoxUserControl cmbManufacturer; - private Library14Petrushin.TextBoxRange txtName; - private PictureBox pbImage; - private Button button1; - private Button button2; - } -} \ No newline at end of file diff --git a/Laba3/ProductForm.cs b/Laba3/ProductForm.cs deleted file mode 100644 index 63fac49..0000000 --- a/Laba3/ProductForm.cs +++ /dev/null @@ -1,116 +0,0 @@ -using Data; -using Data.Models; -using Data.Repositories; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace View -{ - public partial class ProductForm : Form - { - private readonly IProductRepository _productRepository; - private readonly IManufacturerRepository _manufacturerRepository; - private Product _product; - private bool _isNewProduct; - private const int MINL = 3; - private const int MAXL= 10; - - public ProductForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository, Product product = null) - { - InitializeComponent(); - Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; - - _productRepository = productRepository; - _manufacturerRepository = manufacturerRepository; - - - var manufacturers = _manufacturerRepository.GetAllManufacturers().Select(m => m.Name).ToList(); - // cmbManufacturer.Data = manufacturers; - foreach (var manufacturer in manufacturers) - { - cmbManufacturer.AddItem(manufacturer); - } - - _product = product; - _isNewProduct = product == null; - txtName.MinLength = MINL; - txtName.MaxLength = MAXL; - dtpDeliveryDate.DateFormat = "dd MMMM yyyy"; - - if (!_isNewProduct) - { - txtName.InputValue = _product.Name; - cmbManufacturer.SelectedValue = _product.ManufacturerName; - dtpDeliveryDate.Date = _product.DeliveryDate; - - if (_product.Image != null) - { - using (var ms = new MemoryStream(_product.Image)) - { - pbImage.Image = Image.FromStream(ms); - } - } - } - } - - private void btnBrowse_Click(object sender, EventArgs e) - { - using (var openFileDialog = new OpenFileDialog()) - { - openFileDialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp"; - if (openFileDialog.ShowDialog() == DialogResult.OK) - { - pbImage.Image = Image.FromFile(openFileDialog.FileName); - } - } - } - - private void btnSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(txtName.InputValue)) - { - MessageBox.Show("Name is required."); - return; - } - - if (_isNewProduct) - { - _product = new Product(); - } - - _product.Name = txtName.InputValue; - _product.ManufacturerName = cmbManufacturer.SelectedValue.ToString(); - _product.DeliveryDate = dtpDeliveryDate.Date; - - if (pbImage.Image != null) - { - using (var ms = new MemoryStream()) - { - pbImage.Image.Save(ms, pbImage.Image.RawFormat); - _product.Image = ms.ToArray(); - } - } - - if (_isNewProduct) - { - _productRepository.AddProduct(_product); - } - else - { - _productRepository.UpdateProduct(_product); - } - - - DialogResult = DialogResult.OK; - Close(); - } - } -} diff --git a/Laba3/Program.cs b/Laba3/Program.cs index 242e123..2d79bdd 100644 --- a/Laba3/Program.cs +++ b/Laba3/Program.cs @@ -11,15 +11,9 @@ namespace View [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - // - var dbContext = new ApplicationDbContext(); - var productRepository = new ProductRepository(dbContext); - var manufacturerRepository = new ManufacturerRepository(dbContext); // MainForm - Application.Run(new MainForm(productRepository, manufacturerRepository)); + Application.Run(new FormMain()); } } } \ No newline at end of file diff --git a/Laba3/View.csproj b/Laba3/View.csproj index 4b844d1..84d890f 100644 --- a/Laba3/View.csproj +++ b/Laba3/View.csproj @@ -17,11 +17,13 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + - + + diff --git a/Library14Petrushin/Library14Petrushin.sln b/Library14Petrushin/Library14Petrushin.sln index 5985868..faf51a8 100644 --- a/Library14Petrushin/Library14Petrushin.sln +++ b/Library14Petrushin/Library14Petrushin.sln @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "View", "..\Laba3\View.cspro EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "..\Models\Data.csproj", "{DC70937E-903F-4BAA-A774-80D01EC5B75A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginsConvention14", "..\PluginsConvention14\PluginsConvention14.csproj", "{C6CB6D7F-9DCF-414B-8544-1AE4FDE373CD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginsConvention14", "..\PluginsConvention14\PluginsConvention14.csproj", "{C6CB6D7F-9DCF-414B-8544-1AE4FDE373CD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Plugins/PluginsConvention14.dll b/Plugins/PluginsConvention14.dll new file mode 100644 index 0000000000000000000000000000000000000000..49bac5b8809d230578ba518b3d13f794a839989d GIT binary patch literal 20480 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 E0h@AttpET3 literal 0 HcmV?d00001 diff --git a/PluginsConvention14/Forms/MainForm.Designer.cs b/PluginsConvention14/Forms/MainForm.Designer.cs deleted file mode 100644 index 53728bf..0000000 --- a/PluginsConvention14/Forms/MainForm.Designer.cs +++ /dev/null @@ -1,178 +0,0 @@ -namespace PluginsConvention14 -{ - partial class MainForm - { - /// - /// 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(); - menuStrip1 = new MenuStrip(); - createToolStripMenuItem = new ToolStripMenuItem(); - updateToolStripMenuItem = new ToolStripMenuItem(); - deleteToolStripMenuItem = new ToolStripMenuItem(); - manufacturerToolStripMenuItem = new ToolStripMenuItem(); - documentsToolStripMenuItem = new ToolStripMenuItem(); - pdfImageToolStripMenuItem = new ToolStripMenuItem(); - exelTableToolStripMenuItem = new ToolStripMenuItem(); - wordGistToolStripMenuItem = new ToolStripMenuItem(); - outputTableResults = new Library15Gerimovich.OutputTableResults(); - pdfImg = new Library14Petrushin.PdfImg(components); - wordDiagramComponent = new Library15Gerimovich.WordDiagramComponent(components); - componentTable = new WinFormsLibrary1.ComponentTable(components); - saveFileDialogPdf = new SaveFileDialog(); - saveFileDialogWord = new SaveFileDialog(); - saveFileDialogExel = new SaveFileDialog(); - menuStrip1.SuspendLayout(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { createToolStripMenuItem, updateToolStripMenuItem, deleteToolStripMenuItem, manufacturerToolStripMenuItem, documentsToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(480, 28); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; - // - // createToolStripMenuItem - // - createToolStripMenuItem.Name = "createToolStripMenuItem"; - createToolStripMenuItem.Size = new Size(66, 24); - createToolStripMenuItem.Text = "Create"; - createToolStripMenuItem.Click += addToolStripMenuItem_Click; - // - // updateToolStripMenuItem - // - updateToolStripMenuItem.Name = "updateToolStripMenuItem"; - updateToolStripMenuItem.Size = new Size(72, 24); - updateToolStripMenuItem.Text = "Update"; - updateToolStripMenuItem.Click += editToolStripMenuItem_Click; - // - // deleteToolStripMenuItem - // - deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; - deleteToolStripMenuItem.Size = new Size(67, 24); - deleteToolStripMenuItem.Text = "Delete"; - deleteToolStripMenuItem.Click += deleteToolStripMenuItem_Click; - // - // manufacturerToolStripMenuItem - // - manufacturerToolStripMenuItem.Name = "manufacturerToolStripMenuItem"; - manufacturerToolStripMenuItem.Size = new Size(111, 24); - manufacturerToolStripMenuItem.Text = "Manufacturer"; - manufacturerToolStripMenuItem.Click += manufacturersToolStripMenuItem_Click; - // - // documentsToolStripMenuItem - // - documentsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pdfImageToolStripMenuItem, exelTableToolStripMenuItem, wordGistToolStripMenuItem }); - documentsToolStripMenuItem.Name = "documentsToolStripMenuItem"; - documentsToolStripMenuItem.Size = new Size(98, 24); - documentsToolStripMenuItem.Text = "Documents"; - // - // pdfImageToolStripMenuItem - // - pdfImageToolStripMenuItem.Name = "pdfImageToolStripMenuItem"; - pdfImageToolStripMenuItem.Size = new Size(159, 26); - pdfImageToolStripMenuItem.Text = "Pdf Image"; - pdfImageToolStripMenuItem.Click += createSimpleDocumentToolStripMenuItem_Click; - // - // exelTableToolStripMenuItem - // - exelTableToolStripMenuItem.Name = "exelTableToolStripMenuItem"; - exelTableToolStripMenuItem.Size = new Size(159, 26); - exelTableToolStripMenuItem.Text = "Exel table"; - exelTableToolStripMenuItem.Click += createCustomTableDocumentToolStripMenuItem_Click; - // - // wordGistToolStripMenuItem - // - wordGistToolStripMenuItem.Name = "wordGistToolStripMenuItem"; - wordGistToolStripMenuItem.Size = new Size(159, 26); - wordGistToolStripMenuItem.Text = "Word gist"; - wordGistToolStripMenuItem.Click += createChartDocumentToolStripMenuItem_Click; - // - // outputTableResults - // - outputTableResults.Location = new Point(12, 32); - outputTableResults.Margin = new Padding(3, 4, 3, 4); - outputTableResults.Name = "outputTableResults"; - outputTableResults.SelectedRow = -1; - outputTableResults.Size = new Size(467, 308); - outputTableResults.TabIndex = 1; - // - // saveFileDialogPdf - // - saveFileDialogPdf.FileName = "Products.pdf"; - saveFileDialogPdf.Filter = "PDF Files (*.pdf)|*.pdf"; - saveFileDialogPdf.Title = "Save PDF Document"; - // - // saveFileDialogWord - // - saveFileDialogWord.FileName = "Diagram.docx"; - saveFileDialogWord.Filter = "Word Files (*.docx)|*.docx"; - saveFileDialogWord.Title = "Save Word Document"; - // - // saveFileDialogExel - // - saveFileDialogExel.FileName = "ProductReport.xlsx"; - saveFileDialogExel.Filter = "Excel Files (*.xlsx)|*.xlsx"; - saveFileDialogExel.Title = "Save Excel Document"; - // - // MainForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(480, 351); - Controls.Add(outputTableResults); - Controls.Add(menuStrip1); - KeyPreview = true; - MainMenuStrip = menuStrip1; - Name = "MainForm"; - Text = "Form1"; - KeyDown += MainForm_KeyDown; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private MenuStrip menuStrip1; - private ToolStripMenuItem createToolStripMenuItem; - private ToolStripMenuItem updateToolStripMenuItem; - private Library15Gerimovich.OutputTableResults outputTableResults; - private ToolStripMenuItem deleteToolStripMenuItem; - private ToolStripMenuItem manufacturerToolStripMenuItem; - private ToolStripMenuItem documentsToolStripMenuItem; - private ToolStripMenuItem pdfImageToolStripMenuItem; - private ToolStripMenuItem exelTableToolStripMenuItem; - private ToolStripMenuItem wordGistToolStripMenuItem; - private Library14Petrushin.PdfImg pdfImg; - private Library15Gerimovich.WordDiagramComponent wordDiagramComponent; - private WinFormsLibrary1.ComponentTable componentTable; - } -} diff --git a/PluginsConvention14/Forms/MainForm.cs b/PluginsConvention14/Forms/MainForm.cs deleted file mode 100644 index 23c22ac..0000000 --- a/PluginsConvention14/Forms/MainForm.cs +++ /dev/null @@ -1,284 +0,0 @@ -using Data; -using Data.Repositories; -using View; -using System.Windows.Forms; -using Data.Models; -using Library14Petrushin; -using Library15Gerimovich.OfficePackage.HelperModels; -using Library15Gerimovich; -using WinFormsLibrary1; -using WinFormsLibrary1.Models; -using View.ViewModels; - -namespace PluginsConvention14 -{ - public partial class MainForm : Form - { - private readonly IProductRepository _productRepository; - private readonly IManufacturerRepository _manufacturerRepository; - private SaveFileDialog saveFileDialogPdf; - private SaveFileDialog saveFileDialogWord; - private SaveFileDialog saveFileDialogExel; - - public MainForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository) - { - InitializeComponent(); - _productRepository = productRepository; - _manufacturerRepository = manufacturerRepository; - InitializeOutputTableResults(); - LoadProducts(); - } - - private void InitializeOutputTableResults() - { - outputTableResults.ConfigureColumns(new List - { - new ColumnInfo("", 0, false, "Id"), - new ColumnInfo("Name", 150, true, "Name"), - new ColumnInfo("ManufacturerNameManufacturerName", 150, true, "ManufacturerName"), - new ColumnInfo("DeliveryDate", 50, true, "DeliveryDate"), - }); - - } - - private void LoadProducts() - { - var products = _productRepository.GetAllProducts(); - outputTableResults.ClearGrid(); - foreach (var product in products) - { - outputTableResults.InsertValue(product); - } - } - - private void addToolStripMenuItem_Click(object sender, EventArgs e) - { - var productForm = new ProductForm(_productRepository, _manufacturerRepository); - if (productForm.ShowDialog() == DialogResult.OK) - { - LoadProducts(); - } - } - - private void editToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - var selectedProductId = outputTableResults.GetSelectedObject().Id; - var selectedProduct = _productRepository.GetProductById(selectedProductId); - var productForm = new ProductForm(_productRepository, _manufacturerRepository, selectedProduct); - if (productForm.ShowDialog() == DialogResult.OK) - { - LoadProducts(); - } - } - catch (Exception ex) { - MessageBox.Show(ex.ToString()); - } - } - - private void deleteToolStripMenuItem_Click(object sender, EventArgs e) - { - var selectedProductId = outputTableResults.GetSelectedObject().Id; - if (MessageBox.Show("Are you sure you want to delete this product?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - _productRepository.DeleteProduct(selectedProductId); - LoadProducts(); - } - } - - private void manufacturersToolStripMenuItem_Click(object sender, EventArgs e) - { - var manufacturerForm = new ManufacturerForm(_manufacturerRepository); - manufacturerForm.ShowDialog(); - } - - private void createSimpleDocumentToolStripMenuItem_Click(object sender, EventArgs e) - { - // Получаем изображения из базы данных - var images = GetImagesFromDatabase(); - - if (images.Count > 0) - { - // Показываем диалоговое окно для выбора пути сохранения - if (saveFileDialogPdf.ShowDialog() == DialogResult.OK) - { - // Создаем компонент PdfImg - var pdfImg = new Library14Petrushin.PdfImg(); - - // Путь для сохранения PDF-документа - string fileName = saveFileDialogPdf.FileName; - - // Заголовок документа - string documentTitle = "Product Images"; - - // Создаем PDF-документ - pdfImg.CreatePdfDocument(fileName, documentTitle, images); - - // Уведомление об успешной загрузке - MessageBox.Show("PDF document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - MessageBox.Show("No images found in the database."); - } - } - - private void createCustomTableDocumentToolStripMenuItem_Click(object sender, EventArgs e) - { - // Получаем все продукты из базы данных - var products = GetAllProducts(); - - if (products.Count > 0) - { - // Показываем диалоговое окно для выбора пути сохранения - if (saveFileDialogExel.ShowDialog() == DialogResult.OK) - { - // Создаем объекты MergeCell и Column - var mergeCells = new List - { - new MergeCell("Product", new int[] {1, 2}) - }; - - var columns = new List - { - new Column("Id", "Id", 10), - new Column("Name", "Name", 20), - new Column("ManufacturerName", "ManufacturerName", 20), - new Column("DeliveryDate", "DeliveryDate", 20) - }; - - // Создаем компонент ComponentTable - var componentTable = new ComponentTable(); - - // Конвертируем продукты в представление для таблицы - var tableItems = ProductTableItem.ConvertProductsToTableItems(products); - - // Создаем документ Excel - componentTable.CreateDocument(saveFileDialogExel.FileName, "Product Report", mergeCells, columns, tableItems); - - // Уведомление об успешной загрузке - MessageBox.Show("Excel document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - MessageBox.Show("No products found in the database."); - } - } - - private void createChartDocumentToolStripMenuItem_Click(object sender, EventArgs e) - { - // Получаем данные о количестве продукции каждого производителя - var productCounts = GetProductCountsByManufacturer(); - - if (productCounts.Count > 0) - { - // Показываем диалоговое окно для выбора пути сохранения - if (saveFileDialogWord.ShowDialog() == DialogResult.OK) - { - // Создаем объект WordDiagramInfo - var diagramInfo = new WordDiagramInfo - { - FileName = saveFileDialogWord.FileName, - Title = "Product Count by Manufacturer", - ChartTitle = "Product Count", - LegendLocation = Library15Gerimovich.OfficePackage.HelperEnums.WordDiagramLegendLocation.Top, - Series = new WordDiagramSeries - { - SeriesName = "Product Count", - Data = productCounts - } - }; - - // Создаем диаграмму в Word - wordDiagramComponent.CreateDiagram(diagramInfo); - - // Уведомление об успешной загрузке - MessageBox.Show("Word document with chart created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - MessageBox.Show("No products found in the database."); - } - } - - // бизнес логика - - private void MainForm_KeyDown(object sender, KeyEventArgs e) - { - if (e.Control) - { - switch (e.KeyCode) - { - case Keys.A: - addToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.U: - editToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.D: - deleteToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.S: - createSimpleDocumentToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.T: - createCustomTableDocumentToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.C: - createChartDocumentToolStripMenuItem_Click(null, EventArgs.Empty); - break; - } - } - } - - private List GetImagesFromDatabase() - { - var images = new List(); - var products = _productRepository.GetAllProducts(); - - foreach (var product in products) - { - if (product.Image != null) - { - // Создаем временный файл для сохранения изображения - string tempFilePath = Path.GetTempFileName(); - File.WriteAllBytes(tempFilePath, product.Image); - - // Добавляем путь к временному файлу в список - images.Add(new ImageData { ImagePath = tempFilePath }); - } - } - - return images; - } - - private Dictionary GetProductCountsByManufacturer() - { - var productCounts = new Dictionary(); - var products = _productRepository.GetAllProducts(); - - foreach (var product in products) - { - if (productCounts.ContainsKey(product.ManufacturerName)) - { - productCounts[product.ManufacturerName]++; - } - else - { - productCounts[product.ManufacturerName] = 1; - } - } - - return productCounts; - } - - private List GetAllProducts() - { - return _productRepository.GetAllProducts().ToList(); - } - } -} diff --git a/PluginsConvention14/Forms/MainForm.resx b/PluginsConvention14/Forms/MainForm.resx deleted file mode 100644 index 6ce8bc4..0000000 --- a/PluginsConvention14/Forms/MainForm.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - 572, 17 - - - 708, 17 - - - 813, 17 - - - 1039, 17 - - - 17, 17 - - - 195, 17 - - - 388, 17 - - \ No newline at end of file diff --git a/PluginsConvention14/Forms/ManufacturerForm.Designer.cs b/PluginsConvention14/Forms/ManufacturerForm.Designer.cs index fdb5cae..d34b7c9 100644 --- a/PluginsConvention14/Forms/ManufacturerForm.Designer.cs +++ b/PluginsConvention14/Forms/ManufacturerForm.Designer.cs @@ -1,4 +1,4 @@ -namespace ViewPluginsConvention14 +namespace PluginsConvention14 { partial class ManufacturerForm { diff --git a/PluginsConvention14/Forms/ManufacturerForm.cs b/PluginsConvention14/Forms/ManufacturerForm.cs index cf22e6f..af1e794 100644 --- a/PluginsConvention14/Forms/ManufacturerForm.cs +++ b/PluginsConvention14/Forms/ManufacturerForm.cs @@ -1,14 +1,5 @@ using Data.Models; using Data.Repositories; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace PluginsConvention14 { @@ -63,7 +54,7 @@ namespace PluginsConvention14 _manufacturerRepository.AddManufacturer(manufacturer); LoadManufacturers(); } - + // реализация через нажатие клавишь diff --git a/PluginsConvention14/Forms/ProductForm.cs b/PluginsConvention14/Forms/ProductForm.cs index f73451f..9c612cb 100644 --- a/PluginsConvention14/Forms/ProductForm.cs +++ b/PluginsConvention14/Forms/ProductForm.cs @@ -1,16 +1,7 @@ -using Data; -using Data.Models; +using Data.Models; using Data.Repositories; -using System; -using System.Collections.Generic; -using System.ComponentModel; using System.Data; -using System.Drawing; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace PluginsConvention14 { @@ -21,7 +12,7 @@ namespace PluginsConvention14 private Product _product; private bool _isNewProduct; private const int MINL = 3; - private const int MAXL= 10; + private const int MAXL = 10; public ProductForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository, Product product = null) { @@ -108,7 +99,7 @@ namespace PluginsConvention14 _productRepository.UpdateProduct(_product); } - + DialogResult = DialogResult.OK; Close(); } diff --git a/PluginsConvention14/MyPlugin/MainPluginConvention.cs b/PluginsConvention14/MyPlugin/MainPluginConvention.cs index 9ca425c..2144152 100644 --- a/PluginsConvention14/MyPlugin/MainPluginConvention.cs +++ b/PluginsConvention14/MyPlugin/MainPluginConvention.cs @@ -1,17 +1,11 @@ -using PluginsConventionLibrary.Plugins; -using System.Composition; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Library15Gerimovich; -using Data.Repositories; +using Data; using Data.Models; -using Data; -using View.ViewModels; -using WinFormsLibrary1; +using Data.Repositories; +using Library15Gerimovich; using Library15Gerimovich.OfficePackage.HelperModels; +using PluginsConventionLibrary.Plugins; +using System.Composition; +using WinFormsLibrary1; namespace PluginsConvention14.MyPlugin { @@ -22,6 +16,7 @@ namespace PluginsConvention14.MyPlugin private OutputTableResults оutputTableResults; private readonly IProductRepository _productRepository; private readonly IManufacturerRepository _manufacturerRepository; + public string PluginName { get; set; } = "Products"; public MainPluginConvention() { @@ -31,7 +26,7 @@ namespace PluginsConvention14.MyPlugin оutputTableResults = new OutputTableResults(); var menu = new ContextMenuStrip(); - var skillMenuItem = new ToolStripMenuItem("Формы"); + var skillMenuItem = new ToolStripMenuItem("Forms"); menu.Items.Add(skillMenuItem); skillMenuItem.Click += (sender, e) => { @@ -39,15 +34,29 @@ namespace PluginsConvention14.MyPlugin formSkill.ShowDialog(); }; оutputTableResults.ContextMenuStrip = menu; + + InitializeOutputTableResults(); ReloadData(); } + private void InitializeOutputTableResults() + { + оutputTableResults.ConfigureColumns(new List + { + new ColumnInfo("", 0, false, "Id"), + new ColumnInfo("Name", 150, true, "Name"), + new ColumnInfo("ManufacturerNameManufacturerName", 150, true, "ManufacturerName"), + new ColumnInfo("DeliveryDate", 50, true, "DeliveryDate"), + }); + + } + /// Название плагина - string IPluginsConvention.PluginName => PluginName(); + /*string IPluginsConvention.PluginName => PluginName(); public string PluginName() { return "Products"; - } + }*/ public UserControl GetControl => оutputTableResults; @@ -74,7 +83,7 @@ namespace PluginsConvention14.MyPlugin { if (element != null) { - var formOrder = new ProductForm(_productRepository, _manufacturerRepository, _productRepository.GetProductById(element.Id)); + var formOrder = new ProductForm(_productRepository, _manufacturerRepository, _productRepository.GetProductById(Convert.ToInt32(element.Id))); return formOrder; } else @@ -88,7 +97,7 @@ namespace PluginsConvention14.MyPlugin { try { - _productRepository.DeleteProduct(element.Id); + _productRepository.DeleteProduct(Convert.ToInt32(element.Id)); } catch (Exception ex) { @@ -125,18 +134,18 @@ namespace PluginsConvention14.MyPlugin fileName = dialog.FileName.ToString(); } } - // Создаем компонент PdfImg - var pdfImg = new Library14Petrushin.PdfImg(); + // Создаем компонент PdfImg + var pdfImg = new Library14Petrushin.PdfImg(); - // Заголовок документа - string documentTitle = "Product Images"; + // Заголовок документа + string documentTitle = "Product Images"; - // Создаем PDF-документ - pdfImg.CreatePdfDocument(fileName, documentTitle, images); + // Создаем PDF-документ + pdfImg.CreatePdfDocument(fileName, documentTitle, images); + + // Уведомление об успешной загрузке + MessageBox.Show("PDF document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - // Уведомление об успешной загрузке - MessageBox.Show("PDF document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } } catch (Exception) @@ -171,7 +180,7 @@ namespace PluginsConvention14.MyPlugin { try { - + // Получаем все продукты из базы данных var products = GetAllProducts(); @@ -192,7 +201,7 @@ namespace PluginsConvention14.MyPlugin new WinFormsLibrary1.Models.MergeCell("Product", new int[] {1, 2}) }; - var columns = new List + var columns = new List { new WinFormsLibrary1.Models.Column("Id", "Id", 10), new WinFormsLibrary1.Models.Column("Name", "Name", 20), @@ -200,23 +209,24 @@ namespace PluginsConvention14.MyPlugin new WinFormsLibrary1.Models.Column("DeliveryDate", "DeliveryDate", 20) }; - // Создаем компонент ComponentTable - var componentTable = new ComponentTable(); + // Создаем компонент ComponentTable + var componentTable = new ComponentTable(); - // Конвертируем продукты в представление для таблицы - var tableItems = ProductTableItem.ConvertProductsToTableItems(products); + // Конвертируем продукты в представление для таблицы + var tableItems = MainPluginConventionElement.ConvertProductsToTableItems(products); - // Создаем документ Excel - componentTable.CreateDocument(fileName, "Product Report", mergeCells, columns, tableItems); + // Создаем документ Excel + componentTable.CreateDocument(fileName, "Product Report", mergeCells, columns, tableItems); - // Уведомление об успешной загрузке - MessageBox.Show("Excel document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - }else + // Уведомление об успешной загрузке + MessageBox.Show("Excel document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else { MessageBox.Show("No products found in the database."); } - } - + } + catch (Exception) { return false; @@ -248,27 +258,27 @@ namespace PluginsConvention14.MyPlugin if (productCounts.Count > 0) { - // Создаем объект WordDiagramInfo - var diagramInfo = new WordDiagramInfo + // Создаем объект WordDiagramInfo + var diagramInfo = new WordDiagramInfo + { + FileName = fileName, + Title = "Product Count by Manufacturer", + ChartTitle = "Product Count", + LegendLocation = Library15Gerimovich.OfficePackage.HelperEnums.WordDiagramLegendLocation.Top, + Series = new WordDiagramSeries { - FileName = fileName, - Title = "Product Count by Manufacturer", - ChartTitle = "Product Count", - LegendLocation = Library15Gerimovich.OfficePackage.HelperEnums.WordDiagramLegendLocation.Top, - Series = new WordDiagramSeries - { - SeriesName = "Product Count", - Data = productCounts - } - }; + SeriesName = "Product Count", + Data = productCounts + } + }; var wordDiagramComponent = new WordDiagramComponent(); - // Создаем диаграмму в Word - wordDiagramComponent.CreateDiagram(diagramInfo); + // Создаем диаграмму в Word + wordDiagramComponent.CreateDiagram(diagramInfo); - // Уведомление об успешной загрузке - MessageBox.Show("Word document with chart created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); + // Уведомление об успешной загрузке + MessageBox.Show("Word document with chart created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { diff --git a/PluginsConvention14/MyPlugin/MainPluginsConventionElement.cs b/PluginsConvention14/MyPlugin/MainPluginsConventionElement.cs index e3ae721..39263c4 100644 --- a/PluginsConvention14/MyPlugin/MainPluginsConventionElement.cs +++ b/PluginsConvention14/MyPlugin/MainPluginsConventionElement.cs @@ -1,11 +1,5 @@ using Data.Models; using PluginsConventionLibrary.Plugins; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using View.ViewModels; namespace PluginsConvention14.MyPlugin { @@ -14,11 +8,11 @@ namespace PluginsConvention14.MyPlugin public string Name { get; set; } public string ManufacturerName { get; set; } public string DeliveryDate { get; set; } - public static List ConvertProductsToTableItems(List products) + public static List ConvertProductsToTableItems(List products) { - return products.Select(p => new ProductTableItem + return products.Select(p => new MainPluginConventionElement { - Id = p.Id.ToString(), + Id = p.Id, Name = p.Name, ManufacturerName = p.ManufacturerName, DeliveryDate = p.DeliveryDate.ToShortDateString() diff --git a/PluginsConvention14/Plugins/IPluginsConvention.cs b/PluginsConvention14/Plugins/IPluginsConvention.cs index 664ebc4..c055a6f 100644 --- a/PluginsConvention14/Plugins/IPluginsConvention.cs +++ b/PluginsConvention14/Plugins/IPluginsConvention.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PluginsConventionLibrary.Plugins +namespace PluginsConventionLibrary.Plugins { public interface IPluginsConvention { diff --git a/PluginsConvention14/Plugins/PluginsConventionElement.cs b/PluginsConvention14/Plugins/PluginsConventionElement.cs index 1dea201..99f7ef9 100644 --- a/PluginsConvention14/Plugins/PluginsConventionElement.cs +++ b/PluginsConvention14/Plugins/PluginsConventionElement.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PluginsConventionLibrary.Plugins +namespace PluginsConventionLibrary.Plugins { public class PluginsConventionElement { diff --git a/PluginsConvention14/Plugins/PluginsConventionSaveDocument.cs b/PluginsConvention14/Plugins/PluginsConventionSaveDocument.cs index 614962e..a0a7ce1 100644 --- a/PluginsConvention14/Plugins/PluginsConventionSaveDocument.cs +++ b/PluginsConvention14/Plugins/PluginsConventionSaveDocument.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PluginsConventionLibrary.Plugins +namespace PluginsConventionLibrary.Plugins { public class PluginsConventionSaveDocument { diff --git a/PluginsConvention14/PluginsConvention14.csproj b/PluginsConvention14/PluginsConvention14.csproj index 1cd0837..2c85b89 100644 --- a/PluginsConvention14/PluginsConvention14.csproj +++ b/PluginsConvention14/PluginsConvention14.csproj @@ -9,20 +9,17 @@ + - - - Form - Form diff --git a/PluginsConventionLibrary/Forms/MainForm.Designer.cs b/PluginsConventionLibrary/Forms/MainForm.Designer.cs deleted file mode 100644 index 30b9dc5..0000000 --- a/PluginsConventionLibrary/Forms/MainForm.Designer.cs +++ /dev/null @@ -1,178 +0,0 @@ -namespace Laba3 -{ - partial class MainForm - { - /// - /// 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(); - menuStrip1 = new MenuStrip(); - createToolStripMenuItem = new ToolStripMenuItem(); - updateToolStripMenuItem = new ToolStripMenuItem(); - deleteToolStripMenuItem = new ToolStripMenuItem(); - manufacturerToolStripMenuItem = new ToolStripMenuItem(); - documentsToolStripMenuItem = new ToolStripMenuItem(); - pdfImageToolStripMenuItem = new ToolStripMenuItem(); - exelTableToolStripMenuItem = new ToolStripMenuItem(); - wordGistToolStripMenuItem = new ToolStripMenuItem(); - outputTableResults = new Library15Gerimovich.OutputTableResults(); - pdfImg = new Library14Petrushin.PdfImg(components); - wordDiagramComponent = new Library15Gerimovich.WordDiagramComponent(components); - componentTable = new WinFormsLibrary1.ComponentTable(components); - saveFileDialogPdf = new SaveFileDialog(); - saveFileDialogWord = new SaveFileDialog(); - saveFileDialogExel = new SaveFileDialog(); - menuStrip1.SuspendLayout(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { createToolStripMenuItem, updateToolStripMenuItem, deleteToolStripMenuItem, manufacturerToolStripMenuItem, documentsToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(480, 28); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; - // - // createToolStripMenuItem - // - createToolStripMenuItem.Name = "createToolStripMenuItem"; - createToolStripMenuItem.Size = new Size(66, 24); - createToolStripMenuItem.Text = "Create"; - createToolStripMenuItem.Click += addToolStripMenuItem_Click; - // - // updateToolStripMenuItem - // - updateToolStripMenuItem.Name = "updateToolStripMenuItem"; - updateToolStripMenuItem.Size = new Size(72, 24); - updateToolStripMenuItem.Text = "Update"; - updateToolStripMenuItem.Click += editToolStripMenuItem_Click; - // - // deleteToolStripMenuItem - // - deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; - deleteToolStripMenuItem.Size = new Size(67, 24); - deleteToolStripMenuItem.Text = "Delete"; - deleteToolStripMenuItem.Click += deleteToolStripMenuItem_Click; - // - // manufacturerToolStripMenuItem - // - manufacturerToolStripMenuItem.Name = "manufacturerToolStripMenuItem"; - manufacturerToolStripMenuItem.Size = new Size(111, 24); - manufacturerToolStripMenuItem.Text = "Manufacturer"; - manufacturerToolStripMenuItem.Click += manufacturersToolStripMenuItem_Click; - // - // documentsToolStripMenuItem - // - documentsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pdfImageToolStripMenuItem, exelTableToolStripMenuItem, wordGistToolStripMenuItem }); - documentsToolStripMenuItem.Name = "documentsToolStripMenuItem"; - documentsToolStripMenuItem.Size = new Size(98, 24); - documentsToolStripMenuItem.Text = "Documents"; - // - // pdfImageToolStripMenuItem - // - pdfImageToolStripMenuItem.Name = "pdfImageToolStripMenuItem"; - pdfImageToolStripMenuItem.Size = new Size(159, 26); - pdfImageToolStripMenuItem.Text = "Pdf Image"; - pdfImageToolStripMenuItem.Click += createSimpleDocumentToolStripMenuItem_Click; - // - // exelTableToolStripMenuItem - // - exelTableToolStripMenuItem.Name = "exelTableToolStripMenuItem"; - exelTableToolStripMenuItem.Size = new Size(159, 26); - exelTableToolStripMenuItem.Text = "Exel table"; - exelTableToolStripMenuItem.Click += createCustomTableDocumentToolStripMenuItem_Click; - // - // wordGistToolStripMenuItem - // - wordGistToolStripMenuItem.Name = "wordGistToolStripMenuItem"; - wordGistToolStripMenuItem.Size = new Size(159, 26); - wordGistToolStripMenuItem.Text = "Word gist"; - wordGistToolStripMenuItem.Click += createChartDocumentToolStripMenuItem_Click; - // - // outputTableResults - // - outputTableResults.Location = new Point(12, 32); - outputTableResults.Margin = new Padding(3, 4, 3, 4); - outputTableResults.Name = "outputTableResults"; - outputTableResults.SelectedRow = -1; - outputTableResults.Size = new Size(467, 308); - outputTableResults.TabIndex = 1; - // - // saveFileDialogPdf - // - saveFileDialogPdf.FileName = "Products.pdf"; - saveFileDialogPdf.Filter = "PDF Files (*.pdf)|*.pdf"; - saveFileDialogPdf.Title = "Save PDF Document"; - // - // saveFileDialogWord - // - saveFileDialogWord.FileName = "Diagram.docx"; - saveFileDialogWord.Filter = "Word Files (*.docx)|*.docx"; - saveFileDialogWord.Title = "Save Word Document"; - // - // saveFileDialogExel - // - saveFileDialogExel.FileName = "ProductReport.xlsx"; - saveFileDialogExel.Filter = "Excel Files (*.xlsx)|*.xlsx"; - saveFileDialogExel.Title = "Save Excel Document"; - // - // MainForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(480, 351); - Controls.Add(outputTableResults); - Controls.Add(menuStrip1); - KeyPreview = true; - MainMenuStrip = menuStrip1; - Name = "MainForm"; - Text = "Form1"; - KeyDown += MainForm_KeyDown; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private MenuStrip menuStrip1; - private ToolStripMenuItem createToolStripMenuItem; - private ToolStripMenuItem updateToolStripMenuItem; - private Library15Gerimovich.OutputTableResults outputTableResults; - private ToolStripMenuItem deleteToolStripMenuItem; - private ToolStripMenuItem manufacturerToolStripMenuItem; - private ToolStripMenuItem documentsToolStripMenuItem; - private ToolStripMenuItem pdfImageToolStripMenuItem; - private ToolStripMenuItem exelTableToolStripMenuItem; - private ToolStripMenuItem wordGistToolStripMenuItem; - private Library14Petrushin.PdfImg pdfImg; - private Library15Gerimovich.WordDiagramComponent wordDiagramComponent; - private WinFormsLibrary1.ComponentTable componentTable; - } -} diff --git a/PluginsConventionLibrary/Forms/MainForm.cs b/PluginsConventionLibrary/Forms/MainForm.cs deleted file mode 100644 index c0e33f2..0000000 --- a/PluginsConventionLibrary/Forms/MainForm.cs +++ /dev/null @@ -1,284 +0,0 @@ -using Data; -using Data.Repositories; -using View; -using System.Windows.Forms; -using Data.Models; -using Library14Petrushin; -using Library15Gerimovich.OfficePackage.HelperModels; -using Library15Gerimovich; -using WinFormsLibrary1; -using WinFormsLibrary1.Models; -using View.ViewModels; - -namespace Laba3 -{ - public partial class MainForm : Form - { - private readonly IProductRepository _productRepository; - private readonly IManufacturerRepository _manufacturerRepository; - private SaveFileDialog saveFileDialogPdf; - private SaveFileDialog saveFileDialogWord; - private SaveFileDialog saveFileDialogExel; - - public MainForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository) - { - InitializeComponent(); - _productRepository = productRepository; - _manufacturerRepository = manufacturerRepository; - InitializeOutputTableResults(); - LoadProducts(); - } - - private void InitializeOutputTableResults() - { - outputTableResults.ConfigureColumns(new List - { - new ColumnInfo("", 0, false, "Id"), - new ColumnInfo("Name", 150, true, "Name"), - new ColumnInfo("ManufacturerNameManufacturerName", 150, true, "ManufacturerName"), - new ColumnInfo("DeliveryDate", 50, true, "DeliveryDate"), - }); - - } - - private void LoadProducts() - { - var products = _productRepository.GetAllProducts(); - outputTableResults.ClearGrid(); - foreach (var product in products) - { - outputTableResults.InsertValue(product); - } - } - - private void addToolStripMenuItem_Click(object sender, EventArgs e) - { - var productForm = new ProductForm(_productRepository, _manufacturerRepository); - if (productForm.ShowDialog() == DialogResult.OK) - { - LoadProducts(); - } - } - - private void editToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - var selectedProductId = outputTableResults.GetSelectedObject().Id; - var selectedProduct = _productRepository.GetProductById(selectedProductId); - var productForm = new ProductForm(_productRepository, _manufacturerRepository, selectedProduct); - if (productForm.ShowDialog() == DialogResult.OK) - { - LoadProducts(); - } - } - catch (Exception ex) { - MessageBox.Show(ex.ToString()); - } - } - - private void deleteToolStripMenuItem_Click(object sender, EventArgs e) - { - var selectedProductId = outputTableResults.GetSelectedObject().Id; - if (MessageBox.Show("Are you sure you want to delete this product?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - _productRepository.DeleteProduct(selectedProductId); - LoadProducts(); - } - } - - private void manufacturersToolStripMenuItem_Click(object sender, EventArgs e) - { - var manufacturerForm = new ManufacturerForm(_manufacturerRepository); - manufacturerForm.ShowDialog(); - } - - private void createSimpleDocumentToolStripMenuItem_Click(object sender, EventArgs e) - { - // Получаем изображения из базы данных - var images = GetImagesFromDatabase(); - - if (images.Count > 0) - { - // Показываем диалоговое окно для выбора пути сохранения - if (saveFileDialogPdf.ShowDialog() == DialogResult.OK) - { - // Создаем компонент PdfImg - var pdfImg = new Library14Petrushin.PdfImg(); - - // Путь для сохранения PDF-документа - string fileName = saveFileDialogPdf.FileName; - - // Заголовок документа - string documentTitle = "Product Images"; - - // Создаем PDF-документ - pdfImg.CreatePdfDocument(fileName, documentTitle, images); - - // Уведомление об успешной загрузке - MessageBox.Show("PDF document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - MessageBox.Show("No images found in the database."); - } - } - - private void createCustomTableDocumentToolStripMenuItem_Click(object sender, EventArgs e) - { - // Получаем все продукты из базы данных - var products = GetAllProducts(); - - if (products.Count > 0) - { - // Показываем диалоговое окно для выбора пути сохранения - if (saveFileDialogExel.ShowDialog() == DialogResult.OK) - { - // Создаем объекты MergeCell и Column - var mergeCells = new List - { - new MergeCell("Product", new int[] {1, 2}) - }; - - var columns = new List - { - new Column("Id", "Id", 10), - new Column("Name", "Name", 20), - new Column("ManufacturerName", "ManufacturerName", 20), - new Column("DeliveryDate", "DeliveryDate", 20) - }; - - // Создаем компонент ComponentTable - var componentTable = new ComponentTable(); - - // Конвертируем продукты в представление для таблицы - var tableItems = ProductTableItem.ConvertProductsToTableItems(products); - - // Создаем документ Excel - componentTable.CreateDocument(saveFileDialogExel.FileName, "Product Report", mergeCells, columns, tableItems); - - // Уведомление об успешной загрузке - MessageBox.Show("Excel document created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - MessageBox.Show("No products found in the database."); - } - } - - private void createChartDocumentToolStripMenuItem_Click(object sender, EventArgs e) - { - // Получаем данные о количестве продукции каждого производителя - var productCounts = GetProductCountsByManufacturer(); - - if (productCounts.Count > 0) - { - // Показываем диалоговое окно для выбора пути сохранения - if (saveFileDialogWord.ShowDialog() == DialogResult.OK) - { - // Создаем объект WordDiagramInfo - var diagramInfo = new WordDiagramInfo - { - FileName = saveFileDialogWord.FileName, - Title = "Product Count by Manufacturer", - ChartTitle = "Product Count", - LegendLocation = Library15Gerimovich.OfficePackage.HelperEnums.WordDiagramLegendLocation.Top, - Series = new WordDiagramSeries - { - SeriesName = "Product Count", - Data = productCounts - } - }; - - // Создаем диаграмму в Word - wordDiagramComponent.CreateDiagram(diagramInfo); - - // Уведомление об успешной загрузке - MessageBox.Show("Word document with chart created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - MessageBox.Show("No products found in the database."); - } - } - - // бизнес логика - - private void MainForm_KeyDown(object sender, KeyEventArgs e) - { - if (e.Control) - { - switch (e.KeyCode) - { - case Keys.A: - addToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.U: - editToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.D: - deleteToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.S: - createSimpleDocumentToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.T: - createCustomTableDocumentToolStripMenuItem_Click(null, EventArgs.Empty); - break; - case Keys.C: - createChartDocumentToolStripMenuItem_Click(null, EventArgs.Empty); - break; - } - } - } - - private List GetImagesFromDatabase() - { - var images = new List(); - var products = _productRepository.GetAllProducts(); - - foreach (var product in products) - { - if (product.Image != null) - { - // Создаем временный файл для сохранения изображения - string tempFilePath = Path.GetTempFileName(); - File.WriteAllBytes(tempFilePath, product.Image); - - // Добавляем путь к временному файлу в список - images.Add(new ImageData { ImagePath = tempFilePath }); - } - } - - return images; - } - - private Dictionary GetProductCountsByManufacturer() - { - var productCounts = new Dictionary(); - var products = _productRepository.GetAllProducts(); - - foreach (var product in products) - { - if (productCounts.ContainsKey(product.ManufacturerName)) - { - productCounts[product.ManufacturerName]++; - } - else - { - productCounts[product.ManufacturerName] = 1; - } - } - - return productCounts; - } - - private List GetAllProducts() - { - return _productRepository.GetAllProducts().ToList(); - } - } -} diff --git a/PluginsConventionLibrary/Forms/MainForm.resx b/PluginsConventionLibrary/Forms/MainForm.resx deleted file mode 100644 index 6ce8bc4..0000000 --- a/PluginsConventionLibrary/Forms/MainForm.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - 572, 17 - - - 708, 17 - - - 813, 17 - - - 1039, 17 - - - 17, 17 - - - 195, 17 - - - 388, 17 - - \ No newline at end of file diff --git a/PluginsConventionLibrary/Forms/ManufacturerForm.Designer.cs b/PluginsConventionLibrary/Forms/ManufacturerForm.Designer.cs deleted file mode 100644 index 89fec90..0000000 --- a/PluginsConventionLibrary/Forms/ManufacturerForm.Designer.cs +++ /dev/null @@ -1,64 +0,0 @@ -namespace View -{ - partial class ManufacturerForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - dataGridView = new DataGridView(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 12); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.Size = new Size(711, 426); - dataGridView.TabIndex = 0; - dataGridView.CellValueChanged += dataGridView_CellValueChanged; - dataGridView.UserAddedRow += dataGridView_UserAddedRow; - dataGridView.UserDeletingRow += dataGridView_UserDeletingRow; - dataGridView.KeyDown += dataGridView_KeyDown; - // - // ManufacturerForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(731, 450); - Controls.Add(dataGridView); - Name = "ManufacturerForm"; - Text = "ManufacturerForm"; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - } - - #endregion - - private DataGridView dataGridView; - } -} \ No newline at end of file diff --git a/PluginsConventionLibrary/Forms/ManufacturerForm.cs b/PluginsConventionLibrary/Forms/ManufacturerForm.cs deleted file mode 100644 index 23638fb..0000000 --- a/PluginsConventionLibrary/Forms/ManufacturerForm.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Data.Models; -using Data.Repositories; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace View -{ - public partial class ManufacturerForm : Form - { - private readonly IManufacturerRepository _manufacturerRepository; - - public ManufacturerForm(IManufacturerRepository manufacturerRepository) - { - InitializeComponent(); - _manufacturerRepository = manufacturerRepository; - LoadManufacturers(); - } - - private void LoadManufacturers() - { - var manufacturers = _manufacturerRepository.GetAllManufacturers().ToList(); - dataGridView.DataSource = manufacturers; - } - - private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) - { - if (e.RowIndex >= 0) - { - var manufacturer = dataGridView.Rows[e.RowIndex].DataBoundItem as Manufacturer; - if (manufacturer != null) - { - _manufacturerRepository.UpdateManufacturer(manufacturer); - } - } - } - - private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) - { - var manufacturer = e.Row.DataBoundItem as Manufacturer; - if (manufacturer != null) - { - if (MessageBox.Show("Are you sure you want to delete this manufacturer?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - _manufacturerRepository.DeleteManufacturer(manufacturer.Id); - } - else - { - e.Cancel = true; - } - } - } - - private void dataGridView_UserAddedRow(object sender, DataGridViewRowEventArgs e) - { - var manufacturer = new Manufacturer { Name = "" }; - _manufacturerRepository.AddManufacturer(manufacturer); - LoadManufacturers(); - } - - - // реализация через нажатие клавишь - - private void dataGridView_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Insert) - { - var manufacturer = new Manufacturer { Name = "" }; - _manufacturerRepository.AddManufacturer(manufacturer); - LoadManufacturers(); - } - else if (e.KeyCode == Keys.Delete) - { - if (dataGridView.SelectedRows.Count > 0) - { - var selectedManufacturer = dataGridView.SelectedRows[0].DataBoundItem as Manufacturer; - if (selectedManufacturer != null) - { - if (MessageBox.Show("Are you sure you want to delete this manufacturer?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - _manufacturerRepository.DeleteManufacturer(selectedManufacturer.Id); - LoadManufacturers(); - } - } - } - } - } - } -} diff --git a/PluginsConventionLibrary/Forms/ManufacturerForm.resx b/PluginsConventionLibrary/Forms/ManufacturerForm.resx deleted file mode 100644 index af32865..0000000 --- a/PluginsConventionLibrary/Forms/ManufacturerForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/PluginsConventionLibrary/Forms/ProductForm.Designer.cs b/PluginsConventionLibrary/Forms/ProductForm.Designer.cs deleted file mode 100644 index c64b5a8..0000000 --- a/PluginsConventionLibrary/Forms/ProductForm.Designer.cs +++ /dev/null @@ -1,121 +0,0 @@ -namespace Laba3 -{ - partial class ProductForm - { - /// - /// 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() - { - dtpDeliveryDate = new WinFormsLibrary1.DateInputControl(); - cmbManufacturer = new WinFormsLibrary1.ComboBoxUserControl(); - txtName = new Library14Petrushin.TextBoxRange(); - pbImage = new PictureBox(); - button1 = new Button(); - button2 = new Button(); - ((System.ComponentModel.ISupportInitialize)pbImage).BeginInit(); - SuspendLayout(); - // - // dtpDeliveryDate - // - dtpDeliveryDate.DateFormat = null; - dtpDeliveryDate.Location = new Point(13, 137); - dtpDeliveryDate.Margin = new Padding(4, 5, 4, 5); - dtpDeliveryDate.Name = "dtpDeliveryDate"; - dtpDeliveryDate.Size = new Size(186, 110); - dtpDeliveryDate.TabIndex = 0; - // - // cmbManufacturer - // - cmbManufacturer.Location = new Point(12, 218); - cmbManufacturer.Margin = new Padding(4, 5, 4, 5); - cmbManufacturer.Name = "cmbManufacturer"; - cmbManufacturer.SelectedValue = ""; - cmbManufacturer.Size = new Size(201, 40); - cmbManufacturer.TabIndex = 1; - // - // txtName - // - txtName.Location = new Point(12, 12); - txtName.MaxLength = null; - txtName.MinLength = null; - txtName.Name = "txtName"; - txtName.Size = new Size(315, 108); - txtName.TabIndex = 2; - // - // pbImage - // - pbImage.Location = new Point(320, 32); - pbImage.Name = "pbImage"; - pbImage.Size = new Size(451, 344); - pbImage.TabIndex = 3; - pbImage.TabStop = false; - // - // button1 - // - button1.Location = new Point(320, 399); - button1.Name = "button1"; - button1.Size = new Size(110, 29); - button1.TabIndex = 4; - button1.Text = "Choose img"; - button1.UseVisualStyleBackColor = true; - button1.Click += btnBrowse_Click; - // - // button2 - // - button2.Location = new Point(12, 326); - button2.Name = "button2"; - button2.Size = new Size(94, 29); - button2.TabIndex = 5; - button2.Text = "Save"; - button2.UseVisualStyleBackColor = true; - button2.Click += btnSave_Click; - // - // ProductForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(button2); - Controls.Add(button1); - Controls.Add(pbImage); - Controls.Add(txtName); - Controls.Add(cmbManufacturer); - Controls.Add(dtpDeliveryDate); - Name = "ProductForm"; - Text = "ProductForm"; - ((System.ComponentModel.ISupportInitialize)pbImage).EndInit(); - ResumeLayout(false); - } - - #endregion - - private WinFormsLibrary1.DateInputControl dtpDeliveryDate; - private WinFormsLibrary1.ComboBoxUserControl cmbManufacturer; - private Library14Petrushin.TextBoxRange txtName; - private PictureBox pbImage; - private Button button1; - private Button button2; - } -} \ No newline at end of file diff --git a/PluginsConventionLibrary/Forms/ProductForm.cs b/PluginsConventionLibrary/Forms/ProductForm.cs deleted file mode 100644 index 3e88d28..0000000 --- a/PluginsConventionLibrary/Forms/ProductForm.cs +++ /dev/null @@ -1,116 +0,0 @@ -using Data; -using Data.Models; -using Data.Repositories; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Laba3 -{ - public partial class ProductForm : Form - { - private readonly IProductRepository _productRepository; - private readonly IManufacturerRepository _manufacturerRepository; - private Product _product; - private bool _isNewProduct; - private const int MINL = 3; - private const int MAXL= 10; - - public ProductForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository, Product product = null) - { - InitializeComponent(); - Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; - - _productRepository = productRepository; - _manufacturerRepository = manufacturerRepository; - - - var manufacturers = _manufacturerRepository.GetAllManufacturers().Select(m => m.Name).ToList(); - // cmbManufacturer.Data = manufacturers; - foreach (var manufacturer in manufacturers) - { - cmbManufacturer.AddItem(manufacturer); - } - - _product = product; - _isNewProduct = product == null; - txtName.MinLength = MINL; - txtName.MaxLength = MAXL; - dtpDeliveryDate.DateFormat = "dd MMMM yyyy"; - - if (!_isNewProduct) - { - txtName.InputValue = _product.Name; - cmbManufacturer.SelectedValue = _product.ManufacturerName; - dtpDeliveryDate.Date = _product.DeliveryDate; - - if (_product.Image != null) - { - using (var ms = new MemoryStream(_product.Image)) - { - pbImage.Image = Image.FromStream(ms); - } - } - } - } - - private void btnBrowse_Click(object sender, EventArgs e) - { - using (var openFileDialog = new OpenFileDialog()) - { - openFileDialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp"; - if (openFileDialog.ShowDialog() == DialogResult.OK) - { - pbImage.Image = Image.FromFile(openFileDialog.FileName); - } - } - } - - private void btnSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(txtName.InputValue)) - { - MessageBox.Show("Name is required."); - return; - } - - if (_isNewProduct) - { - _product = new Product(); - } - - _product.Name = txtName.InputValue; - _product.ManufacturerName = cmbManufacturer.SelectedValue.ToString(); - _product.DeliveryDate = dtpDeliveryDate.Date; - - if (pbImage.Image != null) - { - using (var ms = new MemoryStream()) - { - pbImage.Image.Save(ms, pbImage.Image.RawFormat); - _product.Image = ms.ToArray(); - } - } - - if (_isNewProduct) - { - _productRepository.AddProduct(_product); - } - else - { - _productRepository.UpdateProduct(_product); - } - - - DialogResult = DialogResult.OK; - Close(); - } - } -} diff --git a/PluginsConventionLibrary/Forms/ProductForm.resx b/PluginsConventionLibrary/Forms/ProductForm.resx deleted file mode 100644 index af32865..0000000 --- a/PluginsConventionLibrary/Forms/ProductForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/PluginsConventionLibrary/Plugins/IPluginsConvention.cs b/PluginsConventionLibrary/Plugins/IPluginsConvention.cs deleted file mode 100644 index 664ebc4..0000000 --- a/PluginsConventionLibrary/Plugins/IPluginsConvention.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -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 CreateWord(PluginsConventionSaveDocument saveDocument); - - /// - /// Создание простого документа - /// - /// - /// - bool CreateExcel(PluginsConventionSaveDocument saveDocument); - - /// - /// Создание документа с диаграммой - /// - /// - /// - bool CreatePdf(PluginsConventionSaveDocument saveDocument); - } -} diff --git a/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs b/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs deleted file mode 100644 index 1dea201..0000000 --- a/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PluginsConventionLibrary.Plugins -{ - public class PluginsConventionElement - { - public int Id { get; set; } - } -} diff --git a/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs b/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs deleted file mode 100644 index 614962e..0000000 --- a/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PluginsConventionLibrary.Plugins -{ - public class PluginsConventionSaveDocument - { - public string FileName { get; set; } - } -} diff --git a/PluginsConventionLibrary/PluginsConventionLibrary.csproj b/PluginsConventionLibrary/PluginsConventionLibrary.csproj deleted file mode 100644 index 5fe0d97..0000000 --- a/PluginsConventionLibrary/PluginsConventionLibrary.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - - - - - - - - Form - - - Form - - - Form - - - -