private void MycmdToPdf_Click() { try { if (ItemsSource.Count <= 0) { return; } jolcode.Code.AplicarEfecto(View as Window); jolcode.Code.DoEvents(); // SaveFileDialog sfd = new SaveFileDialog(); // sfd.Filter = "Pdfs Files|*.Pdf|All Files|*.*"; // if (sfd.ShowDialog() == true) { MergeEx mergeEx = new MergeEx(); String path = @"C:\\ApplicaTmp\\";// System.IO.Path.GetDirectoryName(sfd.FileName); if (!path.EndsWith("\\")) { path += "\\"; } path += Guid.NewGuid().ToString() + "\\"; if (System.IO.Directory.Exists(path)) { String[] fileList1 = System.IO.Directory.GetFiles(path, "*.pdf"); foreach (String fileName in fileList1) { System.IO.File.Delete(fileName); } } else { System.IO.Directory.CreateDirectory(path); } int count = 0; foreach (LotsEndo item in ItemsSource) { count++; mergeEx.DestinationFile = path; mergeEx.setFileName = item.NumElec; //System.IO.Path.GetFileName(sfd.FileName); mergeEx.setSplit = 1000; byte[] Tif = item.EndosoImage; String fileImg = "Formulario-" + item.Formulario + "-" + Guid.NewGuid().ToString() + ".tif"; System.IO.File.WriteAllBytes(path + fileImg, Tif); mergeEx.ConvertImageToPdf(path + fileImg, path + fileImg + ".pdf"); System.Drawing.Point point = new System.Drawing.Point(500, 310); String valido = "(Válido Lote:"; if (item.Status != "0") { valido = "(Inválido Lote:"; } // mergeEx.AddTextToPdf(path + fileImg + ".pdf" , path + count.ToString("00#") + ".pdf", valido + item.Lot + " Formulario:" + item.Formulario + " " + item.Status +")",point ); mergeEx.AddTextToPdf(path + fileImg + ".pdf", path + count.ToString("00#") + ".pdf", valido + item.Lot + " Formulario:" + item.Formulario + ")", point); System.IO.File.Delete(path + fileImg); System.IO.File.Delete(path + fileImg + ".pdf"); } String[] fileList = System.IO.Directory.GetFiles(path, "*.pdf"); foreach (String fileName in fileList) { mergeEx.AddFile(fileName); } mergeEx.Execute(); foreach (String fileName in fileList) { System.IO.File.Delete(fileName); } //open pdf String fileNamepdf = path + mergeEx.setFileName + "_1.pdf"; fileTmp.Add(fileNamepdf); System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = fileNamepdf; process.Start(); //if (process != null) // process.WaitForExit(); } MessageBox.Show("Done...", "Done", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MethodBase site = ex.TargetSite; MessageBox.Show(ex.ToString(), site.Name, MessageBoxButton.OK, MessageBoxImage.Error); } finally { jolcode.Code.QuitarEfecto(View as Window); } }
private Task <bool> run() { bool returnBoll = false; return(Task.Run(() => { try { _run = true; rpt.ReporteRechazadas objRp = new WpfEndososCandidatos.rpt.ReporteRechazadas(); using (SqlExcuteCommand get = new SqlExcuteCommand { DBCeeMasterCnnStr = DBMasterCeeCnnStr, DBCnnStr = DBEndososCnnStr }) { DataTable T = get.MyGeRechazadasToInforme(cbLots_Item); int totalDePaginas = T.Rows.Count; int Pagina = 1; string strPath = PDFPath + cbLots_Item; if (Directory.Exists(strPath)) { Directory.Delete(strPath, true); } Directory.CreateDirectory(strPath); if (!strPath.EndsWith("\\")) { strPath += "\\"; } int myICount = 0; foreach (DataRow R in T.Rows) { myICount++; LblTotal = LblTotal = string.Format("PG:{0:#,#}", myICount); MyDataSet ds = new MyDataSet(); DataRow RR = ds.Tables[0].NewRow(); string lot = R["Lot"].ToString().Trim(); string NumElec = R["NumElec"].ToString().Trim(); RR["PrecintoCEE"] = get.MyCEEPrecintoToInforme(NumElec); RR["Lot"] = lot; RR["NumeroElec"] = "Número Electoral : " + NumElec; RR["Nombre"] = "Nombre del Endosante (TF) : " + string.Concat(R["Nombre"].ToString().Trim(), " ", R["Paterno"].ToString().Trim(), " ", R["Materno"].ToString().Trim()).Trim(); RR["NombreCee"] = "Nombre del Endosante (CEE) : " + get.MyCEENameToInforme(NumElec); RR["Precinto"] = "Precinto (TF) / Precinto (CEE) : " + R["Precinto"]; RR["StatusCEE"] = "Status (CEE) : " + get.MyCEEStatusToInforme(NumElec); RR["FuncionarioElec"] = "Notario : " + R["notario"]; RR["CandidatoElec"] = "Partido : " + R["Partido"];//R["Candidato"]; //RR["CandidatoName"] = "Nombre Candidato : " + get.MyCandidatoNameToInforme(R["Candidato"].ToString().Trim()); RR["Batch"] = "Batch : " + R["Batch"]; RR["Formulario"] = "Formulario : " + R["Formulario"]; //RR["Cargo"] = "Cargo : " + R["Cargo"].ToString() + "-" + get.MyDecCargoToInforme(R["Cargo"].ToString().Trim()).Trim(); string Candidato = string.Empty; if (R["Candidato"] != null) { Candidato = R["Candidato"].ToString().Trim(); } RR["Razon"] = get.MyDecRechazoToInforme(R["Errores"].ToString(), Candidato, NumElec).Trim(); if (R["LeerMSG"].ToString().Trim().Length > 0) { RR["Razon"] += "\r\n " + R["LeerMSG"].ToString().Trim(); } RR["totalDePaginas"] = string.Format("{0:#,#}", totalDePaginas); RR["Pagina"] = string.Format("{0:#,#}", Pagina); {// Para la Imagen byte[] EndosoImage = (byte[])R["EndosoImage"]; RR["Img"] = EndosoImage; } ds.Rechazadas.Rows.Add(RR); if (!Directory.Exists(strPath)) { Directory.CreateDirectory(strPath); } string pdfName = strPath + Pagina.ToString().PadLeft(5, '0') + "_" + RR["lot"] + "_Rechazadas.pdf"; objRp.SetDataSource(ds); ExportOptions CrExportOptions; DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions(); PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions(); CrDiskFileDestinationOptions.DiskFileName = pdfName; CrExportOptions = objRp.ExportOptions; { CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions; CrExportOptions.FormatOptions = CrFormatTypeOptions; } objRp.Export(); // Export PDF // Pagina++; } //Merge PDFs { MergeEx myMerge = new MergeEx(); myMerge.DestinationFile = strPath; myMerge.setFileName = cbLots_Item + "_Informe de Rechazos"; //pdf name myMerge.setSplit = 1000; String[] FileList = Directory.GetFiles(strPath, "*.pdf"); //_pdfPathOut myICount = 0; foreach (string fileName in FileList) { myICount++; LblTotal = LblTotal = string.Format("Merge PDFs:{0:#,#}", myICount); myMerge.AddFile(fileName); } myMerge.Execute(); foreach (string fileName in FileList) { System.IO.File.Delete(fileName); } //open pdf String fileNamepdf = strPath + myMerge.setFileName + "_1.pdf"; System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = fileNamepdf; process.Start(); //process.WaitForExit(); cbLots_Item_Id = -1; } } returnBoll = true; } catch (Exception ex) { MethodBase site = ex.TargetSite; MessageBox.Show(ex.Message, site.Name, MessageBoxButton.OK, MessageBoxImage.Error); } return returnBoll; })); }