Beispiel #1
0
        private static System.Data.DataTable QueryOnBase()
        {
            System.Data.DataTable table = SetupTable();

            int transactionSub = -1;

            using (Application obApp = OnBaseConnect())
            {
                DocumentQuery docQuery = obApp.Core.CreateDocumentQuery();

                String docTypeName = System.Configuration.ConfigurationManager.AppSettings["inputDocumentType"];

                var documentType = obApp.Core.DocumentTypes.Find(docTypeName);

                DateTime endTime   = DateTime.Now;
                DateTime startTime = new DateTime(endTime.Year, endTime.Month, endTime.Day - (endTime.DayOfWeek.Equals(DayOfWeek.Monday) ? 3 : 1), 0, 0, 0);

                docQuery.AddDocumentType(documentType);
                docQuery.AddDateRange(startTime, endTime);

                long maxDocuments = 10;
                using (QueryResult queryResults = docQuery.ExecuteQueryResults(maxDocuments))
                {
                    Document doc = null;
                    foreach (QueryResultItem queryResultItem in queryResults.QueryResultItems)
                    {
                        doc = queryResultItem.Document;
                        break;
                    }

                    if (doc == null)
                    {
                        Log.Logger.Information("Document Not Found! Date Range: {startTime} - {endTime}", startTime, endTime);
                    }
                    else
                    {
                        docDate = doc.DocumentDate;

                        using (PageData pd = obApp.Core.Retrieval.Text.GetDocument(doc.DefaultRenditionOfLatestRevision))
                        {
                            using (StreamReader streamReader = new StreamReader(pd.Stream))
                            {
                                String      line  = null;
                                Transaction trans = new Transaction();
                                while ((line = streamReader.ReadLine()) != null)
                                {
                                    if (transactionSub == -1 && line.StartsWith("153"))
                                    {
                                        transactionSub++;
                                        trans.TransLine1(line);
                                    }
                                    else if (transactionSub == 0)
                                    {
                                        transactionSub++;
                                        trans.TransLine2(line);
                                    }
                                    else if (transactionSub == 1)
                                    {
                                        transactionSub++;
                                        trans.TransLine3(line);
                                    }
                                    else if (transactionSub == 2)
                                    {
                                        transactionSub++;
                                        trans.TransLine4(line);

                                        // Reset Transaction Sub Counter
                                        transactionSub = -1;

                                        // Add Data to Table
                                        table.Rows.Add(trans.RowDataArray());
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(table);
        }
Beispiel #2
0
        public static List <long> QueryDocuments(Application app, string documentsDir)
        {
            logger.Info("Execute document query...");
            List <long> documentIdList = new List <long>();
            string      filePath       = documentsDir + "\\query.json";

            if (File.Exists(filePath))
            {
                logger.Info("Query File found: " + filePath);
                string inputJSON = File.ReadAllText(filePath);

                IList <JToken> jTokens = JToken.Parse(inputJSON)["contents"].Children().ToList();
                foreach (JToken jToken in jTokens)
                {
                    Content content = jToken.ToObject <Content>();

                    DocumentType documentType = app.Core.DocumentTypes.Find(content.documentType);

                    if (documentType == null)
                    {
                        throw new Exception("Document type was not found");
                    }

                    DocumentQuery documentQuery = app.Core.CreateDocumentQuery();
                    documentQuery.AddDisplayColumn(DisplayColumnType.AuthorName);
                    documentQuery.AddDisplayColumn(DisplayColumnType.DocumentDate);
                    documentQuery.AddDisplayColumn(DisplayColumnType.ArchivalDate);
                    documentQuery.AddDocumentType(documentType);

                    KeywordRecordType keywordRecordType = documentType.KeywordRecordTypes[0];

                    foreach (var kt in keywordRecordType.KeywordTypes)
                    {
                        if (content.keywords.ContainsKey(kt.Name))
                        {
                            switch (kt.DataType)
                            {
                            case KeywordDataType.AlphaNumeric:
                                documentQuery.AddKeyword(kt.CreateKeyword(content.keywords[kt.Name]));
                                break;

                            case KeywordDataType.Currency:
                            case KeywordDataType.SpecificCurrency:
                            case KeywordDataType.Numeric20:
                                documentQuery.AddKeyword(kt.CreateKeyword(decimal.Parse(content.keywords[kt.Name])));
                                break;

                            case KeywordDataType.Date:
                            case KeywordDataType.DateTime:
                                documentQuery.AddKeyword(kt.CreateKeyword(DateTime.Parse(content.keywords[kt.Name])));
                                break;

                            case KeywordDataType.FloatingPoint:
                                documentQuery.AddKeyword(kt.CreateKeyword(double.Parse(content.keywords[kt.Name])));
                                break;

                            case KeywordDataType.Numeric9:
                                documentQuery.AddKeyword(kt.CreateKeyword(long.Parse(content.keywords[kt.Name])));
                                break;
                            }
                        }
                    }

                    using (QueryResult queryResults = documentQuery.ExecuteQueryResults(long.MaxValue))
                    {
                        logger.Info("Number of " + content.documentType + " Documents Found: " + queryResults.QueryResultItems.Count().ToString());
                        foreach (QueryResultItem queryResultItem in queryResults.QueryResultItems)
                        {
                            if (!documentIdList.Contains(queryResultItem.Document.ID))
                            {
                                documentIdList.Add(queryResultItem.Document.ID);
                            }

                            logger.Info(string.Format("Document ID: {0}", queryResultItem.Document.ID.ToString()));
                            logger.Info(string.Format("Author: {0}, Document Date: {1}, Archival Date: {2}", queryResultItem.DisplayColumns[0].Value.ToString(), DateTime.Parse(queryResultItem.DisplayColumns[1].Value.ToString()).ToShortDateString(), DateTime.Parse(queryResultItem.DisplayColumns[2].Value.ToString()).ToShortDateString()));

                            foreach (var keyword in queryResultItem.Document.KeywordRecords[0].Keywords)
                            {
                                logger.Info(keyword.KeywordType.Name + " : " + keyword.Value.ToString());
                            }
                            logger.Info("");
                        }
                    }
                }
            }
            logger.Info("");
            return(documentIdList);
        }