コード例 #1
0
    protected void On_ModifyBtn_Clicked(object sender, EventArgs e)
    {
        TreeIter iter;

        BooksView.Selection.GetSelected(out iter);
        var id   = BookList.GetValue(iter, 0);
        var book = Repository.FindById(Convert.ToInt32(id));

        if (id == null)
        {
            MessageDialog warning =
                new MessageDialog(this, DialogFlags.Modal | DialogFlags.DestroyWithParent,
                                  MessageType.Warning, ButtonsType.Ok,
                                  "\nPlease choose a book first!");
            warning.Run();
            warning.Destroy();
            return;
        }
        //modify book dialog
        var dlg = new BookInfoDialog(book.Id, book);

        if (dlg.Run() == (int)ResponseType.Ok)
        {
            var nb = dlg.newBook;
            if (nb != null)
            {
                //set newValue to BookList
                BookList.SetValues(iter, nb.Id, nb.Title, nb.Author, nb.Press, nb.ISBN, nb.Price);
                //updata newInfo to database
                Repository.Modify(nb);
            }
        }
        dlg.Destroy();
    }
コード例 #2
0
    protected void On_AddBtn_Clicked(object sender, EventArgs e)
    {
        //show Addbook dialog
        var newId = lastId + 1;
        var dlg   = new BookInfoDialog(newId, null);

        if (dlg.Run() == (int)ResponseType.Ok)
        {
            var nb = dlg.newBook;
            if (nb != null)
            {
                //update book in BookList(model)
                BookList.AppendValues
                    (nb.Id, nb.Title, nb.Author, nb.Press, nb.ISBN, nb.Price);
                //update book in database
                Repository.Add(nb);
                //update lastId
                lastId = nb.Id;
            }
        }
        dlg.Destroy();
    }