using System;
using System.Data;
using System.Globalization;
using System.IO;
//using iTextSharp.text.pdf;
using System.Net;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class Masters_TA_UI_WhatsAPPScheduleList : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    EmailConfiguration objEmailConfiguration = new EmailConfiguration();
    GetReports objGetReports = new GetReports();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    cls_Common objcommon = new cls_Common();
    //cls_Master_Title objTitle = new cls_Master_Title();
    string strSetAlert;
    DataSet ds_Checkuser = new DataSet();
    //LeaveEventData objLeave = new LeaveEventData();
    int auEmpId;
    string strScript = string.Empty;
    string source_Language;
    string strFileNameandPath = string.Empty;
    int intPreviewShown = 0;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        gvEmailSchedule.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        //get the culture info to set the language       
        if (!Page.IsPostBack)
        {
            base.CheckPages(327);
            objcommon.menu("Masters_WhatsAPPConfiguration", "327");
        }
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        // LoadStrings Function fills the Label from the Resource File
        LoadStrings(ci);
        auEmpId = Convert.ToInt32(Session["EmpAutoID"].ToString());
        //Set UserRights
        UserRights();
        btn_add.Focus();
        if (!IsPostBack)
        {
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            //strSetAlert = strSetAlert + "RestoreAlert('" + rm.GetString("Alert_Norecordsfound", ci) + "','" + rm.GetString("Alert_Areyousuretorestore", ci) + "','" + rm.GetString("Alert_Selecteddataisnotindeletedstatus", ci) + "','" + rm.GetString("Alert_Selectdatatorestore", ci) + "','" + rm.GetString("Alert_Nodeletedrecordsavailable", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
        }
    }
    #endregion
    #region ButtonEvents
    protected void btn_add_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_WhatsAppSchedule.aspx");
    }
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_EmailConfiguration.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            objEmailConfiguration.UpdateWhatsAppScheduleStatus(hdnSelectRow.Value, "Delete");
            string str = "alert('" + rm.GetString("Alert_WhatsAppscheduledeletedsuccessfully", ci) + "');location.replace('TA_UI_WhatsAppScheduleList.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        else
        {
            strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_Norecordstodelete", ci) + "')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;
        }
    }
    protected void btn_delete_Click_1(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int CID = Convert.ToInt32(btn.CommandName);
        objEmailConfiguration.UpdateScheduleStatus(Convert.ToString(CID), "Delete");
        string str = "alert('" + rm.GetString("Alert_Emailscheduledeletedsuccessfully", ci) + "');location.replace('TA_UI_EmailScheduleList.aspx');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
    }
    #endregion
    #region UserDefinedFunctions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_HeaderTemplate.Text = rm.GetString("Masters_WhatsAPPConfiguration", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btnBack.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btnEnable.Text = "&nbsp;&nbsp;" + rm.GetString("SMSTemplateList_btnEnable", ci);
        btnDisable.Text = "&nbsp;&nbsp;" + rm.GetString("SMSTemplateList_btnDisable", ci);
        gvEmailSchedule.Columns[1].Caption = rm.GetString("lblEmailScheduleName", ci);
        gvEmailSchedule.Columns[2].Caption = rm.GetString("lblEmailReportName", ci);
        gvEmailSchedule.Columns[3].Caption = rm.GetString("lblEmailFrequency", ci);
        gvEmailSchedule.Columns[4].Caption = rm.GetString("lblEmailCreatedby", ci);
        gvEmailSchedule.Columns[5].Caption = rm.GetString("email_Status", ci);
        //gvEmailTemplate.Columns[2].Caption = rm.GetString("Caption_TemplateName", ci);
    }
    private void UserRights()
    {
        // paged id changed from 136 to 177 by gopinath for bug.no28834
        ds_Checkuser = objCheckUser.checkRights(177, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["addPrv"]) == 1)
            {
                this.btn_add.Visible = true;
            }
            else
            {
                this.btn_add.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.btn_Delete.Visible = true;
            }
            else
            {
                this.btn_Delete.Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_EmailConfiguration.aspx");
    }
    protected void gvEmailSchedule_HtmlRowPrepared(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType == DevExpress.Web.GridViewRowType.Data)
        {
            source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
            rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            Label ReportName = (Label)gvEmailSchedule.FindRowCellTemplateControl(e.VisibleIndex, null, "lblReportName");
            LinkButton Preview = (LinkButton)gvEmailSchedule.FindRowCellTemplateControl(e.VisibleIndex, null, "lbPreview");
            //if (ReportName != null)
            //{
            //    ReportName.Text = rm.GetString(ReportName.Text, ci);
            //}
            //Enabled='<%# Convert.ToString(Eval("Enabled"))== "Disabled" ? 'false': 'true' %>'
            Label lblStatus = (Label)gvEmailSchedule.FindRowCellTemplateControl(e.VisibleIndex, null, "lblStatus");
            if (lblStatus != null)
            {
                if (lblStatus.Text == "Enabled")
                {
                    lblStatus.Text = "Enabled";
                    //Preview.Enabled = true;
                    if (hdnEnabledData.Value == string.Empty)
                    {
                        hdnEnabledData.Value = e.GetValue("WhatsAppScheduleID").ToString();
                    }
                    else
                    {
                        if (hdnEnabledData.Value.Contains(e.GetValue("WhatsAppScheduleID").ToString()) == false)
                        {
                            hdnEnabledData.Value = hdnEnabledData.Value + "," + e.GetValue("WhatsAppScheduleID").ToString();
                        }
                    }
                }
                else if (lblStatus.Text == "Disabled")
                {
                    if (hdnDisabledData.Value == string.Empty)
                    {
                        hdnDisabledData.Value = e.GetValue("WhatsAppScheduleID").ToString();
                    }
                    else
                    {
                        if (hdnDisabledData.Value.Contains(e.GetValue("WhatsAppScheduleID").ToString()) == false)
                        {
                            hdnDisabledData.Value = hdnDisabledData.Value + "," + e.GetValue("WhatsAppScheduleID").ToString();
                        }
                    }
                }
            }
        }
    }
    #endregion
    protected void btnEnable_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            objEmailConfiguration.UpdateWhatsAppScheduleStatus(hdnSelectRow.Value, "Enable");
            string str = "alert('" + rm.GetString("Alert_WhatsAppscheduleenabledsuccessfully", ci) + "');location.replace('TA_UI_WhatsAppScheduleList.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        else
        {
            strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_Norecordstoenable", ci) + "')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;
        }
    }
    protected void btnDisable_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            objEmailConfiguration.UpdateWhatsAppScheduleStatus(hdnSelectRow.Value, "Disable");
            string str = "alert('" + rm.GetString("Alert_WhatsAppscheduledisabledsuccessfully", ci) + "');location.replace('TA_UI_WhatsAppScheduleList.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        else
        {
            strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_Norecordstodisable", ci) + "')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;
        }
    }
    protected void lbPreview_Click(object sender, EventArgs e)
    {
        LinkButton lbPreview = sender as LinkButton;
        DevExpress.Web.GridViewDataItemTemplateContainer container = lbPreview.NamingContainer as DevExpress.Web.GridViewDataItemTemplateContainer;
        int ScheduleId = Convert.ToInt32(container.KeyValue);
        string FromDate = string.Empty;
        string ToDate = string.Empty;
        string FromDate_InReport = string.Empty;
        string ToDate_InReport = string.Empty;
        string DateFormat = Convert.ToString(Session["MDateFormat"]);
        string TimeFormat = Convert.ToString(Session["ITimeFormat"]);
        DataSet dsScheduleDetails = new DataSet();
        dsScheduleDetails = objEmailConfiguration.SelectEmailScheduleBasedOnId(ScheduleId);
        if (dsScheduleDetails != null)
        {
            if (dsScheduleDetails.Tables.Count > 0)
            {
                if (dsScheduleDetails.Tables[0].Rows.Count > 0)
                {
                    if (dsScheduleDetails.Tables[0].Rows[0]["Frequency"].ToString() == "Daily")
                    {
                        FromDate = DateTime.Now.ToString("yyyy-MM-dd");
                        ToDate = DateTime.Now.ToString("yyyy-MM-dd");
                    }
                    else if (dsScheduleDetails.Tables[0].Rows[0]["Frequency"].ToString() == "Weekly")
                    {
                        string strDayFrom = dsScheduleDetails.Tables[0].Rows[0]["DayFrom"].ToString();
                        string strDayTo = dsScheduleDetails.Tables[0].Rows[0]["DayTo"].ToString();
                        DateTime dtStartDate = new DateTime();
                        string strDayOfWeek = DateTime.Now.Date.DayOfWeek.ToString();
                        switch (strDayOfWeek)
                        {
                            case "Monday":
                                dtStartDate = DateTime.Now.Date.AddDays(-7);
                                break;
                            case "Tuesday":
                                dtStartDate = DateTime.Now.Date.AddDays(-8);
                                break;
                            case "Wednesday":
                                dtStartDate = DateTime.Now.Date.AddDays(-9);
                                break;
                            case "Thursday":
                                dtStartDate = DateTime.Now.Date.AddDays(-10);
                                break;
                            case "Friday":
                                dtStartDate = DateTime.Now.Date.AddDays(-11);
                                break;
                            case "Saturday":
                                dtStartDate = DateTime.Now.Date.AddDays(-12);
                                break;
                            case "Sunday":
                                dtStartDate = DateTime.Now.Date.AddDays(-13);
                                break;
                        }
                        int Status = 0;
                        while (Status == 0)
                        {
                            if (dtStartDate.DayOfWeek.ToString() == strDayFrom)
                            {
                                FromDate = dtStartDate.ToString("yyyy-MM-dd");
                            }
                            if (dtStartDate.DayOfWeek.ToString() == strDayTo)
                            {
                                ToDate = dtStartDate.ToString("yyyy-MM-dd");
                                Status = 1;
                            }
                            dtStartDate = dtStartDate.AddDays(1);
                        }
                    }
                    else if (dsScheduleDetails.Tables[0].Rows[0]["Frequency"].ToString() == "Monthly")
                    {
                        int Month = DateTime.Now.Date.Month;
                        int DateFrom = Convert.ToInt32(dsScheduleDetails.Tables[0].Rows[0]["DateFrom"]);
                        int DateTo = Convert.ToInt32(dsScheduleDetails.Tables[0].Rows[0]["DateTo"]);
                        int Year = DateTime.Now.Year;
                        if (Month != 1)
                        {
                            Month = DateTime.Now.Date.AddMonths(-1).Month;
                            //From Date
                            if (DateFrom <= 28)
                            {
                                FromDate = Convert.ToDateTime(Month.ToString() + "/" + DateFrom.ToString() + "/" + Year.ToString()).ToString();
                            }
                            else
                            {
                                if (Month == 4 || Month == 6 || Month == 9 || Month == 11)
                                {
                                    if (DateFrom == 31)
                                    {
                                        FromDate = Convert.ToDateTime(Month.ToString() + "/" + 30 + "/" + Year.ToString()).ToString();
                                    }
                                }
                                else if (Month == 2 && Month % 4 == 0)
                                {
                                    if (DateFrom > 29)
                                    {
                                        FromDate = Convert.ToDateTime(Month.ToString() + "/" + 29 + "/" + Year.ToString()).ToString();
                                    }
                                }
                                else if (Month == 2 && Month % 4 != 0)
                                {
                                    FromDate = Convert.ToDateTime(Month.ToString() + "/" + 28 + "/" + Year.ToString()).ToString();
                                }
                                else
                                {
                                    FromDate = Convert.ToDateTime(Month.ToString() + "/" + DateFrom.ToString() + "/" + Year.ToString()).ToString();
                                }
                            }
                            //To Date
                            if (DateTo <= 28)
                            {
                                ToDate = Convert.ToDateTime(Month.ToString() + "/" + DateTo.ToString() + "/" + Year.ToString()).ToString();
                            }
                            else
                            {
                                if (Month == 4 || Month == 6 || Month == 9 || Month == 11)
                                {
                                    if (DateTo == 31)
                                    {
                                        ToDate = Convert.ToDateTime(Month.ToString() + "/" + 30 + "/" + Year.ToString()).ToString();
                                    }
                                }
                                else if (Month == 2 && Month % 4 == 0)
                                {
                                    if (DateTo > 29)
                                    {
                                        ToDate = Convert.ToDateTime(Month.ToString() + "/" + 29 + "/" + Year.ToString()).ToString();
                                    }
                                }
                                else if (Month == 2 && Month % 4 != 0)
                                {
                                    ToDate = Convert.ToDateTime(Month.ToString() + "/" + 28 + "/" + Year.ToString()).ToString();
                                }
                                else
                                {
                                    ToDate = Convert.ToDateTime(Month.ToString() + "/" + DateTo.ToString() + "/" + Year.ToString()).ToString();
                                }
                            }
                        }
                        else
                        {
                            Month = DateTime.Now.Date.AddMonths(-1).Month;
                            Year = Year - 1;
                            //From Date
                            if (DateFrom <= 28)
                            {
                                FromDate = Convert.ToDateTime(Month.ToString() + "/" + DateFrom.ToString() + "/" + Year.ToString()).ToString();
                            }
                            else
                            {
                                if (Month == 4 || Month == 6 || Month == 9 || Month == 11)
                                {
                                    if (DateFrom == 31)
                                    {
                                        FromDate = Convert.ToDateTime(Month.ToString() + "/" + 30 + "/" + Year.ToString()).ToString();
                                    }
                                }
                                else if (Month == 2 && Month % 4 == 0)
                                {
                                    if (DateFrom > 29)
                                    {
                                        FromDate = Convert.ToDateTime(Month.ToString() + "/" + 29 + "/" + Year.ToString()).ToString();
                                    }
                                }
                                else if (Month == 2 && Month % 4 != 0)
                                {
                                    FromDate = Convert.ToDateTime(Month.ToString() + "/" + 28 + "/" + Year.ToString()).ToString();
                                }
                                else
                                {
                                    FromDate = Convert.ToDateTime(Month.ToString() + "/" + DateFrom.ToString() + "/" + Year.ToString()).ToString();
                                }
                            }
                            //To Date
                            if (DateTo <= 28)
                            {
                                ToDate = Convert.ToDateTime(Month.ToString() + "/" + DateTo.ToString() + "/" + Year.ToString()).ToString();
                            }
                            else
                            {
                                if (Month == 4 || Month == 6 || Month == 9 || Month == 11)
                                {
                                    if (DateTo == 31)
                                    {
                                        ToDate = Convert.ToDateTime(Month.ToString() + "/" + 30 + "/" + Year.ToString()).ToString();
                                    }
                                }
                                else if (Month == 2 && Month % 4 == 0)
                                {
                                    if (DateTo > 29)
                                    {
                                        ToDate = Convert.ToDateTime(Month.ToString() + "/" + 29 + "/" + Year.ToString()).ToString();
                                    }
                                }
                                else if (Month == 2 && Month % 4 != 0)
                                {
                                    ToDate = Convert.ToDateTime(Month.ToString() + "/" + 28 + "/" + Year.ToString()).ToString();
                                }
                                else
                                {
                                    ToDate = Convert.ToDateTime(Month.ToString() + "/" + DateTo.ToString() + "/" + Year.ToString()).ToString();
                                }
                            }
                        }
                    }
                    FromDate_InReport = Convert.ToDateTime(FromDate).ToString(DateFormat);
                    ToDate_InReport = Convert.ToDateTime(ToDate).ToString(DateFormat);
                    LoadReport(dsScheduleDetails.Tables[0].Rows[0]["displayName"].ToString(), dsScheduleDetails.Tables[0].Rows[0]["Filters"].ToString(), FromDate, ToDate, dsScheduleDetails.Tables[0].Rows[0]["ToEmailList"].ToString(), dsScheduleDetails.Tables[0].Rows[0]["CCEmailList"].ToString(), Convert.ToInt32(dsScheduleDetails.Tables[0].Rows[0]["ScheduleId"]), DateFormat, TimeFormat, dsScheduleDetails.Tables[0].Rows[0]["Subject"].ToString(), dsScheduleDetails.Tables[0].Rows[0]["EmailContent"].ToString(), FromDate_InReport, ToDate_InReport, Convert.ToInt32(dsScheduleDetails.Tables[0].Rows[0]["CompanyId"]), dsScheduleDetails.Tables[0].Rows[0]["ReportType"].ToString(), Convert.ToInt16(dsScheduleDetails.Tables[0].Rows[0]["EmailSendType"]), dsScheduleDetails.Tables[0].Rows[0]["FileType"].ToString());
                }
            }
        }
    }
    public void LoadReport(string ReportName, string Filters, string FromDate, string ToDate, string ToEmail, string CCEmail, int ScheduleId, string DateFormat, string TimeFormat, string Subject, string EmailContent, string FromDateInReport, string ToDateInReport, int CompanyId, string ReportType, int EmailSendType, string FileFormat)
    {
        ReportDocument rptDoc = new ReportDocument();
        HeaderInformation hdrTable = new HeaderInformation();
        DataTable dtHeader = new DataTable();
        dtHeader = objGetReports.getHeader(CompanyId);
        DataSet dsData = new DataSet();
        Filters = Filters.Replace(" Duration_From ", FromDate);
        Filters = Filters.Replace(" Duration_To ", ToDate);
        switch (ReportName)
        {
            case "Report_Absent":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Absent";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Absent Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("absentReport", ci)));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    //EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                    //http://localhost:4310/TimecheckV1.4/Index.aspx?
                                    // ScheduleId=2RuSqlhxuFzj+8Zfaqy06Q==&
                                    //FromDate=MEmz9Pi1KOl/0v0o7eEFcoMMLetL1BpcEqvMQwuZnjk=&
                                    // ToDate=MEmz9Pi1KOl/0v0o7eEFcoMMLetL1BpcEqvMQwuZnjk=
                                    string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";
                                    string LinkPath = "Reports/TA_UI_Report_ReportViewer.aspx?ScheduleId=" + Encryption.Encrypt(ScheduleId.ToString(), "") + "&FromDate=" + Encryption.Encrypt(FromDate.ToString(), "") + "&ToDate=" + Encryption.Encrypt(ToDate.ToString(), "");
                                    LinkPath = baseUrl + LinkPath;
                                    string s = "pop_window=window.open('" + LinkPath + "'";
                                    s = s + ", 'pop_window','width=800,height=600'); pop_window.focus();";
                                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "s", s, true);
                                }
                            }
                            else
                            {
                                strScript = "";
                                strScript = strScript + "<script language='javascript'>";
                                strScript = strScript + "alert('" + rm.GetString("Alert_Norecordsfound", ci) + "')";
                                strScript = strScript + "</script>";
                                Page.RegisterStartupScript("DelAlert1", strScript);
                                return;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_EarltEntry":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Early Entry";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Early Entry Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectEarlyEntryReport("", "0", FromDate, ToDate, "", 0, 0, 0, UserGroupName, GradeLevel, "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load("../Reports/" + rm.GetString("ReportFile_Earlyentry", ci));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    // EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Late_Entry":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Late Entry";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Late Entry Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectLateInstanceReport("", "0", FromDate, ToDate, "", 0, 0, 0, UserGroupName, GradeLevel, "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load("../Reports/" + rm.GetString("rptLateEntry", ci));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    //EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Early_Exit":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Absent";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Early Exit Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectEarlyOutReportNew(FromDate, ToDate, "", 0, "", "", 0, 0, UserGroupName, GradeLevel, "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load("../Reports/" + rm.GetString("rptEarlyExit", ci));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    //EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Late_Exit":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Late Exit";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Late Exit Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectLateExit(FromDate, ToDate, "", 0, "", "", 0, 0, UserGroupName, GradeLevel, "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load("../Reports/" + rm.GetString("rptLateExit", ci));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    //EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Leave":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Leave";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Leave Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectLeave(FromDate, ToDate, "", 0, "", "", "All", "All", 0, 0, UserGroupName, GradeLevel, "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load("../Reports/" + rm.GetString("leaveReport", ci));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    //EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_All_Swipes":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "All Swipes";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "All Swipes Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectMovementsEntryReport("", "", FromDate, ToDate, "", 0, 0, 0, UserGroupName, GradeLevel, "", 0, 0, "Both", "12:00:00 AM", "11:59:59 PM");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("rptAllSwipes", ci)));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    //EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Detailed_Attendance":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Detailed Attendance";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Detailed Attendance Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectDetailAttend(FromDate, ToDate, "", "", "", UserGroupName, GradeLevel, "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    int iField = 1;
                    int iInc = 0;
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                DataTable dtHeaderLabel = new DataTable();
                                dtHeaderLabel.TableName = "HeaderLabels";
                                DataTable dtNew = new DataTable();
                                dtNew = dsData.Tables[0];
                                //DataTable dtDetAttend = new DataTable();
                                //dtDetAttend = dsData.Tables["Table"].Copy();
                                DataTable dt = new DataTable();
                                DataTable dtReportHeader = new DataTable();
                                dtReportHeader = objGetReports.getHeader(CompanyId);
                                if (dsData.Tables[0].Columns.Count > 11)
                                {
                                    // total columns = 16
                                    if (dsData.Tables[0].Columns.Count < 17)
                                    {
                                        int iDiff = (16 - dsData.Tables[0].Columns.Count);
                                        for (int iDum = 0; iDum < iDiff; iDum++)
                                        {
                                            dsData.Tables[0].Columns.Add(new DataColumn("iField" + iInc, System.Type.GetType("System.String")));
                                            iInc = iInc + 1;
                                        }
                                    }
                                    DataRow dsRow = dtHeaderLabel.NewRow();
                                    int iIcont = 1;
                                    for (int iRow = 0; iRow < dsData.Tables[0].Columns.Count; iRow++)
                                    {
                                        dtHeaderLabel.Columns.Add(new DataColumn("Header" + iIcont, System.Type.GetType("System.String")));
                                        if (dsData.Tables[0].Columns[iRow].ColumnName != "Others")
                                        {
                                            dsRow[iRow] = dsData.Tables[0].Columns[iRow].ColumnName;
                                        }
                                        else if (dsData.Tables[0].Columns[iRow].ColumnName == "Others")
                                        {
                                            //dsRow[iRow] = rm.GetString("Employee_Others", ci);
                                            dsRow[iRow] = dsData.Tables[0].Columns[iRow].ColumnName;
                                        }
                                        iIcont = iIcont + 1;
                                    }
                                    int iCheckFlag = 0;
                                    dtHeaderLabel.Rows.InsertAt(dsRow, 0);
                                    for (int iCol = 13; iCol < dsData.Tables[0].Columns.Count; iCol++)
                                    {
                                        if (dsData.Tables[0].Columns[iCol].ColumnName != "Others")
                                        {
                                            dsData.Tables[0].Columns[iCol].ColumnName = "Field" + iField;
                                            iField = iField + 1;
                                        }
                                        else
                                        {
                                            iCheckFlag = 1;
                                        }
                                    }
                                    if (iCheckFlag == 0)
                                    {
                                        //dsEmp.Tables[0].Columns[16].ColumnName = "Others";
                                        //dsEmp.Tables[0].Columns[16].ColumnName = rm.GetString("Employee_Others", ci);
                                    }
                                }
                                rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("detailedAttendanceReport", ci)));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtReportHeader);
                                rptDoc.Database.Tables["HeaderLabels"].SetDataSource(dtHeaderLabel);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                //rptDoc.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperCsheet;
                                if (EmailSendType == 1)
                                {
                                    //EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Monthly_Attendance":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Monthly Attendance";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Monthly Attendance Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectMonthlyAttendanceReport("", FromDate, ToDate, "", "", "", 0, 0, UserGroupName, GradeLevel, "", 0, 0, "Both", 0);
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                if (ReportType == "0")
                                {
                                    rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("rptMonthlyAttendance", ci)));
                                }
                                else
                                {
                                    rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("rptMonthlyAttendanceDetail", ci)));
                                }
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    //EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Punctuality":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Punctuality";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Punctuality Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectPunctuality(FromDate, ToDate, "", 0, "", "", 0, 0, UserGroupName, GradeLevel, "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("rptPunctuality", ci)));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    //EmailSendWithAttachment(FileFormat, ReportName, rptDoc);
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Discrepancy":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Discrepancy";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Discrepancy Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectDiscrepancy(FromDate, ToDate, "", 0, "", "", 0, 0, UserGroupName, GradeLevel, "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("discrepancyReport", ci)));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Permission":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Permission";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Permission Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectPermissionReport(FromDate, ToDate, "", "", "", 0, 0, UserGroupName, GradeLevel, "All", "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("PermissionReport", ci)));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_ManualTimeEntry":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Manual Time Entry";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Manual Time Entry Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    //dsData = objGetReports.SelectManualTimeEntryReport("", "", FromDate, ToDate, "", 0, 0, UserGroupName, GradeLevel, "All", "", 0, 0, "Both");
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("rptManualTimeEntry", ci)));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "MustoRollReport":
                try
                {
                    int iWorkingDays = 0;
                    DataSet dsTot = new DataSet();
                    dsTot = objGetReports.SelectTotalWorkingDays(Convert.ToDateTime(FromDate).Month.ToString(), Convert.ToDateTime(FromDate).Year.ToString());
                    if (dsTot != null && dsTot.Tables.Count > 0 && dsTot.Tables[0].Rows.Count > 0 && dsTot.Tables[0].Rows[0]["TotalWokingDays"] != DBNull.Value)
                    {
                        iWorkingDays = Convert.ToInt32(dsTot.Tables[0].Rows[0]["TotalWokingDays"]);
                    }
                    DataTable dtRptHeader = new DataTable();
                    //start report//
                    //Create the datatable ,that holds the header information
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Header";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = iWorkingDays;
                    drHdr["ReportName"] = "Form 25 Report";
                    drHdr["FromDate"] = Convert.ToDateTime(FromDate).Year.ToString();
                    drHdr["ToDate"] = Convert.ToDateTime(FromDate).Month.ToString();
                    dtHdr1.Rows.Add(drHdr);
                    //Get the Report source from the Server and load this into the report table
                    DataSet dsForm25 = new DataSet();
                    string SelectedMonth = Convert.ToDateTime(FromDate).Month.ToString();
                    string SelectedYear = Convert.ToDateTime(FromDate).Year.ToString();
                    DataTable NewDT = new DataTable();
                    string EmpID = "";
                    DataColumn DC1 = new DataColumn();
                    DC1.ColumnName = "Name";
                    NewDT.Columns.Add(DC1);
                    DataColumn DC2 = new DataColumn();
                    DC2.ColumnName = "FatherName";
                    NewDT.Columns.Add(DC2);
                    DataColumn DC3 = new DataColumn();
                    DC3.ColumnName = "Designation";
                    NewDT.Columns.Add(DC3);
                    DataColumn DC9 = new DataColumn();
                    DC9.ColumnName = "Employee_Code_Id";
                    NewDT.Columns.Add(DC9);
                    DataColumn DC4 = new DataColumn();
                    DC4.ColumnName = "Present";
                    NewDT.Columns.Add(DC4);
                    DataColumn DC5 = new DataColumn();
                    DC5.ColumnName = "Absent";
                    NewDT.Columns.Add(DC5);
                    DataColumn DC6 = new DataColumn();
                    DC6.ColumnName = "Leave";
                    NewDT.Columns.Add(DC6);
                    DataColumn dcHoliday = new DataColumn();
                    dcHoliday.ColumnName = "Holiday";
                    NewDT.Columns.Add(dcHoliday);
                    DataColumn dcOT = new DataColumn();
                    dcOT.ColumnName = "TotalOT";
                    NewDT.Columns.Add(dcOT);
                    for (int j = 1; j <= 31; j++)
                    {
                        DataColumn DC = new DataColumn();
                        DC.ColumnName = "Day" + j;
                        NewDT.Columns.Add(DC);
                    }
                    DataSet dsSummaryData = new DataSet();
                    DataSet dsDetailedData = new DataSet();
                    TimeSpan ts = Convert.ToDateTime(ToDate).Subtract(Convert.ToDateTime(FromDate));
                    int Days = (int)ts.TotalDays + 1;
                    if (Days > 31)
                    {
                        FromDate = Convert.ToDateTime(FromDate).AddDays((Days - 31)).ToString();
                    }
                    //dsSummaryData = objGetReports.SelectInOutEmployeeSummary(SelectedMonth, SelectedYear, "", "", "", "0", "0", UserGroupName, GradeLevel, "", 0, 0, "Both");
                    if (ReportType == "Summary")
                    {
                        dsSummaryData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                        if (dsSummaryData != null)
                        {
                            if (dsSummaryData.Tables.Count > 0)
                            {
                                if (dsSummaryData.Tables[0].Rows.Count > 0)
                                {
                                    rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("rptEmployeeInOutSummary", ci)));
                                    rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                    rptDoc.Database.Tables["Table"].SetDataSource(dsSummaryData.Tables[0]);
                                    rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                    rptDoc.SetParameterValue("DtFormat", DateFormat);
                                    rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                    if (EmailSendType == 1)
                                    {
                                        PreviewReport(FileFormat, ReportName, rptDoc);
                                    }
                                    else
                                    {
                                    }
                                }
                                else
                                {
                                }
                            }
                        }
                    }
                    else
                    {
                        //dsDetailedData = objGetReports.SelectInOutEmployeeNew(SelectedMonth, SelectedYear, "", "", "", "0", "0", UserGroupName, GradeLevel, "", 0, 0, "Both");
                        dsDetailedData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                        if (dsDetailedData != null)
                        {
                            if (dsDetailedData.Tables.Count > 0)
                            {
                                if (dsDetailedData.Tables[0].Rows.Count > 0)
                                {
                                    rptDoc.Load(Server.MapPath("../Reports/" + rm.GetString("rptEmployeeInOut", ci)));
                                    rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                    rptDoc.Database.Tables["Table"].SetDataSource(dsDetailedData.Tables[0]);
                                    rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                    rptDoc.SetParameterValue("DtFormat", DateFormat);
                                    rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                    if (EmailSendType == 1)
                                    {
                                        PreviewReport(FileFormat, ReportName, rptDoc);
                                    }
                                    else
                                    {
                                    }
                                }
                                else
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_SummaryReport":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Summary Entry";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Summary Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    DataSet dsSummaryData = new DataSet();
                    DataSet dsDetailedData = new DataSet();
                    //dsSummaryData = objGetReports.SelectSummaryReport(FromDate, UserGroupName, 0, 0);
                    dsSummaryData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsSummaryData != null)
                    {
                        if (dsSummaryData.Tables.Count > 0)
                        {
                            if (dsSummaryData.Tables[0].Rows.Count > 0)
                            {
                                rptDoc.Load("../Reports/" + rm.GetString("SummaryReport", ci));
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsSummaryData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.Database.Tables["Table1"].SetDataSource(dsSummaryData.Tables[1]);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_Overtime":
                try
                {
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Over Time";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "Over Time Report";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    DataSet dsOverTime = new DataSet();
                    DataSet dsCompOff = new DataSet();
                    if (ReportType == "OverTime")
                    {
                        //dsOverTime = objGetReports.SelectOverTime(FromDate, ToDate, "", 0, "", "0", 0, 0, UserGroupName, GradeLevel, "All", "", 0, 0, "Both", "OverTime");
                        dsOverTime = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                        if (dsOverTime != null)
                        {
                            if (dsOverTime.Tables.Count > 0)
                            {
                                if (dsOverTime.Tables[0].Rows.Count > 0)
                                {
                                    rptDoc.Load("../Reports/" + rm.GetString("overTimeReport", ci));
                                    rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                    rptDoc.Database.Tables["Table"].SetDataSource(dsOverTime.Tables[0]);
                                    rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                    rptDoc.SetParameterValue("DtFormat", DateFormat);
                                    rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                    if (EmailSendType == 1)
                                    {
                                        PreviewReport(FileFormat, ReportName, rptDoc);
                                    }
                                    else
                                    {
                                    }
                                }
                                else
                                {
                                }
                            }
                        }
                    }
                    else
                    {
                        //dsCompOff = objGetReports.SelectCompOff(FromDate, ToDate, "", 0, "", "0", 0, 0, UserGroupName, GradeLevel, "All", "", 0, 0, "Both", "CompOff");
                        dsCompOff = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                        if (dsCompOff != null)
                        {
                            if (dsCompOff.Tables.Count > 0)
                            {
                                if (dsCompOff.Tables[0].Rows.Count > 0)
                                {
                                    rptDoc.Load(rm.GetString("CompensationReport", ci));
                                    rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                    rptDoc.Database.Tables["Table"].SetDataSource(dsCompOff.Tables[0]);
                                    rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                    rptDoc.SetParameterValue("DtFormat", DateFormat);
                                    rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                    if (EmailSendType == 1)
                                    {
                                        PreviewReport(FileFormat, ReportName, rptDoc);
                                    }
                                    else
                                    {
                                    }
                                }
                                else
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
            case "Report_LessHoursWorked":
                try
                {
                    //Create the datatable ,that holds the header information
                    DataTable dtHdr1 = new DataTable();
                    dtHdr1 = hdrTable.CreateHeader();
                    dtHdr1.TableName = "Header";
                    //Add the Header information
                    DataRow drHdr = dtHdr1.NewRow();
                    drHdr["Link"] = 1;
                    drHdr["Hdr1"] = "";
                    drHdr["Hdr2"] = "";
                    drHdr["Address1"] = "";
                    drHdr["Address2"] = "";
                    drHdr["ReportName"] = "LessHoursWorked";
                    drHdr["FromDate"] = FromDateInReport;
                    drHdr["ToDate"] = ToDateInReport;
                    dtHdr1.Rows.Add(drHdr);
                    dsData = objEmailConfiguration.SelectReportData(Filters, ReportName, ReportType);
                    if (dsData != null)
                    {
                        if (dsData.Tables.Count > 0)
                        {
                            if (dsData.Tables[0].Rows.Count > 0)
                            {
                                if (ReportType == "D")
                                {
                                    rptDoc.Load("../Reports/" + rm.GetString("rptLessHoursWorked", ci));
                                }
                                else
                                {
                                    rptDoc.Load("../Reports/" + rm.GetString("rptLessHoursWorked_Summary", ci));
                                }
                                rptDoc.Database.Tables["Header"].SetDataSource(dtHdr1);
                                rptDoc.Database.Tables["Table"].SetDataSource(dsData.Tables[0]);
                                rptDoc.Database.Tables["Table_1"].SetDataSource(dtHeader);
                                rptDoc.SetParameterValue("DtFormat", DateFormat);
                                rptDoc.SetParameterValue("TimeFormat", TimeFormat);
                                if (EmailSendType == 1)
                                {
                                    PreviewReport(FileFormat, ReportName, rptDoc);
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                break;
        }
    }
    public void PreviewReport(string FileFormat, string ReportName, ReportDocument rptDoc)
    {
        /*
             Code Added By Thilakraj.C
             * On : 18-Feb-2013
             * For Open and delete the Report File
             *              
             */
        try
        {
            string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";
            baseUrl = baseUrl + "Masters/EmailReports/";
            switch (FileFormat)
            {
                case "PDF":
                    strFileNameandPath = Server.MapPath(".") + "\\EmailReports\\" + ReportName + ".pdf";
                    FileInfo TheFile = new FileInfo(strFileNameandPath);
                    if (TheFile.Exists)
                    {
                        File.Delete(strFileNameandPath);
                    }
                    rptDoc.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath(".") + "\\EmailReports\\" + ReportName + ".pdf");
                    string LocalpathPdf = baseUrl + ReportName + ".pdf";
                    WebClient client = new WebClient();
                    Byte[] buffer = client.DownloadData(strFileNameandPath);
                    if (buffer != null)
                    {
                        string s = "pop_window=window.open('" + LocalpathPdf + "'";
                        s = s + ", 'pop_window','width=1200,height=600'); pop_window.focus();";
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "s", s, true);
                    }
                    break;
                case "Excel":
                    rptDoc.ExportToDisk(ExportFormatType.Excel, Server.MapPath(".") + "\\EmailReports\\" + ReportName + ".xls");
                    strFileNameandPath = Server.MapPath(".") + "\\EmailReports\\" + ReportName + ".xls";
                    string LocalpathXLS = baseUrl + ReportName + ".xls";
                    WebClient clientXLS = new WebClient();
                    Byte[] bufferXLS = clientXLS.DownloadData(strFileNameandPath);
                    if (bufferXLS != null)
                    {
                        string s = "pop_window=window.open('" + LocalpathXLS + "'";
                        s = s + ", 'pop_window','width=600,height=600'); pop_window.focus();";
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "s", s, true);
                    }
                    break;
                case "RichText":
                    rptDoc.ExportToDisk(ExportFormatType.RichText, Server.MapPath(".") + "\\EmailReports\\" + ReportName + ".rtf");
                    strFileNameandPath = Server.MapPath(".") + "\\EmailReports\\" + ReportName + ".rtf";
                    string Localpathrtf = baseUrl + ReportName + ".rtf";
                    WebClient clientrtf = new WebClient();
                    Byte[] bufferrtf = clientrtf.DownloadData(strFileNameandPath);
                    if (bufferrtf != null)
                    {
                        string s = "pop_window=window.open('" + Localpathrtf + "'";
                        s = s + ", 'pop_window','width=600,height=600'); pop_window.focus();";
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "s", s, true);
                    }
                    break;
                case "Word":
                    rptDoc.ExportToDisk(ExportFormatType.WordForWindows, Server.MapPath(".") + "\\EmailReports\\" + ReportName + ".doc");
                    strFileNameandPath = Server.MapPath(".") + "\\EmailReports\\" + ReportName + ".doc";
                    string Localpathdoc = baseUrl + ReportName + ".doc";
                    WebClient clientdoc = new WebClient();
                    Byte[] bufferdoc = clientdoc.DownloadData(strFileNameandPath);
                    if (bufferdoc != null)
                    {
                        string s = "pop_window=window.open('" + Localpathdoc + "'";
                        s = s + ", 'pop_window','width=600,height=600'); pop_window.focus();";
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "s", s, true);
                    }
                    break;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            //FileInfo TheFile = new FileInfo(strFileNameandPath);
            //if (TheFile.Exists)
            //{
            //    File.Delete(strFileNameandPath);
            //}
        }
    }
    protected void Page_UnLoad(object sender, EventArgs e)
    {
        //if (strFileNameandPath != string.Empty && intPreviewShown==1)
        //{
        //    FileInfo TheFile = new FileInfo(strFileNameandPath);
        //    if (TheFile.Exists)
        //    {
        //        File.Delete(strFileNameandPath);
        //    }
        //}
    }
    protected void gvEmailSchedule_HtmlDataCellPrepared(object sender, DevExpress.Web.ASPxGridViewTableDataCellEventArgs e)
    {
        Label DeletedRecord = (Label)gvEmailSchedule.FindRowCellTemplateControl(e.VisibleIndex, null, "lblStatus");
        if (DeletedRecord.Text.ToString() == "Disabled")
        {
            DeletedRecord.ForeColor = System.Drawing.Color.Red;
            //e.Cell.ForeColor = System.Drawing.Color.Red;
        }
    }
}