Exemple #1
0
        public IHttpActionResult PrintInvoice(int id, string formatFile, string reportName, int invoiceType)
        {
            BLL.ECommercialInvoiceMng bll = new BLL.ECommercialInvoiceMng();
            Library.DTO.Notification  notification;
            // authentication
            Module.Framework.BLL fwBll = new Module.Framework.BLL();
            if (!fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanPrint))
            {
                return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED)));
            }
            //CREATE PRINTOUT
            string printoutFileName = string.Empty;
            int?   companyID        = fwBll.GetCompanyID(ControllerContext.GetAuthUserId());

            /*
             * get report file base on format of report
             * Excel format is special, we will use one function to get report base on excel
             * Another format we will use microsoft report tool to create report
             */
            if (formatFile == "Excel")
            {
                //switch (companyID)
                //{
                //    case 13:
                //        printoutFileName = bll.GetOrangePiePrintout(id, out notification);
                //        break;
                //    default:

                //        break;
                //}

                printoutFileName = bll.GetInvoicePrintoutInExcel(id, reportName, invoiceType, out notification);
            }
            else
            {
                DTO.ECommercialInvoiceMng.InvoiceContainerPrintout dtoPrintout = bll.GetInvoicePrintoutData(id, ControllerContext.GetAuthUserId(), out notification);
                if (dtoPrintout != null && dtoPrintout.Invoices != null && dtoPrintout.InvoiceDetails != null)
                {
                    reportName = reportName + ".rdlc";
                    //switch (companyID)
                    //{
                    //    case 13:
                    //        reportName = reportName + "_OrangePine.rdlc";
                    //        break;
                    //    default:
                    //        reportName = reportName + ".rdlc";
                    //        break;
                    //}
                    Microsoft.Reporting.WebForms.LocalReport lr = new Microsoft.Reporting.WebForms.LocalReport();
                    lr.ReportPath = FrameworkSetting.Setting.AbsoluteReportFolder + reportName;

                    Microsoft.Reporting.WebForms.ReportDataSource rsInvoice = new Microsoft.Reporting.WebForms.ReportDataSource();
                    rsInvoice.Name  = "Invoice";
                    rsInvoice.Value = dtoPrintout.Invoices;
                    lr.DataSources.Add(rsInvoice);

                    Microsoft.Reporting.WebForms.ReportDataSource rsInvoiceDetail = new Microsoft.Reporting.WebForms.ReportDataSource();
                    rsInvoiceDetail.Name  = "InvoiceDetail";
                    rsInvoiceDetail.Value = dtoPrintout.InvoiceDetails;
                    lr.DataSources.Add(rsInvoiceDetail);
                    printoutFileName = PrintoutHelper.BuildPrintoutFile(lr, formatFile);
                }
            }
            return(Ok(new Library.DTO.ReturnData <string>()
            {
                Data = printoutFileName, Message = notification
            }));
        }