using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.DirectoryServices;

public partial class Organization_Settings_GetApprovalDetails : Base.BasePage
{
    #region Global Variable Declaration
    int CompanyID;
    ResourceManager rm;
    CultureInfo ci;
    ShiftEvenData objShift = new ShiftEvenData();
    string ConcatenateString = string.Empty;
    #endregion
    protected override void Page_Load(object sender, EventArgs e)
    {
        GC.Collect();
        base.Page_Load(sender, e);
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        if (Request.QueryString["DomainName"] != null && Request.QueryString["DomainName"] != "")
        {
            string DomainName, UserName, Password = "";
            DomainName = Convert.ToString(Request.QueryString["DomainName"]);
            UserName = Convert.ToString(Request.QueryString["User"]);
            Password = Convert.ToString(Request.QueryString["Password"]);
            try
            {
                DirectoryEntry myDirectoryEntry = new DirectoryEntry();
                DirectorySearcher mySearcher = new DirectorySearcher();
                SearchResultCollection results;
                myDirectoryEntry = new DirectoryEntry("LDAP://" + DomainName, UserName, Password);
                mySearcher = new DirectorySearcher(myDirectoryEntry, "(&(SAMAccountName=" + UserName + ")(objectClass=user)(objectCategory=person))");
                results = mySearcher.FindAll();
                Response.Write("Success");
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToString());
                Response.End();
            }
            Response.End();
        }
        else
        {
            if (Request.QueryString["CompanyID"] != null && Request.QueryString["CompanyID"] != "")
            {
                string Returnval = string.Empty;
                Returnval = getApprovalDetails(Convert.ToInt32(Request.QueryString["CompanyID"]));
                Response.Write(Returnval);
                Response.End();
            }
        }
    }
    protected string getApprovalDetails(int CompanyID)
    {
        Response.Clear();
        DataSet dsApprovalSettings = new DataSet();
        dsApprovalSettings = objShift.SelectApprovalSettings(CompanyID);
        if (dsApprovalSettings != null)
        {
            if (dsApprovalSettings.Tables.Count > 0)
            {
                if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                {
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["Pattern"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["Roster"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["ManualEntry"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["LeaveSanction"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["ODEntry"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["PermissionSanction"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["OTApproval"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["Approval"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["webClockInOut"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["ShiftRequisition"]) == true)
                        ConcatenateString += "$true";
                    else
                        ConcatenateString += "$false";
                }
                else
                {
                    //base.Message(rm.GetString("Msg_ApprovalSettings", ci));
                    Response.Clear();
                    Response.Write("Fail");
                    Response.End();
                }
            }
            else
            {
                Response.Clear();
                Response.Write("Fail");
                Response.End();
            }
        }
        else
        {
            Response.Clear();
            Response.Write("Fail");
            Response.End();
        }
        dsApprovalSettings.Clear();
        dsApprovalSettings.Dispose();
        return ConcatenateString;
    }


}