ИСЭбд-21. Мосевнин А.М. LabWork_1 #1
@ -7,18 +7,18 @@
|
||||
public int Id { get; private set; }
|
||||
public string Author { get; private set; } = string.Empty;
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public BookType Type { get; private set; } = BookType.None;
|
||||
public BookType Type { get; set; } = BookType.None;
|
||||
public int LibraryID { get; private set; }
|
||||
|
||||
public static Book CreateEntity(int id, string author, string name, BookType type, int libraryID)
|
||||
public static Book CreateEntity(int id, string author, string name, int libraryID, BookType type = BookType.None)
|
||||
{
|
||||
return new Book
|
||||
{
|
||||
Id = id,
|
||||
Author = author ?? string.Empty,
|
||||
Name = name ?? string.Empty,
|
||||
Type = type,
|
||||
LibraryID = libraryID
|
||||
LibraryID = libraryID,
|
||||
Type = type
|
||||
};
|
||||
}
|
||||
}
|
||||
|
51
ProjectLibrary/Forms/FBook.Designer.cs
generated
51
ProjectLibrary/Forms/FBook.Designer.cs
generated
@ -33,11 +33,11 @@
|
||||
lblName = new Label();
|
||||
txtName = new TextBox();
|
||||
lblType = new Label();
|
||||
cmbType = new ComboBox();
|
||||
lblLibraryId = new Label();
|
||||
btnSave = new Button();
|
||||
buttonCancel_Click = new Button();
|
||||
comboBoxLibrary = new ComboBox();
|
||||
checkedListBox1 = new CheckedListBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// lblAuthor
|
||||
@ -45,15 +45,15 @@
|
||||
lblAuthor.AutoSize = true;
|
||||
lblAuthor.Location = new Point(19, 25);
|
||||
lblAuthor.Name = "lblAuthor";
|
||||
lblAuthor.Size = new Size(43, 15);
|
||||
lblAuthor.Size = new Size(54, 20);
|
||||
lblAuthor.TabIndex = 2;
|
||||
lblAuthor.Text = "Автор:";
|
||||
//
|
||||
// txtAuthor
|
||||
//
|
||||
txtAuthor.Location = new Point(115, 25);
|
||||
txtAuthor.Location = new Point(105, 25);
|
||||
txtAuthor.Name = "txtAuthor";
|
||||
txtAuthor.Size = new Size(200, 23);
|
||||
txtAuthor.Size = new Size(246, 27);
|
||||
txtAuthor.TabIndex = 3;
|
||||
//
|
||||
// lblName
|
||||
@ -61,15 +61,15 @@
|
||||
lblName.AutoSize = true;
|
||||
lblName.Location = new Point(19, 65);
|
||||
lblName.Name = "lblName";
|
||||
lblName.Size = new Size(62, 15);
|
||||
lblName.Size = new Size(80, 20);
|
||||
lblName.TabIndex = 4;
|
||||
lblName.Text = "Название:";
|
||||
//
|
||||
// txtName
|
||||
//
|
||||
txtName.Location = new Point(115, 65);
|
||||
txtName.Location = new Point(105, 65);
|
||||
txtName.Name = "txtName";
|
||||
txtName.Size = new Size(200, 23);
|
||||
txtName.Size = new Size(246, 27);
|
||||
txtName.TabIndex = 5;
|
||||
//
|
||||
// lblType
|
||||
@ -77,32 +77,22 @@
|
||||
lblType.AutoSize = true;
|
||||
lblType.Location = new Point(19, 105);
|
||||
lblType.Name = "lblType";
|
||||
lblType.Size = new Size(30, 15);
|
||||
lblType.Size = new Size(38, 20);
|
||||
lblType.TabIndex = 6;
|
||||
lblType.Text = "Тип:";
|
||||
//
|
||||
// cmbType
|
||||
//
|
||||
cmbType.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
cmbType.FormattingEnabled = true;
|
||||
cmbType.Items.AddRange(new object[] { "Fiction", "Non-Fiction", "Science", "Biography" });
|
||||
cmbType.Location = new Point(115, 102);
|
||||
cmbType.Name = "cmbType";
|
||||
cmbType.Size = new Size(200, 23);
|
||||
cmbType.TabIndex = 7;
|
||||
//
|
||||
// lblLibraryId
|
||||
//
|
||||
lblLibraryId.AutoSize = true;
|
||||
lblLibraryId.Location = new Point(19, 145);
|
||||
lblLibraryId.Location = new Point(19, 226);
|
||||
lblLibraryId.Name = "lblLibraryId";
|
||||
lblLibraryId.Size = new Size(90, 15);
|
||||
lblLibraryId.Size = new Size(114, 20);
|
||||
lblLibraryId.TabIndex = 8;
|
||||
lblLibraryId.Text = "ID библиотеки:";
|
||||
//
|
||||
// btnSave
|
||||
//
|
||||
btnSave.Location = new Point(19, 185);
|
||||
btnSave.Location = new Point(19, 266);
|
||||
btnSave.Name = "btnSave";
|
||||
btnSave.Size = new Size(100, 30);
|
||||
btnSave.TabIndex = 10;
|
||||
@ -112,7 +102,7 @@
|
||||
//
|
||||
// buttonCancel_Click
|
||||
//
|
||||
buttonCancel_Click.Location = new Point(239, 185);
|
||||
buttonCancel_Click.Location = new Point(251, 266);
|
||||
buttonCancel_Click.Name = "buttonCancel_Click";
|
||||
buttonCancel_Click.Size = new Size(100, 30);
|
||||
buttonCancel_Click.TabIndex = 11;
|
||||
@ -124,14 +114,24 @@
|
||||
comboBoxLibrary.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxLibrary.FormattingEnabled = true;
|
||||
comboBoxLibrary.Items.AddRange(new object[] { "Fiction", "Non-Fiction", "Science", "Biography" });
|
||||
comboBoxLibrary.Location = new Point(115, 145);
|
||||
comboBoxLibrary.Location = new Point(151, 223);
|
||||
comboBoxLibrary.Name = "comboBoxLibrary";
|
||||
comboBoxLibrary.Size = new Size(200, 23);
|
||||
comboBoxLibrary.Size = new Size(200, 28);
|
||||
comboBoxLibrary.TabIndex = 12;
|
||||
//
|
||||
// checkedListBox1
|
||||
//
|
||||
checkedListBox1.FormattingEnabled = true;
|
||||
checkedListBox1.Location = new Point(105, 105);
|
||||
checkedListBox1.Name = "checkedListBox1";
|
||||
checkedListBox1.Size = new Size(246, 114);
|
||||
checkedListBox1.TabIndex = 13;
|
||||
checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged;
|
||||
//
|
||||
// FBook
|
||||
//
|
||||
ClientSize = new Size(400, 300);
|
||||
Controls.Add(checkedListBox1);
|
||||
Controls.Add(comboBoxLibrary);
|
||||
Controls.Add(buttonCancel_Click);
|
||||
Controls.Add(lblAuthor);
|
||||
@ -139,7 +139,6 @@
|
||||
Controls.Add(lblName);
|
||||
Controls.Add(txtName);
|
||||
Controls.Add(lblType);
|
||||
Controls.Add(cmbType);
|
||||
Controls.Add(lblLibraryId);
|
||||
Controls.Add(btnSave);
|
||||
Name = "FBook";
|
||||
@ -154,10 +153,10 @@
|
||||
private System.Windows.Forms.Label lblName;
|
||||
private System.Windows.Forms.TextBox txtName;
|
||||
private System.Windows.Forms.Label lblType;
|
||||
private System.Windows.Forms.ComboBox cmbType;
|
||||
private System.Windows.Forms.Label lblLibraryId;
|
||||
private System.Windows.Forms.Button btnSave;
|
||||
private Button buttonCancel_Click;
|
||||
private ComboBox comboBoxLibrary;
|
||||
private CheckedListBox checkedListBox1;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,10 @@ namespace ProjectLibrary.Forms
|
||||
|
||||
txtAuthor.Text = book.Author;
|
||||
txtName.Text = book.Name;
|
||||
cmbType.SelectedItem = book.Type;
|
||||
//cmbType.SelectedItem = book.Type;
|
||||
comboBoxLibrary.SelectedItem = book.LibraryID;
|
||||
_bookId = value;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -40,6 +41,10 @@ namespace ProjectLibrary.Forms
|
||||
InitializeComponent();
|
||||
_bookRepository = bookRepository ?? throw new ArgumentNullException(nameof(bookRepository));
|
||||
comboBoxLibrary.DataSource = libraryRepository.ReadLibraries();
|
||||
foreach(var elem in Enum.GetValues(typeof(BookType)))
|
||||
{
|
||||
if (!elem.Equals(BookType.None)) checkedListBox1.Items.Add(elem);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnSave_Click(object sender, EventArgs e)
|
||||
@ -51,12 +56,22 @@ namespace ProjectLibrary.Forms
|
||||
throw new Exception("Имеются незаполненные поля.");
|
||||
}
|
||||
|
||||
BookType selectedType = BookType.None;
|
||||
|
||||
foreach (var item in checkedListBox1.CheckedItems)
|
||||
{
|
||||
if (item is BookType type)
|
||||
{
|
||||
selectedType |= type;
|
||||
}
|
||||
}
|
||||
|
||||
var book = Book.CreateEntity(
|
||||
_bookId ?? 0,
|
||||
txtAuthor.Text,
|
||||
txtName.Text,
|
||||
(BookType)cmbType.SelectedValue,
|
||||
Convert.ToInt32(comboBoxLibrary.SelectedItem)
|
||||
Convert.ToInt32(comboBoxLibrary.SelectedItem),
|
||||
selectedType
|
||||
);
|
||||
|
||||
if (_bookId.HasValue)
|
||||
@ -80,5 +95,31 @@ namespace ProjectLibrary.Forms
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
BookType selectedType = BookType.None;
|
||||
|
||||
|
||||
foreach (var item in checkedListBox1.CheckedItems)
|
||||
{
|
||||
if (item is BookType type)
|
||||
{
|
||||
selectedType |= type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var book = _bookRepository.ReadBookById(_bookId ?? 0);
|
||||
book.Type = selectedType;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при обработке выбора", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
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
|
||||
|
@ -10,25 +10,30 @@ namespace ProjectLibrary.Forms
|
||||
|
||||
public FBooks(IUnityContainer container, IBookRepository bookRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeComponent(); // Инициализация компонентов формы, включая DataGridView.
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
_bookRepository = bookRepository ?? throw new ArgumentNullException(nameof(bookRepository));
|
||||
}
|
||||
|
||||
private void LoadList()
|
||||
{
|
||||
// Привязывает к DataGridView коллекцию книг, полученную из репозитория.
|
||||
// Устанавливает источник данных DataGridView (dataGridViewBooks) как список объектов из ReadBooks().
|
||||
dataGridViewBooks.DataSource = _bookRepository.ReadBooks();
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
// Проверяет, выбрана ли хотя бы одна строка в DataGridView.
|
||||
if (dataGridViewBooks.SelectedRows.Count < 1)
|
||||
{
|
||||
// Если строка не выбрана, отображает сообщение об ошибке.
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Извлекает идентификатор (ID) из выбранной строки, используя значение ячейки столбца "Id".
|
||||
id = Convert.ToInt32(dataGridViewBooks.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
@ -37,7 +42,10 @@ namespace ProjectLibrary.Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
// Открывает форму добавления книги.
|
||||
_container.Resolve<FBook>().ShowDialog();
|
||||
|
||||
// После добавления обновляет список записей в DataGridView.
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -48,6 +56,7 @@ namespace ProjectLibrary.Forms
|
||||
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Получает ID выбранной строки из DataGridView.
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
@ -55,9 +64,12 @@ namespace ProjectLibrary.Forms
|
||||
|
||||
try
|
||||
{
|
||||
// Открывает форму редактирования книги с указанным ID.
|
||||
var form = _container.Resolve<FBook>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
|
||||
// После редактирования обновляет список записей в DataGridView.
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -68,11 +80,13 @@ namespace ProjectLibrary.Forms
|
||||
|
||||
private void buttonRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Получает ID выбранной строки из DataGridView.
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Подтверждение удаления записи.
|
||||
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
@ -80,7 +94,10 @@ namespace ProjectLibrary.Forms
|
||||
|
||||
try
|
||||
{
|
||||
// Удаляет запись через репозиторий.
|
||||
_bookRepository.DeleteBook(findId);
|
||||
|
||||
// После удаления обновляет список записей в DataGridView.
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -93,6 +110,7 @@ namespace ProjectLibrary.Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
// При загрузке формы заполняет DataGridView данными из репозитория.
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectLibrary.Entites;
|
||||
using ProjectLibrary.Repositores;
|
||||
using ProjectLibrary.Repositories;
|
||||
using ProjectLibrary.Repositories.Implementations;
|
||||
using System.Windows.Forms;
|
||||
@ -34,10 +35,14 @@ namespace ProjectLibrary.Forms
|
||||
}
|
||||
}
|
||||
|
||||
public FLibrary(ILibraryRepository libraryRepository)
|
||||
public FLibrary(ILibraryRepository libraryRepository, IBookRepository bookRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_libraryRepository = libraryRepository ?? throw new ArgumentNullException(nameof(libraryRepository));
|
||||
|
||||
Book.DataSource = bookRepository.ReadBooks();
|
||||
Book.DisplayMember = "Name";
|
||||
Book.ValueMember = "Id";
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
|
14
ProjectLibrary/Forms/FTicket_Extension.Designer.cs
generated
14
ProjectLibrary/Forms/FTicket_Extension.Designer.cs
generated
@ -36,7 +36,7 @@
|
||||
lblLastUpdateDate.AutoSize = true;
|
||||
lblLastUpdateDate.Location = new Point(20, 64);
|
||||
lblLastUpdateDate.Name = "lblLastUpdateDate";
|
||||
lblLastUpdateDate.Size = new Size(172, 15);
|
||||
lblLastUpdateDate.Size = new Size(219, 20);
|
||||
lblLastUpdateDate.TabIndex = 4;
|
||||
lblLastUpdateDate.Text = "Дата последнего обновления:";
|
||||
//
|
||||
@ -44,7 +44,7 @@
|
||||
//
|
||||
dtpLastUpdateDate.Location = new Point(276, 59);
|
||||
dtpLastUpdateDate.Name = "dtpLastUpdateDate";
|
||||
dtpLastUpdateDate.Size = new Size(200, 23);
|
||||
dtpLastUpdateDate.Size = new Size(200, 27);
|
||||
dtpLastUpdateDate.TabIndex = 5;
|
||||
//
|
||||
// lblNextUpdateDate
|
||||
@ -52,7 +52,7 @@
|
||||
lblNextUpdateDate.AutoSize = true;
|
||||
lblNextUpdateDate.Location = new Point(20, 104);
|
||||
lblNextUpdateDate.Name = "lblNextUpdateDate";
|
||||
lblNextUpdateDate.Size = new Size(178, 15);
|
||||
lblNextUpdateDate.Size = new Size(223, 20);
|
||||
lblNextUpdateDate.TabIndex = 6;
|
||||
lblNextUpdateDate.Text = "Дата следующего обновления:";
|
||||
//
|
||||
@ -60,7 +60,7 @@
|
||||
//
|
||||
dtpNextUpdateDate.Location = new Point(276, 99);
|
||||
dtpNextUpdateDate.Name = "dtpNextUpdateDate";
|
||||
dtpNextUpdateDate.Size = new Size(200, 23);
|
||||
dtpNextUpdateDate.Size = new Size(200, 27);
|
||||
dtpNextUpdateDate.TabIndex = 7;
|
||||
//
|
||||
// btnSave
|
||||
@ -86,15 +86,15 @@
|
||||
labelId.AutoSize = true;
|
||||
labelId.Location = new Point(20, 19);
|
||||
labelId.Name = "labelId";
|
||||
labelId.Size = new Size(17, 15);
|
||||
labelId.Size = new Size(173, 20);
|
||||
labelId.TabIndex = 10;
|
||||
labelId.Text = "id";
|
||||
labelId.Text = "ID Читателского билета";
|
||||
//
|
||||
// comboBoxId
|
||||
//
|
||||
comboBoxId.Location = new Point(273, 16);
|
||||
comboBoxId.Name = "comboBoxId";
|
||||
comboBoxId.Size = new Size(203, 23);
|
||||
comboBoxId.Size = new Size(203, 28);
|
||||
comboBoxId.TabIndex = 11;
|
||||
//
|
||||
// FTicket_Extension
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
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
|
||||
|
@ -24,7 +24,7 @@ namespace ProjectLibrary.Repositories.Implementations
|
||||
public Book ReadBookById(int id)
|
||||
{
|
||||
|
||||
return Book.CreateEntity(id, "", "", BookType.None, 0);
|
||||
return Book.CreateEntity(id, "", "", 0);
|
||||
}
|
||||
|
||||
public IEnumerable<Book> ReadBooks()
|
||||
|
Loading…
Reference in New Issue
Block a user
У элементов форм, с которыми работаем в логике должны быть логичные имена