Ejemplo n.º 1
0
        protected void InsertButton_Click(object sender, EventArgs e)
        {
            try
            {
                int isbn = 0;
                if (txtIsbn.Text != null && txtIsbn.Text != string.Empty)
                {
                    isbn = Convert.ToInt32(txtIsbn.Text);
                }
                string title     = txtTitle.Text.Trim();
                string author    = txtAuthor.Text.Trim();
                int    pages     = Convert.ToInt32(txtPages.Text.Trim());
                string publisher = txtPublisher.Text.Trim();

                proxy = new ServiceReference1.Service1Client();
                ServiceReference1.Book newBook =
                    new ServiceReference1.Book()
                {
                    isbn      = isbn,
                    title     = title,
                    author    = author,
                    pages     = pages,
                    publisher = publisher
                };

                proxy.InsertBook(newBook);

                GridViewBookDetails.DataSource = proxy.GetBooks();
                GridViewBookDetails.DataBind();
                lblMsg.Text = "Book Saved Successfully";
            }
            catch (FaultException <ExceptionMessage> exceptionFromService)
            {
                if (ButtonInsert.Visible == true)
                {
                    lblMsg.Text = "Error while adding new book details :" + exceptionFromService.Detail.errorMessageOfAction;
                }
                else
                {
                    lblMsg.Text = "Error while updating book details :" + exceptionFromService.Detail.errorMessageOfAction;
                }
            }
            catch (Exception exception)
            {
                if (ButtonInsert.Visible == true)
                {
                    lblMsg.Text = "Error while adding new book details :" + exception.Message;
                }
                else
                {
                    lblMsg.Text = "Error while updating book details :" + exception.Message;
                }
            }

            ResetAll();
        }
Ejemplo n.º 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         try
         {
             proxy = new ServiceReference1.Service1Client();
             GridViewBookDetails.DataSource = proxy.GetBooks();
             GridViewBookDetails.DataBind();
         }
         catch (FaultException <ExceptionMessage> exceptionFromService)
         {
             lblMsg.Text = "Error while loading book details :" + exceptionFromService.Detail.errorMessageOfAction;
         }
         catch (Exception exception)
         {
             lblMsg.Text = "Error while loading book details :" + exception.Message;
         }
     }
 }