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 ComponentsLibraryNet60; using ComponentsLibraryNet60.Models; using Contracts.BindingModels; using Contracts.BusinessLogicsContracts; using Contracts.ViewModels; using ControlsLibraryNet60.Data; using ControlsLibraryNet60.Models; namespace Forms { public partial class MainForm : Form { private readonly IProviderLogic _logic; private readonly IOrganisationTypeLogic _ologic; public MainForm(IProviderLogic logic, IOrganisationTypeLogic ologic) { InitializeComponent(); _logic = logic; _ologic = ologic; TreeConfig(); LoadData(); } 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); } private void LoadData() { var list = _logic.ReadList(null); if (list != null) { controlDataTreeTable.Clear(); 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) { int id = Convert.ToInt32(controlDataTreeTable.GetSelectedObject()?.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) { _logic.Delete(new ProviderBindingModel { Id = Convert.ToInt32(controlDataTreeTable.GetSelectedObject()?.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 strings = new List { }; foreach (var item in list) { strings.Add($"{item.Name} : {item.FurnitureType}"); } largeTextComponent.CreateDocument(path, $"Отчет за {DateTime.Now.Year}", strings); MessageBox.Show("Отчет готов"); } } 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 { FilePath = path, Header = "Отчет по поставщикам", ColumnsRowsDataCount = (list![0].GetType().GetProperties().Length, list.Count), UseUnion = false, ColumnsRowsWidth = widths, Headers = headers, Data = list, }; componentDocumentWithTableMultiHeaderExcel.CreateDoc(conf); MessageBox.Show("Отчет готов"); } 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> { }; int index = 1; foreach (var type in _ologic.ReadList(null)!) { int sum = 0; foreach(var item in list) { if(item.OrganisationType == 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("Отчет готов"); } } }