Exemplo n.º 1
0
        public MemoryStream ExecuteReport1()
        {
            //Response.Buffer = true;
            Orchestrator.Reports.ReportBase rpt = GetManifestReport();
            if (rpt == null)
            {
                Response.Clear();
                Response.ClearContent();
                Response.Write("<br /><br />The report failed to generate, please try again. If this problem continues please contact support.");
                if (Utilities.LastError != null)
                {
                    Response.Write("<br />" + Utilities.LastError.Message);
                    Response.Write("<br />" + Utilities.LastError.StackTrace);
                }
                else
                {
                    Response.Write("<br />No error stored");
                }
                Response.End();

                return(null);
            }


            MemoryStream memStream = new MemoryStream();

            // Create the PDF export object
            using (PdfExport pdf = new PdfExport())
            {
                // pdf.Export(rpt.Document, Path.Combine(PDFPath, System.Environment.TickCount.ToString().Substring(0, 4) + ".pdf"));
                pdf.Export(rpt.Document, memStream);
            }

            return(memStream);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Orchestrator.WebUI.Security.Authorise.EnforceAuthorisation(eSystemPortion.Invoicing);

            try
            {
                m_invoiceIdCSV = Request.QueryString["InvoiceIdCSV"].ToString();
            }
            catch { }

            if (m_invoiceIdCSV != String.Empty)
            {
                int counter = 0;

                //if (m_invoiceIdCSV.Length > 0)
                //    m_invoiceIdCSV = m_invoiceIdCSV.Substring(0, m_invoiceIdCSV.Length - 1);

                string[] invoiceIdCSV = m_invoiceIdCSV.Split(',');

                Orchestrator.Reports.ReportBase mainReport = null;

                mainReport = new rptMain();

                // Loop around and view and add invoice to the cache and then generate the main invoice
                foreach (string invoiceId in invoiceIdCSV)
                {
                    m_InvoiceNo = Convert.ToInt32(invoiceId);
                    m_isUpdate  = true;

                    // Invoice Sort Type
                    rdoSortType.DataSource = Utilities.UnCamelCase(Enum.GetNames(typeof(eInvoiceSortType)));
                    rdoSortType.DataBind();
                    rdoSortType.Items[0].Selected = true;

                    if (mainReport != null)
                    {
                        LoadInvoice();

                        Orchestrator.Reports.ReportBase tempReport = LoadReport();

                        for (int a = 0; a <= tempReport.Document.Pages.Count - 1; a++)
                        {
                            mainReport.Document.Pages.Add(tempReport.Document.Pages[a]);
                        }
                    }
                }

                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Buffer      = true;
                Response.ContentType = "application/pdf";

                // IE & Acrobat seem to require "content-disposition" header being in the response.
                // If you don't add it, the doc still works most of the time, but not always.
                // this makes a new window appear: Response.AddHeader("content-disposition","attachment; filename=MyPDF.PDF");
                Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");

                // Create the PDF export object
                PdfExport pdf = new PdfExport();
                // Create a new memory stream that will hold the pdf output
                System.IO.MemoryStream memStream = new System.IO.MemoryStream();
                // Export the report to PDF:
                pdf.Export(mainReport.Document, memStream);
                // Write the PDF stream out
                Response.BinaryWrite(memStream.ToArray());
                // Send all buffered content to the client
                Response.End();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load Report Depending On Invoice Type
        /// </summary>
        private ReportBase LoadReport()
        {
            // Configure the Session variables used to pass data to the report
            NameValueCollection reportParams = new NameValueCollection();

            //-------------------------------------------------------------------------------------
            //						Job/Collect-Drops/References/Demurrages Section
            //-------------------------------------------------------------------------------------
            Facade.IInvoice facInv = new Facade.Invoice();

            DataSet dsInv = null;

            if (m_isUpdate)
            {
                dsInv = facInv.GetJobsForInvoiceId(Convert.ToInt32(lblInvoiceNo.Text));
            }
            else
            {
                dsInv = facInv.GetJobsToInvoice(m_jobIdCSV);
            }

            reportParams.Add("JobIds", m_jobIdCSV);

            reportParams.Add("ExtraIds", m_extraIdCSV);

            //-------------------------------------------------------------------------------------
            //									Param Section
            //-------------------------------------------------------------------------------------
            // Fuel Type & Rate
            eInvoiceDisplayMethod fuelType;
            decimal newRate = 0;

            if (chkIncludeFuelSurcharge.Checked)
            {
                reportParams.Add("Fuel", "Include");

                // Pass The New Rate To Report if so...
                newRate = Convert.ToDecimal(txtFuelSurchargeRate.Text);
                reportParams.Add("FuelRate", newRate.ToString());

                // Pass FuelSurchargeType
                fuelType = (eInvoiceDisplayMethod)Enum.Parse(typeof(eInvoiceDisplayMethod), rdoFuelSurchargeType.SelectedValue);
                reportParams.Add("FuelType", fuelType.ToString());
            }

            // Override
            if (chkOverride.Checked)
            {
                reportParams.Add("Override", "Include");
                reportParams.Add("OverrideVAT", txtOverrideVAT.Text);
                reportParams.Add("OverrideNET", txtOverrideNetAmount.Text);
                reportParams.Add("OverrideGross", txtOverrideGrossAmount.Text);
                reportParams.Add("OverrideReason", txtOverrideReason.Text);
            }

            // PODs
            if (chkIncludePODs.Checked)
            {
                reportParams.Add("PODs", "Include");
            }

            // References
            if (chkIncludeReferences.Checked)
            {
                reportParams.Add("References", "Include");
            }

            // Job
            if (chkJobDetails.Checked)
            {
                reportParams.Add("JobDetails", "Include");

                // Demuragge
                if (chkIncludeDemurrage.Checked)
                {
                    reportParams.Add("Demurrage", "Include");

                    // Demurrage Type
                    try
                    {
                        eInvoiceDisplayMethod demurrageType = (eInvoiceDisplayMethod)Enum.Parse(typeof(eInvoiceDisplayMethod), rdoDemurrageType.SelectedValue);
                        reportParams.Add("DemurrageType", demurrageType.ToString());
                    }
                    catch (Exception) { }
                }
            }

            if (pnlExtras.Visible)
            {
                reportParams.Add("ExtraIds", Convert.ToString(ViewState["ExtraIdCSV"]));
                reportParams.Add("Extras", "Include");
            }

            // Extra details
            if (chkExtraDetails.Visible && chkExtraDetails.Checked)
            {
                reportParams.Add("ExtraDetail", "include");
            }

            // Self Bill Invoice Number
            if ((eInvoiceType)Enum.Parse(typeof(eInvoiceType), lblInvoiceType.Text) == eInvoiceType.SelfBill)
            {
                reportParams.Add("InvoiceType", "SelfBill");
                reportParams.Add("SelfBillInvoiceNumber", txtClientSelfBillInvoiceNumber.Text);
            }
            else
            {
                reportParams.Add("InvoiceType", "Normal");
            }

            // Client Name & Id
            if (m_isUpdate)
            {
                Facade.IInvoice facClient = new Facade.Invoice();

                DataSet ds = facClient.GetClientForInvoiceId(Convert.ToInt32(lblInvoiceNo.Text));

                try
                {
                    reportParams.Add("Client", Convert.ToString(ds.Tables[0].Rows[0]["Client"]));
                    reportParams.Add("ClientId", Convert.ToString(ds.Tables[0].Rows[0]["ClientId"]));

                    m_clientId = int.Parse(ds.Tables[0].Rows[0]["ClientId"].ToString());

                    if (!chkPostToExchequer.Checked)
                    {
                        btnSendToAccounts.Visible = true;
                        pnlInvoiceDeleted.Visible = true;
                    }
                }
                catch
                {
                }
            }
            else
            {
                if (Convert.ToString(Session["ClientName"]) != "")
                {
                    reportParams.Add("Client", Convert.ToString(Session["ClientName"]));
                }

                if (Convert.ToString(Session["ClientId"]) != "")
                {
                    reportParams.Add("ClientId", Convert.ToString(Session["ClientId"]));
                }

                if (m_clientId == 0)
                {
                    m_clientId = int.Parse(Session["ClientId"].ToString());
                }
                else
                {
                    Facade.IOrganisation  facOrg = new Facade.Organisation();
                    Entities.Organisation enOrg  = new Entities.Organisation();
                    enOrg = facOrg.GetForIdentityId(m_clientId);
                    reportParams.Add("Client", enOrg.OrganisationName.ToString());
                    reportParams.Add("ClientId", m_clientId.ToString());
                }
            }

            // Date Range
            if (Convert.ToDateTime(Session["StartDate"]).Date != DateTime.MinValue)
            {
                reportParams.Add("startDate", Convert.ToDateTime(Session["StartDate"]).ToString("dd/MM/yy"));
            }

            if (Convert.ToDateTime(Session["EndDate"]).Date != DateTime.MinValue)
            {
                reportParams.Add("endDate", Convert.ToDateTime(Session["EndDate"]).ToString("dd/MM/yy"));
            }

            // Invoice Id
            if (lblInvoiceNo.Text != "To Be Issued ... (This invoice has not yet been saved, add invoice to allocate Invoice No.)")
            {
                reportParams.Add("invoiceId", lblInvoiceNo.Text);
            }
            else
            {
                reportParams.Add("invoiceId", "0");
            }

            // Posted To Accounts
            if (chkPostToExchequer.Checked)
            {
                reportParams.Add("Accounts", "true");
            }

            int     vatNo   = 0;
            decimal vatRate = 0.00M;

            // VAT Rate
            facInv.GetVatRateForVatType(eVATType.Standard, dteInvoiceDate.SelectedDate.Value, out vatNo, out vatRate);
            reportParams.Add("VATrate", vatRate.ToString());

            // Invoice Date
            reportParams.Add("InvoiceDate", dteInvoiceDate.SelectedDate.Value.ToShortDateString());

            //-------------------------------------------------------------------------------------
            //									Load Report Section
            //-------------------------------------------------------------------------------------
            Session[Orchestrator.Globals.Constants.ReportTypeSessionVariable]       = eReportType.Invoice;
            Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]  = dsInv;
            Session[Orchestrator.Globals.Constants.ReportDataSessionSortVariable]   = rdoSortType.SelectedItem.Text.Replace(" ", "");
            Session[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable] = "Table";
            Session[Orchestrator.Globals.Constants.ReportParamsSessionVariable]     = reportParams;

            Orchestrator.Reports.ReportBase activeReport = null;
            eReportType reportType = 0;

            reportType = (eReportType)Session[Orchestrator.Globals.Constants.ReportTypeSessionVariable];
            try
            {
                activeReport = new Orchestrator.Reports.Invoicing.rptInvoice();
            }
            catch (NullReferenceException e)
            {
                Response.Write(e.Message);
                Response.Flush();
                return(null);
            }

            if (activeReport != null)
            {
                try
                {
                    ApplicationLog.WriteTrace("Getting Data From Session Variable");
                    DataView view = null;
                    DataSet  ds   = (DataSet)Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable];

                    string sortExpression = (string)Session[Orchestrator.Globals.Constants.ReportDataSessionSortVariable];
                    ApplicationLog.WriteTrace("sortExpression ::" + sortExpression);
                    try
                    {
                        if (sortExpression.Length > 0)
                        {
                            view      = new DataView(ds.Tables[0]);
                            view.Sort = sortExpression;
                            activeReport.DataSource = view;
                        }
                        else
                        {
                            activeReport.DataSource = ds;
                        }

                        activeReport.DataMember = (string)Session[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable];
                    }
                    catch (Exception eX)
                    {
                        this.Trace.Write("Err1:" + eX.Message);
                        ApplicationLog.WriteTrace("GetReport :: Err1:" + eX.Message);
                    }
                    activeReport.Document.Printer.PrinterName = string.Empty;
                    activeReport.Document.Printer.PaperKind   = System.Drawing.Printing.PaperKind.A4;
                    //activeReport.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.A4;
                    //activeReport.PrintWidth = activeReport.PageSettings.PaperWidth - (activeReport.PageSettings.Margins.Right + activeReport.PageSettings.Margins.Left);
                    activeReport.Run(false);
                }
                catch (Exception e)
                {
                    Response.Write(e.Message);
                    Response.Flush();
                    return(null);
                }
            }

            Session[Orchestrator.Globals.Constants.ReportSessionVariable] = activeReport;

            return(activeReport);
        }
Exemplo n.º 4
0
        private Orchestrator.Reports.ReportBase GetManifestReport()
        {
            Orchestrator.Reports.ReportBase      activeReport = null;
            Orchestrator.Reports.IDriverRunSheet report       = Orchestrator.Application.GetSpecificImplementation <IDriverRunSheet>();

            if (report != null)
            {
                activeReport = (Orchestrator.Reports.ReportBase)report;
            }
            else
            {
                activeReport = new Orchestrator.Reports.rptDriverRunSheet();
            }

            activeReport.Document.Printer.PrinterName = string.Empty;
            activeReport.Document.Printer.PaperKind   = System.Drawing.Printing.PaperKind.A4;

            if (activeReport != null)
            {
                try
                {
                    ApplicationLog.WriteTrace("Getting Data From Session Variable");
                    DataView view           = null;
                    string   sortExpression = string.Empty;
                    object   ds             = null;

                    //if (useReportParametersKey)
                    //{
                    //    if (htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionTableVariable] is DataSet)
                    //        ds = (DataSet)htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionTableVariable];
                    //    else
                    //        ds = htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionTableVariable];

                    //    sortExpression = (string)htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionSortVariable];
                    //}
                    //else
                    //{
                    if (Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable] is DataSet)
                    {
                        ds = (DataSet)Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable];
                    }
                    else
                    {
                        ds = Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable];
                    }
                    sortExpression = (string)Session[Orchestrator.Globals.Constants.ReportDataSessionSortVariable];
                    //}


                    ApplicationLog.WriteTrace("sortExpression ::" + sortExpression);
                    try
                    {
                        if (sortExpression.Length > 0)
                        {
                            if (ds is DataSet)
                            {
                                view = new DataView(((DataSet)ds).Tables[0]);
                            }
                            view.Sort = sortExpression;
                            activeReport.DataSource = view;
                        }
                        else
                        {
                            activeReport.DataSource = ds;
                        }

                        //if (enforceDataExistence && ds != null)
                        //{
                        //    if (ds is DataSet)
                        //        if (((DataSet)ds).Tables.Count > 0 && ((DataSet)ds).Tables[0].Rows.Count == 0)
                        //        {
                        //            // There is no data to display so redirect to a page.
                        //            Response.Clear();
                        //            Server.Transfer("blankReport.aspx");
                        //        }
                        //}

                        //if (useReportParametersKey)
                        //{
                        //    activeReport.DataMember = (string)htReportInformation[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable];
                        //}
                        //else
                        //{
                        activeReport.DataMember = (string)Session[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable];
                        //}
                    }
                    catch (Exception eX)
                    {
                        Utilities.LastError = eX;
                        this.Trace.Write("Err1:" + eX.Message);
                        ApplicationLog.WriteTrace("GetReport :: Err1:" + eX.Message);
                    }
                    activeReport.SetReportCulture();
                    activeReport.Run(false);
                }
                catch (Exception e)
                {
                    Utilities.LastError = e;
                    return(null);
                }
            }
            this.Trace.Write("Returning Report");
            ApplicationLog.WriteTrace("GetReport :: Returning Report");

            return(activeReport);
        }