2023-12-12 16:23:04 +04:00
|
|
|
|
using ComponentsLibraryNet60.Models;
|
|
|
|
|
using Contracts.BindingModels;
|
|
|
|
|
using Contracts.BusinessLogicContracts;
|
|
|
|
|
using Contracts.SearchModels;
|
|
|
|
|
using Contracts.ViewModels;
|
|
|
|
|
using CustomComponents;
|
|
|
|
|
using KOP_Labs.Classes;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Unity;
|
|
|
|
|
using ViewComponents.NotVisualComponents;
|
|
|
|
|
|
2023-11-29 20:58:13 +04:00
|
|
|
|
namespace Library
|
|
|
|
|
{
|
|
|
|
|
public partial class FormMain : Form
|
|
|
|
|
{
|
2023-12-12 16:23:04 +04:00
|
|
|
|
private readonly IBookLogic _bookLogic;
|
|
|
|
|
private readonly IAuthorLogic _authorLogic;
|
|
|
|
|
public FormMain(IBookLogic bookLogic, IAuthorLogic authorLogic)
|
2023-11-29 20:58:13 +04:00
|
|
|
|
{
|
2023-12-12 16:23:04 +04:00
|
|
|
|
_bookLogic = bookLogic;
|
|
|
|
|
_authorLogic = authorLogic;
|
2023-11-29 20:58:13 +04:00
|
|
|
|
InitializeComponent();
|
2023-12-12 16:23:04 +04:00
|
|
|
|
tableComponent.TableConfiguration(5, new List<TableParameters>
|
|
|
|
|
{
|
|
|
|
|
new TableParameters("Id", 80, false, "Id"),
|
|
|
|
|
new TableParameters("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 100, true, "Name"),
|
|
|
|
|
new TableParameters("<22><><EFBFBD><EFBFBD><EFBFBD>", 180, true, "Author"),
|
|
|
|
|
new TableParameters("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 80, false, "PicturePath"),
|
|
|
|
|
new TableParameters("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 150, true, "PublicationDate")
|
|
|
|
|
});
|
|
|
|
|
tableComponent.ContextMenuStrip = contextMenuStrip;
|
|
|
|
|
}
|
|
|
|
|
private void FormMain_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
tableComponent.ClearRows();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _bookLogic.Read(null);
|
|
|
|
|
foreach (var row in list)
|
|
|
|
|
{
|
|
|
|
|
tableComponent.AddRow(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddNewElement()
|
|
|
|
|
{
|
|
|
|
|
var form = Program.Container.Resolve<FormBook>();
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateElement()
|
|
|
|
|
{
|
|
|
|
|
var form = Program.Container.Resolve<FormBook>();
|
|
|
|
|
var selectedBook = tableComponent.GetSelectedObject<BookSearchModel>();
|
|
|
|
|
if (selectedBook != null)
|
|
|
|
|
{
|
|
|
|
|
form.Id = Convert.ToInt32(selectedBook.Id);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeleteElement()
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
var selectedBook = tableComponent.GetSelectedObject<BookSearchModel>();
|
|
|
|
|
int id = Convert.ToInt32(selectedBook.Id);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_bookLogic.Delete(new BookBindingModel { Id = id });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreatePdf()
|
|
|
|
|
{
|
|
|
|
|
string fileName = "";
|
|
|
|
|
using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" })
|
|
|
|
|
{
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
fileName = dialog.FileName.ToString();
|
|
|
|
|
MessageBox.Show("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<string> images = new List<string>();
|
|
|
|
|
var list = _bookLogic.Read(null);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
images.Add(item.PicturePath);
|
|
|
|
|
}
|
|
|
|
|
string[] imagesArray = images.ToArray();
|
|
|
|
|
|
|
|
|
|
pdfImages.CreatePdfDoc(new ImagesForPDF(fileName, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>", imagesArray));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateExcel()
|
|
|
|
|
{
|
|
|
|
|
string fileName = "";
|
|
|
|
|
using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" })
|
|
|
|
|
{
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
fileName = dialog.FileName.ToString();
|
|
|
|
|
MessageBox.Show("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<(int Column, int Row)> width = new List<(int, int)>() { (30, 0), (30, 0), (30, 0), (30, 0) };
|
|
|
|
|
List<(int StartIndex, int Count)> column_union = new List<(int, int)>() { (1, 2) };
|
|
|
|
|
List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> headers =
|
|
|
|
|
new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> {
|
|
|
|
|
(0,0, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Id"),
|
|
|
|
|
(1,0,"<22><><EFBFBD><EFBFBD><EFBFBD>", ""),
|
|
|
|
|
(1,1,"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Name"),
|
|
|
|
|
(2,1,"<22><><EFBFBD><EFBFBD><EFBFBD>","Author"),
|
|
|
|
|
(3,0,"<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "PublicationDate")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var list = _bookLogic.Read(null);
|
|
|
|
|
ComponentDocumentWithTableHeaderDataConfig<BookViewModel> config = new();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
excelTable1.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig<BookViewModel>()
|
|
|
|
|
{
|
|
|
|
|
Data = list,
|
|
|
|
|
UseUnion = true,
|
|
|
|
|
ColumnsRowsWidth = width,
|
|
|
|
|
ColumnUnion = column_union,
|
|
|
|
|
Headers = headers,
|
|
|
|
|
FilePath = fileName,
|
|
|
|
|
Header = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateWord()
|
|
|
|
|
{
|
|
|
|
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
|
|
|
|
string fileName = "";
|
|
|
|
|
using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" })
|
|
|
|
|
{
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
fileName = dialog.FileName.ToString();
|
|
|
|
|
MessageBox.Show("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else return;
|
|
|
|
|
}
|
|
|
|
|
List<DataHistogramm> dataHistogramms = new List<DataHistogramm>();
|
|
|
|
|
|
|
|
|
|
var list_author = _authorLogic.Read(null);
|
|
|
|
|
var list_book = _bookLogic.Read(null);
|
|
|
|
|
foreach (var nm in list_author)
|
|
|
|
|
{
|
|
|
|
|
int bk_count = 0;
|
|
|
|
|
foreach (var bk in list_book)
|
|
|
|
|
if (bk.Author.Contains(nm.FIO)) bk_count++;
|
|
|
|
|
dataHistogramms.Add(new DataHistogramm(nm.FIO, bk_count));
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
wordHistogramm.CreateHistogramm(new MyHistogramm(fileName, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>", EnumLegends.Top, dataHistogramms));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AddNewElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DeleteElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PDFToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CreatePdf();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ExcelToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CreateExcel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WordToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CreateWord();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var form = Program.Container.Resolve<FormAuthor>();
|
|
|
|
|
form.ShowDialog();
|
2023-11-29 20:58:13 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|