void confirm_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(txtName.Text))
     {
         MessageBox.Show("Name of the book is required");
         txtName.Focus();
     }
     else if (String.IsNullOrEmpty(txtAuthor.Text))
     {
         MessageBox.Show("Name of the Author is required");
         txtAuthor.Focus();
     }
     else
     {
         using (BooksDatacontext context = new BooksDatacontext(App.booksconnectionString))
         {
             try
             {
                 //Add the details to the Tables
                 TblBooks st = new TblBooks()
                 {
                     name = txtName.Text, author = txtAuthor.Text, description = txtDesc.Text, version = txtVersion.Text
                 };
                 context.TblBooks.InsertOnSubmit(st);
                 context.SubmitChanges();
                 MessageBox.Show("Book has been Added Successfully");
             }
             catch (Exception)
             {
                 MessageBox.Show("Unable to add book");
             }
         }
     }
 }
Esempio n. 2
0
 private void confirm_Click(object sender, EventArgs e)
 {
     //throw new NotImplementedException();
     using (BooksDatacontext context = new BooksDatacontext(App.booksconnectionString))
     {
         var BookLoaded = (from book in context.TblBooks where book.id == Int32.Parse(txtID.Text) select book).FirstOrDefault();
         if (BookLoaded != null)
         {
             try
             {
                 //Adding changes into the database
                 String id = NavigationContext.QueryString["id"];
                 BookLoaded.author      = txtAuthor.Text;
                 BookLoaded.description = txtDesc.Text;
                 BookLoaded.name        = txtName.Text;
                 BookLoaded.version     = txtVersion.Text;
                 context.SubmitChanges();
                 MessageBox.Show("Book Editted successfully");
                 //Move back to the view page
                 NavigationService.Navigate(new Uri("/ViewBook.xaml?id=" + id, UriKind.RelativeOrAbsolute));
             }
             catch (Exception)
             {
                 MessageBox.Show("Unable to Edit the book");
             }
         }
     }
 }
 //delete book by id
 public void DeleteUser(String id)
 {
     using (BooksDatacontext context = new BooksDatacontext(App.booksconnectionString))
     {
         IQueryable <TblBooks> entityQuery = from c in context.TblBooks where c.id.Equals(id) select c;
         TblBooks entityToDelete           = entityQuery.FirstOrDefault();
         context.TblBooks.DeleteOnSubmit(entityToDelete);
         context.SubmitChanges();
     }
 }
        void confirm_Click(object sender, EventArgs e)
        {
            //validate the form
            if (String.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("Name is required");
                txtName.Focus();
            }
            else if (String.IsNullOrEmpty(txtUname.Text))
            {
                MessageBox.Show("Username is required");
                txtUname.Focus();
            }
            else if (String.IsNullOrEmpty(txtPasswd.Password))
            {
                MessageBox.Show("Password is required");
                txtPasswd.Focus();
            }
            else
            {
                using (BooksDatacontext context = new BooksDatacontext(App.booksconnectionString))
                {
                    try
                    {
                        //Add user information in the database table TblAccounts
                        TblAccounts tb = new TblAccounts();

                        tb.name     = txtName.Text;
                        tb.username = txtUname.Text;
                        tb.passwd   = txtPasswd.Password;
                        context.TblAccounts.InsertOnSubmit(tb);
                        context.SubmitChanges();
                        MessageBox.Show("Account Created Successfully");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("unable to Create an Account");
                    }
                }
            }
        }