Exemple #1
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);
                }
            }
        }
Exemple #2
0
        private bool isRotinaChecagem()
        {
            string rotinaChecagem = Path.Combine(Application.StartupPath, "r_ch_vendas_lanctos");
            var    dataAtual      = DateTime.Now.Date;

            if (File.Exists(rotinaChecagem) == false)
            {
                //cria o arquivo
                FileManagerIts.CreateFile(rotinaChecagem);
            }
            try
            {
                string checagem          = FileManagerIts.GetDataStringFile(rotinaChecagem);
                Nullable <DateTime> data = DataUtil.ToDate(checagem).Date;

                if (data == dataAtual)
                {
                    return(true);
                }
                else
                {
                    //registra a ocorrencia da rotina no dia
                    FileManagerIts.OverWriteOnFile(rotinaChecagem, dataAtual.ToShortDateString());
                }
            }
            catch (Exception)
            {
                FileManagerIts.DeleteFile(rotinaChecagem);
            }
            return(false);
        }
Exemple #3
0
        internal void MonitorarFilial()
        {
            if (UnitWork.Filial == null)
            {
                UnitWork.Filial = new EmpresaFilial();
                if (FormsUtil.isFormDisposedOrNull(this._xFrmSetMatFilial))
                {
                    _xFrmSetMatFilial = new XFrmSetMatrizFilial();
                }


                if (this._xFrmSetMatFilial.Visible == false)
                {
                    FileManagerIts.DeleteFile(UnitWork.PREFERENCIAS);
                    _xFrmSetMatFilial.Text = "Conexão com nova base detectada";
                    _xFrmSetMatFilial.ChangeIconBtnOk(Properties.Resources.bolocalization_16x16);

                    _xFrmSetMatFilial.ShowDialog();

                    if (!_xFrmSetMatFilial.IsFilial)
                    {
                        MessageBoxTick.Show("Seleção de matriz cancelada o programa será encerrado!",
                                            "Atenção", 5);//5 segundso
                        Application.Exit();
                    }
                }
            }
        }
Exemple #4
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);
                    }
                }
            }
        }
Exemple #5
0
        private static void showResultBuilder(StringBuilder sb)
        {
            Console.WriteLine(sb);
            var file = FileManagerIts.DeskTopPath + "\\out.txt";

            FileManagerIts.DeleteFile(file);
            FileManagerIts.AppendLines(file, sb.ToString());
            FileManagerIts.OpenFromSystem(file);
        }
Exemple #6
0
        /// <summary>
        /// Remove os dashboard criados no disco
        /// <br>Todos .xml será apagado</br>
        /// </summary>
        /// <param name="dashboardAnt"></param>
        public void ClearCache()
        {
            var dashs = FileManagerIts.ToFiles(_dashboardDir, new string[] { "", ".xml" });

            foreach (var path in dashs)
            {
                FileManagerIts.DeleteFile(path);
            }
        }
Exemple #7
0
        /// <summary>
        /// Atualiza o dashboard existente no banco
        /// </summary>
        /// <param name="dashboardDesigner">Designer do dashboard</param>
        /// <param name="dash">Dashboard a ser persistido</param>
        /// <returns>O Dashboard persistido no banco ou null</returns>
        public bool UpdateDashboard(DashboardDesigner dashboardDesigner, DashboardImage dash)
        {
            try
            {
                using (var ctx = new ReportContext())
                {
                    //nome padrão
                    dash.DefaultName = dashboardDesigner.ActiveControl.Name;

                    //gera um nome aleatorio utilizando o nome setado no dashboard
                    string dashPath = generatePath(dash, ctx);
                    // using (MemoryStream ms = new MemoryStream())

                    //objeto designer do dashboard
                    var designer = dashboardDesigner.Dashboard;

                    FileManagerIts.DeleteFile(dashPath);
                    //salva o layout em memoria
                    //designer.SaveToXml(ms);

                    //salva o dashboard no disco em formato xml
                    designer.SaveToXml(dashPath);

                    var bytes = FileManagerIts.GetBytesFromFile(dashPath); //ms.GetBuffer();

                    //passando objeto pro contexto
                    var current = ctx.DashboardImageDao.Find(dash.IdReport);

                    //atualiza o dashboard
                    current.Update(dash);

                    //garante a atualização
                    current.ReportImageData = bytes;

                    //efetiva no banco
                    return(ctx.DashboardImageDao.Update(current));
                }
            }
            catch (Exception ex)
            {
                XMessageIts.Advertencia("Houve um erro na atualização do dashboard.\n\n"
                                        + ex.Message);

                LoggerUtilIts.GenerateLogs(ex);
                return(false);
            }
        }
Exemple #8
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);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Exportar os dados para uma planilha .xlsx localizada no Desktop
        ///
        /// O metodo de exportação pertence ao gridControl
        /// </summary>
        /// <param name="gridView"></param>
        public static void ExportXlsxDirect(this GridView gridView)
        {
            if (gridView.IsEmpty)
            {
                XMessageIts.Mensagem("Nada a exportar !");
            }
            else
            {
                if (gridView.DataSource != null)
                {
                    string excelName = "ExportExcel-" + DataUtil.ToDateSql();
                    string excel     = Path.Combine(FileManagerIts.DeskTopPath, excelName) + ".xlsx";
                    FileManagerIts.DeleteFile(excel);

                    gridView.ExportToXlsx(excel);
                    FileManagerIts.OpenFromSystem(excel);
                }
            }
        }
Exemple #10
0
        private void barBtnExportarPdf_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridView1.IsEmpty)
            {
                XMessageIts.Mensagem("Nada a exportar !");
            }
            else
            {
                if (gridView1.DataSource != null)
                {
                    string pdfName = "export_cambio_pdf" + DataUtil.ToDateSql();
                    string pdf     = Path.Combine(FileManagerIts.DeskTopPath, pdfName) + ".pdf";
                    FileManagerIts.DeleteFile(pdf);

                    gridControl1.ExportToPdf(pdf);
                    FileManagerIts.OpenFromSystem(pdf);
                }
            }
        }
Exemple #11
0
        public static void SaveLayout(this GridView gridView, string layoutName, string path = null)
        {
            if (path == null)
            {
                string layouts = Path.Combine(Application.ExecutablePath, "Layouts");
                if (Directory.Exists(layouts))
                {
                    Directory.CreateDirectory(layouts);
                }
                //barBtnSalvar_ItemClick(null, null);

                layoutName = layoutName.Replace(".xml", "");

                string xml = Path.Combine(layouts, layoutName + ".xml");
                FileManagerIts.DeleteFile(xml);
                //OptionsLayoutBase.FullLayout
                gridView.SaveLayoutToXml(xml);
            }
        }
Exemple #12
0
        /// <summary>
        /// Recupera o nome de usuário no arquivo de preferências
        /// </summary>
        /// <param name="logon"></param>
        /// <returns></returns>
        private string retryLogon(string logon)
        {
            if (logon == null)
            {
                List <string> preferencias = FileManagerIts.GetDataFile(UnitWork.PREFERENCIAS);
                if (preferencias.Count > 3)
                {
                    try
                    {
                        //recupera do arquivo o logon
                        return(ASCIIEncodingIts.Decoded(preferencias[3]));
                    }
                    catch (Exception ex)
                    {
                        LoggerUtilIts.ShowExceptionLogs(ex);

                        FileManagerIts.DeleteFile(UnitWork.PREFERENCIAS);
                        return(null);
                    }
                }
            }
            return(logon);
        }
Exemple #13
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);
            }
        }
Exemple #14
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;
            }
        }
Exemple #15
0
 public void DeletePreferences()
 {
     FileManagerIts.DeleteFile(UnitWork.PREFERENCIAS);
 }
Exemple #16
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;
            }
        }
Exemple #17
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);
                }
            }
        }