PIAPS_CW/WinFormsApp/FormStatistics.cs

127 lines
4.3 KiB
C#
Raw Normal View History

using Contracts.BusinessLogicContracts;
using Contracts.SearchModels;
2024-06-25 19:23:43 +04:00
using DataModels.Enums;
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;
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,
});
2024-06-25 19:23:43 +04:00
if (checkBoxPending.Checked)
{
2024-06-25 19:23:43 +04:00
var date = dateTimePickerTo.Value;
chart.Series.Add("Pending");
for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
2024-06-25 19:23:43 +04:00
{
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;
2024-06-25 19:23:43 +04:00
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++)
2024-06-25 19:23:43 +04:00
{
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;
2024-06-25 19:23:43 +04:00
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++)
2024-06-25 19:23:43 +04:00
{
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;
2024-06-25 19:23:43 +04:00
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 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();
}
}
}