From e37edd505a77684c07e4174fdd559ebc104f250b Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Fri, 27 Oct 2023 20:29:38 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D1=803=20=D0=BF=D0=BE=D1=85=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COP/VisualCompLib/MyDropDownList.Designer.cs | 3 +- COP/WinForms/FormClient.Designer.cs | 6 +- COP/WinForms/FormMain.Designer.cs | 4 ++ COP/WinForms/FormMain.cs | 76 +++++++++++++++++++- COP/WinForms/FormMain.resx | 6 ++ 5 files changed, 90 insertions(+), 5 deletions(-) diff --git a/COP/VisualCompLib/MyDropDownList.Designer.cs b/COP/VisualCompLib/MyDropDownList.Designer.cs index d8d1e79..1bc644a 100644 --- a/COP/VisualCompLib/MyDropDownList.Designer.cs +++ b/COP/VisualCompLib/MyDropDownList.Designer.cs @@ -46,7 +46,8 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + AutoSize = true; + AutoSizeMode = AutoSizeMode.GrowAndShrink; Controls.Add(dropDownList); Margin = new Padding(3, 4, 3, 4); Name = "MyDropDownList"; diff --git a/COP/WinForms/FormClient.Designer.cs b/COP/WinForms/FormClient.Designer.cs index b6f2394..116fff7 100644 --- a/COP/WinForms/FormClient.Designer.cs +++ b/COP/WinForms/FormClient.Designer.cs @@ -1,4 +1,6 @@ -namespace WinForms +using ControlsLibraryNet60.Input; + +namespace WinForms { partial class FormClient { @@ -124,6 +126,7 @@ // // controlInputNullableInt1 // + controlInputNullableInt1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; controlInputNullableInt1.Location = new Point(14, 240); controlInputNullableInt1.Margin = new Padding(5, 8, 5, 8); controlInputNullableInt1.Name = "controlInputNullableInt1"; @@ -133,6 +136,7 @@ // // myDropDownList1 // + myDropDownList1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; myDropDownList1.Location = new Point(12, 105); myDropDownList1.Margin = new Padding(3, 4, 3, 4); myDropDownList1.Name = "myDropDownList1"; diff --git a/COP/WinForms/FormMain.Designer.cs b/COP/WinForms/FormMain.Designer.cs index d36bf14..c1b7dc0 100644 --- a/COP/WinForms/FormMain.Designer.cs +++ b/COP/WinForms/FormMain.Designer.cs @@ -39,6 +39,8 @@ статусыToolStripMenuItem = new ToolStripMenuItem(); myTreeView1 = new VisableComponents.MyTreeView(); wordText1 = new VisualCompLib.Components.WordText(components); + excelChart1 = new UnvisableComponents.ExcelChart(components); + componentDocumentWithTableMultiHeaderPdf1 = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderPdf(components); contextMenuStrip1.SuspendLayout(); SuspendLayout(); // @@ -140,5 +142,7 @@ private ToolStripMenuItem статусыToolStripMenuItem; private VisableComponents.MyTreeView myTreeView1; private VisualCompLib.Components.WordText wordText1; + private UnvisableComponents.ExcelChart excelChart1; + private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderPdf componentDocumentWithTableMultiHeaderPdf1; } } \ No newline at end of file diff --git a/COP/WinForms/FormMain.cs b/COP/WinForms/FormMain.cs index f432039..5bb70d3 100644 --- a/COP/WinForms/FormMain.cs +++ b/COP/WinForms/FormMain.cs @@ -3,6 +3,8 @@ using ClientsContracts.BusinessLogicContracts; using ClientsContracts.ViewModels; using ClientsContracts.BindingModels; using ControlsLibraryNet60.Data; +using ComponentsLibraryNet60.Models; +using UnvisableComponents; using Unity; using DocumentFormat.OpenXml.Spreadsheet; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; @@ -107,7 +109,7 @@ namespace WinForms { foreach (var item in list) { - if(item.Amount != null) + if (item.Amount != null) { string clients = string.Concat("ФИО: ", item.Name, " Отзывы: ", item.Reviews); textList.Add(clients); @@ -118,6 +120,74 @@ namespace WinForms } } + private void createExcel() + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + var statuses = _statusLogic.Read(null); + var clients = _clientLogic.Read(null); + List<(string, int)> dates = new List<(string, int)>(); + for (int i = 0; i < statuses.Count; i++) + { + int counter = 0; + for(int j = 0; j < clients.Count; j++) + { + if (clients[j].Status == statuses[i].Name && clients[j].Amount != null) counter++; + } + dates.Add((statuses[i].Name, counter)); + } + excelChart1.Load(new ChartInfo + { + Path = fileName, + Title = "Сколько клиентов какого статуса совершали покупки", + DiagrammTitle = "Круговая диаграмма", + Dates = dates, + DirLegend = DirectionLegend.Right + }); + } + + private void CreatePdf() + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + var clients = _clientLogic.Read(null); + for (int i = 0; i < clients.Count; i++) + { + if (clients[i].Amount == null) { clients[i].Amount = 0; } + } + componentDocumentWithTableMultiHeaderPdf1.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig + { + FilePath = fileName, + Header = "Отчет по клиентам", + ColumnsRowsWidth = new List<(int, int)> { (5, 5), (10, 5), (15, 0), (15, 0) }, + Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> + { + (0, 0, "Id", "Id"), + (1, 0, "ФИО", "Name"), + (2, 0, "Статус", "Status"), + (3, 0, "Сумма покупок", "Amount") + }, + Data = clients + }); + } + private void статусыToolStripMenuItem_Click(object sender, EventArgs e) { var form = Program.Container.Resolve(); @@ -126,12 +196,12 @@ namespace WinForms private void сохранитьВПдфToolStripMenuItem_Click(object sender, EventArgs e) { - throw new NotImplementedException(); + CreatePdf(); } private void сохранитьВЭксельToolStripMenuItem_Click(object sender, EventArgs e) { - throw new NotImplementedException(); + createExcel(); } private void сохранитьВВордToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/COP/WinForms/FormMain.resx b/COP/WinForms/FormMain.resx index c8cc348..4e5788e 100644 --- a/COP/WinForms/FormMain.resx +++ b/COP/WinForms/FormMain.resx @@ -123,4 +123,10 @@ 202, 17 + + 327, 17 + + + 460, 17 + \ No newline at end of file