все готово, спать

This commit is contained in:
a.puchkina 2024-10-28 23:31:04 +04:00
parent caaa65f204
commit 3729d74f4f
4 changed files with 165 additions and 58 deletions

View File

@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
namespace LibraryAccountingApp_lab3.DatabaseImplement.Models
{
public class BookForExcel
{
public int? Id { get; set; }
[Required]
public string Title { get; set; }
[Required]
public string Author { get; set; }
[Required]
public string Date { get; set; }
}
}

View File

@ -31,7 +31,6 @@
components = new System.ComponentModel.Container();
buttonChooseImage = new Button();
groupBox1 = new GroupBox();
buttonBookDelete = new Button();
buttonAddAuthor = new Button();
textBoxTitle = new TextBox();
buttonBookAdd = new Button();
@ -44,10 +43,12 @@
groupBox2 = new GroupBox();
controlDataTableCellBooks = new ControlsLibraryNet60.Data.ControlDataTableCell();
pdfForImages = new COP_5.PdfForImages(components);
componentDocumentWithChartBarWord1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord(components);
tableComponent1 = new FedComponentLib.NonVisualComponents.TableComponent(components);
componentDocumentWithChartBarWord = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord(components);
tableComponent = new FedComponentLib.NonVisualComponents.TableComponent(components);
buttonPdfCreate = new Button();
groupBox3 = new GroupBox();
buttonChartBarCreate = new Button();
buttonExcelCreate = new Button();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
groupBox3.SuspendLayout();
@ -56,7 +57,7 @@
// buttonChooseImage
//
buttonChooseImage.Anchor = AnchorStyles.None;
buttonChooseImage.Location = new Point(52, 244);
buttonChooseImage.Location = new Point(52, 274);
buttonChooseImage.Margin = new Padding(3, 2, 3, 2);
buttonChooseImage.Name = "buttonChooseImage";
buttonChooseImage.Size = new Size(176, 24);
@ -68,7 +69,6 @@
// groupBox1
//
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBox1.Controls.Add(buttonBookDelete);
groupBox1.Controls.Add(buttonAddAuthor);
groupBox1.Controls.Add(textBoxTitle);
groupBox1.Controls.Add(buttonBookAdd);
@ -86,23 +86,11 @@
groupBox1.TabStop = false;
groupBox1.Text = "Загрузка книги";
//
// buttonBookDelete
//
buttonBookDelete.Anchor = AnchorStyles.None;
buttonBookDelete.BackColor = Color.LightCoral;
buttonBookDelete.Location = new Point(18, 405);
buttonBookDelete.Name = "buttonBookDelete";
buttonBookDelete.Size = new Size(231, 36);
buttonBookDelete.TabIndex = 26;
buttonBookDelete.Text = "Удалить книгу";
buttonBookDelete.UseVisualStyleBackColor = false;
buttonBookDelete.Click += buttonBookDelete_Click;
//
// buttonAddAuthor
//
buttonAddAuthor.Anchor = AnchorStyles.None;
buttonAddAuthor.BackColor = Color.PaleTurquoise;
buttonAddAuthor.Location = new Point(6, 195);
buttonAddAuthor.Location = new Point(6, 216);
buttonAddAuthor.Margin = new Padding(3, 2, 3, 2);
buttonAddAuthor.Name = "buttonAddAuthor";
buttonAddAuthor.Size = new Size(111, 24);
@ -123,7 +111,7 @@
//
buttonBookAdd.Anchor = AnchorStyles.None;
buttonBookAdd.BackColor = Color.YellowGreen;
buttonBookAdd.Location = new Point(18, 363);
buttonBookAdd.Location = new Point(18, 399);
buttonBookAdd.Name = "buttonBookAdd";
buttonBookAdd.Size = new Size(231, 36);
buttonBookAdd.TabIndex = 19;
@ -136,7 +124,7 @@
buttonClearImage.Anchor = AnchorStyles.None;
buttonClearImage.BackColor = Color.Silver;
buttonClearImage.Font = new Font("Segoe UI", 7F, FontStyle.Regular, GraphicsUnit.Point);
buttonClearImage.Location = new Point(139, 303);
buttonClearImage.Location = new Point(139, 333);
buttonClearImage.Name = "buttonClearImage";
buttonClearImage.Size = new Size(127, 27);
buttonClearImage.TabIndex = 19;
@ -147,7 +135,7 @@
// textBoxImage
//
textBoxImage.Anchor = AnchorStyles.None;
textBoxImage.Location = new Point(6, 274);
textBoxImage.Location = new Point(6, 304);
textBoxImage.Name = "textBoxImage";
textBoxImage.ReadOnly = true;
textBoxImage.Size = new Size(243, 23);
@ -157,7 +145,7 @@
//
label2.Anchor = AnchorStyles.None;
label2.AutoSize = true;
label2.Location = new Point(6, 151);
label2.Location = new Point(6, 172);
label2.Name = "label2";
label2.Size = new Size(43, 15);
label2.TabIndex = 22;
@ -166,7 +154,7 @@
// controlSelectedComboBoxSingleAuthor
//
controlSelectedComboBoxSingleAuthor.Anchor = AnchorStyles.None;
controlSelectedComboBoxSingleAuthor.Location = new Point(6, 169);
controlSelectedComboBoxSingleAuthor.Location = new Point(6, 190);
controlSelectedComboBoxSingleAuthor.Margin = new Padding(5, 3, 5, 3);
controlSelectedComboBoxSingleAuthor.Name = "controlSelectedComboBoxSingleAuthor";
controlSelectedComboBoxSingleAuthor.SelectedElement = "";
@ -177,7 +165,7 @@
//
dateTextBoxDate.Anchor = AnchorStyles.None;
dateTextBoxDate.DatePattern = null;
dateTextBoxDate.Location = new Point(6, 77);
dateTextBoxDate.Location = new Point(6, 88);
dateTextBoxDate.Name = "dateTextBoxDate";
dateTextBoxDate.Size = new Size(243, 57);
dateTextBoxDate.TabIndex = 21;
@ -197,7 +185,7 @@
groupBox2.Controls.Add(controlDataTableCellBooks);
groupBox2.Location = new Point(288, 12);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(527, 286);
groupBox2.Size = new Size(527, 330);
groupBox2.TabIndex = 19;
groupBox2.TabStop = false;
groupBox2.Text = "Вывод книг";
@ -209,14 +197,14 @@
controlDataTableCellBooks.Margin = new Padding(4, 3, 4, 3);
controlDataTableCellBooks.Name = "controlDataTableCellBooks";
controlDataTableCellBooks.SelectedRowIndex = -1;
controlDataTableCellBooks.Size = new Size(517, 261);
controlDataTableCellBooks.Size = new Size(517, 311);
controlDataTableCellBooks.TabIndex = 0;
//
// buttonPdfCreate
//
buttonPdfCreate.Location = new Point(20, 35);
buttonPdfCreate.Location = new Point(31, 35);
buttonPdfCreate.Name = "buttonPdfCreate";
buttonPdfCreate.Size = new Size(132, 48);
buttonPdfCreate.Size = new Size(140, 48);
buttonPdfCreate.TabIndex = 20;
buttonPdfCreate.Text = "Создать PDF с обложками";
buttonPdfCreate.UseVisualStyleBackColor = true;
@ -224,14 +212,36 @@
//
// groupBox3
//
groupBox3.Controls.Add(buttonChartBarCreate);
groupBox3.Controls.Add(buttonExcelCreate);
groupBox3.Controls.Add(buttonPdfCreate);
groupBox3.Location = new Point(291, 304);
groupBox3.Location = new Point(291, 370);
groupBox3.Name = "groupBox3";
groupBox3.Size = new Size(524, 173);
groupBox3.Size = new Size(524, 107);
groupBox3.TabIndex = 21;
groupBox3.TabStop = false;
groupBox3.Text = "Формирование отчётов";
//
// buttonChartBarCreate
//
buttonChartBarCreate.Location = new Point(356, 35);
buttonChartBarCreate.Name = "buttonChartBarCreate";
buttonChartBarCreate.Size = new Size(140, 48);
buttonChartBarCreate.TabIndex = 22;
buttonChartBarCreate.Text = "Создать гистограмму в Word";
buttonChartBarCreate.UseVisualStyleBackColor = true;
buttonChartBarCreate.Click += buttonChartBarCreate_Click;
//
// buttonExcelCreate
//
buttonExcelCreate.Location = new Point(194, 35);
buttonExcelCreate.Name = "buttonExcelCreate";
buttonExcelCreate.Size = new Size(140, 48);
buttonExcelCreate.TabIndex = 21;
buttonExcelCreate.Text = "Создать Excel таблицу по всем книгам";
buttonExcelCreate.UseVisualStyleBackColor = true;
buttonExcelCreate.Click += buttonExcelCreate_Click;
//
// FormLibrary
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -265,11 +275,12 @@
private GroupBox groupBox2;
private ControlsLibraryNet60.Data.ControlDataTableCell controlDataTableCellBooks;
private Button buttonAddAuthor;
private Button buttonBookDelete;
private COP_5.PdfForImages pdfForImages;
private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord componentDocumentWithChartBarWord1;
private FedComponentLib.NonVisualComponents.TableComponent tableComponent1;
private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord componentDocumentWithChartBarWord;
private FedComponentLib.NonVisualComponents.TableComponent tableComponent;
private Button buttonPdfCreate;
private GroupBox groupBox3;
private Button buttonExcelCreate;
private Button buttonChartBarCreate;
}
}

View File

@ -3,8 +3,11 @@ using ControlsLibraryNet60.Data;
using ControlsLibraryNet60.Models;
using COP_5;
using COP_5.PdfHelper;
using COP_5.TestClasses;
using DocumentFormat.OpenXml.Office2010.Excel;
using FedComponentLib;
using FedComponentLib.NonVisualComponents.HelperModels;
using FedComponentLib.NonVisualComponents;
using LibraryAccountingApp_lab3.Contracts.BindingModels;
using LibraryAccountingApp_lab3.Contracts.BusinessLogicsContracts;
using LibraryAccountingApp_lab3.Contracts.StorageContracts;
@ -12,6 +15,7 @@ using LibraryAccountingApp_lab3.Contracts.ViewModels;
using LibraryAccountingApp_lab3.DatabaseImplement.Models;
using Microsoft.IdentityModel.Abstractions;
using System.Windows.Forms;
using ComponentsLibraryNet60.Models;
namespace LibraryAccountingApp_lab3
{
@ -172,29 +176,6 @@ namespace LibraryAccountingApp_lab3
}
}
private void buttonBookDelete_Click(object sender, EventArgs e)
{
//if (controlDataTableCellBooks.SelectedRowIndex != -1)
//{
// if (MessageBox.Show("Óäàëèòü êíèãó?", "Âîïðîñ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
// {
// int id = controlDataTableCellBooks.SelectedRowIndex;
// var model = controlDataTableCellBooks.GetSelectedObject();
// try
// {
// _bookLogic.Delete(new BookBindingModel
// {
// Id = id
// });
// LoadDataInTable();
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
// }
// }
//}
}
private void buttonChooseImage_Click(object sender, EventArgs e)
{
using OpenFileDialog openFileDialog = new OpenFileDialog
@ -266,5 +247,102 @@ namespace LibraryAccountingApp_lab3
MessageBox.Show($"Îøèáêà çàãðóçêè äàííûõ: {ex.Message}");
}
}
private void buttonExcelCreate_Click(object sender, EventArgs e)
{
try
{
string filepath = "D:\\ULSTU\\COP\\ExcelWithBooks.xlsx";
string title = "Òàáëèöà ñ êíèãàìè áèáëèîòåêè";
List<MergeCells> mergeCells = new List<MergeCells>()
{
new MergeCells("Êíèãà", new int[] { 1, 2 }),
};
List<ColumnInfo> columns = new List<ColumnInfo>()
{
new ColumnInfo("Id", "Id", 10),
new ColumnInfo("Title", "Íàçâàíèå", 30),
new ColumnInfo("Author", "Àâòîð", 30),
new ColumnInfo("Date", "Äàòà", 20),
};
var list = _bookLogic.Read(null);
List<BookForExcel> data = new List<BookForExcel>();
if (list != null)
{
foreach (var book in list)
{
data.Add(new BookForExcel
{
Id = book.Id,
Title = book.Title,
Author = book.Author,
Date = book.Date
});
}
controlDataTableCellBooks.Update();
}
tableComponent.CreateDocument(filepath, title,
mergeCells, columns,
data);
MessageBox.Show("Excel óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Îøèáêà çàãðóçêè äàííûõ: {ex.Message}");
}
}
private void buttonChartBarCreate_Click(object sender, EventArgs e)
{
try
{
List<(int AuthorId, double Value)> listData = new List<(int AuthorId, double Value)>();
(int AuthorId, double Value) item = default;
// Ïîëó÷åíèå ñïèñêà àâòîðîâ
var authors = _authorLogic.Read(null);
if (authors != null)
{
// Ïîëó÷åíèå ñïèñêà êíèã
var books = _bookLogic.Read(null);
if (books != null)
{
// Ïîäñ÷åò êîëè÷åñòâà êíèã äëÿ êàæäîãî àâòîðà
foreach (var author in authors)
{
int bookCount = books.Count(book => book.Author == author.Name);
listData.Add((author.Id, bookCount));
}
}
}
Dictionary<string, List<(int AuthorId, double Value)>> data = new()
{
{ "Àâòîðû", listData }
};
var config = new ComponentDocumentWithChartConfig
{
ChartTitle = "Ñêîëüêî êíèã íàïèñàëè àâòîðû",
FilePath = "D:\\ULSTU\\COP\\WordChartBar.docx",
Header = "Ãèñòîãðàììà â Word",
Data = data,
LegendLocation = ComponentsLibraryNet60.Models.Location.Rigth,
};
componentDocumentWithChartBarWord.CreateDoc(config);
MessageBox.Show("Word óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Îøèáêà çàãðóçêè äàííûõ: {ex.Message}");
}
}
}
}

View File

@ -120,10 +120,10 @@
<metadata name="pdfForImages.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>295, 17</value>
</metadata>
<metadata name="componentDocumentWithChartBarWord1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="componentDocumentWithChartBarWord.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="tableComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="tableComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>428, 17</value>
</metadata>
</root>