Example #1
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        lblEMsg.Visible = false;
        string[] Book;
        Profile pro = new Profile();
        string Author_ID, Publisher_ID, Category_ID, Supplier_ID;
        try
        {
            if (lstbook.SelectedItem.Text == "")
            {
                lblEMsg.Text = "Please select Book ID";
                lblEMsg.Visible = true;
            }
            else
            {
                string sql;

                //Retrieve Author ID.
                sql = "SELECT Author_ID FROM Author WHERE Author_Name = '" + LstAuthor.SelectedItem.Text + "'";
                Author_ID = ReturnData(sql);

                //Retrieve Publisher ID.
                sql = "SELECT Publisher_ID FROM Publisher WHERE Publisher_Name = '" + LstPublisher.SelectedItem.Text + "'";
                Publisher_ID = ReturnData(sql);

                //Retrieve Category ID.
                sql = "SELECT Category_ID FROM Category WHERE Category_Name = '" + LstCategory.SelectedItem.Text + "'";
                Category_ID= ReturnData(sql);

                //Retrieve Supplier ID.
                sql = "SELECT Supplier_ID FROM Supplier WHERE Supplier_Name = '" + LstSupplier.SelectedItem.Text + "'";
                Supplier_ID= ReturnData(sql);

                Book = new string[15];

                Book[0] = lstbook.SelectedItem.Text;
                Book[1] = txtBTitle.Text;
                Book[2] = Author_ID;
                Book[3] = Publisher_ID;
                Book[4] = Category_ID;
                Book[5] = Supplier_ID;
                Book[6] = txtKey.Text;
                Book[7] = txtIsbn.Text;
                Book[8] = txtQuantity.Text;
                Book[9] = txtPrice.Text;
                if (chkStatus.Checked == true)
                {
                    Book[10] = "A";
                }
                else
                {
                    Book[10] = "D";
                }

                bool status;
                status = pro.Books(Book,"UpdateBook");

                if (status == false)
                {
                    lblEMsg.Visible = true;
                    lblEMsg.Text = "Book updation Failed";
                }
                lblEMsg.Visible = true;
                lblEMsg.Text = "Book updated.";

                ReadBook();
                lstbook.Text = "";
                txtBTitle.Text = "";
                LstAuthor.Text = "";
                LstCategory.Text = "";
                LstPublisher.Text = "";
                LstSupplier.Text = "";
                txtKey.Text = "";
                txtIsbn.Text = "";
                txtQuantity.Text = "";
                txtPrice.Text = "";
                chkStatus.Checked = false;
                lblEMsg.Visible = false;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
Example #2
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        lblEMsg.Visible = false;
        string[] Book;
        string Author_ID, Publisher_ID, Category_ID, Supplier_ID;
        try
        {
            string sql;
            SqlDataReader sdr;
            Profile pro = new Profile();

            //Retrieve Author ID.
            sql = "SELECT Author_ID FROM Author WHERE Author_Name = '" + LstAuthor.SelectedItem.Text + "'";
            sdr = pro.ReturnMDetails(sql);
            if (sdr.Read() == true)
            {
                Author_ID = sdr["Author_ID"].ToString().Trim();
            }
            else
            {
                Author_ID = "";
            }
            sdr.Close();

            //Retrieve Publisher ID.
            sql = "SELECT Publisher_ID FROM Publisher WHERE Publisher_Name = '" + LstPublisher.SelectedItem.Text + "'";
            sdr = pro.ReturnMDetails(sql);
            if (sdr.Read() == true)
            {
                Publisher_ID = sdr["Publisher_ID"].ToString().Trim();
            }
            else
            {
                Publisher_ID = "";
            }
            sdr.Close();

            //Retrieve Category ID.
            sql = "SELECT Category_ID FROM Category WHERE Category_Name = '" + LstCategory.SelectedItem.Text + "'";
            sdr = pro.ReturnMDetails(sql);
            if (sdr.Read() == true)
            {
                Category_ID = sdr["Category_ID"].ToString().Trim();
            }
            else
            {
                Category_ID = "";
            }
            sdr.Close();

            //Retrieve Supplier ID.
            sql = "SELECT Supplier_ID FROM Supplier WHERE Supplier_Name = '" + LstSupplier.SelectedItem.Text + "'";
            sdr = pro.ReturnMDetails(sql);
            if (sdr.Read() == true)
            {
                Supplier_ID = sdr["Supplier_ID"].ToString().Trim();
            }
            else
            {
                Supplier_ID= "";
            }
            sdr.Close();

            sql = "SELECT COUNT(*) FROM Book_Master WHERE Book_Title = '" + txtBTitle.Text + "' And Author_ID ='" + Author_ID + "' And Publisher_ID = '" + Publisher_ID + "' And Status = 'A'";
            sdr = pro.ReturnMDetails(sql);

            sdr.Read();
            int RegNo = (int)sdr[0];
            if (RegNo > 0)
            {
                lblEMsg.Text = "Book Name already exists.";
                lblEMsg.Visible = true;
                sdr.Close();
                return;
            }
            else
            {
                Book = new string[15];

                Book[0] = txtBook.Text;
                Book[1] = txtBTitle.Text;
                Book[2] = Author_ID;
                Book[3] = Publisher_ID;
                Book[4] = Category_ID;
                Book[5] = Supplier_ID;
                Book[6] = txtKey.Text;
                Book[7] = txtIsbn.Text;
                Book[8] = txtQuantity.Text;
                Book[9] = txtPrice.Text;
                if (chkStatus.Checked == true)
                {
                    Book[10] = "A";
                }
                else
                {
                    Book[10] = "I";
                }

                bool status;
                status = pro.Books(Book,"AddBook");

                if (status == false)
                {
                    lblEMsg.Visible = true;
                    lblEMsg.Text = "Book creation Failed";
                }
                lblEMsg.Visible = true;
                lblEMsg.Text = "Book added.";
                ReadBook();
                txtBTitle.Text = "";
                LstAuthor.Text = "";
                LstCategory.Text = "";
                LstPublisher.Text = "";
                LstSupplier.Text = "";
                txtKey.Text = "";
                txtIsbn.Text = "";
                txtQuantity.Text = "";
                txtPrice.Text = "";
                chkStatus.Checked = false;
                lblEMsg.Visible = false;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }