181 lines
6.6 KiB
C#
Raw Normal View History

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;
2024-10-22 19:58:21 +04:00
using ComponentsLibraryNet60;
2024-10-23 15:53:54 +04:00
using ComponentsLibraryNet60.Models;
using Contracts.BindingModels;
2024-10-22 19:58:21 +04:00
using Contracts.BusinessLogicsContracts;
using Contracts.ViewModels;
using ControlsLibraryNet60.Data;
using ControlsLibraryNet60.Models;
namespace Forms
{
public partial class MainForm : Form
{
2024-10-22 19:58:21 +04:00
private readonly IProviderLogic _logic;
2024-10-23 15:53:54 +04:00
private readonly IOrganisationTypeLogic _ologic;
2024-10-22 19:58:21 +04:00
2024-10-23 15:53:54 +04:00
public MainForm(IProviderLogic logic, IOrganisationTypeLogic ologic)
{
InitializeComponent();
2024-10-22 19:58:21 +04:00
_logic = logic;
2024-10-23 15:53:54 +04:00
_ologic = ologic;
TreeConfig();
2024-10-22 19:58:21 +04:00
LoadData();
}
2024-10-23 15:53:54 +04:00
private void TreeConfig()
{
DataTreeNodeConfig treeConfig = new();
treeConfig.NodeNames = new();
treeConfig.NodeNames.Enqueue("OrganisationType");
treeConfig.NodeNames.Enqueue("DateLastDelivery");
treeConfig.NodeNames.Enqueue("Id");
treeConfig.NodeNames.Enqueue("Name");
controlDataTreeTable.LoadConfig(treeConfig);
}
2024-10-22 19:58:21 +04:00
private void LoadData()
{
var list = _logic.ReadList(null);
if (list != null)
{
2024-10-23 15:53:54 +04:00
controlDataTreeTable.Clear();
2024-10-22 19:58:21 +04:00
controlDataTreeTable.AddTable(list);
}
}
private void organisationTypesToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(OrganisationTypeForm));
if (service is OrganisationTypeForm form)
{
form.ShowDialog();
}
}
private void addProviderToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(ProviderForm));
if (service is ProviderForm form)
{
form.ShowDialog();
}
LoadData();
}
private void editProviderToolStripMenuItem_Click(object sender, EventArgs e)
{
2024-10-23 15:53:54 +04:00
int id = Convert.ToInt32(controlDataTreeTable.GetSelectedObject<ProviderViewModel>()?.Id);
ProviderForm form = new ProviderForm(_logic, _ologic, id);
form.ShowDialog();
LoadData();
}
private void deleteProviderToolStripMenuItem_Click(object sender, EventArgs e)
{
var confirmResult = MessageBox.Show("Вы действительно хотите удалить запись?", "Подтвердите действие",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
if (confirmResult == DialogResult.Yes)
2024-10-22 19:58:21 +04:00
{
2024-10-23 15:53:54 +04:00
_logic.Delete(new ProviderBindingModel
2024-10-22 19:58:21 +04:00
{
2024-10-23 15:53:54 +04:00
Id = Convert.ToInt32(controlDataTreeTable.GetSelectedObject<ProviderViewModel>()?.Id),
});
LoadData();
}
}
private void createPdfToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.ShowDialog();
string path = saveFileDialog.FileName + ".pdf";
var list = _logic.ReadList(null);
if (list != null)
{
List<string> strings = new List<string> { };
foreach (var item in list)
{
strings.Add($"{item.Name} : {item.FurnitureType}");
}
largeTextComponent.CreateDocument(path, $"Отчет за {DateTime.Now.Year}", strings);
}
}
private void createExcelToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.ShowDialog();
string path = saveFileDialog.FileName + ".xlsx";
var list = _logic.ReadList(null);
var widths = new List<(int Column, int Row)> { (5, 5), (10, 5), (5, 5), (7, 5), (10, 5), };
var headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> {
(0,0,"АЙДИ", "Id"),
(1,0,"Название", "Name"),
(2,0,"Перечень мебели", "FurnitureType"),
(3,0,"Тип организации", "OrganisationType"),
(4,0,"Дата последней доставки", "DateLastDelivery")
};
var conf = new ComponentDocumentWithTableHeaderDataConfig<ProviderViewModel>
{
FilePath = path,
Header = "Отчет по поставщикам",
ColumnsRowsDataCount = (list![0].GetType().GetProperties().Length, list.Count),
UseUnion = false,
ColumnsRowsWidth = widths,
Headers = headers,
Data = list,
};
componentDocumentWithTableMultiHeaderExcel.CreateDoc<ProviderViewModel>(conf);
}
private void createToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.ShowDialog();
string path = saveFileDialog.FileName + ".docx";
var list = _logic.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 _ologic.ReadList(null)!)
{
int sum = 0;
foreach(var item in list)
{
if(item.OrganisationType == type.Name)
{
sum++;
}
2024-10-22 19:58:21 +04:00
}
2024-10-23 15:53:54 +04:00
header += $"{index} - {type.Name}\n";
if (sum != 0) data.Add((index, sum));
index++;
2024-10-22 19:58:21 +04:00
}
2024-10-23 15:53:54 +04:00
chart.Add("ИП", data);
var conf = new ComponentDocumentWithChartConfig
{
FilePath = path,
Header = header,
ChartTitle = "Диаграмма по типам организаций",
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
Data = chart,
};
componentDocumentWithChartPieWord.CreateDoc(conf);
}
}
}