PIAPS_CW/WinFormsApp/FormStatistics.cs

176 lines
6.6 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;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace WinFormsApp
{
public partial class FormStatistics : Form
{
ISupplyLogic _supplyLogic;
ISupplierLogic _supplierLogic;
public FormStatistics(ISupplyLogic supplyLogic, ISupplierLogic supplierLogic)
{
InitializeComponent();
_supplyLogic = supplyLogic;
_supplierLogic = supplierLogic;
}
private void FormStatistics_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
chart.Series.Clear();
if (comboBox1.SelectedIndex == 0)
{
var list = _supplyLogic.ReadList(new SupplySearchModel()
{
DateStart = dateTimePickerTo.Value,
DateEnd = dateTimePickerFrom.Value,
});
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++)
{
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
}
if (checkBoxArriving.Checked)
2024-06-25 19:23:43 +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
}
}
if (comboBox1.SelectedIndex == 1)
2024-06-25 19:23:43 +04:00
{
var supplylist = _supplyLogic.ReadList(new SupplySearchModel()
2024-06-25 19:23:43 +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
}
}
}
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();
}
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();
}
}
}