public ActionResult Prints(DataTable Dt) { try { // DataTable Dt = new DataTable(); List <byte[]> PdfStream = new List <byte[]>(); DirectReportPrint drp = new DirectReportPrint(); byte[] Pdf; Pdf = drp.DirectPrint(Dt, User.Identity.Name); PdfStream.Add(Pdf); PdfMerger pm = new PdfMerger(); byte[] Merge = pm.MergeFiles(PdfStream); if (Merge != null) { return(File(Merge, "application/pdf")); } } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { success = "Error", data = message }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Success" }, JsonRequestBehavior.AllowGet)); }
public void Merge_with_not_enough_files_Fail() { PdfMerger pdfMerger = new PdfMerger(); pdfMerger.AddFile(PDF_TEST_FILE_1); if (System.IO.File.Exists(PDF_OUT)) { System.IO.File.Delete(PDF_OUT); } Assert.ThrowsException <ArgumentException>(() => pdfMerger.MergeFiles(PDF_OUT)); }
public void Merge_files_Pass() { PdfMerger pdfMerger = new PdfMerger(); pdfMerger.AddFile(PDF_TEST_FILE_1); pdfMerger.AddFile(PDF_TEST_FILE_2); if (System.IO.File.Exists(PDF_OUT)) { System.IO.File.Delete(PDF_OUT); } pdfMerger.MergeFiles(PDF_OUT); Assert.IsTrue(System.IO.File.Exists(PDF_OUT)); }
public bool MergeAllFiles(int id) { try { var returnedValue = false; List <string> listOfFiles = new List <string>(); var meeting = _repository .Query() .Include(c => c.AgendaItems.Select(d => d.AgendaDetails)) .SelectQueryable() .Where(c => c.Id == id).FirstOrDefault(); string meetingAgendaSource = ConfigurationManager.AppSettings["MeetingPath"] + "//" + meeting.Id + "//"; meeting.AgendaItems.Where(c => !String.IsNullOrEmpty(c.AttachementName)).ToList() .ForEach(c => listOfFiles.Add(ConfigurationManager.AppSettings["MeetingPath"] + "//" + c.AttachementName)); meeting.AgendaItems.ToList().ForEach(d => d.AgendaDetails.Where(c => !String.IsNullOrEmpty(c.AttachementName)).ToList() .ForEach(c => listOfFiles.Add(ConfigurationManager.AppSettings["MeetingPath"] + "//" + c.AttachementName))); meetingAgendaSource = meetingAgendaSource + string.Format("{0}_{1}.pdf", "Meeting_Agenda", meeting.MeetingNumber); if (File.Exists(meetingAgendaSource)) { File.Delete(meetingAgendaSource); } if (listOfFiles.Any()) { returnedValue = PdfMerger.MergeFiles(meetingAgendaSource, listOfFiles); if (returnedValue) { _unitOfWork.BeginTransaction(); var meetingObj = _repository.Find(id); meetingObj.MeetingAgendaAttachmnet = string.Format("{0}//{1}_{2}.pdf", meetingObj.Id, "Meeting_Agenda", meeting.MeetingNumber); meetingObj.TrackingState = TrackableEntities.TrackingState.Modified; _repository.Update(meetingObj); _unitOfWork.SaveChanges(); _unitOfWork.Commit(); } } return(returnedValue); } catch (Exception ex) { throw ex; } }
public void Merge_files_pageCount_verify_Pass() { PdfMerger pdfMerger = new PdfMerger(); pdfMerger.AddFile(PDF_TEST_FILE_1); pdfMerger.AddFile(PDF_TEST_FILE_2); pdfMerger.AddFile(PDF_TEST_FILE_1); pdfMerger.AddFile(PDF_TEST_FILE_2); if (System.IO.File.Exists(PDF_OUT)) { System.IO.File.Delete(PDF_OUT); } pdfMerger.MergeFiles(PDF_OUT); var count = PdfReader.Open(PDF_OUT.Replace(@"\", "/"), PdfDocumentOpenMode.Import).PageCount; Assert.AreEqual(pdfMerger.Documents.Count, count); }
public ActionResult GeneratePrints(string Ids, int DocTypeId) { if (!string.IsNullOrEmpty(Ids)) { int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; var Settings = new SaleOrderSettingsService(_unitOfWork).GetSaleOrderSettingsForDocument(DocTypeId, DivisionId, SiteId); if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, DocTypeId, Settings.ProcessId, this.ControllerContext.RouteData.Values["controller"].ToString(), "GeneratePrints") == false) { return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task.")); } try { List <byte[]> PdfStream = new List <byte[]>(); foreach (var item in Ids.Split(',').Select(Int32.Parse)) { DirectReportPrint drp = new DirectReportPrint(); var pd = context.SaleOrderHeader.Find(item); LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pd.DocTypeId, DocId = pd.SaleOrderHeaderId, ActivityType = (int)ActivityTypeContants.Print, DocNo = pd.DocNo, DocDate = pd.DocDate, DocStatus = pd.Status, })); byte[] Pdf; if (pd.Status == (int)StatusConstants.Drafted || pd.Status == (int)StatusConstants.Import || pd.Status == (int)StatusConstants.Modified) { //LogAct(item.ToString()); Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint, User.Identity.Name, item); PdfStream.Add(Pdf); } else if (pd.Status == (int)StatusConstants.Submitted || pd.Status == (int)StatusConstants.ModificationSubmitted) { Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint_AfterSubmit, User.Identity.Name, item); PdfStream.Add(Pdf); } else { Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint_AfterApprove, User.Identity.Name, item); PdfStream.Add(Pdf); } } PdfMerger pm = new PdfMerger(); byte[] Merge = pm.MergeFiles(PdfStream); if (Merge != null) { return(File(Merge, "application/pdf")); } } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { success = "Error", data = message }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Error", data = "No Records Selected." }, JsonRequestBehavior.AllowGet)); }
public ActionResult GeneratePrints(string ActionName, int LedgerAccountGroupId = 0) { string PrintProcedure = ""; if (!string.IsNullOrEmpty(ActionName)) { var settings = new TrialBalanceSettingService(_unitOfWork).GetTrailBalanceSetting(User.Identity.Name); string SiteId = settings.SiteIds; string DivisionId = settings.DivisionIds; string FromDate = settings.FromDate.HasValue ? settings.FromDate.Value.ToString("dd/MMM/yyyy") : ""; string ToDate = settings.ToDate.HasValue ? settings.ToDate.Value.ToString("dd/MMM/yyyy") : ""; if (ActionName == "BalanceSheet") { PrintProcedure = "Web.spBalanceSheet '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'"; } else if (ActionName == "ProfitAndLoss") { PrintProcedure = "Web.spProfitAndLoss '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'"; } else if (ActionName == "TrialBalanceSummary") { PrintProcedure = "Web.spTrialBalanceSummary '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'"; } else if (ActionName == "TrialBalance") { PrintProcedure = "Web.spTrialBalance '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + ToDate.ToString() + "'"; } else if (ActionName == "SubTrialBalanceSummary") { if (LedgerAccountGroupId == 0) { PrintProcedure = "Web.spSubTrialBalanceSummary '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'"; } else { PrintProcedure = "Web.spSubTrialBalanceSummary '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "','" + LedgerAccountGroupId.ToString() + "'"; } } else if (ActionName == "SubTrialBalance") { if (LedgerAccountGroupId == 0) { PrintProcedure = "Web.spSubTrialBalance '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + ToDate.ToString() + "'"; } else { PrintProcedure = "Web.spSubTrialBalance '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + ToDate.ToString() + "','" + LedgerAccountGroupId.ToString() + "'"; } } else if (ActionName == "LedgerBalance") { if (LedgerAccountGroupId == 0) { PrintProcedure = "Web.spLedger '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'"; } else { PrintProcedure = "Web.spLedger '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "','" + LedgerAccountGroupId.ToString() + "'"; } } try { List <byte[]> PdfStream = new List <byte[]>(); DirectReportPrint drp = new DirectReportPrint(); byte[] Pdf; Pdf = drp.DirectDocumentPrint(PrintProcedure, User.Identity.Name); PdfStream.Add(Pdf); PdfMerger pm = new PdfMerger(); byte[] Merge = pm.MergeFiles(PdfStream); if (Merge != null) { return(File(Merge, "application/pdf")); } } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { success = "Error", data = message }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Error", data = "No Records Selected." }, JsonRequestBehavior.AllowGet)); }
public ActionResult GeneratePrints(string ActionName, int Id = 0) { string PrintProcedure = ""; if (!string.IsNullOrEmpty(ActionName)) { var Settings = new StockInHandSettingService(_unitOfWork).GetTrailBalanceSetting(User.Identity.Name); string SqlParameterGroupOn; string SqlParameterShowBalance; string SqlParameterProdType; string SqlParameterSiteId = Settings.SiteIds; string DivisionId = Settings.DivisionIds; string SqlParameterFromDate = Settings.FromDate.HasValue ? Settings.FromDate.Value.ToString("dd/MMM/yyyy") : ""; string SqlParameterToDate = Settings.ToDate.HasValue ? Settings.ToDate.Value.ToString("dd/MMM/yyyy") : ""; SqlParameterProdType = Id.ToString(); if (string.IsNullOrEmpty(Settings.GroupOn)) { SqlParameterGroupOn = "NULL"; } else { SqlParameterGroupOn = Settings.GroupOn.ToString(); } if (string.IsNullOrEmpty(Settings.ShowBalance) || Settings.ShowBalance == StockInHandShowBalanceConstants.All) { SqlParameterShowBalance = "NULL"; } else { SqlParameterShowBalance = Settings.ShowBalance.ToString(); } if (ActionName == "StockInHand") { PrintProcedure = "Web.spStockInHand @ProductType ='" + SqlParameterProdType.ToString() + "', @Site='" + SqlParameterSiteId.ToString() + "', @FromDate='" + SqlParameterFromDate.ToString() + "', @ToDate='" + SqlParameterToDate.ToString() + "', @GroupOn='" + SqlParameterGroupOn.ToString() + "'"; } try { DataTable Dt = new DataTable(); List <byte[]> PdfStream = new List <byte[]>(); DirectReportPrint drp = new DirectReportPrint(); byte[] Pdf; Pdf = drp.DirectPrint(Dt, User.Identity.Name); PdfStream.Add(Pdf); PdfMerger pm = new PdfMerger(); byte[] Merge = pm.MergeFiles(PdfStream); if (Merge != null) { return(File(Merge, "application/pdf")); } } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { success = "Error", data = message }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Error", data = "No Records Selected." }, JsonRequestBehavior.AllowGet)); }
public void Merge_with_no_files_Fail() { PdfMerger pdfMerger = new PdfMerger(); Assert.ThrowsException <ArgumentException>(() => pdfMerger.MergeFiles()); }
void ExportToPDF2() { DataRow dr; System.Data.DataTable dtPlaning = new System.Data.DataTable("TPlaning"); System.Data.DataTable dtPlaningFile = new System.Data.DataTable("TPlaning_File"); try { dtPlaning.Columns.Add("PID"); dtPlaningFile.Columns.Add("PID"); dtPlaningFile.Columns.Add("File", typeof(byte[])); dtPlaningFile.Columns.Add("File1", typeof(byte[])); dtPlaningFile.Columns.Add("File2", typeof(byte[])); dtPlaningFile.Columns.Add("File3", typeof(byte[])); dtPlaningFile.Columns.Add("File4", typeof(byte[])); dr = dtPlaning.NewRow(); dr["PID"] = "1"; dtPlaning.Rows.Add(dr); dr = dtPlaningFile.NewRow(); dr["PID"] = "1"; dr["File1"] = Utility.GetByteArray(this.Server.MapPath(@"~\img\img1.jpg")); dr["File2"] = Utility.GetByteArray(this.Server.MapPath(@"~\img\img3.jpg")); dr["File3"] = Utility.GetByteArray(this.Server.MapPath(@"~\img\gasflow.png")); dtPlaningFile.Rows.Add(dr); MemoryStream stream = new MemoryStream(); ReportDocument report = new ReportDocument(); report.Load(Server.MapPath("~/UI/Report/RPT/TPlaning.rpt")); report.SetDataSource(dtPlaningFile); report.SetDataSource(dtPlaningFile); if (report.Subreports.Count > 0) { //foreach (DataRow drTemp in dtPlaningFile.Rows) //{ // if (dtPlaningFile.Columns.Count >= 3 && drTemp["FileName1"] != null) // { // drTemp["File1"] = Utility.GetByteArray(this.Server.MapPath(drTemp["FileName1"].ToString())); // } // if (dtPlaningFile.Columns.Count > 4 && drTemp["FileName2"] != null && drTemp["FileName2"].ToString() != "") // { // drTemp["File2"] = Utility.GetByteArray(this.Server.MapPath(drTemp["FileName2"].ToString())); // } // if (dtPlaningFile.Columns.Count > 5 && drTemp["FileName3"] != null) // { // drTemp["File3"] = Utility.GetByteArray(this.Server.MapPath(drTemp["FileName3"].ToString())); // } // if (dtPlaningFile.Columns.Count > 6 && drTemp["FileName4"] != null) // { // drTemp["File4"] = Utility.GetByteArray(this.Server.MapPath(drTemp["FileName4"].ToString())); // } //} report.Subreports["TPlaingFile.rpt"].Database.Tables[0].SetDataSource(dtPlaningFile); } stream = (MemoryStream)report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); string planOverAll = System.Configuration.ConfigurationManager.AppSettings["UploadOverAll"]; string rootPath = planOverAll; Utility.HaveDirectory(this.Server.MapPath(string.Format(rootPath))); string fileName = string.Format("1Planing{0}.pdf", "222"); string pdfName = this.Server.MapPath(string.Format(rootPath)) + "\\" + fileName; Utility.DeleteFile(pdfName); FileStream fsObj = new FileStream(pdfName, FileMode.Create, FileAccess.Write); fsObj.Write(stream.ToArray(), 0, System.Convert.ToInt32(stream.ToArray().Length)); fsObj.Close(); if (report != null) { report.Close(); report.Dispose(); } string[] files = Directory.GetFiles(Server.MapPath(rootPath.ToString()), "*.pdf"); List <string> fileAll = new List <string>(); fileAll.AddRange(files); fileAll.Sort(); List <byte[]> filesByte = new List <byte[]>(); foreach (string file in fileAll) { filesByte.Add(File.ReadAllBytes(file)); } string strDateTimeExport = DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Millisecond.ToString(); string actionAll = string.Format("ActionAll{0}.pdf", strDateTimeExport); byte[] output = PdfMerger.MergeFiles(filesByte); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment;filename=\"InspectionAll.pdf\""); Response.BinaryWrite(output); Response.End(); } catch (Exception ex) { Label1.Text = ex.Message + "---" + ex.StackTrace; } finally { } }
public ActionResult GeneratePrints(string Ids, int DocTypeId) { if (!string.IsNullOrEmpty(Ids)) { int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; var Settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(DocTypeId, DivisionId, SiteId); try { List <byte[]> PdfStream = new List <byte[]>(); foreach (var item in Ids.Split(',').Select(Int32.Parse)) { DirectReportPrint drp = new DirectReportPrint(); var pd = db.PurchaseOrderAmendmentHeader.Find(item); LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pd.DocTypeId, DocId = pd.PurchaseOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.Print, DocNo = pd.DocNo, DocDate = pd.DocDate, DocStatus = pd.Status, })); byte[] Pdf; if (pd.Status == (int)StatusConstants.Drafted || pd.Status == (int)StatusConstants.Import || pd.Status == (int)StatusConstants.Modified) { //LogAct(item.ToString()); Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint, User.Identity.Name, item); PdfStream.Add(Pdf); } else if (pd.Status == (int)StatusConstants.Submitted || pd.Status == (int)StatusConstants.ModificationSubmitted) { Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint_AfterSubmit, User.Identity.Name, item); PdfStream.Add(Pdf); } else { Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint_AfterApprove, User.Identity.Name, item); PdfStream.Add(Pdf); } } PdfMerger pm = new PdfMerger(); byte[] Merge = pm.MergeFiles(PdfStream); if (Merge != null) { return(File(Merge, "application/pdf")); } } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { success = "Error", data = message }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Error", data = "No Records Selected." }, JsonRequestBehavior.AllowGet)); }
public byte[] GetReport(string Ids, int DocTypeId, string UserName) { int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; var Settings = new JobReceiveSettingsService(_unitOfWork).GetJobReceiveSettingsForDocument(DocTypeId, DivisionId, SiteId); string ReportSql = ""; if (!string.IsNullOrEmpty(Settings.DocumentPrint)) { ReportSql = GetReportHeader(Settings.DocumentPrint).ReportSQL; } List <byte[]> PdfStream = new List <byte[]>(); foreach (var item in Ids.Split(',').Select(Int32.Parse)) { DirectReportPrint drp = new DirectReportPrint(); var pd = Find(item); byte[] Pdf; if (!string.IsNullOrEmpty(ReportSql)) { Pdf = drp.rsDirectDocumentPrint(ReportSql, UserName, item); PdfStream.Add(Pdf); } else { if (pd.Status == (int)StatusConstants.Drafted || pd.Status == (int)StatusConstants.Import || pd.Status == (int)StatusConstants.Modified) { Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint, UserName, item); PdfStream.Add(Pdf); } else if (pd.Status == (int)StatusConstants.Submitted || pd.Status == (int)StatusConstants.ModificationSubmitted) { Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint_AfterSubmit, UserName, item); PdfStream.Add(Pdf); } else { Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint_AfterApprove, UserName, item); PdfStream.Add(Pdf); } } _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel { DocTypeId = pd.DocTypeId, DocId = pd.JobReceiveHeaderId, ActivityType = (int)ActivityTypeContants.Print, DocNo = pd.DocNo, DocDate = pd.DocDate, DocStatus = pd.Status, })); } PdfMerger pm = new PdfMerger(); byte[] Merge = pm.MergeFiles(PdfStream); return(Merge); }