private void Button1_Click(object sender, System.EventArgs e)
        {
            string addISBN;
            string addAuthor;
            double addPrice;
            string addTitle;
            string addDescription;
            int    addCatId;
            string addPath;
            string resultAdd;


            addISBN        = txtISBN.Text;
            addAuthor      = txtAuthor.Text;
            addPrice       = double.Parse(txtPrice.Text);
            addTitle       = txtTitle.Text;
            addDescription = txtDesc.Text;
            addCatId       = int.Parse(listCat.SelectedItem.Value);
            addPath        = txtPath.Text;

            addNewBook = new WebReference1.sellerAdmin();

            resultAdd = addNewBook.addItem(addISBN, addAuthor, addPrice, addTitle, addDescription, addPath, addCatId);
            if (resultAdd == "Success")
            {
                addBookLabel.Text = "Book added to database.";
                Server.Transfer("adminPage.aspx");
            }
            else
            {
                addBookLabel.Text = "Error on insert." + resultAdd;
            }
        }
Exemple #2
0
        private void changeBooks_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            string upISBN        = e.Item.Cells[2].Text;
            string upAuthor      = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
            double upPrice       = double.Parse(((TextBox)e.Item.Cells[4].Controls[0]).Text);
            string upTitle       = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
            string upDescription = ((TextBox)e.Item.Cells[6].Controls[0]).Text;
            int    upCatId       = int.Parse(e.Item.Cells[7].Text);
            string upImage       = ((TextBox)e.Item.Cells[8].Controls[0]).Text;

            myView.RowFilter = "isbn='" + upISBN + "'";
            if (myView.Count > 0)
            {
                myView.Delete(0);
            }
            myView.RowFilter = "";


            DataRow dr = Dt.NewRow();

            dr["isbn"]        = upISBN;
            dr["author"]      = upAuthor;
            dr["price"]       = upPrice;
            dr["title"]       = upTitle;
            dr["description"] = upDescription;
            dr["id"]          = upCatId;
            dr["imgSrc"]      = upImage;


            Dt.Rows.Add(dr);

            changeBooks.EditItemIndex = -1;
            changeBooks.DataSource    = myView;
            changeBooks.DataBind();

            // Now update the database with the new data

            WebReference1.sellerAdmin newData = new WebReference1.sellerAdmin();

            string results;

            results = newData.updateItem(upISBN, upAuthor, upPrice, upTitle, upDescription, upImage, upCatId);

            if (results == "Success")
            {
                errorLabel.Text = "Book Updated to database!";
            }
            else
            {
                errorLabel.Text = results;
            }
        }