コード例 #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"));
            }
        }
コード例 #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"));
            }
        }
コード例 #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);
            }
        }
コード例 #4
0
        public void ExportToPdf(string inFile, string outFile)
        {
            XlsFile xls = new XlsFile(inFile);

            using (var pdf = new FlexCel.Render.FlexCelPdfExport(xls, true))
            {
                pdf.Export(outFile);
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
0
        public async Task <byte[]> GoToViewPhieuTiepNhan(PhieuTiepNhanInputDto input)
        {
            try
            {
                byte[]    fileTemplate = null;
                ExcelFile xls          = null;
                XlsFile   Result       = new XlsFile(true);

                using (FlexCelReport fr = new FlexCelReport(true))
                {
                    string DuongDan = "/ThuTuc_37/PhieuTiepNhan.xlsx";
                    var    path     = _appFolders.PDFTemplate + DuongDan;

                    var hoso = await _hoSoRepos.GetAsync(input.HoSoId);

                    fr.SetValue("HoVaTen", hoso.TenNguoiDaiDien);
                    fr.SetValue("DiaChi", hoso.DiaChi);
                    fr.SetValue("DienThoai", hoso.SoDienThoai);
                    fr.SetValue("SoGiayTiepNhan", Utility.GetCodeRandom());
                    if (input.ListTaiLieuDaNhan.Count > 0)
                    {
                        fr.AddTable("ListTaiLieuDaNhan", input.ListTaiLieuDaNhan);
                    }

                    fr.SetValue("NgayHen", input.NgayHenCap.Value.ToString("dd/MM/yyyy"));

                    var listHoSoXyLyBoSung = _hoSoXuLyRepos.GetAll().Where(x => x.HoSoId == hoso.Id && x.IsHoSoBS == true).ToList();
                    List <TiepNhanBoSungReport37Dto> ListTiepNhanBoSung = new List <TiepNhanBoSungReport37Dto>();
                    if (listHoSoXyLyBoSung.Count > 0)
                    {
                        if (listHoSoXyLyBoSung.Count == 1) // lần đầu nộp bổ xung
                        {
                            ListTiepNhanBoSung.Add(new TiepNhanBoSungReport37Dto()
                            {
                                SoLanBoSung            = listHoSoXyLyBoSung.Count,
                                NgayTraGiayTiepNhanStr = "ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year
                            });
                        }
                        else
                        {
                            for (int i = 0; i < listHoSoXyLyBoSung.Count; i++)
                            {
                                var NguoiNhan = _userRepos.Get(listHoSoXyLyBoSung[i].VanThuId.Value);
                                var tiepNhanBoSungReport37Dto = new TiepNhanBoSungReport37Dto()
                                {
                                    SoLanBoSung            = i + 1,
                                    NgayTraGiayTiepNhanStr = listHoSoXyLyBoSung[i].NgayTraGiayTiepNhan.Value.ToShortDateString()
                                };
                                ListTiepNhanBoSung.Add(tiepNhanBoSungReport37Dto);
                            }
                            ListTiepNhanBoSung.Add(new TiepNhanBoSungReport37Dto()
                            {
                                SoLanBoSung            = listHoSoXyLyBoSung.Count + 1,
                                NgayTraGiayTiepNhanStr = DateTime.Now.ToShortDateString()
                            });
                        }
                    }

                    fr.AddTable("ListTiepNhanBoSung", ListTiepNhanBoSung);
                    var currentUser = _userRepos.Get(_session.UserId.Value);
                    fr.SetValue("NguoiKy", currentUser.Surname + " " + currentUser.Name);
                    var day   = String.Empty;
                    var month = String.Empty;
                    if (DateTime.Today.Day <= 9)
                    {
                        day = string.Format("0{0}", DateTime.Today.Day);
                    }
                    else
                    {
                        day = DateTime.Today.Day.ToString();
                    }
                    if (DateTime.Today.Month <= 9)
                    {
                        month = string.Format("0{0}", DateTime.Today.Month);
                    }
                    else
                    {
                        month = DateTime.Today.Month.ToString();
                    }
                    string NgayKy = "Hà nội, ngày " + day + " tháng " + month + " năm " + DateTime.Today.Year;
                    if (currentUser.TinhId.HasValue)
                    {
                        var tinh = _tinhRepos.Get(currentUser.TinhId.Value);
                        NgayKy = tinh.Ten + ", ngày " + DateTime.Today.Day + " tháng " + DateTime.Today.Month + " năm " + DateTime.Today.Year;
                    }
                    fr.SetValue("NgayKy", NgayKy);
                    Result.Open(path);
                    fr.Run(Result);
                    fr.Dispose();
                    xls = Result;

                    var outS = new System.IO.MemoryStream();
                    using (FlexCel.Render.FlexCelPdfExport pdf = new FlexCel.Render.FlexCelPdfExport(xls, true))
                    {
                        pdf.Export(outS);
                    }
                    fileTemplate = outS.ToArray();
                    return(fileTemplate);
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex.Message);
                return(null);
            }
        }
コード例 #7
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));
            }
        }