Пример #1
0
        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;
            }));
        }