protected void GetTemplateDetails()
        {
            iPartRequestClient   objService = new iPartRequestClient();
            mRequestTemplateHead ReqTmpHead = new mRequestTemplateHead();

            try
            {
                CustomProfile profile = CustomProfile.GetProfile();
                ReqTmpHead = objService.GetTemplateOrderHead(Convert.ToInt64(hdnTemplateID.Value), profile.DBConnection._constr);

                long SiteID = Convert.ToInt64(ReqTmpHead.Department); hdnselectedDept.Value = SiteID.ToString(); Session["DeptID"] = SiteID.ToString();

                iUCCommonFilterClient objCommon = new iUCCommonFilterClient();
                long CompanyID = objCommon.GetCompanyIDFromSiteID(SiteID, profile.DBConnection._constr);

                txtTitle.Text = ReqTmpHead.TemplateTitle.ToString();
                ddlAccessType.SelectedValue = ReqTmpHead.Accesstype.ToString();

                //ddlCompany.SelectedIndex = ddlCompany.Items.IndexOf(ddlCompany.Items.FindByValue(ReqTmpHead.Customer.ToString()));
                //cmp = long.Parse(ReqTmpHead.Customer.ToString());
                List <mCompany> CompanyLst = new List <mCompany>();
                string          UserType   = profile.Personal.UserType.ToString();
                long            UID        = profile.Personal.UserID;

                if (UserType == "Admin")
                {
                    //  CompanyLst = objService.GetCompanyName(profile.DBConnection._constr).ToList();
                    // CompanyLst = objService.GetUserCompanyName(UID, profile.DBConnection._constr).ToList();

                    CompanyLst = objCommon.GetUserCompanyNameNEW(UID, profile.DBConnection._constr).ToList();
                }
                else if (UserType == "User" || UserType == "Requester And Approver" || UserType == "Requester" || profile.Personal.UserType == "Requestor" || profile.Personal.UserType == "Requestor And Approver")
                {
                    CompanyLst = objCommon.GetUserCompanyName(UID, profile.DBConnection._constr).ToList();
                }
                else
                {
                    CompanyLst = objCommon.GetCompanyName(profile.DBConnection._constr).ToList();
                }
                ddlCompany.DataSource = CompanyLst;
                ddlCompany.DataBind();

                ddlCompany.SelectedIndex = ddlCompany.Items.IndexOf(ddlCompany.Items.FindByValue(CompanyID.ToString())); //ddlCompany.Items.IndexOf(ddlCompany.Items.FindByValue(ReqTmpHead.Customer.ToString()));
                cmp = CompanyID;

                int Cmpny = int.Parse(CompanyID.ToString());  //Convert.ToInt16(ReqTmpHead.Customer.ToString());
                ddlSites.DataSource = WMGetDept(Cmpny);
                ddlSites.DataBind();
                ddlSites.SelectedIndex = ddlSites.Items.IndexOf(ddlSites.Items.FindByValue(ReqTmpHead.Department.ToString()));
                dpt = long.Parse(ReqTmpHead.Department.ToString());

                txtRemark.Text = ReqTmpHead.Remark.ToString();

                //ddlAddress.DataSource = WMGetDeptAddress(CompanyID); //WMGetDeptAddress(SiteID);
                //ddlAddress.DataBind();
                //ddlAddress.SelectedIndex = ddlAddress.Items.IndexOf(ddlAddress.Items.FindByValue(ReqTmpHead.Address.ToString()));
                //adrs = long.Parse(ReqTmpHead.Address.ToString());

                //ddlContact1.DataSource = WMGetContactPersonLst(CompanyID); //WMGetContactPersonLst(SiteID);
                //ddlContact1.DataBind();
                //ddlContact1.SelectedIndex = ddlContact1.Items.IndexOf(ddlContact1.Items.FindByValue(ReqTmpHead.Contact1.ToString()));
                //c1 = long.Parse(ReqTmpHead.Contact1.ToString());
                ////ddlContact2.DataSource = WMGetContactPerson2Lst(Convert.ToInt64(ReqTmpHead.Department), Convert.ToInt64(ddlContact1.SelectedIndex));
                //ddlContact2.DataSource = WMGetContactPerson2Lst(CompanyID, Convert.ToInt64(ddlContact1.SelectedIndex));
                //ddlContact2.DataBind();
                //ddlContact2.SelectedIndex = ddlContact2.Items.IndexOf(ddlContact2.Items.FindByValue(ReqTmpHead.Contact2.ToString()));
                //c2 = long.Parse(ReqTmpHead.Contact2.ToString());

                //lblAddress.Text = ddlAddress.SelectedItem.ToString();

                DataSet dsTemplatePartLst = new DataSet();
                dsTemplatePartLst = objService.GetTemplatePartLstByTemplateID(Convert.ToInt64(hdnTemplateID.Value), profile.DBConnection._constr);
                List <POR_SP_GetPartDetail_ForRequest_Result> TemplatePartList = new List <POR_SP_GetPartDetail_ForRequest_Result>();
                if (dsTemplatePartLst.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i <= dsTemplatePartLst.Tables[0].Rows.Count - 1; i++)
                    {
                        TemplatePartList = objService.AddPartIntoRequest_TempData(dsTemplatePartLst.Tables[0].Rows[i]["PrdID"].ToString(), Session.SessionID, profile.Personal.UserID.ToString(), ObjectName, SiteID, profile.DBConnection._constr).ToList();
                        string uom = objService.GetUOMName(Convert.ToInt64(dsTemplatePartLst.Tables[0].Rows[i]["UOMID"].ToString()), profile.DBConnection._constr);
                        POR_SP_GetPartDetail_ForRequest_Result PartRequest = new POR_SP_GetPartDetail_ForRequest_Result();
                        PartRequest.Sequence      = i + 1;
                        PartRequest.RequestQty    = Convert.ToDecimal(dsTemplatePartLst.Tables[0].Rows[i]["Qty"].ToString()); // Convert.ToDecimal(dictionary["RequestQty"]);
                        PartRequest.Price         = Convert.ToDecimal(dsTemplatePartLst.Tables[0].Rows[i]["Price"].ToString());
                        PartRequest.Total         = Convert.ToDecimal(dsTemplatePartLst.Tables[0].Rows[i]["Total"].ToString());
                        PartRequest.IsPriceChange = Convert.ToInt16(dsTemplatePartLst.Tables[0].Rows[i]["IsPriceChange"].ToString());
                        PartRequest.UOMID         = Convert.ToInt64(dsTemplatePartLst.Tables[0].Rows[i]["UOMID"].ToString());
                        PartRequest.UOM           = uom;

                        objService.UpdatePartRequest_TempData12(HttpContext.Current.Session.SessionID, ObjectName, profile.Personal.UserID.ToString(), PartRequest, profile.DBConnection._constr);
                        // objService.UpdatePartRequest_TempData(HttpContext.Current.Session.SessionID, ObjectName, profile.Personal.UserID.ToString(), PartRequest, profile.DBConnection._constr);

                        TemplatePartList = objService.GetExistingTempDataBySessionIDObjectName(Session.SessionID, profile.Personal.UserID.ToString(), ObjectName, profile.DBConnection._constr).ToList();
                    }
                }

                Grid1.DataSource = TemplatePartList;
                Grid1.DataBind();
            }
            catch (System.Exception ex)
            {
                Login.Profile.ErrorHandling(ex, this, "Request Template", "GetTemplateDetails");
            }
            finally { objService.Close(); }
        }
        protected void pageSave(object sender, BrilliantWMS.ToolbarService.iUCToolbarClient e)
        {
            iPartRequestClient objService = new iPartRequestClient();

            try
            {
                CustomProfile        profile     = CustomProfile.GetProfile();
                mRequestTemplateHead ReqTempHead = new mRequestTemplateHead();

                int cnt;
                cnt = objService.GridRowCount(Session.SessionID, ObjectName, profile.Personal.UserID.ToString(), profile.DBConnection._constr);

                if (cnt == 0)
                {
                    WebMsgBox.MsgBox.Show("Add atleast one part into the Request Part List");
                }
                else
                {
                    List <POR_SP_GetPartDetail_ForRequest_Result> GetGridRowsTemplate = new List <POR_SP_GetPartDetail_ForRequest_Result>();
                    GetGridRowsTemplate = objService.GridRowsTemplate(Session.SessionID, ObjectName, profile.Personal.UserID.ToString(), profile.DBConnection._constr).ToList();
                    //var ReqQty = GetGridRowsTemplate.Where(r => r.RequestQty == 0).ToList();

                    //long RQty = Convert.ToInt64(ReqQty.Count);
                    //if (RQty >=1)
                    //{
                    //    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "showAlert('One or more request quantity is zero','Error','#')", true);

                    //}
                    //else
                    //{

                    if (hdnTemplateID.Value == "")
                    {
                        ReqTempHead.CreatedBy   = profile.Personal.UserID;
                        ReqTempHead.CreatedDate = DateTime.Now;
                    }
                    else
                    {
                        ReqTempHead             = objService.GetTemplateOrderHead(Convert.ToInt64(hdnTemplateID.Value), profile.DBConnection._constr);
                        ReqTempHead.CreatedBy   = ReqTempHead.CreatedBy;
                        ReqTempHead.CreatedDate = ReqTempHead.CreatedDate;

                        ReqTempHead.ModifiedBy   = profile.Personal.UserID;
                        ReqTempHead.ModifiedDate = DateTime.Now;
                        ReqTempHead.ID           = Convert.ToInt64(hdnTemplateID.Value);
                    }

                    ReqTempHead.TemplateTitle = txtTitle.Text;
                    ReqTempHead.Accesstype    = ddlAccessType.SelectedValue.ToString();

                    if (hdnselectedDept.Value == "")
                    {
                        ReqTempHead.Department = dpt;
                    }
                    else
                    {
                        ReqTempHead.Department = Convert.ToInt64(hdnselectedDept.Value);
                    }

                    if (hdnselectedCompany.Value == "")
                    {
                        ReqTempHead.Customer = cmp;
                    }
                    else
                    {
                        ReqTempHead.Customer = Convert.ToInt64(hdnselectedCompany.Value);
                    }
                    ReqTempHead.Active = "Yes";

                    ReqTempHead.Remark = txtRemark.Text;
                    if (hdnSelAddress.Value == "")
                    {
                        ReqTempHead.Address = adrs;
                    }
                    else
                    {
                        ReqTempHead.Address = Convert.ToInt64(hdnSelAddress.Value);
                    }
                    if (hdnselectedCont1.Value == "")
                    {
                        ReqTempHead.Contact1 = c1;
                    }
                    else
                    {
                        ReqTempHead.Contact1 = Convert.ToInt64(hdnselectedCont1.Value);
                    }
                    if (hdnselectedCont2.Value == "")
                    {
                        ReqTempHead.Contact2 = c2;
                    }
                    else
                    {
                        ReqTempHead.Contact2 = Convert.ToInt64(hdnselectedCont2.Value);
                    }

                    long RequestTemplateID = objService.InsertIntomRequestTemplateHead(ReqTempHead, profile.DBConnection._constr);
                    if (RequestTemplateID > 0)
                    {
                        objService.FinalSavemRequestTemplateDetailTemplate(HttpContext.Current.Session.SessionID, ObjectName, RequestTemplateID, profile.Personal.UserID.ToString(), profile.DBConnection._constr);
                        WebMsgBox.MsgBox.Show("Template Saved Successfully");
                        clearfields();
                        //tbTemplateLst.Visible = true;
                        //tbTemplateDetail.Visible = false;
                        //tabContainerReqTemplate.ActiveTabIndex = 0;
                        //GetTemplateList();
                        //Response.Redirect("../PowerOnRent/RequestTemplate.aspx");
                    }
                    //}
                }
                //}
            }
            catch (System.Exception ex)
            {
                Login.Profile.ErrorHandling(ex, this, "Request Template", "pageSave");
            }
            finally { objService.Close(); }
        }