using Components; using Contracts.BindingModels; using Contracts.BusinessLogicContracts; namespace COP3_ { public partial class FormMain : Form { private readonly IOrderLogic _orderLogic; public FormMain(IOrderLogic orderLogic) { InitializeComponent(); _orderLogic = orderLogic; this.KeyPreview = true; LoadData(); } private void FormMain_Load(object sender, EventArgs e) { LoadData(); } private void LoadData() { try { var orders = _orderLogic.ReadList(null); } catch (Exception ex) { MessageBox.Show($"{ex.Message}"); } } private void Create(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormEdit)); if (!(service is FormEdit form)) { return; } if (form.ShowDialog() == DialogResult.OK) { LoadData(); } } private void Open(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormEdit)); if (!(service is FormEdit form)) { return; } var selectedOrder = listComponent1.GetObjectFromSelectedRow(); form.Id = Convert.ToInt32(selectedOrder.Id); if (form.ShowDialog() == DialogResult.OK) { LoadData(); } } private void Delete(object sender, EventArgs e) { try { var selectedOrder = listComponent1.GetObjectFromSelectedRow(); if (selectedOrder != null) { var result = MessageBox.Show( "Подтвердите удаление записи", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question ); if (result == DialogResult.Yes) { _orderLogic.Delete(new OrderBindingModel { Id = selectedOrder.Id }); MessageBox.Show("Удалено"); LoadData(); } else if (result == DialogResult.No) { MessageBox.Show("Удаление отменено", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); } LoadData(); } LoadData(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void CreateDoc(object sender, EventArgs e) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.Filter = "Word Documents (*.docx)|*.docx"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string filePath = saveFileDialog.FileName; string title = "заказы, которые оплачены полностью за счет скидок :D"; string[] data; try { var orders = _orderLogic.ReadList(null); if (orders != null) { /* // Фильтруем заказы, где сумма заказа равна null или пустой строке var freeOrders = orders .Where(x => string.IsNullOrEmpty(x.OrderDeliveryTime)) .Select(x => $"ID: {x.Id}, ФИО: {x.FIO}, Статус заказа: {x.OrderDestination}, Описание заказа: {x.OrderPath}") .ToList(); if (freeOrders.Count == 0) { MessageBox.Show("Нет заказов, оплаченных скидками."); return; } */ // Преобразуем список в массив строк для передачи в метод //data = freeOrders.ToArray(); // Создаем документ Word // bigTextWordNoVisibleComponent1.CreateAndSaveDocument(filePath, title, data); MessageBox.Show("Успешно :D проверяй наличие файла..."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } private void CreateTableDoc(object sender, EventArgs e) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.Filter = "Excel Files (*.xlsx)|*.xlsx"; saveFileDialog.Title = "Сохранить диаграмму в Excel"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string filePath = saveFileDialog.FileName; try { var orders = _orderLogic.ReadList(null); if (orders == null || !orders.Any()) { MessageBox.Show("Нет данных для создания диаграммы."); return; } /* var groupedData = orders .Where(o => o.OrderDeliveryTime != null && o.OrderDeliveryTime != "" && o.OrderDeliveryTime != string.Empty) .GroupBy(o => o.OrderDestination) .Select(g => new ComponentExcelWithPieDiagram.ChartData { SeriesName = g.Key, SeriesValue = g.Count() }) .ToList(); if (!groupedData.Any()) { MessageBox.Show("Нет оплаченных заказов."); return; } string title = "Оплаченные заказы по статусам"; string diagramTitle = "Распределение оплаченных заказов"; componentExcelWithPieDiagram1.CreateExcelWithPieChart( filePath, title, diagramTitle, ComponentExcelWithPieDiagram.LegendPosition.Left, groupedData );*/ MessageBox.Show("Файл успешно создан.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show($"Ошибка при создании файла: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } private void CreateDiagramDoc(object sender, EventArgs e) { using (SaveFileDialog fileDialog = new SaveFileDialog()) { fileDialog.Filter = "PDF Files (*.pdf)|*.pdf"; fileDialog.Title = "Сохранить диаграмму в PDF"; if (fileDialog.ShowDialog() == DialogResult.OK) { string filePath = fileDialog.FileName; string fileTitle = "Информация о заказах"; try { var orders = _orderLogic.ReadList(null); /* if (orders == null || !orders.Any()) { MessageBox.Show("Нет данных"); return; } List tables = new List(); string[,] tableData = new string[orders.Count + 1, 5]; // Шапка таблицы tableData[0, 0] = "Идентификатор"; tableData[0, 1] = "ФИО"; tableData[0, 2] = "Статус заказа"; tableData[0, 3] = "Сумма заказов"; tableData[0, 4] = "Описание"; for (int i = 0; i < orders.Count; i++) { var order = orders[i]; tableData[i + 1, 0] = order.Id.ToString(); tableData[i + 1, 1] = order.FIO; tableData[i + 1, 2] = order.OrderDestination; tableData[i + 1, 3] = string.IsNullOrWhiteSpace(order.OrderDeliveryTime) ? "Оплачен скидками" : order.OrderDeliveryTime; tableData[i + 1, 4] = order.OrderPath; } diagramWordNoVisibleComponent1.CreateDocumentWithChart(filePath, fileTitle, "", UserComponentsOption19.DiagramWordNoVisibleComponent.LegendPosition.Bottom, tables); */ MessageBox.Show("Файл успешно создан.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show($"Ошибка при создании файла: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e) { } private void справочникToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormGuide)); if (!(service is FormGuide form)) { return; } if (form.ShowDialog() == DialogResult.OK) { LoadData(); } } } }