2023-11-02 02:24:20 +04:00
|
|
|
|
using ComponentsLibraryNet60.Core;
|
|
|
|
|
using ComponentsLibraryNet60.Models;
|
|
|
|
|
using Contracts.StoragesContracts;
|
|
|
|
|
using Contracts.ViewModels;
|
|
|
|
|
using ControlsLibraryNet60.Models;
|
|
|
|
|
using DataBaseImplement.Implements;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
|
|
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
|
|
|
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;
|
|
|
|
|
using System.Windows.Forms.VisualStyles;
|
|
|
|
|
using PdfFormsLibrary;
|
|
|
|
|
using PdfFormsLibrary.Helpers;
|
2023-11-02 09:16:50 +04:00
|
|
|
|
using WinFormsLibrary.SupportClasses;
|
|
|
|
|
using WinFormsLibrary.SupportClasses.Enums;
|
|
|
|
|
using DataBaseImplement.Models;
|
2023-11-02 09:38:50 +04:00
|
|
|
|
using WinFormsLibrary.not_visual;
|
2023-11-02 02:24:20 +04:00
|
|
|
|
|
|
|
|
|
namespace AppView
|
|
|
|
|
{
|
|
|
|
|
public partial class FormMain : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly IProviderStorage _providerStorage;
|
|
|
|
|
private readonly ITypeStorage _typeStorage;
|
|
|
|
|
|
|
|
|
|
public FormMain(
|
|
|
|
|
IProviderStorage providerStorage,
|
|
|
|
|
ITypeStorage typeStorage
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
_providerStorage = providerStorage;
|
|
|
|
|
_typeStorage = typeStorage;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
KeyDown += new KeyEventHandler(FormMain_KeyDown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormMain_Load(
|
|
|
|
|
object sender,
|
|
|
|
|
EventArgs e
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var providers = _providerStorage.GetFullList();
|
|
|
|
|
if (providers != null)
|
|
|
|
|
{
|
|
|
|
|
controlDataTreeCell.Clear();
|
|
|
|
|
TreeColumnConfiguration();
|
|
|
|
|
if (providers.Count > 0) AddTreeData(providers);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
ex.Message,
|
|
|
|
|
"Ошибка",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TreeColumnConfiguration()
|
|
|
|
|
{
|
|
|
|
|
DataTreeNodeConfig treeConfig = new();
|
|
|
|
|
treeConfig.NodeNames = new();
|
|
|
|
|
treeConfig.NodeNames.Enqueue("Type");
|
|
|
|
|
treeConfig.NodeNames.Enqueue("SupplyDateTime");
|
|
|
|
|
treeConfig.NodeNames.Enqueue("Id");
|
|
|
|
|
treeConfig.NodeNames.Enqueue("Name");
|
|
|
|
|
|
|
|
|
|
controlDataTreeCell.LoadConfig(treeConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddTreeData(List<ProviderViewModel> providers)
|
|
|
|
|
{
|
|
|
|
|
int numOfProperties = typeof(ProviderViewModel).GetProperties().Length;
|
|
|
|
|
for (int i = 0; i < providers.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
providers[i].SupplyDateTime = providers[i].SupplyDate.ToString();
|
|
|
|
|
for (int j = 0; j < numOfProperties; ++j)
|
|
|
|
|
{
|
|
|
|
|
controlDataTreeCell.AddCell(j, providers[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-02 09:16:50 +04:00
|
|
|
|
private void AddProviderItem_Click(object sender, EventArgs e)
|
2023-11-02 02:24:20 +04:00
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormProvider));
|
|
|
|
|
if (service is FormProvider form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EditProviderItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (controlDataTreeCell.GetSelectedObject<ProviderViewModel>() == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormProvider));
|
|
|
|
|
if (service is FormProvider form)
|
|
|
|
|
{
|
|
|
|
|
form.Id = Convert.ToInt32(controlDataTreeCell.GetSelectedObject<ProviderViewModel>()?.Id);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveProviderItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (controlDataTreeCell.GetSelectedObject<ProviderViewModel>() == null) return;
|
|
|
|
|
if (MessageBox.Show(
|
|
|
|
|
"Вы хотите удалить выбранный элементы?",
|
|
|
|
|
"Вопрос",
|
|
|
|
|
MessageBoxButtons.YesNo,
|
|
|
|
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
_providerStorage.Delete(new(controlDataTreeCell.GetSelectedObject<ProviderViewModel>()));
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetSimpleDocumentItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
|
|
|
|
SaveFileDialog saveFileDialog = new()
|
|
|
|
|
{
|
|
|
|
|
Filter = "PDF Files|*.pdf"
|
|
|
|
|
};
|
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
string filePath = saveFileDialog.FileName;
|
|
|
|
|
string documentTitle = "Поставщики";
|
|
|
|
|
List<string> textData = new();
|
|
|
|
|
|
|
|
|
|
foreach (var provider in _providerStorage.GetFullList())
|
|
|
|
|
{
|
|
|
|
|
textData.Add(provider.Name + ": " + provider.Furniture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
pdfGeneratorControl.GeneratePdf(filePath, documentTitle, textData);
|
|
|
|
|
MessageBox.Show("PDF-документ успешно сохранен.", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
$"Ошибка при создании PDF-документа: {ex.Message}",
|
|
|
|
|
"Ошибка",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetTableDocumentItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
List<ProviderViewModel> providersList = _providerStorage.GetFullList();
|
|
|
|
|
foreach (var provider in providersList)
|
|
|
|
|
{
|
|
|
|
|
if (provider.SupplyDate == null)
|
|
|
|
|
{
|
|
|
|
|
provider.SupplyDateTime = "Поставок не было";
|
|
|
|
|
provider.SupplyDate = DateTime.MinValue;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
provider.SupplyDateTime = provider.SupplyDate.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-02 09:38:50 +04:00
|
|
|
|
var columnConfigs = new List<ColumnConfig>
|
|
|
|
|
{
|
|
|
|
|
new ColumnConfig { Width = 50f, PropertyName = "Id" },
|
|
|
|
|
new ColumnConfig { Width = 50f, PropertyName = "Name" },
|
|
|
|
|
new ColumnConfig { Width = 50f, PropertyName = "Type" },
|
|
|
|
|
new ColumnConfig { Width = 70f, PropertyName = "SupplyDateTime" },
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-02 02:24:20 +04:00
|
|
|
|
SaveFileDialog saveFileDialog = new()
|
|
|
|
|
{
|
|
|
|
|
Filter = "Excel Files|*.xlsx"
|
|
|
|
|
};
|
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-11-02 09:38:50 +04:00
|
|
|
|
componentWithSettings.GenerateExcelDocument(saveFileDialog.FileName, "Отчет по всем поставщикам", columnConfigs, 25f, 35f, providersList);
|
2023-11-02 02:24:20 +04:00
|
|
|
|
MessageBox.Show(
|
|
|
|
|
"Excel-документ успешно сохранен.",
|
|
|
|
|
"Успех",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
$"Ошибка при создании Excel-документа: {ex.Message}",
|
|
|
|
|
"Ошибка",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetDiagramDocumentItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var providersList = _providerStorage
|
|
|
|
|
.GetFullList()
|
|
|
|
|
.Where(item => item.SupplyDate?.Year == DateTime.Now.Year)
|
|
|
|
|
.GroupBy(item => item.Type)
|
|
|
|
|
.Select(group => new
|
|
|
|
|
{
|
|
|
|
|
Type = group.Key,
|
|
|
|
|
Date = group.Select(item => item.SupplyDate),
|
|
|
|
|
Count = (double)group.Count(),
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-02 09:16:50 +04:00
|
|
|
|
List<double> results = new();
|
|
|
|
|
List<string> names = new();
|
2023-11-02 02:24:20 +04:00
|
|
|
|
|
|
|
|
|
foreach (var provider in providersList)
|
|
|
|
|
{
|
2023-11-02 09:16:50 +04:00
|
|
|
|
results.Add(provider.Count);
|
|
|
|
|
names.Add(provider.Type);
|
2023-11-02 02:24:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SaveFileDialog saveFileDialog = new()
|
|
|
|
|
{
|
|
|
|
|
Filter = "Word Files|*.docx"
|
|
|
|
|
};
|
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2023-11-02 09:38:50 +04:00
|
|
|
|
SimpleCircleDiagram simpleCircleDiagram = new(saveFileDialog.FileName, "Круговая диаграмма", "Количество поставщиков в разрезе типа организации",
|
2023-11-02 09:16:50 +04:00
|
|
|
|
EnumAreaLegend.Right, new() { new DataCircleDiagram("Типы организации", results.ToArray()) });
|
|
|
|
|
simpleCircleDiagram.NameData = names.ToArray();
|
2023-11-02 02:24:20 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-11-02 09:16:50 +04:00
|
|
|
|
//componentDocumentWithChartPieWord.CreateDoc(config);
|
|
|
|
|
circleDiagram.AddCircleDiagram(simpleCircleDiagram);
|
2023-11-02 02:24:20 +04:00
|
|
|
|
MessageBox.Show(
|
|
|
|
|
"Word-документ успешно сохранен.",
|
|
|
|
|
"Успех",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
$"Ошибка при создании Word-документа: {ex.Message}",
|
|
|
|
|
"Ошибка",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormMain_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Control)
|
|
|
|
|
{
|
|
|
|
|
switch (e.KeyCode)
|
|
|
|
|
{
|
|
|
|
|
case Keys.A:
|
|
|
|
|
AddProviderItem_Click(sender, e);
|
|
|
|
|
break;
|
|
|
|
|
case Keys.U:
|
|
|
|
|
EditProviderItem_Click(sender, e);
|
|
|
|
|
break;
|
|
|
|
|
case Keys.D:
|
|
|
|
|
RemoveProviderItem_Click(sender, e);
|
|
|
|
|
break;
|
|
|
|
|
case Keys.S:
|
|
|
|
|
GetSimpleDocumentItem_Click(sender, e);
|
|
|
|
|
break;
|
|
|
|
|
case Keys.T:
|
|
|
|
|
GetTableDocumentItem_Click(sender, e);
|
|
|
|
|
break;
|
|
|
|
|
case Keys.C:
|
|
|
|
|
GetDiagramDocumentItem_Click(sender, e);
|
|
|
|
|
break;
|
|
|
|
|
case Keys.M:
|
|
|
|
|
OpenListToolStripMenuItem_Click(sender, e);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenListToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormType));
|
|
|
|
|
if (service is FormType form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|