простейшая статистика по поставкам

This commit is contained in:
the 2024-06-25 18:32:16 +04:00
parent 464ab47941
commit 794931d97b
8 changed files with 340 additions and 19 deletions

View File

@ -14,7 +14,9 @@ namespace DatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql("Server=192.168.191.42:32768;Database=gun_market;Username=postgres;Password=7355608;");
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
optionsBuilder.UseNpgsql("Server=192.168.191.42:32768;Database=gun_market;Username=postgres;Password=7355608;");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -41,6 +41,7 @@
printPreviewDialog = new PrintPreviewDialog();
printDialog = new PrintDialog();
buttonRefresh = new Button();
статистикаToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
@ -66,7 +67,7 @@
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { товарыToolStripMenuItem, поставщикиToolStripMenuItem });
menuStrip1.Items.AddRange(new ToolStripItem[] { товарыToolStripMenuItem, поставщикиToolStripMenuItem, статистикаToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(901, 24);
@ -151,6 +152,13 @@
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click;
//
// статистикаToolStripMenuItem
//
статистикаToolStripMenuItem.Name = "статистикаToolStripMenuItem";
статистикаToolStripMenuItem.Size = new Size(80, 20);
статистикаToolStripMenuItem.Text = "Статистика";
статистикаToolStripMenuItem.Click += статистикаToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -189,5 +197,6 @@
private PrintPreviewDialog printPreviewDialog;
private PrintDialog printDialog;
private Button buttonRefresh;
private ToolStripMenuItem статистикаToolStripMenuItem;
}
}

View File

@ -153,22 +153,22 @@ namespace WinFormsApp
MessageBox.Show("Выберите одну поставку для формирования отчета", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
try
{
_reportLogic.SaveSuppliesToPdfFile(new ReportBindingModel
{
_reportLogic.SaveSuppliesToPdfFile(new ReportBindingModel
{
FileName = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf",
Date = (DateTime)dataGridView.SelectedRows[0].Cells["Date"].Value,
SupplyId = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value
});
_logger.LogInformation("Сохранение отчета о поставке");
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения отчета о поставке");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
FileName = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf",
Date = (DateTime)dataGridView.SelectedRows[0].Cells["Date"].Value,
SupplyId = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value
});
_logger.LogInformation("Сохранение отчета о поставке");
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения отчета о поставке");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonPrintReport_Click(object sender, EventArgs e)
@ -178,7 +178,7 @@ namespace WinFormsApp
if (service is FormPreviewPDF form)
{
var src = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf";
if (!File.Exists(src))
if (!File.Exists(src))
{
var result = MessageBox.Show("Отчёт о поставке не был найден. Сформировать?", "", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
@ -214,5 +214,14 @@ namespace WinFormsApp
{
LoadData();
}
private void статистикаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStatistics));
if (service is FormStatistics form)
{
form.ShowDialog();
}
}
}
}

106
WinFormsApp/FormStatistics.Designer.cs generated Normal file
View File

@ -0,0 +1,106 @@
namespace WinFormsApp
{
partial class FormStatistics
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
chart = new System.Windows.Forms.DataVisualization.Charting.Chart();
dateTimePickerTo = new DateTimePicker();
dateTimePickerFrom = new DateTimePicker();
panel1 = new Panel();
((System.ComponentModel.ISupportInitialize)chart).BeginInit();
panel1.SuspendLayout();
SuspendLayout();
//
// chart
//
chartArea1.Name = "ChartArea1";
chart.ChartAreas.Add(chartArea1);
chart.Dock = DockStyle.Bottom;
legend1.Name = "Legend1";
chart.Legends.Add(legend1);
chart.Location = new Point(0, 12);
chart.Name = "chart";
chart.Size = new Size(800, 438);
chart.TabIndex = 0;
chart.Text = "chart1";
chart.Click += chart_Click;
//
// dateTimePickerTo
//
dateTimePickerTo.Dock = DockStyle.Left;
dateTimePickerTo.Location = new Point(0, 0);
dateTimePickerTo.Name = "dateTimePickerTo";
dateTimePickerTo.Size = new Size(200, 23);
dateTimePickerTo.TabIndex = 1;
dateTimePickerTo.ValueChanged += dateTimePickerFrom_ValueChanged;
//
// dateTimePickerFrom
//
dateTimePickerFrom.Dock = DockStyle.Right;
dateTimePickerFrom.Location = new Point(598, 0);
dateTimePickerFrom.Name = "dateTimePickerFrom";
dateTimePickerFrom.Size = new Size(200, 23);
dateTimePickerFrom.TabIndex = 2;
dateTimePickerFrom.ValueChanged += dateTimePickerTo_ValueChanged;
//
// panel1
//
panel1.BorderStyle = BorderStyle.FixedSingle;
panel1.Controls.Add(dateTimePickerFrom);
panel1.Controls.Add(dateTimePickerTo);
panel1.Dock = DockStyle.Top;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new Size(800, 24);
panel1.TabIndex = 3;
//
// FormStatistics
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(panel1);
Controls.Add(chart);
Name = "FormStatistics";
Text = "FormStatistics";
Load += FormStatistics_Load;
((System.ComponentModel.ISupportInitialize)chart).EndInit();
panel1.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataVisualization.Charting.Chart chart;
private DateTimePicker dateTimePickerTo;
private DateTimePicker dateTimePickerFrom;
private Panel panel1;
}
}

View File

@ -0,0 +1,74 @@
using Contracts.BusinessLogicContracts;
using Contracts.SearchModels;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFormsApp
{
public partial class FormStatistics : Form
{
ISupplyLogic _supplyLogic;
public FormStatistics(ISupplyLogic supplyLogic)
{
InitializeComponent();
_supplyLogic = supplyLogic;
}
private void FormStatistics_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
chart.Series.Clear();
var list = _supplyLogic.ReadList(new SupplySearchModel()
{
DateStart = dateTimePickerTo.Value,
DateEnd = dateTimePickerFrom.Value,
});
var date = dateTimePickerTo.Value;
chart.Series.Add("Completed");
for (int i = 0; i < diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
{
var count = list.Where(x => x.Date.Month == date.Month).ToList().Count;
foreach (var x in list)
{
Debug.WriteLine(x.Date.Month);
Debug.WriteLine(date.Month);
}
chart.Series["Completed"].Points.AddXY(date.Month, count);
date = date.AddMonths(1);
}
}
private void chart_Click(object sender, EventArgs e)
{
}
private void dateTimePickerFrom_ValueChanged(object sender, EventArgs e)
{
LoadData();
}
private void dateTimePickerTo_ValueChanged(object sender, EventArgs e)
{
LoadData();
}
private int diff_month(DateTime d1, DateTime d2)
{
return (d1.Year - d2.Year) * 12 + d1.Month - d2.Month;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -62,7 +62,7 @@ namespace WinFormsApp
services.AddTransient<FormSupplierProduct>();
services.AddTransient<FormMediaFiles>();
services.AddTransient<FormPreviewPDF>();
services.AddTransient<FormStatistics>();
}
}
}

View File

@ -36,6 +36,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
<PackageReference Include="Spire.PDF" Version="10.6.7" />
<PackageReference Include="WinForms.DataVisualization" Version="1.9.2" />
</ItemGroup>
<ItemGroup>