Готовая лабораторная

This commit is contained in:
Даниил Путинцев 2024-05-15 11:18:27 +04:00
parent 20a6b8ebcf
commit 88fdddcf23
36 changed files with 3319 additions and 18 deletions

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -0,0 +1,18 @@
using BookingAbstractions.Models;
namespace BookingAbstractions.WorkAbstractions
{
public interface IAuthorWork
{
List<Author> GetAll();
Author? Get(int id);
Author? Create(Author author);
Author? Update(Author author);
Author? Delete(int id);
}
}

View File

@ -0,0 +1,17 @@
using BookingAbstractions.Models;
namespace BookingAbstractions.WorkAbstractions
{
public interface IBookWork
{
List<Book> GetAll();
Book? Get(int id);
Book? Create(Book book);
Book? Update(Book book);
Book? Delete(int id);
}
}

View File

@ -0,0 +1,17 @@
using BookingAbstractions.Models;
namespace BookingAbstractions.WorkAbstractions
{
public interface IBookingWork
{
List<Booking> GetAll();
Booking? Get(int id);
Booking? Create(Booking booking);
Booking? Update(Booking booking);
Booking? Delete(int id);
}
}

View File

@ -0,0 +1,18 @@
using BookingAbstractions.Models;
namespace BookingAbstractions.WorkAbstractions
{
public interface IClientWork
{
List<Client> GetAll();
Client? Get(int id);
Client? Create(Client client);
Client? Update(Client client);
Client? Delete(int id);
}
}

View File

@ -0,0 +1,17 @@
using BookingAbstractions.Models;
namespace BookingAbstractions.WorkAbstractions
{
public interface IReviewWork
{
List<Review> GetAll();
Review? Get(int id);
Review? Create(Review review);
Review? Update(Review review);
Review? Delete(int id);
}
}

View File

@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="8.0.2" />
<PackageReference Include="Npgsql" Version="8.0.3" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,86 @@
using BookingAbstractions.Models;
using BookingAbstractions.WorkAbstractions;
using Npgsql;
namespace BookingPostgresImplementation.WorkImplementation
{
public class AuthorWork : IAuthorWork
{
public List<Author> GetAll()
{
var authors = new List<Author>();
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;
}
}
}

View File

@ -0,0 +1,94 @@
using BookingAbstractions.Models;
using BookingAbstractions.WorkAbstractions;
using Npgsql;
namespace BookingPostgresImplementation.WorkImplementation
{
public class BookWork : IBookWork
{
public List<Book> GetAll()
{
var books = new List<Book>();
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;
}
}
}

View File

@ -0,0 +1,88 @@
using BookingAbstractions.Models;
using BookingAbstractions.WorkAbstractions;
using Npgsql;
namespace BookingPostgresImplementation.WorkImplementation
{
public class BookingWork : IBookingWork
{
public List<Booking> GetAll()
{
var bookings = new List<Booking>();
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;
}
}
}

View File

@ -0,0 +1,86 @@
using BookingAbstractions.Models;
using BookingAbstractions.WorkAbstractions;
using Npgsql;
namespace BookingPostgresImplementation.WorkImplementation
{
public class ClientWork : IClientWork
{
public List<Client> GetAll()
{
var clients = new List<Client>();
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;
}
}
}

View File

@ -0,0 +1,85 @@
using BookingAbstractions.Models;
using BookingAbstractions.WorkAbstractions;
using Npgsql;
namespace BookingPostgresImplementation.WorkImplementation
{
public class ReviewWork : IReviewWork
{
public List<Review> GetAll()
{
var reviews = new List<Review>();
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;
}
}
}

View File

@ -17,4 +17,16 @@
<ProjectReference Include="..\BookingPostgresImplementation\BookingPostgresImplementation.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="FormBook.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="FormClient.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="FormBooking.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>

229
Booking/BookingView/FormAuthor.Designer.cs generated Normal file
View File

@ -0,0 +1,229 @@
namespace BookingView
{
partial class FormAuthor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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();
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

279
Booking/BookingView/FormBook.Designer.cs generated Normal file
View File

@ -0,0 +1,279 @@
namespace BookingView
{
partial class FormBook
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,232 @@
namespace BookingView
{
partial class FormBooking
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

229
Booking/BookingView/FormClient.Designer.cs generated Normal file
View File

@ -0,0 +1,229 @@
namespace BookingView
{
partial class FormClient
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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();
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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;
}
}

View File

@ -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<int> 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<int> 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} миллисекунд";
}
}
}
}

View File

@ -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;

209
Booking/BookingView/FormReview.Designer.cs generated Normal file
View File

@ -0,0 +1,209 @@
namespace BookingView
{
partial class FormReview
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -25,8 +25,19 @@ namespace BookingView
private static void ConfigureServices(ServiceCollection services)
{
services.AddTransient<IPublisherWork, PublisherWork>();
services.AddTransient<IAuthorWork, AuthorWork>();
services.AddTransient<IClientWork, ClientWork>();
services.AddTransient<IReviewWork, ReviewWork>();
services.AddTransient<IBookingWork, BookingWork>();
services.AddTransient<IBookWork, BookWork>();
services.AddTransient<FormMain>();
services.AddTransient<FormPublisher>();
services.AddTransient<FormAuthor>();
services.AddTransient<FormClient>();
services.AddTransient<FormReview>();
services.AddTransient<FormBooking>();
services.AddTransient<FormBook>();
}
}
}