2024-06-25 18:32:16 +04:00
|
|
|
|
using Contracts.BusinessLogicContracts;
|
|
|
|
|
using Contracts.SearchModels;
|
2024-06-25 19:23:43 +04:00
|
|
|
|
using DataModels.Enums;
|
2024-06-25 18:32:16 +04:00
|
|
|
|
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;
|
2024-06-25 18:43:20 +04:00
|
|
|
|
using System.Windows.Forms.DataVisualization.Charting;
|
2024-06-25 23:28:09 +04:00
|
|
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
2024-06-25 18:32:16 +04:00
|
|
|
|
|
|
|
|
|
namespace WinFormsApp
|
|
|
|
|
{
|
|
|
|
|
public partial class FormStatistics : Form
|
|
|
|
|
{
|
|
|
|
|
ISupplyLogic _supplyLogic;
|
2024-06-25 23:28:09 +04:00
|
|
|
|
ISupplierLogic _supplierLogic;
|
|
|
|
|
public FormStatistics(ISupplyLogic supplyLogic, ISupplierLogic supplierLogic)
|
2024-06-25 18:32:16 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_supplyLogic = supplyLogic;
|
2024-06-25 23:28:09 +04:00
|
|
|
|
_supplierLogic = supplierLogic;
|
2024-06-25 18:32:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormStatistics_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
chart.Series.Clear();
|
2024-06-25 23:28:09 +04:00
|
|
|
|
if (comboBox1.SelectedIndex == 0)
|
2024-06-25 18:32:16 +04:00
|
|
|
|
{
|
2024-06-25 23:28:09 +04:00
|
|
|
|
var list = _supplyLogic.ReadList(new SupplySearchModel()
|
|
|
|
|
{
|
|
|
|
|
DateStart = dateTimePickerTo.Value,
|
|
|
|
|
DateEnd = dateTimePickerFrom.Value,
|
|
|
|
|
});
|
|
|
|
|
if (checkBoxPending.Checked)
|
2024-06-25 19:23:43 +04:00
|
|
|
|
{
|
2024-06-25 23:28:09 +04:00
|
|
|
|
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;
|
|
|
|
|
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);
|
|
|
|
|
}
|
2024-06-25 19:23:43 +04:00
|
|
|
|
}
|
2024-06-25 23:28:09 +04:00
|
|
|
|
if (checkBoxArriving.Checked)
|
2024-06-25 19:23:43 +04:00
|
|
|
|
{
|
2024-06-25 23:28:09 +04:00
|
|
|
|
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);
|
|
|
|
|
}
|
2024-06-25 19:23:43 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-25 23:28:09 +04:00
|
|
|
|
if (comboBox1.SelectedIndex == 1)
|
2024-06-25 19:23:43 +04:00
|
|
|
|
{
|
2024-06-25 23:28:09 +04:00
|
|
|
|
var supplylist = _supplyLogic.ReadList(new SupplySearchModel()
|
2024-06-25 19:23:43 +04:00
|
|
|
|
{
|
2024-06-25 23:28:09 +04:00
|
|
|
|
DateStart = dateTimePickerTo.Value,
|
|
|
|
|
DateEnd = dateTimePickerFrom.Value,
|
|
|
|
|
});
|
|
|
|
|
var supplierlist = _supplierLogic.ReadList(null);
|
|
|
|
|
foreach (var supplier in supplierlist)
|
|
|
|
|
{
|
|
|
|
|
var date = dateTimePickerTo.Value;
|
|
|
|
|
chart.Series.Add(supplier.Name);
|
|
|
|
|
for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
|
|
|
|
|
{
|
|
|
|
|
var count = supplylist.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Completed && x.SupplierId == supplier.Id).ToList().Count;
|
|
|
|
|
DataPoint dataPoint = new DataPoint();
|
|
|
|
|
dataPoint.XValue = i;
|
|
|
|
|
dataPoint.IsVisibleInLegend = false;
|
|
|
|
|
dataPoint.Label = $"{supplier.Name}";
|
|
|
|
|
dataPoint.SetValueY(count);
|
|
|
|
|
chart.Series[supplier.Name].Points.Add(dataPoint);
|
|
|
|
|
date = date.AddMonths(1);
|
|
|
|
|
}
|
2024-06-25 19:23:43 +04:00
|
|
|
|
}
|
2024-06-25 18:32:16 +04:00
|
|
|
|
}
|
2024-06-25 23:28:09 +04:00
|
|
|
|
|
2024-06-25 18:32:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2024-06-25 19:23:43 +04:00
|
|
|
|
|
|
|
|
|
private void checkBoxPending_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkBoxArriving_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkBoxCompleted_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
2024-06-25 23:28:09 +04:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2024-06-25 18:32:16 +04:00
|
|
|
|
}
|
|
|
|
|
}
|