using System;
using System.Collections;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Text;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cryptographys;
public partial class System_Settings_ExportDataForORCL : Base.BasePage
{
    #region VariableDeclaration
    MonthClosureEventData objMonthClosureEventData = new MonthClosureEventData();
    ExportData objExportData = new ExportData();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    ResourceManager rm;
    string strMonthName = string.Empty, strMonthValue = string.Empty;
    int intYear;
    CultureInfo ci;
    DataSet dsCustomFormat = new DataSet();
    DataSet dsPayrollProcess = new DataSet();
    DataSet dsCustomFields = new DataSet();
    #endregion
    #region Pageload
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        //dsPayrollProcess.ReadXml(@"E:\ExportData.xml");
        // Get the culture info to set the language
        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;
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_SelectanyoneOptiontomove") + "','" + rm.GetString("Alert_Select_Company") + "','" + rm.GetString("Alert_SelectDuration") + "','" + rm.GetString("Alert_SureToExportData") + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        //Call to a function to implement the UserRights
        UserRights();
        if (!IsPostBack)
        {
            //FillYearDropdown();
            CompanyBinding();
            ddlCompany.Focus();
            //btn_Export.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_AreyousuretoExportData", ci) + "');return false;";
        }
        if (ddlCompany.SelectedValue != "-Select-")
        {
            FillFieldListBox();
            BindFields();
        }
        hdnSelectedOption.Value = rbOption.SelectedValue;
        hdnSelectedDataType.Value = rblMonthDateWise.SelectedValue;
        //To apply toot tip for the list box items
        lst_PayrollFieldList.PreRender += LB_PreRender;
    }
    #endregion
    #region UserDefinedFunctions
    private void CompanyBinding()
    {
        ShiftEvenData objShift = new ShiftEvenData();
        string gstrUserGroupName = string.Empty;
        DataSet dsCompany = new DataSet();
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        dsCompany = objShift.SelectCompany(gstrUserGroupName, Convert.ToString(Session["LevelRights"]), 0);
        if (dsCompany != null)
        {
            if (dsCompany.Tables[0].Rows.Count > 0)
            {
                ddlCompany.DataSource = dsCompany;
                ddlCompany.DataTextField = "CompanyName";
                ddlCompany.DataValueField = "CompanyId";
                ddlCompany.DataBind();
            }
            foreach (ListItem item in ddlCompany.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }
    private void filldurationDetails(int companyId)
    {
        DataSet ds_DurationDetails = new DataSet();
        ds_DurationDetails = objMonthClosureEventData.SelectPayrollDurtaion(companyId);
        ddlDuration.DataSource = ds_DurationDetails;
        ddlDuration.DataValueField = "MonthClosure_Id";
        ddlDuration.DataTextField = "Duration";
        ddlDuration.DataBind();
        ddlDuration.Items.Insert(0, "-Select-");
        foreach (ListItem item in ddlDuration.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    /// <summary>
    /// Methods to upload file to FTP Server
    /// </summary>
    /// <param name="_FileName">local source file name</param>
    /// <param name="_UploadPath">Upload FTP path including Host name</param>
    /// <param name="_FTPUser">FTP login username</param>
    /// <param name="_FTPPass">FTP login password</param>
    public void UploadFile(string _FileName, string _UploadPath, string _FTPUser, string _FTPPass)
    {
        //try
        //{
        System.IO.FileInfo _FileInfo = new System.IO.FileInfo(_FileName);
        string strFilename = _FileName.Substring(Convert.ToInt16(_FileName.LastIndexOf(@"\")) + 1, (_FileName.Length - _FileName.LastIndexOf(@"\") - 1));
        // Create FtpWebRequest object from the Uri provided
        System.Net.FtpWebRequest _FtpWebRequest = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(new Uri(_UploadPath + @"/" + Path.GetFileName(_FileName)));
        //System.Net.FtpWebRequest _FtpWebRequest = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(new Uri(_UploadPath + @"/" + Path.GetFileName(_FileName)));
        // Provide the WebPermission Credintials
        _FtpWebRequest.Credentials = new System.Net.NetworkCredential(_FTPUser, _FTPPass);
        // By default KeepAlive is true, where the control connection is not closed
        // after a command is executed.
        _FtpWebRequest.KeepAlive = false;
        // set timeout for 20 seconds
        _FtpWebRequest.Timeout = 20000;
        // Specify the command to be executed.
        _FtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
        // Specify the data transfer type.
        _FtpWebRequest.UseBinary = false;
        // Notify the server about the size of the uploaded file
        _FtpWebRequest.ContentLength = _FileInfo.Length;
        // The buffer size is set to 2kb
        int buffLength = 2048;
        byte[] buff = new byte[buffLength];
        System.IO.FileStream _FileStream = null;
        System.IO.Stream _Stream = null;
        try
        {
            // Opens a file stream (System.IO.FileStream) to read the file to be uploaded
            _FileStream = _FileInfo.OpenRead();
            // Stream to which the file to be upload is written
            _Stream = _FtpWebRequest.GetRequestStream();
            //System.IO.Stream _Stream = request.GetRequestStream();
            // Read from the file stream 2kb at a time
            int contentLen = _FileStream.Read(buff, 0, buffLength);
            // Till Stream content ends
            while (contentLen != 0)
            {
                // Write Content from the file stream to the FTP Upload Stream
                _Stream.Write(buff, 0, contentLen);
                contentLen = _FileStream.Read(buff, 0, buffLength);
            }
            // Close the file stream and the Request Stream
            _Stream.Close();
            _Stream.Dispose();
            _FileStream.Close();
            _FileStream.Dispose();
        }
        catch (Exception ex)
        {
            throw ex;
            //    MessageBox.Show(ex.Message, "Upload Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        finally
        {
            // Close the file stream and the Request Stream
            //_Stream.Close();
            //_Stream.Dispose();
            _FileStream.Close();
            _FileStream.Dispose();
        }
    }
    /// <summary>
    /// This will delete the tempary files from the folder
    /// </summary>
    protected void DeleteExistingFiles(string strFilePath)
    {
        if (Directory.Exists(strFilePath))
        {
            foreach (string strFilePaths in Directory.GetFiles(strFilePath))
            {
                File.Delete(strFilePaths);
            }
        }
    }
    public StringBuilder Export(DataSet ds)
    {
        StringBuilder columnnames = new StringBuilder();
        StringBuilder body = new StringBuilder();
        StringBuilder record = new StringBuilder();
        //string header = "";
        int RowCount = ds.Tables[0].Columns.Count;
        int increment = 0;
        foreach (DataColumn col in ds.Tables[0].Columns)
        {
            increment = increment + 1;
            // columnnames = columnnames + " " + col.ColumnName + " " + ",";
            //columnnames.Append(columnnames);
            columnnames.Append(" ");
            columnnames.Append(col.ColumnName);
            columnnames.Append(" ");
            if (increment != RowCount)
            {
                columnnames.Append(",");
            }
        }
        //columnnames = columnnames + "Reason,";
        //columnnames.Append(columnnames.ToString().Substring(0, columnnames.Length - 1));
        //columnnames = columnnames.ToString().Substring(0, columnnames.Length - 1);
        foreach (DataRow row in ds.Tables[0].Rows)
        {
            object[] arr = row.ItemArray;
            for (int i = 0; i <= arr.Length - 1; i++)
            {
                if (arr[i].ToString().IndexOf(",") > 0)
                {
                    //record = record + " " + arr[i].ToString() + " " + ",";
                    //record.Append(record);
                    record.Append(" ");
                    record.Append(arr[i].ToString());
                    record.Append(" ");
                    record.Append(",");
                }
                else
                {
                    //record = record + arr[i].ToString() + ",";
                    //record.Append(record);
                    record.Append(arr[i].ToString());
                    record.Append(",");
                }
            }
            //record = record + "" + strReason + ",";
            //body = body + record.Substring(0, record.Length - 1) + System.Environment.NewLine;
            //body.Append(body);
            body.Append(record.ToString().Substring(0, record.Length - 1) + System.Environment.NewLine);
            record.Remove(0, record.Length);
        }
        //if (exportcolumnheadings)
        //{
        columnnames.Append(System.Environment.NewLine);
        return (columnnames.Append(body.ToString()));
        //}
        //else
        //{
        //    return (body);
        //}
    }
    /// <summary>
    /// To change the date time format of the fields in the dataset.
    /// </summary>
    private string ChangeDateTimeFormats()
    {
        string ErrorStatus = "Success";
        //To change the date format of the dataset in the specified format.
        dsCustomFields.Tables[0].DefaultView.RowFilter = "FieldType='Date'";
        if (dsCustomFields.Tables[0].DefaultView.Table.Rows.Count > 0)
        {
            if (dsCustomFormat.Tables.Count > 0)
            {
                if (dsCustomFormat.Tables[0].Rows.Count > 0)
                {
                    if ((dsCustomFormat.Tables[0].Rows[0]["DateFormat"].ToString() != string.Empty) || (dsCustomFormat.Tables[0].Rows[0]["DateFormat"] != null))
                    {
                        string DateFormat = dsCustomFormat.Tables[0].Rows[0]["DateFormat"].ToString();
                        foreach (DataRow rowDefaultView in dsCustomFields.Tables[0].DefaultView.ToTable().Rows)
                        {
                            foreach (DataRow rowPayRollProcess in dsPayrollProcess.Tables[0].Rows)
                            {
                                try
                                {
                                    string FieldName = rowDefaultView["FieldName"].ToString();
                                    string FieldData = rowPayRollProcess[FieldName].ToString();
                                    if (FieldData != string.Empty)
                                    {
                                        string ConvertedData = DateTime.Parse(FieldData).ToString(DateFormat);
                                        rowPayRollProcess[FieldName] = ConvertedData;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ErrorStatus = "Date";
                                    return ErrorStatus;
                                }
                            }
                        }
                    }
                }
            }
        }
        //To change the time format of the dataset in the specified format.
        dsCustomFields.Tables[0].DefaultView.RowFilter = "FieldType='Time'";
        if (dsCustomFields.Tables[0].DefaultView.Table.Rows.Count > 0)
        {
            if (dsCustomFormat.Tables.Count > 0)
            {
                if (dsCustomFormat.Tables[0].Rows.Count > 0)
                {
                    if ((dsCustomFormat.Tables[0].Rows[0]["TimeFormat"].ToString() != string.Empty) || (dsCustomFormat.Tables[0].Rows[0]["TimeFormat"] != null))
                    {
                        string TimeFormat = dsCustomFormat.Tables[0].Rows[0]["TimeFormat"].ToString();
                        foreach (DataRow rowDefaultView in dsCustomFields.Tables[0].DefaultView.ToTable().Rows)
                        {
                            foreach (DataRow rowPayRollProcess in dsPayrollProcess.Tables[0].Rows)
                            {
                                try
                                {
                                    string FieldName = rowDefaultView["FieldName"].ToString();
                                    string FieldData = rowPayRollProcess[FieldName].ToString();
                                    if (FieldData != string.Empty)
                                    {
                                        string ConvertedData = DateTime.Parse(FieldData).ToString(TimeFormat);
                                        rowPayRollProcess[FieldName] = ConvertedData;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ErrorStatus = "Time";
                                    return ErrorStatus;
                                }
                            }
                        }
                    }
                }
            }
        }
        //To change the time format of the dataset in the specified format.
        dsCustomFields.Tables[0].DefaultView.RowFilter = "FieldType='Date&Time'";
        if (dsCustomFields.Tables[0].DefaultView.Table.Rows.Count > 0)
        {
            if (dsCustomFormat.Tables.Count > 0)
            {
                if (dsCustomFormat.Tables[0].Rows.Count > 0)
                {
                    if ((dsCustomFormat.Tables[0].Rows[0]["DateTimeFormat"].ToString() != string.Empty) || (dsCustomFormat.Tables[0].Rows[0]["DateTimeFormat"] != null))
                    {
                        string DateTimeFormat = dsCustomFormat.Tables[0].Rows[0]["DateTimeFormat"].ToString();
                        foreach (DataRow rowDefaultView in dsCustomFields.Tables[0].DefaultView.ToTable().Rows)
                        {
                            foreach (DataRow rowPayRollProcess in dsPayrollProcess.Tables[0].Rows)
                            {
                                try
                                {
                                    string FieldName = rowDefaultView["FieldName"].ToString();
                                    string FieldData = rowPayRollProcess[FieldName].ToString();
                                    if (FieldData != string.Empty)
                                    {
                                        string ConvertedData = DateTime.Parse(FieldData).ToString(DateTimeFormat);
                                        rowPayRollProcess[FieldName] = ConvertedData;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ErrorStatus = "DateTime";
                                    return ErrorStatus;
                                }
                            }
                        }
                    }
                }
            }
        }
        return ErrorStatus;
    }
    // **********************************************************************************************************************
    // Function Name : FillYearDropdown
    // Purpose :
    //     The FillYearDropdown Method is used to fill the years in the Year DropDown List. 
    // **********************************************************************************************************************
    //private void FillYearDropdown()
    //{
    //    // Get the Current Year
    //    int year = System.DateTime.Now.Year;
    //    int StartYear = year - 10;
    //    // Insert the year starting from Current Year upto 10 years ahead in the Year DropDown List
    //    for (int i = StartYear; i <= year; i++)
    //    {
    //        ddl_Year.Items.Add(i.ToString());
    //    }
    //    // Insert Default Item -Select- in the Year DropDown List
    //    ddl_Year.Items.Insert(0, "-Select-");
    //}
    private void FillFieldListBox()
    {
        DataSet dsPayrollFieldNames = new DataSet();
        dsPayrollFieldNames = objExportData.GetCustomFieldNamesForExportData("All", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
        if (dsPayrollFieldNames != null)
        {
            if (dsPayrollFieldNames.Tables[0].Rows.Count == 0)
            {
                dsPayrollFieldNames = objMonthClosureEventData.GetPayrollFieldNames(rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                if (dsPayrollFieldNames.Tables[0].Rows.Count > 0)
                {
                    lst_PayrollFieldList.DataSource = dsPayrollFieldNames;
                    lst_PayrollFieldList.DataTextField = "FieldName";
                    //lst_PayrollFieldList.DataTextField = "Description";
                    lst_PayrollFieldList.DataValueField = "FieldName";
                    lst_PayrollFieldList.DataBind();
                }
            }
            else
            {
                lst_PayrollFieldList.DataSource = dsPayrollFieldNames;
                lst_PayrollFieldList.DataTextField = "column_name";
                //lst_PayrollFieldList.DataTextField = "Description";
                lst_PayrollFieldList.DataValueField = "FieldName";
                lst_PayrollFieldList.DataBind();
            }
            foreach (ListItem item in lst_PayrollFieldList.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }
    public string Export(DataSet ds, Boolean exportcolumnheadings, string month, int year, string strReason)
    {
        string columnnames = "", body = "", record = "";
        //string header = "";
        if (exportcolumnheadings)
        {
            //columnnames = columnnames + " Month " + ",";
            ///columnnames = columnnames + " Year " + ",";
            foreach (DataColumn col in ds.Tables[0].Columns)
            {
                columnnames = columnnames + col.ColumnName + ",";
            }
            //columnnames = columnnames + "remarks,";
            columnnames = columnnames.Substring(0, columnnames.Length - 1);
        }
        foreach (DataRow row in ds.Tables[0].Rows)
        {
            object[] arr = row.ItemArray;
            //record = record + "" + month + "" + ",";
            //record = record + "" + year + "" + ",";
            for (int i = 0; i <= arr.Length - 1; i++)
            {
                if (arr[i].ToString().IndexOf(",") > 0)
                {
                    record = record + arr[i].ToString() + ",";
                }
                else
                {
                    record = record + arr[i].ToString() + ",";
                }
            }
            record = record + "" + strReason + ",";
            body = body + record.Substring(0, record.Length - 1) + System.Environment.NewLine;
            record = "";
        }
        if (exportcolumnheadings)
        {
            return (columnnames + System.Environment.NewLine + body);
        }
        else
        {
            return (body);
        }
    }
    // Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lblHeader_ExportData.Text = rm.GetString("SystemSettings_Exportdata", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        //lbl_Year.Text = rm.GetString("PayrollProcess_Year", ci);
        //lbl_Month.Text = rm.GetString("PayrollProcess_Month", ci); 
        //RequiredFieldValidator7.ErrorMessage = rm.GetString("Alert_SelectMonth", ci);
        //RequiredFieldValidator8.ErrorMessage = rm.GetString("Alert_SelectYear", ci);
        lbl_FieldList.Text = rm.GetString("ExportData_FieldList", ci);
        lbl_SelectedFieldList.Text = rm.GetString("ExportData_SelectedFieldList", ci);
        btn_Export.Text = rm.GetString("btn_Export", ci);
        //lblOption.Text = rm.GetString("Choice", ci);
        lblCompany.Text = rm.GetString("EntranceMaster_Company", ci);
        lblDuration.Text = rm.GetString("Report_Duration", ci);
        rbOption.Items[0].Text = rm.GetString("ExportData_All", ci);
        rbOption.Items[1].Text = rm.GetString("ExportData_OTData", ci);
        rbOption.Items[2].Text = rm.GetString("Dashboard_AttData", ci);
        RequiredFieldValidator8.ErrorMessage = rm.GetString("Alert_SelectDuration", ci);
        RequiredFieldValidator2.ErrorMessage = rm.GetString("Alert_Select_Company", ci);
        ddlCompany.Items[0].Text = rm.GetString("Select", ci);
        ddlDuration.Items[0].Text = rm.GetString("Select", ci);
        rbExportToXLS.Text = rm.GetString("Caption_ExportToXLS", ci);
        rbExportToCSV.Text = rm.GetString("Caption_ExportToCSV", ci);
        rbExportToXML.Text = rm.GetString("Caption_ExportToXML", ci);
        lblConfiguration.Text = rm.GetString("Caption_Configuration", ci);
        lnkCustomFields.Text = rm.GetString("Caption_CustomFields", ci);
        rblMonthDateWise.Items[0].Text = rm.GetString("Caption_SummarizedData", ci);
        rblMonthDateWise.Items[1].Text = rm.GetString("Caption_DailyData", ci);
        lblDataType.Text = rm.GetString("Caption_DataType", ci);
        lblOption.Text = rm.GetString("Option", ci);
    }
    protected void BindFields()
    {
        if (ddlCompany.SelectedValue == "-Select-")
        {
            string strScript;
            strScript = "<script language='javascript'>";
            strScript = strScript + "alert('Select Company');";
            strScript = strScript + " </script>";
            Page.RegisterStartupScript("Select Company", strScript);
            return;
        }
        lst_PayrollSelectedFieldList.Items.Clear();
        if (rbOption.SelectedIndex == 0)
        {
            //All
            rblMonthDateWise.Items[1].Enabled = true;
            DataSet dsPayrollFieldNames = new DataSet();
            dsPayrollFieldNames = objExportData.GetCustomFieldNamesForExportData("All", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
            if (dsPayrollFieldNames != null)
            {
                if (dsPayrollFieldNames.Tables[0].Rows.Count == 0)
                {
                    dsPayrollFieldNames = objMonthClosureEventData.GetPayrollFieldNames(rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                    if (dsPayrollFieldNames.Tables[0].Rows.Count > 0)
                    {
                        lst_PayrollFieldList.DataSource = dsPayrollFieldNames;
                        lst_PayrollFieldList.DataTextField = "FieldName";
                        //lst_PayrollFieldList.DataTextField = "Description";
                        //lst_PayrollFieldList.DataValueField = "ColumnName";
                        lst_PayrollFieldList.DataValueField = "FieldName";
                        lst_PayrollFieldList.DataBind();
                    }
                }
                else
                {
                    lst_PayrollFieldList.DataSource = dsPayrollFieldNames;
                    lst_PayrollFieldList.DataTextField = "column_name";
                    //lst_PayrollFieldList.DataTextField = "Description";
                    lst_PayrollFieldList.DataValueField = "FieldName";
                    lst_PayrollFieldList.DataBind();
                }
                foreach (ListItem item in lst_PayrollFieldList.Items)
                {
                    item.Attributes.Add("title", item.Text);
                }
            }
            btn_Add.Enabled = true;
            btn_AddAll.Enabled = true;
            btn_Remove.Enabled = true;
            btn_RemoveAll.Enabled = true;
        }
        else if (rbOption.SelectedIndex == 1)
        {
            lst_PayrollFieldList.Items.Clear();
            rblMonthDateWise.Items[1].Enabled = false;
            rblMonthDateWise.SelectedIndex = 0;
            btn_Add.Enabled = false;
            btn_AddAll.Enabled = false;
            btn_Remove.Enabled = false;
            btn_RemoveAll.Enabled = false;
            //Over Time
            DataSet dsPayrollFieldNames = new DataSet();
            dsPayrollFieldNames = objExportData.GetCustomFieldNamesForExportData("OT", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
            if (dsPayrollFieldNames != null)
            {
                if (dsPayrollFieldNames.Tables[0].Rows.Count > 0)
                {
                    lst_PayrollSelectedFieldList.DataSource = dsPayrollFieldNames;
                    //lst_PayrollFieldList.DataTextField = "column_name";
                    lst_PayrollSelectedFieldList.DataTextField = "column_name";
                    lst_PayrollSelectedFieldList.DataValueField = "FieldName";
                    lst_PayrollSelectedFieldList.DataBind();
                }
                else
                {
                    lst_PayrollSelectedFieldList.Items.Clear();
                    lst_PayrollSelectedFieldList.Items.Add("employee_code");
                    lst_PayrollSelectedFieldList.Items.Add("pay_month");
                    lst_PayrollSelectedFieldList.Items.Add("pay_year");
                    lst_PayrollSelectedFieldList.Items.Add("ot_type");
                    lst_PayrollSelectedFieldList.Items.Add("ot_hours");
                    //lst_PayrollSelectedFieldList.Items.Add("remarks");
                }
            }
            else
            {
                lst_PayrollSelectedFieldList.Items.Clear();
                lst_PayrollSelectedFieldList.Items.Add("employee_code");
                lst_PayrollSelectedFieldList.Items.Add("pay_month");
                lst_PayrollSelectedFieldList.Items.Add("pay_year");
                lst_PayrollSelectedFieldList.Items.Add("ot_type");
                lst_PayrollSelectedFieldList.Items.Add("ot_hours");
                //lst_PayrollSelectedFieldList.Items.Add("remarks");
            }
            foreach (ListItem item in lst_PayrollSelectedFieldList.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
        else if (rbOption.SelectedIndex == 2)
        {
            lst_PayrollFieldList.Items.Clear();
            rblMonthDateWise.Items[1].Enabled = false;
            rblMonthDateWise.SelectedIndex = 0;
            btn_Add.Enabled = false;
            btn_AddAll.Enabled = false;
            btn_Remove.Enabled = false;
            btn_RemoveAll.Enabled = false;
            //Attandance
            DataSet dsPayrollFieldNames = new DataSet();
            dsPayrollFieldNames = objExportData.GetCustomFieldNamesForExportData("Attendance", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
            if (dsPayrollFieldNames != null)
            {
                if (dsPayrollFieldNames.Tables[0].Rows.Count > 0)
                {
                    lst_PayrollSelectedFieldList.DataSource = dsPayrollFieldNames;
                    //lst_PayrollFieldList.DataTextField = "column_name";
                    lst_PayrollSelectedFieldList.DataTextField = "column_name";
                    lst_PayrollSelectedFieldList.DataValueField = "FieldName";
                    lst_PayrollSelectedFieldList.DataBind();
                }
                else
                {
                    lst_PayrollSelectedFieldList.Items.Clear();
                    lst_PayrollSelectedFieldList.Items.Add("employee_code");
                    lst_PayrollSelectedFieldList.Items.Add("pay_month");
                    lst_PayrollSelectedFieldList.Items.Add("pay_year");
                    lst_PayrollSelectedFieldList.Items.Add("attn_code");
                    lst_PayrollSelectedFieldList.Items.Add("no_of_days");
                    //lst_PayrollSelectedFieldList.Items.Add("remarks");
                }
            }
            else
            {
                lst_PayrollSelectedFieldList.Items.Clear();
                lst_PayrollSelectedFieldList.Items.Add("employee_code");
                lst_PayrollSelectedFieldList.Items.Add("pay_month");
                lst_PayrollSelectedFieldList.Items.Add("pay_year");
                lst_PayrollSelectedFieldList.Items.Add("attn_code");
                lst_PayrollSelectedFieldList.Items.Add("no_of_days");
                //lst_PayrollSelectedFieldList.Items.Add("remarks");
            }
            foreach (ListItem item in lst_PayrollSelectedFieldList.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
        else if (rbOption.SelectedIndex == 3)
        {
            lst_PayrollFieldList.Items.Clear();
            //rblMonthDateWise.Items[1].Enabled = false;
            //rblMonthDateWise.SelectedIndex = 0;
            rblMonthDateWise.Items[1].Enabled = true;
            btn_Add.Enabled = false;
            btn_AddAll.Enabled = false;
            btn_Remove.Enabled = false;
            btn_RemoveAll.Enabled = false;
            //Leave
            DataSet dsPayrollFieldNames = new DataSet();
            dsPayrollFieldNames = objExportData.GetCustomFieldNamesForExportData("Leave", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
            if (dsPayrollFieldNames != null)
            {
                if (dsPayrollFieldNames.Tables[0].Rows.Count > 0)
                {
                    lst_PayrollSelectedFieldList.DataSource = dsPayrollFieldNames;
                    //lst_PayrollFieldList.DataTextField = "column_name";
                    lst_PayrollSelectedFieldList.DataTextField = "column_name";
                    lst_PayrollSelectedFieldList.DataValueField = "FieldName";
                    lst_PayrollSelectedFieldList.DataBind();
                }
                else
                {
                    if (rblMonthDateWise.SelectedIndex == 0)
                    {
                        lst_PayrollSelectedFieldList.Items.Clear();
                        lst_PayrollSelectedFieldList.Items.Add("Employee_Code_Id");
                        //lst_PayrollSelectedFieldList.Items.Add("EmployeeName");
                        //lst_PayrollSelectedFieldList.Items.Add("LeaveDate");
                        //lst_PayrollSelectedFieldList.Items.Add("LeaveType");
                        lst_PayrollSelectedFieldList.Items.Add("NoOfDays");
                    }
                    else
                    {
                        lst_PayrollSelectedFieldList.Items.Clear();
                        lst_PayrollSelectedFieldList.Items.Add("Employee_Code_Id");
                        lst_PayrollSelectedFieldList.Items.Add("Leave_FromDate");
                        lst_PayrollSelectedFieldList.Items.Add("Leave_Todate");
                        lst_PayrollSelectedFieldList.Items.Add("LeaveType");
                        lst_PayrollSelectedFieldList.Items.Add("NoOfDays");
                        lst_PayrollSelectedFieldList.Items.Add("TransactionType");
                    }
                }
                foreach (ListItem item in lst_PayrollSelectedFieldList.Items)
                {
                    item.Attributes.Add("title", item.Text);
                }
            }
            else
            {
                if (rblMonthDateWise.SelectedIndex == 0)
                {
                    lst_PayrollSelectedFieldList.Items.Clear();
                    lst_PayrollSelectedFieldList.Items.Add("Employee_Code_Id");
                    //lst_PayrollSelectedFieldList.Items.Add("EmployeeName");
                    //lst_PayrollSelectedFieldList.Items.Add("LeaveDate");
                    //lst_PayrollSelectedFieldList.Items.Add("LeaveType");
                    lst_PayrollSelectedFieldList.Items.Add("NoOfDays");
                }
                else
                {
                    lst_PayrollSelectedFieldList.Items.Clear();
                    lst_PayrollSelectedFieldList.Items.Add("Employee_Code_Id");
                    lst_PayrollSelectedFieldList.Items.Add("Leave_FromDate");
                    lst_PayrollSelectedFieldList.Items.Add("Leave_Todate");
                    lst_PayrollSelectedFieldList.Items.Add("LeaveType");
                    lst_PayrollSelectedFieldList.Items.Add("NoOfDays");
                    lst_PayrollSelectedFieldList.Items.Add("TransactionType");
                }
            }
        }
    }
    public string DataTable2ExcelString(System.Data.DataTable dt)
    {
        StringBuilder sbTop = new StringBuilder();
        sbTop.Append("<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" ");
        sbTop.Append("xmlns=\"http://www.w3.org/TR/REC-html40\"><head><meta http-equiv=Content-Type content=\"text/html; charset=windows-1252\">");
        sbTop.Append("<meta name=ProgId content=Excel.Sheet><meta name=Generator content=\"Microsoft Excel 9\"><!--[if gte mso 9]>");
        sbTop.Append("<xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>" + dt.TableName + "</x:Name><x:WorksheetOptions>");
        sbTop.Append("<x:Selected/><x:ProtectContents>False</x:ProtectContents><x:ProtectObjects>False</x:ProtectObjects>");
        sbTop.Append("<x:ProtectScenarios>False</x:ProtectScenarios></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets>");
        sbTop.Append("<x:ProtectStructure>False</x:ProtectStructure><x:ProtectWindows>False</x:ProtectWindows></x:ExcelWorkbook></xml>");
        sbTop.Append("<![endif]--></head><body><table>");
        string bottom = "</table></body></html>";
        StringBuilder sb = new StringBuilder();
        //Header
        sb.Append("<tr>");
        for (int i = 0; i < dt.Columns.Count; i++)
        {
            sb.Append("<td>" + dt.Columns[i].ColumnName + "</td>");
        }
        sb.Append("</tr>");
        //Items
        for (int x = 0; x < dt.Rows.Count; x++)
        {
            sb.Append("<tr>");
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                sb.Append("<td>" + dt.Rows[x][i] + "</td>");
            }
            sb.Append("</tr>");
        }
        string SSxml = sbTop.ToString() + sb.ToString() + bottom;
        return SSxml;
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(66, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("SystemLandingPage.aspx");
        }
        else
        {
            //   
        }
    }
    #endregion
    #region ButtonEvents
    //To apply toot tip for the list box items
    private void LB_PreRender(object sender, System.EventArgs e)
    {
        foreach (ListItem item in lst_PayrollFieldList.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e)
    {
        hdn_SelectedFieldNames.Value = string.Empty;
        int companyId;
        if (ddlCompany.SelectedValue != "-Select-")
        {
            companyId = Convert.ToInt32(ddlCompany.SelectedValue);
            filldurationDetails(companyId);
        }
        else
        {
            ddlDuration.DataSource = "";
            ddlDuration.DataBind();
            ddlDuration.Items.Insert(0, "-Select-");
            lst_PayrollFieldList.Items.Clear();
            lst_PayrollSelectedFieldList.Items.Clear();
        }
    }
    protected void rbOption_SelectedIndexChanged(object sender, EventArgs e)
    {
        hdnSelectedOption.Value = rbOption.SelectedValue;
        BindFields();
        string strScript;
        strScript = "<script language='javascript'>";
        strScript = strScript + "FillHiddenField();";
        strScript = strScript + " </script>";
        Page.RegisterStartupScript("FillHiddenField", strScript);
    }
    protected void rblMonthDateWise_SelectedIndexChanged(object sender, EventArgs e)
    {
        hdnSelectedDataType.Value = rblMonthDateWise.SelectedValue;
        hdn_SelectedFieldNames.Value = string.Empty;
        if (rbOption.SelectedIndex == 3 && rblMonthDateWise.SelectedIndex == 0)
        {
            //Leave
            DataSet dsPayrollFieldNames = new DataSet();
            dsPayrollFieldNames = objExportData.GetCustomFieldNamesForExportData("Leave", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
            if (dsPayrollFieldNames != null)
            {
                if (dsPayrollFieldNames.Tables[0].Rows.Count > 0)
                {
                    lst_PayrollSelectedFieldList.DataSource = dsPayrollFieldNames;
                    //lst_PayrollFieldList.DataTextField = "column_name";
                    lst_PayrollSelectedFieldList.DataTextField = "column_name";
                    lst_PayrollSelectedFieldList.DataValueField = "FieldName";
                    lst_PayrollSelectedFieldList.DataBind();
                    //foreach (ListItem li in lst_PayrollSelectedFieldList.Items)
                    //{
                    //    if (li.Value == "LeaveDate" || li.Value == "LeaveType")
                    //    {
                    //        lst_PayrollSelectedFieldList.Items.Remove(lst_PayrollSelectedFieldList.Items[2]);
                    //        lst_PayrollSelectedFieldList.Items.Remove(lst_PayrollSelectedFieldList.Items[3]);
                    //    }
                    //}
                }
                else
                {
                    lst_PayrollSelectedFieldList.Items.Clear();
                    lst_PayrollSelectedFieldList.Items.Add("Employee_Code_Id");
                    //lst_PayrollSelectedFieldList.Items.Add("EmployeeName");
                    //lst_PayrollSelectedFieldList.Items.Add("LeaveDate");
                    //lst_PayrollSelectedFieldList.Items.Add("LeaveType");
                    lst_PayrollSelectedFieldList.Items.Add("NoOfDays");
                }
            }
            else
            {
                lst_PayrollSelectedFieldList.Items.Clear();
                lst_PayrollSelectedFieldList.Items.Add("Employee_Code_Id");
                //lst_PayrollSelectedFieldList.Items.Add("EmployeeName");
                //lst_PayrollSelectedFieldList.Items.Add("LeaveDate");
                //lst_PayrollSelectedFieldList.Items.Add("LeaveType");
                lst_PayrollSelectedFieldList.Items.Add("NoOfDays");
            }
            foreach (ListItem item in lst_PayrollSelectedFieldList.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
        string strScript;
        strScript = "<script language='javascript'>";
        strScript = strScript + "FillHiddenField();";
        strScript = strScript + " </script>";
        Page.RegisterStartupScript("FillHiddenField", strScript);
    }
    protected void btn_Export_Click(object sender, EventArgs e)
    {
        DataTable dtMonthCloseDetails = new DataTable();
        int intMonthClosureId = Convert.ToInt32(ddlDuration.SelectedValue);
        // Get the Details of the Payroll Process Details for a particular Month Closure ID by passing the Month Closure ID
        DataSet dsMonthCloseDetails = objMonthClosureEventData.SelectMonthCloseDetailsByIDview(intMonthClosureId);
        dtMonthCloseDetails = dsMonthCloseDetails.Tables[0];
        string strCurrentDateTime = string.Empty;
        strCurrentDateTime = "_" + DateTime.Now.ToString("dd-MMM-yyyy").Replace("-", "").ToString() + "_" + DateTime.Now.ToString("hh:mm tt").Replace(":", "_").ToString().Replace(" ", "").ToString();
        // If Record Exists
        if (dtMonthCloseDetails.Rows.Count > 0)
        {
            if (dtMonthCloseDetails.Rows[0]["MonthClosure_Month"] != DBNull.Value)
            {
                strMonthName = dtMonthCloseDetails.Rows[0]["MonthClosure_Month"].ToString();
            }
            if (dtMonthCloseDetails.Rows[0]["MonthClosure_Year"] != DBNull.Value)
            {
                intYear = Convert.ToInt32(dtMonthCloseDetails.Rows[0]["MonthClosure_Year"].ToString());
            }
            if (dtMonthCloseDetails.Rows[0]["MonthClosure_StartDate"] != DBNull.Value)
            {
                //strMonthValue = Convert.ToDateTime((DateTime.Parse(dtMonthCloseDetails.Rows[0]["MonthClosure_StartDate"].ToString())).ToString(Session["MDateFormat"].ToString())).Month.ToString();
                strMonthValue = Convert.ToDateTime(dtMonthCloseDetails.Rows[0]["MonthClosure_StartDate"].ToString()).Month.ToString();
            }
        }
        bool blnProcessDataExists = false;
        string strHead = "";
        strHead = "<HTML xmlns:x='urn:schemas-microsoft-com:office:excel'>";
        strHead += "<HEAD><meta charset='utf-8'><style type=\"text/css\">  <!--table";
        strHead += "  @page {mso-header-data:'&CMultiplication Table\\000ADate\\: &D\\000APage &P';mso-page-orientation:landscape;}";
        strHead += "br{mso-data-placement:same-cell;}";
        strHead += "--></style>";
        strHead += "<!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>";
        strHead += "<x:Name>Sheet1</x:Name><x:WorksheetOptions><x:Print><x:ValidPrinterInfo/>";
        strHead += "</x:Print></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook>";
        strHead += "</xml><![endif]--></HEAD><body><table><tr>";
        //If All option is selected
        if (rbOption.SelectedIndex == 0)
        {
            if (hdn_SelectedFieldNames.Value == "")
            {
                //lbl_Error.Text = "Add the Field Names in the Selected Field List";
                // base.Message("Select Fields from the field list");
                base.Message(rm.GetString("Alert_SelectFieldsfromthefieldlist", ci));
                return;
            }
            Rpt_Common rptcommon = new Rpt_Common();
            string strLevel = "";
            strLevel = rptcommon.getNodes(Convert.ToInt16(ddlCompany.SelectedValue), Convert.ToString(Session["LevelRights"]));
            dsPayrollProcess = objMonthClosureEventData.Payroll(hdn_SelectedFieldNames.Value, strMonthName, intYear, Convert.ToInt16(ddlCompany.SelectedValue), strLevel, strMonthValue, intMonthClosureId, Convert.ToString(Session["UserGroupName"]), Convert.ToInt16(ddlCompany.SelectedValue), rblMonthDateWise.SelectedValue);
            //dsPayrollProcess = objMonthClosureEventData.Payroll(hdn_SelectedFieldNames.Value, ddl_Month.SelectedItem.Text, int.Parse(ddl_Year.SelectedItem.Text), Convert.ToInt16(ddlCompany.SelectedValue), strLevel, ddl_Month.SelectedValue);
            if (dsPayrollProcess.Tables.Count > 0)
            {
                if (dsPayrollProcess.Tables[0].Rows.Count > 0)
                {
                    blnProcessDataExists = true;
                    //To get custom formats.
                    dsCustomFormat = objExportData.GetCustomFormatsForExportData("All", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                    //To get custom field names.
                    dsCustomFields = objExportData.GetCustomFieldNamesForExportData("All", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                    ChangeDateTimeFormats();
                    //To change  the column name of the dataset with custom field name.
                    if (dsCustomFields.Tables.Count > 0)
                    {
                        if (dsCustomFields.Tables[0].Rows.Count > 0)
                        {
                            Hashtable CustomFields = new Hashtable();
                            foreach (DataRow row in dsCustomFields.Tables[0].Rows)
                            {
                                CustomFields.Add(row["FieldName"], row["UserDefinedFieldName"]);
                            }
                            foreach (DataColumn col in dsPayrollProcess.Tables[0].Columns)
                            {
                                if (CustomFields.Contains(col.ColumnName))
                                {
                                    if (CustomFields[col.ColumnName].ToString() != string.Empty)
                                    {
                                        col.ColumnName = CustomFields[col.ColumnName].ToString();
                                    }
                                }
                            }
                        }
                    }
                    if (rbExportToXLS.Checked == true)
                    {
                        if (rbFTPNo.Checked == true)
                        {
                            dsPayrollProcess.Tables[0].TableName = "Sheet 1";
                            DataTable dt = dsPayrollProcess.Tables[0];
                            dt.TableName = "Sheet 1";
                            string attachment = "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls";
                            //attachment += "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Payroll_" + ddl_Month.SelectedItem.Text + "_" + ddl_Year.SelectedItem.Text + ".xls";
                            Response.ClearContent();
                            Response.AddHeader("content-disposition", attachment);
                            Response.ContentType = "application/vnd.ms-excel";
                            string tab = "";
                            Response.Write(strHead);
                            foreach (DataColumn dc in dt.Columns)
                            {
                                Response.Write("<td>" + dc.ColumnName + "</td>");
                            }
                            Response.Write("</tr><tr>");
                            int i;
                            foreach (DataRow dr in dt.Rows)
                            {
                                tab = "";
                                for (i = 0; i < dt.Columns.Count; i++)
                                {
                                    Response.Write("<td>" + dr[i].ToString() + "</td>");
                                }
                                Response.Write("</tr><tr>");
                            }
                            Response.Write("</tr></BODY></HTML>");
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            StreamWriter sw = new StreamWriter(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls"), false);
                            StringBuilder strExcelData = new StringBuilder();
                            strExcelData.Append(strHead);
                            foreach (DataColumn dc in dsPayrollProcess.Tables[0].Columns)
                            {
                                strExcelData.Append("<td>" + dc.ColumnName + "</td>");
                            }
                            strExcelData.Append("</tr><tr>");
                            int i;
                            foreach (DataRow dr in dsPayrollProcess.Tables[0].Rows)
                            {
                                for (i = 0; i < dsPayrollProcess.Tables[0].Columns.Count; i++)
                                {
                                    strExcelData.Append("<td>" + dr[i].ToString() + "</td>");
                                }
                                strExcelData.Append("</tr><tr>");
                            }
                            strExcelData.Append("</tr></BODY></HTML>");
                            sw.Write(strExcelData.ToString());
                            sw.Close();
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + "');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert('" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls" + " : Uploaded sucessfully ');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    else if (rbExportToCSV.Checked == true)
                    {
                        StringBuilder strData = Export(dsPayrollProcess);
                        if (rbFTPNo.Checked == true)
                        {
                            byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(strData.ToString());
                            string attachment = "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv";
                            Response.Clear();
                            Response.AddHeader("Content-Type", "application/Excel");
                            Response.AddHeader("Content-Disposition", attachment);
                            Response.BinaryWrite(data);
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            StreamWriter sw = new StreamWriter(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv"), false);
                            sw.Write(strData.ToString());
                            sw.Close();
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv" + " : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    else if (rbExportToXML.Checked == true)
                    {
                        if (rbFTPNo.Checked == true)
                        {
                            // Get a StreamWriter object
                            //StreamWriter xmlDoc = new StreamWriter(Server.MapPath("~Testdo.xml"), false);
                            // Apply the WriteXml method to write an XML document
                            // dsPayrollProcess.WriteXml(xmlDoc);
                            //xmlDoc.Close();
                            if (dsCustomFormat.Tables.Count > 0)
                            {
                                if (dsCustomFormat.Tables[0].Rows.Count > 0)
                                {
                                    if (dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString() != string.Empty)
                                    {
                                        dsPayrollProcess.DataSetName = dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString();
                                    }
                                    if (dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString() != string.Empty)
                                    {
                                        dsPayrollProcess.Tables[0].TableName = dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString();
                                    }
                                }
                            }
                            //string strXMLData = dsPayrollProcess.GetXml();
                            //Response.ContentType = "text/xml";
                            //Response.AddHeader("content-disposition", "attachment; filename=\"ExportData_All.xml\"");
                            //Response.Write(strXMLData);
                            //Response.End();
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            dsPayrollProcess.Tables[0].WriteXml(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml"));
                            Response.ContentType = "text/xml";
                            string strFile = Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml");
                            Response.AddHeader("content-disposition", "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml");
                            Response.WriteFile(strFile);
                            Response.Flush();
                            Response.End();
                        }
                        else
                        {
                            if (dsCustomFormat.Tables.Count > 0)
                            {
                                if (dsCustomFormat.Tables[0].Rows.Count > 0)
                                {
                                    if (dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString() != string.Empty)
                                    {
                                        dsPayrollProcess.DataSetName = dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString();
                                    }
                                    if (dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString() != string.Empty)
                                    {
                                        dsPayrollProcess.Tables[0].TableName = dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString();
                                    }
                                }
                            }
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            dsPayrollProcess.Tables[0].WriteXml(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml"));
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml" + "  : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                            //Response.ContentType = "text/xml";
                            //string strFile = Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + ".xml");
                            //Response.AddHeader("content-disposition", "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Payroll_" + strMonthName + "_" + intYear.ToString() + ".xml");
                            //Response.WriteFile(strFile);
                            //Response.Flush();
                            //Response.End();
                        }
                    }
                }
            }
        }
        //If OT option is selected
        else if (rbOption.SelectedIndex == 1)
        {
            //by overtime
            Rpt_Common rptcommon = new Rpt_Common();
            string strLevel = "";
            strLevel = rptcommon.getNodes(Convert.ToInt16(ddlCompany.SelectedValue), Convert.ToString(Session["LevelRights"]));
            dsPayrollProcess = objMonthClosureEventData.PayrollByOverTime(hdn_SelectedFieldNames.Value, strMonthName, intYear, Convert.ToInt16(ddlCompany.SelectedValue), strLevel, strMonthValue, intMonthClosureId, Convert.ToString(Session["UserGroupName"]), Convert.ToInt16(ddlCompany.SelectedValue));
            //dsPayrollProcess = objMonthClosureEventData.PayrollByOverTime(hdn_SelectedFieldNames.Value, ddl_Month.SelectedItem.Text, int.Parse(ddl_Year.SelectedItem.Text), Convert.ToInt16(ddlCompany.SelectedValue), strLevel, ddl_Month.SelectedValue);
            if (dsPayrollProcess.Tables.Count > 0)
            {
                //dsPayrollProcess.Tables[0].WriteXmlSchema(@"e:\ExportOT.xml");
                if (dsPayrollProcess.Tables[0].Rows.Count > 0)
                {
                    blnProcessDataExists = true;
                    //To get custom formats.
                    dsCustomFormat = objExportData.GetCustomFormatsForExportData("OT", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                    //To get custom field names.
                    dsCustomFields = objExportData.GetCustomFieldNamesForExportData("OT", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                    ChangeDateTimeFormats();
                    //To change  the column name of the dataset with custom field name.
                    if (dsCustomFields.Tables.Count > 0)
                    {
                        if (dsCustomFields.Tables[0].Rows.Count > 0)
                        {
                            Hashtable CustomFields = new Hashtable();
                            foreach (DataRow row in dsCustomFields.Tables[0].Rows)
                            {
                                CustomFields.Add(row["FieldName"], row["UserDefinedFieldName"]);
                            }
                            foreach (DataColumn col in dsPayrollProcess.Tables[0].Columns)
                            {
                                if (CustomFields.Contains(col.ColumnName))
                                {
                                    if (CustomFields[col.ColumnName].ToString() != string.Empty)
                                    {
                                        col.ColumnName = CustomFields[col.ColumnName].ToString();
                                    }
                                }
                            }
                        }
                    }
                    //Export to XLS
                    if (rbExportToXLS.Checked == true)
                    {
                        if (rbFTPNo.Checked == true)
                        {
                            dsPayrollProcess.Tables[0].TableName = "Sheet 1";
                            DataTable dt = dsPayrollProcess.Tables[0];
                            dt.TableName = "Sheet 1";
                            string attachment = "attachment; filename=" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls";
                            //attachment += "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Payroll_" + ddl_Month.SelectedItem.Text + "_" + ddl_Year.SelectedItem.Text + ".xls";
                            Response.ClearContent();
                            Response.AddHeader("content-disposition", attachment);
                            Response.ContentType = "application/vnd.ms-excel";
                            string tab = "";
                            Response.Write(strHead);
                            foreach (DataColumn dc in dt.Columns)
                            {
                                Response.Write("<td>" + dc.ColumnName + "</td>");
                                //tab = "\t";
                            }
                            //Response.Write("\n");
                            Response.Write("</tr><tr>");
                            int i;
                            foreach (DataRow dr in dt.Rows)
                            {
                                tab = "";
                                for (i = 0; i < dt.Columns.Count; i++)
                                {
                                    Response.Write("<td>" + dr[i].ToString() + "</td>");
                                    // tab = "\t";
                                }
                                Response.Write("</tr><tr>");
                            }
                            Response.Write("</tr></BODY></HTML>");
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            StreamWriter sw = new StreamWriter(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls"), false);
                            StringBuilder strExcelData = new StringBuilder();
                            strExcelData.Append(strHead);
                            foreach (DataColumn dc in dsPayrollProcess.Tables[0].Columns)
                            {
                                strExcelData.Append("<td>" + dc.ColumnName + "</td>");
                            }
                            strExcelData.Append("</tr><tr>");
                            int i;
                            foreach (DataRow dr in dsPayrollProcess.Tables[0].Rows)
                            {
                                for (i = 0; i < dsPayrollProcess.Tables[0].Columns.Count; i++)
                                {
                                    strExcelData.Append("<td>" + dr[i].ToString() + "</td>");
                                }
                                strExcelData.Append("</tr><tr>");
                            }
                            strExcelData.Append("</tr></BODY></HTML>");
                            sw.Write(strExcelData.ToString());
                            sw.Close();
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls" + "  : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    //Export to CSV
                    else if (rbExportToCSV.Checked == true)
                    {
                        StringBuilder strData = Export(dsPayrollProcess);
                        if (rbFTPNo.Checked == true)
                        {
                            byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(strData.ToString());
                            string attachment = "attachment; filename=" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv";
                            Response.Clear();
                            Response.AddHeader("Content-Type", "application/Excel");
                            Response.AddHeader("Content-Disposition", attachment);
                            Response.BinaryWrite(data);
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            StreamWriter sw = new StreamWriter(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv"), false);
                            sw.Write(strData.ToString());
                            sw.Close();
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv" + "  : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    //Export to XML
                    else if (rbExportToXML.Checked == true)
                    {
                        if (dsCustomFormat.Tables.Count > 0)
                        {
                            if (dsCustomFormat.Tables[0].Rows.Count > 0)
                            {
                                if (dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString() != string.Empty)
                                {
                                    dsPayrollProcess.DataSetName = dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString();
                                }
                                if (dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString() != string.Empty)
                                {
                                    dsPayrollProcess.Tables[0].TableName = dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString();
                                }
                            }
                        }
                        //string strXMLData = dsPayrollProcess.GetXml();
                        //Response.ContentType = "text/xml";
                        //Response.AddHeader("content-disposition", "attachment; filename=\"ExportData_OT.xml\"");
                        //Response.Write(strXMLData);
                        //Response.End();
                        if (rbFTPNo.Checked == true)
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            dsPayrollProcess.Tables[0].WriteXml(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml"));
                            Response.ContentType = "text/xml";
                            string strFile = Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml");
                            Response.AddHeader("content-disposition", "attachment; filename=" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml");
                            Response.WriteFile(strFile);
                            Response.Flush();
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            dsPayrollProcess.Tables[0].WriteXml(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml"));
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert('" + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert('" + ddlCompany.SelectedItem.Text + "_OT_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml" + "  : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    //string fnName = ddlCompany.SelectedItem.Text + "_OverTimeReport_" + strMonthName + "_" + intYear.ToString();
                    ////fnName = Server.UrlEncode(fnName);
                    //string strScript = "window.open('AttendanceReport.aspx?hidFields=&Mont=" + strMonthName + "&Yea=" + intYear + "&Com=" + Convert.ToInt16(ddlCompany.SelectedValue) + "&Mon=" + strMonthValue + "&fn=" + fnName + "&MonthClosureId=" + intMonthClosureId + "&RptType=OT')";
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "OverTimeReport", strScript, true);
                }
            }
        }
        //If Attendance option is selected
        else if (rbOption.SelectedIndex == 2)
        {
            //by Attandance
            Rpt_Common rptcommon = new Rpt_Common();
            string strLevel = "";
            strLevel = rptcommon.getNodes(Convert.ToInt16(ddlCompany.SelectedValue), Convert.ToString(Session["LevelRights"]));
            dsPayrollProcess = objMonthClosureEventData.PayrollByAttandance(hdn_SelectedFieldNames.Value, strMonthName, intYear, Convert.ToInt16(ddlCompany.SelectedValue), strLevel, strMonthValue, intMonthClosureId, Convert.ToString(Session["UserGroupName"]), Convert.ToInt16(ddlCompany.SelectedValue));
            if (dsPayrollProcess.Tables.Count > 0)
            {
                //dsPayrollProcess.Tables[0].WriteXmlSchema(@"e:\ExportAttendance.xml");
                if (dsPayrollProcess.Tables[0].Rows.Count > 0)
                {
                    //To get custom formats.
                    dsCustomFormat = objExportData.GetCustomFormatsForExportData("Attendance", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                    //To get custom field names.
                    dsCustomFields = objExportData.GetCustomFieldNamesForExportData("Attendance", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                    ChangeDateTimeFormats();
                    //To change  the column name of the dataset with custom field name.
                    if (dsCustomFields.Tables.Count > 0)
                    {
                        if (dsCustomFields.Tables[0].Rows.Count > 0)
                        {
                            Hashtable CustomFields = new Hashtable();
                            foreach (DataRow row in dsCustomFields.Tables[0].Rows)
                            {
                                CustomFields.Add(row["FieldName"], row["UserDefinedFieldName"]);
                            }
                            foreach (DataColumn col in dsPayrollProcess.Tables[0].Columns)
                            {
                                if (CustomFields.Contains(col.ColumnName))
                                {
                                    if (CustomFields[col.ColumnName].ToString() != string.Empty)
                                    {
                                        col.ColumnName = CustomFields[col.ColumnName].ToString();
                                    }
                                }
                            }
                        }
                    }
                    //Export to CSV
                    if (rbExportToCSV.Checked == true)
                    {
                        StringBuilder strData = Export(dsPayrollProcess);
                        if (rbFTPNo.Checked == true)
                        {
                            byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(strData.ToString());
                            string attachment = "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv";
                            Response.Clear();
                            Response.AddHeader("Content-Type", "application/Excel");
                            Response.AddHeader("Content-Disposition", attachment);
                            Response.BinaryWrite(data);
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            StreamWriter sw = new StreamWriter(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv"), false);
                            sw.Write(strData.ToString());
                            sw.Close();
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv" + " : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    //Export to XLS
                    else if (rbExportToXLS.Checked == true)
                    {
                        if (rbFTPNo.Checked == true)
                        {
                            dsPayrollProcess.Tables[0].TableName = "Sheet 1";
                            DataTable dt = dsPayrollProcess.Tables[0];
                            dt.TableName = "Sheet 1";
                            string attachment = "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls";
                            //attachment += "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Payroll_" + ddl_Month.SelectedItem.Text + "_" + ddl_Year.SelectedItem.Text + ".xls";
                            Response.ClearContent();
                            Response.AddHeader("content-disposition", attachment);
                            Response.ContentType = "application/vnd.ms-excel";
                            string tab = "";
                            Response.Write(strHead);
                            foreach (DataColumn dc in dt.Columns)
                            {
                                Response.Write("<td>" + dc.ColumnName + "</td>");
                                //tab = "\t";
                            }
                            //Response.Write("\n");
                            Response.Write("</tr><tr>");
                            int i;
                            foreach (DataRow dr in dt.Rows)
                            {
                                tab = "";
                                for (i = 0; i < dt.Columns.Count; i++)
                                {
                                    Response.Write("<td>" + dr[i].ToString() + "</td>");
                                    // tab = "\t";
                                }
                                Response.Write("</tr><tr>");
                            }
                            Response.Write("</tr></BODY></HTML>");
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            StreamWriter sw = new StreamWriter(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + strCurrentDateTime + ".xls"), false);
                            StringBuilder strExcelData = new StringBuilder();
                            strExcelData.Append(strHead);
                            foreach (DataColumn dc in dsPayrollProcess.Tables[0].Columns)
                            {
                                strExcelData.Append("<td>" + dc.ColumnName + "</td>");
                            }
                            strExcelData.Append("</tr><tr>");
                            int i;
                            foreach (DataRow dr in dsPayrollProcess.Tables[0].Rows)
                            {
                                for (i = 0; i < dsPayrollProcess.Tables[0].Columns.Count; i++)
                                {
                                    strExcelData.Append("<td>" + dr[i].ToString() + "</td>");
                                }
                                strExcelData.Append("</tr><tr>");
                            }
                            strExcelData.Append("</tr></BODY></HTML>");
                            sw.Write(strExcelData.ToString());
                            sw.Close();
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls" + "  : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    //Export to XML
                    else if (rbExportToXML.Checked == true)
                    {
                        if (dsCustomFormat.Tables.Count > 0)
                        {
                            if (dsCustomFormat.Tables[0].Rows.Count > 0)
                            {
                                if (dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString() != string.Empty)
                                {
                                    dsPayrollProcess.DataSetName = dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString();
                                }
                                if (dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString() != string.Empty)
                                {
                                    dsPayrollProcess.Tables[0].TableName = dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString();
                                }
                            }
                        }
                        //string strXMLData = dsPayrollProcess.GetXml();
                        //Response.ContentType = "text/xml";
                        //Response.AddHeader("content-disposition", "attachment; filename=\"ExportData_Attendance.xml\"");
                        //Response.Write(strXMLData);
                        //Response.End();
                        if (rbFTPNo.Checked == true)
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            dsPayrollProcess.Tables[0].WriteXml(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml"));
                            Response.ContentType = "text/xml";
                            string strFile = Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml");
                            Response.AddHeader("content-disposition", "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml");
                            Response.WriteFile(strFile);
                            Response.Flush();
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            dsPayrollProcess.Tables[0].WriteXml(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml"));
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_Attendance_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml" + " : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    //string fnName = ddlCompany.SelectedItem.Text + "_AttendanceReport_" + strMonthName + "_" + intYear.ToString();
                    ////fnName = Server.UrlEncode(fnName);
                    //string strScript = "window.open('AttendanceReport.aspx?hidFields=&Mont=" + strMonthName + "&Yea=" + intYear + "&Com=" + Convert.ToInt16(ddlCompany.SelectedValue) + "&Mon=" + strMonthValue + "&fn=" + fnName + "&MonthClosureId=" + intMonthClosureId + "&RptType=Attn')";
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "AttendanceReport", strScript, true);
                    blnProcessDataExists = true;
                }
            }
        }
        //If Leave option is selected
        else if (rbOption.SelectedIndex == 3)
        {
            //by Attandance
            Rpt_Common rptcommon = new Rpt_Common();
            string strLevel = "";
            strLevel = rptcommon.getNodes(Convert.ToInt16(ddlCompany.SelectedValue), Convert.ToString(Session["LevelRights"]));
            string strOption = string.Empty;
            //rblMonthDateWise.SelectedIndex = 1;
            if (rblMonthDateWise.SelectedIndex == 0)
            {
                strOption = "S";
            }
            else
            {
                strOption = "D";
            }
            string strFTPOption = string.Empty;
            if (rbFTPYes.Checked == true)
            {
                strFTPOption = "1";
            }
            else
            {
                strFTPOption = "0";
            }
            dsPayrollProcess = objMonthClosureEventData.PayrollByLeave(hdn_SelectedFieldNames.Value, intMonthClosureId, Convert.ToString(Session["UserGroupName"]), Convert.ToInt16(ddlCompany.SelectedValue), strOption, strFTPOption);
            if (dsPayrollProcess.Tables.Count > 0)
            {
                //dsPayrollProcess.Tables[0].WriteXmlSchema(@"e:\ExportAttendance.xml");
                if (dsPayrollProcess.Tables[0].Rows.Count > 0)
                {
                    //To get custom formats.
                    dsCustomFormat = objExportData.GetCustomFormatsForExportData("Leave", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                    //To get custom field names.
                    dsCustomFields = objExportData.GetCustomFieldNamesForExportData("Leave", rblMonthDateWise.SelectedValue, Convert.ToInt16(ddlCompany.SelectedValue));
                    ChangeDateTimeFormats();
                    //To change  the column name of the dataset with custom field name.
                    if (dsCustomFields.Tables.Count > 0)
                    {
                        if (dsCustomFields.Tables[0].Rows.Count > 0)
                        {
                            Hashtable CustomFields = new Hashtable();
                            foreach (DataRow row in dsCustomFields.Tables[0].Rows)
                            {
                                CustomFields.Add(row["FieldName"], row["UserDefinedFieldName"]);
                            }
                            foreach (DataColumn col in dsPayrollProcess.Tables[0].Columns)
                            {
                                if (CustomFields.Contains(col.ColumnName))
                                {
                                    if (CustomFields[col.ColumnName].ToString() != string.Empty)
                                    {
                                        col.ColumnName = CustomFields[col.ColumnName].ToString();
                                    }
                                }
                            }
                        }
                    }
                    //Export to CSV
                    if (rbExportToCSV.Checked == true)
                    {
                        StringBuilder strData = Export(dsPayrollProcess);
                        if (rbFTPNo.Checked == true)
                        {
                            byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(strData.ToString());
                            string attachment = "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv";
                            Response.Clear();
                            Response.AddHeader("Content-Type", "application/Excel");
                            Response.AddHeader("Content-Disposition", attachment);
                            Response.BinaryWrite(data);
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            StreamWriter sw = new StreamWriter(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv"), false);
                            sw.Write(strData.ToString());
                            sw.Close();
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                    //UpdateFlag for uploaded recoreds
                                    if (strOption == "D")
                                    {
                                        StringWriter strXMLData = new StringWriter();
                                        dsPayrollProcess.Tables[1].WriteXml(strXMLData);
                                        objMonthClosureEventData.UpdateFlagFTPUpload(strXMLData.ToString());
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".csv" + "  : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    //Export to XLS
                    else if (rbExportToXLS.Checked == true)
                    {
                        if (rbFTPNo.Checked == true)
                        {
                            dsPayrollProcess.Tables[0].TableName = "Sheet 1";
                            DataTable dt = dsPayrollProcess.Tables[0];
                            dt.TableName = "Sheet 1";
                            string attachment = "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls";
                            //attachment += "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Payroll_" + ddl_Month.SelectedItem.Text + "_" + ddl_Year.SelectedItem.Text + ".xls";
                            Response.ClearContent();
                            Response.AddHeader("content-disposition", attachment);
                            Response.ContentType = "application/vnd.ms-excel";
                            string tab = "";
                            Response.Write(strHead);
                            foreach (DataColumn dc in dt.Columns)
                            {
                                Response.Write("<td>" + dc.ColumnName + "</td>");
                                //tab = "\t";
                            }
                            //Response.Write("\n");
                            Response.Write("</tr><tr>");
                            int i;
                            foreach (DataRow dr in dt.Rows)
                            {
                                tab = "";
                                for (i = 0; i < dt.Columns.Count; i++)
                                {
                                    Response.Write("<td>" + dr[i].ToString() + "</td>");
                                    // tab = "\t";
                                }
                                Response.Write("</tr><tr>");
                            }
                            Response.Write("</tr></BODY></HTML>");
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            StreamWriter sw = new StreamWriter(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls"), false);
                            StringBuilder strExcelData = new StringBuilder();
                            strExcelData.Append(strHead);
                            foreach (DataColumn dc in dsPayrollProcess.Tables[0].Columns)
                            {
                                strExcelData.Append("<td>" + dc.ColumnName + "</td>");
                            }
                            strExcelData.Append("</tr><tr>");
                            int i;
                            foreach (DataRow dr in dsPayrollProcess.Tables[0].Rows)
                            {
                                for (i = 0; i < dsPayrollProcess.Tables[0].Columns.Count; i++)
                                {
                                    strExcelData.Append("<td>" + dr[i].ToString() + "</td>");
                                }
                                strExcelData.Append("</tr><tr>");
                            }
                            strExcelData.Append("</tr></BODY></HTML>");
                            sw.Write(strExcelData.ToString());
                            sw.Close();
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                    if (strOption == "D")
                                    {
                                        StringWriter strXMLData = new StringWriter();
                                        dsPayrollProcess.Tables[1].WriteXml(strXMLData);
                                        objMonthClosureEventData.UpdateFlagFTPUpload(strXMLData.ToString());
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert('" + ex.Message.ToString() + "');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                                string Script;
                                Script = "<script language='javascript'>";
                                Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xls" + " : Uploaded sucessfully');";
                                Script = Script + " </script>";
                                Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                return;
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    //Export to XML
                    else if (rbExportToXML.Checked == true)
                    {
                        if (dsCustomFormat.Tables.Count > 0)
                        {
                            if (dsCustomFormat.Tables[0].Rows.Count > 0)
                            {
                                if (dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString() != string.Empty)
                                {
                                    dsPayrollProcess.DataSetName = dsCustomFormat.Tables[0].Rows[0]["XML_RootTag"].ToString();
                                }
                                if (dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString() != string.Empty)
                                {
                                    dsPayrollProcess.Tables[0].TableName = dsCustomFormat.Tables[0].Rows[0]["XML_FirstChildTag"].ToString();
                                }
                            }
                        }
                        //string strXMLData = dsPayrollProcess.GetXml();
                        //Response.ContentType = "text/xml";
                        //Response.AddHeader("content-disposition", "attachment; filename=\"ExportData_Attendance.xml\"");
                        //Response.Write(strXMLData);
                        //Response.End();
                        if (rbFTPNo.Checked == true)
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            dsPayrollProcess.Tables[0].WriteXml(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml"));
                            Response.ContentType = "text/xml";
                            string strFile = Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml");
                            Response.AddHeader("content-disposition", "attachment; filename=" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml");
                            Response.WriteFile(strFile);
                            Response.Flush();
                            Response.End();
                        }
                        else
                        {
                            DeleteExistingFiles(Server.MapPath("~\\System Settings\\Download"));
                            dsPayrollProcess.Tables[0].WriteXml(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml"));
                            DataSet dsFTPConfiguration = new DataSet();
                            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
                            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    UploadFile(Server.MapPath("~/System Settings/Download/" + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml").ToString(), dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString(), dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString(), Cryptography.Decrypt(dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString(), "Password"));
                                    if (strOption == "D")
                                    {
                                        StringWriter strXMLData = new StringWriter();
                                        dsPayrollProcess.Tables[1].WriteXml(strXMLData);
                                        objMonthClosureEventData.UpdateFlagFTPUpload(strXMLData.ToString());
                                    }
                                    string Script;
                                    Script = "<script language='javascript'>";
                                    Script = Script + "alert(' " + ddlCompany.SelectedItem.Text + "_Leave_" + strMonthName + "_" + intYear.ToString() + strCurrentDateTime + ".xml" + " : Uploaded sucessfully');";
                                    Script = Script + " </script>";
                                    Page.RegisterStartupScript("Uploaded sucessfully", Script);
                                    return;
                                }
                                catch (Exception ex)
                                {
                                    string strScript;
                                    strScript = "<script language='javascript'>";
                                    strScript = strScript + "alert(' " + ex.Message.ToString() + " ');";
                                    strScript = strScript + " </script>";
                                    Page.RegisterStartupScript("FTP configuration", strScript);
                                    return;
                                }
                            }
                            else
                            {
                                string strScript;
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "alert('Please fill the FTP configuration');";
                                strScript = strScript + " </script>";
                                Page.RegisterStartupScript("FTP configuration", strScript);
                                return;
                            }
                        }
                    }
                    //string fnName = ddlCompany.SelectedItem.Text + "_AttendanceReport_" + strMonthName + "_" + intYear.ToString();
                    ////fnName = Server.UrlEncode(fnName);
                    //string strScript = "window.open('AttendanceReport.aspx?hidFields=&Mont=" + strMonthName + "&Yea=" + intYear + "&Com=" + Convert.ToInt16(ddlCompany.SelectedValue) + "&Mon=" + strMonthValue + "&fn=" + fnName + "&MonthClosureId=" + intMonthClosureId + "&RptType=Attn')";
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "AttendanceReport", strScript, true);
                    blnProcessDataExists = true;
                }
                else
                {
                    string strScript = string.Empty;
                    if (dsPayrollProcess.Tables[1].Rows.Count > 0)
                    {
                        strScript = "alert('No New / Updated leave data found for this duration')";
                    }
                    else
                    {
                        strScript = "alert('No leave data found for this duration')";
                    }
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", strScript, true);
                    return;
                }
            }
        }
        if (blnProcessDataExists == false)
        {
            //lbl_Error.Text = "No Process record found for this duration";
            string strScript = "alert('" + rm.GetString("Alert_NoProcessrecordfoundforthisduration", ci) + "')";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", strScript, true);
        }
    }
    #endregion
}