From 88fdddcf23dafce0e98c72cdab139d5b7ec7b9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=B8=D0=BB=20=D0=9F=D1=83=D1=82?= =?UTF-8?q?=D0=B8=D0=BD=D1=86=D0=B5=D0=B2?= Date: Wed, 15 May 2024 11:18:27 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Booking/BookingAbstractions/Models/Author.cs | 17 ++ Booking/BookingAbstractions/Models/Book.cs | 21 ++ Booking/BookingAbstractions/Models/Booking.cs | 17 ++ Booking/BookingAbstractions/Models/Client.cs | 17 ++ Booking/BookingAbstractions/Models/Review.cs | 16 + .../WorkAbstractions/IAuthorWork.cs | 18 ++ .../WorkAbstractions/IBookWork.cs | 17 ++ .../WorkAbstractions/IBookingWork.cs | 17 ++ .../WorkAbstractions/IClientWork.cs | 18 ++ .../WorkAbstractions/IReviewWork.cs | 17 ++ .../BookingPostgresImplementation.csproj | 2 +- .../WorkImplementation/AuthorWork.cs | 86 ++++++ .../WorkImplementation/BookWork.cs | 94 ++++++ .../WorkImplementation/BookingWork.cs | 88 ++++++ .../WorkImplementation/CLientWork.cs | 86 ++++++ .../WorkImplementation/ReviewWork.cs | 85 ++++++ Booking/BookingView/BookingView.csproj | 12 + Booking/BookingView/FormAuthor.Designer.cs | 229 ++++++++++++++ Booking/BookingView/FormAuthor.cs | 123 ++++++++ Booking/BookingView/FormAuthor.resx | 120 ++++++++ Booking/BookingView/FormBook.Designer.cs | 279 ++++++++++++++++++ Booking/BookingView/FormBook.cs | 152 ++++++++++ Booking/BookingView/FormBook.resx | 120 ++++++++ Booking/BookingView/FormBooking.Designer.cs | 232 +++++++++++++++ Booking/BookingView/FormBooking.cs | 141 +++++++++ Booking/BookingView/FormBooking.resx | 120 ++++++++ Booking/BookingView/FormClient.Designer.cs | 229 ++++++++++++++ Booking/BookingView/FormClient.cs | 123 ++++++++ Booking/BookingView/FormClient.resx | 120 ++++++++ Booking/BookingView/FormMain.Designer.cs | 117 +++++++- Booking/BookingView/FormMain.cs | 124 +++++++- Booking/BookingView/FormPublisher.Designer.cs | 5 - Booking/BookingView/FormReview.Designer.cs | 209 +++++++++++++ Booking/BookingView/FormReview.cs | 135 +++++++++ Booking/BookingView/FormReview.resx | 120 ++++++++ Booking/BookingView/Program.cs | 11 + 36 files changed, 3319 insertions(+), 18 deletions(-) create mode 100644 Booking/BookingAbstractions/Models/Author.cs create mode 100644 Booking/BookingAbstractions/Models/Book.cs create mode 100644 Booking/BookingAbstractions/Models/Booking.cs create mode 100644 Booking/BookingAbstractions/Models/Client.cs create mode 100644 Booking/BookingAbstractions/Models/Review.cs create mode 100644 Booking/BookingAbstractions/WorkAbstractions/IAuthorWork.cs create mode 100644 Booking/BookingAbstractions/WorkAbstractions/IBookWork.cs create mode 100644 Booking/BookingAbstractions/WorkAbstractions/IBookingWork.cs create mode 100644 Booking/BookingAbstractions/WorkAbstractions/IClientWork.cs create mode 100644 Booking/BookingAbstractions/WorkAbstractions/IReviewWork.cs create mode 100644 Booking/BookingPostgresImplementation/WorkImplementation/AuthorWork.cs create mode 100644 Booking/BookingPostgresImplementation/WorkImplementation/BookWork.cs create mode 100644 Booking/BookingPostgresImplementation/WorkImplementation/BookingWork.cs create mode 100644 Booking/BookingPostgresImplementation/WorkImplementation/CLientWork.cs create mode 100644 Booking/BookingPostgresImplementation/WorkImplementation/ReviewWork.cs create mode 100644 Booking/BookingView/FormAuthor.Designer.cs create mode 100644 Booking/BookingView/FormAuthor.cs create mode 100644 Booking/BookingView/FormAuthor.resx create mode 100644 Booking/BookingView/FormBook.Designer.cs create mode 100644 Booking/BookingView/FormBook.cs create mode 100644 Booking/BookingView/FormBook.resx create mode 100644 Booking/BookingView/FormBooking.Designer.cs create mode 100644 Booking/BookingView/FormBooking.cs create mode 100644 Booking/BookingView/FormBooking.resx create mode 100644 Booking/BookingView/FormClient.Designer.cs create mode 100644 Booking/BookingView/FormClient.cs create mode 100644 Booking/BookingView/FormClient.resx create mode 100644 Booking/BookingView/FormReview.Designer.cs create mode 100644 Booking/BookingView/FormReview.cs create mode 100644 Booking/BookingView/FormReview.resx diff --git a/Booking/BookingAbstractions/Models/Author.cs b/Booking/BookingAbstractions/Models/Author.cs new file mode 100644 index 0000000..49104a0 --- /dev/null +++ b/Booking/BookingAbstractions/Models/Author.cs @@ -0,0 +1,17 @@ +namespace BookingAbstractions.Models +{ + public class Author + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string LastName { get; set; } = string.Empty; + + public DateTime DateOfBirth { get; set; } + + public string HomeCountry { get; set; } = string.Empty; + + public int AmountOfBooks { get; set; } = 0; + } +} diff --git a/Booking/BookingAbstractions/Models/Book.cs b/Booking/BookingAbstractions/Models/Book.cs new file mode 100644 index 0000000..c27fccc --- /dev/null +++ b/Booking/BookingAbstractions/Models/Book.cs @@ -0,0 +1,21 @@ +namespace BookingAbstractions.Models +{ + public class Book + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string Genre { get; set; } = string.Empty; + + public DateTime Date { get; set; } + + public int ISBN { get; set; } = 0; + + public int Price { get; set; } = 0; + + public int AuthorId { get; set; } + + public int PublisherId { get; set; } + } +} diff --git a/Booking/BookingAbstractions/Models/Booking.cs b/Booking/BookingAbstractions/Models/Booking.cs new file mode 100644 index 0000000..a994c54 --- /dev/null +++ b/Booking/BookingAbstractions/Models/Booking.cs @@ -0,0 +1,17 @@ +namespace BookingAbstractions.Models +{ + public class Booking + { + public int Id { get; set; } + + public DateTime Date { get; set; } + + public string Status { get; set; } = string.Empty; + + public int Sum { get; set; } = 0; + + public int ClientId { get; set; } + + public int BookId { get; set; } + } +} diff --git a/Booking/BookingAbstractions/Models/Client.cs b/Booking/BookingAbstractions/Models/Client.cs new file mode 100644 index 0000000..216d3dc --- /dev/null +++ b/Booking/BookingAbstractions/Models/Client.cs @@ -0,0 +1,17 @@ +namespace BookingAbstractions.Models +{ + public class Client + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string LastName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public string Email { get; set; } = string.Empty; + + public string PhoneNumber { get; set; } = string.Empty; + } +} diff --git a/Booking/BookingAbstractions/Models/Review.cs b/Booking/BookingAbstractions/Models/Review.cs new file mode 100644 index 0000000..eb6d4cc --- /dev/null +++ b/Booking/BookingAbstractions/Models/Review.cs @@ -0,0 +1,16 @@ +namespace BookingAbstractions.Models +{ + public class Review + { + public int Id { get; set; } + + public int Score { get; set; } = 0; + + public string Text { get; set; } = string.Empty; + + public int ClientId { get; set; } + + public int BookId { get; set; } + + } +} diff --git a/Booking/BookingAbstractions/WorkAbstractions/IAuthorWork.cs b/Booking/BookingAbstractions/WorkAbstractions/IAuthorWork.cs new file mode 100644 index 0000000..8563f4d --- /dev/null +++ b/Booking/BookingAbstractions/WorkAbstractions/IAuthorWork.cs @@ -0,0 +1,18 @@ +using BookingAbstractions.Models; + +namespace BookingAbstractions.WorkAbstractions +{ + public interface IAuthorWork + { + List GetAll(); + + Author? Get(int id); + + Author? Create(Author author); + + Author? Update(Author author); + + Author? Delete(int id); + + } +} diff --git a/Booking/BookingAbstractions/WorkAbstractions/IBookWork.cs b/Booking/BookingAbstractions/WorkAbstractions/IBookWork.cs new file mode 100644 index 0000000..8b0f735 --- /dev/null +++ b/Booking/BookingAbstractions/WorkAbstractions/IBookWork.cs @@ -0,0 +1,17 @@ +using BookingAbstractions.Models; + +namespace BookingAbstractions.WorkAbstractions +{ + public interface IBookWork + { + List GetAll(); + + Book? Get(int id); + + Book? Create(Book book); + + Book? Update(Book book); + + Book? Delete(int id); + } +} diff --git a/Booking/BookingAbstractions/WorkAbstractions/IBookingWork.cs b/Booking/BookingAbstractions/WorkAbstractions/IBookingWork.cs new file mode 100644 index 0000000..0510d81 --- /dev/null +++ b/Booking/BookingAbstractions/WorkAbstractions/IBookingWork.cs @@ -0,0 +1,17 @@ +using BookingAbstractions.Models; + +namespace BookingAbstractions.WorkAbstractions +{ + public interface IBookingWork + { + List GetAll(); + + Booking? Get(int id); + + Booking? Create(Booking booking); + + Booking? Update(Booking booking); + + Booking? Delete(int id); + } +} diff --git a/Booking/BookingAbstractions/WorkAbstractions/IClientWork.cs b/Booking/BookingAbstractions/WorkAbstractions/IClientWork.cs new file mode 100644 index 0000000..12291b8 --- /dev/null +++ b/Booking/BookingAbstractions/WorkAbstractions/IClientWork.cs @@ -0,0 +1,18 @@ +using BookingAbstractions.Models; + +namespace BookingAbstractions.WorkAbstractions +{ + public interface IClientWork + { + List GetAll(); + + Client? Get(int id); + + Client? Create(Client client); + + Client? Update(Client client); + + Client? Delete(int id); + + } +} diff --git a/Booking/BookingAbstractions/WorkAbstractions/IReviewWork.cs b/Booking/BookingAbstractions/WorkAbstractions/IReviewWork.cs new file mode 100644 index 0000000..c39dede --- /dev/null +++ b/Booking/BookingAbstractions/WorkAbstractions/IReviewWork.cs @@ -0,0 +1,17 @@ +using BookingAbstractions.Models; + +namespace BookingAbstractions.WorkAbstractions +{ + public interface IReviewWork + { + List GetAll(); + + Review? Get(int id); + + Review? Create(Review review); + + Review? Update(Review review); + + Review? Delete(int id); + } +} diff --git a/Booking/BookingPostgresImplementation/BookingPostgresImplementation.csproj b/Booking/BookingPostgresImplementation/BookingPostgresImplementation.csproj index 6394d55..7930bef 100644 --- a/Booking/BookingPostgresImplementation/BookingPostgresImplementation.csproj +++ b/Booking/BookingPostgresImplementation/BookingPostgresImplementation.csproj @@ -7,7 +7,7 @@ - + diff --git a/Booking/BookingPostgresImplementation/WorkImplementation/AuthorWork.cs b/Booking/BookingPostgresImplementation/WorkImplementation/AuthorWork.cs new file mode 100644 index 0000000..bac323c --- /dev/null +++ b/Booking/BookingPostgresImplementation/WorkImplementation/AuthorWork.cs @@ -0,0 +1,86 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; +using Npgsql; + +namespace BookingPostgresImplementation.WorkImplementation +{ + public class AuthorWork : IAuthorWork + { + public List GetAll() + { + var authors = new List(); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM author order by id", con); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + authors.Add(new Author + { + Id = reader.GetInt32(0), + Name = reader.GetString(1), + LastName = reader.GetString(2), + DateOfBirth = reader.GetDateTime(3), + HomeCountry = reader.GetString(4), + AmountOfBooks = reader.GetInt32(5), + }); + } + return authors; + } + + public Author? Get(int id) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM author WHERE id = {id}", con); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Author + { + Id = reader.GetInt32(0), + Name = reader.GetString(1), + LastName = reader.GetString(2), + DateOfBirth = reader.GetDateTime(3), + HomeCountry = reader.GetString(4), + AmountOfBooks = reader.GetInt32(5), + }; + } + return null; + } + + public Author? Create(Author author) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("INSERT INTO author (name, lastname, dateofbirth, homecountry, amountofbooks) VALUES (@Name, @LastName, @DateOfBirth, @HomeCountry, @AmountOfBooks)", con); + cmd.Parameters.AddWithValue("@Name", author.Name); + cmd.Parameters.AddWithValue("@LastName", author.LastName); + cmd.Parameters.AddWithValue("@DateOfBirth", author.DateOfBirth); + cmd.Parameters.AddWithValue("@HomeCountry", author.HomeCountry); + cmd.Parameters.AddWithValue("@AmountOfBooks", author.AmountOfBooks); + cmd.ExecuteNonQuery(); + return author; + } + + public Author? Update(Author author) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"UPDATE author SET name = '{author.Name}', lastname = '{author.LastName}', dateofbirth = '{author.DateOfBirth}', homecountry = '{author.HomeCountry}', amountofbooks = {author.AmountOfBooks} WHERE id = {author.Id}", con); + cmd.ExecuteNonQuery(); + var element = Get(author.Id); + return element; + } + + public Author? Delete(int id) + { + var element = Get(id); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM author WHERE id = {id}", con); + cmd.ExecuteNonQuery(); + return element; + } + } +} diff --git a/Booking/BookingPostgresImplementation/WorkImplementation/BookWork.cs b/Booking/BookingPostgresImplementation/WorkImplementation/BookWork.cs new file mode 100644 index 0000000..abc5db9 --- /dev/null +++ b/Booking/BookingPostgresImplementation/WorkImplementation/BookWork.cs @@ -0,0 +1,94 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; +using Npgsql; + +namespace BookingPostgresImplementation.WorkImplementation +{ + public class BookWork : IBookWork + { + public List GetAll() + { + var books = new List(); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM book order by id", con); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + books.Add(new Book + { + Id = reader.GetInt32(0), + Name = reader.GetString(1), + Genre = reader.GetString(2), + Date = reader.GetDateTime(3), + ISBN = reader.GetInt32(4), + Price = reader.GetInt32(5), + AuthorId = !reader.IsDBNull(6) ? reader.GetInt32(6) : 0, + PublisherId = !reader.IsDBNull(7) ? reader.GetInt32(7) : 0, + }); + } + return books; + } + + public Book? Get(int id) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM book WHERE id = {id}", con); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Book + { + Id = reader.GetInt32(0), + Name = reader.GetString(1), + Genre = reader.GetString(2), + Date = reader.GetDateTime(3), + ISBN = reader.GetInt32(4), + Price = reader.GetInt32(5), + AuthorId = !reader.IsDBNull(6) ? reader.GetInt32(6) : 0, + PublisherId = !reader.IsDBNull(7) ? reader.GetInt32(7) : 0, + }; + } + return null; + } + + public Book? Create(Book book) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("INSERT INTO book (name, genre, dateofpublishing, ISBN, price, authorid, publisherid) VALUES (@Name, @Genre, @Date, @ISBN, @Price, @AuthorId, @PublisherId)", con); + cmd.Parameters.AddWithValue("@Name", book.Name); + cmd.Parameters.AddWithValue("@Genre", book.Genre); + cmd.Parameters.AddWithValue("@Date", book.Date); + cmd.Parameters.AddWithValue("@ISBN", book.ISBN); + cmd.Parameters.AddWithValue("@Price", book.Price); + cmd.Parameters.AddWithValue("@AuthorId", book.AuthorId == 0 ? DBNull.Value : book.AuthorId); + cmd.Parameters.AddWithValue("@PublisherId", book.PublisherId == 0 ? DBNull.Value : book.PublisherId); + cmd.ExecuteNonQuery(); + return book; + } + + public Book? Update(Book book) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"UPDATE book SET name = '{book.Name}', genre = '{book.Genre}', dateofpublishing = '{book.Date}', ISBN = '{book.ISBN}', price = {book.Price}, authorid = @AuthorId, publisherid = @PublisherId WHERE id = {book.Id}", con); + cmd.Parameters.AddWithValue("@AuthorId", book.AuthorId == 0 ? DBNull.Value : book.AuthorId); + cmd.Parameters.AddWithValue("@PublisherId", book.PublisherId == 0 ? DBNull.Value : book.PublisherId); + cmd.ExecuteNonQuery(); + var element = Get(book.Id); + return element; + } + + public Book? Delete(int id) + { + var element = Get(id); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM book WHERE id = {id}", con); + cmd.ExecuteNonQuery(); + return element; + } + } +} diff --git a/Booking/BookingPostgresImplementation/WorkImplementation/BookingWork.cs b/Booking/BookingPostgresImplementation/WorkImplementation/BookingWork.cs new file mode 100644 index 0000000..0fd87ad --- /dev/null +++ b/Booking/BookingPostgresImplementation/WorkImplementation/BookingWork.cs @@ -0,0 +1,88 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; +using Npgsql; + +namespace BookingPostgresImplementation.WorkImplementation +{ + public class BookingWork : IBookingWork + { + public List GetAll() + { + var bookings = new List(); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM booking order by id", con); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + bookings.Add(new Booking + { + Id = reader.GetInt32(0), + Date = reader.GetDateTime(1), + Status = reader.GetString(2), + Sum = reader.GetInt32(3), + ClientId = !reader.IsDBNull(4) ? reader.GetInt32(4) : 0, + BookId = !reader.IsDBNull(5) ? reader.GetInt32(5) : 0, + }); + } + return bookings; + } + + public Booking? Get(int id) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM booking WHERE id = {id}", con); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Booking + { + Id = reader.GetInt32(0), + Date = reader.GetDateTime(1), + Status = reader.GetString(2), + Sum = reader.GetInt32(3), + ClientId = !reader.IsDBNull(4) ? reader.GetInt32(4) : 0, + BookId = !reader.IsDBNull(5) ? reader.GetInt32(5) : 0, + }; + } + return null; + } + + public Booking? Create(Booking booking) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("INSERT INTO booking (dateoforder, status, sum, clientid, bookid) VALUES (@Date, @Status, @Sum, @ClientId, @BookId)", con); + cmd.Parameters.AddWithValue("@Date", booking.Date); + cmd.Parameters.AddWithValue("@Status", booking.Status); + cmd.Parameters.AddWithValue("@Sum", booking.Sum); + cmd.Parameters.AddWithValue("@ClientId", booking.ClientId == 0 ? DBNull.Value : booking.ClientId); + cmd.Parameters.AddWithValue("@BookId", booking.BookId == 0 ? DBNull.Value : booking.BookId); + cmd.ExecuteNonQuery(); + return booking; + } + + public Booking? Update(Booking booking) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"UPDATE booking SET dateoforder = '{booking.Date}', status = '{booking.Status}', sum = {booking.Sum}, clientid = @ClientId, bookid = @BookId WHERE id = {booking.Id}", con); + cmd.Parameters.AddWithValue("@ClientId", booking.ClientId == 0 ? DBNull.Value : booking.ClientId); + cmd.Parameters.AddWithValue("@BookId", booking.BookId == 0 ? DBNull.Value : booking.BookId); + cmd.ExecuteNonQuery(); + var element = Get(booking.Id); + return element; + } + + public Booking? Delete(int id) + { + var element = Get(id); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM booking WHERE id = {id}", con); + cmd.ExecuteNonQuery(); + return element; + } + } +} diff --git a/Booking/BookingPostgresImplementation/WorkImplementation/CLientWork.cs b/Booking/BookingPostgresImplementation/WorkImplementation/CLientWork.cs new file mode 100644 index 0000000..e9ec4cb --- /dev/null +++ b/Booking/BookingPostgresImplementation/WorkImplementation/CLientWork.cs @@ -0,0 +1,86 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; +using Npgsql; + +namespace BookingPostgresImplementation.WorkImplementation +{ + public class ClientWork : IClientWork + { + public List GetAll() + { + var clients = new List(); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM client order by id", con); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + clients.Add(new Client + { + Id = reader.GetInt32(0), + Name = reader.GetString(1), + LastName = reader.GetString(2), + Address = reader.GetString(3), + Email = reader.GetString(4), + PhoneNumber = reader.GetString(5), + }); + } + return clients; + } + + public Client? Get(int id) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM client WHERE id = {id}", con); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Client + { + Id = reader.GetInt32(0), + Name = reader.GetString(1), + LastName = reader.GetString(2), + Address = reader.GetString(3), + Email = reader.GetString(4), + PhoneNumber = reader.GetString(5), + }; + } + return null; + } + + public Client? Create(Client client) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("INSERT INTO client (name, lastname, adress, email, phonenumber) VALUES (@Name, @LastName, @Address, @Email, @PhoneNumber)", con); + cmd.Parameters.AddWithValue("@Name", client.Name); + cmd.Parameters.AddWithValue("@LastName", client.LastName); + cmd.Parameters.AddWithValue("@Address", client.Address); + cmd.Parameters.AddWithValue("@Email", client.Email); + cmd.Parameters.AddWithValue("@PhoneNumber", client.PhoneNumber); + cmd.ExecuteNonQuery(); + return client; + } + + public Client? Update(Client client) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"UPDATE client SET name = '{client.Name}', lastname = '{client.LastName}', adress = '{client.Address}', email = '{client.Email}', phonenumber = {client.PhoneNumber} WHERE id = {client.Id}", con); + cmd.ExecuteNonQuery(); + var element = Get(client.Id); + return element; + } + + public Client? Delete(int id) + { + var element = Get(id); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM client WHERE id = {id}", con); + cmd.ExecuteNonQuery(); + return element; + } + } +} diff --git a/Booking/BookingPostgresImplementation/WorkImplementation/ReviewWork.cs b/Booking/BookingPostgresImplementation/WorkImplementation/ReviewWork.cs new file mode 100644 index 0000000..cdacb3f --- /dev/null +++ b/Booking/BookingPostgresImplementation/WorkImplementation/ReviewWork.cs @@ -0,0 +1,85 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; +using Npgsql; + +namespace BookingPostgresImplementation.WorkImplementation +{ + public class ReviewWork : IReviewWork + { + public List GetAll() + { + var reviews = new List(); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM review order by id", con); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + reviews.Add(new Review + { + Id = reader.GetInt32(0), + Score = reader.GetInt32(1), + Text = reader.GetString(2), + ClientId = !reader.IsDBNull(3) ? reader.GetInt32(3) : 0, + BookId = !reader.IsDBNull(4) ? reader.GetInt32(4) : 0, + }); + } + return reviews; + } + + public Review? Get(int id) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM review WHERE id = {id}", con); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Review + { + Id = reader.GetInt32(0), + Score = reader.GetInt32(1), + Text = reader.GetString(2), + ClientId = !reader.IsDBNull(3) ? reader.GetInt32(3) : 0, + BookId = !reader.IsDBNull(4) ? reader.GetInt32(4) : 0, + }; + } + return null; + } + + public Review? Create(Review review) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("INSERT INTO review (score, text, clientid, bookid) VALUES (@Score, @Text, @ClientId, @BookId)", con); + cmd.Parameters.AddWithValue("@Score", review.Score); + cmd.Parameters.AddWithValue("@Text", review.Text); + cmd.Parameters.AddWithValue("@ClientId", review.ClientId == 0 ? DBNull.Value : review.ClientId); + cmd.Parameters.AddWithValue("@BookId", review.BookId == 0 ? DBNull.Value : review.BookId); + cmd.ExecuteNonQuery(); + return review; + } + + public Review? Update(Review review) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"UPDATE review SET score = {review.Score}, text = '{review.Text}', clientid = @ClientId, bookid = @BookId WHERE id = {review.Id}", con); + cmd.Parameters.AddWithValue("@ClientId", review.ClientId == 0 ? DBNull.Value : review.ClientId); + cmd.Parameters.AddWithValue("@BookId", review.BookId == 0 ? DBNull.Value : review.BookId); + cmd.ExecuteNonQuery(); + var element = Get(review.Id); + return element; + } + + public Review? Delete(int id) + { + var element = Get(id); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM review WHERE id = {id}", con); + cmd.ExecuteNonQuery(); + return element; + } + } +} diff --git a/Booking/BookingView/BookingView.csproj b/Booking/BookingView/BookingView.csproj index 635b4e7..93bc68a 100644 --- a/Booking/BookingView/BookingView.csproj +++ b/Booking/BookingView/BookingView.csproj @@ -17,4 +17,16 @@ + + + Form + + + Form + + + Form + + + \ No newline at end of file diff --git a/Booking/BookingView/FormAuthor.Designer.cs b/Booking/BookingView/FormAuthor.Designer.cs new file mode 100644 index 0000000..8e86798 --- /dev/null +++ b/Booking/BookingView/FormAuthor.Designer.cs @@ -0,0 +1,229 @@ +namespace BookingView +{ + partial class FormAuthor + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + textBoxName = new TextBox(); + label1 = new Label(); + dataGridView = new DataGridView(); + textBoxLastName = new TextBox(); + label3 = new Label(); + labelPatronymic = new Label(); + textBoxBooks = new TextBox(); + label4 = new Label(); + textBoxCountry = new TextBox(); + label5 = new Label(); + dateTimePickerDate = new DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonDelete + // + buttonDelete.Location = new Point(888, 521); + buttonDelete.Margin = new Padding(3, 4, 3, 4); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(146, 40); + buttonDelete.TabIndex = 28; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(888, 455); + buttonUpdate.Margin = new Padding(3, 4, 3, 4); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(146, 40); + buttonUpdate.TabIndex = 27; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(888, 390); + buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(146, 40); + buttonCreate.TabIndex = 26; + buttonCreate.Text = "Добавить"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // textBoxName + // + textBoxName.Location = new Point(909, 58); + textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(229, 27); + textBoxName.TabIndex = 21; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(748, 61); + label1.Name = "label1"; + label1.Size = new Size(46, 20); + label1.TabIndex = 16; + label1.Text = "Имя: "; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(15, 19); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(697, 811); + dataGridView.TabIndex = 15; + dataGridView.CellClick += DataGridView_CellClick; + // + // textBoxLastName + // + textBoxLastName.Location = new Point(909, 116); + textBoxLastName.Margin = new Padding(3, 4, 3, 4); + textBoxLastName.Name = "textBoxLastName"; + textBoxLastName.Size = new Size(229, 27); + textBoxLastName.TabIndex = 32; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(748, 119); + label3.Name = "label3"; + label3.Size = new Size(80, 20); + label3.TabIndex = 31; + label3.Text = "Фамилия: "; + // + // labelPatronymic + // + labelPatronymic.AutoSize = true; + labelPatronymic.Location = new Point(748, 176); + labelPatronymic.Name = "labelPatronymic"; + labelPatronymic.Size = new Size(119, 20); + labelPatronymic.TabIndex = 33; + labelPatronymic.Text = "Дата рождения:"; + // + // textBoxBooks + // + textBoxBooks.Location = new Point(909, 291); + textBoxBooks.Margin = new Padding(3, 4, 3, 4); + textBoxBooks.Name = "textBoxBooks"; + textBoxBooks.Size = new Size(230, 27); + textBoxBooks.TabIndex = 38; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(749, 294); + label4.Name = "label4"; + label4.Size = new Size(132, 20); + label4.TabIndex = 37; + label4.Text = "Количество книг: "; + // + // textBoxCountry + // + textBoxCountry.Location = new Point(909, 233); + textBoxCountry.Margin = new Padding(3, 4, 3, 4); + textBoxCountry.Name = "textBoxCountry"; + textBoxCountry.Size = new Size(229, 27); + textBoxCountry.TabIndex = 40; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(748, 236); + label5.Name = "label5"; + label5.Size = new Size(61, 20); + label5.TabIndex = 39; + label5.Text = "Страна:"; + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(909, 171); + dateTimePickerDate.Margin = new Padding(3, 4, 3, 4); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(229, 27); + dateTimePickerDate.TabIndex = 41; + // + // FormAuthor + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1159, 845); + Controls.Add(dateTimePickerDate); + Controls.Add(textBoxCountry); + Controls.Add(label5); + Controls.Add(textBoxBooks); + Controls.Add(label4); + Controls.Add(labelPatronymic); + Controls.Add(textBoxLastName); + Controls.Add(label3); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(textBoxName); + Controls.Add(label1); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormAuthor"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Авторы"; + Load += FormAuthor_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + private TextBox textBoxName; + private Label label5; + private Label label1; + private Label labelPatronymic; + private DataGridView dataGridView; + private TextBox textBoxLastName; + private Label label3; + private TextBox textBoxBooks; + private Label label4; + private TextBox textBoxCountry; + private DateTimePicker dateTimePickerDate; + } +} \ No newline at end of file diff --git a/Booking/BookingView/FormAuthor.cs b/Booking/BookingView/FormAuthor.cs new file mode 100644 index 0000000..c9b83ed --- /dev/null +++ b/Booking/BookingView/FormAuthor.cs @@ -0,0 +1,123 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; + +namespace BookingView +{ + public partial class FormAuthor : Form + { + private readonly IAuthorWork _logic; + + public FormAuthor(IAuthorWork logic) + { + InitializeComponent(); + _logic = logic; + } + + private void FormAuthor_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + var authors = _logic.GetAll(); + + dataGridView.Rows.Clear(); + + if (dataGridView.ColumnCount == 0) + { + dataGridView.Columns.Add("Id", "ID"); + dataGridView.Columns.Add("Name", "Имя"); + dataGridView.Columns.Add("LastName", "Фамилия"); + dataGridView.Columns.Add("DateOfBirth", "Дата рождения"); + dataGridView.Columns.Add("HomeCountry", "Страна"); + dataGridView.Columns.Add("AmountOfBooks", "Количество книг"); + } + + dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["LastName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DateOfBirth"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["HomeCountry"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["AmountOfBooks"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + foreach (var author in authors) + { + dataGridView.Rows.Add(author.Id, author.Name, author.LastName, author.DateOfBirth, author.HomeCountry, author.AmountOfBooks); + } + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Author newAuthor = new() + { + Name = textBoxName.Text, + LastName = textBoxLastName.Text, + DateOfBirth = dateTimePickerDate.Value, + HomeCountry = textBoxCountry.Text, + AmountOfBooks = Convert.ToInt32(textBoxBooks.Text), + }; + + _logic.Create(newAuthor); + + LoadData(); + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int authorId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + Author updatedAuthor = new() + { + Id = authorId, + Name = textBoxName.Text, + LastName = textBoxLastName.Text, + DateOfBirth = dateTimePickerDate.Value, + HomeCountry = textBoxCountry.Text, + AmountOfBooks = Convert.ToInt32(textBoxBooks.Text), + }; + + _logic.Update(updatedAuthor); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите автора, информацию о котором необходимо обновить"); + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int authorId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + _logic.Delete(authorId); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите автора, информацию о котором необходимо удалить"); + } + } + + private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0) + { + DataGridViewRow row = dataGridView.Rows[e.RowIndex]; + textBoxName.Text = row.Cells["Name"].Value.ToString(); + textBoxLastName.Text = row.Cells["LastName"].Value.ToString(); + dateTimePickerDate.Value = DateTime.Parse(row.Cells["DateOfBirth"].Value.ToString()); + textBoxCountry.Text = row.Cells["HomeCountry"].Value.ToString(); + textBoxBooks.Text = row.Cells["AmountOfBooks"].Value.ToString(); + } + } + } +} diff --git a/Booking/BookingView/FormAuthor.resx b/Booking/BookingView/FormAuthor.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Booking/BookingView/FormAuthor.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Booking/BookingView/FormBook.Designer.cs b/Booking/BookingView/FormBook.Designer.cs new file mode 100644 index 0000000..c49031d --- /dev/null +++ b/Booking/BookingView/FormBook.Designer.cs @@ -0,0 +1,279 @@ +namespace BookingView +{ + partial class FormBook + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + label1 = new Label(); + dataGridView = new DataGridView(); + label2 = new Label(); + comboBoxAuthor = new ComboBox(); + label3 = new Label(); + label4 = new Label(); + comboBoxPublisher = new ComboBox(); + textBoxGenre = new TextBox(); + textBoxName = new TextBox(); + label6 = new Label(); + dateTimePickerDate = new DateTimePicker(); + textBoxISBN = new TextBox(); + label7 = new Label(); + textBoxPrice = new TextBox(); + label8 = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonDelete + // + buttonDelete.Location = new Point(847, 545); + buttonDelete.Margin = new Padding(3, 4, 3, 4); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(146, 40); + buttonDelete.TabIndex = 28; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(847, 480); + buttonUpdate.Margin = new Padding(3, 4, 3, 4); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(146, 40); + buttonUpdate.TabIndex = 27; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(847, 415); + buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(146, 40); + buttonCreate.TabIndex = 26; + buttonCreate.Text = "Добавить"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(681, 123); + label1.Name = "label1"; + label1.Size = new Size(109, 20); + label1.TabIndex = 16; + label1.Text = "Дата выпуска: "; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(15, 19); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(649, 568); + dataGridView.TabIndex = 15; + dataGridView.CellClick += DataGridView_CellClick; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(682, 275); + label2.Name = "label2"; + label2.Size = new Size(54, 20); + label2.TabIndex = 29; + label2.Text = "Автор:"; + // + // comboBoxAuthor + // + comboBoxAuthor.FormattingEnabled = true; + comboBoxAuthor.Location = new Point(854, 271); + comboBoxAuthor.Margin = new Padding(3, 4, 3, 4); + comboBoxAuthor.Name = "comboBoxAuthor"; + comboBoxAuthor.Size = new Size(265, 28); + comboBoxAuthor.TabIndex = 30; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(682, 324); + label3.Name = "label3"; + label3.Size = new Size(106, 20); + label3.TabIndex = 33; + label3.Text = "Издательство:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(681, 71); + label4.Name = "label4"; + label4.Size = new Size(51, 20); + label4.TabIndex = 34; + label4.Text = "Жанр:"; + // + // comboBoxPublisher + // + comboBoxPublisher.FormattingEnabled = true; + comboBoxPublisher.Location = new Point(855, 321); + comboBoxPublisher.Margin = new Padding(3, 4, 3, 4); + comboBoxPublisher.Name = "comboBoxPublisher"; + comboBoxPublisher.Size = new Size(265, 28); + comboBoxPublisher.TabIndex = 35; + // + // textBoxGenre + // + textBoxGenre.Location = new Point(854, 68); + textBoxGenre.Margin = new Padding(3, 4, 3, 4); + textBoxGenre.Name = "textBoxGenre"; + textBoxGenre.Size = new Size(265, 27); + textBoxGenre.TabIndex = 36; + // + // textBoxName + // + textBoxName.Location = new Point(854, 19); + textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(265, 27); + textBoxName.TabIndex = 38; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(681, 22); + label6.Name = "label6"; + label6.Size = new Size(80, 20); + label6.TabIndex = 37; + label6.Text = "Название:"; + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(853, 118); + dateTimePickerDate.Margin = new Padding(3, 4, 3, 4); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(265, 27); + dateTimePickerDate.TabIndex = 42; + // + // textBoxISBN + // + textBoxISBN.Location = new Point(855, 170); + textBoxISBN.Margin = new Padding(3, 4, 3, 4); + textBoxISBN.Name = "textBoxISBN"; + textBoxISBN.Size = new Size(265, 27); + textBoxISBN.TabIndex = 46; + // + // label7 + // + label7.AutoSize = true; + label7.Location = new Point(682, 173); + label7.Name = "label7"; + label7.Size = new Size(44, 20); + label7.TabIndex = 45; + label7.Text = "ISBN:"; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(855, 219); + textBoxPrice.Margin = new Padding(3, 4, 3, 4); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(265, 27); + textBoxPrice.TabIndex = 44; + // + // label8 + // + label8.AutoSize = true; + label8.Location = new Point(682, 222); + label8.Name = "label8"; + label8.Size = new Size(48, 20); + label8.TabIndex = 43; + label8.Text = "Цена:"; + // + // FormBook + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1131, 600); + Controls.Add(textBoxISBN); + Controls.Add(label7); + Controls.Add(textBoxPrice); + Controls.Add(label8); + Controls.Add(dateTimePickerDate); + Controls.Add(textBoxName); + Controls.Add(label6); + Controls.Add(textBoxGenre); + Controls.Add(comboBoxPublisher); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(comboBoxAuthor); + Controls.Add(label2); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(label1); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormBook"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Книги"; + Load += FormBook_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + private ComboBox comboBoxBodyType; + private Label label5; + private Label label1; + private DataGridView dataGridView; + private Label label2; + private ComboBox comboBoxAuthor; + private Label label3; + private Label label4; + private ComboBox comboBoxPublisher; + private TextBox textBoxGenre; + private TextBox textBoxName; + private Label label6; + private DateTimePicker dateTimePickerDate; + private TextBox textBoxISBN; + private Label label7; + private TextBox textBoxPrice; + private Label label8; + } +} \ No newline at end of file diff --git a/Booking/BookingView/FormBook.cs b/Booking/BookingView/FormBook.cs new file mode 100644 index 0000000..130a715 --- /dev/null +++ b/Booking/BookingView/FormBook.cs @@ -0,0 +1,152 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; + +namespace BookingView +{ + public partial class FormBook : Form + { + private readonly IBookWork _bookLogic; + + private readonly IAuthorWork _authorLogic; + + private readonly IPublisherWork _publisherLogic; + + public FormBook(IBookWork bookLogic, IAuthorWork authorLogic, IPublisherWork publisherLogic) + { + InitializeComponent(); + _bookLogic = bookLogic; + _authorLogic = authorLogic; + _publisherLogic = publisherLogic; + } + + private void FormBook_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + var books = _bookLogic.GetAll(); + + dataGridView.Rows.Clear(); + + if (dataGridView.ColumnCount == 0) + { + dataGridView.Columns.Add("Id", "ID"); + dataGridView.Columns.Add("Name", "Название"); + dataGridView.Columns.Add("Genre", "Жанр"); + dataGridView.Columns.Add("Date", "Дата публикации"); + dataGridView.Columns.Add("ISBN", "ISBN"); + dataGridView.Columns.Add("Price", "Цена"); + dataGridView.Columns.Add("AuthorId", "AuthorId"); + dataGridView.Columns.Add("PublisherId", "PublisherId"); + dataGridView.Columns["AuthorId"].Visible = false; + dataGridView.Columns["PublisherId"].Visible = false; + dataGridView.Columns.Add("Author", "Автор"); + dataGridView.Columns.Add("Publisher", "Издательство"); + } + + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Genre"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ISBN"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Price"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Author"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Publisher"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + comboBoxAuthor.DataSource = _authorLogic.GetAll(); + comboBoxAuthor.DisplayMember = "Author"; + comboBoxAuthor.ValueMember = "Name"; + + comboBoxPublisher.DataSource = _publisherLogic.GetAll(); + comboBoxPublisher.DisplayMember = "Publisher"; + comboBoxPublisher.ValueMember = "Name"; + + foreach (var book in books) + { + dataGridView.Rows.Add(book.Id, book.Name, book.Genre, book.Date, book.ISBN, book.Price, book.AuthorId, book.PublisherId, _authorLogic.Get(book.AuthorId)?.Name, _publisherLogic.Get(book.PublisherId)?.Name); + } + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Book newBook = new() + { + Name = textBoxName.Text, + Genre = textBoxGenre.Text, + Date = dateTimePickerDate.Value, + ISBN = Convert.ToInt32(textBoxISBN.Text), + Price = Convert.ToInt32(textBoxPrice.Text), + AuthorId = ((Author?)comboBoxAuthor.SelectedItem)?.Id ?? 0, + PublisherId = ((Publisher?)comboBoxPublisher.SelectedItem)?.Id ?? 0, + }; + + _bookLogic.Create(newBook); + + LoadData(); + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int bookId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + Book updatedBook = new() + { + Id = bookId, + Name = textBoxName.Text, + Genre = textBoxGenre.Text, + Date = dateTimePickerDate.Value, + ISBN = Convert.ToInt32(textBoxISBN.Text), + Price = Convert.ToInt32(textBoxPrice.Text), + AuthorId = ((Author?)comboBoxAuthor.SelectedItem)?.Id ?? 0, + PublisherId = ((Publisher?)comboBoxPublisher.SelectedItem)?.Id ?? 0, + }; + + _bookLogic.Update(updatedBook); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите отзыв, которое необходимо обновить"); + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int bookId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + _bookLogic.Delete(bookId); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите отзыв, которое необходимо удалить"); + } + } + + private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0) + { + DataGridViewRow row = dataGridView.Rows[e.RowIndex]; + textBoxName.Text = row.Cells["Name"].Value.ToString(); + textBoxGenre.Text = row.Cells["Genre"].Value.ToString(); + dateTimePickerDate.Value = DateTime.Parse(row.Cells["Date"].Value.ToString()); + textBoxISBN.Text = row.Cells["ISBN"].Value.ToString(); + textBoxPrice.Text = row.Cells["Price"].Value.ToString(); + comboBoxAuthor.SelectedValue = row.Cells["Author"].Value; + comboBoxPublisher.SelectedValue = row.Cells["Publisher"].Value; + } + } + } +} diff --git a/Booking/BookingView/FormBook.resx b/Booking/BookingView/FormBook.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Booking/BookingView/FormBook.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Booking/BookingView/FormBooking.Designer.cs b/Booking/BookingView/FormBooking.Designer.cs new file mode 100644 index 0000000..aff81b2 --- /dev/null +++ b/Booking/BookingView/FormBooking.Designer.cs @@ -0,0 +1,232 @@ +namespace BookingView +{ + partial class FormBooking + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + label1 = new Label(); + dataGridView = new DataGridView(); + label2 = new Label(); + comboBoxClient = new ComboBox(); + label3 = new Label(); + label4 = new Label(); + comboBoxBook = new ComboBox(); + textBoxStatus = new TextBox(); + textBoxSum = new TextBox(); + label6 = new Label(); + dateTimePickerDate = new DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonDelete + // + buttonDelete.Location = new Point(847, 545); + buttonDelete.Margin = new Padding(3, 4, 3, 4); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(146, 40); + buttonDelete.TabIndex = 28; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(847, 480); + buttonUpdate.Margin = new Padding(3, 4, 3, 4); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(146, 40); + buttonUpdate.TabIndex = 27; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(847, 415); + buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(146, 40); + buttonCreate.TabIndex = 26; + buttonCreate.Text = "Добавить"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(681, 21); + label1.Name = "label1"; + label1.Size = new Size(97, 20); + label1.TabIndex = 16; + label1.Text = "Дата заказа: "; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(15, 19); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(649, 568); + dataGridView.TabIndex = 15; + dataGridView.CellClick += DataGridView_CellClick; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(681, 182); + label2.Name = "label2"; + label2.Size = new Size(61, 20); + label2.TabIndex = 29; + label2.Text = "Клиент:"; + // + // comboBoxClient + // + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(853, 178); + comboBoxClient.Margin = new Padding(3, 4, 3, 4); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(265, 28); + comboBoxClient.TabIndex = 30; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(681, 231); + label3.Name = "label3"; + label3.Size = new Size(53, 20); + label3.TabIndex = 33; + label3.Text = "Книга:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(681, 71); + label4.Name = "label4"; + label4.Size = new Size(55, 20); + label4.TabIndex = 34; + label4.Text = "Статус:"; + // + // comboBoxBook + // + comboBoxBook.FormattingEnabled = true; + comboBoxBook.Location = new Point(854, 228); + comboBoxBook.Margin = new Padding(3, 4, 3, 4); + comboBoxBook.Name = "comboBoxBook"; + comboBoxBook.Size = new Size(265, 28); + comboBoxBook.TabIndex = 35; + // + // textBoxStatus + // + textBoxStatus.Location = new Point(854, 68); + textBoxStatus.Margin = new Padding(3, 4, 3, 4); + textBoxStatus.Name = "textBoxStatus"; + textBoxStatus.Size = new Size(265, 27); + textBoxStatus.TabIndex = 36; + // + // textBoxSum + // + textBoxSum.Location = new Point(854, 123); + textBoxSum.Margin = new Padding(3, 4, 3, 4); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(265, 27); + textBoxSum.TabIndex = 38; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(681, 126); + label6.Name = "label6"; + label6.Size = new Size(58, 20); + label6.TabIndex = 37; + label6.Text = "Сумма:"; + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(853, 16); + dateTimePickerDate.Margin = new Padding(3, 4, 3, 4); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(265, 27); + dateTimePickerDate.TabIndex = 42; + // + // FormBooking + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1131, 600); + Controls.Add(dateTimePickerDate); + Controls.Add(textBoxSum); + Controls.Add(label6); + Controls.Add(textBoxStatus); + Controls.Add(comboBoxBook); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(comboBoxClient); + Controls.Add(label2); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(label1); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormBooking"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказы"; + Load += FormBooking_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + private Label label5; + private Label label1; + private DataGridView dataGridView; + private Label label2; + private ComboBox comboBoxClient; + private Label label3; + private Label label4; + private ComboBox comboBoxBook; + private TextBox textBoxStatus; + private TextBox textBoxSum; + private Label label6; + private DateTimePicker dateTimePickerDate; + } +} \ No newline at end of file diff --git a/Booking/BookingView/FormBooking.cs b/Booking/BookingView/FormBooking.cs new file mode 100644 index 0000000..5ef7847 --- /dev/null +++ b/Booking/BookingView/FormBooking.cs @@ -0,0 +1,141 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; +using System.Windows.Forms.VisualStyles; + +namespace BookingView +{ + public partial class FormBooking : Form + { + private readonly IBookingWork _bookingLogic; + + private readonly IClientWork _clientLogic; + + private readonly IBookWork _bookLogic; + + public FormBooking(IBookingWork bookingLogic, IClientWork clientLogic, IBookWork bookLogic) + { + InitializeComponent(); + _bookingLogic = bookingLogic; + _clientLogic = clientLogic; + _bookLogic = bookLogic; + } + + private void FormBooking_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + var bookings = _bookingLogic.GetAll(); + + dataGridView.Rows.Clear(); + + if (dataGridView.ColumnCount == 0) + { + dataGridView.Columns.Add("Id", "ID"); + dataGridView.Columns.Add("Date", "Дата"); + dataGridView.Columns.Add("Status", "Статус"); + dataGridView.Columns.Add("Sum", "Сумма"); + dataGridView.Columns.Add("ClientId", "ClientId"); + dataGridView.Columns.Add("BookId", "BookId"); + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["BookId"].Visible = false; + dataGridView.Columns.Add("Client", "Клиент"); + dataGridView.Columns.Add("Book", "Книга"); + } + + dataGridView.Columns["Date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Status"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Sum"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Client"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Book"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + comboBoxClient.DataSource = _clientLogic.GetAll(); + comboBoxClient.DisplayMember = "Client"; + comboBoxClient.ValueMember = "Name"; + + comboBoxBook.DataSource = _bookLogic.GetAll(); + comboBoxBook.DisplayMember = "Book"; + comboBoxBook.ValueMember = "Name"; + + foreach (var booking in bookings) + { + dataGridView.Rows.Add(booking.Id, booking.Date, booking.Status, booking.Sum, booking.ClientId, booking.BookId, _clientLogic.Get(booking.ClientId)?.Name, _bookLogic.Get(booking.BookId)?.Name); + } + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Booking newBooking = new() + { + Date = dateTimePickerDate.Value, + Status = textBoxStatus.Text, + Sum = Convert.ToInt32(textBoxSum.Text), + ClientId = ((Client?)comboBoxClient.SelectedItem)?.Id ?? 0, + BookId = ((Book?)comboBoxBook.SelectedItem)?.Id ?? 0, + }; + + _bookingLogic.Create(newBooking); + + LoadData(); + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int bookingId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + Booking updatedBooking = new() + { + Id = bookingId, + Date = dateTimePickerDate.Value, + Status = textBoxStatus.Text, + Sum = Convert.ToInt32(textBoxSum.Text), + ClientId = ((Client?)comboBoxClient.SelectedItem)?.Id ?? 0, + BookId = ((Book?)comboBoxBook.SelectedItem)?.Id ?? 0, + }; + + _bookingLogic.Update(updatedBooking); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите отзыв, которое необходимо обновить"); + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int bookingId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + _bookingLogic.Delete(bookingId); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите отзыв, которое необходимо удалить"); + } + } + + private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0) + { + DataGridViewRow row = dataGridView.Rows[e.RowIndex]; + dateTimePickerDate.Value = DateTime.Parse(row.Cells["Date"].Value.ToString()); + textBoxStatus.Text = row.Cells["Status"].Value.ToString(); + textBoxSum.Text = row.Cells["Sum"].Value.ToString(); + comboBoxClient.SelectedValue = row.Cells["Client"].Value; + comboBoxBook.SelectedValue =row.Cells["Book"].Value; + } + } + } +} diff --git a/Booking/BookingView/FormBooking.resx b/Booking/BookingView/FormBooking.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Booking/BookingView/FormBooking.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Booking/BookingView/FormClient.Designer.cs b/Booking/BookingView/FormClient.Designer.cs new file mode 100644 index 0000000..1c33d36 --- /dev/null +++ b/Booking/BookingView/FormClient.Designer.cs @@ -0,0 +1,229 @@ +namespace BookingView +{ + partial class FormClient + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + textBoxName = new TextBox(); + label1 = new Label(); + dataGridView = new DataGridView(); + textBoxLastName = new TextBox(); + label3 = new Label(); + textBoxPhone = new TextBox(); + label4 = new Label(); + textBoxEmail = new TextBox(); + label5 = new Label(); + textBoxAddress = new TextBox(); + label2 = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonDelete + // + buttonDelete.Location = new Point(888, 521); + buttonDelete.Margin = new Padding(3, 4, 3, 4); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(146, 40); + buttonDelete.TabIndex = 28; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(888, 455); + buttonUpdate.Margin = new Padding(3, 4, 3, 4); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(146, 40); + buttonUpdate.TabIndex = 27; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(888, 390); + buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(146, 40); + buttonCreate.TabIndex = 26; + buttonCreate.Text = "Добавить"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // textBoxName + // + textBoxName.Location = new Point(909, 58); + textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(229, 27); + textBoxName.TabIndex = 21; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(748, 61); + label1.Name = "label1"; + label1.Size = new Size(46, 20); + label1.TabIndex = 16; + label1.Text = "Имя: "; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(15, 19); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(697, 811); + dataGridView.TabIndex = 15; + dataGridView.CellClick += DataGridView_CellClick; + // + // textBoxLastName + // + textBoxLastName.Location = new Point(909, 116); + textBoxLastName.Margin = new Padding(3, 4, 3, 4); + textBoxLastName.Name = "textBoxLastName"; + textBoxLastName.Size = new Size(229, 27); + textBoxLastName.TabIndex = 32; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(748, 119); + label3.Name = "label3"; + label3.Size = new Size(80, 20); + label3.TabIndex = 31; + label3.Text = "Фамилия: "; + // + // textBoxPhone + // + textBoxPhone.Location = new Point(909, 291); + textBoxPhone.Margin = new Padding(3, 4, 3, 4); + textBoxPhone.Name = "textBoxPhone"; + textBoxPhone.Size = new Size(230, 27); + textBoxPhone.TabIndex = 38; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(749, 294); + label4.Name = "label4"; + label4.Size = new Size(76, 20); + label4.TabIndex = 37; + label4.Text = "Телефон: "; + // + // textBoxEmail + // + textBoxEmail.Location = new Point(909, 233); + textBoxEmail.Margin = new Padding(3, 4, 3, 4); + textBoxEmail.Name = "textBoxEmail"; + textBoxEmail.Size = new Size(229, 27); + textBoxEmail.TabIndex = 40; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(748, 236); + label5.Name = "label5"; + label5.Size = new Size(54, 20); + label5.TabIndex = 39; + label5.Text = "Почта:"; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(909, 173); + textBoxAddress.Margin = new Padding(3, 4, 3, 4); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(229, 27); + textBoxAddress.TabIndex = 41; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(748, 176); + label2.Name = "label2"; + label2.Size = new Size(58, 20); + label2.TabIndex = 42; + label2.Text = "Адрес: "; + // + // FormClient + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1159, 845); + Controls.Add(label2); + Controls.Add(textBoxAddress); + Controls.Add(textBoxEmail); + Controls.Add(label5); + Controls.Add(textBoxPhone); + Controls.Add(label4); + Controls.Add(textBoxLastName); + Controls.Add(label3); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(textBoxName); + Controls.Add(label1); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormClient"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Клиенты"; + Load += FormClient_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + private TextBox textBoxName; + private Label label5; + private Label label1; + private TextBox textBoxPhone; + private TextBox textBoxLastName; + private Label label3; + private Label label4; + private TextBox textBoxEmail; + private DataGridView dataGridView; + private TextBox textBoxAddress; + private Label label2; + } +} \ No newline at end of file diff --git a/Booking/BookingView/FormClient.cs b/Booking/BookingView/FormClient.cs new file mode 100644 index 0000000..a20189b --- /dev/null +++ b/Booking/BookingView/FormClient.cs @@ -0,0 +1,123 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; + +namespace BookingView +{ + public partial class FormClient : Form + { + private readonly IClientWork _logic; + + public FormClient(IClientWork logic) + { + InitializeComponent(); + _logic = logic; + } + + private void FormClient_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + var clients = _logic.GetAll(); + + dataGridView.Rows.Clear(); + + if (dataGridView.ColumnCount == 0) + { + dataGridView.Columns.Add("Id", "ID"); + dataGridView.Columns.Add("Name", "Имя"); + dataGridView.Columns.Add("LastName", "Фамилия"); + dataGridView.Columns.Add("Address", "Адрес"); + dataGridView.Columns.Add("Email", "Почта"); + dataGridView.Columns.Add("PhoneNumber", "Номер"); + } + + dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["LastName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Email"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PhoneNumber"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + foreach (var client in clients) + { + dataGridView.Rows.Add(client.Id, client.Name, client.LastName, client.Address, client.Email, client.PhoneNumber); + } + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Client newClient = new() + { + Name = textBoxName.Text, + LastName = textBoxLastName.Text, + Address = textBoxAddress.Text, + Email = textBoxEmail.Text, + PhoneNumber = textBoxPhone.Text, + }; + + _logic.Create(newClient); + + LoadData(); + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int clientId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + Client updatedClient = new() + { + Id = clientId, + Name = textBoxName.Text, + LastName = textBoxLastName.Text, + Address = textBoxAddress.Text, + Email = textBoxEmail.Text, + PhoneNumber = textBoxPhone.Text, + }; + + _logic.Update(updatedClient); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите клиента, информацию о котором необходимо обновить"); + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int clientId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + _logic.Delete(clientId); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите клиента, информацию о котором необходимо удалить"); + } + } + + private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0) + { + DataGridViewRow row = dataGridView.Rows[e.RowIndex]; + textBoxName.Text = row.Cells["Name"].Value.ToString(); + textBoxLastName.Text = row.Cells["LastName"].Value.ToString(); + textBoxAddress.Text = row.Cells["Address"].Value.ToString(); + textBoxEmail.Text = row.Cells["Email"].Value.ToString(); + textBoxPhone.Text = row.Cells["PhoneNumber"].Value.ToString(); + } + } + } +} diff --git a/Booking/BookingView/FormClient.resx b/Booking/BookingView/FormClient.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Booking/BookingView/FormClient.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Booking/BookingView/FormMain.Designer.cs b/Booking/BookingView/FormMain.Designer.cs index 93144e7..a4dba16 100644 --- a/Booking/BookingView/FormMain.Designer.cs +++ b/Booking/BookingView/FormMain.Designer.cs @@ -30,16 +30,26 @@ { menuStrip1 = new MenuStrip(); справочникиToolStripMenuItem = new ToolStripMenuItem(); - замерВремениToolStripMenuItem = new ToolStripMenuItem(); - labelTest = new Label(); издателиToolStripMenuItem = new ToolStripMenuItem(); + авторыToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); + отзывыToolStripMenuItem = new ToolStripMenuItem(); + заказыToolStripMenuItem = new ToolStripMenuItem(); + книгиToolStripMenuItem = new ToolStripMenuItem(); + замерВремениToolStripMenuItem = new ToolStripMenuItem(); + замерыВремениToolStripMenuItem = new ToolStripMenuItem(); + добавление1000ToolStripMenuItem = new ToolStripMenuItem(); + получение1000ToolStripMenuItem = new ToolStripMenuItem(); + обновление1000ToolStripMenuItem = new ToolStripMenuItem(); + удаление1000ToolStripMenuItem = new ToolStripMenuItem(); + labelTest = new Label(); menuStrip1.SuspendLayout(); SuspendLayout(); // // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, замерВремениToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, замерВремениToolStripMenuItem, замерыВремениToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Padding = new Padding(7, 3, 0, 3); @@ -49,11 +59,93 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { издателиToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { издателиToolStripMenuItem, авторыToolStripMenuItem, клиентыToolStripMenuItem, отзывыToolStripMenuItem, заказыToolStripMenuItem, книгиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; // + // издателиToolStripMenuItem + // + издателиToolStripMenuItem.Name = "издателиToolStripMenuItem"; + издателиToolStripMenuItem.Size = new Size(157, 26); + издателиToolStripMenuItem.Text = "Издатели"; + издателиToolStripMenuItem.Click += издателиToolStripMenuItem_Click; + // + // авторыToolStripMenuItem + // + авторыToolStripMenuItem.Name = "авторыToolStripMenuItem"; + авторыToolStripMenuItem.Size = new Size(157, 26); + авторыToolStripMenuItem.Text = "Авторы"; + авторыToolStripMenuItem.Click += авторыToolStripMenuItem_Click; + // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(157, 26); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; + // + // отзывыToolStripMenuItem + // + отзывыToolStripMenuItem.Name = "отзывыToolStripMenuItem"; + отзывыToolStripMenuItem.Size = new Size(157, 26); + отзывыToolStripMenuItem.Text = "Отзывы"; + отзывыToolStripMenuItem.Click += отзывыToolStripMenuItem_Click; + // + // заказыToolStripMenuItem + // + заказыToolStripMenuItem.Name = "заказыToolStripMenuItem"; + заказыToolStripMenuItem.Size = new Size(157, 26); + заказыToolStripMenuItem.Text = "Заказы"; + заказыToolStripMenuItem.Click += заказыToolStripMenuItem_Click; + // + // книгиToolStripMenuItem + // + книгиToolStripMenuItem.Name = "книгиToolStripMenuItem"; + книгиToolStripMenuItem.Size = new Size(157, 26); + книгиToolStripMenuItem.Text = "Книги"; + книгиToolStripMenuItem.Click += книгиToolStripMenuItem_Click; + // + // замерВремениToolStripMenuItem + // + замерВремениToolStripMenuItem.Name = "замерВремениToolStripMenuItem"; + замерВремениToolStripMenuItem.Size = new Size(14, 24); + // + // замерыВремениToolStripMenuItem + // + замерыВремениToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { добавление1000ToolStripMenuItem, получение1000ToolStripMenuItem, обновление1000ToolStripMenuItem, удаление1000ToolStripMenuItem }); + замерыВремениToolStripMenuItem.Name = "замерыВремениToolStripMenuItem"; + замерыВремениToolStripMenuItem.Size = new Size(144, 24); + замерыВремениToolStripMenuItem.Text = "Замеры времени"; + // + // добавление1000ToolStripMenuItem + // + добавление1000ToolStripMenuItem.Name = "добавление1000ToolStripMenuItem"; + добавление1000ToolStripMenuItem.Size = new Size(224, 26); + добавление1000ToolStripMenuItem.Text = "Добавление 1000"; + добавление1000ToolStripMenuItem.Click += добавление1000ToolStripMenuItem_Click; + // + // получение1000ToolStripMenuItem + // + получение1000ToolStripMenuItem.Name = "получение1000ToolStripMenuItem"; + получение1000ToolStripMenuItem.Size = new Size(224, 26); + получение1000ToolStripMenuItem.Text = "Получение 1000"; + получение1000ToolStripMenuItem.Click += получение1000ToolStripMenuItem_Click; + // + // обновление1000ToolStripMenuItem + // + обновление1000ToolStripMenuItem.Name = "обновление1000ToolStripMenuItem"; + обновление1000ToolStripMenuItem.Size = new Size(224, 26); + обновление1000ToolStripMenuItem.Text = "Обновление 1000"; + обновление1000ToolStripMenuItem.Click += обновление1000ToolStripMenuItem_Click; + // + // удаление1000ToolStripMenuItem + // + удаление1000ToolStripMenuItem.Name = "удаление1000ToolStripMenuItem"; + удаление1000ToolStripMenuItem.Size = new Size(224, 26); + удаление1000ToolStripMenuItem.Text = "Удаление 1000"; + удаление1000ToolStripMenuItem.Click += удаление1000ToolStripMenuItem_Click; + // // labelTest // labelTest.BorderStyle = BorderStyle.FixedSingle; @@ -63,13 +155,6 @@ labelTest.TabIndex = 3; labelTest.TextAlign = ContentAlignment.MiddleCenter; // - // издателиToolStripMenuItem - // - издателиToolStripMenuItem.Name = "издателиToolStripMenuItem"; - издателиToolStripMenuItem.Size = new Size(224, 26); - издателиToolStripMenuItem.Text = "Издатели"; - издателиToolStripMenuItem.Click += издателиToolStripMenuItem_Click; - // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -95,5 +180,15 @@ private ToolStripMenuItem замерВремениToolStripMenuItem; private Label labelTest; private ToolStripMenuItem издателиToolStripMenuItem; + private ToolStripMenuItem авторыToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem отзывыToolStripMenuItem; + private ToolStripMenuItem заказыToolStripMenuItem; + private ToolStripMenuItem книгиToolStripMenuItem; + private ToolStripMenuItem замерыВремениToolStripMenuItem; + private ToolStripMenuItem добавление1000ToolStripMenuItem; + private ToolStripMenuItem получение1000ToolStripMenuItem; + private ToolStripMenuItem обновление1000ToolStripMenuItem; + private ToolStripMenuItem удаление1000ToolStripMenuItem; } } \ No newline at end of file diff --git a/Booking/BookingView/FormMain.cs b/Booking/BookingView/FormMain.cs index 686341e..c1644d0 100644 --- a/Booking/BookingView/FormMain.cs +++ b/Booking/BookingView/FormMain.cs @@ -1,4 +1,5 @@ -using BookingAbstractions.WorkAbstractions; +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; namespace BookingView { @@ -18,5 +19,126 @@ namespace BookingView form.ShowDialog(); } } + + private void авторыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAuthor)); + if (service is FormAuthor form) + { + form.ShowDialog(); + } + } + + private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPublisher)); + if (service is FormPublisher form) + { + form.ShowDialog(); + } + } + + private void отзывыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReview)); + if (service is FormReview form) + { + form.ShowDialog(); + } + } + + private void заказыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBooking)); + if (service is FormBooking form) + { + form.ShowDialog(); + } + } + + private void книгиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBook)); + if (service is FormBook form) + { + form.ShowDialog(); + } + } + + private void добавление1000ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(IPublisherWork)); + if (service is IPublisherWork publisherLogic) + { + DateTime startTime = DateTime.Now; + for (int i = 0; i < 1000; i++) + { + Publisher publisher = new() + { + Name = "Название №" + i, + Address = "Адрес " + i, + PhoneNumber = "Номер " + i + }; + publisherLogic.Create(publisher); + } + DateTime endTime = DateTime.Now; + + labelTest.Text = $"Добавление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд"; + } + } + + private void получение1000ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(IPublisherWork)); + if (service is IPublisherWork publisherLogic) + { + DateTime startTime = DateTime.Now; + publisherLogic.GetAll(); + DateTime endTime = DateTime.Now; + + labelTest.Text = $"Получение 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд"; + } + } + + private void обновление1000ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(IPublisherWork)); + if (service is IPublisherWork publisherLogic) + { + List ids = publisherLogic.GetAll().Select(area => area.Id).ToList(); + DateTime startTime = DateTime.Now; + for (int i = 0; i < ids.Count; i++) + { + Publisher publisher = new() + { + Id = ids[i], + Name = "Название №" + i + 2000, + Address = "Адрес " + i + 2000, + PhoneNumber = "Номер " + i + 2000 + }; + publisherLogic.Update(publisher); + } + DateTime endTime = DateTime.Now; + + labelTest.Text = $"Обновление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд"; + } + } + + private void удаление1000ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(IPublisherWork)); + if (service is IPublisherWork publisherLogic) + { + List ids = publisherLogic.GetAll().Select(area => area.Id).ToList(); + DateTime startTime = DateTime.Now; + for (int i = 0; i < ids.Count; i++) + { + publisherLogic.Delete(ids[i]); + } + DateTime endTime = DateTime.Now; + + labelTest.Text = $"Удаление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд"; + } + } } } diff --git a/Booking/BookingView/FormPublisher.Designer.cs b/Booking/BookingView/FormPublisher.Designer.cs index 9f6c024..30a4dac 100644 --- a/Booking/BookingView/FormPublisher.Designer.cs +++ b/Booking/BookingView/FormPublisher.Designer.cs @@ -172,11 +172,6 @@ private Button buttonDelete; private Button buttonUpdate; private Button buttonCreate; - private ComboBox comboBoxBodyType; - private TextBox textBoxSeats; - private TextBox textBoxYear; - private TextBox textBoxModel; - private Label label5; private DataGridView dataGridView; private TextBox textBoxPublisherName; private Label label1; diff --git a/Booking/BookingView/FormReview.Designer.cs b/Booking/BookingView/FormReview.Designer.cs new file mode 100644 index 0000000..bf1d0c7 --- /dev/null +++ b/Booking/BookingView/FormReview.Designer.cs @@ -0,0 +1,209 @@ +namespace BookingView +{ + partial class FormReview + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + textBoxScore = new TextBox(); + label1 = new Label(); + dataGridView = new DataGridView(); + label2 = new Label(); + comboBoxClient = new ComboBox(); + label3 = new Label(); + label4 = new Label(); + comboBoxBook = new ComboBox(); + textBoxText = new TextBox(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonDelete + // + buttonDelete.Location = new Point(847, 545); + buttonDelete.Margin = new Padding(3, 4, 3, 4); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(146, 40); + buttonDelete.TabIndex = 28; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(847, 480); + buttonUpdate.Margin = new Padding(3, 4, 3, 4); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(146, 40); + buttonUpdate.TabIndex = 27; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(847, 415); + buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(146, 40); + buttonCreate.TabIndex = 26; + buttonCreate.Text = "Добавить"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // textBoxScore + // + textBoxScore.Location = new Point(853, 17); + textBoxScore.Margin = new Padding(3, 4, 3, 4); + textBoxScore.Name = "textBoxScore"; + textBoxScore.Size = new Size(265, 27); + textBoxScore.TabIndex = 21; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(681, 21); + label1.Name = "label1"; + label1.Size = new Size(68, 20); + label1.TabIndex = 16; + label1.Text = "Оценка: "; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(15, 19); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(649, 568); + dataGridView.TabIndex = 15; + dataGridView.CellClick += DataGridView_CellClick; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(681, 120); + label2.Name = "label2"; + label2.Size = new Size(61, 20); + label2.TabIndex = 29; + label2.Text = "Клиент:"; + // + // comboBoxClient + // + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(853, 116); + comboBoxClient.Margin = new Padding(3, 4, 3, 4); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(265, 28); + comboBoxClient.TabIndex = 30; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(681, 169); + label3.Name = "label3"; + label3.Size = new Size(53, 20); + label3.TabIndex = 33; + label3.Text = "Книга:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(681, 71); + label4.Name = "label4"; + label4.Size = new Size(101, 20); + label4.TabIndex = 34; + label4.Text = "Текст отзыва:"; + // + // comboBoxBook + // + comboBoxBook.FormattingEnabled = true; + comboBoxBook.Location = new Point(854, 166); + comboBoxBook.Margin = new Padding(3, 4, 3, 4); + comboBoxBook.Name = "comboBoxBook"; + comboBoxBook.Size = new Size(265, 28); + comboBoxBook.TabIndex = 35; + // + // textBoxText + // + textBoxText.Location = new Point(854, 68); + textBoxText.Margin = new Padding(3, 4, 3, 4); + textBoxText.Name = "textBoxText"; + textBoxText.Size = new Size(265, 27); + textBoxText.TabIndex = 36; + // + // FormReview + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1131, 600); + Controls.Add(textBoxText); + Controls.Add(comboBoxBook); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(comboBoxClient); + Controls.Add(label2); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(textBoxScore); + Controls.Add(label1); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormReview"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Отзывы"; + Load += FormReview_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + private ComboBox comboBoxBodyType; + private TextBox textBoxScore; + private Label label1; + private DataGridView dataGridView; + private Label label2; + private ComboBox comboBoxClient; + private Label label3; + private Label label4; + private ComboBox comboBoxBook; + private TextBox textBoxText; + } +} \ No newline at end of file diff --git a/Booking/BookingView/FormReview.cs b/Booking/BookingView/FormReview.cs new file mode 100644 index 0000000..b36ca55 --- /dev/null +++ b/Booking/BookingView/FormReview.cs @@ -0,0 +1,135 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; + +namespace BookingView +{ + public partial class FormReview : Form + { + private readonly IReviewWork _reviewLogic; + + private readonly IClientWork _clientLogic; + + private readonly IBookWork _bookLogic; + + public FormReview(IReviewWork reviewLogic, IClientWork clientLogic, IBookWork bookLogic) + { + InitializeComponent(); + _reviewLogic = reviewLogic; + _clientLogic = clientLogic; + _bookLogic = bookLogic; + } + + private void FormReview_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + var reviews = _reviewLogic.GetAll(); + + dataGridView.Rows.Clear(); + + if (dataGridView.ColumnCount == 0) + { + dataGridView.Columns.Add("Id", "ID"); + dataGridView.Columns.Add("Score", "Оценка"); + dataGridView.Columns.Add("Text", "Текст"); + dataGridView.Columns.Add("ClientId", "ClientId"); + dataGridView.Columns.Add("BookId", "BookId"); + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["BookId"].Visible = false; + dataGridView.Columns.Add("Client", "Клиент"); + dataGridView.Columns.Add("Book", "Книга"); + } + + dataGridView.Columns["Score"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Text"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Client"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Book"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + comboBoxClient.DataSource = _clientLogic.GetAll(); + comboBoxClient.DisplayMember = "Client"; + comboBoxClient.ValueMember = "Name"; + + comboBoxBook.DataSource = _bookLogic.GetAll(); + comboBoxBook.DisplayMember = "Book"; + comboBoxBook.ValueMember = "Name"; + + foreach (var review in reviews) + { + dataGridView.Rows.Add(review.Id, review.Score, review.Text, review.ClientId, review.BookId, _clientLogic.Get(review.ClientId)?.Name, _bookLogic.Get(review.BookId)?.Name); + } + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Review newReview = new() + { + Score = Convert.ToInt32(textBoxScore.Text), + Text = textBoxText.Text, + ClientId = ((Client?)comboBoxClient.SelectedItem)?.Id ?? 0, + BookId = ((Book?)comboBoxBook.SelectedItem)?.Id ?? 0, + }; + + _reviewLogic.Create(newReview); + + LoadData(); + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int reviewId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + Review updatedReview = new() + { + Id = reviewId, + Score = Convert.ToInt32(textBoxScore.Text), + Text = textBoxText.Text, + ClientId = ((Client?)comboBoxClient.SelectedItem)?.Id ?? 0, + BookId = ((Book?)comboBoxBook.SelectedItem)?.Id ?? 0, + }; + + _reviewLogic.Update(updatedReview); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите отзыв, которое необходимо обновить"); + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int reviewId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + _reviewLogic.Delete(reviewId); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите отзыв, которое необходимо удалить"); + } + } + + private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0) + { + DataGridViewRow row = dataGridView.Rows[e.RowIndex]; + textBoxScore.Text = row.Cells["Score"].Value.ToString(); + textBoxText.Text = row.Cells["Text"].Value.ToString(); + comboBoxClient.SelectedValue = row.Cells["Client"].Value; + comboBoxBook.SelectedValue = row.Cells["Book"].Value; + } + } + } +} diff --git a/Booking/BookingView/FormReview.resx b/Booking/BookingView/FormReview.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Booking/BookingView/FormReview.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Booking/BookingView/Program.cs b/Booking/BookingView/Program.cs index b0d1a01..f986f51 100644 --- a/Booking/BookingView/Program.cs +++ b/Booking/BookingView/Program.cs @@ -25,8 +25,19 @@ namespace BookingView private static void ConfigureServices(ServiceCollection services) { services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file