public void LoadPopInfobyLoadIdForProduct(int loadid)
    {
        Loads loadobj = new Loads(loadid);
        int LoadTypeId = loadobj.LoadTypeId;
        lblLoadType.Text = loadobj.LookUpTypeName;
        hdnlotid.Value = loadid.ToString();
        lblProductCount.Text = Convert.ToString(Loads.getCountLoadByLoadId(loadid));
        lblHauerName.Text = loadobj.HaulerOrganization;
        lblTransferName.Text = loadobj.TransferOrganization;

        DataSet ds = Loads.getProductInfoByLoadId(loadid, CatId);
        gvLoadProductInfo.DataSource = ds;
        gvLoadProductInfo.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        /*       AddNew Lot Method On Load,In this Automaticaly New Lot created and Tires Add on this Lot               */
        lblErrorSuccessInventory.Visible = false;


        if (!IsPostBack)
        {
            GetPermission(ResourceType.AddInventoryInventory, ref canView, ref canAdd, ref canUpdate, ref canDelete);
            if (!canView)
            {
                Response.Redirect("error");
            }

            if (CatId == (int)ProductCategory.Tire)
            {
                dvInventoryAdd.Visible = true;
            }
            else
            {
                dvProducts.Visible = true;
                RequiredFieldValidator rfv = rfvSubCategory;
                DataSet Check = Product.GetAllSubCategories(CatId);
                if (Check != null && Check.Tables[0].Rows.Count > 0)
                {
                    dvSubCategory.Visible = true;
                    Utils.GetLookUpData<DropDownList>(ref ddlSubCategory, LookUps.SelectedSubCategory, CatId, UserOrganizationId);


                    rfv.Enabled = true;


                    ddlMaterial.Enabled = false;
                    ddlShape.Enabled = false;
                    ddlSize.Enabled = false;
                    ddlBrand.Enabled = false;

                }
                else
                {
                    Utils.GetProductProperties<DropDownList>(ref ddlMaterial, LookUps.ProductMaterial, CatId, LanguageId);
                    Utils.GetProductProperties<DropDownList>(ref ddlShape, LookUps.ProductShape, CatId, LanguageId);
                    Utils.GetProductProperties<DropDownList>(ref ddlSize, LookUps.ProductSize, CatId, LanguageId);
                    Utils.GetProductProperties<DropDownList>(ref ddlBrand, LookUps.ProductBrand, CatId, LanguageId);
                }

            }

            if (Request.QueryString["LoadId"] != null)
            {
                Loads ObjLoad = new Loads(Conversion.ParseInt(Request.QueryString["LoadId"]));

                lblLotNumber.Text = "Load# " + ObjLoad.LoadNumber;
                lblProductLot.Text = "Load " + ObjLoad.LoadNumber;
                imgProductLot.ImageUrl = String.Format("/images/temp/{0}.Gif", ObjLoad.Guid);
                imgLotBarcode.ImageUrl = String.Format("/images/temp/{0}.Gif", ObjLoad.Guid);
                imgLotBarcode.Visible = true;
                imgProductLot.Visible = true;

            }
            else
            {
                AddNewLOT();
            }

            string OrgName = string.Empty;
            OrgName = OrganizationInfo.GetOrgLegalNameByOrgId(UserInfo.GetCurrentUserInfo().OrganizationId);
            txtQuantity.Text = "0";

            ClientScript.RegisterStartupScript(GetType(), "SetHeaderMenu", String.Format("SetHeaderMenu('liInventory','{0}');", ResourceMgr.GetMessage("Inventory" + " " + OrgName)), true);
            lblCBarcodeText.Text = OrgName + " Barcode";
            if (User.Identity.IsAuthenticated == false)
            {
                Response.Redirect("/");
            }

            //txtQuantity.Text = "0";
            //dvLot.Visible = false;
            ////txtCompanyName.Text = UserInfo.GetCurrentUserInfo().FullName;
            ////txtCompanyName.Enabled = false;
            //txtdate.Text = DateTime.Today.ToString("MM/dd/yyyy");

            //if (Request.QueryString["p"] == null)
            //{
            //    Session["Tire"] = "";
            //    Session["SubLotTireIds"] = "";
            //    Session["SelectedLotId"] = "";
            //    Load_AllAdminInventory();

            //    if (Request.QueryString["lotId"] != null)
            //    {
            //        dvLot.Visible = false;
            //        dvInventoryAdd.Visible = true;
            //        dvLotOption.Visible = false;
            //        dvLot1.Visible = false;
            //    }
            //}
            //else if (Convert.ToString(Session["Tire"]) == "1")
            //{
            //    Load_TireInventory(CurPageNum);
            //    chkSublot.Checked = true;
            //    Check_Clicked(null, null);
            //}
            //else
            //{
            //    Load_AllAdminInventory();
            //    chkSublot.Checked = true;
            //    Check_Clicked(null, null);

            //    dvLot.Visible = true;
            //    dvLotOption.Visible = false;
            //    dvLot.Visible = true;

            //}




            ddlTireState.DataSource = Tire.getTireStateCategory();
            ddlTireState.DataBind();
            //Utils.GetLookUpData<DropDownList>(ref ddlTireClass, LookUps.LoadInventoryClass);
            //ddlTireClass.SelectedIndex = 1;

            //Utils.GetLookUpData<DropDownList>(ref ddlTireState, LookUps.LoadInventoryAction);
            //ddlTireState.SelectedIndex = 1;
            //Utils.GetLookUpData<DropDownList>(ref ddlRecycleState, LookUps.LoadInventoryOutcome);
            //ddlRecycleState.SelectedIndex = 1;
            Utils.GetLookUpData<DropDownList>(ref ddlTireClass, LookUps.LoadInventoryClass);
            Utils.GetLookUpData<DropDownList>(ref ddlTireState, LookUps.LoadInventoryAction);
            Utils.GetLookUpData<DropDownList>(ref ddlRecycleState, LookUps.LoadInventoryOutcome);
            ddlTireState.SelectedIndex = 1;
            ddlTireClass.SelectedIndex = 1;
            ddlRecycleState.SelectedIndex = 1;

            //commented by bilal LoadTireStateType();
            lnkMultiple_Click(null, null);

            //ddlTireState.Items.Insert(0, new ListItem(ResourceMgr.GetMessage("Select"), "0"));
            if (Request.QueryString["OpenLotId"] != null)
            {
                hidLotId.Value = Request.QueryString["OpenLotId"].ToString();
                DataSet ds = Lots.getBarcodeByLotId(Convert.ToInt32(hidLotId.Value));
                //lblLotNumber.Visible = true;
                lblLotNumber.Text = "Lot# " + ds.Tables[0].Rows[0][1].ToString();

                imgLotBarcode.Visible = true;
                imgLotBarcode.ImageUrl = "/Handlers/GetBarcodeImage.ashx?LotID=" + Request.QueryString["OpenLotId"];
                imgProductLot.ImageUrl = "/Handlers/GetBarcodeImage.ashx?LotID=" + Request.QueryString["OpenLotId"];
                lblProductLot.Text = "Lot# " + ds.Tables[0].Rows[0][1].ToString();
                if (CatId == (int)ProductCategory.Tire)
                {
                    dvInventoryAdd.Visible = true;
                    gvAllTire.DataSource = Tire.getCompleteTireInfo_ByLotID(Conversion.ParseInt(Request.QueryString["OpenLotId"]));
                    gvAllTire.DataBind();
                }
                else
                {
                    dvInventoryAdd.Visible = false;
                    gvProduct.DataSource = Product.GetAllProductsByLotId(Conversion.ParseInt(Request.QueryString["OpenLotId"]));
                    gvProduct.DataBind();
                }
            }
        }

    }
    protected void lnkbtnAddInventory_Click(object sender, EventArgs e)
    {
        try
        {
            if (Session["SelectedLotId"] == "")
            {
                lblLotError.Text = "Please Select Any Lot!.";
                return;
            }
            else
                lblLotError.Text = string.Empty;

            StringBuilder str = new StringBuilder(255);
            if ((int)ProductCategory.Tire == CatId)
            {
                str.Append(Conversion.ParseString(Session["SelectedTiresId"]));
            }
            else
            {
                str.Append(Conversion.ParseString(Session["SelectedProductId"]));
            }

            if (str.ToString()[0] == ',')
            {
                str = str.Remove(0, 1);
            }


            //yahan sy 
            string[] arr = str.ToString().Split(',');
            arr = arr.Distinct().ToArray();
            List<string> LotIds = new List<string>();
            foreach (string st in arr)
            {
                string[] arrLot = st.Split(',');
                if (!LotIds.Contains(arrLot[0]))
                {
                    LotIds.Add(arrLot[0]);
                }
            }
            //StringBuilder tireIds = new StringBuilder(255);
            //List<string> TireIds = new List<string>();
            // string[] LotTires = new string[2];

            foreach (string lotid in LotIds)
            {
                int count = 0;
                tireids = "";
                foreach (string id in arr)
                {
                    string[] bothids = id.Split(',');
                    if (bothids[0] == lotid)
                    {
                        if (count == 0)
                        {

                            tireids += bothids[count];
                        }
                        else
                        {
                            tireids += "," + bothids[count];
                        }
                        count++;
                    }
                }

                //yaha tak
                string testtireids = tireids;
                if (string.IsNullOrEmpty(tireids.ToString()))
                {
                    if (CatId == (int)ProductCategory.Tire)
                    {
                        lblTireError.Text = "Please Select Any Tire!.";
                    }
                    else
                    {
                        lblProductError.Text = "Please Select Any Product!.";
                    }

                    return;
                }
                else
                {
                    lblTireError.Text = string.Empty;
                    DataSet ds = null;
                    string ExistingPteTireIds = null;
                    int stateid = OrganizationInfo.getStateId(UserOrganizationId);
                    int organizaionsubtypeid = new OrganizationInfo(UserOrganizationId).OrganizationSubTypeID;
                    string SelectedTiresIds = string.Join(",", arr);
                    if (CatId == (int)ProductCategory.Tire)
                    {
                        ds = Loads.GetPteByTireId(stateid, organizaionsubtypeid, SelectedTiresIds);
                    }
                    else
                    {
                        ds = Loads.GetPteByProductId(stateid, organizaionsubtypeid, SelectedTiresIds, CatId);
                    }


                    foreach (DataRow row in ds.Tables[0].Rows)
                        ExistingPteTireIds += row["ProductId"].ToString() + ",";
                    if (ExistingPteTireIds != null)
                        ExistingPteTireIds = ExistingPteTireIds.Remove(ExistingPteTireIds.Length - 1);
                    //string ExistingPteTireIdsString = string.Join(",", TireIdsForExistingPTE.Select(n => n.ToString()).ToArray());
                    string ExistingPteTireIdsString = string.Join(",", ExistingPteTireIds);
                    string[] NONExistingPteTireIds = SelectedTiresIds.Split(new char[] { ',' }).Except(ExistingPteTireIdsString.Split(new char[] { ',' })).ToArray();
                    NONExistingPteTireIdsString = string.Join(",", NONExistingPteTireIds);
                }

                string tired = Conversion.ParseString(Session["SelectedTiresId"]);
                Loads.AddLoadTires(Convert.ToInt32(Session["loadId"]), tireids, LoginMemberId);
            }
            Loads loadobj = new Loads(Convert.ToInt32(Session["loadId"]));
            if (loadobj.LoadTypeId == 75)
            {
                SendNotification(Convert.ToInt32(Session["loadId"]));
            }

            Response.Redirect("inventory-load", true);

            //if (NONExistingPteTireIdsString != null && NONExistingPteTireIdsString.Length > 0)
            //{

            //    //DataSet dset = null;
            //    //if (CatId == (int)ProductCategory.Tire)
            //    //{
            //    //    dvPteNotDefined.Visible = true;
            //    //    dset = Tire.getSizecodeForTireIds(NONExistingPteTireIdsString);
            //    //    gvSizeCodes.DataSource = dset;
            //    //    gvSizeCodes.DataBind();
            //    //}
            //    //else
            //    //{
            //    //    dvPteNotDefinedProduct.Visible = true;
            //    //    dset = Product.getSizecodeForProductIds(NONExistingPteTireIdsString);
            //    //    gvSizeCodesProduct.DataSource = dset;
            //    //    gvSizeCodesProduct.DataBind();

            //    //    Response.Redirect("inventory-load", true);
            //    //}


            //}
            //else
                

        }
        catch (Exception ex)
        {
            new SqlLog().InsertSqlLog(0, "createload.lnkbtnAddInventory_Click", ex);
        }
    }
    private void SendNotificationForReject(int LoadId)
    {

        Loads loadObject = new Loads(LoadId);

        Notifications objNotifications = new Notifications();
        objNotifications.BitIsActive = true;
        objNotifications.BitIsReaded = false;
        objNotifications.DtmDateCreated = DateTime.Now;
        objNotifications.DtmDateReaded = DateTime.MinValue;
        objNotifications.IntFromOrganizationId = UserOrganizationId;
        objNotifications.IntFromUserId = 0;
        objNotifications.IntNotificationId = 0;
        objNotifications.IntParentNotificationId = 0;
        objNotifications.IntSourceId = 0;
        objNotifications.IntToOrganizationId = loadObject.OrganizationId;
        objNotifications.IntToUserId = 0;
        objNotifications.VchNotificationText = "Load " + loadObject.LoadNumber + "that sent from " + loadObject.TransferOrganization + " to " + loadObject.HaulerOrganization + " Rejected because " + txtNotes.Text.Trim();
        objNotifications.InsertUpdate();
    }
    private void SendNotification(int LoadId)
    {

        Loads loadObject = new Loads(LoadId);

        Notifications objNotifications = new Notifications();
        objNotifications.BitIsActive = true;
        objNotifications.BitIsReaded = false;
        objNotifications.DtmDateCreated = DateTime.Now;
        objNotifications.DtmDateReaded = DateTime.MinValue;
        objNotifications.IntFromOrganizationId = UserOrganizationId;
        objNotifications.IntFromUserId = 0;
        objNotifications.IntNotificationId = 0;
        objNotifications.IntParentNotificationId = 0;
        objNotifications.IntSourceId = 0;
        objNotifications.IntToOrganizationId = Conversion.ParseInt(hidOrgID.Value);
        objNotifications.IntToUserId = 0;
        objNotifications.VchNotificationText = "Load  " + txtLoadnumber.Text.Trim() + "  Ship From  " + loadObject.TransferOrganization + " To " + loadObject.HaulerOrganization + " .";
        objNotifications.InsertUpdate();
    }
    protected void SetShipLoadInfo()
    {
        try
        {



            divLoads.Visible = true;
            dvLoadOption.Visible = false;

            lnkAccept.Visible = true;
            lnkReject.Visible = true;
            //txtquantity.Enabled = false;
            Loads load = new Loads(Convert.ToInt32(Request.QueryString["loadId"]));
            txtLoadnumber.Text = load.LoadNumber.ToString();
            txtLoadnumber.ReadOnly = true;
            txtquantity.Text = load.Quantity.ToString();
            txtquantity.ReadOnly = true;
            txtponumber.Text = load.POnumber.ToString();
            txtponumber.ReadOnly = true;
            txtinvoicenumber.Text = load.InvoiceNumber.ToString();
            txtinvoicenumber.ReadOnly = true;
            txtsealnumber.Text = load.SealNumber.ToString();
            txtsealnumber.ReadOnly = true;
            txtsealnumber.Text = load.TrailerNumber.ToString();
            txtsealnumber.ReadOnly = true;
            txtweight.Text = load.Weight.ToString();
            txtweight.ReadOnly = true;
            txtladingnumber.Text = load.BillOfLandingNumber.ToString();
            txtladingnumber.ReadOnly = true;
            txttrailernumber.Text = load.TrailerNumber.ToString();
            txttrailernumber.ReadOnly = true;
            txthauleridnumber.Text = new OrganizationInfo(load.HaulerIDNumber).LegalName;
            txthauleridnumber.ReadOnly = true;

            lnkbtnAddCreateLoad.Visible = false;

        }
        catch (Exception ex)
        {
            new SqlLog().InsertSqlLog(0, "CreateLoad.aspx SetShipLoadInfo()", ex);
        }
    }
    private void LoadEditInfoOnLoadPage()
    {
        int loadid = Conversion.ParseInt(Request.QueryString["LoadId"]);

        Loads objLoad = new Loads(loadid);
        Utils.GetLookUpData<DropDownList>(ref ddlLoadType, LookUps.LoadType);
        ddlLoadType.SelectedValue = objLoad.LoadTypeId.ToString();

        if (objLoad.LoadTypeId == 73 || objLoad.LoadTypeId == 75)
        {

            BarCode objBarCode = new BarCode(objLoad.BarcodeId);




            txtCompanyName.Text = UserInfo.GetCurrentUserInfo().FullName;
            txtLoadnumber.Text = objLoad.LoadNumber;
            hidOrgID.Value = objLoad.HaulerIDNumber.ToString();
            txtponumber.Text = objLoad.POnumber;
            txtinvoicenumber.Text = objLoad.InvoiceNumber;
            txtsealnumber.Text = objLoad.SealNumber;
            txttrailernumber.Text = objLoad.TrailerNumber;
            txthauleridnumber.Text = objLoad.HaulerOrganization;
            txtweight.Text = objLoad.Weight;
            txtladingnumber.Text = objLoad.BillOfLandingNumber;

            hdnLotBarCodeImageFileName.Value = objBarCode.BarCodeNumber + ".gif";
            imgLotBarcode.ImageUrl = String.Format("/images/temp/{0}.Gif", objBarCode.BarCodeNumber);
            imgLotBarcode.Visible = true;
        }
        else if (objLoad.LoadTypeId == 72)
        {
            BarCode objBarCode = new BarCode(objLoad.BarcodeId);

            pnlControls.Visible = false;
            pnlDropDowns.Visible = true;
            BindddlFacility();


            BindddlLane();
            txtCompanyName.Text = UserInfo.GetCurrentUserInfo().FullName;
            ddlFacility.SelectedValue = objLoad.FacilityId.ToString();
            BindddlLots();
            ddlLot.SelectedValue = objLoad.LotID.ToString();
            BindddlSpace();
            ddlSpace.SelectedValue = objLoad.SpaceId.ToString();
            BindddlLane();
            ddlLane.SelectedValue = objLoad.Lane;

            hdnLotBarCodeImageFileName.Value = objBarCode.BarCodeNumber + ".gif";
            imgLoadBarCodeTransfer.ImageUrl = String.Format("/images/temp/{0}.Gif", objBarCode.BarCodeNumber);
            imgLoadBarCodeTransfer.Visible = true;

        }
        else
        {
            BarCode objBarCode = new BarCode(objLoad.BarcodeId);

            pnlControls.Visible = true;
            pnlDropDowns.Visible = false;
            dvSearchHauler1.Visible = false;
            txtCompanyName.Text = UserInfo.GetCurrentUserInfo().FullName;
            txtLoadnumber.Text = objLoad.LoadNumber;

            txtponumber.Text = objLoad.POnumber;
            txtinvoicenumber.Text = objLoad.InvoiceNumber;
            txtsealnumber.Text = objLoad.SealNumber;
            txttrailernumber.Text = objLoad.TrailerNumber;
            txthauleridnumber.Text = objLoad.HaulerOrganization;
            txtweight.Text = objLoad.Weight;
            txtladingnumber.Text = objLoad.BillOfLandingNumber;

            hdnLotBarCodeImageFileName.Value = objBarCode.BarCodeNumber + ".gif";
            imgLotBarcode.ImageUrl = String.Format("/images/temp/{0}.Gif", objBarCode.BarCodeNumber);
            imgLotBarcode.Visible = true;
            hidOrgID.Value = objLoad.HaulerIDNumber.ToString();

        }

    }
    protected void lnkbtnAddCreateLoad_Click(object sender, EventArgs e)
    {
        int loadid = Conversion.ParseInt(Request.QueryString["LoadId"]);

            Loads objLoad = new Loads(loadid);
            BarCode objBarCode = new BarCode(objLoad.BarcodeId);
        if (ddlLoadType.SelectedValue == "74")
        {
            dvSearchHauler1.Visible = false;
            rfvHaul.Enabled = false;

            lblerrorPONumber.Text = string.Empty;
            lblErrorInvoiceNumber.Text = string.Empty;
            if (txtponumber.Text.Trim().ToString() == txtsealnumber.Text.Trim().ToString())
            {
                if (txtinvoicenumber.Text.Trim().ToString() == txtladingnumber.Text.Trim().ToString())
                {
                    lblerrorPONumber.Text = "PO Number Seal Number are Same. !";
                    //  lblerrorPONumber.Text = string.Empty;
                    lblErrorInvoiceNumber.Text = "Invoice Number Bill Of Lading Number are Same. !";
                }
                else
                {
                    lblerrorPONumber.Text = "PO Number Seal Number are Same. !";
                }


            }
            else
            {
                lblerrorPONumber.Text = string.Empty;

                if (txtinvoicenumber.Text.Trim().ToString() == txtladingnumber.Text.Trim().ToString())
                {
                    lblErrorInvoiceNumber.Text = "Invoice Number Bill Of Lading Number are Same. !";
                }
                else
                {
                    lblErrorInvoiceNumber.Text = string.Empty;

                    //BarCode br = new BarCode();
                    //br.DateCreated = DateTime.Now.ToShortDateString();
                    //br.OrganizationID = UserOrganizationId;
                    //br.BarCodeNumber = GenerateLotSerialNumber();

                    //// Guid g = Guid.NewGuid();
                    //string str = br.BarCodeNumber.ToString().Replace("-", "");
                    //if (br.GenerateLotBarCodeImage(str))
                    //{
                    //    hdnLotBarCodeImageFileName.Value = str + ".gif";
                    //    imgLotBarcode.ImageUrl = String.Format("/images/temp/{0}.Gif", str);
                    //    imgLotBarcode.Visible = true;
                    //    //txtBrand.Focus();
                    //}
                    //if (System.IO.File.Exists(Server.MapPath(String.Format("/images/temp/{0}", hdnLotBarCodeImageFileName.Value))))
                    //{
                    //    br.Image = System.IO.File.ReadAllBytes(Server.MapPath(String.Format("/images/temp/{0}", hdnLotBarCodeImageFileName.Value)));

                    //}

                    
                    //lnkContinue.Visible = true;
                    //int barcodeId = BarCode.Insert(br);
                    //int loadId = 0;
                    Loads.updateRecieveLoad(loadid, Conversion.ParseInt(ddlLoadType.SelectedValue),txtponumber.Text, txtinvoicenumber.Text, txtsealnumber.Text, txttrailernumber.Text, txtweight.Text, txtladingnumber.Text, UserOrganizationId,LoginMemberId, objLoad.BarcodeId, objBarCode.BarCodeNumber, txtLoadnumber.Text);
                   
                    Response.Redirect("inventory-load");



                }
            }

        }
        else if (ddlLoadType.SelectedValue == "73" || ddlLoadType.SelectedValue == "75")
        {


            dvSearchHauler1.Visible = true;
            rfvHaul.Enabled = true;
            lblerrorPONumber.Text = string.Empty;
            lblErrorInvoiceNumber.Text = string.Empty;
            if (txtponumber.Text.Trim().ToString() == txtsealnumber.Text.Trim().ToString())
            {
                if (txtinvoicenumber.Text.Trim().ToString() == txtladingnumber.Text.Trim().ToString())
                {
                    lblerrorPONumber.Text = "PO Number Seal Number are Same. !";
                    //  lblerrorPONumber.Text = string.Empty;
                    lblErrorInvoiceNumber.Text = "Invoice Number Bill Of Lading Number are Same. !";
                }
                else
                {
                    lblerrorPONumber.Text = "PO Number Seal Number are Same. !";
                }


            }
            else
            {
                lblerrorPONumber.Text = string.Empty;

                if (txtinvoicenumber.Text.Trim().ToString() == txtladingnumber.Text.Trim().ToString())
                {
                    lblErrorInvoiceNumber.Text = "Invoice Number Bill Of Lading Number are Same. !";
                }
                else
                {
                    lblErrorInvoiceNumber.Text = string.Empty;

                    //BarCode br = new BarCode();
                    //br.DateCreated = DateTime.Now.ToShortDateString();
                    //br.OrganizationID = UserOrganizationId;
                    //br.BarCodeNumber = GenerateLotSerialNumber();

                    //// Guid g = Guid.NewGuid();
                    //string str = br.BarCodeNumber.ToString().Replace("-", "");
                    //if (br.GenerateLotBarCodeImage(str))
                    //{
                    //    hdnLotBarCodeImageFileName.Value = str + ".gif";
                    //    imgLotBarcode.ImageUrl = String.Format("/images/temp/{0}.Gif", str);
                    //    imgLotBarcode.Visible = true;
                    //    //txtBrand.Focus();
                    //}
                    //if (System.IO.File.Exists(Server.MapPath(String.Format("/images/temp/{0}", hdnLotBarCodeImageFileName.Value))))
                    //{
                    //    br.Image = System.IO.File.ReadAllBytes(Server.MapPath(String.Format("/images/temp/{0}", hdnLotBarCodeImageFileName.Value)));

                    //}

                    //lnkbtnAddCreateLoad.Visible = false;
                    ////lnkContinue.Visible = true;
                    //int barcodeId = BarCode.Insert(br);
                    //int loadId = 0;

                    if (Conversion.ParseInt(hidOrgID.Value) == UserOrganizationId)
                    {
                        lblHaulerError.Text = "Please Select Any other Hauler Name";
                        return;
                    }
                    else
                    {
                        lblHaulerError.Text = string.Empty;
                        Loads.updatePendingAndShipLoad(loadid, Conversion.ParseInt(ddlLoadType.SelectedValue), txtponumber.Text.Trim(), txtinvoicenumber.Text.Trim(), txtsealnumber.Text.Trim(), txttrailernumber.Text.Trim(), txtweight.Text.Trim(), txtladingnumber.Text.Trim(), UserOrganizationId, LoginMemberId, Conversion.ParseInt(hidOrgID.Value), objLoad.BarcodeId, objBarCode.BarCodeNumber, txtLoadnumber.Text.Trim());
                        if (Conversion.ParseInt(ddlLoadType.SelectedValue) == 75)
                        {
                            SendNotification(loadid);
                        }
                        Response.Redirect("inventory-load");
                    }
                       
                }
            }


     
        }
        else
        {

            //BarCode br = new BarCode();
            //br.DateCreated = DateTime.Now.ToShortDateString();
            //br.OrganizationID = UserOrganizationId;
            //br.BarCodeNumber = GenerateLotSerialNumber();

            //// Guid g = Guid.NewGuid();
            //string str = br.BarCodeNumber.ToString().Replace("-", "");
            //if (br.GenerateLotBarCodeImage(str))
            //{
            //    hdnLotBarCodeImageFileName.Value = str + ".gif";
            //    imgLoadBarCodeTransfer.ImageUrl = String.Format("/images/temp/{0}.Gif", str);
            //    imgLoadBarCodeTransfer.Visible = true;


            //    //txtBrand.Focus();
            //}
            //if (System.IO.File.Exists(Server.MapPath(String.Format("/images/temp/{0}", hdnLotBarCodeImageFileName.Value))))
            //{
            //    br.Image = System.IO.File.ReadAllBytes(Server.MapPath(String.Format("/images/temp/{0}", hdnLotBarCodeImageFileName.Value)));

            //}

            //lnkbtnAddCreateLoad.Visible = false;
            //lnkContinue.Visible = true;
            //int barcodeId = BarCode.Insert(br);
            //int loadId = 0;


            if (ddlLoadType.SelectedValue =="72")
            {
                Loads.updateTransferLoad(loadid,Conversion.ParseInt(ddlLoadType.SelectedValue), Conversion.ParseInt(ddlLot.SelectedValue), Conversion.ParseInt(ddlSpace.SelectedValue), Conversion.ParseInt(ddlLane.SelectedValue), UserOrganizationId,LoginMemberId,objLoad.BarcodeId, objLoad.LoadNumber);
                Response.Redirect("inventory-load");

            }
        }        /* lot.BarCodeId*/
        //int id = BarCode.Insert(br);



    }
    private void HideControlsForTransfer()
    {
        int loadid = Conversion.ParseInt(Request.QueryString["LoadId"]);

        Loads objLoad = new Loads(loadid);
        BarCode objBarCode = new BarCode(objLoad.BarcodeId);

        if (ddlLoadType.SelectedValue=="74")
        {

            pnlControls.Visible = true;
            pnlDropDowns.Visible = false;
            rvfFacility.Enabled = false;
            rvfLane.Enabled = false;
            rvfLot.Enabled = false;
            rvfSpace.Enabled = false;
            dvSearchHauler1.Visible = false;
            rfvHaul.Enabled = false;
            hdnLotBarCodeImageFileName.Value = objBarCode.BarCodeNumber + ".gif";
            imgLotBarcode.ImageUrl = String.Format("/images/temp/{0}.Gif", objBarCode.BarCodeNumber);
            imgLotBarcode.Visible = true;
           
        }

        else if (ddlLoadType.SelectedValue=="72")
        {
            
            pnlControls.Visible = false;
            pnlDropDowns.Visible = true;
            BindddlFacility();
            BindddlLots();
            BindddlSpace();
            BindddlLane();
            rvfFacility.Enabled = true;
            rvfLane.Enabled = true;
            rvfLot.Enabled = true;
            rvfSpace.Enabled = true;
           
            hdnLotBarCodeImageFileName.Value = objBarCode.BarCodeNumber + ".gif";
            imgLoadBarCodeTransfer.ImageUrl = String.Format("/images/temp/{0}.Gif", objBarCode.BarCodeNumber);
            imgLoadBarCodeTransfer.Visible = true;
          
        }
        else 
        {
            dvSearchHauler1.Visible = true;
            rfvHaul.Enabled = true;

            pnlControls.Visible = true;
            pnlDropDowns.Visible = false;
            rvfFacility.Enabled = false;
            rvfLane.Enabled = false;
            rvfLot.Enabled = false;
            rvfSpace.Enabled = false;
            hdnLotBarCodeImageFileName.Value = objBarCode.BarCodeNumber + ".gif";
            imgLotBarcode.ImageUrl = String.Format("/images/temp/{0}.Gif", objBarCode.BarCodeNumber);
            imgLotBarcode.Visible = true;
          
        }
    }