protected void GetProductTransferRecordProductListById(string transferRecordId)
        {
            ProductTransferRecordBLL productTransferRecord = new ProductTransferRecordBLL();

            try
            {
                DataTable dt = productTransferRecord.GetProductTransferRecordProductListById(transferRecordId);

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

                    if (transferRecordProductListGridView.Rows.Count > 0)
                    {
                        transferRecordProductListGridView.UseAccessibleHeader = true;
                        transferRecordProductListGridView.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
            {
                productTransferRecord = null;
            }
        }
        public string SaveProductTransferRecord(ProductTransferRecordBLL productTransferRecord, DataTable dtPrdList, LumexDBPlayer db)
        {
            string transferRecordId = "";

            try
            {
                db.AddParameters("@TransferOrderId", productTransferRecord.TransferOrderId.Trim());
                db.AddParameters("@TransferFrom", productTransferRecord.TransferFrom.Trim());
                db.AddParameters("@TransferTo", productTransferRecord.TransferTo.Trim());
                db.AddParameters("@TransferType", productTransferRecord.TransferType.Trim());
                db.AddParameters("@Description", productTransferRecord.Description.Trim());
                db.AddParameters("@CreatedBy", LumexSessionManager.Get("ActiveUserId").ToString());
                db.AddParameters("@CreatedFrom", LumexLibraryManager.GetTerminal());

                DataTable dt = db.ExecuteDataTable("INSERT_PRODUCT_TRANSFER_RECORD", true);

                if (dt.Rows.Count > 0)
                {
                    transferRecordId = dt.Rows[0][0].ToString();
                }

                for (int i = 0; i < dtPrdList.Rows.Count; i++)
                {
                    db.ClearParameters();
                    db.AddParameters("@TransferRecordId", transferRecordId.Trim());
                    db.AddParameters("@ProductId", dtPrdList.Rows[i]["ProductId"].ToString());
                    db.AddParameters("@ReceivedQuantity", dtPrdList.Rows[i]["ReceivedQuantity"].ToString());
                    db.AddParameters("@DisappearedQuantity", dtPrdList.Rows[i]["DisappearedQuantity"].ToString());
                    db.AddParameters("@Status", dtPrdList.Rows[i]["Status"].ToString());
                    db.AddParameters("@Narration", dtPrdList.Rows[i]["Narration"].ToString());

                    db.ExecuteNonQuery("INSERT_PRODUCT_TRANSFER_RECORD_PRODUCT", true);
                }

                db.ClearParameters();
                db.AddParameters("@TransferOrderId", productTransferRecord.TransferOrderId.Trim());
                db.AddParameters("@Status", productTransferRecord.Status.Trim());
                db.AddParameters("@CanceledBy", "");
                db.AddParameters("@CanceledFrom", "");

                db.ExecuteNonQuery("UPDATE_PRODUCT_TRANSFER_ORDER_STATUS_BY_ID", true);

                return transferRecordId;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                productTransferRecord = null;
            }
        }
        protected void GetProductTransferRecordById(string transferRecordId)
        {
            ProductTransferRecordBLL productTransferRecord = new ProductTransferRecordBLL();

            try
            {
                DataTable dt = productTransferRecord.GetProductTransferRecordById(transferRecordId);

                if (dt.Rows.Count > 0)
                {
                    receivedDateLabel.Text = dt.Rows[0]["ReceivedDate"].ToString();
                    recordStatusLabel.Text = dt.Rows[0]["RecordStatus"].ToString();
                    orderIdLabel.Text = dt.Rows[0]["TransferOrderId"].ToString();
                    orderDateLabel.Text = dt.Rows[0]["OrderDate"].ToString();
                    transferTypeLabel.Text = dt.Rows[0]["TransferType"].ToString();
                    transferFromIdLabel.Text = dt.Rows[0]["TransferFrom"].ToString();
                    transferFromNameLabel.Text = dt.Rows[0]["TransferFromName"].ToString();
                    transferToIdLabel.Text = dt.Rows[0]["TransferTo"].ToString();
                    transferToNameLabel.Text = dt.Rows[0]["TransferToName"].ToString();
                    requisitionIdLabel.Text = dt.Rows[0]["RequisitionId"].ToString();
                    requisitionDateLabel.Text = dt.Rows[0]["RequisitionDate"].ToString();
                    transportDateLabel.Text = dt.Rows[0]["TransportDate"].ToString();
                    descriptionLabel.Text = dt.Rows[0]["Description"].ToString();
                    narrationLabel.Text = dt.Rows[0]["Narration"].ToString();
                    statusLabel.Text = dt.Rows[0]["Status"].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
            {
                productTransferRecord = null;
            }
        }
        public DataTable GetProductTransferRecordsListByTransferDescriptionTypeFromToDateRangeAndStatus(ProductTransferRecordBLL productTransferRecord, LumexDBPlayer db)
        {
            try
            {
                db.AddParameters("@TransferDescription", productTransferRecord.Description.Trim());
                db.AddParameters("@TransferType", productTransferRecord.TransferType.Trim());
                db.AddParameters("@TransferTo", productTransferRecord.TransferTo.Trim());
                db.AddParameters("@FromDate", productTransferRecord.FromDate.Trim());
                db.AddParameters("@ToDate", productTransferRecord.ToDate.Trim());
                db.AddParameters("@Status", productTransferRecord.Status.Trim());

                DataTable dt = db.ExecuteDataTable("GET_PRODUCT_TRANSFER_RECORDS_BY_TRANSFER_DESCRIPTION_TYPE_FROM_TO_DATE_RANGE_AND_STATUS", true);

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                productTransferRecord = null;
            }
        }
        protected void saveButton_Click(object sender, EventArgs e)
        {
            ProductTransferRecordBLL productTransferRecord = new ProductTransferRecordBLL();

            string msg = string.Empty;
            TextBox receivedQuantityTextBox;
            TextBox disappearedQuantityTextBox;
            TextBox narrationTextBox;
            int rQty;
            int dQty;
            int pNClCount = 0;

            DataTable dt = new DataTable();
            DataRow dr = null;

            dt.Columns.Add("ProductId");
            dt.Columns.Add("OrderQuantity");
            dt.Columns.Add("ReceivedQuantity");
            dt.Columns.Add("DisappearedQuantity");
            dt.Columns.Add("Narration");
            dt.Columns.Add("Status");

            try
            {
                for (int i = 0; i < productTransferOrderProductListGridView.Rows.Count; i++)
                {
                    receivedQuantityTextBox = (TextBox)productTransferOrderProductListGridView.Rows[i].FindControl("receivedQuantityTextBox");
                    disappearedQuantityTextBox = (TextBox)productTransferOrderProductListGridView.Rows[i].FindControl("disappearedQuantityTextBox");
                    narrationTextBox = (TextBox)productTransferOrderProductListGridView.Rows[i].FindControl("narrationTextBox");
                    string[] oQty = productTransferOrderProductListGridView.Rows[i].Cells[2].Text.Trim().Split(' ');

                    if (!int.TryParse(receivedQuantityTextBox.Text.Trim(), out rQty))
                    {
                        msg = "Product ID [" + productTransferOrderProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid Received Quantity.";
                        msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else if (!int.TryParse(disappearedQuantityTextBox.Text.Trim(), out dQty))
                    {
                        msg = "Product ID [" + productTransferOrderProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid Disappeared Quantity.";
                        msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else if (disappearedQuantityTextBox.Text.Trim() != "0" && string.IsNullOrEmpty(narrationTextBox.Text.Trim()))
                    {
                        msg = "Narration field is required for Product ID [" + productTransferOrderProductListGridView.Rows[i].Cells[0].Text.ToString() + "]";
                        msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else
                    {
                        dr = dt.NewRow();

                        dr["ProductId"] = productTransferOrderProductListGridView.Rows[i].Cells[0].Text.ToString();
                        dr["OrderQuantity"] = oQty[0].ToString().Trim();
                        dr["ReceivedQuantity"] = receivedQuantityTextBox.Text.Trim();
                        dr["DisappearedQuantity"] = disappearedQuantityTextBox.Text.Trim();
                        dr["Narration"] = narrationTextBox.Text.Trim();

                        if (disappearedQuantityTextBox.Text.Trim() == "0")
                        {
                            dr["Status"] = "Cl";
                        }
                        else
                        {
                            dr["Status"] = "NCl"; pNClCount++;
                        }

                        dt.Rows.Add(dr);
                    }
                }

                if (dt.Rows.Count == productTransferOrderProductListGridView.Rows.Count)
                {
                    productTransferRecord.TransferOrderId = orderIdLabel.Text.Trim();
                    productTransferRecord.TransferFrom = transferFromIdLabel.Text.Trim();
                    productTransferRecord.TransferTo = transferToIdLabel.Text.Trim();
                    productTransferRecord.TransferType = transferTypeLabel.Text.Trim();
                    productTransferRecord.Description = descriptionLabel.Text.Trim();

                    if (pNClCount > 0)
                    {
                        productTransferRecord.Status = "PD";
                    }
                    else
                    {
                        productTransferRecord.Status = "D";
                    }

                    string id = productTransferRecord.SaveProductTransferRecord(dt);

                    if (!string.IsNullOrEmpty(id))
                    {
                        MyAlertBox("alert(\"Product Transfer Record Created Successfully with Transfer Record ID: " + id + " \"); window.location=\"/UI/ProductTransferRecord/TransferRecordList.aspx\"");
                    }
                    else
                    {
                        msgbox.Visible = true; msgTitleLabel.Text = "Failed to Create Product Transfer Record!!!"; msgDetailLabel.Text = "";
                    }
                }
            }
            catch (Exception ex)
            {
                msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = ex.Message;
            }
            finally
            {
                productTransferRecord = null;
            }
        }
        protected void recordListButton_Click(object sender, EventArgs e)
        {
            ProductTransferRecordBLL productTransferRecord = new ProductTransferRecordBLL();

            try
            {
                if (transferTypeDropDownList.SelectedValue == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Transfer Type field is required.";
                }
                else if (transferToDropDownList.SelectedValue == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Transfer To field is required.";
                }
                else
                {
                    productTransferRecord.Description = transferDescriptionDropDownList.SelectedValue.Trim();
                    productTransferRecord.TransferType = transferTypeDropDownList.SelectedValue.Trim();
                    productTransferRecord.TransferTo = transferToDropDownList.SelectedValue.Trim();
                    productTransferRecord.FromDate = LumexLibraryManager.ParseAppDate(fromDateTextBox.Text.Trim());
                    productTransferRecord.ToDate = LumexLibraryManager.ParseAppDate(toDateTextBox.Text.Trim());
                    productTransferRecord.Status = statusDropDownList.SelectedValue.Trim();

                    DataTable dt = productTransferRecord.GetProductTransferRecordsListByTransferDescriptionTypeFromToDateRangeAndStatus();

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

                    if (transferRecordListGridView.Rows.Count > 0)
                    {
                        transferRecordListGridView.UseAccessibleHeader = true;
                        transferRecordListGridView.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
            {
                productTransferRecord = null;
            }
        }
        public void ApproveProductTransferRecord(ProductTransferRecordBLL productTransferRecord, LumexDBPlayer db)
        {
            try
            {
                db.AddParameters("@TransferRecordId", productTransferRecord.TransferRecordId.Trim());
                db.AddParameters("@Description", productTransferRecord.Description.Trim());
                db.AddParameters("@TransferType", productTransferRecord.TransferType.Trim());
                db.AddParameters("@TransferTo", productTransferRecord.TransferTo.Trim());
                db.AddParameters("@ApprovedBy", LumexSessionManager.Get("ActiveUserId").ToString());
                db.AddParameters("@ApprovedFrom", LumexLibraryManager.GetTerminal());

                db.ExecuteNonQuery("APPROVE_PRODUCT_TRANSFER_RECORD", true);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                productTransferRecord = null;
            }
        }
        protected void GetApprovalList()
        {
            ProductTransferRecordBLL productTransferRecord = new ProductTransferRecordBLL();

            try
            {
                if (transferTypeDropDownList.SelectedValue == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Transfer Type field is required.";
                }
                else if (transferToDropDownList.SelectedValue == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Transfer To field is required.";
                }
                else
                {
                    productTransferRecord.Description = transferDescriptionDropDownList.SelectedValue.Trim();
                    productTransferRecord.TransferType = transferTypeDropDownList.SelectedValue.Trim();
                    productTransferRecord.TransferTo = transferToDropDownList.SelectedValue.Trim();
                    productTransferRecord.Status = "P";

                    DataTable dt = productTransferRecord.GetProductTransferRecordsListByTransferDescriptionTypeFromToAndStatus();

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

                    if (transferRecordListGridView.Rows.Count > 0)
                    {
                        transferRecordListGridView.UseAccessibleHeader = true;
                        transferRecordListGridView.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
            {
                productTransferRecord = null;
            }
        }
        protected void approveButton_Click(object sender, EventArgs e)
        {
            ProductTransferRecordBLL productTransferRecord = new ProductTransferRecordBLL();

            try
            {
                productTransferRecord.TransferRecordId = idLabel.Text.Trim();
                productTransferRecord.Description = descriptionLabel.Text.Trim();
                productTransferRecord.TransferType = transferTypeLabel.Text.Trim();
                productTransferRecord.TransferTo = transferToIdLabel.Text.Trim();

                productTransferRecord.ApproveProductTransferRecord();

                MyAlertBox("alert(\"Product Transfer Record Approved Successfully.\"); window.location=\"/UI/ProductTransferRecord/TransferRecordApprovalList.aspx\"");
            }
            catch (Exception ex)
            {
                msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = ex.Message;
            }
            finally
            {
                productTransferRecord = null;
            }
        }