public EditBookViewModel(string author_edit, string title_edit, string year_edit) { Author_block = author_edit; Title_block = title_edit; selected_year = new Combobox_values(year_edit); values = new ObservableCollection <Combobox_values>(); values.Add(new Combobox_values("")); for (int i = DateTime.Now.Year; i > 1700; i--) { values.Add(new Combobox_values(i.ToString())); if (String.Equals(year_edit, i.ToString())) { Selected_year = values.ElementAt(2020 - i); } } button = "Edit"; title_window = "Edit book"; Modification = new Command(Edit_Book); CloseWindow = new Command(Close_Window); }
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; }