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_GetPayrollDetails : Base.BasePage
{
    #region Global Variable Declaration
    int CompanyID;
    ResourceManager rm;
    CultureInfo ci;
    PayrollConfigurationEventData objPayrollData = new PayrollConfigurationEventData();
    string ConcatenateString = string.Empty;
    #endregion
    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
        {
            if (Request.QueryString["CompanyID"] != null && Request.QueryString["CompanyID"] != "")
            {
                string Returnval = string.Empty;
                Returnval = getPayrollDetails(Convert.ToInt32(Request.QueryString["CompanyID"]));
                Response.Write(Returnval);
                Response.End();
            }
        }
    }

    private string getPayrollDetails(int CompanyID)
    {

        Response.Clear();
        DataSet ds = new DataSet();
        DataSet dsPayrollSettings = new DataSet();
        Hashtable searchTable = new Hashtable();
        searchTable.Add("@tag", 'S');
        searchTable.Add("@CompanyID", CompanyID);
        dsPayrollSettings = objPayrollData.InsertPayrollConfigSetting(searchTable);

        if (dsPayrollSettings != null)
        {
            if (dsPayrollSettings.Tables[0].Rows.Count > 0)
            {

                if(dsPayrollSettings.Tables[0].Rows[0]["CompanyId"].ToString()!=" ")
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["CompanyId"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if(dsPayrollSettings.Tables[0].Rows[0]["D_Allowance"] !=DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["D_Allowance"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }

                if (dsPayrollSettings.Tables[0].Rows[0]["HRA_Metro"] != DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["HRA_Metro"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (dsPayrollSettings.Tables[0].Rows[0]["HRA_NonMetro"] != DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["HRA_NonMetro"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (dsPayrollSettings.Tables[0].Rows[0]["MedicalAmount"] != DBNull.Value && Convert.ToDouble(dsPayrollSettings.Tables[0].Rows[0]["MedicalAmount"]) != 0)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["MedicalAmount"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (dsPayrollSettings.Tables[0].Rows[0]["MedicalPercent"] != DBNull.Value && Convert.ToDouble(dsPayrollSettings.Tables[0].Rows[0]["MedicalPercent"])!=0)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["MedicalPercent"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (dsPayrollSettings.Tables[0].Rows[0]["CEAAmount"] != DBNull.Value && Convert.ToDouble(dsPayrollSettings.Tables[0].Rows[0]["CEAAmount"]) != 0)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["CEAAmount"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (dsPayrollSettings.Tables[0].Rows[0]["CEAPercentage"] != DBNull.Value && Convert.ToDouble(dsPayrollSettings.Tables[0].Rows[0]["CEAPercentage"]) != 0)
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["CEAPercentage"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (dsPayrollSettings.Tables[0].Rows[0]["isMedicalflag"] != DBNull.Value && Convert.ToDouble(dsPayrollSettings.Tables[0].Rows[0]["isMedicalflag"]) != 0 || Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["isMedicalflag"])=="True")
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["isMedicalflag"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }

                if (dsPayrollSettings.Tables[0].Rows[0]["isCEAflag"] != DBNull.Value && Convert.ToDouble(dsPayrollSettings.Tables[0].Rows[0]["isCEAflag"]) != 0 || Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["isCEAflag"]) == "True")
                {
                    ConcatenateString += "$" + (Convert.ToString(dsPayrollSettings.Tables[0].Rows[0]["isCEAflag"]));
                }
                else
                {
                    ConcatenateString += "$0";
                }


            }
            else
            {
                Response.Clear();
                Response.Write("Fail");
                Response.End();
            }
        }
        else
        {
            Response.Clear();
            Response.Write("Fail");
            Response.End();
        }
        dsPayrollSettings.Clear();
        ds.Clear();
        ds.Dispose();
        return ConcatenateString;
    }
}