Labwork_4 ИСЭбд-21 Мосевнин А. #5

Closed
Aleks_andr435 wants to merge 7 commits from Labwork_4 into Labwork_3
30 changed files with 265 additions and 117 deletions

View File

@ -1,14 +1,24 @@
namespace ProjectLibrary.Entities namespace ProjectLibrary.Entities
{ {
using ProjectLibrary.Entities.Enums; using ProjectLibrary.Entities.Enums;
using System.ComponentModel;
public class Book public class Book
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Автор")]
public string Author { get; private set; } = string.Empty; public string Author { get; private set; } = string.Empty;
[Browsable(false)]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[Browsable(false)]
public BookType TypeBookID { get; set; } = BookType.None; public BookType TypeBookID { get; set; } = BookType.None;
[DisplayName("Название книги (жанр)")]
public string NameTypeBookID => $"{Name}({TypeBookID})";
public static Book CreateEntity(int id, string author, string name, BookType typeBookID = BookType.None) public static Book CreateEntity(int id, string author, string name, BookType typeBookID = BookType.None)
{ {
return new Book return new Book

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -9,9 +10,15 @@ namespace ProjectLibrary.Entites
public class Book_Orders public class Book_Orders
{ {
public int BookID { get; private set; } public int BookID { get; private set; }
public int OrderID { get; private set; } public int OrderID { get; private set; }
[DisplayName("Количество")]
public int Count { get; private set; } public int Count { get; private set; }
public string BookName { get; set; }
public static Book_Orders CreateEntity(int orderID,int bookID, int count ) public static Book_Orders CreateEntity(int orderID,int bookID, int count )
{ {
return new Book_Orders return new Book_Orders

View File

@ -1,9 +1,13 @@
namespace ProjectLibrary.Entites using System.ComponentModel;
namespace ProjectLibrary.Entites
{ {
public class Book_Library public class Book_Library
{ {
public int BookID { get; private set; } public int BookID { get; private set; }
public int LibraryID { get; private set; } public int LibraryID { get; private set; }
[DisplayName("Количество")]
public int Count { get; private set; } public int Count { get; private set; }
public static Book_Library CreateEntity(int libraryID, int bookID, int count) public static Book_Library CreateEntity(int libraryID, int bookID, int count)

View File

@ -1,6 +1,7 @@
using ProjectLibrary.Forms; using ProjectLibrary.Forms;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,14 +11,24 @@ namespace ProjectLibrary.Entites
public class Library public class Library
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Название")]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[DisplayName("Адрес")]
public string Address { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty;
[Browsable(false)]
public IEnumerable<Book_Library> BookLibrary public IEnumerable<Book_Library> BookLibrary
{ {
get; get;
private set; private set;
} }
[DisplayName("Перечень книг в библиотеке")]
public string ListBookInLibrary => BookLibrary != null ?
string.Join("; ", BookLibrary.Select(x => $"{x.BookID},{x.Count}")): string.Empty;
public static Library CreateEntity(int id, string name, string address, IEnumerable<Book_Library> bookLibrary) public static Library CreateEntity(int id, string name, string address, IEnumerable<Book_Library> bookLibrary)
{ {
return new Library return new Library
@ -28,5 +39,13 @@ namespace ProjectLibrary.Entites
BookLibrary = bookLibrary BookLibrary = bookLibrary
}; };
} }
public void SetLibraryForBook(IEnumerable<Book_Library> book_Library)
{
if (book_Library != null && book_Library.Any())
{
BookLibrary = book_Library;
}
}
} }
} }

View File

@ -3,6 +3,7 @@ using Microsoft.VisualBasic;
using ProjectLibrary.Entities; using ProjectLibrary.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,15 +13,32 @@ namespace ProjectLibrary.Entites
public class Orders public class Orders
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Дата взятия книги")]
public DateTime OrderDate { get; private set; } public DateTime OrderDate { get; private set; }
[DisplayName("Дата зврата книги")]
public DateTime ReturnDate { get; private set; } public DateTime ReturnDate { get; private set; }
[Browsable(false)]
public int ReaderID { get; private set; } public int ReaderID { get; private set; }
[DisplayName("ФИО читателя")]
public string ReaderName { get; private set; }
public string BookName { get; set; }
[Browsable(false)]
public IEnumerable<Book_Orders> BookOrders public IEnumerable<Book_Orders> BookOrders
{ {
get; get;
private set; private set;
} = []; } = [];
[DisplayName("Отданные книги")]
public string BookOrdersing => BookOrders != null ?
string.Join(", ", BookOrders.Select(x => $"{x.BookID}({x.Count})")) :
string.Empty;
public static Orders CreateEntity(int id, DateTime returnDate, int readerID, IEnumerable<Book_Orders> bookOrders) public static Orders CreateEntity(int id, DateTime returnDate, int readerID, IEnumerable<Book_Orders> bookOrders)
{ {
@ -33,17 +51,12 @@ namespace ProjectLibrary.Entites
BookOrders = bookOrders BookOrders = bookOrders
}; };
} }
public void SetOrdersOfBooks(IEnumerable<Book_Orders> book_Orders)
public static Orders CreateEntity(TempBookOrders tempBookOrders, IEnumerable<Book_Orders> bookOrders)
{ {
return new Orders if (book_Orders != null && book_Orders.Any())
{ {
Id = tempBookOrders.Id, BookOrders = book_Orders;
OrderDate = tempBookOrders.OrderDate, }
ReturnDate = tempBookOrders.ReturnDate,
ReaderID = tempBookOrders.ReaderID,
BookOrders = bookOrders
};
} }
} }
} }

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entites;
internal class QueryBuilder
{
private readonly StringBuilder _builder;
public QueryBuilder()
{
_builder = new();
}
public QueryBuilder AddCollerction(string condition)
{
if (_builder.Length > 0)
{
_builder.Append("AND");
}
_builder.Append(condition);
return this;
}
public string Build()
{
if (_builder.Length == 0)
{
return string.Empty;
}
return $"WHERE {_builder}";
}
}

View File

@ -1,10 +1,18 @@
namespace ProjectLibrary.Entities using System.ComponentModel;
namespace ProjectLibrary.Entities
{ {
public class Reader public class Reader
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("ФИО")]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[DisplayName("Читательский билет")]
public int ReaderTicket { get; private set; } public int ReaderTicket { get; private set; }
[DisplayName("Дата регистрации")]
public DateTime RegistrationDateRT { get; private set; } // Изменение на DateTime public DateTime RegistrationDateRT { get; private set; } // Изменение на DateTime
public static Reader CreateEntity(int id, string name, int readerTicket) public static Reader CreateEntity(int id, string name, int readerTicket)

View File

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entites;
public class TempBookOrders
{
public int Id { get; set; }
public DateTime OrderDate { get; set; }
public DateTime ReturnDate { get; set; }
public int ReaderID { get; set; }
public int BookID { get; set; }
public int Count { get; set; }
}

View File

@ -1,12 +1,25 @@
namespace ProjectLibrary.Entites using System.ComponentModel;
namespace ProjectLibrary.Entites
{ {
public class TicketExtensions public class TicketExtensions
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Browsable(false)]
public int ReaderID { get; private set; } public int ReaderID { get; private set; }
[DisplayName("ФИО читателя")]
public string ReaderName { get; private set; }
[DisplayName("Последняя дата обновления")]
public DateTime LastUpdateDate { get; private set; } public DateTime LastUpdateDate { get; private set; }
[DisplayName("Следущая дата обновления")]
public DateTime NextUpdateDate { get; private set; } public DateTime NextUpdateDate { get; private set; }
public static TicketExtensions CreateEntity(int id, int readerID, DateTime lastUpdateDate, DateTime nextUpdateDate) public static TicketExtensions CreateEntity(int id, int readerID, DateTime lastUpdateDate, DateTime nextUpdateDate)
{ {
return new TicketExtensions return new TicketExtensions

View File

@ -40,57 +40,52 @@
dataGridViewBooks.AllowUserToAddRows = false; dataGridViewBooks.AllowUserToAddRows = false;
dataGridViewBooks.AllowUserToDeleteRows = false; dataGridViewBooks.AllowUserToDeleteRows = false;
dataGridViewBooks.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridViewBooks.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewBooks.Location = new Point(10, 9); dataGridViewBooks.Location = new Point(11, 12);
dataGridViewBooks.Margin = new Padding(3, 2, 3, 2);
dataGridViewBooks.Name = "dataGridViewBooks"; dataGridViewBooks.Name = "dataGridViewBooks";
dataGridViewBooks.ReadOnly = true; dataGridViewBooks.ReadOnly = true;
dataGridViewBooks.RowHeadersWidth = 51; dataGridViewBooks.RowHeadersWidth = 51;
dataGridViewBooks.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewBooks.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewBooks.Size = new Size(602, 254); dataGridViewBooks.Size = new Size(688, 339);
dataGridViewBooks.TabIndex = 8; dataGridViewBooks.TabIndex = 8;
// //
// buttonAdd // buttonAdd
// //
buttonAdd.Location = new Point(27, 267); buttonAdd.Location = new Point(31, 356);
buttonAdd.Margin = new Padding(3, 2, 3, 2);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(161, 37); buttonAdd.Size = new Size(184, 49);
buttonAdd.TabIndex = 9; buttonAdd.TabIndex = 9;
buttonAdd.Text = "Добавить"; buttonAdd.Text = "Добавить";
buttonAdd.Click += buttonAdd_Click; buttonAdd.Click += buttonAdd_Click;
// //
// buttonUpdate // buttonUpdate
// //
buttonUpdate.Location = new Point(247, 267); buttonUpdate.Location = new Point(282, 356);
buttonUpdate.Margin = new Padding(3, 2, 3, 2);
buttonUpdate.Name = "buttonUpdate"; buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(161, 37); buttonUpdate.Size = new Size(184, 49);
buttonUpdate.TabIndex = 10; buttonUpdate.TabIndex = 10;
buttonUpdate.Text = "Изменить"; buttonUpdate.Text = "Изменить";
buttonUpdate.Click += buttonUpdate_Click; buttonUpdate.Click += buttonUpdate_Click;
// //
// buttonRemove // buttonRemove
// //
buttonRemove.Location = new Point(452, 267); buttonRemove.Location = new Point(517, 356);
buttonRemove.Margin = new Padding(3, 2, 3, 2);
buttonRemove.Name = "buttonRemove"; buttonRemove.Name = "buttonRemove";
buttonRemove.Size = new Size(161, 37); buttonRemove.Size = new Size(184, 49);
buttonRemove.TabIndex = 11; buttonRemove.TabIndex = 11;
buttonRemove.Text = "Удалить"; buttonRemove.Text = "Удалить";
buttonRemove.Click += buttonRemove_Click; buttonRemove.Click += buttonRemove_Click;
// //
// FBooks // FBooks
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(700, 338); ClientSize = new Size(800, 451);
Controls.Add(dataGridViewBooks); Controls.Add(dataGridViewBooks);
Controls.Add(buttonAdd); Controls.Add(buttonAdd);
Controls.Add(buttonUpdate); Controls.Add(buttonUpdate);
Controls.Add(buttonRemove); Controls.Add(buttonRemove);
Margin = new Padding(3, 2, 3, 2);
Name = "FBooks"; Name = "FBooks";
Text = "FBooks"; Text = "Книги";
Load += FBooks_Load; Load += FBooks_Load;
((System.ComponentModel.ISupportInitialize)dataGridViewBooks).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewBooks).EndInit();
ResumeLayout(false); ResumeLayout(false);

View File

@ -20,6 +20,7 @@ namespace ProjectLibrary.Forms
// Привязывает к DataGridView коллекцию книг, полученную из репозитория. // Привязывает к DataGridView коллекцию книг, полученную из репозитория.
// Устанавливает источник данных DataGridView (dataGridViewBooks) как список объектов из ReadBooks(). // Устанавливает источник данных DataGridView (dataGridViewBooks) как список объектов из ReadBooks().
dataGridViewBooks.DataSource = _bookRepository.ReadBooks(); dataGridViewBooks.DataSource = _bookRepository.ReadBooks();
dataGridViewBooks.Columns["Id"].Visible = false;
} }
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)

View File

@ -40,56 +40,53 @@
dataGridViewOrders.AllowUserToAddRows = false; dataGridViewOrders.AllowUserToAddRows = false;
dataGridViewOrders.AllowUserToDeleteRows = false; dataGridViewOrders.AllowUserToDeleteRows = false;
dataGridViewOrders.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridViewOrders.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewOrders.Location = new Point(12, 11); dataGridViewOrders.Location = new Point(14, 15);
dataGridViewOrders.Margin = new Padding(3, 2, 3, 2);
dataGridViewOrders.Name = "dataGridViewOrders"; dataGridViewOrders.Name = "dataGridViewOrders";
dataGridViewOrders.ReadOnly = true; dataGridViewOrders.ReadOnly = true;
dataGridViewOrders.RowHeadersWidth = 51; dataGridViewOrders.RowHeadersWidth = 51;
dataGridViewOrders.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewOrders.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewOrders.Size = new Size(525, 225); dataGridViewOrders.Size = new Size(600, 300);
dataGridViewOrders.TabIndex = 8; dataGridViewOrders.TabIndex = 8;
// //
// buttonAdd // buttonAdd
// //
buttonAdd.Location = new Point(12, 251); buttonAdd.Location = new Point(14, 335);
buttonAdd.Margin = new Padding(3, 2, 3, 2);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(88, 22); buttonAdd.Size = new Size(101, 29);
buttonAdd.TabIndex = 9; buttonAdd.TabIndex = 9;
buttonAdd.Text = "Добавить"; buttonAdd.Text = "Добавить";
buttonAdd.Click += buttonAdd_Click; buttonAdd.Click += buttonAdd_Click;
// //
// buttonUpdate // buttonUpdate
// //
buttonUpdate.Location = new Point(227, 251); buttonUpdate.Location = new Point(259, 335);
buttonUpdate.Margin = new Padding(3, 2, 3, 2);
buttonUpdate.Name = "buttonUpdate"; buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(88, 22); buttonUpdate.Size = new Size(101, 29);
buttonUpdate.TabIndex = 10; buttonUpdate.TabIndex = 10;
buttonUpdate.Text = "Изменить"; buttonUpdate.Text = "Изменить";
buttonUpdate.Click += buttonUpdate_Click; buttonUpdate.Click += buttonUpdate_Click;
// //
// buttonRemove // buttonRemove
// //
buttonRemove.Location = new Point(450, 251); buttonRemove.Location = new Point(514, 335);
buttonRemove.Margin = new Padding(3, 2, 3, 2);
buttonRemove.Name = "buttonRemove"; buttonRemove.Name = "buttonRemove";
buttonRemove.Size = new Size(88, 22); buttonRemove.Size = new Size(101, 29);
buttonRemove.TabIndex = 11; buttonRemove.TabIndex = 11;
buttonRemove.Text = "Удалить"; buttonRemove.Text = "Удалить";
buttonRemove.Click += buttonRemove_Click; buttonRemove.Click += buttonRemove_Click;
// //
// FLibraries // FLibraries
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(562, 283); ClientSize = new Size(642, 377);
Controls.Add(dataGridViewOrders); Controls.Add(dataGridViewOrders);
Controls.Add(buttonAdd); Controls.Add(buttonAdd);
Controls.Add(buttonUpdate); Controls.Add(buttonUpdate);
Controls.Add(buttonRemove); Controls.Add(buttonRemove);
Margin = new Padding(3, 4, 3, 4);
Name = "FLibraries"; Name = "FLibraries";
Text = "FLibraries"; Text = "Библиотеки";
Load += FLibraries_Load; Load += FLibraries_Load;
((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit();
ResumeLayout(false); ResumeLayout(false);

View File

@ -85,6 +85,7 @@ namespace ProjectLibrary.Forms
private void LoadList() private void LoadList()
{ {
dataGridViewOrders.DataSource = _libraryRepository.ReadLibraries(); dataGridViewOrders.DataSource = _libraryRepository.ReadLibraries();
dataGridViewOrders.Columns["Id"].Visible = false;
} }
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {

View File

@ -41,7 +41,7 @@ namespace ProjectLibrary.Forms
_libraryRepository = libraryRepository ?? throw new ArgumentNullException(nameof(libraryRepository)); _libraryRepository = libraryRepository ?? throw new ArgumentNullException(nameof(libraryRepository));
Book.DataSource = bookRepository.ReadBooks(); Book.DataSource = bookRepository.ReadBooks();
Book.DisplayMember = "Name"; Book.DisplayMember = "NameTypeBookID";
Book.ValueMember = "Id"; Book.ValueMember = "Id";
} }

View File

@ -21,7 +21,7 @@ namespace ProjectLibrary.Forms
comboBox.ValueMember = "Id"; comboBox.ValueMember = "Id";
Book.DataSource = bookRepository.ReadBooks(); Book.DataSource = bookRepository.ReadBooks();
Book.DisplayMember = "Name"; comboBox.DisplayMember = "NameTypeBookID";
Book.ValueMember = "Id"; Book.ValueMember = "Id";
} }

View File

@ -82,7 +82,7 @@
buttonCreate.UseVisualStyleBackColor = false; buttonCreate.UseVisualStyleBackColor = false;
buttonCreate.Click += ButtonCreate_Click; buttonCreate.Click += ButtonCreate_Click;
// //
// FormOrderDistributionReport // FOrderDistributionReport
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
@ -92,8 +92,8 @@
Controls.Add(label1); Controls.Add(label1);
Controls.Add(labelFileName); Controls.Add(labelFileName);
Controls.Add(buttonSelectFileName); Controls.Add(buttonSelectFileName);
Name = "FormOrderDistributionReport"; Name = "FOrderDistributionReport";
Text = "FormInvoiceDistributionReport"; Text = "Количество книг в библиотеках";
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }

View File

@ -74,7 +74,7 @@
Controls.Add(buttonAdd); Controls.Add(buttonAdd);
Controls.Add(buttonRemove); Controls.Add(buttonRemove);
Name = "FOrders"; Name = "FOrders";
Text = "FOrders"; Text = "Заказы";
Load += FOrders_Load; Load += FOrders_Load;
((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit();
ResumeLayout(false); ResumeLayout(false);

View File

@ -18,6 +18,9 @@ namespace ProjectLibrary.Forms
private void LoadList() private void LoadList()
{ {
dataGridViewOrders.DataSource = _orderRepository.ReadOrders(); dataGridViewOrders.DataSource = _orderRepository.ReadOrders();
dataGridViewOrders.Columns["Id"].Visible = false;
dataGridViewOrders.Columns["OrderDate"].DefaultCellStyle.Format = "dd.MM.yyyy";
dataGridViewOrders.Columns["ReturnDate"].DefaultCellStyle.Format = "dd.MM.yyyy";
} }
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)

View File

@ -19,6 +19,7 @@ namespace ProjectLibrary.Forms
private void LoadList() private void LoadList()
{ {
dataGridViewReaders.DataSource = _readerRepository.ReadReaders(); dataGridViewReaders.DataSource = _readerRepository.ReadReaders();
dataGridViewReaders.Columns["Id"].Visible = false;
} }
private void FReaders_Load(object sender, EventArgs e) private void FReaders_Load(object sender, EventArgs e)
{ {

View File

@ -39,45 +39,43 @@
dataGridView.AllowUserToAddRows = false; dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToDeleteRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 11); dataGridView.Location = new Point(14, 15);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true; dataGridView.ReadOnly = true;
dataGridView.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(525, 225); dataGridView.Size = new Size(600, 300);
dataGridView.TabIndex = 8; dataGridView.TabIndex = 8;
// //
// buttonAdd // buttonAdd
// //
buttonAdd.Location = new Point(12, 251); buttonAdd.Location = new Point(14, 335);
buttonAdd.Margin = new Padding(3, 2, 3, 2);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(88, 22); buttonAdd.Size = new Size(101, 29);
buttonAdd.TabIndex = 9; buttonAdd.TabIndex = 9;
buttonAdd.Text = "Добавить"; buttonAdd.Text = "Добавить";
buttonAdd.Click += buttonAdd_Click; buttonAdd.Click += buttonAdd_Click;
// //
// buttonUpdate // buttonUpdate
// //
buttonUpdate.Location = new Point(227, 251); buttonUpdate.Location = new Point(259, 335);
buttonUpdate.Margin = new Padding(3, 2, 3, 2);
buttonUpdate.Name = "buttonUpdate"; buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(88, 22); buttonUpdate.Size = new Size(101, 29);
buttonUpdate.TabIndex = 10; buttonUpdate.TabIndex = 10;
buttonUpdate.Text = "Изменить"; buttonUpdate.Text = "Изменить";
buttonUpdate.Click += buttonUpdate_Click; buttonUpdate.Click += buttonUpdate_Click;
// //
// FTiclet_Extensions // FTiclet_Extensions
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(569, 293); ClientSize = new Size(650, 391);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Controls.Add(buttonAdd); Controls.Add(buttonAdd);
Controls.Add(buttonUpdate); Controls.Add(buttonUpdate);
Margin = new Padding(3, 4, 3, 4);
Name = "FTiclet_Extensions"; Name = "FTiclet_Extensions";
Text = "FTiclet_Extensions"; Text = "Продления билетов";
Load += FTiclet_Extensions_Load; Load += FTiclet_Extensions_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);

View File

@ -62,6 +62,11 @@ namespace ProjectLibrary.Forms
private void LoadList() private void LoadList()
{ {
dataGridView.DataSource = _ticketRepository.ReadTicketExtensions(); dataGridView.DataSource = _ticketRepository.ReadTicketExtensions();
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["LastUpdateDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
dataGridView.Columns["NextUpdateDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
} }
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging; using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.Extensions.Logging;
using ProjectLibrary.Repositories; using ProjectLibrary.Repositories;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -23,7 +24,7 @@ public class ChartReport
{ {
new PdfBuilder(filePath) new PdfBuilder(filePath)
.AddHeader("Количество книг в библиотеках") .AddHeader("Количество книг в библиотеках")
.AddPieChart("Библиотеки", GetData(dateTime)) .AddPieChart($"Библиотеки на {dateTime: dd MMMM yyyy}", GetData(dateTime))
.Build(); .Build();
return true; return true;
} }
@ -34,13 +35,12 @@ public class ChartReport
} }
} }
private List<(string Caption, double Value)> GetData(DateTime dateTime) private List<(string Caption, double Value)> GetData(DateTime? dateTime = null)
{ {
return _orderRepository return _orderRepository
.ReadOrders() .ReadOrders()
.Where(x => x.OrderDate.Date == dateTime.Date) .GroupBy(x => x.BookOrders.First(y => y.OrderID == x.Id).BookName , (key, group) => new { Name = key, Count = group.Sum(y => y.BookOrders.First(z => z.OrderID == y.Id).Count) })
.GroupBy(x => x.BookOrders.First(y => y.OrderID == x.Id).BookID , (key, group) => new { ID = key, Count = group.Sum(y => y.BookOrders.First(z => z.OrderID == y.Id).Count) }) .Select(x => (x.Name, (double)x.Count))
.Select(x => (x.ID.ToString(), (double)x.Count))
.ToList(); .ToList();
} }
} }

View File

@ -13,7 +13,7 @@ public class TableReport
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly ILogger<TableReport> _logger; private readonly ILogger<TableReport> _logger;
internal static readonly string[] item = ["Id заказа","Дата заказа", "Дата возврата", "Книга", "Количество"]; internal static readonly string[] item = ["Id заказа", "Дата заказа", "Дата возврата","Книга", "Количество"];
public TableReport(IOrderRepository orderRepository, ILogger<TableReport> logger) public TableReport(IOrderRepository orderRepository, ILogger<TableReport> logger)
@ -22,13 +22,13 @@ public class TableReport
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); _logger = logger ?? throw new ArgumentNullException(nameof(logger));
} }
public bool CreateTable(string filePath, DateTime startDate, DateTime endDate) public bool CreateTable(string filePath, DateTime? startDate = null, DateTime? endDate = null)
{ {
try try
{ {
new ExcelBuilder(filePath) new ExcelBuilder(filePath)
.AddHeader("Сводка по движению книг", 0, 5) .AddHeader("Сводка по движению книг", 0, 5)
.AddParagraph("за период", 0) .AddParagraph($"За период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}",0)
.AddTable([10, 10, 10, 15, 15], GetData(startDate, endDate)) .AddTable([10, 10, 10, 15, 15], GetData(startDate, endDate))
.Build(); .Build();
return true; return true;
@ -40,27 +40,27 @@ public class TableReport
} }
} }
private List<string[]> GetData(DateTime startDate, DateTime endDate) private List<string[]> GetData(DateTime? startDate = null, DateTime? endDate = null)
{ {
var data = _orderRepository var data = _orderRepository
.ReadOrders() .ReadOrders(StartDate: startDate, EndDate: endDate)
.Where(x => x.OrderDate >= startDate && x.OrderDate <= endDate && x.BookOrders.Any(y => y.OrderID == x.Id))
.Select(x => new .Select(x => new
{ {
x.Id, x.Id,
DateOrder = x.OrderDate, DateOrder = x.OrderDate,
DateReturn = x.ReturnDate, DateReturn = x.ReturnDate,
Book = (int?)x.BookOrders.First(y => y.OrderID == x.Id).BookID, Book = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.BookName,
Count = (int?)x.BookOrders.First(y => y.OrderID == x.Id).Count Count = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.Count
}) })
.OrderBy(x => x.DateOrder); .OrderBy(x => x.Id);
return return
new List<string[]>() { item } new List<string[]>() { item }
.Union( .Union(
data data
.Select(x => new string[] { x.Id.ToString(), x.DateOrder.ToString(), x.DateReturn.ToString(), .Select(x => new string[] { x.Id.ToString(), x.DateOrder.ToString("dd.MM.yyyy"), x.DateReturn.ToString("dd.MM.yyyy"),
x.Book?.ToString() ?? string.Empty, x.Count?.ToString() ?? string.Empty})) x.Book?.ToString() ?? string.Empty, x.Count?.ToString("N0") ?? string.Empty}))
.Union([["Всего", "", "", "", data.Sum(x => x.Count ?? 0).ToString()]]) .Union([["Всего", "", "", "", data.Sum(x => x.Count ?? 0).ToString("N0")]])
.ToList(); .ToList();
//return null;
Review

Закомментированного кода быть не должно

Закомментированного кода быть не должно
} }
} }

View File

@ -4,7 +4,7 @@
public interface IOrderRepository public interface IOrderRepository
{ {
IEnumerable<Orders> ReadOrders(); IEnumerable<Orders> ReadOrders(DateTime? StartDate = null, DateTime? EndDate = null);
Orders ReadOrderById(int id); Orders ReadOrderById(int id);
void CreateOrder(Orders order); void CreateOrder(Orders order);
void DeleteOrder(int id); void DeleteOrder(int id);

View File

@ -164,14 +164,35 @@ namespace ProjectLibrary.Repositories.Implementations
public IEnumerable<Library> ReadLibraries() public IEnumerable<Library> ReadLibraries()
{ {
_logger.LogInformation("Получение всех библиотек"); _logger.LogInformation("Получение всех библиотек");
var builder = new QueryBuilder();
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Library"; var querySelect = @$"SELECT lbr.*,
var libraries = connection.Query<Library>(querySelect); bl.Bookid as Bookid,
bl.count
from library lbr
left join book_library bl on lbr.id = bl.libraryid {builder.Build()}";
var BooksFromLibraryDict = new Dictionary<int, List<Book_Library>>();
var libraries = connection.Query<Library, Book_Library, Library>(querySelect, (libr, bookfromlib) =>
{
if (!BooksFromLibraryDict.TryGetValue(libr.Id, out var booklibrer))
{
booklibrer = [];
BooksFromLibraryDict.Add(libr.Id, booklibrer);
}
booklibrer.Add(bookfromlib);
return libr;
},
splitOn: "Bookid", param: new { });
_logger.LogDebug("Полученные библиотеки: {json}", JsonConvert.SerializeObject(libraries)); _logger.LogDebug("Полученные библиотеки: {json}", JsonConvert.SerializeObject(libraries));
return libraries; return BooksFromLibraryDict.Select(x =>
{
var lbfb = libraries.First(y => y.Id == x.Key);
lbfb.SetLibraryForBook(x.Value);
return lbfb;
}).ToList();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -108,20 +108,54 @@ namespace ProjectLibrary.Repositories.Implementations
} }
// Получение всех заказов // Получение всех заказов
public IEnumerable<Orders> ReadOrders() public IEnumerable<Orders> ReadOrders(DateTime? StartDate = null, DateTime? EndDate = null)
{ {
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT ord.*, bo.BookId, bo.Count var builder = new QueryBuilder();
if(StartDate.HasValue)
{
builder.AddCollerction("ord.OrderDate >= @StartDate");
}
/*if (EndDate.HasValue)
{
builder.AddCollerction("ord.ReturnDate < @EndDate");
}*/
var querySelect = $@"SELECT ord.*,re.name as ReaderName,
bk.Name as BookName,
Obo.bookid as bookid,
Obo.Orderid, obo.count
FROM Orders ord FROM Orders ord
INNER JOIN Book_Orders bo ON bo.orderId = ord.Id"; INNER JOIN Book_Orders Obo ON Obo.orderId = ord.Id
var order = connection.Query<TempBookOrders>(querySelect); Inner join book bk on bk.ID = obo.Bookid
inner join reader re on re.id = ord.readerid
{builder.Build()}";
var OrderBookDict = new Dictionary<int, List<Book_Orders>>();
var order = connection
.Query<Orders, Book_Orders, Orders>(querySelect, (orders, books_orders) =>
{
if (!OrderBookDict.TryGetValue(orders.Id, out var Book_Orders))
{
Book_Orders = [];
OrderBookDict.Add(orders.Id, Book_Orders);
}
books_orders.BookName = orders.BookName;
Book_Orders.Add(books_orders);
return orders;
},
splitOn: "bookid", param: new { StartDate, EndDate });
_logger.LogDebug("Получ енные объекты: {json}", JsonConvert.SerializeObject(order)); _logger.LogDebug("Получ енные объекты: {json}", JsonConvert.SerializeObject(order));
return order.GroupBy(x => x.Id, y => y, return OrderBookDict.Select(x =>
(key, value) => Orders.CreateEntity(value.First(), {
value.Select(z => Book_Orders.CreateEntity(z.Id, z.BookID, z.Count)))).ToList(); var or = order.First(y => y.Id == x.Key);
or.SetOrdersOfBooks(x.Value);
return or;
}).ToArray();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -112,7 +112,9 @@ namespace ProjectLibrary.Repositories.Implementations
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Ticket_Extensions"; var querySelect = @"SELECT te.*, r.Name as ReaderName
FROM Ticket_Extensions te
INNER JOIN Reader r ON r.Id = te.ReaderId";
var ticketExtensions = connection.Query<TicketExtensions>(querySelect).ToList(); var ticketExtensions = connection.Query<TicketExtensions>(querySelect).ToList();
_logger.LogDebug("Полученные продления билетов: {json}", JsonConvert.SerializeObject(ticketExtensions)); _logger.LogDebug("Полученные продления билетов: {json}", JsonConvert.SerializeObject(ticketExtensions));