Пример #1
0
        public FunctionResponse OpenPdfReport(PdfReportParameter reportParameter)
        {
            var filename = reportParameter.filename;

            if (string.IsNullOrEmpty(filename))
            {
                return new FunctionResponse {
                           status = "error", result = "Invalid file Name"
                }
            }
            ;
            var reportDirectory = _env.WebRootPath;

            if (filename.EndsWith(".ims") == false)
            {
                filename = filename + ".ims";
            }
            var reportFile = Path.Combine(reportDirectory, "IMSReport", filename);

            if (File.Exists(reportFile) == false)
            {
                return new FunctionResponse {
                           status = "error", result = "File not found"
                }
            }
            ;
            string str = File.ReadAllText(reportFile);

            inoicePrinting = new InvoicePrinting();
            inv            = inoicePrinting.LoadInvFromJsonString(str);
            if (inv.Document.DetailDataType == DataType.SQLServer)
            {
                if (!string.IsNullOrEmpty(inv.Document.QueryParameter))
                {
                    FunctionResponse res = CompareParameter(reportParameter.Parameter, inv.Document.QueryParameter);
                    if (res.status == "error")
                    {
                        return(res);
                    }
                    inoicePrinting.InputParameters = res.result as Dictionary <string, object>;
                    PrepareSqlReportData(inoicePrinting, inv, inoicePrinting.InputParameters);
                }
            }
            //var pdfFile = reportDirectory

            using (MemoryStream memStream = new MemoryStream())
            {
                byte[] bytes = inoicePrinting.PrintInvoice(inv, "", memStream: memStream);

                return(new FunctionResponse {
                    status = "ok", result = bytes
                });
            }
        }
Пример #2
0
        private void Open_Click(Object sender, EventArgs e)
        {
            openFileDialog1.Filter = "PdfInvoice|*.ims";
            openFileDialog1.Title  = "Open Pdf Invoice File";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var    filename = openFileDialog1.FileName;
                    string str      = File.ReadAllText(filename);



                    inoicePrinting = new InvoicePrinting();
                    inv            = inoicePrinting.LoadInvFromJsonString(str);
                    LoadTree();
                    LoadPdf();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #3
0
        public FunctionResponse OpenPdfReportMultipleParameter(PdfReportMultiParameter pdfReportMultiParameter)
        {
            var filename = pdfReportMultiParameter.filename;

            if (string.IsNullOrEmpty(filename))
            {
                return new FunctionResponse {
                           status = "error", result = "Invalid file Name"
                }
            }
            ;
            var reportDirectory = _env.WebRootPath;
            var reportFile      = Path.Combine(reportDirectory, "IMSReport", filename);

            if (File.Exists(reportFile) == false)
            {
                return new FunctionResponse {
                           status = "error", result = "File not found"
                }
            }
            ;
            string str = File.ReadAllText(reportFile);

            inoicePrinting = new InvoicePrinting();
            inv            = inoicePrinting.LoadInvFromJsonString(str);
            List <byte[]> pdfFiles = new List <byte[]>();

            foreach (var parameter in pdfReportMultiParameter.Parameters)
            {
                if (inv.Document.DetailDataType == DataType.SQLServer)
                {
                    if (!string.IsNullOrEmpty(inv.Document.QueryParameter))
                    {
                        FunctionResponse res = CompareParameter(parameter, inv.Document.QueryParameter);
                        if (res.status == "error")
                        {
                            return(res);
                        }
                        inoicePrinting.InputParameters = res.result as Dictionary <string, object>;
                        if (!(pdfReportMultiParameter.IsSameDataQuery == true && inoicePrinting.DetailData != null))
                        {
                            PrepareSqlReportData(inoicePrinting, inv, inoicePrinting.InputParameters);
                        }
                    }
                    using (MemoryStream memStream = new MemoryStream())
                    {
                        byte[] bytes = inoicePrinting.PrintInvoice(inv, "", memStream: memStream);
                        pdfFiles.Add(bytes);
                        //return new FunctionResponse { status = "ok", result = memStream.ToArray() };
                    }
                }
            }

            //var pdfFile = reportDirectory



            using (MemoryStream memoryStream = new MemoryStream())
            {
                inoicePrinting.MergePdfinMemory(memoryStream, pdfFiles);

                return(new FunctionResponse {
                    status = "ok", result = memoryStream.ToArray()
                });
            }
        }