using Contracts.BindlingModels; using Contracts.BusinessLogicContracts; using Contracts.ViewModels; using Controls; using ControlsLibraryNet60.Data; using ControlsLibraryNet60.Models; using CustomComponents; using CustomComponents.NonViewComponents.Enums; using CustomComponents.NonViewComponents.SupportClasses; using CustomComponents.NonViewComponents; 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 DatabaseImplement.Models; using ComponentsLibraryNet60.DocumentWithTable; using ComponentsLibraryNet60.Models; using NotVisualComponent.Models; using NotVisualComponent; 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()?.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()?.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 = 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(); var series = new List { new() { SeriesName = "Количество доставок", ValuesY = valuesY, Color = Color.FromArgb(100, 150, 200) } }; pieChartWord.CreateDiagramDocument(new PieChartData() { FileName = path, DocumentTitle = "Диаграмма", DiagramTitle = "Количество доставок по типам", LegendLayout = PieChartLegendAlign.Bottom, CategoriesX = categoriesX, SeriesData = series }); MessageBox.Show("Отчет готов"); } private void excelОтчётToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.ShowDialog(); string path = saveFileDialog.FileName + ".xlsx"; var list = _dlogic.ReadList(null); excelHardTable.CreateDoc(new TableWithHeaderConfig { FilePath = path, 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("Отчет готов"); } } }