コード例 #1
0
        /// <summary>
        /// Importa os registros do arquivo de log(.CSV) e insere no banco de dados
        /// </summary>
        public Boolean ImportFile(String fileName)
        {
            DateTime?fileDate = PrintLogFile.GetDate(fileName);

            // Informações de trace são enviadas ao listener através de NotifyListener()
            // O listener grava essas informações em log de arquivo
            CSVReader reader = new CSVReader(fileName, listener);

            NotifyListener("Fazendo a leitura do CSV.");
            DataTable printedDocumentTable = reader.Read();
            int       rowCount             = printedDocumentTable.Rows.Count;

            // Verifica se existem registros no CSV
            if (rowCount < 1)
            {
                NotifyListener("CSV inválido. Nenhum registro encontrado.");
                return(false);
            }

            // Informa a quantidade de registros no CSV e uma amostra de seu conteúdo
            NotifyListener("Quantidade de registros no CSV - " + rowCount);
            String sampleData = printedDocumentTable.Rows[0]["Time"].ToString() + " - " +
                                printedDocumentTable.Rows[0]["Document Name"].ToString();

            NotifyListener("Amostra dos dados - " + sampleData);

            PrintedDocumentDAO printedDocumentDAO = new PrintedDocumentDAO(sqlConnection);

            CreateDigest(fileDate);

            PrintedDocument printedDocument;

            foreach (DataRow row in printedDocumentTable.Rows)
            {
                printedDocument             = new PrintedDocument();
                printedDocument.tenantId    = tenantId;
                printedDocument.jobTime     = DateTime.Parse(row["Time"].ToString());
                printedDocument.userName    = row["User"].ToString();
                printedDocument.printerName = row["Printer"].ToString();
                printedDocument.name        = row["Document Name"].ToString();
                printedDocument.pageCount   = int.Parse(row["Pages"].ToString());
                printedDocument.copyCount   = int.Parse(row["Copies"].ToString());
                printedDocument.duplex      = ConvertToBool(row["Duplex"].ToString());
                printedDocument.color       = !ConvertToBool(row["Grayscale"].ToString());

                printedDocumentDAO.InsertPrintedDocument(printedDocument);
                AddToDigest(printedDocument, row["Language"].ToString(), row["Size"].ToString());
            }

            return(true);
        }
コード例 #2
0
        public override void BuildReport()
        {
            TenantDAO tenantDAO = new TenantDAO(sqlConnection);
            Tenant    tenant    = tenantDAO.GetTenant(tenantId);

            // Obtem a lista de documentos considerando o filtro (faixa de datas, usuário, impressora)
            PrintedDocumentDAO printedDocumentDAO = new PrintedDocumentDAO(sqlConnection);
            List <Object>      printedDocuments   = printedDocumentDAO.GetPrintedDocuments(tenantId, startDate, endDate, userId, printerId);

            reportBuilder.OpenMedia(reportMedia); // Abre a mídia para o output do relatório

            Dictionary <String, Object> reportFilter = new Dictionary <String, Object>();

            reportFilter.Add("tenantId", tenantId);
            reportFilter.Add("startDate", startDate);
            reportFilter.Add("endDate", endDate);
            reportFilter.Add("userId", userId);
            reportFilter.Add("printerId", printerId);
            reportBuilder.SetReportHeadings("Relatório de Impressões", tenant.alias, reportFilter);

            String[] columnNames  = new String[] { "Data/Hora", "Usuário", "Impressora", "Páginas", "Nome do documento" };
            int[]    columnWidths = new int[] { 25, 25, 25, 15, 45 };
            int      rowCount     = printedDocuments.Count;

            reportBuilder.CreateDataTable(columnNames, columnWidths, rowCount);
            if (reportBuilder.IsNavigable())
            {
                Dictionary <String, Object> exportOptions = ExportFormatContext.GetExportOptions(tenantId, sqlConnection);
                reportBuilder.SetNavigationData(this.GetType().Name, rowCount, exportOptions); // neste caso recordCount = rowCount
                reportBuilder.SetReportPage(action, currentPage);
            }
            for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
            {
                PrintedDocument printedDocument = (PrintedDocument)printedDocuments[rowIndex];
                ReportCell[]    cells           = new ReportCell[]
                {
                    new ReportCell(printedDocument.jobTime.ToString()),
                    new ReportCell(printedDocument.userName),
                    new ReportCell(printedDocument.printerName),
                    new ReportCell(printedDocument.pageCount * printedDocument.copyCount),
                    new ReportCell(printedDocument.name)
                };
                reportBuilder.InsertRow(rowIndex, cells);
            }

            reportBuilder.CloseMedia();
        }
コード例 #3
0
        public int LogPrintedDocuments(List <PrintedDocument> printedDocuments)
        {
            if (printedDocuments == null)
            {
                return(0);
            }
            if (printedDocuments.Count == 0)
            {
                return(0);
            }
            StartDBAccess();

            int      tenantId  = printedDocuments[0].tenantId;
            DateTime startDate = DateTime.Now.Date;
            DateTime endDate   = startDate.Add(new TimeSpan(23, 59, 59));

            JobDataDependency jobDataDependency = new JobDataDependency(printedDocuments, dataAccess.GetConnection(), tenantId);

            jobDataDependency.CreateDataDependency();

            PrintedDocumentDAO printedDocumentDAO = new PrintedDocumentDAO(dataAccess.GetConnection());
            List <Object>      alreadyInserted    = printedDocumentDAO.GetPrintedDocuments(tenantId, startDate, endDate, null, null);

            int rowCount = 0;

            foreach (PrintedDocument printedDocument in printedDocuments)
            {
                currentJob = printedDocument;
                if (alreadyInserted.Find(CheckPrintedDocument) == null) // Verifica se o registro já existe
                {
                    // Caso não exista insere no banco
                    printedDocumentDAO.InsertPrintedDocument(printedDocument);
                    rowCount++;
                }
            }

            FinishDBAccess();
            return(rowCount);
        }
コード例 #4
0
        /// <summary>
        /// Verifica se o arquivo já foi importado previamente
        /// </summary>
        public Boolean FileImported(DateRange dateRange)
        {
            Boolean imported = false;

            // Verifica se a faixa de datas foi fornecida
            if (dateRange == null)
            {
                return(false);
            }

            // Verifica se existe alguma impressão no intervalo de datas
            PrintedDocumentDAO printedDocumentDAO = new PrintedDocumentDAO(sqlConnection);
            List <Object>      printedDocuments   = printedDocumentDAO.GetPrintedDocuments(tenantId, dateRange.GetFirstDay(), dateRange.GetLastDay(), null, null);

            if (printedDocuments.Count > 0)
            {
                NotifyListener("Já existiam registros inseridos anteriormente no intervalo de datas.");
                imported = true;
            }

            return(imported);
        }