193 lines
7.0 KiB
C#
193 lines
7.0 KiB
C#
using BusinessLogic.BusinessLogic;
|
||
using ComponentsLibraryNet60.DocumentWithChart;
|
||
using ComponentsLibraryNet60.DocumentWithTable;
|
||
using ComponentsLibraryNet60.Models;
|
||
using Contracts.BindlingModels;
|
||
using Contracts.BusinessLogicContracts;
|
||
using Contracts.ViewModels;
|
||
using Controls;
|
||
using ControlsLibraryNet60.Data;
|
||
using ControlsLibraryNet60.Models;
|
||
using CustomComponents.NonViewComponents;
|
||
using CustomComponents.NonViewComponents.Enums;
|
||
using CustomComponents.NonViewComponents.SupportClasses;
|
||
using DatabaseImplement.Implements;
|
||
using NotVisualComponent;
|
||
using NotVisualComponent.Models;
|
||
using PluginsConventionLibrary;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace Forms
|
||
{
|
||
public class PluginsConvention : IPluginsConvention
|
||
{
|
||
private readonly IDeliveryLogic _dlogic;
|
||
private readonly IDeliveryTypeLogic _dtlogic;
|
||
private readonly ControlDataTreeTable _controlDataTreeTable = new();
|
||
private readonly LargeTextComponent _largeTextComponent = new();
|
||
private readonly ExcelHardTable excelHardTable = new();
|
||
private readonly PieChartWord pieChartWord = new();
|
||
|
||
public PluginsConvention()
|
||
{
|
||
_dtlogic = new DeliveryTypeLogic(new DeliveryTypeStorage());
|
||
_dlogic = new DeliveryLogic(new DeliveryStorage());
|
||
ReloadData();
|
||
}
|
||
|
||
public string PluginName => "PluginLab3";
|
||
|
||
public UserControl GetControl => _controlDataTreeTable;
|
||
|
||
public PluginsConventionElement GetElement
|
||
{
|
||
get
|
||
{
|
||
var selected = _controlDataTreeTable.GetSelectedObject<DeliveryViewModel>();
|
||
if (selected == null) throw new Exception("Не удалось получить выбранный элемент");
|
||
byte[] bytes = new byte[16];
|
||
BitConverter.GetBytes(selected.Id).CopyTo(bytes, 0);
|
||
return new PluginsConventionProvider()
|
||
{
|
||
Id = new Guid(bytes),
|
||
FCs = selected.FCs,
|
||
Wishes = selected.Wishes,
|
||
DeliveryType = selected.DeliveryType,
|
||
DeliveryDate = selected.DeliveryDate,
|
||
};
|
||
}
|
||
}
|
||
|
||
public Form GetForm(PluginsConventionElement element)
|
||
{
|
||
var deliveryForm = new DeliveryForm(_dlogic, _dtlogic);
|
||
if (element != null)
|
||
{
|
||
deliveryForm = new DeliveryForm(_dlogic, _dtlogic, element.Id.GetHashCode());
|
||
}
|
||
return deliveryForm;
|
||
}
|
||
|
||
public Form GetThesaurus()
|
||
{
|
||
return new DeliveryTypeForm(_dtlogic);
|
||
}
|
||
|
||
public bool DeleteElement(PluginsConventionElement element)
|
||
{
|
||
return _dlogic.Delete(new DeliveryBindingModel
|
||
{
|
||
Id = element.Id.GetHashCode()
|
||
});
|
||
}
|
||
|
||
public void ReloadData()
|
||
{
|
||
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);
|
||
|
||
var list = _dlogic.ReadList(null);
|
||
if (list != null)
|
||
{
|
||
_controlDataTreeTable.Clear();
|
||
_controlDataTreeTable.AddTable(list);
|
||
}
|
||
}
|
||
|
||
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
|
||
{
|
||
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(saveDocument.FileName, $"Отчет по доставкам без даты:", strings);
|
||
MessageBox.Show("Отчет готов");
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
|
||
{
|
||
var list = _dlogic.ReadList(null);
|
||
if (list != null)
|
||
{
|
||
excelHardTable.CreateDoc(new TableWithHeaderConfig<DeliveryViewModel>
|
||
{
|
||
FilePath = saveDocument.FileName,
|
||
Header = "Deliveryies",
|
||
ColumnsRowsWidth = new List<(int Column, int Row)> { (5, 5), (20, 5), (10, 0), (15, 0), },
|
||
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
|
||
{
|
||
(0, 0, "Id", "Id"),
|
||
(1, 0, "FCs", "FCs"),
|
||
(2, 0, "DeliveryType", "DeliveryType"),
|
||
(3, 0, "DeliveryDate", "DeliveryDate"),
|
||
},
|
||
Data = list
|
||
});
|
||
MessageBox.Show("Отчет готов");
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
|
||
{
|
||
var list = _dlogic.ReadList(null);
|
||
var data = list
|
||
.Where(x => x.DeliveryDate != "Даты доставки нет")
|
||
.GroupBy(x => x.DeliveryType)
|
||
.Select(g => (type: g.Key, Value: g.Count()))
|
||
.ToList();
|
||
|
||
var categoriesX = data.Select(d => d.type).ToList();
|
||
var valuesY = data.Select(d => (double)d.Value).ToList();
|
||
if (list != null)
|
||
{
|
||
var series = new List<SeriesData>
|
||
{
|
||
new()
|
||
{
|
||
SeriesName = "Количество доставок",
|
||
ValuesY = valuesY,
|
||
Color = Color.FromArgb(100, 150, 200)
|
||
}
|
||
};
|
||
pieChartWord.CreateDiagramDocument(new PieChartData()
|
||
{
|
||
FileName = saveDocument.FileName,
|
||
DocumentTitle = "Диаграмма",
|
||
DiagramTitle = "Количество доставок по типам",
|
||
LegendLayout = PieChartLegendAlign.Bottom,
|
||
CategoriesX = categoriesX,
|
||
SeriesData = series
|
||
});
|
||
MessageBox.Show("Отчет готов");
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
}
|
||
}
|