Лаб 1 22минП

This commit is contained in:
Aleksandr4350 2024-11-12 23:13:20 +04:00
parent 63a88d7539
commit 6e34674f13
28 changed files with 655 additions and 4 deletions

View File

@ -0,0 +1,26 @@
namespace ProjectLibrary.Entities
{
using ProjectLibrary.Entities.Enums;
public class Book
{
public int Id { get; private set; }
public string Author { get; private set; } = string.Empty;
public string Name { get; private set; } = string.Empty;
public BookType Type { get; private set; } = BookType.None;
public int LibraryID { get; private set; }
public static Book CreateEntity(int id, string author, string name, BookType type, int libraryID)
{
return new Book
{
Id = id,
Author = author ?? string.Empty,
Name = name ?? string.Empty,
Type = type,
LibraryID = libraryID
};
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entites
{
public class BookOrders
{
public int BookID { get; private set; }
public int OrderID { get; private set; }
public static BookOrders CreateEntity(int bookID, int orderID)
{
return new BookOrders
{
BookID = bookID,
OrderID = orderID
};
}
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entites
{
public class BookLibrary
{
public int BookID { get; private set; }
public int LibraryID { get; private set; }
public int Count { get; private set; }
public static BookLibrary CreateEntity(int bookID, int libraryID, int count)
{
return new BookLibrary
{
BookID = bookID,
LibraryID = libraryID,
Count = count
};
}
}
}

View File

@ -0,0 +1,11 @@
namespace ProjectLibrary.Entities.Enums
{
public enum BookStatus
{
None = 0,
Available = 1,
CheckedOut = 2,
Reserved = 3,
Lost = 4
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entities.Enums
{
[Flags]
public enum BookType
{
None = 0,
Fiction = 1,
NonFiction = 2,
Science = 4,
History = 8,
Mystery = 16,
Fantasy = 32
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entites
{
public class Library
{
public int Id { get; private set; }
public string Name { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public static Library CreateEntity(int id, string name, string address)
{
return new Library
{
Id = id,
Name = name ?? string.Empty,
Address = address ?? string.Empty
};
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entites
{
public class Orders
{
public int Id { get; private set; }
public int OrderDate { get; private set; }
public int ReturnDate { get; private set; }
public int ReaderID { get; private set; }
public static Orders CreateEntity(int id, int orderDate, int returnDate, int readerID)
{
return new Orders
{
Id = id,
OrderDate = orderDate,
ReturnDate = returnDate,
ReaderID = readerID
};
}
}
}

View File

@ -0,0 +1,21 @@
namespace ProjectLibrary.Entities
{
public class Reader
{
public int Id { get; private set; }
public string Name { get; private set; } = string.Empty;
public int ReaderTicket { get; private set; }
public DateTime RegistrationDateRT { get; private set; } // Изменение на DateTime
public static Reader CreateEntity(int id, string name, int readerTicket, DateTime registrationDateRT)
{
return new Reader
{
Id = id,
Name = name ?? string.Empty,
ReaderTicket = readerTicket,
RegistrationDateRT = registrationDateRT
};
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entites
{
public class TicketExtensions
{
public int ReaderID { get; private set; }
public int ExtensionID { get; private set; }
public DateTime LastUpdateDate { get; private set; }
public DateTime NextUpdateDate { get; private set; }
public static TicketExtensions CreateEntity(int readerID, int extensionID, DateTime lastUpdateDate, DateTime nextUpdateDate)
{
return new TicketExtensions
{
ReaderID = readerID,
ExtensionID = extensionID,
LastUpdateDate = lastUpdateDate,
NextUpdateDate = nextUpdateDate
};
}
}
}

View File

@ -1,6 +1,6 @@
namespace ProjectLibrary
{
partial class Form1
partial class FormLibrary
{
/// <summary>
/// Required designer variable.

View File

@ -1,8 +1,8 @@
namespace ProjectLibrary
{
public partial class Form1 : Form
public partial class FormLibrary : Form
{
public Form1()
public FormLibrary()
{
InitializeComponent();
}

View File

@ -1,3 +1,7 @@
using ProjectLibrary.Repositories.Implementations;
using ProjectLibrary.Repositories;
using Unity;
namespace ProjectLibrary
{
internal static class Program
@ -11,7 +15,25 @@ namespace ProjectLibrary
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(CreateContainer().Resolve<FormLibrary>());
}
private static IUnityContainer CreateContainer()
{
var container = new UnityContainer();
// Ðåãèñòðàöèÿ ðåïîçèòîðèåâ
container.RegisterType<IBookRepository, BookRepository>();
container.RegisterType<ILibraryRepository, LibraryRepository>();
container.RegisterType<IReaderRepository, ReaderRepository>();
container.RegisterType<IOrderRepository, OrderRepository>();
container.RegisterType<ITicketExtensionsRepository, TicketExtensionsRepository>();
container.RegisterType<IBookOrdersRepository, BookOrdersRepository>();
container.RegisterType<IBookLibraryRepository, BookLibraryRepository>();
return container;
}
}
}

View File

@ -8,4 +8,8 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Unity" Version="5.11.10" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,12 @@
namespace ProjectLibrary.Repositories
{
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
public interface IBookLibraryRepository
{
IEnumerable<BookLibrary> ReadBookLibraries(int? bookId = null, int? libraryId = null);
void CreateBookLibrary(BookLibrary bookLibrary);
void DeleteBookLibrary(int bookId, int libraryId);
}
}

View File

@ -0,0 +1,12 @@
namespace ProjectLibrary.Repositories
{
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
public interface IBookOrdersRepository
{
IEnumerable<BookOrders> ReadBookOrders(int? bookId = null, int? orderId = null);
void CreateBookOrder(BookOrders bookOrder);
void DeleteBookOrder(int bookId, int orderId);
}
}

View File

@ -0,0 +1,13 @@
namespace ProjectLibrary.Repositories
{
using ProjectLibrary.Entities;
public interface IBookRepository
{
IEnumerable<Book> ReadBooks();
Book ReadBookById(int id);
void CreateBook(Book book);
void UpdateBook(Book book);
void DeleteBook(int id);
}
}

View File

@ -0,0 +1,14 @@
namespace ProjectLibrary.Repositories
{
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
public interface ILibraryRepository
{
IEnumerable<Library> ReadLibraries();
Library ReadLibraryById(int id);
void CreateLibrary(Library library);
void UpdateLibrary(Library library);
void DeleteLibrary(int id);
}
}

View File

@ -0,0 +1,13 @@
namespace ProjectLibrary.Repositories
{
using ProjectLibrary.Entites;
public interface IOrderRepository
{
IEnumerable<Orders> ReadOrders();
Orders ReadOrderById(int id);
void CreateOrder(Orders order);
void UpdateOrder(Orders order);
void DeleteOrder(int id);
}
}

View File

@ -0,0 +1,14 @@
namespace ProjectLibrary.Repositories
{
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
public interface IReaderRepository
{
IEnumerable<Reader> ReadReaders();
Reader ReadReaderById(int id);
void CreateReader(Reader reader);
void UpdateReader(Reader reader);
void DeleteReader(int id);
}
}

View File

@ -0,0 +1,14 @@
namespace ProjectLibrary.Repositories
{
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
public interface ITicketExtensionsRepository
{
IEnumerable<TicketExtensions> ReadTicketExtensions();
TicketExtensions ReadTicketExtensionById(int id);
void CreateTicketExtension(TicketExtensions ticketExtension);
void UpdateTicketExtension(TicketExtensions ticketExtension);
void DeleteTicketExtension(int id);
}
}

View File

@ -0,0 +1,49 @@
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class BookLibraryRepository : IBookLibraryRepository
{
// Эмулируем базу данных в виде списка
private readonly List<BookLibrary> _bookLibraries = new List<BookLibrary>();
public void CreateBookLibrary(BookLibrary bookLibrary)
{
// Логика для добавления связи книги и библиотеки
_bookLibraries.Add(bookLibrary);
}
public void DeleteBookLibrary(int bookId, int libraryId)
{
// Логика для удаления связи книги и библиотеки по идентификаторам
var bookLibrary = _bookLibraries.FirstOrDefault(bl => bl.BookID == bookId && bl.LibraryID == libraryId);
if (bookLibrary != null)
{
_bookLibraries.Remove(bookLibrary);
}
}
public IEnumerable<BookLibrary> ReadBookLibraries(int? bookId = null, int? libraryId = null)
{
// Логика для получения всех связей книг и библиотек с возможностью фильтрации по bookId и libraryId
return _bookLibraries.Where(bl =>
(!bookId.HasValue || bl.BookID == bookId) &&
(!libraryId.HasValue || bl.LibraryID == libraryId));
}
public void UpdateBookLibrary(BookLibrary bookLibrary)
{
// Логика для обновления информации о связи книги и библиотеки
var existingBookLibrary = _bookLibraries.FirstOrDefault(bl => bl.BookID == bookLibrary.BookID && bl.LibraryID == bookLibrary.LibraryID);
if (existingBookLibrary != null)
{
_bookLibraries.Remove(existingBookLibrary);
_bookLibraries.Add(bookLibrary);
}
}
}
}

View File

@ -0,0 +1,38 @@
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class BookOrdersRepository : IBookOrdersRepository
{
// Эмулируем базу данных в виде списка
private readonly List<BookOrders> _bookOrders = new List<BookOrders>();
public void CreateBookOrder(BookOrders bookOrder)
{
// Логика для добавления связи книги и заказа
_bookOrders.Add(bookOrder);
}
public void DeleteBookOrder(int bookId, int orderId)
{
// Логика для удаления связи книги и заказа по идентификаторам
var bookOrder = _bookOrders.FirstOrDefault(bo => bo.BookID == bookId && bo.OrderID == orderId);
if (bookOrder != null)
{
_bookOrders.Remove(bookOrder);
}
}
public IEnumerable<BookOrders> ReadBookOrders(int? bookId = null, int? orderId = null)
{
// Логика для получения всех связей книг и заказов с возможностью фильтрации по bookId и orderId
return _bookOrders.Where(bo =>
(!bookId.HasValue || bo.BookID == bookId) &&
(!orderId.HasValue || bo.OrderID == orderId));
}
}
}

View File

@ -0,0 +1,53 @@
using ProjectLibrary.Entities;
using ProjectLibrary.Entities.Enums;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class BookRepository : IBookRepository
{
// Эмулируем базу данных в виде списка
private readonly List<Book> _books = new List<Book>();
public void CreateBook(Book book)
{
// Логика для добавления книги в базу данных
_books.Add(book);
}
public void DeleteBook(int id)
{
// Логика для удаления книги по id
var book = _books.FirstOrDefault(b => b.Id == id);
if (book != null)
{
_books.Remove(book);
}
}
public Book ReadBookById(int id)
{
// Логика для получения книги по id
return _books.FirstOrDefault(b => b.Id == id) ?? Book.CreateEntity(id, "Unknown Author", "Unknown Title", BookType.None, 0);
}
public IEnumerable<Book> ReadBooks()
{
// Логика для получения всех книг
return _books;
}
public void UpdateBook(Book book)
{
// Логика для обновления информации о книге
var existingBook = _books.FirstOrDefault(b => b.Id == book.Id);
if (existingBook != null)
{
_books.Remove(existingBook);
_books.Add(book);
}
}
}
}

View File

@ -0,0 +1,47 @@
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class LibraryRepository : ILibraryRepository
{
private readonly List<Library> _libraries = new List<Library>();
public void CreateLibrary(Library library)
{
_libraries.Add(library);
}
public void DeleteLibrary(int id)
{
var library = _libraries.FirstOrDefault(l => l.Id == id);
if (library != null)
{
_libraries.Remove(library);
}
}
public Library ReadLibraryById(int id)
{
return _libraries.FirstOrDefault(l => l.Id == id) ?? Library.CreateEntity(id, "Unknown Library", "Unknown Address");
}
public IEnumerable<Library> ReadLibraries()
{
return _libraries;
}
public void UpdateLibrary(Library library)
{
var existingLibrary = _libraries.FirstOrDefault(l => l.Id == library.Id);
if (existingLibrary != null)
{
_libraries.Remove(existingLibrary);
_libraries.Add(library);
}
}
}
}

View File

@ -0,0 +1,47 @@
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class OrderRepository : IOrderRepository
{
private readonly List<Orders> _orders = new List<Orders>();
public void CreateOrder(Orders order)
{
_orders.Add(order);
}
public void DeleteOrder(int id)
{
var order = _orders.FirstOrDefault(o => o.Id == id);
if (order != null)
{
_orders.Remove(order);
}
}
public Orders ReadOrderById(int id)
{
return _orders.FirstOrDefault(o => o.Id == id) ?? Orders.CreateEntity(id, 0, 0, 0);
}
public IEnumerable<Orders> ReadOrders()
{
return _orders;
}
public void UpdateOrder(Orders order)
{
var existingOrder = _orders.FirstOrDefault(o => o.Id == order.Id);
if (existingOrder != null)
{
_orders.Remove(existingOrder);
_orders.Add(order);
}
}
}
}

View File

@ -0,0 +1,47 @@
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class ReaderRepository : IReaderRepository
{
private readonly List<Reader> _readers = new List<Reader>();
public void CreateReader(Reader reader)
{
_readers.Add(reader);
}
public void DeleteReader(int id)
{
var reader = _readers.FirstOrDefault(r => r.Id == id);
if (reader != null)
{
_readers.Remove(reader);
}
}
public Reader ReadReaderById(int id)
{
return _readers.FirstOrDefault(r => r.Id == id) ?? Reader.CreateEntity(id, "Unknown Reader", 0, DateTime.Now);
}
public IEnumerable<Reader> ReadReaders()
{
return _readers;
}
public void UpdateReader(Reader reader)
{
var existingReader = _readers.FirstOrDefault(r => r.Id == reader.Id);
if (existingReader != null)
{
_readers.Remove(existingReader);
_readers.Add(reader);
}
}
}
}

View File

@ -0,0 +1,47 @@
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class TicketExtensionsRepository : ITicketExtensionsRepository
{
private readonly List<TicketExtensions> _ticketExtensions = new List<TicketExtensions>();
public void CreateTicketExtension(TicketExtensions ticketExtension)
{
_ticketExtensions.Add(ticketExtension);
}
public void DeleteTicketExtension(int id)
{
var ticketExtension = _ticketExtensions.FirstOrDefault(t => t.ExtensionID == id);
if (ticketExtension != null)
{
_ticketExtensions.Remove(ticketExtension);
}
}
public TicketExtensions ReadTicketExtensionById(int id)
{
return _ticketExtensions.FirstOrDefault(t => t.ExtensionID == id) ?? TicketExtensions.CreateEntity(0, id, DateTime.Now, DateTime.Now);
}
public IEnumerable<TicketExtensions> ReadTicketExtensions()
{
return _ticketExtensions;
}
public void UpdateTicketExtension(TicketExtensions ticketExtension)
{
var existingTicketExtension = _ticketExtensions.FirstOrDefault(t => t.ExtensionID == ticketExtension.ExtensionID);
if (existingTicketExtension != null)
{
_ticketExtensions.Remove(existingTicketExtension);
_ticketExtensions.Add(ticketExtension);
}
}
}
}