From 3ea68ad50d92e14fdcd9db8ac5cf649c94cfb085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Wed, 20 Nov 2024 16:45:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=81=D0=B5=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0,=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20?= =?UTF-8?q?=D1=81=D0=B4=D0=B0=D1=82=D1=8C=20=D0=BE=D1=81=D1=82=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormMain.Designer.cs | 11 + .../AppShopInternetOption19/Forms/FormMain.cs | 299 ++++++++++++++++-- .../Forms/FormMain.resx | 9 + 3 files changed, 289 insertions(+), 30 deletions(-) diff --git a/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.Designer.cs b/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.Designer.cs index 4fe4c0c..aec1749 100644 --- a/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.Designer.cs +++ b/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + components = new System.ComponentModel.Container(); userControlTreeView = new Components.UserControlTreeView(); menuStrip1 = new MenuStrip(); добавитьToolStripMenuItem = new ToolStripMenuItem(); @@ -37,6 +38,9 @@ сОзданиеДоктаСТаблицейToolStripMenuItem = new ToolStripMenuItem(); созданиеДоктаСДиаграммойToolStripMenuItem = new ToolStripMenuItem(); справочникToolStripMenuItem = new ToolStripMenuItem(); + createWord = new UserComponentsOption19.BigTextWordNoVisibleComponent(components); + createExcelPieDiagram = new Components.ComponentExcelWithPieDiagram(components); + createPdfTable = new WinFormsLibrary1.PDFTable(components); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -88,18 +92,21 @@ созданиеПростогоДокументаToolStripMenuItem.Name = "созданиеПростогоДокументаToolStripMenuItem"; созданиеПростогоДокументаToolStripMenuItem.Size = new Size(235, 24); созданиеПростогоДокументаToolStripMenuItem.Text = "Создание простого документа"; + созданиеПростогоДокументаToolStripMenuItem.Click += созданиеПростогоДокументаToolStripMenuItem_Click; // // сОзданиеДоктаСТаблицейToolStripMenuItem // сОзданиеДоктаСТаблицейToolStripMenuItem.Name = "сОзданиеДоктаСТаблицейToolStripMenuItem"; сОзданиеДоктаСТаблицейToolStripMenuItem.Size = new Size(219, 24); сОзданиеДоктаСТаблицейToolStripMenuItem.Text = "Создание док-та с таблицей"; + сОзданиеДоктаСТаблицейToolStripMenuItem.Click += сОзданиеДоктаСТаблицейToolStripMenuItem_Click; // // созданиеДоктаСДиаграммойToolStripMenuItem // созданиеДоктаСДиаграммойToolStripMenuItem.Name = "созданиеДоктаСДиаграммойToolStripMenuItem"; созданиеДоктаСДиаграммойToolStripMenuItem.Size = new Size(241, 24); созданиеДоктаСДиаграммойToolStripMenuItem.Text = "Создание док-та с диаграммой"; + созданиеДоктаСДиаграммойToolStripMenuItem.Click += созданиеДоктаСДиаграммойToolStripMenuItem_Click; // // справочникToolStripMenuItem // @@ -119,6 +126,7 @@ Name = "FormMain"; Text = "Главная форма"; Load += FormMain_Load; + KeyDown += FormMain_KeyDown; menuStrip1.ResumeLayout(false); menuStrip1.PerformLayout(); ResumeLayout(false); @@ -136,5 +144,8 @@ private ToolStripMenuItem сОзданиеДоктаСТаблицейToolStripMenuItem; private ToolStripMenuItem созданиеДоктаСДиаграммойToolStripMenuItem; private ToolStripMenuItem справочникToolStripMenuItem; + private UserComponentsOption19.BigTextWordNoVisibleComponent createWord; + private Components.ComponentExcelWithPieDiagram createExcelPieDiagram; + private WinFormsLibrary1.PDFTable createPdfTable; } } diff --git a/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.cs b/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.cs index b9ebfb1..5d205e7 100644 --- a/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.cs +++ b/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.cs @@ -1,8 +1,13 @@ using AppShopInternetOption19.Forms; +using Components; using ShopContracts.BindingModels; using ShopContracts.BusinessLogicContracts; using ShopContracts.SearchModels; using ShopDataBaseImplements.Models; +using System.Windows.Forms; +using UserComponentsOption19; +using WinFormsLibrary1; +using WinFormsLibrary1.HelperClasses; namespace AppShopInternetOption19 { @@ -17,17 +22,8 @@ namespace AppShopInternetOption19 InitializeComponent(); _orderLogic = orderLogic; _orderStatusLogic = orderStatusLogic; + this.KeyPreview = true; LoadData(); - - //OrderBindingModel order = new OrderBindingModel - //{ - // FIO = " ", - // OrderDescription = "Description", - // OrderStatus = " ", - // OrderSumm = "20", - //}; - //_orderLogic.Create(order); - } private void FormMain_Load(object sender, EventArgs e) @@ -37,16 +33,7 @@ namespace AppShopInternetOption19 private void ToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormEdit_Add)); - if (!(service is FormEdit_Add form)) - { - return; - } - - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + Add(); } private void LoadData() @@ -79,6 +66,43 @@ namespace AppShopInternetOption19 } private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + Update(); + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + Delete(); + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormGuide)); + if (!(service is FormGuide form)) + { + return; + } + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void Add() + { + var service = Program.ServiceProvider?.GetService(typeof(FormEdit_Add)); + if (!(service is FormEdit_Add form)) + { + return; + } + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void Update() { var service = Program.ServiceProvider?.GetService(typeof(FormEdit_Add)); if (!(service is FormEdit_Add form)) @@ -94,7 +118,7 @@ namespace AppShopInternetOption19 } } - private void ToolStripMenuItem_Click(object sender, EventArgs e) + private void Delete() { try { @@ -123,24 +147,239 @@ namespace AppShopInternetOption19 } LoadData(); } - catch (Exception) + catch (Exception ex) { - - throw; + MessageBox.Show(ex.Message); } } - private void ToolStripMenuItem_Click(object sender, EventArgs e) + private void CreateWord() { - var service = Program.ServiceProvider?.GetService(typeof(FormGuide)); - if (!(service is FormGuide form)) + using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { - return; + saveFileDialog.Filter = "Word Documents (*.docx)|*.docx"; + + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + string filePath = saveFileDialog.FileName; + + string title = ", :D"; + + string[] data; + + try + { + var orders = _orderLogic.ReadList(null); + + if (orders != null) + { + // , null + var freeOrders = orders + .Where(x => string.IsNullOrEmpty(x.OrderSumm)) + .Select(x => $"ID: {x.Id}, : {x.FIO}, : {x.OrderStatus}, : {x.OrderDescription}") + .ToList(); + + if (freeOrders.Count == 0) + { + MessageBox.Show(" , ."); + return; + } + + // + data = freeOrders.ToArray(); + + // Word + createWord.CreateAndSaveDocument(filePath, title, data); + MessageBox.Show(" :D ..."); + + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } } - if (form.ShowDialog() == DialogResult.OK) + } + + private void CreateExcel() + { + using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { - LoadData(); + saveFileDialog.Filter = "Excel Files (*.xlsx)|*.xlsx"; + saveFileDialog.Title = " Excel"; + + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + string filePath = saveFileDialog.FileName; + + try + { + var orders = _orderLogic.ReadList(null); + + if (orders == null || !orders.Any()) + { + MessageBox.Show(" ."); + return; + } + + var groupedData = orders + .Where(o => o.OrderSumm != null && o.OrderSumm != "" && o.OrderSumm != string.Empty) + .GroupBy(o => o.OrderStatus) + .Select(g => new ComponentExcelWithPieDiagram.ChartData + { + SeriesName = g.Key, + SeriesValue = g.Count() + }) + .ToList(); + + if (!groupedData.Any()) + { + MessageBox.Show(" ."); + return; + } + + string title = " "; + string diagramTitle = " "; + + createExcelPieDiagram.CreateExcelWithPieChart( + filePath, + title, + diagramTitle, + ComponentExcelWithPieDiagram.LegendPosition.Left, + groupedData + ); + + MessageBox.Show(" .", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show($" : {ex.Message}", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } + + private void CreatePdf() + { + using (SaveFileDialog fileDialog = new SaveFileDialog()) + { + fileDialog.Filter = "PDF Files (*.pdf)|*.pdf"; + fileDialog.Title = " PDF"; + + if (fileDialog.ShowDialog() == DialogResult.OK) + { + string filePath = fileDialog.FileName; + string fileTitle = " "; + + try + { + var orders = _orderLogic.ReadList(null); + + if (orders == null || !orders.Any()) + { + MessageBox.Show(" "); + return; + } + + List tables = new List(); + string[,] tableData = new string[orders.Count + 1, 5]; + + // + tableData[0, 0] = ""; + tableData[0, 1] = ""; + tableData[0, 2] = " "; + tableData[0, 3] = " "; + tableData[0, 4] = ""; + + for (int i = 0; i < orders.Count; i++) + { + var order = orders[i]; + tableData[i + 1, 0] = order.Id.ToString(); + tableData[i + 1, 1] = order.FIO; + tableData[i + 1, 2] = order.OrderStatus; + tableData[i + 1, 3] = string.IsNullOrWhiteSpace(order.OrderSumm) + ? " " + : order.OrderSumm; + tableData[i + 1, 4] = order.OrderDescription; + } + tables.Add(tableData); + + PdfDocumentData pdfData = new PdfDocumentData(filePath, fileTitle, tables); + createPdfTable.GeneratePdf(pdfData); + MessageBox.Show(" .", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show($" : {ex.Message}", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + //private class PdfDocumentData + //{ + // public string FileName { get; set; } + + // public string DocumentTitle { get; set; } + + // public List Tables { get; set; } + + // public PdfDocumentData(string fileName, string documentTitle, List tables) + // { + // FileName = fileName ?? throw new ArgumentNullException("fileName"); + // DocumentTitle = documentTitle ?? throw new ArgumentNullException("documentTitle"); + // Tables = tables ?? throw new ArgumentNullException("tables"); + // } + //} + + private void FormMain_KeyDown(object sender, KeyEventArgs e) + { + if (e.Control) + { + switch (e.KeyCode) + { + case Keys.A: + Add(); + e.SuppressKeyPress = true; + break; + case Keys.U: + Update(); + e.SuppressKeyPress = true; + break; + case Keys.D: + Delete(); + e.SuppressKeyPress = true; + break; + case Keys.S: + CreateWord(); + e.SuppressKeyPress = true; + break; + case Keys.C: + CreateExcel(); + e.SuppressKeyPress = true; + break; + case Keys.T: + CreatePdf(); + e.SuppressKeyPress = true; + break; + } + } + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateWord(); + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + CreatePdf(); + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateExcel(); + } } } diff --git a/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.resx b/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.resx index a0623c8..7f43f88 100644 --- a/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.resx +++ b/UserComponentsOption19/AppShopInternetOption19/Forms/FormMain.resx @@ -120,4 +120,13 @@ 17, 17 + + 153, 17 + + + 444, 17 + + + 727, 17 + \ No newline at end of file