Example #1
0
    private void RenderReport(string FederationID, string CampYear, string PaymentID, string FederationName)
    {
        CamperApplication oCA = new CamperApplication();

        //************************
        //Update TimeInCamp
        //************************

        //oCA.UpdateTimeInCamp_PaymentReport(Convert.ToInt32(FederationID),Convert.ToInt32(CampYear));


        string strRpt = "/CIPMSReports/PaymentRequest";
        //string strRpt = "/CIPMS_Reports/Report1";
        string strReportServerURL = ConfigurationManager.AppSettings["ReportServerURL"];
        string strParamValue      = "";

        //*****************************
        //Set general report properties
        //*****************************
        ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
        ReportViewer1.ServerReport.ReportServerUrl = new Uri(strReportServerURL);   // Report Server URL
        ReportViewer1.ServerReport.ReportPath      = strRpt;                        // Report Name
        ReportViewer1.ShowParameterPrompts         = false;
        ReportViewer1.ShowDocumentMapButton        = true;
        ReportViewer1.ShowPrintButton = true;
        ReportViewer1.ZoomMode        = ZoomMode.PageWidth;

        //*************************
        // Create report parameters
        //*************************

        //Report mode parameter
        ReportParameter reportMode = new ReportParameter();

        reportMode.Name = "Report_Parameter_Mode";
        if (radFinal.Checked)
        {
            strParamValue = "Final";
        }
        else
        {
            strParamValue = "Preliminary";
        }
        reportMode.Values.Add(strParamValue);

        //Federation Name parameter
        ReportParameter reportFederation = new ReportParameter();

        reportFederation.Name = "Report_Parameter_Federation";
        strParamValue         = lstFederations.SelectedItem.Text;
        reportFederation.Values.Add(strParamValue);

        //Report_Parameter_FederationID parameter
        ReportParameter reportFederationID = new ReportParameter();

        reportFederationID.Name = "FederationID";
        strParamValue           = FederationID;
        reportFederationID.Values.Add(strParamValue);

        //Report_Parameter_PaymentID
        ReportParameter reportPaymentID = new ReportParameter();

        reportPaymentID.Name = "PaymentID";
        if (PaymentID != NULL)
        {
            strParamValue = PaymentID;
        }
        else
        {
            strParamValue = null;
        }
        reportPaymentID.Values.Add(strParamValue);

        //Report_Parameter_CampYear
        ReportParameter reportCampYear = new ReportParameter();

        reportCampYear.Name = "CampYear";
        strParamValue       = CampYear;
        reportCampYear.Values.Add(strParamValue);


        //*************************
        //new paarameters
        //*************************
        structThresholdInfo ThresholdInfo;
        string strThresholdInfo        = "";
        string strRequestedPaymentInfo = "";

        ThresholdInfo = oCA.GetFedThresholdInfo(Convert.ToUInt16(FederationID));

        switch (ThresholdInfo.ThresholdType)
        {
        case "A":
            strThresholdInfo        = ThresholdInfo.Threshold1 + " for all campers";
            strRequestedPaymentInfo = ThresholdInfo.NbrOfPmtRequested1.ToString() + " of 1st time and " + ThresholdInfo.NbrOfPmtRequested2.ToString() + " of 2nd time campers";
            break;

        case "F":
            strThresholdInfo        = ThresholdInfo.Threshold1.ToString() + " for first time campers";
            strRequestedPaymentInfo = ThresholdInfo.NbrOfPmtRequested1.ToString() + " of first time campers";
            break;

        case "FS":
            strThresholdInfo        = ThresholdInfo.Threshold1.ToString() + " for first time campers and " + ThresholdInfo.Threshold2.ToString() + " for second time campers";
            strRequestedPaymentInfo = ThresholdInfo.NbrOfPmtRequested1.ToString() + " of 1st time and " + ThresholdInfo.NbrOfPmtRequested2.ToString() + " of 2nd time campers";
            break;

        default:
            strThresholdInfo        = "No community incentive thresholds";
            strRequestedPaymentInfo = "N/A";
            break;
        }

        //ThresholdInfo
        ReportParameter reportThresholdInfo = new ReportParameter();

        reportThresholdInfo.Name = "ThresholdInfo";
        strParamValue            = strThresholdInfo;
        reportThresholdInfo.Values.Add(strParamValue);

        //RequestedPaymentInfo
        ReportParameter reportRequestedPaymentInfo = new ReportParameter();

        reportRequestedPaymentInfo.Name = "RequestedPaymentInfo";
        strParamValue = strRequestedPaymentInfo;
        reportRequestedPaymentInfo.Values.Add(strParamValue);
        //*************************

        //Added by Ram for running the report locally
        //IReportServerCredentials irsc = new CustomReportCredentials("trajesh", "ness@123456", "Innovahyd");
        //ReportViewer1.ServerReport.ReportServerCredentials = irsc;
        //IReportServerCredentials irsc = new CustomReportCredentials("ness", "wayne@1234", "FILE");
        //ReportViewer1.ServerReport.ReportServerCredentials = irsc;

        //string strUserName = ConfigurationManager.AppSettings["UserName"].ToString();
        //string strPassword = ConfigurationManager.AppSettings["Password"].ToString();
        //string strDomain = ConfigurationManager.AppSettings["Domain"].ToString();
        //ReportViewer1.ServerReport.ReportServerCredentials = new CustomReportCredentials(strUserName, strPassword, strDomain);


        // Set the report parameters for the report
        ReportViewer1.ServerReport.SetParameters(
            new ReportParameter[] { reportMode, reportFederation, reportFederationID, reportPaymentID, reportCampYear, reportThresholdInfo, reportRequestedPaymentInfo });

        if (radFinal.Checked)
        {
            Warning[] warnings;
            string[]  streamids;
            string    mimeType;
            string    encoding;
            string    extension;
            string    deviceInfo;

            deviceInfo = "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>";

            byte[] bytes = ReportViewer1.ServerReport.Render(
                "PDF", null, out mimeType, out encoding, out extension,
                out streamids, out warnings);
            string datetime = Convert.ToString(DateTime.Now);
            datetime = datetime.Replace('/', '_');
            datetime = datetime.Replace(':', '_');

            // 2014-06-13 Some federation names might have forward slash /, which will cause file creation error below, so we have to get rid of the /
            FederationName = FederationName.Replace('/', '_');

            string strPaymentReportURL = ConfigurationManager.AppSettings["PaymentReportPath"];
            strPaymentReportURL = strPaymentReportURL + FederationName + "_" + datetime + ".pdf";
            //FederationID + "_" + Convert.ToString(DateTime.Now) +
            //ConfigurationManager.AppSettings["PaymentReportPath"] + FederationID + DateTime.Now
            FileStream fs =
                new FileStream(@strPaymentReportURL, FileMode.Create);
            fs.Write(bytes, 0, bytes.Length);
            fs.Close();
        }
    }