public void edit_book() { if (Selected_item == null || string.IsNullOrWhiteSpace(Selected_item.Author)) { MessageBox.Show("Press the item to delete."); } else { child_editbook = new EditBookViewModel(Selected_item.Author, Selected_item.Title, Selected_item.Year); add_edit_view = new edit_add_dialog(); child_editbook.WindowClosed += this.Close_childwindow; child_editbook.BookEdited += this.Edit_selectedBook; add_edit_view.DataContext = child_editbook; add_edit_view.ShowDialog(); } }
public BookViewModel() { source_library model = new source_library(); dtb1 = model.dtb1; //// collection = new ObservableCollection <Book>(); selected_item = new Book(); _selected = new Combobox_values(""); Author_block = ""; Title_block = ""; foreach (DataRow dr in dtb1.Rows) { int index = dtb1.Rows.IndexOf(dr); int id = (int)dtb1.Rows[index][0]; string addauthor = dtb1.Rows[index][1].ToString(); string addtitle = dtb1.Rows[index][2].ToString(); string addyear = dtb1.Rows[index][3].ToString(); Collection.Add(new Book { Id = id, Author = addauthor, Title = addtitle, Year = addyear, Selected = false }); } this._Book = CollectionViewSource.GetDefaultView(Collection); FilterCommand = new Command(filter); ClearCommand = new Command(clear); DeleteCommand = new Command(delete_selected); AddnewbookCommand = new Command(add_book); EditnewbookCommand = new Command(edit_book); values = new ObservableCollection <Combobox_values>(); values.Add(new Combobox_values("")); todelete = new ObservableCollection <Book>(); for (int i = DateTime.Now.Year; i > 1700; i--) { values.Add(new Combobox_values(i.ToString())); } allselected = false; child_addbook = new AddBookViewModel(); add_edit_view = new edit_add_dialog(); child_addbook.BookAdded += this.OnBookAdded; child_addbook.WindowClosed += this.Close_childwindow; }
public void add_book() { add_edit_view = new edit_add_dialog(); add_edit_view.DataContext = child_addbook; add_edit_view.ShowDialog(); }