Esempio n. 1
0
        /// <summary>
        /// Visualiza um relatório.
        /// <br>
        /// O relatório sempre será escrito no disco.
        /// </br>
        /// O designer é montando manualmente.
        /// </summary>
        /// <param name="report"></param>
        public static void PrintReportOverwrite(ReportImage report)
        {
            try
            {
                using (var ctx = new ReportContext())
                {
                    var    current = ctx.ReportImageDao.Find(report.IdReport);
                    string path    = Path.Combine(Application.StartupPath, "Reports", current.ReportName + ".repx");

                    FileManagerIts.WriteBytesToFile(path, current.ReportImageData);

                    //carregue a estrutura do relatório
                    XtraReport xreport = XtraReport.FromFile(path, true);

                    //objeto para gerar a tela de parametros
                    ReportPrintTool reportPrintTool = new ReportPrintTool(xreport);

                    //chama a tela de parametros
                    xreport.CreateDocument();

                    //gera o relatorio
                    PrintPreviewFormEx preview = new PrintPreviewFormEx();
                    preview.PrintingSystem = xreport.PrintingSystem;
                    //exibe o relatorio
                    preview.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                XMessageIts.Erro("Falha gerar relatório\n\n" + ex.Message, "Atenção!!!");
                LoggerUtilIts.GenerateLogs(ex);
            }
        }
Esempio n. 2
0
        private void barBtnExportarTodos_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridView1.IsSelectOneRowWarning())
            {
                var anexos = gridView1.GetItens <AnexoLancamento>();

                var destiny = Path.Combine(FileManagerIts.DeskTopPath,
                                           "Anexos" + DateTime.Now.ToString("dd-MM-yyyy"));

                FileManagerIts.CreateDirectory(destiny);
                foreach (var anexo in anexos)
                {
                    string name = anexo.IdentificacaoAnexo.Replace("/", "-")
                                  + anexo.Extensao;
                    string fileName = Path.Combine(destiny, name);

                    if (FileManagerIts.WriteBytesToFile(fileName, anexo.DataFile))
                    {
                        XMessageIts.Mensagem("Anexo salvo com sucesso!");
                    }
                    else
                    {
                        XMessageIts.Erro("Falha ao salvar anexo!\n" + anexo.PathFile);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Localiza um relatorio no banco e carrega para um arquivo temporario
        /// Este cache irá ser salvo no banco
        /// </summary>
        /// <param name="reportID"></param>
        public string LoadToCache(ReportImage report)
        {
            try
            {
                using (var ctx = new ReportContext())
                {
                    //recupera o objeto do banco para alteração dos campos
                    report = ctx.ReportImageDao.Find(report.IdReport);

                    //caminho do relatorio
                    string reportPath = string.Format("{0}\\{1}", _reportDir, report.ReportName + ".repx");

                    //gera o arquivos atraves dos bytes salvo no banco
                    if (!File.Exists(reportPath))
                    {
                        FileManagerIts.WriteBytesToFile(reportPath, report.ReportImageData);
                    }

                    return(reportPath);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 4
0
        private void barBtnExportarAnexo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridView1.IsSelectOneRowWarning())
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "All Files | *.*";

                var anexo = gridView1.GetFocusedRow <AnexoLancamento>();

                sfd.FileName = anexo.IdentificacaoAnexo + anexo.Extensao;
                var op = sfd.ShowDialog();

                if (op == DialogResult.OK)
                {
                    if (FileManagerIts.WriteBytesToFile(sfd.FileName, anexo.DataFile))
                    {
                        XMessageIts.Mensagem("Anexo salvo com sucesso!");
                    }
                    else
                    {
                        XMessageIts.Erro("Falha ao salvar anexo!");
                    }
                }
            }
        }
Esempio n. 5
0
        public static void ExportReport(ReportImage rpt)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter   = ReportFilter;
            sfd.FileName = "Export_" + rpt.ReportName;
            var op = sfd.ShowDialog();

            //novo
            var novo = new ReportImage();

            //gera um novo
            novo.Update(rpt);

            //serializa p relatorio
            var bytes = SerializeIts.SerializeObject(novo);

            if (op == DialogResult.OK)
            {
                if (FileManagerIts.WriteBytesToFile(sfd.FileName, bytes))
                {
                    XMessageIts.Mensagem("Arquivo salvo com sucesso!");
                }
                else
                {
                    XMessageIts.Erro("Erro na exportação do relatório!");
                }
            }
        }
Esempio n. 6
0
        public static void ExportDashboardList(List <DashboardImage> reports)
        {
            string outReports = Path.Combine(FileManagerIts.DeskTopPath, "Dashboards ITS");

            if (!Directory.Exists(outReports))
            {
                FileManagerIts.CreateDirectory(outReports);
            }

            bool flag = false;

            foreach (var rpt in reports)
            {
                var novo = new DashboardImage();
                //gera um novo
                novo.Update(rpt);


                string file = outReports + "\\" + rpt.ReportName + ".itsdsh";

                //serializa p relatorio
                var bytes = SerializeIts.SerializeObject(novo);
                flag = FileManagerIts.WriteBytesToFile(file, bytes);
            }
            if (flag)
            {
                XMessageIts.Mensagem("Dashboards exportados com sucesso!");
            }
            else
            {
                XMessageIts.Erro("Dashboards exportados com erro!");
            }
        }
Esempio n. 7
0
        private void barBtnViewAttach_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridViewAnexos.IsSelectOneRowWarning())
            {
                var row = gridViewAnexos.GetFocusedRow <AnexoPackage>();

                if (row != null)
                {
                    //evita um nome duplicado
                    string file = FileManagerIts.GetTempFile(row.PathFile);
                    FileManagerIts.DeleteFile(file);
                    FileManagerIts.WriteBytesToFile(file, row.DataFile);

                    if (file.EndsWith(".sql"))
                    {
                        var high = new XFrmHighlighting(file, ScintillaNET.Lexer.Sql);
                        high.ShowDialog();

                        if (high.IsTextSave)
                        {
                            row.DataFile = FileManagerIts.GetBytesFromFile(file);
                        }
                    }
                    else
                    {
                        //deixe o sistema se virar
                        FileManagerIts.OpenFromSystem(file);
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Carrega um .xml em disco
        /// </summary>
        /// <param name="dash"></param>Objeto DashboardImage
        /// <returns></returns>Obtém o path do dashboard no banco
        public string LoadToChache(DashboardImage dash, bool overwrite = false)
        {
            using (var ctx = new ReportContext())
            {
                try
                {
                    //recupera o objeto do banco para alteração dos campos
                    dash = ctx.DashboardImageDao.Find(dash.IdReport);

                    //caminho do dashboard
                    string dashboardPath = generatePath(dash, ctx);


                    if (overwrite)
                    {
                        FileManagerIts.DeleteFile(dashboardPath);
                    }

                    //gera o arquivo atraves dos bytes salvos no banco e gera um arquivo em disco
                    if (!File.Exists(dashboardPath))
                    {
                        FileManagerIts.WriteBytesToFile(dashboardPath, dash.ReportImageData);
                    }

                    //caso contrario vou carregar diretamente do disco

                    return(dashboardPath);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
Esempio n. 9
0
        private void barBtnExportarTo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridViewAnexos.IsSelectOneRowWarning())
            {
                var anexo = gridViewAnexos.GetFocusedRow <AnexoPackage>();

                string ext = anexo.Extensao;
                //Text Files (*.txt)|*.txt|
                saveFileDialog1.Filter = "ITE Solution Attach (*" + ext + ")| *" + ext;

                saveFileDialog1.FileName = anexo.FileName;
                var op = saveFileDialog1.ShowDialog();


                if (op == DialogResult.OK)
                {
                    if (FileManagerIts.WriteBytesToFile(saveFileDialog1.FileName, anexo.DataFile))
                    {
                        XMessageIts.Mensagem("Arquivo salvo com sucesso!");
                    }
                    else
                    {
                        XMessageIts.Erro("Erro na exportação do relatório!");
                    }
                }
            }
        }
Esempio n. 10
0
        public bool PublicarPacote(Package pacote)
        {
            try
            {
                using (var ctx = new AdminContext())
                {
                    var pkgCurrent = ctx.PackageDao.Find(pacote.IdPacote);
                    var pkgNew     = new Package();

                    //passa tudo do pacote atual pro novo
                    pkgNew.Update(pkgCurrent);

                    //novo status
                    pkgNew.Status = Enumeradores.TypeStatusPackage.Publicado;

                    foreach (var anx in pacote.Anexos)
                    {
                        var anxSalvar = new AnexoPackage(anx.DataFile, anx.FileName, anx.PathFile);
                        pkgNew.Anexos.Add(anxSalvar);
                    }

                    var            bytes = SerializeIts.SerializeObject(pkgNew);
                    SaveFileDialog sfd   = new SaveFileDialog();
                    sfd.Filter = "IT Solution package| *.itspkg";
                    //sfd.FilterIndex = 0;
                    //sfd.DefaultExt = ".itsPkg";
                    sfd.FileName = "ITS_Package_" + pkgNew.NumeroPacote;
                    var op = sfd.ShowDialog();

                    if (op == DialogResult.OK)
                    {
                        if (FileManagerIts.WriteBytesToFile(sfd.FileName, bytes))
                        {
                            //publicar o pacote
                            pkgCurrent.Publish(DateTime.Now, bytes);

                            var transation = ctx.PackageDao.Update(pkgCurrent);
                            if (transation)
                            {
                                XMessageIts.Mensagem("Pacote publicado com sucesso!");

                                pacote.Update(pkgCurrent);
                                return(transation);
                            }
                        }
                    }
                    return(false);
                }
            }
            catch (Exception ex)
            {
                XMessageIts.ExceptionMessage(ex, "Falha ao publicar pacote", "Publicação de Pacote");

                return(false);
            }
        }
Esempio n. 11
0
 private void groupControlLogo_DoubleClick(object sender, EventArgs e)
 {
     if (pictureFotoProduto.Image != null)
     {
         var img  = ImageUtilIts.GetBytesFromImage(pictureFotoProduto.Image);
         var path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".jpg");
         FileManagerIts.WriteBytesToFile(path, img);
         FileManagerIts.OpenFromSystem(path);
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Cria um XtraReport a partir do nome do relatório salvo no banco.
        /// </summary>
        /// <param name="reportName"></param>
        /// <param name="showParams"></param>
        /// <returns></returns>
        public static XtraReport CreateReportByName(string reportName, bool showParams = true)
        {
            using (var ctx = new ReportContext())
            {
                try
                {
                    var    current = ctx.ReportImageDao.First(r => r.ReportName == reportName);
                    string dir     = Path.GetTempPath().Replace("Temp", "Reports");

                    FileManagerIts.CreateDirectory(dir);

                    string path = Path.Combine(dir, current.ReportName + ".repx");

                    //salva o report no disco
                    FileManagerIts.WriteBytesToFile(path, current.ReportImageData);

                    //carregue a estrutura do relatório
                    XtraReport report = XtraReport.FromFile(path, true);


                    if (showParams == false)
                    {
                        //nao exibe
                        foreach (var p in report.Parameters)
                        {
                            p.Visible = false;
                        }
                    }

                    //objeto para chamar a tela de parametros
                    ReportPrintTool reportPrintTool = new ReportPrintTool(report);

                    ReportUtil.SetParamDataSource(report.DataSource as SqlDataSource, AppConfigManager.Configuration.AppConfig);
                    //criar o documento
                    report.CreateDocument();

                    //libera memoria da ferramenta
                    reportPrintTool.Dispose();

                    //retorna o relatorio
                    return(report);
                }
                catch (Exception ex)
                {
                    XMessageIts.ExceptionMessageDetails(ex, "Impossível gerar relatório !", "Falha ao gerar relatório");
                    LoggerUtilIts.GenerateLogs(ex);
                    return(null);
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// PDF nao fica muito bom
        /// </summary>
        /// <param name="bb"></param>
        public static void ShowBoletoPDF(BoletoBancario bb)
        {
            var bytes = bb.MontaBytesPDF();

            var path = Path.Combine(FileManagerIts.DeskTopPath, "Boleto-" + bb.Banco.Nome + ".pdf");


            for (int i = 1; File.Exists(path); i++)
            {
                path = Path.Combine(FileManagerIts.DeskTopPath, "Boleto-" + bb.Banco.Nome + "_" + i + ".pdf");
            }

            FileManagerIts.WriteBytesToFile(path, bytes);


            FileManagerIts.OpenFromSystem(path);
        }
Esempio n. 14
0
        public Package SaveFilePacote(Package pacote)
        {
            try
            {
                var pkgSalvar = new Package();

                pkgSalvar.DataCriacao    = pacote.DataCriacao;
                pkgSalvar.DataPublicacao = pacote.DataPublicacao;
                pkgSalvar.Descricao      = pacote.Descricao;
                pkgSalvar.NumeroPacote   = pacote.NumeroPacote;
                pkgSalvar.Sintoma        = pacote.Sintoma;
                pkgSalvar.Status         = pacote.Status;
                pkgSalvar.Tratamento     = pacote.Tratamento;

                foreach (var anx in pacote.Anexos)
                {
                    var anxSalvar = new AnexoPackage();
                    anxSalvar.DataFile = anx.DataFile;
                    anxSalvar.FileName = anx.FileName;
                    anxSalvar.PathFile = anx.PathFile;
                    pkgSalvar.Anexos.Add(anxSalvar);
                }

                var            bytes = SerializeIts.SerializeObject(pkgSalvar);
                SaveFileDialog sfd   = new SaveFileDialog();
                sfd.Filter   = "IT Solution package| *.itspkg";
                sfd.FileName = "ITS_Package_" + pkgSalvar.NumeroPacote;

                var op = sfd.ShowDialog();

                if (op == DialogResult.OK)
                {
                    if (FileManagerIts.WriteBytesToFile(sfd.FileName, bytes))
                    {
                        XMessageIts.Mensagem("Pacote salvo com sucesso!");
                    }
                }
                return(pkgSalvar);
            }
            catch (Exception ex)
            {
                XMessageIts.ExceptionMessage(ex);
                return(null);
            }
        }
Esempio n. 15
0
        private void barBtnVisualizarAnexo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridView1.IsSelectOneRowWarning())
            {
                var row = gridView1.GetFocusedRow <AnexoLancamento>();

                if (row != null)
                {
                    //evita um nome duplicado
                    string file = FileManagerIts.GetTempFile(row.PathFile);
                    FileManagerIts.DeleteFile(file);
                    FileManagerIts.WriteBytesToFile(file, row.DataFile);
                    FileManagerIts.OpenFromSystem(file);

                    this._temps.Add(file);
                }
            }
        }
Esempio n. 16
0
        public XtraReport GetReport(int idReport)
        {
            using (var ctx = new ReportContext())
            {
                var    current   = ctx.ReportImageDao.Find(idReport);
                string reportDir = Path.GetTempPath().Replace("Temp", "Reports");
                string path      = Path.Combine(reportDir, current.ReportName + ".repx");
                //var pathPrnx = Path.Combine(Application.StartupPath, "Reports", current.ReportName + ".prnx");

                //carregue a estrutura do relatório
                XtraReport xreport = new XtraReport();

                if (!File.Exists(path))
                {
                    FileManagerIts.WriteBytesToFile(path, current.ReportImageData);
                }
                xreport.LoadLayout(path);
                //var rpt = (ItsXtraReport)xreport;

                return(xreport);
            }
        }
Esempio n. 17
0
        public static void ExportDashaboard(DashboardImage dash)
        {
            var            bytes = SerializeIts.SerializeObject(dash);
            SaveFileDialog sfd   = new SaveFileDialog();

            sfd.Filter   = DashboardFilter;
            sfd.FileName = "Export_" + dash.ReportDescription;
            var op = sfd.ShowDialog();

            if (op == DialogResult.OK)
            {
                //sfd.FileName = Path.ChangeExtension(sfd.FileName, "iteReport");

                if (FileManagerIts.WriteBytesToFile(sfd.FileName, bytes))
                {
                    XMessageIts.Mensagem("Arquivo salvo com sucesso!");
                }
                else
                {
                    XMessageIts.Erro("Erro");
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Visualizar ou salvar o relatório selecionado do spool
        /// </summary>
        /// <param name="idSpool">Id do spool</param>
        /// <param name="typeGeracaoSpool">Informar o tipo: Visualizar, ExpPdf ou ExpExcel</param>
        public void GerarRelatorioFromSpool(Int32 idSpool, TypeGeracaoSpool typeGeracaoSpool)
        {
            using (var ctx = new ReportContext())
            {
                try
                {
                    var sv = new SaveFileDialog();
                    //relatorio selecionado
                    var relat = ctx.ReportSpoolDao.Find(idSpool);
                    //caminho temporario
                    var path = Application.StartupPath + "\\temp.prnx";
                    //escreve os bytes do relatorio selecionado no arquivo
                    var reportImageUnzip = ZipUtil.UnzipFromBytes(relat.ReportSpoolImage);
                    FileManagerIts.WriteBytesToFile(path, reportImageUnzip);
                    // Create a PrintingSystem instance.
                    PrintingSystem ps = new PrintingSystem();

                    // Load the document from a file.
                    ps.LoadDocument(path);

                    // Create an instance of the preview dialog.
                    PrintPreviewRibbonFormEx preview = new PrintPreviewRibbonFormEx();

                    PrintPreviewFormEx prev = new PrintPreviewFormEx();
                    prev.PrintingSystem = ps;
                    // Load the report document into it.
                    //preview.PrintingSystem = ps;
                    if (typeGeracaoSpool == TypeGeracaoSpool.PreVisualizar)
                    {
                        // Show the preview dialog.
                        //preview.ShowDialog(); //ribbon

                        //não ribbon
                        prev.Show();
                    }
                    else if (typeGeracaoSpool == TypeGeracaoSpool.ExportarParaPdf)
                    {
                        sv.Filter = "Arquivo PDF | *.pdf";
                        sv.ShowDialog();
                        if (sv.FileName != "")
                        {
                            ps.ExportToPdf(sv.FileName);
                        }
                    }
                    else if (typeGeracaoSpool == TypeGeracaoSpool.ExportarParaExcel)
                    {
                        sv.Filter = "Arquivo XLSX | *.xlsx";
                        sv.ShowDialog();
                        if (sv.FileName != "")
                        {
                            ps.ExportToXlsx(sv.FileName);
                        }
                    }
                    //Remova o relatorio temporario
                    FileManagerIts.DeleteFile(path);
                }
                catch
                (Exception
                 ex)
                {
                    LoggerUtilIts.ShowExceptionLogs(ex);
                }
            }
        }
Esempio n. 19
0
        private static XtraReport printReportXtra(int idreport, bool requestParameters = true,
                                                  bool visibleParameters = true, bool ribbon = false)
        {
            try
            {
                using (var ctx = new ReportContext())
                {
                    var    current   = ctx.ReportImageDao.Find(idreport);
                    string reportDir = Path.GetTempPath().Replace("Temp", "Reports");
                    string path      = Path.Combine(reportDir, current.ReportName + ".repx");
                    //var pathPrnx = Path.Combine(Application.StartupPath, "Reports", current.ReportName + ".prnx");

                    //carregue a estrutura do relatório
                    XtraReport xreport = new XtraReport();

                    if (!File.Exists(path))
                    {
                        FileManagerIts.WriteBytesToFile(path, current.ReportImageData);
                    }
                    xreport.LoadLayout(path);

                    var ds      = xreport.DataSource as SqlDataSource;
                    var appConf = AppConfigManager.Configuration.AppConfig;

                    if (ds == null)
                    {
                        ds = new SqlDataSource(appConf.ServerName);
                    }

                    SetParamDataSource(ds, appConf);

                    ds.Connection.CreateConnectionString();

                    ds.RebuildResultSchema();

                    //objeto para gerar a tela de parametros
                    //ReportPrintTool reportPrintTool = new ReportPrintTool(xreport);

                    //permissao para solicitar os parametros
                    xreport.RequestParameters = requestParameters;


                    //permissao para exibir os parametros
                    if (visibleParameters == false)
                    {
                        foreach (var p in xreport.Parameters)
                        {
                            p.Visible = false;
                        }
                    }
                    return(xreport);

                    //chama a tela de parametros
                    //xreport.CreateDocument();

                    //libera memoria da ferramenta
                    //reportPrintTool.Dispose();

                    //if (ribbon)
                    //    //chama o ribbon para exibir o relatório
                    //    xreport.ShowRibbonPreview();
                    //else
                    //    xreport.ShowPreview();

                    ////carregando o relatório manualmente
                    ////salva o documento gerado em prnx
                    //xreport.PrintingSystem.SaveDocument(pathPrnx);

                    //// Create a PrintingSystem instance.
                    //PrintingSystem ps = new PrintingSystem();

                    //// Load the document from a file.
                    //ps.LoadDocument(pathPrnx);

                    ////ribbon form para visualizar o relatório
                    //PrintPreviewRibbonFormEx preview = new PrintPreviewRibbonFormEx();
                    //preview.PrintingSystem = ps;
                    ////xtraform para visualizar o relatório
                    //PrintPreviewFormEx prev = new PrintPreviewFormEx();
                    //prev.PrintingSystem = ps;
                    ////exibe o relatorio
                    //preview.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                XMessageIts.Erro("Falha gerar relatório\n\n" + ex.Message, "Atenção!!!");
                LoggerUtilIts.GenerateLogs(ex);
                return(null);
            }
        }
Esempio n. 20
0
        //Estou considerando que o pacote .zip é um pacote com dlls
        private void updateDLLs()
        {
            try
            {
                //pkg do arquivo zip
                var pkg = this._pacote.Anexos.FirstOrDefault();

                //nome do arquivo zip
                string zipResource = pkg.FileName;

                //extraindo atualização
                taskLog("Iniciando atualização: " + zipResource);

                if (Directory.Exists(_resourceDir))
                {
                    zipResource = _resourceDir;
                }
                else
                {
                    //raiz da instalação
                    var raiz = Path.GetPathRoot(_installDir);

                    //garante que o root de instalação e atualização sejam são iguais
                    //a atualização sera extraida no mesmo o root "=> Volume do disco Ex: C:
                    //Deve ser o mesmo root onde esta a instalação do programa
                    string resourceDir = Path.Combine(Path.GetPathRoot(raiz), "ite_package_update_" + Guid.NewGuid());

                    //cria o temporario para receber a atualização
                    FileManagerIts.CreateDirectory(resourceDir);

                    //agora eu tenho um diretorio entao gere um arquivo .zip
                    zipResource = resourceDir + "\\" + zipResource;

                    //gera o zip em disco
                    FileManagerIts.WriteBytesToFile(zipResource, pkg.DataFile);

                    //extrai as atualizações pra um temporario
                    ZipUtil.ExtractToDirectory(zipResource, resourceDir);
                }

                taskLog("Salvando instalação atual ...");
                //garante que exista somente um .bak
                FileManagerIts.DeleteDirectory(_installDir + ".bak");

                //faz a copia o da instalaçao atual
                FileManagerIts.DirectoryCopy(_installDir, _installDir + ".bak");

                taskLog("Diretório pronto para receber atualização ...");

                taskLog("Atualizando diretórios e dlls ... ");

                Task.Run(new Action(() =>
                {
                    foreach (var f in new FileManagerIts().ToFilesRecursive(_resourceDir))
                    {
                        //vo mostrar so o nome o temporario q gerei nao eh importante
                        taskLog("Atualizando: " + Path.GetFileName(f));
                    }
                }));

                //ilustrar dps
                _taskManager.UpdateSoftware(_resourceDir, _installDir);

                //apague o temporário
                FileManagerIts.DeleteDirectory(_resourceDir);
            }
            catch (Exception ex)
            {
                try
                {
                    cancelation();

                    taskLog("Falha no pacote de atualizações");
                    taskLog(ex.Message);
                    LoggerUtilIts.ShowExceptionLogs(ex, this);
                }

                catch (OperationCanceledException oc)
                {
                    Console.WriteLine("Operação cancelada=> " + oc.Message);
                }
            }
        }
Esempio n. 21
0
        private void loadPackage(Package pacote)
        {
            this._pacote = pacote;
            this.wizardControl1.SelectedPageIndex = 1;
            try
            {
                groupControlInfoPackage.Visible = true;

                if (pacote.DataPublicacao.HasValue)
                {
                    lbDtPublish.Text   = pacote.DataPublicacao.Value.ToShortDateString();
                    labelControl6.Text = pacote.NumeroPacote;
                    memoEditDesc.Text  = pacote.Descricao;


                    if (pacote.Anexos.Any(a => a.Extensao == ".zip"))
                    {
                        var    firstPkg = pacote.Anexos.FirstOrDefault();
                        string zipName  = firstPkg.FileName;
                        //crie um temporario para receber os dados do pacote
                        this._resourceDir = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(zipName));
                        FileManagerIts.DeleteDirectory(_resourceDir);
                        FileManagerIts.CreateDirectory(_resourceDir);

                        try
                        {
                            //arquivo zip
                            string zipFile = Path.Combine(Path.GetTempPath(), zipName);

                            //gera o zip em disco
                            FileManagerIts.WriteBytesToFile(zipFile, firstPkg.DataFile);

                            //extrai os dados pro temporario
                            ZipUtil.ExtractToDirectory(zipFile, this._resourceDir);
                            //todos os arquivos
                            foreach (string item in FileManagerIts.ToFiles(this._resourceDir, new string[] { ".sql" }, true))
                            {
                                if (item.EndsWith(".sql"))
                                {
                                    _containsSql = true;
                                }
                                else if (item.EndsWith(".dll"))
                                {
                                    _containsDll = true;
                                }
                            }
                            //ja extrai o pacote e nao preciso dele no disco, os dados ja foram extraidos
                            FileManagerIts.DeleteFile(zipFile);
                        }
                        catch (Exception ex)
                        {
                            string msg = "Falha na verificação de integridade do pacote.";
                            XMessageIts.ExceptionMessageDetails(ex, msg);
                            LoggerUtilIts.GenerateLogs(ex, msg);
                        }
                    }
                    else
                    {
                        int countSql = pacote.Anexos.Count(a => a.Extensao == ".sql");
                        int countDll = pacote.Anexos.Count(a => a.Extensao == ".dll");


                        this._containsSql = countSql > 0;
                        this._containsDll = countDll > 0;
                    }
                    this.pnlSql.Visible = _containsSql;

                    if (_containsDll)
                    {
                        this.pnlDlls.Visible = true;
                        detectInstallDir();
                        //this.groupControlInfoPackage.Location = new Point(17, 251);
                        //this.groupControlInfoPackage.Size = new Size(806, 242);
                    }
                    else
                    {
                        this.pnlDlls.Visible = false;
                        //this.groupControlInfoPackage.Location = new Point(17, 159);
                        //this.groupControlInfoPackage.Size = new Size(806, 344);
                    }
                    wizardPage1.AllowNext = true;
                }
                else
                {
                    XMessageIts.Erro("O pacote selecionado não foi publicado e não pode ser aplicado.");
                }
            }
            catch (Exception ex)
            {
                string msg = "O pacote de atualização informado é inválido!"
                             + "\n\nContate o administrador para aplicar atualização.";

                XMessageIts.ExceptionMessageDetails(ex, msg, "Atenção");

                LoggerUtilIts.GenerateLogs(ex, msg);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Gera um relatório para o Spool de relatórios
        /// </summary>
        /// <param name="id">ID do relatório</param>
        /// <returns></returns>
        public void PrintReportSpool(int id, bool visualizar = true)
        {
            try
            {
                var ctx         = new ReportContext();
                var imageReport = ctx.ReportImageDao.Find(id);
                var path        = Application.StartupPath + "\\temp.repx";
                var pathPrnx    = Application.StartupPath + "\\tempPrnx.prnx";
                var isCanceled  = false;

                //download do *.repx do banco
                FileManagerIts.WriteBytesToFile(path, imageReport.ReportImageData);

                //carregue a estrutura do relatório
                XtraReport report = XtraReport.FromFile(path, true);

                //tela personalizado de parametros
                var parameters = new XFrmReportParams_DEV(report.Parameters);

                //se o relatorio tem parametros....
                if (report.Parameters.Count >= 1)
                {
                    report.RequestParameters = false;

                    //chame a tela de paramentros
                    parameters.ShowDialog();

                    report.Parameters.Clear();

                    foreach (var item in parameters.NewParametros)
                    {
                        report.Parameters.Add(item);
                    }

                    isCanceled = parameters._isCanceled;
                }

                #region Processamento do relatório
                //se a geração nao foi cancelada em
                //XFrmReportParams, continue com a geração
                if (isCanceled == false)
                {
                    //criar o documento
                    ReportPrintTool reportPrintTool = new ReportPrintTool(report);
                    report.CreateDocument();

                    //salva o documento gerado em prnx
                    report.PrintingSystem.SaveDocument(pathPrnx);

                    //carrega o relatório gerado para bytes[]
                    var image = FileManagerIts.ReadBytesFromFile(pathPrnx);

                    //zipar a imagem
                    var imageZipped = ZipUtil.ZipFromBytes(image);

                    //criaçao do relatorio
                    var imgSave = new ReportSpool(DateTime.Now, report.DisplayName, imageZipped);
                    var result  = ctx.ReportSpoolDao.Save(imgSave);


                    if (result && visualizar)
                    {
                        GerarRelatorioFromSpool(imgSave.IdSpool, TypeGeracaoSpool.PreVisualizar);
                    }
                    else if (result && !visualizar)
                    {
                        XMessageIts.Mensagem("Relatório gerado com sucesso!", "Sucesso");
                    }
                    else
                    {
                        XMessageIts.Advertencia("Falha ao gerar relatório.\n\n" +
                                                "Contate o adminstrador do sistema", "Atenção");
                    }

                    //Remova o relatorio temporario
                    FileManagerIts.DeleteFile(path);
                    FileManagerIts.DeleteFile(pathPrnx);
                }

                #endregion

                //se não passar pelo if, a geração foi cancelada, então Task<bool> = false
            }
            catch (Exception ex)
            {
                LoggerUtilIts.ShowExceptionLogs(ex);
                throw ex;
            }
        }
Esempio n. 23
0
        public void PrintReportCustomById(int idReport)
        {
            try
            {
                using (var ctx = new ReportContext())
                {
                    var imageReport = ctx.ReportImageDao.Find(idReport);
                    var path        = FileManagerIts.DeskTopPath + "\\temp.repx";

                    //download do *.repx do banco
                    FileManagerIts.WriteBytesToFile(path, imageReport.ReportImageData);

                    //carregue a estrutura do relatório
                    XtraReport report = XtraReport.FromFile(path, true);

                    //tela personalizado de parametros
                    var parameters = new XFrmReportParams_DEV(report.Parameters);

                    //se o relatorio tem parametros....
                    if (report.Parameters.Count >= 1)
                    {
                        //cancele os parametros nativos
                        report.RequestParameters = false;

                        //chame a tela de parametros
                        parameters.ShowDialog();

                        //limpar os parametros atuais
                        report.Parameters.Clear();

                        //add os novos parametros
                        foreach (var p in parameters.NewParametros)
                        {
                            report.Parameters.Add(p);
                        }
                    }

                    //se a geração nao foi cancelada em
                    if (parameters._isCanceled == false)
                    {
                        //criar o documento
                        ReportPrintTool reportPrintTool = new ReportPrintTool(report);
                        report.CreateDocument();

                        //exibe o relatorio
                        report.ShowPreview();

                        //Remova o relatorio temporario
                        FileManagerIts.DeleteFile(path);
                    }
                    else
                    {
                        XMessageIts.Mensagem("Relatório cancelado.");
                    }
                }
                //se não passar pelo if, a geração foi cancelada, então Task<bool> = false
            }
            catch (Exception ex)
            {
                LoggerUtilIts.ShowExceptionLogs(ex);
                throw ex;
            }
        }