статистика по поставщикам

This commit is contained in:
the 2024-06-25 23:28:09 +04:00
parent 2f245da975
commit 83d1365b68
2 changed files with 121 additions and 59 deletions

View File

@ -28,12 +28,13 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
chart = new System.Windows.Forms.DataVisualization.Charting.Chart(); chart = new System.Windows.Forms.DataVisualization.Charting.Chart();
dateTimePickerTo = new DateTimePicker(); dateTimePickerTo = new DateTimePicker();
dateTimePickerFrom = new DateTimePicker(); dateTimePickerFrom = new DateTimePicker();
panel1 = new Panel(); panel1 = new Panel();
comboBox1 = new ComboBox();
checkBoxPending = new CheckBox(); checkBoxPending = new CheckBox();
checkBoxArriving = new CheckBox(); checkBoxArriving = new CheckBox();
checkBoxCompleted = new CheckBox(); checkBoxCompleted = new CheckBox();
@ -45,14 +46,14 @@
// //
// chart // chart
// //
chartArea1.Name = "ChartArea1"; chartArea2.Name = "ChartArea1";
chart.ChartAreas.Add(chartArea1); chart.ChartAreas.Add(chartArea2);
chart.Dock = DockStyle.Bottom; chart.Dock = DockStyle.Bottom;
legend1.Name = "Legend1"; legend2.Name = "Legend1";
chart.Legends.Add(legend1); chart.Legends.Add(legend2);
chart.Location = new Point(0, 30); chart.Location = new Point(0, 57);
chart.Name = "chart"; chart.Name = "chart";
chart.Size = new Size(800, 420); chart.Size = new Size(800, 393);
chart.TabIndex = 0; chart.TabIndex = 0;
chart.Text = "chart1"; chart.Text = "chart1";
chart.Click += chart_Click; chart.Click += chart_Click;
@ -76,6 +77,7 @@
// panel1 // panel1
// //
panel1.BorderStyle = BorderStyle.FixedSingle; panel1.BorderStyle = BorderStyle.FixedSingle;
panel1.Controls.Add(comboBox1);
panel1.Controls.Add(checkBoxPending); panel1.Controls.Add(checkBoxPending);
panel1.Controls.Add(checkBoxArriving); panel1.Controls.Add(checkBoxArriving);
panel1.Controls.Add(checkBoxCompleted); panel1.Controls.Add(checkBoxCompleted);
@ -86,13 +88,23 @@
panel1.Dock = DockStyle.Top; panel1.Dock = DockStyle.Top;
panel1.Location = new Point(0, 0); panel1.Location = new Point(0, 0);
panel1.Name = "panel1"; panel1.Name = "panel1";
panel1.Size = new Size(800, 24); panel1.Size = new Size(800, 51);
panel1.TabIndex = 3; panel1.TabIndex = 3;
// //
// comboBox1
//
comboBox1.FormattingEnabled = true;
comboBox1.Items.AddRange(new object[] { "По поставкам", "По поставщикам" });
comboBox1.Location = new Point(542, -1);
comboBox1.Name = "comboBox1";
comboBox1.Size = new Size(121, 23);
comboBox1.TabIndex = 8;
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
//
// checkBoxPending // checkBoxPending
// //
checkBoxPending.AutoSize = true; checkBoxPending.AutoSize = true;
checkBoxPending.Location = new Point(481, 3); checkBoxPending.Location = new Point(3, 27);
checkBoxPending.Name = "checkBoxPending"; checkBoxPending.Name = "checkBoxPending";
checkBoxPending.Size = new Size(92, 19); checkBoxPending.Size = new Size(92, 19);
checkBoxPending.TabIndex = 7; checkBoxPending.TabIndex = 7;
@ -103,7 +115,7 @@
// checkBoxArriving // checkBoxArriving
// //
checkBoxArriving.AutoSize = true; checkBoxArriving.AutoSize = true;
checkBoxArriving.Location = new Point(590, 3); checkBoxArriving.Location = new Point(101, 27);
checkBoxArriving.Name = "checkBoxArriving"; checkBoxArriving.Name = "checkBoxArriving";
checkBoxArriving.Size = new Size(61, 19); checkBoxArriving.Size = new Size(61, 19);
checkBoxArriving.TabIndex = 6; checkBoxArriving.TabIndex = 6;
@ -114,7 +126,7 @@
// checkBoxCompleted // checkBoxCompleted
// //
checkBoxCompleted.AutoSize = true; checkBoxCompleted.AutoSize = true;
checkBoxCompleted.Location = new Point(668, 4); checkBoxCompleted.Location = new Point(168, 27);
checkBoxCompleted.Name = "checkBoxCompleted"; checkBoxCompleted.Name = "checkBoxCompleted";
checkBoxCompleted.Size = new Size(104, 19); checkBoxCompleted.Size = new Size(104, 19);
checkBoxCompleted.TabIndex = 5; checkBoxCompleted.TabIndex = 5;
@ -148,7 +160,7 @@
Controls.Add(panel1); Controls.Add(panel1);
Controls.Add(chart); Controls.Add(chart);
Name = "FormStatistics"; Name = "FormStatistics";
Text = "FormStatistics"; Text = "Статистика по поставкам";
Load += FormStatistics_Load; Load += FormStatistics_Load;
((System.ComponentModel.ISupportInitialize)chart).EndInit(); ((System.ComponentModel.ISupportInitialize)chart).EndInit();
panel1.ResumeLayout(false); panel1.ResumeLayout(false);
@ -167,5 +179,6 @@
private CheckBox checkBoxPending; private CheckBox checkBoxPending;
private CheckBox checkBoxArriving; private CheckBox checkBoxArriving;
private CheckBox checkBoxCompleted; private CheckBox checkBoxCompleted;
private ComboBox comboBox1;
} }
} }

View File

@ -13,16 +13,19 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting; using System.Windows.Forms.DataVisualization.Charting;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace WinFormsApp namespace WinFormsApp
{ {
public partial class FormStatistics : Form public partial class FormStatistics : Form
{ {
ISupplyLogic _supplyLogic; ISupplyLogic _supplyLogic;
public FormStatistics(ISupplyLogic supplyLogic) ISupplierLogic _supplierLogic;
public FormStatistics(ISupplyLogic supplyLogic, ISupplierLogic supplierLogic)
{ {
InitializeComponent(); InitializeComponent();
_supplyLogic = supplyLogic; _supplyLogic = supplyLogic;
_supplierLogic = supplierLogic;
} }
private void FormStatistics_Load(object sender, EventArgs e) private void FormStatistics_Load(object sender, EventArgs e)
@ -33,59 +36,88 @@ namespace WinFormsApp
private void LoadData() private void LoadData()
{ {
chart.Series.Clear(); chart.Series.Clear();
var list = _supplyLogic.ReadList(new SupplySearchModel() if (comboBox1.SelectedIndex == 0)
{ {
DateStart = dateTimePickerTo.Value, var list = _supplyLogic.ReadList(new SupplySearchModel()
DateEnd = dateTimePickerFrom.Value,
});
if (checkBoxPending.Checked)
{
var date = dateTimePickerTo.Value;
chart.Series.Add("Pending");
for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
{ {
var count = list.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Pending).ToList().Count; DateStart = dateTimePickerTo.Value,
DataPoint dataPoint = new DataPoint(); DateEnd = dateTimePickerFrom.Value,
dataPoint.XValue = i; });
dataPoint.IsVisibleInLegend = false; if (checkBoxPending.Checked)
dataPoint.Label = $"{date.Year}.{date.Month}"; {
dataPoint.SetValueY(count); var date = dateTimePickerTo.Value;
chart.Series["Pending"].Points.Add(dataPoint); chart.Series.Add("Pending");
date = date.AddMonths(1); for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
{
var count = list.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Pending).ToList().Count;
DataPoint dataPoint = new DataPoint();
dataPoint.XValue = i;
dataPoint.IsVisibleInLegend = false;
dataPoint.Label = $"{date.Year}.{date.Month}";
dataPoint.SetValueY(count);
chart.Series["Pending"].Points.Add(dataPoint);
date = date.AddMonths(1);
}
}
if (checkBoxArriving.Checked)
{
var date = dateTimePickerTo.Value;
chart.Series.Add("Arriving");
for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
{
var count = list.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Arriving).ToList().Count;
DataPoint dataPoint = new DataPoint();
dataPoint.XValue = i;
dataPoint.IsVisibleInLegend = false;
dataPoint.Label = $"{date.Year}.{date.Month}";
dataPoint.SetValueY(count);
chart.Series["Arriving"].Points.Add(dataPoint);
date = date.AddMonths(1);
}
}
if (checkBoxCompleted.Checked)
{
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 && x.Status == SupplyStatus.Completed).ToList().Count;
DataPoint dataPoint = new DataPoint();
dataPoint.XValue = i;
dataPoint.IsVisibleInLegend = false;
dataPoint.Label = $"{date.Year}.{date.Month}";
dataPoint.SetValueY(count);
chart.Series["Completed"].Points.Add(dataPoint);
date = date.AddMonths(1);
}
} }
} }
if (checkBoxArriving.Checked) if (comboBox1.SelectedIndex == 1)
{ {
var date = dateTimePickerTo.Value; var supplylist = _supplyLogic.ReadList(new SupplySearchModel()
chart.Series.Add("Arriving");
for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
{ {
var count = list.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Arriving).ToList().Count; DateStart = dateTimePickerTo.Value,
DataPoint dataPoint = new DataPoint(); DateEnd = dateTimePickerFrom.Value,
dataPoint.XValue = i; });
dataPoint.IsVisibleInLegend = false; var supplierlist = _supplierLogic.ReadList(null);
dataPoint.Label = $"{date.Year}.{date.Month}"; foreach (var supplier in supplierlist)
dataPoint.SetValueY(count); {
chart.Series["Arriving"].Points.Add(dataPoint); var date = dateTimePickerTo.Value;
date = date.AddMonths(1); chart.Series.Add(supplier.Name);
} for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
} {
if (checkBoxCompleted.Checked) var count = supplylist.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Completed && x.SupplierId == supplier.Id).ToList().Count;
{ DataPoint dataPoint = new DataPoint();
var date = dateTimePickerTo.Value; dataPoint.XValue = i;
chart.Series.Add("Completed"); dataPoint.IsVisibleInLegend = false;
for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++) dataPoint.Label = $"{supplier.Name}";
{ dataPoint.SetValueY(count);
var count = list.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Completed).ToList().Count; chart.Series[supplier.Name].Points.Add(dataPoint);
DataPoint dataPoint = new DataPoint(); date = date.AddMonths(1);
dataPoint.XValue = i; }
dataPoint.IsVisibleInLegend = false;
dataPoint.Label = $"{date.Year}.{date.Month}";
dataPoint.SetValueY(count);
chart.Series["Completed"].Points.Add(dataPoint);
date = date.AddMonths(1);
} }
} }
} }
private void chart_Click(object sender, EventArgs e) private void chart_Click(object sender, EventArgs e)
@ -122,5 +154,22 @@ namespace WinFormsApp
{ {
LoadData(); LoadData();
} }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex != 0)
{
checkBoxArriving.Visible = false;
checkBoxCompleted.Visible = false;
checkBoxPending.Visible = false;
}
else
{
checkBoxArriving.Visible = true;
checkBoxCompleted.Visible = true;
checkBoxPending.Visible = true;
}
LoadData();
}
} }
} }