КУПИТЕ МНЕ ЛИЦЕНЗИЮ ЭКСЕЛЯ
This commit is contained in:
parent
5fdba2649f
commit
2b6207f365
22
Laba3/MainForm.Designer.cs
generated
22
Laba3/MainForm.Designer.cs
generated
@ -42,12 +42,26 @@
|
||||
pdfImg = new Library14Petrushin.PdfImg(components);
|
||||
wordDiagramComponent = new Library15Gerimovich.WordDiagramComponent(components);
|
||||
componentTable = new WinFormsLibrary1.ComponentTable(components);
|
||||
saveFileDialog = new SaveFileDialog(); // Инициализация SaveFileDialog
|
||||
saveFileDialogPdf = new SaveFileDialog(); // Инициализация SaveFileDialog
|
||||
|
||||
// Настройка SaveFileDialog
|
||||
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
|
||||
saveFileDialog.Title = "Save PDF Document";
|
||||
saveFileDialog.FileName = "Products.pdf";
|
||||
saveFileDialogPdf.Filter = "PDF Files (*.pdf)|*.pdf";
|
||||
saveFileDialogPdf.Title = "Save PDF Document";
|
||||
saveFileDialogPdf.FileName = "Products.pdf";
|
||||
|
||||
saveFileDialogWord = new SaveFileDialog(); // Инициализация SaveFileDialog
|
||||
|
||||
// Настройка SaveFileDialog
|
||||
saveFileDialogWord.Filter = "Word Files (*.docx)|*.docx";
|
||||
saveFileDialogWord.Title = "Save Word Document";
|
||||
saveFileDialogWord.FileName = "Diagram.docx";
|
||||
|
||||
saveFileDialogExel = new SaveFileDialog(); // Инициализация SaveFileDialog
|
||||
|
||||
// Настройка SaveFileDialog
|
||||
saveFileDialogExel.Filter = "Excel Files (*.xlsx)|*.xlsx";
|
||||
saveFileDialogExel.Title = "Save Excel Document";
|
||||
saveFileDialogExel.FileName = "ProductReport.xlsx";
|
||||
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
|
@ -4,6 +4,10 @@ using View;
|
||||
using System.Windows.Forms;
|
||||
using Data.Models;
|
||||
using Library14Petrushin;
|
||||
using Library15Gerimovich.OfficePackage.HelperModels;
|
||||
using Library15Gerimovich;
|
||||
using WinFormsLibrary1;
|
||||
using WinFormsLibrary1.Models;
|
||||
|
||||
namespace Laba3
|
||||
{
|
||||
@ -11,7 +15,9 @@ namespace Laba3
|
||||
{
|
||||
private readonly IProductRepository _productRepository;
|
||||
private readonly IManufacturerRepository _manufacturerRepository;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private SaveFileDialog saveFileDialogPdf;
|
||||
private SaveFileDialog saveFileDialogWord;
|
||||
private SaveFileDialog saveFileDialogExel;
|
||||
|
||||
public MainForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository)
|
||||
{
|
||||
@ -24,12 +30,12 @@ namespace Laba3
|
||||
|
||||
private void InitializeOutputTableResults()
|
||||
{
|
||||
outputTableResults.ConfigureColumns(new List<Library15Gerimovich.ColumnInfo>
|
||||
outputTableResults.ConfigureColumns(new List<ColumnInfo>
|
||||
{
|
||||
new Library15Gerimovich.ColumnInfo("", 0, false, "Id"),
|
||||
new Library15Gerimovich.ColumnInfo("Name", 150, true, "Name"),
|
||||
new Library15Gerimovich.ColumnInfo("ManufacturerNameManufacturerName", 150, true, "ManufacturerName"),
|
||||
new Library15Gerimovich.ColumnInfo("DeliveryDate", 50, true, "DeliveryDate"),
|
||||
new ColumnInfo("", 0, false, "Id"),
|
||||
new ColumnInfo("Name", 150, true, "Name"),
|
||||
new ColumnInfo("ManufacturerNameManufacturerName", 150, true, "ManufacturerName"),
|
||||
new ColumnInfo("DeliveryDate", 50, true, "DeliveryDate"),
|
||||
});
|
||||
|
||||
}
|
||||
@ -94,13 +100,13 @@ namespace Laba3
|
||||
if (images.Count > 0)
|
||||
{
|
||||
// Показываем диалоговое окно для выбора пути сохранения
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
if (saveFileDialogPdf.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
// Создаем компонент PdfImg
|
||||
var pdfImg = new Library14Petrushin.PdfImg();
|
||||
|
||||
// Путь для сохранения PDF-документа
|
||||
string fileName = saveFileDialog.FileName;
|
||||
string fileName = saveFileDialogPdf.FileName;
|
||||
|
||||
// Заголовок документа
|
||||
string documentTitle = "Product Images";
|
||||
@ -118,12 +124,75 @@ namespace Laba3
|
||||
|
||||
private void createCustomTableDocumentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Реализация создания документа с настраиваемой таблицей
|
||||
// Получаем все продукты из базы данных
|
||||
var products = GetAllProducts();
|
||||
|
||||
if (products.Count > 0)
|
||||
{
|
||||
// Показываем диалоговое окно для выбора пути сохранения
|
||||
if (saveFileDialogExel.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
// Создаем объекты MergeCell и Column
|
||||
var mergeCells = new List<MergeCell>
|
||||
{
|
||||
new MergeCell("Product Information", new int[] { 0, 1, 2, 3 })
|
||||
};
|
||||
|
||||
var columns = new List<Column>
|
||||
{
|
||||
new Column("ID", "Id", 10),
|
||||
new Column("Name", "Name", 20),
|
||||
new Column("Manufacturer", "ManufacturerName", 20),
|
||||
new Column("Delivery Date", "DeliveryDate", 20)
|
||||
};
|
||||
|
||||
|
||||
// Создаем компонент ComponentTable
|
||||
var componentTable = new ComponentTable();
|
||||
|
||||
// Создаем документ Excel
|
||||
componentTable.CreateDocument(saveFileDialogExel.FileName, "Product Report", mergeCells, columns, products);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("No products found in the database.");
|
||||
}
|
||||
}
|
||||
|
||||
private void createChartDocumentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Реализация создания документа с диаграммой
|
||||
// Получаем данные о количестве продукции каждого производителя
|
||||
var productCounts = GetProductCountsByManufacturer();
|
||||
|
||||
if (productCounts.Count > 0)
|
||||
{
|
||||
// Показываем диалоговое окно для выбора пути сохранения
|
||||
if (saveFileDialogWord.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
// Создаем объект WordDiagramInfo
|
||||
var diagramInfo = new WordDiagramInfo
|
||||
{
|
||||
FileName = saveFileDialogWord.FileName,
|
||||
Title = "Product Count by Manufacturer",
|
||||
ChartTitle = "Product Count",
|
||||
LegendLocation = Library15Gerimovich.OfficePackage.HelperEnums.WordDiagramLegendLocation.Top,
|
||||
Series = new WordDiagramSeries
|
||||
{
|
||||
SeriesName = "Product Count",
|
||||
Data = productCounts
|
||||
}
|
||||
};
|
||||
|
||||
// Создаем диаграмму в Word
|
||||
wordDiagramComponent.CreateDiagram(diagramInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("No products found in the database.");
|
||||
}
|
||||
}
|
||||
|
||||
private void MainForm_KeyDown(object sender, KeyEventArgs e)
|
||||
@ -174,5 +243,30 @@ namespace Laba3
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
private Dictionary<string, double> GetProductCountsByManufacturer()
|
||||
{
|
||||
var productCounts = new Dictionary<string, double>();
|
||||
var products = _productRepository.GetAllProducts();
|
||||
|
||||
foreach (var product in products)
|
||||
{
|
||||
if (productCounts.ContainsKey(product.ManufacturerName))
|
||||
{
|
||||
productCounts[product.ManufacturerName]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
productCounts[product.ManufacturerName] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return productCounts;
|
||||
}
|
||||
|
||||
private List<Product> GetAllProducts()
|
||||
{
|
||||
return _productRepository.GetAllProducts().ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user