что-то с чем-то
This commit is contained in:
parent
019751daa5
commit
30b3ef6a2d
@ -1,11 +0,0 @@
|
||||
namespace LibraryAccountingApp_lab3
|
||||
{
|
||||
public class Book
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
//public byte[] Image { get; set; }
|
||||
public string Author { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
}
|
||||
}
|
61
COP_5/LibraryAccountingApp_lab3/BusinessLogic/AuthorLogic.cs
Normal file
61
COP_5/LibraryAccountingApp_lab3/BusinessLogic/AuthorLogic.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.BusinessLogicsContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.StorageContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.ViewModels;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.BusinessLogic
|
||||
{
|
||||
public class AuthorLogic : IAuthorLogic
|
||||
{
|
||||
private readonly IAuthorStorage _authorStorage;
|
||||
|
||||
public AuthorLogic(IAuthorStorage authorStorage)
|
||||
{
|
||||
_authorStorage = authorStorage;
|
||||
}
|
||||
|
||||
public List<AuthorViewModel> Read(AuthorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return _authorStorage.GetFullList();
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return new List<AuthorViewModel> { _authorStorage.GetElement(model) };
|
||||
}
|
||||
return _authorStorage.GetFilteredList(model);
|
||||
}
|
||||
|
||||
public void CreateOrUpdate(AuthorBindingModel model)
|
||||
{
|
||||
var element = _authorStorage.GetElement(
|
||||
new AuthorBindingModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new Exception("Такой автор уже существует");
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
_authorStorage.Update(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
_authorStorage.Insert(model);
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(AuthorBindingModel model)
|
||||
{
|
||||
var element = _authorStorage.GetElement(new AuthorBindingModel { Id = model.Id });
|
||||
if (element == null)
|
||||
{
|
||||
throw new Exception("Автор не найден");
|
||||
}
|
||||
_authorStorage.Delete(model);
|
||||
}
|
||||
}
|
||||
}
|
60
COP_5/LibraryAccountingApp_lab3/BusinessLogic/BookLogic.cs
Normal file
60
COP_5/LibraryAccountingApp_lab3/BusinessLogic/BookLogic.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.BusinessLogicsContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.StorageContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.ViewModels;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.BusinessLogic
|
||||
{
|
||||
public class BookLogic : IBookLogic
|
||||
{
|
||||
private readonly IBookStorage _bookStorage;
|
||||
public BookLogic(IBookStorage bookStorage)
|
||||
{
|
||||
_bookStorage = bookStorage;
|
||||
}
|
||||
|
||||
public List<BookViewModel> Read(BookBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return _bookStorage.GetFullList();
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return new List<BookViewModel> { _bookStorage.GetElement(model) };
|
||||
}
|
||||
return _bookStorage.GetFilteredList(model);
|
||||
}
|
||||
|
||||
public void CreateOrUpdate(BookBindingModel model)
|
||||
{
|
||||
var element = _bookStorage.GetElement(
|
||||
new BookBindingModel
|
||||
{
|
||||
Title = model.Title
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new Exception("Книга с таким названием уже существует");
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
_bookStorage.Update(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
_bookStorage.Insert(model);
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(BookBindingModel model)
|
||||
{
|
||||
var element = _bookStorage.GetElement(new BookBindingModel { Id = model.Id });
|
||||
if (element == null)
|
||||
{
|
||||
throw new Exception("Книга не найдена");
|
||||
}
|
||||
_bookStorage.Delete(model);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Contracts.BindingModels
|
||||
{
|
||||
public class AuthorBindingModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Contracts.BindingModels
|
||||
{
|
||||
public class BookBindingModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string Author { get; set; }
|
||||
|
||||
public string Date { get; set; }
|
||||
public string Image { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.ViewModels;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Contracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IAuthorLogic
|
||||
{
|
||||
List<AuthorViewModel> Read(AuthorBindingModel model);
|
||||
void CreateOrUpdate(AuthorBindingModel model);
|
||||
void Delete(AuthorBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.ViewModels;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Contracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IBookLogic
|
||||
{
|
||||
List<BookViewModel>? Read(BookBindingModel? model);
|
||||
void CreateOrUpdate(BookBindingModel model);
|
||||
void Delete(BookBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.ViewModels;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Contracts.StorageContracts
|
||||
{
|
||||
public interface IAuthorStorage
|
||||
{
|
||||
List<AuthorViewModel> GetFullList();
|
||||
List<AuthorViewModel> GetFilteredList(AuthorBindingModel model);
|
||||
AuthorViewModel GetElement(AuthorBindingModel model);
|
||||
|
||||
void Insert(AuthorBindingModel model);
|
||||
void Update(AuthorBindingModel model);
|
||||
void Delete(AuthorBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.ViewModels;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Contracts.StorageContracts
|
||||
{
|
||||
public interface IBookStorage
|
||||
{
|
||||
List<BookViewModel> GetFullList();
|
||||
List<BookViewModel> GetFilteredList(BookBindingModel model);
|
||||
BookViewModel GetElement(BookBindingModel model);
|
||||
|
||||
void Insert(BookBindingModel model);
|
||||
void Update(BookBindingModel model);
|
||||
void Delete(BookBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Contracts.ViewModels
|
||||
{
|
||||
public class AuthorViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<BookViewModel> Books { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Contracts.ViewModels
|
||||
{
|
||||
public class BookViewModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[DisplayName("Автор")]
|
||||
public string Author { get; set; }
|
||||
|
||||
[DisplayName("Дата издания")]
|
||||
public string Date { get; set; }
|
||||
public string Image { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace LibraryAccountingApp_lab3.DataModels
|
||||
{
|
||||
public interface IAuthorModel : IId
|
||||
{
|
||||
string Name { get; set; }
|
||||
}
|
||||
}
|
10
COP_5/LibraryAccountingApp_lab3/DataModels/IBookModel.cs
Normal file
10
COP_5/LibraryAccountingApp_lab3/DataModels/IBookModel.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace LibraryAccountingApp_lab3.DataModels
|
||||
{
|
||||
public interface IBookModel : IId
|
||||
{
|
||||
string Title { get; }
|
||||
string Author { get; }
|
||||
string Date { get; }
|
||||
string Image { get; }
|
||||
}
|
||||
}
|
7
COP_5/LibraryAccountingApp_lab3/DataModels/IId.cs
Normal file
7
COP_5/LibraryAccountingApp_lab3/DataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace LibraryAccountingApp_lab3.DataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.StorageContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.ViewModels;
|
||||
using LibraryAccountingApp_lab3.DatabaseImplement.Models;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.DatabaseImplement.Implements
|
||||
{
|
||||
public class AuthorStorage : IAuthorStorage
|
||||
{
|
||||
public List<AuthorViewModel> GetFullList()
|
||||
{
|
||||
using var context = new LibraryDatabase();
|
||||
return context.Authors
|
||||
.Select(CreateModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<AuthorViewModel> GetFilteredList(AuthorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new LibraryDatabase();
|
||||
return context.Authors
|
||||
.Where(rec => rec.Name.Contains(model.Name))
|
||||
.Select(CreateModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public AuthorViewModel GetElement(AuthorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new LibraryDatabase();
|
||||
|
||||
var author = context.Authors
|
||||
.ToList()
|
||||
.FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name);
|
||||
return author != null ? CreateModel(author) : null;
|
||||
|
||||
}
|
||||
|
||||
public void Insert(AuthorBindingModel model)
|
||||
{
|
||||
var context = new LibraryDatabase();
|
||||
var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
context.Authors.Add(CreateModel(model, new Author()));
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(AuthorBindingModel model)
|
||||
{
|
||||
var context = new LibraryDatabase();
|
||||
var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var author = context.Authors.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (author == null)
|
||||
{
|
||||
throw new Exception("Автор не найден");
|
||||
}
|
||||
CreateModel(model, author);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Delete(AuthorBindingModel model)
|
||||
{
|
||||
var context = new LibraryDatabase();
|
||||
var shape = context.Authors.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (shape != null)
|
||||
{
|
||||
context.Authors.Remove(shape);
|
||||
context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Автор не найден");
|
||||
}
|
||||
}
|
||||
|
||||
private static Author CreateModel(AuthorBindingModel model, Author author)
|
||||
{
|
||||
author.Name = model.Name;
|
||||
return author;
|
||||
}
|
||||
|
||||
private static AuthorViewModel CreateModel(Author author)
|
||||
{
|
||||
return new AuthorViewModel
|
||||
{
|
||||
Id = author.Id,
|
||||
Name = author.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.StorageContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.ViewModels;
|
||||
using LibraryAccountingApp_lab3.DatabaseImplement.Models;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.DatabaseImplement.Implements
|
||||
{
|
||||
public class BookStorage : IBookStorage
|
||||
{
|
||||
public List<BookViewModel> GetFullList()
|
||||
{
|
||||
using (var context = new LibraryDatabase())
|
||||
{
|
||||
return context.Books
|
||||
.ToList()
|
||||
.Select(CreateModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<BookViewModel> GetFilteredList(BookBindingModel model)
|
||||
{
|
||||
var context = new LibraryDatabase();
|
||||
return context.Books
|
||||
.Where(book => book.Title.Contains(model.Title) && book.Author.Contains(model.Author))
|
||||
.ToList()
|
||||
.Select(CreateModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public BookViewModel GetElement(BookBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new LibraryDatabase();
|
||||
var book = context.Books
|
||||
.ToList()
|
||||
.FirstOrDefault(rec => rec.Title == model.Title || rec.Id == model.Id);
|
||||
return book != null ? CreateModel(book) : null;
|
||||
}
|
||||
|
||||
public void Insert(BookBindingModel model)
|
||||
{
|
||||
var context = new LibraryDatabase();
|
||||
var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
context.Books.Add(CreateModel(model, new Book()));
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(BookBindingModel model)
|
||||
{
|
||||
var context = new LibraryDatabase();
|
||||
var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var book = context.Books.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (book == null)
|
||||
{
|
||||
throw new Exception("Книга не найдена");
|
||||
}
|
||||
CreateModel(model, book);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Delete(BookBindingModel model)
|
||||
{
|
||||
var context = new LibraryDatabase();
|
||||
var book = context.Books.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (book != null)
|
||||
{
|
||||
context.Books.Remove(book);
|
||||
context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Книга не найдена");
|
||||
}
|
||||
}
|
||||
|
||||
private static Book CreateModel(BookBindingModel model, Book book)
|
||||
{
|
||||
book.Title = model.Title;
|
||||
book.Author = model.Author;
|
||||
book.Date = model.Date;
|
||||
book.Image = model.Image;
|
||||
return book;
|
||||
}
|
||||
|
||||
private BookViewModel CreateModel(Book book)
|
||||
{
|
||||
return new BookViewModel
|
||||
{
|
||||
Id = book.Id,
|
||||
Title = book.Title,
|
||||
Author = book.Author,
|
||||
Date = book.Date,
|
||||
Image = book.Image
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LibraryAccountingApp_lab3.DatabaseImplement.Models;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.DatabaseImplement
|
||||
{
|
||||
public class LibraryDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=PC-Anna\SQLEXPRESS;Initial Catalog=LibraryAppCOP;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
//optionsBuilder.UseNpgsql("Host=localhost;Database=LibraryAppCOP;Username=postgres;Password=postgres");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Book> Books { set; get; }
|
||||
public virtual DbSet<Author> Authors{ set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.DatabaseImplement.Models
|
||||
{
|
||||
public class Author
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LibraryAccountingApp_lab3.DatabaseImplement.Models
|
||||
{
|
||||
public class Book
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Author { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Date { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Image { get; set; }
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
using COP_5;
|
||||
using FedComponentLib;
|
||||
|
||||
namespace LibraryAccountingApp_lab3
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private byte[]? selectedImage = new byte[16];
|
||||
private int counterBooksIds = 0;
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeTableBooks();
|
||||
FillControlSelectedComboBoxSingle();
|
||||
dateTextBoxDate.DatePattern = @"^(0[1-9]|[12][0-9]|3[01])\s+(ÿíâàðü|ôåâðàëü|ìàðò|àïðåëü|ìàé|èþíü|èþëü|àâãóñò|ñåíòÿáðü|îêòÿáðü|íîÿáðü|äåêàáðü)\s+\d{4}$";
|
||||
}
|
||||
|
||||
private void FillControlSelectedComboBoxSingle()
|
||||
{
|
||||
List<string> list = new List<string>() {
|
||||
"Äåíèåë Êèç",
|
||||
"Àëåêñàíäð Ïóøêèí",
|
||||
"Ô¸äîð Äîñòîåâñêèé",
|
||||
"Áîðèñ Àêóíèí",
|
||||
"Íèêîëàñ Ñïàðêñ"
|
||||
};
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
controlSelectedComboBoxSingleAuthor.AddElement(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeTableBooks()
|
||||
{
|
||||
Book book1 = new Book
|
||||
{
|
||||
Id = 1,
|
||||
Title = "Title 1",
|
||||
Author = "Author 1",
|
||||
Date = DateTime.Now,
|
||||
};
|
||||
Book book2 = new Book
|
||||
{
|
||||
Id = 2,
|
||||
Title = "Title 2",
|
||||
Author = "Author 2",
|
||||
Date = DateTime.Now.AddDays(-1),
|
||||
};
|
||||
//controlDataTableCellBooks.dataGridView.Columns.Add("Title", "Title");
|
||||
//List<string> list = new List<string> { "Title", "Author" };
|
||||
//controlDataTableCellBooks.LoadColumns(List list);
|
||||
//controlDataTableCellBooks.AddCell(0, 0, book1);
|
||||
dataGridViewBooks.Rows.Add(book1);
|
||||
dataGridViewBooks.Rows.Add(book2);
|
||||
}
|
||||
|
||||
private void buttonChooseImage_Click(object sender, EventArgs e)
|
||||
{
|
||||
using OpenFileDialog openFileDialog = new OpenFileDialog
|
||||
{
|
||||
Multiselect = true,
|
||||
Filter = "Èçîáðàæåíèÿ|*.jpg;*.jpeg;*.png;*.bmp"
|
||||
};
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
ClearImage();
|
||||
|
||||
foreach (string filePath in openFileDialog.FileNames)
|
||||
{
|
||||
selectedImage = File.ReadAllBytes(filePath);
|
||||
textBoxImage.Text = Path.GetFileName(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearImage()
|
||||
{
|
||||
selectedImage = null;
|
||||
textBoxImage.Clear();
|
||||
}
|
||||
|
||||
private void buttonClearImage_Click(object sender, EventArgs e)
|
||||
{
|
||||
ClearImage();
|
||||
}
|
||||
|
||||
private void buttonBookAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxTitle.Text))
|
||||
MessageBox.Show("Ââåäèòå íàçâàíèå!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(dateTextBoxDate.TextBoxValue))
|
||||
MessageBox.Show("Ââåäèòå äàòó èçäàíèÿ!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
if (string.IsNullOrEmpty(controlSelectedComboBoxSingleAuthor.SelectedElement))
|
||||
MessageBox.Show("Âûáåðèòå àâòîðà!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
if (string.IsNullOrEmpty(textBoxImage.Text))
|
||||
MessageBox.Show("Âûáåðèòå îáëîæêó!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
//controlDataTableCellBooks.AddCell<T>(0, 0,)
|
||||
Book newBook = new Book
|
||||
{
|
||||
Id = counterBooksIds,
|
||||
Title = textBoxTitle.Text,
|
||||
Author = controlSelectedComboBoxSingleAuthor.SelectedElement,
|
||||
Date = DateTime.Now,
|
||||
};
|
||||
dataGridViewBooks.Rows.Add(newBook);
|
||||
}
|
||||
}
|
||||
}
|
97
COP_5/LibraryAccountingApp_lab3/FormAuthor.Designer.cs
generated
Normal file
97
COP_5/LibraryAccountingApp_lab3/FormAuthor.Designer.cs
generated
Normal file
@ -0,0 +1,97 @@
|
||||
namespace LibraryAccountingApp_lab3
|
||||
{
|
||||
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()
|
||||
{
|
||||
textBoxAuthor = new TextBox();
|
||||
label1 = new Label();
|
||||
buttonAdd = new Button();
|
||||
buttonCancel = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBoxAuthor
|
||||
//
|
||||
textBoxAuthor.Location = new Point(12, 27);
|
||||
textBoxAuthor.Name = "textBoxAuthor";
|
||||
textBoxAuthor.Size = new Size(277, 23);
|
||||
textBoxAuthor.TabIndex = 0;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(12, 9);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(34, 15);
|
||||
label1.TabIndex = 1;
|
||||
label1.Text = "Имя:";
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackColor = Color.LightGreen;
|
||||
buttonAdd.Location = new Point(50, 76);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(88, 23);
|
||||
buttonAdd.TabIndex = 2;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = false;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.BackColor = Color.Salmon;
|
||||
buttonCancel.Location = new Point(165, 76);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(88, 23);
|
||||
buttonCancel.TabIndex = 3;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = false;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// FormAuthor
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(301, 114);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonAdd);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(textBoxAuthor);
|
||||
Name = "FormAuthor";
|
||||
Text = "Добавление автора";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox textBoxAuthor;
|
||||
private Label label1;
|
||||
private Button buttonAdd;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
48
COP_5/LibraryAccountingApp_lab3/FormAuthor.cs
Normal file
48
COP_5/LibraryAccountingApp_lab3/FormAuthor.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.BusinessLogicsContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.StorageContracts;
|
||||
|
||||
namespace LibraryAccountingApp_lab3
|
||||
{
|
||||
public partial class FormAuthor : Form
|
||||
{
|
||||
private readonly IAuthorLogic _logic;
|
||||
private readonly IAuthorStorage _storage;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormAuthor(IAuthorLogic logic, IAuthorStorage storage)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logic = logic;
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxAuthor.Text))
|
||||
MessageBox.Show("Введите имя автора!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
try
|
||||
{
|
||||
_logic.CreateOrUpdate(new AuthorBindingModel
|
||||
{
|
||||
Id = _id,
|
||||
Name = textBoxAuthor.Text,
|
||||
});
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Ошибка при добавлении!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
COP_5/LibraryAccountingApp_lab3/FormAuthor.resx
Normal file
120
COP_5/LibraryAccountingApp_lab3/FormAuthor.resx
Normal 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>
|
@ -1,6 +1,6 @@
|
||||
namespace LibraryAccountingApp_lab3
|
||||
{
|
||||
partial class Form1
|
||||
partial class FormLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -32,6 +32,7 @@
|
||||
componentDocumentWithChartBarWord1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord(components);
|
||||
buttonChooseImage = new Button();
|
||||
groupBox1 = new GroupBox();
|
||||
buttonAddAuthor = new Button();
|
||||
textBoxTitle = new TextBox();
|
||||
buttonBookAdd = new Button();
|
||||
buttonClearImage = new Button();
|
||||
@ -41,24 +42,19 @@
|
||||
dateTextBoxDate = new FedComponentLib.DateTextBox();
|
||||
label1 = new Label();
|
||||
groupBox2 = new GroupBox();
|
||||
dataGridViewBooks = new DataGridView();
|
||||
Id = new DataGridViewTextBoxColumn();
|
||||
Title = new DataGridViewTextBoxColumn();
|
||||
Автор = new DataGridViewTextBoxColumn();
|
||||
Date = new DataGridViewTextBoxColumn();
|
||||
controlDataTableCellBooks = new ControlsLibraryNet60.Data.ControlDataTableCell();
|
||||
buttonBookDelete = new Button();
|
||||
groupBox1.SuspendLayout();
|
||||
groupBox2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewBooks).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonChooseImage
|
||||
//
|
||||
buttonChooseImage.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonChooseImage.Location = new Point(52, 238);
|
||||
buttonChooseImage.Anchor = AnchorStyles.None;
|
||||
buttonChooseImage.Location = new Point(52, 244);
|
||||
buttonChooseImage.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonChooseImage.Name = "buttonChooseImage";
|
||||
buttonChooseImage.Size = new Size(125, 29);
|
||||
buttonChooseImage.Size = new Size(176, 24);
|
||||
buttonChooseImage.TabIndex = 17;
|
||||
buttonChooseImage.Text = "Выбрать обложку";
|
||||
buttonChooseImage.UseVisualStyleBackColor = true;
|
||||
@ -67,6 +63,8 @@
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBox1.Controls.Add(buttonBookDelete);
|
||||
groupBox1.Controls.Add(buttonAddAuthor);
|
||||
groupBox1.Controls.Add(textBoxTitle);
|
||||
groupBox1.Controls.Add(buttonBookAdd);
|
||||
groupBox1.Controls.Add(buttonClearImage);
|
||||
@ -78,24 +76,39 @@
|
||||
groupBox1.Controls.Add(buttonChooseImage);
|
||||
groupBox1.Location = new Point(12, 12);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(243, 431);
|
||||
groupBox1.Size = new Size(272, 465);
|
||||
groupBox1.TabIndex = 18;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Загрузка книги";
|
||||
//
|
||||
// buttonAddAuthor
|
||||
//
|
||||
buttonAddAuthor.Anchor = AnchorStyles.None;
|
||||
buttonAddAuthor.BackColor = Color.PaleTurquoise;
|
||||
buttonAddAuthor.Location = new Point(6, 195);
|
||||
buttonAddAuthor.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonAddAuthor.Name = "buttonAddAuthor";
|
||||
buttonAddAuthor.Size = new Size(111, 24);
|
||||
buttonAddAuthor.TabIndex = 25;
|
||||
buttonAddAuthor.Text = "Добавить автора";
|
||||
buttonAddAuthor.UseVisualStyleBackColor = false;
|
||||
buttonAddAuthor.Click += buttonAddAuthor_Click;
|
||||
//
|
||||
// textBoxTitle
|
||||
//
|
||||
textBoxTitle.Location = new Point(6, 46);
|
||||
textBoxTitle.Anchor = AnchorStyles.None;
|
||||
textBoxTitle.Location = new Point(6, 48);
|
||||
textBoxTitle.Name = "textBoxTitle";
|
||||
textBoxTitle.Size = new Size(221, 23);
|
||||
textBoxTitle.Size = new Size(243, 23);
|
||||
textBoxTitle.TabIndex = 19;
|
||||
//
|
||||
// buttonBookAdd
|
||||
//
|
||||
buttonBookAdd.Anchor = AnchorStyles.None;
|
||||
buttonBookAdd.BackColor = Color.YellowGreen;
|
||||
buttonBookAdd.Location = new Point(18, 380);
|
||||
buttonBookAdd.Location = new Point(18, 363);
|
||||
buttonBookAdd.Name = "buttonBookAdd";
|
||||
buttonBookAdd.Size = new Size(209, 32);
|
||||
buttonBookAdd.Size = new Size(231, 36);
|
||||
buttonBookAdd.TabIndex = 19;
|
||||
buttonBookAdd.Text = "Добавить книгу";
|
||||
buttonBookAdd.UseVisualStyleBackColor = false;
|
||||
@ -103,30 +116,31 @@
|
||||
//
|
||||
// buttonClearImage
|
||||
//
|
||||
buttonClearImage.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonClearImage.Anchor = AnchorStyles.None;
|
||||
buttonClearImage.BackColor = Color.Silver;
|
||||
buttonClearImage.Font = new Font("Segoe UI", 7F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonClearImage.Location = new Point(110, 301);
|
||||
buttonClearImage.Location = new Point(139, 303);
|
||||
buttonClearImage.Name = "buttonClearImage";
|
||||
buttonClearImage.Size = new Size(117, 23);
|
||||
buttonClearImage.Size = new Size(127, 27);
|
||||
buttonClearImage.TabIndex = 19;
|
||||
buttonClearImage.Text = "Очистить";
|
||||
buttonClearImage.UseVisualStyleBackColor = true;
|
||||
buttonClearImage.UseVisualStyleBackColor = false;
|
||||
buttonClearImage.Click += buttonClearImage_Click;
|
||||
//
|
||||
// textBoxImage
|
||||
//
|
||||
textBoxImage.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
textBoxImage.Location = new Point(6, 272);
|
||||
textBoxImage.Anchor = AnchorStyles.None;
|
||||
textBoxImage.Location = new Point(6, 274);
|
||||
textBoxImage.Name = "textBoxImage";
|
||||
textBoxImage.ReadOnly = true;
|
||||
textBoxImage.Size = new Size(221, 23);
|
||||
textBoxImage.Size = new Size(243, 23);
|
||||
textBoxImage.TabIndex = 24;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
label2.Anchor = AnchorStyles.None;
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(6, 149);
|
||||
label2.Location = new Point(6, 151);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(43, 15);
|
||||
label2.TabIndex = 22;
|
||||
@ -134,28 +148,28 @@
|
||||
//
|
||||
// controlSelectedComboBoxSingleAuthor
|
||||
//
|
||||
controlSelectedComboBoxSingleAuthor.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
controlSelectedComboBoxSingleAuthor.Location = new Point(6, 167);
|
||||
controlSelectedComboBoxSingleAuthor.Anchor = AnchorStyles.None;
|
||||
controlSelectedComboBoxSingleAuthor.Location = new Point(6, 169);
|
||||
controlSelectedComboBoxSingleAuthor.Margin = new Padding(5, 3, 5, 3);
|
||||
controlSelectedComboBoxSingleAuthor.Name = "controlSelectedComboBoxSingleAuthor";
|
||||
controlSelectedComboBoxSingleAuthor.SelectedElement = "";
|
||||
controlSelectedComboBoxSingleAuthor.Size = new Size(221, 24);
|
||||
controlSelectedComboBoxSingleAuthor.Size = new Size(243, 28);
|
||||
controlSelectedComboBoxSingleAuthor.TabIndex = 19;
|
||||
//
|
||||
// dateTextBoxDate
|
||||
//
|
||||
dateTextBoxDate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dateTextBoxDate.Anchor = AnchorStyles.None;
|
||||
dateTextBoxDate.DatePattern = null;
|
||||
dateTextBoxDate.Location = new Point(6, 75);
|
||||
dateTextBoxDate.Location = new Point(6, 77);
|
||||
dateTextBoxDate.Name = "dateTextBoxDate";
|
||||
dateTextBoxDate.Size = new Size(221, 53);
|
||||
dateTextBoxDate.Size = new Size(243, 57);
|
||||
dateTextBoxDate.TabIndex = 21;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
label1.Anchor = AnchorStyles.None;
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(6, 27);
|
||||
label1.Location = new Point(6, 29);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(62, 15);
|
||||
label1.TabIndex = 19;
|
||||
@ -163,69 +177,50 @@
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
groupBox2.Controls.Add(dataGridViewBooks);
|
||||
groupBox2.Location = new Point(261, 12);
|
||||
groupBox2.Controls.Add(controlDataTableCellBooks);
|
||||
groupBox2.Location = new Point(288, 12);
|
||||
groupBox2.Name = "groupBox2";
|
||||
groupBox2.Size = new Size(527, 286);
|
||||
groupBox2.TabIndex = 19;
|
||||
groupBox2.TabStop = false;
|
||||
groupBox2.Text = "Вывод книг";
|
||||
//
|
||||
// dataGridViewBooks
|
||||
//
|
||||
dataGridViewBooks.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewBooks.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewBooks.Columns.AddRange(new DataGridViewColumn[] { Id, Title, Автор, Date });
|
||||
dataGridViewBooks.Location = new Point(6, 22);
|
||||
dataGridViewBooks.Name = "dataGridViewBooks";
|
||||
dataGridViewBooks.RowTemplate.Height = 25;
|
||||
dataGridViewBooks.Size = new Size(515, 258);
|
||||
dataGridViewBooks.TabIndex = 20;
|
||||
//
|
||||
// Id
|
||||
//
|
||||
Id.HeaderText = "Идентификатор";
|
||||
Id.Name = "Id";
|
||||
Id.Visible = false;
|
||||
//
|
||||
// Title
|
||||
//
|
||||
Title.HeaderText = "Название";
|
||||
Title.Name = "Title";
|
||||
//
|
||||
// Автор
|
||||
//
|
||||
Автор.HeaderText = "Author";
|
||||
Автор.Name = "Автор";
|
||||
//
|
||||
// Date
|
||||
//
|
||||
Date.HeaderText = "Дата издания";
|
||||
Date.Name = "Date";
|
||||
//
|
||||
// controlDataTableCellBooks
|
||||
//
|
||||
controlDataTableCellBooks.Location = new Point(623, 250);
|
||||
controlDataTableCellBooks.AutoSize = true;
|
||||
controlDataTableCellBooks.Location = new Point(3, 19);
|
||||
controlDataTableCellBooks.Margin = new Padding(4, 3, 4, 3);
|
||||
controlDataTableCellBooks.Name = "controlDataTableCellBooks";
|
||||
controlDataTableCellBooks.SelectedRowIndex = -1;
|
||||
controlDataTableCellBooks.Size = new Size(159, 106);
|
||||
controlDataTableCellBooks.Size = new Size(517, 261);
|
||||
controlDataTableCellBooks.TabIndex = 0;
|
||||
//
|
||||
// Form1
|
||||
// buttonBookDelete
|
||||
//
|
||||
buttonBookDelete.Anchor = AnchorStyles.None;
|
||||
buttonBookDelete.BackColor = Color.LightCoral;
|
||||
buttonBookDelete.Location = new Point(18, 405);
|
||||
buttonBookDelete.Name = "buttonBookDelete";
|
||||
buttonBookDelete.Size = new Size(231, 36);
|
||||
buttonBookDelete.TabIndex = 26;
|
||||
buttonBookDelete.Text = "Удалить книгу";
|
||||
buttonBookDelete.UseVisualStyleBackColor = false;
|
||||
buttonBookDelete.Click += buttonBookDelete_Click;
|
||||
//
|
||||
// FormLibrary
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(controlDataTableCellBooks);
|
||||
ClientSize = new Size(821, 489);
|
||||
Controls.Add(groupBox2);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "Form1";
|
||||
Name = "FormLibrary";
|
||||
Text = "Библиотека";
|
||||
Load += FormLibrary_Load;
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
groupBox2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewBooks).EndInit();
|
||||
groupBox2.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -243,10 +238,7 @@
|
||||
private TextBox textBoxTitle;
|
||||
private GroupBox groupBox2;
|
||||
private ControlsLibraryNet60.Data.ControlDataTableCell controlDataTableCellBooks;
|
||||
private DataGridView dataGridViewBooks;
|
||||
private DataGridViewTextBoxColumn Id;
|
||||
private DataGridViewTextBoxColumn Title;
|
||||
private DataGridViewTextBoxColumn Автор;
|
||||
private DataGridViewTextBoxColumn Date;
|
||||
private Button buttonAddAuthor;
|
||||
private Button buttonBookDelete;
|
||||
}
|
||||
}
|
246
COP_5/LibraryAccountingApp_lab3/FormLibrary.cs
Normal file
246
COP_5/LibraryAccountingApp_lab3/FormLibrary.cs
Normal file
@ -0,0 +1,246 @@
|
||||
using ComponentsLibraryNet60.Heplers;
|
||||
using ControlsLibraryNet60.Data;
|
||||
using ControlsLibraryNet60.Models;
|
||||
using COP_5;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using FedComponentLib;
|
||||
using LibraryAccountingApp_lab3.Contracts.BindingModels;
|
||||
using LibraryAccountingApp_lab3.Contracts.BusinessLogicsContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.StorageContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.ViewModels;
|
||||
using LibraryAccountingApp_lab3.DatabaseImplement.Models;
|
||||
using Microsoft.IdentityModel.Abstractions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace LibraryAccountingApp_lab3
|
||||
{
|
||||
public partial class FormLibrary : Form
|
||||
{
|
||||
private byte[]? selectedImage = new byte[16];
|
||||
private int counterBooksIds = 0;
|
||||
private int counterRows = 0;
|
||||
private readonly IBookLogic _bookLogic;
|
||||
private readonly IAuthorLogic _authorLogic;
|
||||
public readonly IBookStorage _bookStorage;
|
||||
int rowIndex = 0;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormLibrary(IBookLogic bookLogic, IAuthorLogic authorLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_bookLogic = bookLogic;
|
||||
_authorLogic = authorLogic;
|
||||
InitializeTableBooks();
|
||||
LoadDataInTable();
|
||||
FillControlSelectedComboBoxSingle();
|
||||
dateTextBoxDate.DatePattern = @"^(0[1-9]|[12][0-9]|3[01])\s+(ÿíâàðü|ôåâðàëü|ìàðò|àïðåëü|ìàé|èþíü|èþëü|àâãóñò|ñåíòÿáðü|îêòÿáðü|íîÿáðü|äåêàáðü)\s+\d{4}$";
|
||||
}
|
||||
private void FormLibrary_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadDataInTable();
|
||||
}
|
||||
|
||||
|
||||
private void FillControlSelectedComboBoxSingle()
|
||||
{
|
||||
//List<string> list = new List<string>() {
|
||||
// "Äåíèåë Êèç",
|
||||
// "Àëåêñàíäð Ïóøêèí",
|
||||
// "Ô¸äîð Äîñòîåâñêèé",
|
||||
// "Áîðèñ Àêóíèí",
|
||||
// "Íèêîëàñ Ñïàðêñ"
|
||||
//};
|
||||
//for (int i = 0; i < list.Count; i++)
|
||||
//{
|
||||
// controlSelectedComboBoxSingleAuthor.AddElement(list[i]);
|
||||
//}
|
||||
controlSelectedComboBoxSingleAuthor.Clear();
|
||||
try
|
||||
{
|
||||
var list = _authorLogic.Read(null);
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
foreach (var author in list)
|
||||
{
|
||||
controlSelectedComboBoxSingleAuthor.AddElement(author.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Îøèáêà çàãðóçêè äàííûõ: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBook(int rowIndex, BookViewModel book)
|
||||
{
|
||||
controlDataTableCellBooks.AddCell(rowIndex, 1, book);
|
||||
controlDataTableCellBooks.AddCell(rowIndex, 2, book);
|
||||
controlDataTableCellBooks.AddCell(rowIndex, 3, book);
|
||||
}
|
||||
|
||||
private void LoadDataInTable()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _bookLogic.Read(null);
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
rowIndex = 0;
|
||||
foreach (var book in list)
|
||||
{
|
||||
AddBook(rowIndex, book);
|
||||
rowIndex++;
|
||||
}
|
||||
controlDataTableCellBooks.Update();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Îøèáêà çàãðóçêè äàííûõ: {ex.Message}");
|
||||
}
|
||||
}
|
||||
private void InitializeTableBooks()
|
||||
{
|
||||
|
||||
List<DataTableColumnConfig> columns = new List<DataTableColumnConfig> { };
|
||||
DataTableColumnConfig item1 = new DataTableColumnConfig
|
||||
{
|
||||
ColumnHeader = "Id",
|
||||
PropertyName = "Id",
|
||||
Width = 20,
|
||||
Visible = false,
|
||||
};
|
||||
DataTableColumnConfig item2 = new DataTableColumnConfig
|
||||
{
|
||||
ColumnHeader = "Title",
|
||||
PropertyName = "Title",
|
||||
Width = 150,
|
||||
Visible = true,
|
||||
};
|
||||
DataTableColumnConfig item3 = new DataTableColumnConfig
|
||||
{
|
||||
ColumnHeader = "Author",
|
||||
PropertyName = "Author",
|
||||
Width = 150,
|
||||
Visible = true,
|
||||
};
|
||||
DataTableColumnConfig item4 = new DataTableColumnConfig
|
||||
{
|
||||
ColumnHeader = "Date",
|
||||
PropertyName = "Date",
|
||||
Width = 150,
|
||||
Visible = true,
|
||||
};
|
||||
columns.Add(item1);
|
||||
columns.Add(item2);
|
||||
columns.Add(item3);
|
||||
columns.Add(item4);
|
||||
controlDataTableCellBooks.LoadColumns(columns);
|
||||
}
|
||||
private void buttonBookAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxTitle.Text))
|
||||
MessageBox.Show("Ââåäèòå íàçâàíèå!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(dateTextBoxDate.TextBoxValue))
|
||||
MessageBox.Show("Ââåäèòå äàòó èçäàíèÿ!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
if (string.IsNullOrEmpty(controlSelectedComboBoxSingleAuthor.SelectedElement))
|
||||
MessageBox.Show("Âûáåðèòå àâòîðà!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
if (string.IsNullOrEmpty(textBoxImage.Text))
|
||||
MessageBox.Show("Âûáåðèòå îáëîæêó!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
try
|
||||
{
|
||||
_bookLogic.CreateOrUpdate(new BookBindingModel
|
||||
{
|
||||
Id = _id,
|
||||
Title = textBoxTitle.Text,
|
||||
Author = controlSelectedComboBoxSingleAuthor.SelectedElement,
|
||||
Date = dateTextBoxDate.TextBoxValue,
|
||||
Image = textBoxImage.Text,
|
||||
});
|
||||
LoadDataInTable();
|
||||
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî", "Ñîîáùåíèå", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Îøèáêà ïðè äîáàâëåíèè!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonBookDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
//if (controlDataTableCellBooks.SelectedRowIndex != -1)
|
||||
//{
|
||||
// if (MessageBox.Show("Óäàëèòü êíèãó?", "Âîïðîñ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
// {
|
||||
// int id = controlDataTableCellBooks.SelectedRowIndex;
|
||||
// var model = controlDataTableCellBooks.GetSelectedObject();
|
||||
// try
|
||||
// {
|
||||
// _bookLogic.Delete(new BookBindingModel
|
||||
// {
|
||||
// Id = id
|
||||
// });
|
||||
// LoadDataInTable();
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
private void buttonChooseImage_Click(object sender, EventArgs e)
|
||||
{
|
||||
using OpenFileDialog openFileDialog = new OpenFileDialog
|
||||
{
|
||||
Multiselect = true,
|
||||
Filter = "Èçîáðàæåíèÿ|*.jpg;*.jpeg;*.png;*.bmp"
|
||||
};
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
ClearImage();
|
||||
|
||||
foreach (string filePath in openFileDialog.FileNames)
|
||||
{
|
||||
selectedImage = File.ReadAllBytes(filePath);
|
||||
textBoxImage.Text = Path.GetFileName(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearImage()
|
||||
{
|
||||
selectedImage = null;
|
||||
textBoxImage.Clear();
|
||||
}
|
||||
|
||||
private void buttonClearImage_Click(object sender, EventArgs e)
|
||||
{
|
||||
ClearImage();
|
||||
}
|
||||
|
||||
private void buttonAddAuthor_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormAuthor));
|
||||
if (service is FormAuthor form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
FillControlSelectedComboBoxSingle();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -120,28 +120,4 @@
|
||||
<metadata name="componentDocumentWithChartBarWord1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Title.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Автор.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Date.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Title.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Автор.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Date.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
@ -12,6 +12,13 @@
|
||||
<PackageReference Include="ComponentsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="ControlsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="FedComponentLib" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.18" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.18" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
75
COP_5/LibraryAccountingApp_lab3/Migrations/20241015201338_InitialCreate.Designer.cs
generated
Normal file
75
COP_5/LibraryAccountingApp_lab3/Migrations/20241015201338_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
using LibraryAccountingApp_lab3.DatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Migrations
|
||||
{
|
||||
[DbContext(typeof(LibraryDatabase))]
|
||||
[Migration("20241015201338_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.18")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("LibraryAccountingApp_lab3.DatabaseImplement.Models.Author", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("LibraryAccountingApp_lab3.DatabaseImplement.Models.Book", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Author")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Date")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<byte[]>("Image")
|
||||
.IsRequired()
|
||||
.HasColumnType("varbinary(max)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Books");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Authors",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Authors", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Books",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Author = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Date = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Image = table.Column<byte[]>(type: "varbinary(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Books", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Authors");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Books");
|
||||
}
|
||||
}
|
||||
}
|
75
COP_5/LibraryAccountingApp_lab3/Migrations/20241028091634_imageFix.Designer.cs
generated
Normal file
75
COP_5/LibraryAccountingApp_lab3/Migrations/20241028091634_imageFix.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
using LibraryAccountingApp_lab3.DatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Migrations
|
||||
{
|
||||
[DbContext(typeof(LibraryDatabase))]
|
||||
[Migration("20241028091634_imageFix")]
|
||||
partial class imageFix
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.18")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("LibraryAccountingApp_lab3.DatabaseImplement.Models.Author", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("LibraryAccountingApp_lab3.DatabaseImplement.Models.Book", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Author")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Date")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Image")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Books");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class imageFix : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Image",
|
||||
table: "Books",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
oldClrType: typeof(byte[]),
|
||||
oldType: "varbinary(max)");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<byte[]>(
|
||||
name: "Image",
|
||||
table: "Books",
|
||||
type: "varbinary(max)",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
// <auto-generated />
|
||||
using LibraryAccountingApp_lab3.DatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace LibraryAccountingApp_lab3.Migrations
|
||||
{
|
||||
[DbContext(typeof(LibraryDatabase))]
|
||||
partial class LibraryDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.18")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("LibraryAccountingApp_lab3.DatabaseImplement.Models.Author", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("LibraryAccountingApp_lab3.DatabaseImplement.Models.Book", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Author")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Date")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Image")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Books");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,16 @@
|
||||
using LibraryAccountingApp_lab3.BusinessLogic;
|
||||
using LibraryAccountingApp_lab3.Contracts.BusinessLogicsContracts;
|
||||
using LibraryAccountingApp_lab3.Contracts.StorageContracts;
|
||||
using LibraryAccountingApp_lab3.DatabaseImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace LibraryAccountingApp_lab3
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -11,7 +20,22 @@ namespace LibraryAccountingApp_lab3
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormLibrary>());
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IBookStorage, BookStorage>();
|
||||
services.AddTransient<IAuthorStorage, AuthorStorage>();
|
||||
|
||||
services.AddTransient<IBookLogic, BookLogic>();
|
||||
services.AddTransient<IAuthorLogic, AuthorLogic>();
|
||||
|
||||
services.AddTransient<FormLibrary>();
|
||||
services.AddTransient<FormAuthor>();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ namespace WinFormsApp
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
//Application.Run(new FormLibrary());
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,12 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComponentsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="ControlsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="FedComponentLib" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\COP_5\COP_5.csproj" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user