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

public partial class Organization_Settings_GetAPIDetails : Base.BasePage
{

    int CompanyID;
    ResourceManager rm;
    CultureInfo ci;
    SMSNotification objSMS = new SMSNotification();
    string ConcatenateString = string.Empty;
    protected override void Page_Load(object sender, EventArgs e)
    {
        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
        {
            string Returnval = string.Empty;
            Returnval = getAPIDetails();
            Response.Write(Returnval);
            Response.End();

        }
    }
    private string getAPIDetails()
    {
        Response.Clear();
        DataSet ds = new DataSet();
        DataSet dsAPISetting = new DataSet();

        Hashtable htable = new Hashtable();
        htable.Add("@tag", "S");

        dsAPISetting =objSMS.SelectApIConfiguration(htable);

        if (dsAPISetting != null)
        {
            if (dsAPISetting.Tables[0].Rows.Count > 0)
            {
                if (dsAPISetting.Tables[0].Rows[0]["APIURL"].ToString() != " ")
                {
                    ConcatenateString += "$" + (Convert.ToString(dsAPISetting.Tables[0].Rows[0]["APIURL"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (dsAPISetting.Tables[0].Rows[0]["BiostarUsername"] != DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsAPISetting.Tables[0].Rows[0]["BiostarUsername"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (dsAPISetting.Tables[0].Rows[0]["BiostarPassword"] != DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsAPISetting.Tables[0].Rows[0]["BiostarPassword"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (dsAPISetting.Tables[0].Rows[0]["syncEmp"] != DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsAPISetting.Tables[0].Rows[0]["syncEmp"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if(dsAPISetting.Tables[0].Rows[0]["WhatsAPP_SID"] != DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsAPISetting.Tables[0].Rows[0]["WhatsAPP_SID"]));
                }
                if(dsAPISetting.Tables[0].Rows[0]["WhatsApp_authToken"] != DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsAPISetting.Tables[0].Rows[0]["WhatsApp_authToken"]));
                }
                if (dsAPISetting.Tables[0].Rows[0]["WhatsApp_SenderNumber"] != DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsAPISetting.Tables[0].Rows[0]["WhatsApp_SenderNumber"]));
                }
               
            }
            else
            {
                Response.Clear();
                Response.Write("Fail");
                Response.End();
            }
        }
        else
        {
            Response.Clear();
            Response.Write("Fail");
            Response.End();
        }
        dsAPISetting.Clear();
        ds.Clear();
        ds.Dispose();
        return ConcatenateString;
    }
}