//gvUserCreation.DataSource = null;
        //List<SP_GWCGetUserForApprovalMaster_Result> getlst = new List<SP_GWCGetUserForApprovalMaster_Result>();
        //if (hdnUserIDs.Value != "" || hdnUserIDs.Value != "0")
        //{
        //    getlst = ApprovalClient.GWCGetUserForApprovalMaster(Convert.ToInt64(hdnSelectedLevel.Value), hdnUserIDs.Value, profile.DBConnection._constr).ToList();
        //    gvUserCreation.DataSource = getlst;
        //    gvUserCreation.DataBind();
        //}

        public void GetApproverList()
        {
            iApprovalLevelMasterClient ApprovalClient = new iApprovalLevelMasterClient();

            try
            {
                CustomProfile profile = CustomProfile.GetProfile();
                gvUserCreation.DataSource = null;
                gvUserCreation.DataBind();
                DataSet dsApproverList = new DataSet();
                List <SP_GWCGetApproverListBySp_Result> getlst = new List <SP_GWCGetApproverListBySp_Result>();
                //if (hdnStatus.Value == "AddNew")
                //{
                // getlst = ApprovalClient.GetApproverListBySp(Convert.ToInt64(hdnSelectedLevel.Value), profile.DBConnection._constr).ToList();
                getlst         = ApprovalClient.GetApproverListBySp(Convert.ToInt64(hdnSelectedDepartment.Value), profile.DBConnection._constr).ToList();
                dsApproverList = ApprovalClient.GetApproverList(profile.DBConnection._constr);
                // gvUserCreation.DataSource = dsApproverList;
                gvUserCreation.DataSource = getlst;
                gvUserCreation.DataBind();
                //}
                //else
                //{
                //    gvUserCreation.DataSource = ApprovalClient.GWCGetApprovalDetailForEditWithZero(Convert.ToInt64(hdnApprovalID.Value), profile.DBConnection._constr);
                //    gvUserCreation.DataBind();
                //}
            }
            catch (System.Exception ex)
            {
                Login.Profile.ErrorHandling(ex, "Approval Level Master", "GetApproverList");
            }
            finally
            {
                ApprovalClient.Close();
            }
        }
        public static string PMGetApprovalLevelByObjectName(string objectName, long territoryID)
        {
            iApprovalLevelMasterClient ApprovalClient = new iApprovalLevelMasterClient();
            string NewLevel = "";

            try
            {
                CustomProfile profile = CustomProfile.GetProfile();
                NewLevel = ApprovalClient.GetApprovalLevelMax(objectName, territoryID, profile.DBConnection._constr).ToString();
            }
            catch (System.Exception ex)
            { Login.Profile.ErrorHandling(ex, "Approval Level Master", "PMGetApprovalLevelByObjectName"); }
            finally
            { ApprovalClient.Close(); }
            return(NewLevel);
        }
        public static string PMApprovalLevel(long CompanyID, long DeptID)
        {
            iApprovalLevelMasterClient ApprovalClient = new iApprovalLevelMasterClient();
            string AppLevel = "";

            try
            {
                CustomProfile profile = CustomProfile.GetProfile();
                AppLevel = ApprovalClient.GetApprovalLevel(CompanyID, DeptID, profile.DBConnection._constr).ToString();
            }
            catch (System.Exception ex)
            { Login.Profile.ErrorHandling(ex, "Approval Level Master", "PMGetApprovalLevelByObjectName"); }
            finally
            { ApprovalClient.Close(); }

            return(AppLevel);
        }
        public void GetGWCApprovalLevel(long CompanyID, long DeptID)
        {
            iApprovalLevelMasterClient ApprovalClient = new iApprovalLevelMasterClient();
            string AppLevel = "";

            try
            {
                CustomProfile profile = CustomProfile.GetProfile();
                AppLevel = ApprovalClient.GetApprovalLevel(CompanyID, DeptID, profile.DBConnection._constr).ToString();
                lblApprovalLevel.Text = AppLevel;
            }
            catch (System.Exception ex)
            { Login.Profile.ErrorHandling(ex, "Approval Level Master", "GetGWCApprovalLevel"); }
            finally
            { ApprovalClient.Close(); }

            // return AppLevel;
        }
        protected void gvUserCreation_OnRebind(object sender, EventArgs e)
        {
            iApprovalLevelMasterClient ApprovalClient = new iApprovalLevelMasterClient();
            CustomProfile profile = CustomProfile.GetProfile();

            try
            {
                string insertgata = Session["InsertData"].ToString();
                if (hdnStatus.Value == "Edit" && Session["InsertData"].ToString() == "")
                {
                    //List<vGWCGetApprovalDetailsForEdit> getlst = new List<vGWCGetApprovalDetailsForEdit>();
                    //DataSet ds = new DataSet();
                    gvUserCreation.DataSource = ApprovalClient.GWCGetApprovalDetailsForEdit(Convert.ToInt64(hdnApprovalID.Value), profile.DBConnection._constr);
                    //getlst = ApprovalClient.GWCGetApprovalDetailsForEdit(Convert.ToInt64(hdnApprovalID.Value), profile.DBConnection._constr).ToList();
                    //gvUserCreation.DataSource = getlst;
                    gvUserCreation.DataBind();

                    // getlst = ApprovalClient.GWCGetUserForApprovalMaster(Convert.ToInt64(hdnSelectedLevel.Value), stringss[i], profile.DBConnection._constr).ToList();


                    GetApproverList();
                }
                else if (hdnStatus.Value == "AddNew" && Hdn1.Value == "1" && Session["InsertData"].ToString() == "")
                {
                    GetApproverList();
                }
                else if (Session["InsertData"].ToString() == "Insert")
                {
                    /*Add By Suresh*/
                    int AvailableApprovalLevel = ApprovalClient.GetApprovalRecordByApvrlLevelID(Convert.ToInt16(hdnSelectedLevel.Value), Convert.ToInt64(hdnSelectedDepartment.Value), profile.DBConnection._constr);
                    if (AvailableApprovalLevel > 0)
                    {
                        //  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "showAlert('Approval For This Level Are Already Available','Error','#')", true);
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Approval For This Level Are Already Available')", true);
                    }
                    else
                    {
                        mApprovalLevel ObjApproval = new mApprovalLevel();
                        ObjApproval.ObjectName              = "MaterialRequest";
                        ObjApproval.ApprovalLevel           = Convert.ToByte(hdnSelectedLevel.Value);
                        ObjApproval.NoOfApprovers           = Convert.ToByte(txtnoapprovar.Text);
                        ObjApproval.Active                  = "Y";
                        ObjApproval.TerritoryID             = Convert.ToInt64(hdnSelectedDepartment.Value);
                        ObjApproval.MinApprovalReq          = 0;
                        ObjApproval.MinApprovalReq          = 0;
                        ObjApproval.MaxAmount               = 0;
                        ObjApproval.IsLowerLevelApprovalReq = true;
                        if (hdnSelectedDepartment.Value != "" || hdnSelectedDepartment.Value != "0")
                        {
                            ObjApproval.OrderCancelInDays = ApprovalClient.GetCancelDays(Convert.ToInt64(hdnSelectedDepartment.Value), profile.DBConnection._constr);
                        }

                        int result = 0;

                        //if (hdnStatus.Value != "Edit")
                        //{
                        ObjApproval.CreatedBy    = profile.Personal.UserID.ToString();
                        ObjApproval.CreationDate = DateTime.Now;
                        result = ApprovalClient.InsertmApprovalLevel(ObjApproval, profile.DBConnection._constr);
                        // ObjApprovalDetail.ApprovalLevelID = result;
                        // ApprovalClient.UpdateApprovallevelID(result, profile.DBConnection._constr);
                        if (result != 0)
                        {
                            // WebMsgBox.MsgBox.Show("Record saved successfully");
                        }
                        //}
                        //else if (hdnStatus.Value == "Edit")
                        //{
                        //    ObjApproval.LastModifiedBy = profile.Personal.UserID.ToString();
                        //    ObjApproval.LastModifiedDate = DateTime.Now;
                        //    result= Convert.ToInt32(hdnApprovalID.Value);
                        //}
                        /*Add By Suresh*/

                        mApprovalLevelDetail ObjApprovalDetail = new mApprovalLevelDetail();
                        string[]             stringss          = new string[] { };
                        hdnUserIDs.Value = Session["Userlist"].ToString();
                        stringss         = hdnUserIDs.Value.Split(',');

                        ObjApprovalDetail.ApprovalLevelID = result;  //ObjApprovalDetail.ApprovalLevelID = 0;
                        ObjApprovalDetail.Active          = "Y";
                        ObjApprovalDetail.CreatedBy       = profile.Personal.UserID.ToString();
                        ObjApprovalDetail.CreationDate    = DateTime.Now;
                        ObjApprovalDetail.CompanyID       = Convert.ToInt64(hdnSelectedCompany.Value);
                        ObjApprovalDetail.DepartmentID    = Convert.ToInt64(hdnSelectedDepartment.Value);
                        if (chkand.Checked == true)
                        {
                            ObjApprovalDetail.ApproverLogic = "AND";
                        }
                        else
                        {
                            ObjApprovalDetail.ApproverLogic = "OR";
                        }

                        for (int i = 0; i < stringss.Length; i++)
                        {
                            ObjApprovalDetail.UserID = Convert.ToInt64(stringss[i].ToString());
                            ApprovalClient.InsertGWCApprovalDetails(ObjApprovalDetail, profile.DBConnection._constr);
                        }
                    }
                    GetApproverList();
                    Session["InsertData"] = "";
                }
            }
            catch (System.Exception ex)
            {
                Login.Profile.ErrorHandling(ex, "Approval Level Master", "gvUserCreation_OnRebind");
            }
            finally {
                ApprovalClient.Close();
            }
        }