diff --git a/Publication/Entites/PrintingHouses.cs b/Publication/Entites/PrintingHouses.cs index cfb1d8b..bccce91 100644 --- a/Publication/Entites/PrintingHouses.cs +++ b/Publication/Entites/PrintingHouses.cs @@ -1,4 +1,7 @@ -namespace Publication.Entites; +using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing; +using Unity; + +namespace Publication.Entites; public class PrintingHouses { @@ -13,7 +16,7 @@ public class PrintingHouses public IEnumerable printingHouseOrder { get; set; } = []; - public static PrintingHouses CreateEntity(int id, string title, string phone, string address,int materialsId,IEnumerable printingHouseOrders) + public static PrintingHouses CreateEntity(int id, string title, string phone, string address,int materialsId, IEnumerable printingHouseOrders) { return new PrintingHouses @@ -23,7 +26,22 @@ public class PrintingHouses Phone = phone, Address = address, MaterialsId=materialsId, + Date = DateTime.Now, printingHouseOrder = printingHouseOrders }; } + + public static PrintingHouses CreateEntity(TempPrintingHouseOrders tempPrintingHouseOrders, IEnumerable _printingHouseOrders) + { + return new PrintingHouses + { + Id = tempPrintingHouseOrders.Id, + Title = tempPrintingHouseOrders.Title, + Phone = tempPrintingHouseOrders.Phone, + Address = tempPrintingHouseOrders.Address, + MaterialsId = tempPrintingHouseOrders.MaterialsId, + Date = tempPrintingHouseOrders.Date, + printingHouseOrder = _printingHouseOrders + }; + } } diff --git a/Publication/Entites/TempPrintingHouseOrders.cs b/Publication/Entites/TempPrintingHouseOrders.cs new file mode 100644 index 0000000..0e58ac8 --- /dev/null +++ b/Publication/Entites/TempPrintingHouseOrders.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Publication.Entites; + +public class TempPrintingHouseOrders +{ + public int Id { get; set; } + public string Title { get; set; } + public string Phone { get; set; } + public string Address { get; set; } + + public int MaterialsId { get; set; } + + public DateTime Date { get; set; } + + public int OrderId { get; set; } + public int Count { get; set; } +} diff --git a/Publication/Forms/FormCountReport.Designer.cs b/Publication/Forms/FormCountReport.Designer.cs index ff36846..40707cd 100644 --- a/Publication/Forms/FormCountReport.Designer.cs +++ b/Publication/Forms/FormCountReport.Designer.cs @@ -29,14 +29,12 @@ private void InitializeComponent() { label1 = new Label(); - label2 = new Label(); label3 = new Label(); label4 = new Label(); textBoxFilePath = new TextBox(); dateTimePickerStartDate = new DateTimePicker(); dateTimePickerEndDate = new DateTimePicker(); buttonSelectFilePath = new Button(); - comboBoxProducts = new ComboBox(); buttonMakeReport = new Button(); SuspendLayout(); // @@ -49,19 +47,10 @@ label1.TabIndex = 0; label1.Text = "Путь до файла:"; // - // label2 - // - label2.AutoSize = true; - label2.Location = new Point(22, 72); - label2.Name = "label2"; - label2.Size = new Size(69, 20); - label2.TabIndex = 1; - label2.Text = "Продукт:"; - // // label3 // label3.AutoSize = true; - label3.Location = new Point(22, 127); + label3.Location = new Point(22, 79); label3.Name = "label3"; label3.Size = new Size(97, 20); label3.TabIndex = 2; @@ -70,7 +59,7 @@ // label4 // label4.AutoSize = true; - label4.Location = new Point(22, 178); + label4.Location = new Point(22, 130); label4.Name = "label4"; label4.Size = new Size(90, 20); label4.TabIndex = 3; @@ -86,14 +75,14 @@ // // dateTimePickerStartDate // - dateTimePickerStartDate.Location = new Point(188, 127); + dateTimePickerStartDate.Location = new Point(188, 79); dateTimePickerStartDate.Name = "dateTimePickerStartDate"; dateTimePickerStartDate.Size = new Size(181, 27); dateTimePickerStartDate.TabIndex = 5; // // dateTimePickerEndDate // - dateTimePickerEndDate.Location = new Point(188, 173); + dateTimePickerEndDate.Location = new Point(188, 125); dateTimePickerEndDate.Name = "dateTimePickerEndDate"; dateTimePickerEndDate.Size = new Size(181, 27); dateTimePickerEndDate.TabIndex = 6; @@ -107,42 +96,34 @@ buttonSelectFilePath.TabIndex = 7; buttonSelectFilePath.Text = ".."; buttonSelectFilePath.UseVisualStyleBackColor = false; - // - // comboBoxProducts - // - comboBoxProducts.FormattingEnabled = true; - comboBoxProducts.Location = new Point(188, 72); - comboBoxProducts.Name = "comboBoxProducts"; - comboBoxProducts.Size = new Size(181, 28); - comboBoxProducts.TabIndex = 8; + buttonSelectFilePath.Click += ButtonSelectFilePath_Click; // // buttonMakeReport // buttonMakeReport.BackColor = Color.FromArgb(192, 192, 255); - buttonMakeReport.Location = new Point(22, 234); + buttonMakeReport.Location = new Point(22, 186); buttonMakeReport.Name = "buttonMakeReport"; buttonMakeReport.Size = new Size(347, 29); buttonMakeReport.TabIndex = 9; buttonMakeReport.Text = "Сформировать"; buttonMakeReport.UseVisualStyleBackColor = false; + buttonMakeReport.Click += ButtonMakeReport_Click; // - // FormProductReport + // FormCountReport // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(409, 302); + ClientSize = new Size(409, 249); Controls.Add(buttonMakeReport); - Controls.Add(comboBoxProducts); Controls.Add(buttonSelectFilePath); Controls.Add(dateTimePickerEndDate); Controls.Add(dateTimePickerStartDate); Controls.Add(textBoxFilePath); Controls.Add(label4); Controls.Add(label3); - Controls.Add(label2); Controls.Add(label1); - Name = "FormProductReport"; - Text = "FormProductReport"; + Name = "FormCountReport"; + Text = "FormCountReport"; ResumeLayout(false); PerformLayout(); } @@ -150,14 +131,12 @@ #endregion private Label label1; - private Label label2; private Label label3; private Label label4; private TextBox textBoxFilePath; private DateTimePicker dateTimePickerStartDate; private DateTimePicker dateTimePickerEndDate; private Button buttonSelectFilePath; - private ComboBox comboBoxProducts; private Button buttonMakeReport; } } \ No newline at end of file diff --git a/Publication/Forms/FormCountReport.cs b/Publication/Forms/FormCountReport.cs index 6e906d9..7c56465 100644 --- a/Publication/Forms/FormCountReport.cs +++ b/Publication/Forms/FormCountReport.cs @@ -1,4 +1,5 @@ -using System; +using Publication.Reports; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +8,59 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Unity; namespace Publication.Forms { public partial class FormCountReport : Form { - public FormCountReport() + IUnityContainer _container; + + public FormCountReport(IUnityContainer container) { InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void ButtonSelectFilePath_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Excel Files | *.xlsx" + }; + if (sfd.ShowDialog() != DialogResult.OK) + { + return; + } + textBoxFilePath.Text = sfd.FileName; + } + + private void ButtonMakeReport_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFilePath.Text)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + if (dateTimePickerEndDate.Value <= dateTimePickerStartDate.Value) + { + throw new Exception("Дата начала должна быть раньше даты окончания"); + } + if (_container.Resolve().CreateTable(textBoxFilePath.Text, dateTimePickerStartDate.Value, dateTimePickerEndDate.Value)) + { + MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании очета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } } diff --git a/Publication/Forms/FormCountReport.resx b/Publication/Forms/FormCountReport.resx index 1af7de1..af32865 100644 --- a/Publication/Forms/FormCountReport.resx +++ b/Publication/Forms/FormCountReport.resx @@ -1,17 +1,17 @@  - diff --git a/Publication/Forms/FormPrintingHouse.cs b/Publication/Forms/FormPrintingHouse.cs index 5d2f30d..66fe4cf 100644 --- a/Publication/Forms/FormPrintingHouse.cs +++ b/Publication/Forms/FormPrintingHouse.cs @@ -82,7 +82,8 @@ MessageBoxButtons.OK, MessageBoxIcon.Error); ) ); } - return list; + return list.GroupBy(x => x.OrderId, x => x.Count, (id, counts) => + PrintingHouseOrders.CreateEntity(0, id, counts.Sum())).ToList(); } private void ButtonBreak_Click(object sender, EventArgs e) => Close(); diff --git a/Publication/Forms/Publication.Designer.cs b/Publication/Forms/Publication.Designer.cs index 0f5455e..af60789 100644 --- a/Publication/Forms/Publication.Designer.cs +++ b/Publication/Forms/Publication.Designer.cs @@ -38,6 +38,8 @@ CreateOrderToolStripMenuItem = new ToolStripMenuItem(); PrintingToolStripMenuItem = new ToolStripMenuItem(); ReportsToolStripMenuItem = new ToolStripMenuItem(); + DirectoryReportToolStripMenuItem = new ToolStripMenuItem(); + CountReportToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -92,9 +94,22 @@ // // ReportsToolStripMenuItem // + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, CountReportToolStripMenuItem }); ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; resources.ApplyResources(ReportsToolStripMenuItem, "ReportsToolStripMenuItem"); // + // DirectoryReportToolStripMenuItem + // + DirectoryReportToolStripMenuItem.Name = "DirectoryReportToolStripMenuItem"; + resources.ApplyResources(DirectoryReportToolStripMenuItem, "DirectoryReportToolStripMenuItem"); + DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click; + // + // CountReportToolStripMenuItem + // + CountReportToolStripMenuItem.Name = "CountReportToolStripMenuItem"; + resources.ApplyResources(CountReportToolStripMenuItem, "CountReportToolStripMenuItem"); + CountReportToolStripMenuItem.Click += CountReportToolStripMenuItem_Click; + // // Publication // resources.ApplyResources(this, "$this"); @@ -119,5 +134,7 @@ private ToolStripMenuItem CreateOrderToolStripMenuItem; private ToolStripMenuItem PrintingToolStripMenuItem; private ToolStripMenuItem ReportsToolStripMenuItem; + private ToolStripMenuItem DirectoryReportToolStripMenuItem; + private ToolStripMenuItem CountReportToolStripMenuItem; } } diff --git a/Publication/Forms/Publication.cs b/Publication/Forms/Publication.cs index 1840d63..00569c7 100644 --- a/Publication/Forms/Publication.cs +++ b/Publication/Forms/Publication.cs @@ -81,4 +81,28 @@ public partial class Publication : Form MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void DirectoryReportToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + unityContainer.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CountReportToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + unityContainer.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } diff --git a/Publication/Forms/Publication.resx b/Publication/Forms/Publication.resx index 230ba5a..9d79e54 100644 --- a/Publication/Forms/Publication.resx +++ b/Publication/Forms/Publication.resx @@ -127,24 +127,31 @@ Справочники - - 224, 26 - - - Создать заказ - - - 224, 26 - - - Печать - 95, 24 Операции + + + Ctrl+W + + + 350, 26 + + + Документ со справочниками + + + Ctrl+E + + + 350, 26 + + + Движение заказов + 73, 24 @@ -183,17 +190,29 @@ Заказчики - 224, 26 + 185, 26 Материалы - 224, 26 + 185, 26 Издательства + + 188, 26 + + + Создать заказ + + + 188, 26 + + + Печать + True @@ -2156,7 +2175,6 @@ Gg8Vxln/2Q== - Stretch @@ -2217,6 +2235,18 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + DirectoryReportToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + CountReportToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Publication diff --git a/Publication/Reports/PdfBuilder.cs b/Publication/Reports/PdfBuilder.cs new file mode 100644 index 0000000..dd8d965 --- /dev/null +++ b/Publication/Reports/PdfBuilder.cs @@ -0,0 +1,86 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Publication.Reports; + +public class PdfBuilder +{ + /*private readonly string _filePath; + private readonly Document _document; + public PdfBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _document = new Document(); + DefineStyles(); + } + public PdfBuilder AddHeader(string header) + { + _document.AddSection().AddParagraph(header, "NormalBold"); + return this; + } + + public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) + { + if (data == null || data.Count == 0) + { + return this; + } + var chart = new Chart(ChartType.Pie2D); + var series = chart.SeriesCollection.AddSeries(); + series.Add(data.Select(x => x.Value).ToArray()); + + var xseries = chart.XValues.AddXSeries(); + xseries.Add(data.Select(x => x.Caption).ToArray()); + + chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Position = DataLabelPosition.OutsideEnd; + + chart.Width = Unit.FromCentimeter(16); + chart.Height = Unit.FromCentimeter(12); + + chart.TopArea.AddParagraph(title); + + chart.XAxis.MajorTickMark = TickMarkType.Outside; + + chart.YAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.HasMajorGridlines = true; + + chart.PlotArea.LineFormat.Width = 1; + chart.PlotArea.LineFormat.Visible = true; + + chart.TopArea.AddLegend(); + + _document.LastSection.Add(chart); + return this; + } + + public void Build() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(_filePath); + } + private void DefineStyles() + { + var headerStyle = _document.AddStyle("NormalBold", "Normal"); + headerStyle.Font.Bold = true; + headerStyle.Font.Size = 14; + headerStyle.Font.Color = Colors.DeepPink; + }*/ +} diff --git a/Publication/Repositories/Implementations/PrintingHouseRepository.cs b/Publication/Repositories/Implementations/PrintingHouseRepository.cs index 48a4870..baa948d 100644 --- a/Publication/Repositories/Implementations/PrintingHouseRepository.cs +++ b/Publication/Repositories/Implementations/PrintingHouseRepository.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using Npgsql; using Publication.Entites; using Dapper; +using Unity; namespace Publication.Repositories.Implementations; @@ -75,10 +76,15 @@ public class PrintingHouseRepository : IPrintingHouseRepository try { using var connection = new NpgsqlConnection(connectionRepository.GetConnection); - var querySelect = "SELECT * FROM PrintingHouses"; - var printingHouses = connection.Query(querySelect); + var querySelect = @"SELECT ph.*, pho.OrderId, pho.Count + FROM PrintingHouses ph + INNER JOIN PrintingHouseOrders pho ON pho.PrintingHouseId = ph.Id"; + var printingHouses = connection.Query(querySelect); logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(printingHouses)); - return printingHouses; + return printingHouses.GroupBy(x => x.Id, y => y, + (key, value) => PrintingHouses.CreateEntity(value.First(), + value.Select(z => PrintingHouseOrders.CreateEntity(0, z.OrderId, z.Count)))).ToList(); + } catch (Exception ex) {