private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem == null) { MessageBox.Show("Выберите пользователя"); return; } if (checkedListBox1.SelectedItems.Count == 0) { MessageBox.Show("Выберите книги"); return; } using (var db = new LibraryContainer()) { var user = db.UsersSet.ToList().Find(p => p.Id == (comboBox1.SelectedItem as Users).Id); foreach (var item in checkedListBox1.SelectedItems) { var book = db.BooksSet.ToList().Find(p => p.Id == (item as Books).Id); db.LogBooksSet.Add(new LogBooks { Books = book, Users = user, IsDebtor = true }); } db.SaveChanges(); } this.Close(); }
private void buttonQuery4_Click(object sender, EventArgs e) { listBoxQuery4.Items.Clear(); using (var db = new LibraryContainer()) { listBoxQuery4.Items.AddRange(db.UsersSet.ToList().Skip(1).FirstOrDefault().LogBooks.Where(p => p.IsDebtor).Select(p => p.Books).ToArray()); } }
private void checkBoxDebstor_CheckedChanged(object sender, EventArgs e) { using (var db = new LibraryContainer()) { db.LogBooksSet.ToList().Find(p => p.Id == logBook.Id).IsDebtor = !checkBoxDebstor.Checked; db.SaveChanges(); } }
public FormAddBook() { InitializeComponent(); using (var db = new LibraryContainer()) { checkedListBox1.Items.AddRange(db.AuthorsSet.ToArray()); } }
private void buttonQuery2_Click(object sender, EventArgs e) { listBoxQuery2.Items.Clear(); using (var db = new LibraryContainer()) { listBoxQuery2.Items.AddRange(db.BooksSet.ToList().Skip(2).FirstOrDefault().Authors.ToArray()); } }
private void buttonQuery5_Click(object sender, EventArgs e) { using (var db = new LibraryContainer()) { db.LogBooksSet.ToList().ForEach(p => p.IsDebtor = false); db.SaveChanges(); ShowAll(); } }
private void Show() { using (var db = new LibraryContainer()) { foreach (var item in db.AuthorsSet) { listBox1.Items.Add(item); } } }
private void ShowLogs() { panelListLogs.Controls.Clear(); using (var db = new LibraryContainer()) { foreach (var item in db.LogBooksSet) { var panel = new LogsPanel(item); panelListLogs.Controls.Add(panel); } } }
private void ShowUsers() { panelListUsers.Controls.Clear(); using (var db = new LibraryContainer()) { foreach (var item in db.UsersSet) { var panel = new UsersPanel(item); panelListUsers.Controls.Add(panel); } } }
private void InitDB() { using (var db = new LibraryContainer()) { try { foreach (var item in db.BooksSet) { item.Authors.Clear(); } db.BooksSet?.RemoveRange(db.BooksSet); db.AuthorsSet?.RemoveRange(db.AuthorsSet); db.LogBooksSet?.RemoveRange(db.LogBooksSet); db.UsersSet?.RemoveRange(db.UsersSet); db.SaveChanges(); db.UsersSet.Add(new Users { Name = "Max" }); db.UsersSet.Add(new Users { Name = "Ira" }); db.SaveChanges(); db.BooksSet.Add(new Books { Name = "Calina" }); db.BooksSet.Add(new Books { Name = "Stalingrad" }); db.SaveChanges(); db.AuthorsSet.Add(new Authors { Name = "Pushkin" }); db.AuthorsSet.Add(new Authors { Name = "Lenin" }); db.SaveChanges(); db.AuthorsSet.ToList()[0].Books.Add(db.BooksSet.ToList()[0]); db.AuthorsSet.ToList()[0].Books.Add(db.BooksSet.ToList()[1]); db.AuthorsSet.ToList()[1].Books.Add(db.BooksSet.ToList()[1]); db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.InnerException.InnerException.Message); } } }
private void buttonQuery3_Click(object sender, EventArgs e) { listBoxQuery3.Items.Clear(); using (var db = new LibraryContainer()) { var listBook = db.BooksSet.ToList(); foreach (var item in db.LogBooksSet.Where(p => p.IsDebtor)) { listBook.Remove(listBook.Find(p => p.Id == item.Books.Id)); } listBoxQuery3.Items.AddRange(listBook.ToArray()); } }
private void buttonDelete_Click(object sender, EventArgs e) { if (MessageBox.Show($"Вы дейсвительно хотите удалить запись", "Подтверждение удаления", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } using (var db = new LibraryContainer()) { db.LogBooksSet.Remove(db.LogBooksSet.ToList().Find(p => p.Id == logBook.Id)); db.SaveChanges(); } this.Parent.Controls.Remove(this); }
public FormAddLog() { InitializeComponent(); using (var db = new LibraryContainer()) { var listBook = db.BooksSet.ToList(); foreach (var item in db.LogBooksSet.Where(p => p.IsDebtor)) { listBook.Remove(listBook.Find(p => p.Id == item.Books.Id)); } checkedListBox1.Items.AddRange(listBook.ToArray()); comboBox1.Items.AddRange(db.UsersSet.ToArray()); } }
private void buttonQuery1_Click(object sender, EventArgs e) { listBoxQuery1.Items.Clear(); using (var db = new LibraryContainer()) { foreach (var item in db.UsersSet) { if (item.LogBooks.ToList().Exists(ex => ex.IsDebtor)) { listBoxQuery1.Items.Add(item); } } //listBoxQuery1.Items.AddRange(db.UsersSet.Where(p => p.LogBooks.ToList().Exists(ex => ex.IsDebtor)).ToArray()); //не работает, хз почему, кидает не понятный Exception } }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Length == 0) { MessageBox.Show("Введите ФИО!"); return; } using (var db = new LibraryContainer()) { db.UsersSet.Add(new Users { Name = textBox1.Text }); db.SaveChanges(); } this.Close(); }
private void buttonDelete_Click(object sender, EventArgs e) { if (MessageBox.Show($"Вы дейсвительно хотите удалить Автора {authors.Name}", "Подтверждение удаления", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } using (var db = new LibraryContainer()) { var authorFind = db.AuthorsSet.ToList().Find(p => p.Id == authors.Id); if (authorFind != null) { authorFind.Books.Clear(); db.AuthorsSet.Remove(authorFind); db.SaveChanges(); } } this.Parent.Controls.Remove(this); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Length == 0) { MessageBox.Show("Введите название книги!"); return; } using (var db = new LibraryContainer()) { var newBook = new Books(); newBook.Name = textBox1.Text; foreach (var item in checkedListBox1.SelectedItems) { var author = db.AuthorsSet.ToList().Find(p => p.Id == (item as Authors).Id); newBook.Authors.Add(author); } db.BooksSet.Add(newBook); db.SaveChanges(); } this.Close(); }