Example #1
0
        public FileContentResult RacunReportCollection(string jqGridFilters)
        {
            DataAccessAdapterBase adapter = Helpers.Helper.GetDataAccessAdapter();
            long firmaId = UserEntity.GetFirmaId(adapter, User.Identity.Name);

            string reportPath = Server.MapPath(string.Format("~/ReportTemplates/{0}/Racun.xls", firmaId));

            FlexCel.XlsAdapter.XlsFile xls = new FlexCel.XlsAdapter.XlsFile();
            xls.Open(reportPath);

            short godina = ConfigEntity.GetInstance(adapter, firmaId).AktivnaGodina;
            RelationPredicateBucket bucket = RacunGlavaPager.CreateBucket(godina, jqGridFilters);

            bucket.PredicateExpression.Add(RacunGlavaFields.FirmaId == firmaId);

            IEnumerable <RacunReport> racunReportCollection = CoolJ.DatabaseGeneric.BusinessLogic.RacunReport.GetRacunReportCollection(adapter, bucket, firmaId);

            FlexCel.Report.FlexCelReport report = new FlexCel.Report.FlexCelReport();
            report.AddTable("Racun", racunReportCollection);
            report.Run(xls);

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                FlexCel.Render.FlexCelPdfExport pdfExport = new FlexCel.Render.FlexCelPdfExport(xls);
                pdfExport.BeginExport(ms);
                pdfExport.ExportAllVisibleSheets(false, "");
                pdfExport.EndExport();

                //xls.Save(ms);
                ms.Position = 0;

                return(File(ms.ToArray(), "application/pdf"));
            }
        }
Example #2
0
        public FileContentResult RacunReport(long racunGlavaId)
        {
            DataAccessAdapterBase adapter = Helpers.Helper.GetDataAccessAdapter();
            long firmaId = UserEntity.GetFirmaId(adapter, User.Identity.Name);

            string reportPath = Server.MapPath(string.Format("~/ReportTemplates/{0}/Racun.xls", firmaId));

            FlexCel.XlsAdapter.XlsFile xls = new FlexCel.XlsAdapter.XlsFile();
            xls.Open(reportPath);

            List <RacunReport> racunGlavaList = new List <RacunReport>();

            racunGlavaList.Add(new RacunReport(adapter, racunGlavaId));

            FlexCel.Report.FlexCelReport report = new FlexCel.Report.FlexCelReport();
            report.AddTable("Racun", racunGlavaList);
            report.Run(xls);

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                FlexCel.Render.FlexCelPdfExport pdfExport = new FlexCel.Render.FlexCelPdfExport(xls);
                pdfExport.BeginExport(ms);
                pdfExport.ExportAllVisibleSheets(false, "");
                pdfExport.EndExport();

                //xls.Save(ms);
                ms.Position = 0;

                return(File(ms.ToArray(), "application/pdf"));
            }
        }
Example #3
0
        public ActionResult GoToViewHoSo(long hoSoId = 0, bool exportExcel = false)
        {
            var hoSo = _hoSoRepos.Get(hoSoId);

            if (hoSo != null)
            {
                if (hoSo.IsCA == true)
                {
                    var    stream    = new MemoryStream();
                    var    outStream = new MemoryStream();
                    byte[] byteInfo  = stream.ToArray();
                    using (iTextSharp.text.Document document = new iTextSharp.text.Document())
                        using (PdfCopy copy = new PdfCopy(document, outStream))
                        {
                            document.Open();
                            string ATTP_FILE_PDF = GetUrlFileDefaut();
                            string filePath      = Path.Combine(ATTP_FILE_PDF, hoSo.DuongDanTepCA);
                            var    fileBytes     = System.IO.File.ReadAllBytes(filePath);
                            copy.AddDocument(new PdfReader(fileBytes));
                        }

                    return(File(outStream.ToArray(), "application/pdf"));
                }
                else
                {
                    //File Template
                    var    xls          = FileHoSo(hoSoId);
                    byte[] fileTemplate = null;
                    using (FlexCel.Render.FlexCelPdfExport pdf = new FlexCel.Render.FlexCelPdfExport())
                    {
                        pdf.Workbook = xls;
                        using (MemoryStream ms = new MemoryStream())
                        {
                            pdf.BeginExport(ms);
                            pdf.ExportAllVisibleSheets(false, "PDF");
                            pdf.EndExport();
                            ms.Position  = 0;
                            fileTemplate = ms.ToArray();
                        }
                    }

                    //Copy List File Đính Kèm
                    string ATTP_FILE_PDF = GetUrlFileDefaut();
                    var    outStream     = new MemoryStream();
                    using (iTextSharp.text.Document document = new iTextSharp.text.Document())
                        using (PdfCopy copy = new PdfCopy(document, outStream))
                        {
                            document.Open();
                            copy.AddDocument(new PdfReader((fileTemplate)));
                        }
                    return(File(outStream.ToArray(), "application/pdf"));
                }
            }
            else
            {
                return(null);
            }
        }
Example #4
0
        protected ActionResult ViewReport(FlexCel.Core.ExcelFile xls, string fileName, bool exportExcel = false)
        {
            try
            {
                if (exportExcel)
                {
                    if (xls == null)
                    {
                        return(ExportExcelNotData());
                    }

                    var clsResult = new Models.Excel.clsExcelResult();
                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                    {
                        xls.Save(ms);
                        ms.Position        = 0;
                        clsResult.ms       = ms;
                        clsResult.FileName = fileName;
                        clsResult.type     = "xls";
                        return(clsResult);
                    }
                }
                else
                {
                    if (xls == null)
                    {
                        xls = ExportExcelError("Không có giá trị");
                    }

                    using (FlexCel.Render.FlexCelPdfExport pdf = new FlexCel.Render.FlexCelPdfExport())
                    {
                        pdf.Workbook = xls;
                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                        {
                            pdf.BeginExport(ms);
                            pdf.ExportAllVisibleSheets(false, "PDF");
                            pdf.EndExport();
                            ms.Position = 0;
                            return(File(ms.ToArray(), "application/pdf"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"{DateTime.Now.ToString("HH:mm:ss dd/MM/yyyy")} ViewReport {ex.Message} {JsonConvert.SerializeObject(ex)}");
                return(null);
            }
        }
Example #5
0
        private void export_Click(object sender, System.EventArgs e)
        {
            if (!HasFileOpen())
            {
                return;
            }
            if (!LoadPreferences())
            {
                return;
            }

            if (exportDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            using (FileStream Pdf = new FileStream(exportDialog.FileName, FileMode.Create))
            {
                int SaveSheet = flexCelPdfExport1.Workbook.ActiveSheet;
                try
                {
                    flexCelPdfExport1.BeginExport(Pdf);
                    if (chExportAll.Checked)
                    {
                        flexCelPdfExport1.PageLayout = TPageLayout.Outlines; //To how the bookmarks when opening the file.
                        flexCelPdfExport1.ExportAllVisibleSheets(cbResetPageNumber.Checked, Path.GetFileNameWithoutExtension(exportDialog.FileName));
                    }
                    else
                    {
                        flexCelPdfExport1.PageLayout = TPageLayout.None;
                        flexCelPdfExport1.ExportSheet();
                    }
                    flexCelPdfExport1.EndExport();
                }
                finally
                {
                    flexCelPdfExport1.Workbook.ActiveSheet = SaveSheet;
                }

                if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Process.Start(exportDialog.FileName);
                }
            }
        }
Example #6
0
        public ActionResult InsertPDFHoSo(long hoSoId)
        {
            try
            {
                var    hoSo         = _hoSoRepos.Get(hoSoId);
                string HCC_FILE_PDF = GetUrlFileDefaut();
                var    xls          = FileHoSo(hoSoId);
                using (FlexCel.Render.FlexCelPdfExport pdf = new FlexCel.Render.FlexCelPdfExport())
                {
                    pdf.Workbook = xls;

                    using (MemoryStream ms = new MemoryStream())
                    {
                        pdf.BeginExport(ms);
                        pdf.ExportAllVisibleSheets(false, "PDF");
                        pdf.EndExport();
                        ms.Position = 0;
                        var file      = File(ms.ToArray(), "application/pdf");
                        var outStream = new MemoryStream();
                        using (iTextSharp.text.Document document = new iTextSharp.text.Document())
                            using (PdfCopy copy = new PdfCopy(document, outStream))
                            {
                                document.Open();
                                copy.AddDocument(new PdfReader((file.FileContents)));
                            }

                        String ext = "pdf";

                        var doanhnghiep = _doanhNghiepRepos.GetAll().FirstOrDefault(t => t.Id == hoSo.DoanhNghiepId);

                        //lấy tỉnh để tạo thêm thư mục
                        var strTinh = "unknown";
                        if (doanhnghiep != null)
                        {
                            strTinh = !string.IsNullOrEmpty(doanhnghiep.Tinh) ? RemoveUnicode(doanhnghiep.Tinh).ToLower().Trim().Replace(" ", "-") : "unknown";
                        }

                        var maSoThue      = hoSo.MaSoThue;
                        var strThuMucHoSo = "HOSO_0";
                        if (!string.IsNullOrEmpty(hoSo.StrThuMucHoSo))
                        {
                            strThuMucHoSo = hoSo.StrThuMucHoSo;
                        }
                        var folder = $"{MA_THU_TUC.THU_TUC_98}\\{strTinh}\\{maSoThue}\\{hoSo.StrThuMucHoSo}\\HoSo\\";

                        if (!Directory.Exists(Path.Combine(HCC_FILE_PDF, folder)))
                        {
                            Directory.CreateDirectory(Path.Combine(HCC_FILE_PDF, folder));
                        }

                        var filename = Path.Combine(folder, @"HoSo_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_" + Guid.NewGuid() + "." + ext);

                        var name = (Path.Combine(HCC_FILE_PDF, filename));
                        System.IO.File.WriteAllBytes(name, outStream.ToArray());

                        #region lưu đường dẫn file rác
                        var fileKy = new LogFileKy
                        {
                            HoSoId         = hoSo.Id,
                            ThuTucId       = hoSo.ThuTucId,
                            DuongDanTep    = filename,
                            LoaiTepDinhKem = (int)CommonENum.LOAI_FILE_KY.DON_DANG_KY,
                            DaSuDung       = false
                        };
                        _fileKyRepos.Insert(fileKy);
                        #endregion

                        return(Json(new
                        {
                            fileName = filename
                        }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex.Message);
                return(Json(new
                {
                    fileName = ""
                }, JsonRequestBehavior.AllowGet));
            }
        }