protected void GetPurchaseOrderProductListById(string purchaseOrderId)
        {
            PurchaseOrderBLL purchaseOrder = new PurchaseOrderBLL();

            try
            {
                DataTable dt = purchaseOrder.GetPurchaseOrderProductListById(purchaseOrderId, prIDLabel.Text.Trim());

                if (dt.Rows.Count > 0)
                {
                    purchaseOrderProductListGridView.DataSource = dt;
                    purchaseOrderProductListGridView.DataBind();

                    if (purchaseOrderProductListGridView.Rows.Count > 0)
                    {
                        purchaseOrderProductListGridView.UseAccessibleHeader = true;
                        purchaseOrderProductListGridView.HeaderRow.TableSection = TableRowSection.TableHeader;
                    }
                }
                else
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Data Not Found!!!"; msgDetailLabel.Text = "";
                }
            }
            catch (Exception ex)
            {
                msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = ex.Message;
            }
            finally
            {
                purchaseOrder = null;
            }
        }
        protected void GetPurchaseOrderById(string purchaseOrderId)
        {
            PurchaseOrderBLL purchaseOrder = new PurchaseOrderBLL();

            try
            {
                DataTable dt = purchaseOrder.GetPurchaseOrderById(purchaseOrderId);

                if (dt.Rows.Count > 0)
                {
                    orderDateLabel.Text = dt.Rows[0]["OrderDate"].ToString();
                    prIDLabel.Text = dt.Rows[0]["PurchaseRequisitionId"].ToString();
                    prDateLabel.Text = ", " + dt.Rows[0]["PurchaseRequisitionDate"].ToString();
                    warehouseIdLabel.Text = dt.Rows[0]["WarehouseId"].ToString();
                    warehouseNameLabel.Text = dt.Rows[0]["WarehouseName"].ToString();
                    vendorIdLabel.Text = dt.Rows[0]["VendorId"].ToString();
                    vendorNameLabel.Text = dt.Rows[0]["VendorName"].ToString();
                    narrationLabel.Text = dt.Rows[0]["Narration"].ToString();
                    statusLabel.Text = dt.Rows[0]["Status"].ToString();
                    createdByLabel.Text = dt.Rows[0]["CreatedBy"].ToString();
                }
                else
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Data Not Found!!!"; msgDetailLabel.Text = "";
                }
            }
            catch (Exception ex)
            {
                msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = ex.Message;
            }
            finally
            {
                purchaseOrder = null;
            }
        }
        protected void GetPendingOrderList()
        {
            PurchaseOrderBLL purchaseOrder = new PurchaseOrderBLL();

            try
            {
                DataTable dt = purchaseOrder.GetPendingPurchaseOrdersListByWarehouse(warehouseDropDownList.SelectedValue.Trim());

                pendingPurchaseOrderListGridView.DataSource = dt;
                pendingPurchaseOrderListGridView.DataBind();

                if (pendingPurchaseOrderListGridView.Rows.Count > 0)
                {
                    pendingPurchaseOrderListGridView.UseAccessibleHeader = true;
                    pendingPurchaseOrderListGridView.HeaderRow.TableSection = TableRowSection.TableHeader;
                }
                else
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Data Not Found!!!"; msgDetailLabel.Text = "";
                }
            }
            catch (Exception ex)
            {
                msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = ex.Message;
            }
            finally
            {
                purchaseOrder = null;
            }
        }
        protected void orderListButton_Click(object sender, EventArgs e)
        {
            PurchaseOrderBLL purchaseOrder = new PurchaseOrderBLL();

            try
            {
                if (warehouseDropDownList.SelectedValue == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Warehouse Name field is required.";
                }
                else if (fromDateTextBox.Text.Trim() == "" || LumexLibraryManager.ParseAppDate(fromDateTextBox.Text.Trim()) == "False")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Date From field is required.";
                }
                else if (toDateTextBox.Text.Trim() == "" || LumexLibraryManager.ParseAppDate(toDateTextBox.Text.Trim()) == "False")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Date To field is required.";
                }
                else
                {
                    string warehouseId = warehouseDropDownList.SelectedValue.Trim();
                    string fromDate = LumexLibraryManager.ParseAppDate(fromDateTextBox.Text.Trim());
                    string toDate = LumexLibraryManager.ParseAppDate(toDateTextBox.Text.Trim());
                    string status = statusDropDownList.SelectedValue.Trim();

                    DataTable dt = purchaseOrder.GetPurchaseOrdersListByWarehouseDateRangeAndStatus(warehouseId, fromDate, toDate, status);

                    purchaseOrderListGridView.DataSource = dt;
                    purchaseOrderListGridView.DataBind();

                    if (purchaseOrderListGridView.Rows.Count > 0)
                    {
                        purchaseOrderListGridView.UseAccessibleHeader = true;
                        purchaseOrderListGridView.HeaderRow.TableSection = TableRowSection.TableHeader;
                    }
                    else
                    {
                        msgbox.Visible = true; msgTitleLabel.Text = "Data Not Found!!!"; msgDetailLabel.Text = "";
                    }
                }
            }
            catch (Exception ex)
            {
                msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = ex.Message;
            }
            finally
            {
                purchaseOrder = null;
            }
        }
        protected void cancelRequestLinkButton_Click(object sender, EventArgs e)
        {
            PurchaseOrderBLL purchaseOrder = new PurchaseOrderBLL();

            try
            {
                LinkButton lnkBtn = (LinkButton)sender;
                GridViewRow row = (GridViewRow)lnkBtn.NamingContainer;

                purchaseOrder.UpdatePurchaseOrderStatusById(pendingPurchaseOrderListGridView.Rows[row.RowIndex].Cells[0].Text.ToString(), "CP");

                MyAlertBox("alert(\"Purchase Order [" + pendingPurchaseOrderListGridView.Rows[row.RowIndex].Cells[0].Text.ToString() + "] Cancel Request Submitted Successfully.\"); window.location=\"/UI/PurchaseOrder/PurchaseOrderCancelRequestList.aspx\"");
            }
            catch (Exception ex)
            {
                msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = ex.Message;
            }
            finally
            {
                purchaseOrder = null;
            }
        }
        protected void cancelRequestListButton_Click(object sender, EventArgs e)
        {
            PurchaseOrderBLL purchaseOrder = new PurchaseOrderBLL();

            try
            {
                if (warehouseDropDownList.SelectedValue == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Warehouse Name field is required.";
                }
                else
                {
                    string warehouseId = warehouseDropDownList.SelectedValue.Trim();

                    DataTable dt = purchaseOrder.GetPurchaseOrderCancelRequestListByWarehouse(warehouseId);

                    purchaseOrderCancelRequestListGridView.DataSource = dt;
                    purchaseOrderCancelRequestListGridView.DataBind();

                    if (purchaseOrderCancelRequestListGridView.Rows.Count > 0)
                    {
                        purchaseOrderCancelRequestListGridView.UseAccessibleHeader = true;
                        purchaseOrderCancelRequestListGridView.HeaderRow.TableSection = TableRowSection.TableHeader;
                    }
                    else
                    {
                        msgbox.Visible = true; msgTitleLabel.Text = "Data Not Found!!!"; msgDetailLabel.Text = "";
                    }
                }
            }
            catch (Exception ex)
            {
                msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = ex.Message;
            }
            finally
            {
                purchaseOrder = null;
            }
        }
        protected void purchaseOrderDetailsButton_Click(object sender, EventArgs e)
        {
            PurchaseOrderBLL purchaseOrder = new PurchaseOrderBLL();

            try
            {
                if (warehouseDropDownList.SelectedValue == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Warehouse Name field is required.";
                }
                else if (purchaseOrderIdTextBox.Text.Trim() == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Purchase Order ID field is required.";
                }
                else
                {
                    DataTable dt=new DataTable();

                    dt = purchaseOrder.GetPendingPurchaseOrderByIdAndWarehouse(purchaseOrderIdTextBox.Text.Trim(), warehouseDropDownList.SelectedValue.Trim());

                    if (dt.Rows.Count > 0)
                    {
                        prIDLabel.Text = dt.Rows[0]["PurchaseRequisitionId"].ToString();
                        prDateLabel.Text = ", " + dt.Rows[0]["PurchaseRequisitionDate"].ToString();
                        poIDLabel.Text = dt.Rows[0]["PurchaseOrderId"].ToString();
                        poDateLabel.Text = ", " + dt.Rows[0]["OrderDate"].ToString();
                        warehouseIdLabel.Text = dt.Rows[0]["WarehouseId"].ToString();
                        warehouseNameLabel.Text = dt.Rows[0]["WarehouseName"].ToString();
                        LoadVendors();
                        vendorDropDownList.SelectedValue = dt.Rows[0]["VendorId"].ToString();
                      
                        lblVendorID.Text = dt.Rows[0]["VendorId"].ToString();
                        //purchaseOrder.VendorId = dt.Rows[0]["VendorId"].ToString();
                        
                        // vendorNameLabel.Text = dt.Rows[0]["VendorName"].ToString();
                        requisitionNarrationLabel.Text = dt.Rows[0]["Narration"].ToString();

                        dt = purchaseOrder.GetPurchaseOrderProductListById(poIDLabel.Text.Trim(), prIDLabel.Text.Trim());
                        purchaseOrderProductListGridView.DataSource = dt;
                        purchaseOrderProductListGridView.DataBind();

                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            TextBox purchaseQuantityTextBox = (TextBox)purchaseOrderProductListGridView.Rows[i].FindControl("purchaseQuantityTextBox");
                            purchaseQuantityTextBox.Text = dt.Rows[i]["Quantity"].ToString();
                        }

                        orderInfoContainer.Visible = true;
                        saveButton.Enabled = true;
                    }
                    else
                    {
                        orderInfoContainer.Visible = false;
                        saveButton.Enabled = false;
                        msgbox.Visible = true; msgTitleLabel.Text = "Data Not Found!!!"; msgDetailLabel.Text = "";
                    }

                    if (purchaseOrderProductListGridView.Rows.Count > 0)
                    {
                        purchaseOrderProductListGridView.UseAccessibleHeader = true;
                        purchaseOrderProductListGridView.HeaderRow.TableSection = TableRowSection.TableHeader;
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }
            finally
            {
                purchaseOrder = null;
            }
        }