protected void btnSave_Click(object sender, EventArgs e)
        {
            dtgridList = (DataTable)ViewState["dtgridList"];
            string users = Session["id"].ToString();
            decimal totalamt = 0;

            try
            {
                foreach (DataRow dr in dtgridList.Rows)
                {
                    totalamt = totalamt + decimal.Parse(dr["Amount"].ToString());
                }
                FrameWork.ProductRequestOrder PRO = new FrameWork.ProductRequestOrder();
                FrameWork.ProductRequestOrderDetails PROsub = new ProductRequestOrderDetails();
                busProductRequestOrder busPRO = new busProductRequestOrder();
                PRO.SupplierID = int.Parse(this.drpSupplier.SelectedValue);
                PRO.CreatedById = int.Parse(users);
                PRO.ExpectedDate = DateTime.Parse(this.txtDateNeeded.Text);
                PRO.PaymentAmount = totalamt;

                string x = busPRO.insertProductRequestOrder(PRO);
                foreach (DataRow dr in dtgridList.Rows)
                {
                    PROsub.ProductRequestOrderID = int.Parse(x);
                    PROsub.Quantity = Single.Parse(dr["Quantity"].ToString());
                    PROsub.UnitCost = decimal.Parse(dr["UnitPrice"].ToString());
                    PROsub.ProductID = int.Parse(dr["ProductID"].ToString());

                    busPRO.insertProductRequestOrderDetails(PROsub);
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                this.txtQuantity.Text = string.Empty;
                this.txtUOM.Text = string.Empty;
                this.drpProduct.SelectedValue = "0";
                //this.lblDescription.Text = string.Empty;
                this.txtUnitPrice.Text = string.Empty;
                this.drpSupplier.SelectedValue = "0";
                //this.txtTerms.Text = string.Empty;
                DataTable ds = (DataTable)ViewState["dtgridList"]; ;
                ds.Clear();
                this.grdList.DataSource = ds;
                grdList.DataBind();

            }
        }
        public string insertProductRequestOrderDetails(ProductRequestOrderDetails prod)
        {
            string Message = string.Empty;
            int result = 0;
            SqlTransaction transaction;
            con.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO [dbo].ProductRequestOrdersDetails ([Quantity],[UnitCost],[ProductRequestOrderID],[ProductID],[IsSubmitted],[PostedToInventory]) VALUES (@Quantity,@UnitCost,@ProductRequestOrderID,@ProductID,@IsSubmitted,@PostedToInventory)", con);

            cmd.Parameters.AddWithValue("@Quantity", prod.Quantity);
            cmd.Parameters.AddWithValue("@UnitCost", prod.UnitCost);
            cmd.Parameters.AddWithValue("@ProductRequestOrderID", prod.ProductRequestOrderID);
            cmd.Parameters.AddWithValue("@ProductID", prod.ProductID);
            cmd.Parameters.AddWithValue("@IsSubmitted", 1);
            cmd.Parameters.AddWithValue("@PostedToInventory", 1);

            transaction = con.BeginTransaction();
            cmd.Transaction = transaction;

            try
            {
                result = cmd.ExecuteNonQuery();
                transaction.Commit();
            }
            catch (Exception ex)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception ex2)
                {
                    // This catch block will handle any errors that may have occurred
                    // on the server that would cause the rollback to fail, such as
                    // a closed connection.
                    Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType());
                    Console.WriteLine("  Message: {0}", ex2.Message);
                }
            }
            con.Close();
            return Message;
        }
        public ProductRequestOrderDetails[] retrieveProductRequestOrderDetails(string ID)
        {
            string query = "SELECT a.[ID] ,[Quantity],[UnitCost],[ProductID],[ProductName]  FROM [dbo].[ProductRequestOrdersDetails] a inner join [dbo].Products b on a.ProductID = b.ID  where ProductRequestOrderID='" + ID + "' order by a.[ID] asc";
            DataTable table = new DataTable();

            table = DataAccess.DBAdapter.GetRecordSet(query);
            ProductRequestOrderDetails[] dec = new ProductRequestOrderDetails[table.Rows.Count];

            for (int i = 0; i < table.Rows.Count; i++)
            {
                dec[i] = new ProductRequestOrderDetails(table.Rows[i]);
            }

            return dec;
        }