diff --git a/ProjectLibrary/Entites/Book.cs b/ProjectLibrary/Entites/Book.cs index bb5894b..7204483 100644 --- a/ProjectLibrary/Entites/Book.cs +++ b/ProjectLibrary/Entites/Book.cs @@ -7,18 +7,16 @@ 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; set; } = BookType.None; - public int LibraryID { get; private set; } + public BookType TypeBookID { get; set; } = BookType.None; - public static Book CreateEntity(int id, string author, string name, int libraryID, BookType type = BookType.None) + public static Book CreateEntity(int id, string author, string name, BookType typeBookID = BookType.None) { return new Book { Id = id, Author = author ?? string.Empty, Name = name ?? string.Empty, - LibraryID = libraryID, - Type = type + TypeBookID = typeBookID }; } } diff --git a/ProjectLibrary/Entites/Enums/BookType.cs b/ProjectLibrary/Entites/Enums/BookType.cs index 865fa09..cb2350f 100644 --- a/ProjectLibrary/Entites/Enums/BookType.cs +++ b/ProjectLibrary/Entites/Enums/BookType.cs @@ -17,4 +17,4 @@ namespace ProjectLibrary.Entities.Enums Mystery = 16, Fantasy = 32 } -} \ No newline at end of file +} diff --git a/ProjectLibrary/Entites/Library.cs b/ProjectLibrary/Entites/Library.cs index 0cc6ead..07c629c 100644 --- a/ProjectLibrary/Entites/Library.cs +++ b/ProjectLibrary/Entites/Library.cs @@ -16,7 +16,7 @@ namespace ProjectLibrary.Entites { get; private set; - } = []; + } public static Library CreateEntity(int id, string name, string address, IEnumerable bookLibrary) { diff --git a/ProjectLibrary/Entites/Orders.cs b/ProjectLibrary/Entites/Orders.cs index 2065d1f..f395901 100644 --- a/ProjectLibrary/Entites/Orders.cs +++ b/ProjectLibrary/Entites/Orders.cs @@ -13,7 +13,6 @@ namespace ProjectLibrary.Entites public DateTime OrderDate { get; private set; } public DateTime ReturnDate { get; private set; } public int ReaderID { get; private set; } - public IEnumerable BookOrders { get; @@ -21,12 +20,12 @@ namespace ProjectLibrary.Entites } = []; - public static Orders CreateEntity(int id, DateTime orderDate, DateTime returnDate, int readerID, IEnumerable bookOrders) + public static Orders CreateEntity(int id, DateTime returnDate, int readerID, IEnumerable bookOrders) { return new Orders { Id = id, - OrderDate = orderDate, + OrderDate = DateTime.Now, ReturnDate = returnDate, ReaderID = readerID, BookOrders = bookOrders diff --git a/ProjectLibrary/Entites/Ticket_Extension.cs b/ProjectLibrary/Entites/Ticket_Extension.cs index 2f6f2dc..331ace5 100644 --- a/ProjectLibrary/Entites/Ticket_Extension.cs +++ b/ProjectLibrary/Entites/Ticket_Extension.cs @@ -2,14 +2,16 @@ { public class TicketExtensions { + public int Id { get; private set; } public int ReaderID { get; private set; } public DateTime LastUpdateDate { get; private set; } public DateTime NextUpdateDate { get; private set; } - public static TicketExtensions CreateEntity(int readerID, DateTime lastUpdateDate, DateTime nextUpdateDate) + public static TicketExtensions CreateEntity(int id, int readerID, DateTime lastUpdateDate, DateTime nextUpdateDate) { return new TicketExtensions { + Id = id, ReaderID = readerID, LastUpdateDate = lastUpdateDate, NextUpdateDate = nextUpdateDate diff --git a/ProjectLibrary/Forms/FBook.Designer.cs b/ProjectLibrary/Forms/FBook.Designer.cs index 853de9c..2423c93 100644 --- a/ProjectLibrary/Forms/FBook.Designer.cs +++ b/ProjectLibrary/Forms/FBook.Designer.cs @@ -33,10 +33,8 @@ lblName = new Label(); txtName = new TextBox(); lblType = new Label(); - lblLibraryId = new Label(); btnSave = new Button(); buttonCancel_Click = new Button(); - comboBoxLibrary = new ComboBox(); checkedListBox1 = new CheckedListBox(); SuspendLayout(); // @@ -81,15 +79,6 @@ lblType.TabIndex = 6; lblType.Text = "Тип:"; // - // lblLibraryId - // - lblLibraryId.AutoSize = true; - lblLibraryId.Location = new Point(19, 226); - lblLibraryId.Name = "lblLibraryId"; - lblLibraryId.Size = new Size(114, 20); - lblLibraryId.TabIndex = 8; - lblLibraryId.Text = "ID библиотеки:"; - // // btnSave // btnSave.Location = new Point(19, 266); @@ -109,16 +98,6 @@ buttonCancel_Click.Text = "Отмена"; buttonCancel_Click.Click += ButtonCancel_Click; // - // comboBoxLibrary - // - comboBoxLibrary.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxLibrary.FormattingEnabled = true; - comboBoxLibrary.Items.AddRange(new object[] { "Fiction", "Non-Fiction", "Science", "Biography" }); - comboBoxLibrary.Location = new Point(151, 223); - comboBoxLibrary.Name = "comboBoxLibrary"; - comboBoxLibrary.Size = new Size(200, 28); - comboBoxLibrary.TabIndex = 12; - // // checkedListBox1 // checkedListBox1.FormattingEnabled = true; @@ -126,20 +105,17 @@ 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); Controls.Add(txtAuthor); Controls.Add(lblName); Controls.Add(txtName); Controls.Add(lblType); - Controls.Add(lblLibraryId); Controls.Add(btnSave); Name = "FBook"; Text = "Книга"; @@ -153,10 +129,8 @@ private System.Windows.Forms.Label lblName; private System.Windows.Forms.TextBox txtName; private System.Windows.Forms.Label lblType; - private System.Windows.Forms.Label lblLibraryId; private System.Windows.Forms.Button btnSave; private Button buttonCancel_Click; - private ComboBox comboBoxLibrary; private CheckedListBox checkedListBox1; } } diff --git a/ProjectLibrary/Forms/FBook.cs b/ProjectLibrary/Forms/FBook.cs index 9732e74..4920718 100644 --- a/ProjectLibrary/Forms/FBook.cs +++ b/ProjectLibrary/Forms/FBook.cs @@ -24,8 +24,12 @@ namespace ProjectLibrary.Forms txtAuthor.Text = book.Author; txtName.Text = book.Name; - //cmbType.SelectedItem = book.Type; - comboBoxLibrary.SelectedItem = book.LibraryID; + //checkedListBox1.SelectedItem = book.TypeBookID; + char[] listInd = Convert.ToString((int)book.TypeBookID, 2).ToCharArray(); + for (int i = 0; i < listInd.Length; i++) + { + checkedListBox1.SetItemChecked(i, listInd[i]=='1'); + } _bookId = value; } @@ -36,11 +40,10 @@ namespace ProjectLibrary.Forms } } - public FBook(IBookRepository bookRepository, ILibraryRepository libraryRepository) + public FBook(IBookRepository bookRepository) { 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); @@ -51,39 +54,22 @@ namespace ProjectLibrary.Forms { try { - if (string.IsNullOrWhiteSpace(txtAuthor.Text) || string.IsNullOrWhiteSpace(txtName.Text) || comboBoxLibrary.SelectedItem == null) + if (string.IsNullOrWhiteSpace(txtAuthor.Text) || string.IsNullOrWhiteSpace(txtName.Text)) { 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, - Convert.ToInt32(comboBoxLibrary.SelectedItem), - selectedType - ); - if (_bookId.HasValue) { - _bookRepository.UpdateBook(book); + _bookRepository.UpdateBook(CreateBook(_bookId.Value)); } else { - _bookRepository.CreateBook(book); + _bookRepository.CreateBook(CreateBook(0)); } Close(); + } catch (Exception ex) { @@ -91,35 +77,26 @@ namespace ProjectLibrary.Forms } } + private Book CreateBook(int bookId) + { + BookType selectedType = BookType.None; + + foreach (var item in checkedListBox1.CheckedItems) + { + if (item is BookType type) + { + selectedType |= type; // Это должно работать, если тип является BookType + } + } + + return Book.CreateEntity(bookId, txtAuthor.Text, txtName.Text, selectedType); + } + + + private void ButtonCancel_Click(object sender, EventArgs e) { 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); - } - } - } } diff --git a/ProjectLibrary/Forms/FLibrary.cs b/ProjectLibrary/Forms/FLibrary.cs index 5e94e6c..8a3676a 100644 --- a/ProjectLibrary/Forms/FLibrary.cs +++ b/ProjectLibrary/Forms/FLibrary.cs @@ -25,7 +25,7 @@ namespace ProjectLibrary.Forms txtName.Text = library.Name; txtAddress.Text = library.Address; - dataGridView.DataSource = library.BookLibrary; + SetListBooksToDataGrid(library.BookLibrary); _orderId = value; } catch (Exception ex) @@ -69,6 +69,8 @@ namespace ProjectLibrary.Forms { _libraryRepository.CreateLibrary(library); } + + Close(); } catch (Exception ex) @@ -79,7 +81,7 @@ namespace ProjectLibrary.Forms private void buttonCancel_Click_Click(object sender, EventArgs e) { - this.Close(); + Close(); } private List CreateListBooksFromDataGrid() @@ -91,9 +93,21 @@ namespace ProjectLibrary.Forms { continue; } - list.Add(Book_Library.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnBook"].Value), Convert.ToInt32(row.Cells["ColumnCount"].Value))); + list.Add(Book_Library.CreateEntity(0, Convert.ToInt32(row.Cells["Book"].Value), Convert.ToInt32(row.Cells["Count"].Value))); } return list; } + + private void SetListBooksToDataGrid(IEnumerable list) + { + int index = 0; + foreach (Book_Library elem in list) + { + dataGridView.Rows.Add(); + dataGridView.Rows[index].Cells["Book"].Value = elem.BookID; + dataGridView.Rows[index].Cells["Count"].Value = elem.Count; + index++; + } + } } } diff --git a/ProjectLibrary/Forms/FLibrary.resx b/ProjectLibrary/Forms/FLibrary.resx index 5faf464..3105a36 100644 --- a/ProjectLibrary/Forms/FLibrary.resx +++ b/ProjectLibrary/Forms/FLibrary.resx @@ -1,7 +1,7 @@