using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Transactions_AjaxGetApprovalStatus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
     {
         if (!IsPostBack)
         {
             int levelId;
             int intCompanyId;
             string strStatus = string.Empty;
             string strModule = string.Empty;
             if (Session["ParentLevelID"] == null)
             {
                 levelId = 0;
             }
             else
             {
                 levelId = Convert.ToInt32(Session["ParentLevelID"]);
             }
             if (levelId == 0)
             {
                 Response.Clear();
                 Response.Write("CompanyRequired");
                 Response.End();
             }
             strModule = Request.QueryString["Module"];
             intCompanyId = getParentCompany(levelId);
             strStatus = GetApprovalStatus(intCompanyId, strModule);
             Response.Clear();
             Response.Write(strStatus);
             Response.End();
         }
    }
    public int getParentCompany(int iEmployeeLevelID)
    {
        //Select Company
        org_levelsEventData getOrg = new org_levelsEventData();
        getOrg.GetOrgParentLevels_FromID(iEmployeeLevelID);
        DataSet ds_getOrg = new DataSet();
        ds_getOrg = getOrg.GetOrgParentLevels();
        int iCompanyID = 0;
        if (ds_getOrg != null)
        {
            if (ds_getOrg.Tables[0].Rows.Count > 0)
            {
                iCompanyID = Convert.ToInt32(ds_getOrg.Tables[0].Rows[0]["LevelID"].ToString());
            }
        }
        return iCompanyID;
    }
    public string GetApprovalStatus(int intCompanyId,string strModule)
    {
        cls_Common objClassCommon = new cls_Common();
        int approvalSettingsPageExists = 0;
        //Checking grade module is available or not and changed the id value from 110 to 228        
        approvalSettingsPageExists = objClassCommon.CheckPageExistsInLicense(228);
        string strStatus = string.Empty;
        if (approvalSettingsPageExists == 1)
        {
            //Get Approval Settings Based on Company Id
            DataSet dsApprovalSettings = new DataSet();
            ShiftEvenData objShift = new ShiftEvenData();
            dsApprovalSettings = objShift.SelectApprovalSettings(intCompanyId);
            if (dsApprovalSettings != null)
            {
                if (dsApprovalSettings.Tables.Count > 0)
                {
                    if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                    {
                        if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0][strModule]) == false)
                        {
                            strStatus = "ApprovalNotRequired";
                        }
                        else
                        {
                            strStatus = "ApprovalRequired";
                        }
                    }
                    else
                    {
                        strStatus = "NotDefined";
                    }
                }
            }
        }
        else
        {
            strStatus = "ApprovalRequired";
        }
        return strStatus;
    }
}
