PIbd-31_Malafeev.L.S._COP_25/Cop_25/Forms/FormMain.cs

174 lines
6.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ComponentsLibraryNet60.DocumentWithChart;
using ComponentsLibraryNet60.Models;
using Contracts.BindlingModels;
using Contracts.BusinessLogicContracts;
using Contracts.ViewModels;
using Controls;
using ControlsLibraryNet60.Data;
using ControlsLibraryNet60.Models;
using CustomComponents;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Forms
{
public partial class FormMain : Form
{
private readonly IDeliveryLogic _dlogic;
private readonly IDeliveryTypeLogic _dtlogic;
public FormMain(IDeliveryLogic dLogic, IDeliveryTypeLogic dtLogic)
{
InitializeComponent();
_dlogic = dLogic;
_dtlogic = dtLogic;
TreeConfig();
LoadData();
}
private void TreeConfig()
{
DataTreeNodeConfig treeConfig = new();
treeConfig.NodeNames = new();
treeConfig.NodeNames.Enqueue("Id");
treeConfig.NodeNames.Enqueue("FCs");
treeConfig.NodeNames.Enqueue("Wishes");
treeConfig.NodeNames.Enqueue("DeliveryType");
treeConfig.NodeNames.Enqueue("DeliveryDate");
controlDataTreeTable.LoadConfig(treeConfig);
}
private void LoadData()
{
var list = _dlogic.ReadList(null);
if (list != null)
{
controlDataTreeTable.Clear();
controlDataTreeTable.AddTable(list);
}
}
private void созданиеТипаДоставкиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(DeliveryTypeForm));
if (service is DeliveryTypeForm form)
{
form.ShowDialog();
}
}
private void созданиеДоставкиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(DeliveryForm));
if (service is DeliveryForm form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void editProviderToolStripMenuItem_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(controlDataTreeTable.GetSelectedObject<DeliveryViewModel>()?.Id);
DeliveryForm form = new DeliveryForm(_dlogic, _dtlogic, id);
form.ShowDialog();
LoadData();
}
private void deleteProviderToolStripMenuItem_Click(object sender, EventArgs e)
{
var confirmResult = MessageBox.Show("Вы действительно хотите удалить запись?", "Подтвердите действие",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
if (confirmResult == DialogResult.Yes)
{
_dlogic.Delete(new DeliveryBindingModel
{
Id = Convert.ToInt32(controlDataTreeTable.GetSelectedObject<DeliveryViewModel>()?.Id),
});
LoadData();
}
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void pDFДокументToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.ShowDialog();
string path = saveFileDialog.FileName + ".pdf";
var list = _dlogic.ReadList(null);
if (list != null)
{
int i = 0;
foreach (var item in list)
{
if (item.DeliveryDate == "Даты доставки нет") i++;
}
string[] strings = new string[i];
int j = 0;
foreach (var item in list)
{
if (item.DeliveryDate == "Даты доставки нет") { strings[j] = ($"{item.FCs} : {item.Wishes}"); j++; }
}
largeTextComponent.CreateDocument(path, $"Отчет по доставкам без даты:", strings);
MessageBox.Show("Отчет готов");
}
}
private void wordДиаграммаToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.ShowDialog();
string path = saveFileDialog.FileName + ".docx";
var list = _dlogic.ReadList(null);
var data = new List<(int Date, double Value)> { };
string header = "График доставок известной даты\n";
var chart = new Dictionary<string, List<(int Date, double Value)>> { };
int index = 1;
foreach (var type in _dtlogic.ReadList(null)!)
{
int sum = 0;
foreach (var item in list)
{
if (item.DeliveryType == type.Name)
{
sum++;
}
}
header += $"{index} - {type.Name}\n";
if (sum != 0) data.Add((index, sum));
index++;
}
chart.Add("ИП", data);
var conf = new ComponentDocumentWithChartConfig
{
FilePath = path,
Header = header,
ChartTitle = "Диаграмма по типам доставок",
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
Data = chart,
};
componentDocumentWithChartPieWord.CreateDoc(conf);
MessageBox.Show("Отчет готов");
}
}
}