// ////////////////////////////////////////////////////////////////////////
        // NAVIGATION EVENTS
        //
        protected void tkrmTop_ItemClick(object sender, RadMenuEventArgs e)
        {
            string url = "";
            string headerValues = "";

            switch (e.Item.Value)
            {
                case "mClearSearch":
                    url = "./jliner_navigator.aspx?source_page=lm&client=" + hdfCurrentClient.Value;
                    break;

                case "mPreview":
                    int totalColumns = 38;

                    // Update comments
                    JlinerNavigator jlinerNavigator = new JlinerNavigator(jlinerNavigatorTDS);
                    jlinerNavigator.UpdateCommentsHistoryForReport();

                    // Establishing header values
                    if (cbxId.Checked) headerValues += "ID";
                    if (cbxClientLateralId.Checked) headerValues += " * Client Lateral ID";
                    if (cbxHamiltonInspectionNumber.Checked) headerValues += " * Hamilton Inspection Number";
                    if (cbxStreet.Checked) headerValues += " * Street";
                    if (cbxAddress.Checked) headerValues += " * Address";
                    if (cbxCity.Checked) headerValues += " * City";
                    if (cbxUSMH.Checked) headerValues += " * USMH";
                    if (cbxDSMH.Checked) headerValues += " * DSMH";
                    if (cbxVideoInspection.Checked) headerValues += " * Video Inspection";
                    if (cbxVideoLengthToPropertyLine.Checked) headerValues += " * Video Length To PL";
                    if (cbxPipeLocated.Checked) headerValues += " * Pipe Located";
                    if (cbxServicesLocated.Checked) headerValues += " * Services Located";
                    if (cbxCoRequired.Checked) headerValues += " * C/O Req.";
                    if (cbxPitRequired.Checked) headerValues += " * Pit Req.";
                    if (cbxCoPitLocation.Checked) headerValues += " * CO/Pit Location";
                    if (cbxCoInstalled.Checked) headerValues += " * C/O Installed";
                    if (cbxBackfilledConcrete.Checked) headerValues += " * Backfilled Con.";
                    if (cbxBackfilledSoil.Checked) headerValues += " * Backfilled Soil";
                    if (cbxGrouted.Checked) headerValues += " * Grouted";
                    if (cbxCored.Checked) headerValues += " * Cored";
                    if (cbxPrepped.Checked) headerValues += " * Prepped";
                    if (cbxPreVideo.Checked) headerValues += " * Pre-Video";
                    if (cbxMeasured.Checked) headerValues += " * Measured";
                    if (cbxLinerSize.Checked) headerValues += " * Liner Size";
                    if (cbxLiningThruCo.Checked) headerValues += " * Lining Thru C/O";
                    if (cbxNoticeDelivered.Checked) headerValues += " * Notice Delivered";
                    if (cbxInProcess.Checked) headerValues += " * In Process";
                    if (cbxInStock.Checked) headerValues += " * In Stock";
                    if (cbxDelivered.Checked) headerValues += " * Delivered";
                    if (cbxLinerInstalled.Checked) headerValues += " * Liner Installed";
                    if (cbxFinalVideo.Checked) headerValues += " * Final Video";
                    if (cbxDistanceFromUSMH.Checked) headerValues += " * Dist. From USMH";
                    if (cbxDistanceFromDSMH.Checked) headerValues += " * Dist. From DSMH";
                    if (cbxPostContractDigRequired.Checked) headerValues += " * Post Contract Dig?";
                    if (cbxCoCutDown.Checked) headerValues += " * C/O Cut Down?";
                    if (cbxFinalRestoration.Checked) headerValues += " * Final Restoration";
                    if (cbxCost.Checked) headerValues += " * Cost";
                    if (cbxBuidRebuid.Checked) headerValues += " * Build / Rebuild";

                    // Establishing columns to display
                    string[] columns = headerValues.Split('*');
                    string columnsForReport = "";
                    int j;

                    // ... for visible columns
                    for (int i = 0; i < columns.Length; i++)
                    {
                        j = i + 1;
                        columnsForReport += "&header" + j + "=" + columns[i].Trim();
                    }

                    // ... For not visible columns
                    for (int i = columns.Length; i < totalColumns; i++)
                    {
                        j = i + 1;
                        columnsForReport += "&header" + j + "=None";
                    }

                    // ... For comments and history options
                    string comments = "None";
                    string history = "None";
                    if (cbxComments.Checked) comments = "Comments";
                    if (cbxHistory.Checked) history = "History";

                    // Report call
                    Page.Validate();
                    if (Page.IsValid)
                    {
                        PostPageChanges();
                        Response.Write("<script language='javascript'> {window.open('./../../viewer.aspx?target_report=rJlinerPrintSearchResults" + columnsForReport + "&comments=" + comments + "&history=" + history + "&totalColumns=" + totalColumns + "&totalSelectedColumns=" + columns.Length + "&name=" + hdfClientName.Value + "&format=pdf', '_blank', 'toolbar=yes, location=yes, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=600, height=300');}</script>");
                    }

                    break;

                case "mExport":
                    int totalColumnsExport = 40;
                    headerValues = "";
                    columnsForReport = "";

                    // Update comments
                    JlinerNavigator jlinerNavigatorExcel = new JlinerNavigator(jlinerNavigatorTDS);
                    jlinerNavigatorExcel.UpdateCommentsHistoryForReport();

                    // Establishing header values
                    if (cbxId.Checked) headerValues += "ID";
                    if (cbxClientLateralId.Checked) headerValues += " * Client Lateral ID";
                    if (cbxHamiltonInspectionNumber.Checked) headerValues += " * Hamilton Inspection Number";
                    if (cbxStreet.Checked) headerValues += " * Street";
                    if (cbxAddress.Checked) headerValues += " * Address";
                    if (cbxCity.Checked) headerValues += " * City";
                    if (cbxUSMH.Checked) headerValues += " * USMH";
                    if (cbxDSMH.Checked) headerValues += " * DSMH";
                    if (cbxVideoInspection.Checked) headerValues += " * Video Inspection";
                    if (cbxVideoLengthToPropertyLine.Checked) headerValues += " * Video Length To PL";
                    if (cbxPipeLocated.Checked) headerValues += " * Pipe Located";
                    if (cbxServicesLocated.Checked) headerValues += " * Services Located";
                    if (cbxCoRequired.Checked) headerValues += " * C/O Req.";
                    if (cbxPitRequired.Checked) headerValues += " * Pit Req.";
                    if (cbxCoPitLocation.Checked) headerValues += " * CO/Pit Location";
                    if (cbxCoInstalled.Checked) headerValues += " * C/O Installed";
                    if (cbxBackfilledConcrete.Checked) headerValues += " * Backfilled Con.";
                    if (cbxBackfilledSoil.Checked) headerValues += " * Backfilled Soil";
                    if (cbxGrouted.Checked) headerValues += " * Grouted";
                    if (cbxCored.Checked) headerValues += " * Cored";
                    if (cbxPrepped.Checked) headerValues += " * Prepped";
                    if (cbxPreVideo.Checked) headerValues += " * Pre-Video";
                    if (cbxMeasured.Checked) headerValues += " * Measured";
                    if (cbxLinerSize.Checked) headerValues += " * Liner Size";
                    if (cbxLiningThruCo.Checked) headerValues += " * Lining Thru C/O";
                    if (cbxNoticeDelivered.Checked) headerValues += " * Notice Delivered";
                    if (cbxInProcess.Checked) headerValues += " * In Process";
                    if (cbxInStock.Checked) headerValues += " * In Stock";
                    if (cbxDelivered.Checked) headerValues += " * Delivered";
                    if (cbxLinerInstalled.Checked) headerValues += " * Liner Installed";
                    if (cbxFinalVideo.Checked) headerValues += " * Final Video";
                    if (cbxDistanceFromUSMH.Checked) headerValues += " * Dist. From USMH";
                    if (cbxDistanceFromDSMH.Checked) headerValues += " * Dist. From DSMH";
                    if (cbxPostContractDigRequired.Checked) headerValues += " * Post Contract Dig?";
                    if (cbxCoCutDown.Checked) headerValues += " * C/O Cut Down?";
                    if (cbxFinalRestoration.Checked) headerValues += " * Final Restoration";
                    if (cbxCost.Checked) headerValues += " * Cost";
                    if (cbxBuidRebuid.Checked) headerValues += " * Build / Rebuild";
                    if (cbxComments.Checked) headerValues += " * Comments";
                    if (cbxHistory.Checked) headerValues += " * History";

                    // Establishing columns to display
                    string[] columnsExcel = headerValues.Split('*');

                    // ... for visible columns
                    for (int i = 0; i < columnsExcel.Length; i++)
                    {
                        j = i + 1;
                        columnsForReport += "&header" + j + "=" + columnsExcel[i].Trim();
                    }

                    // ... For not visible columns
                    for (int i = columnsExcel.Length; i < totalColumnsExport; i++)
                    {
                        j = i + 1;
                        columnsForReport += "&header" + j + "=None";
                    }

                    // Report call
                    Page.Validate();
                    if (Page.IsValid)
                    {
                        PostPageChanges();
                        url = "./../../viewer.aspx?target_report=rJlinerPrintSearchResults" + columnsForReport + "&totalColumns=" + totalColumnsExport + "&totalSelectedColumns=" + columnsExcel.Length + "&name=" + hdfClientName.Value + "&format=excel";

                    }
                    break;

            }

            if (url != "") Response.Redirect(url);
        }
        private void PostPageChanges()
        {
            JlinerNavigator jlinerNavigator = new JlinerNavigator(jlinerNavigatorTDS);

            // Update jlinernavigator rows
            foreach (GridViewRow row in grdJlinerNavigator.Rows)
            {
                string id_ = ((Label)row.FindControl("lblId_")).Text.Trim();
                bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;

                jlinerNavigator.Update(id_, selected);
            }

            jlinerNavigator.Data.AcceptChanges();

            // Store datasets
            Session["jlinerNavigatorTDS"] = jlinerNavigatorTDS;
        }
        private JlinerNavigatorTDS SubmitSearch()
        {
            // Retrieve clauses
            string whereClause = GetWhereClause();
            string orderByClause = GetOrderByClause();

            JlinerNavigator jlinerNavigator = new JlinerNavigator();

            // ... Load data
            jlinerNavigator.Load(whereClause, orderByClause);

            return (JlinerNavigatorTDS)jlinerNavigator.Data;
        }
        /// ////////////////////////////////////////////////////////////////////////
        /// EVENTS
        ///
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // Security check
            if (!Convert.ToBoolean(Session["sgLFS_APP_VIEW"]))
            {
                Response.Redirect("./error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
            }

            // Validate query string
            if ((Request.QueryString["target_report"] == null) || (Request.QueryString["format"] == null))
            {
                Response.Redirect("./error_page.aspx?error=" + "Invalid query string in viewer.aspx");
            }

            // Initialize
            bool empty = false;

            // Get report data
            #region Get report data

            switch (Request.QueryString["target_report"])
            {
                // ... TimesheetMissing
                case "TimesheetMissing":
                    bool includeSalaried = (Request.QueryString["include_salaried"] == "true") ? true : false;
                    TimesheetMissingReportGateway gateway = new TimesheetMissingReportGateway();
                    if (Request.QueryString["all_employees"] == "true")
                    {
                        if (Request.QueryString["all_countries"] == "true")
                        {
                            gateway.LoadByFromTo(DateTime.Parse(Request.QueryString["date_from"]), DateTime.Parse(Request.QueryString["date_to"]), Request.QueryString["employee_state"], Request.QueryString["employee_type"], includeSalaried);
                        }
                        else
                        {
                            gateway.LoadByCountryIdFromTo(int.Parse(Request.QueryString["country_id"]), DateTime.Parse(Request.QueryString["date_from"]), DateTime.Parse(Request.QueryString["date_to"]), Request.QueryString["employee_state"], Request.QueryString["employee_type"], includeSalaried);
                        }
                    }
                    else
                    {
                        if (Request.QueryString["all_countries"] == "true")
                        {
                            gateway.LoadByEmployeeIDFromTo(int.Parse(Request.QueryString["employee_id"]), DateTime.Parse(Request.QueryString["date_from"]), DateTime.Parse(Request.QueryString["date_to"]), Request.QueryString["employee_state"], Request.QueryString["employee_type"], includeSalaried);
                        }
                        else
                        {
                            gateway.LoadByCountryIdEmployeeIDFromTo(int.Parse(Request.QueryString["country_id"]), int.Parse(Request.QueryString["employee_id"]), DateTime.Parse(Request.QueryString["date_from"]), DateTime.Parse(Request.QueryString["date_to"]), Request.QueryString["employee_state"], Request.QueryString["employee_type"], includeSalaried);
                        }
                    }

                    if (gateway.Table.Rows.Count > 0)
                    {
                        report = new TimesheetMissingReport();
                        report.SetDataSource(gateway.Data);

                        if (Request.QueryString["format"] == "pdf")
                        {
                            ((Section)report.ReportDefinition.Sections["sPageHeader"]).SectionFormat.EnableSuppress = false;
                            ((Section)report.ReportDefinition.Sections["sPageFooter"]).SectionFormat.EnableSuppress = false;
                        }
                        else
                        {
                            ((Section)report.ReportDefinition.Sections["sPageHeader"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sPageFooter"]).SectionFormat.EnableSuppress = true;
                        }
                    }
                    else
                    {
                        empty = true;
                    }
                    break;

                // rJlinerPrintSearchResults
                case "rJlinerPrintSearchResults":
                    JlinerNavigatorTDS jlinerNavigatorTDS = (JlinerNavigatorTDS)Session["jlinerNavigatorTDS"];
                    LiquiForce.LFSLive.BL.CWP.Jliner.JlinerNavigator jlinerNavigator = new LiquiForce.LFSLive.BL.CWP.Jliner.JlinerNavigator(jlinerNavigatorTDS);

                    if (jlinerNavigator.Table.Rows.Count > 0)
                    {
                        report = new LiquiForce.LFSLive.WebUI.CWP.Jliner.rJlinerPrintSearchResults();
                        report.SetDataSource(jlinerNavigator.Data);

                        ArrayList parameterList = new ArrayList();
                        parameterList.Add(Request.QueryString["name"]);
                        SetCurrentValuesForParameterField(report, "name", parameterList);
                        parameterList.Clear();

                        if (Request.QueryString["format"] == "pdf")
                        {
                            // ... Parameters
                            int j;
                            for (int i = 0; i < int.Parse(Request.QueryString["totalColumns"]); i++)
                            {
                                j = i + 1;
                                if (Request.QueryString["header" + j].ToString() == "Hamilton Inspection Number")
                                {
                                    parameterList.Add("Hamilton Insp.#");
                                    SetCurrentValuesForParameterField(report, "header" + j, parameterList);
                                    parameterList.Clear();
                                }
                                else
                                {
                                    if (Request.QueryString["header" + j].ToString() == "Build / Rebuild")
                                    {
                                        parameterList.Add("Build / Rebuild #");
                                        SetCurrentValuesForParameterField(report, "header" + j, parameterList);
                                        parameterList.Clear();
                                    }
                                    else
                                    {
                                        parameterList.Add(Request.QueryString["header" + j]);
                                        SetCurrentValuesForParameterField(report, "header" + j, parameterList);
                                        parameterList.Clear();
                                    }
                                }
                            }

                            parameterList.Add(Request.QueryString["comments"]);
                            SetCurrentValuesForParameterField(report, "header39", parameterList);
                            parameterList.Clear();

                            parameterList.Add(Request.QueryString["history"]);
                            SetCurrentValuesForParameterField(report, "header40", parameterList);
                            parameterList.Clear();

                            // ... Sections
                            ((Section)report.ReportDefinition.Sections["sReportHeader"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sDetailForExel"]).SectionFormat.EnableSuppress = true;

                            if (int.Parse(Request.QueryString["totalSelectedColumns"]) <= 12)
                            {
                                ((Section)report.ReportDefinition.Sections["sDetail48columns"]).SectionFormat.EnableSuppress = true;
                                ((Section)report.ReportDefinition.Sections["sDetail36columns"]).SectionFormat.EnableSuppress = true;
                                ((Section)report.ReportDefinition.Sections["sDetail24columns"]).SectionFormat.EnableSuppress = true;
                                ((Section)report.ReportDefinition.Sections["sDetail12columns"]).SectionFormat.EnableSuppress = false;
                            }
                            else
                            {
                                if ((int.Parse(Request.QueryString["totalSelectedColumns"]) > 12) && (int.Parse(Request.QueryString["totalSelectedColumns"]) <= 24))
                                {
                                    ((Section)report.ReportDefinition.Sections["sDetail48columns"]).SectionFormat.EnableSuppress = true;
                                    ((Section)report.ReportDefinition.Sections["sDetail36columns"]).SectionFormat.EnableSuppress = true;
                                    ((Section)report.ReportDefinition.Sections["sDetail24columns"]).SectionFormat.EnableSuppress = false;
                                    ((Section)report.ReportDefinition.Sections["sDetail12columns"]).SectionFormat.EnableSuppress = true;
                                }
                                else
                                {
                                    if ((int.Parse(Request.QueryString["totalSelectedColumns"]) > 24) && (int.Parse(Request.QueryString["totalSelectedColumns"]) <= 36))
                                    {
                                        ((Section)report.ReportDefinition.Sections["sDetail48columns"]).SectionFormat.EnableSuppress = true;
                                        ((Section)report.ReportDefinition.Sections["sDetail36columns"]).SectionFormat.EnableSuppress = false;
                                        ((Section)report.ReportDefinition.Sections["sDetail24columns"]).SectionFormat.EnableSuppress = true;
                                        ((Section)report.ReportDefinition.Sections["sDetail12columns"]).SectionFormat.EnableSuppress = true;
                                    }
                                    else
                                    {
                                        ((Section)report.ReportDefinition.Sections["sDetail48columns"]).SectionFormat.EnableSuppress = false;
                                        ((Section)report.ReportDefinition.Sections["sDetail36columns"]).SectionFormat.EnableSuppress = true;
                                        ((Section)report.ReportDefinition.Sections["sDetail24columns"]).SectionFormat.EnableSuppress = true;
                                        ((Section)report.ReportDefinition.Sections["sDetail12columns"]).SectionFormat.EnableSuppress = true;
                                    }
                                }
                            }
                        }
                        else
                        {

                            // ... Parameters
                            int j;
                            for (int i = 0; i < int.Parse(Request.QueryString["totalColumns"]); i++)
                            {
                                j = i + 1;
                                if (Request.QueryString["header" + j].ToString() == "Hamilton Inspection Number")
                                {
                                    parameterList.Add("Hamilton Insp.#");
                                    SetCurrentValuesForParameterField(report, "header" + j, parameterList);
                                    parameterList.Clear();
                                }
                                else
                                {
                                    parameterList.Add(Request.QueryString["header" + j]);
                                    SetCurrentValuesForParameterField(report, "header" + j, parameterList);
                                    parameterList.Clear();
                                }
                            }

                            // ... Sections
                            ((Section)report.ReportDefinition.Sections["sReportHeader"]).SectionFormat.EnableSuppress = false;
                            ((Section)report.ReportDefinition.Sections["sDetailForExel"]).SectionFormat.EnableSuppress = false;
                            ((Section)report.ReportDefinition.Sections["sDetail48columns"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sDetail36columns"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sDetail24columns"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sDetail12columns"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sDetailSectionComments"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sDetailSectionHistory"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sDetailSeparator"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sPageFooter"]).SectionFormat.EnableSuppress = true;
                            ((Section)report.ReportDefinition.Sections["sTitle"]).SectionFormat.EnableSuppress = true;
                        }

                        // Report format
                        report.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
                        report.PrintOptions.PaperSize = PaperSize.PaperLegal;
                    }
                    else
                    {
                        empty = true;
                    }
                    break;

            }
            #endregion

            if (!empty)
            {
                // Configure report

                // ... Disk options
                string physicalApplicationPath = Request.PhysicalApplicationPath;
                if (Request.PhysicalApplicationPath.Substring(Request.PhysicalApplicationPath.Length - 1, 1) != "\\")
                {
                    physicalApplicationPath += "\\";
                }

                string fName = "";
                switch (Request.QueryString["format"])
                {
                    case "pdf":
                        fName = physicalApplicationPath + "export\\" + Guid.NewGuid().ToString() + ".pdf";
                        Session["fName"] = fName;
                        break;

                    case "excel":
                        fName = physicalApplicationPath + "export\\" + Guid.NewGuid().ToString() + ".xls";
                        Session["fName"] = fName;
                        break;

                    case "word":
                        break;
                }

                DiskFileDestinationOptions diskOptions = new DiskFileDestinationOptions();
                diskOptions.DiskFileName = fName;

                // ... Export options
                report.ExportOptions.DestinationOptions = diskOptions;
                report.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

                switch (Request.QueryString["format"])
                {
                    case "pdf":
                        report.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                        break;

                    case "excel":
                        ExcelFormatOptions excelOptions = new ExcelFormatOptions();
                        excelOptions.ExcelUseConstantColumnWidth = false;
                        excelOptions.ExcelTabHasColumnHeadings = false;

                        report.ExportOptions.ExportFormatType = ExportFormatType.Excel;
                        report.ExportOptions.FormatOptions = excelOptions;
                        break;

                    case "word":
                        break;
                }

                // Export report
                try
                {
                    report.Export();
                }
                catch (Exception ex)
                {
                    Response.Redirect("./error_page.aspx?error=" + ex.Message);
                }

                // Preview report
                Response.Redirect("./viewer2.aspx?target_report=" + Request.QueryString["target_report"] + "&format=" + Request.QueryString["format"], true);
            }
            else
            {
                Response.Write("<br>         No records found for your report.");
            }
        }