Пример #1
0
        public static SboReportDocument FromDefaultReportFor(string reportCode, string cardCode, int?userSign = null)
        {
            Logger.Trace("Getting Crystal Report document from default for {0} - {1} - {2}", reportCode, cardCode, userSign);

            string layoutCode = null;

            var cacheKey = $"SboReportDocument.FromDefaultReportFor({reportCode},{cardCode},{userSign})";

            if (SboTemporaryCache.Contains(cacheKey))
            {
                layoutCode = SboTemporaryCache.Get <string>(cacheKey);
            }

            if (layoutCode == null)
            {
                using (var factory = new SboDisposableBusinessObjectFactory())
                {
                    var companyService      = factory.GetCompanyService();
                    var reportLayoutService = (ReportLayoutsService)companyService.GetBusinessService(ServiceTypes.ReportLayoutsService);

                    var reportParam =
                        (ReportParams)reportLayoutService.GetDataInterface(ReportLayoutsServiceDataInterfaces.rlsdiReportParams);
                    reportParam.UserID     = userSign ?? SboAddon.Instance.Company.UserSignature;
                    reportParam.ReportCode = reportCode;
                    reportParam.CardCode   = cardCode;

                    var reportLayout = reportLayoutService.GetDefaultReport(reportParam);
                    layoutCode = reportLayout.LayoutCode;

                    SboTemporaryCache.Set(cacheKey, layoutCode);
                }
            }

            return(FromLayoutCode(layoutCode));
        }
Пример #2
0
        public static T DoQueryValue <T>(this Recordset recordset, string query, params object[] args)
        {
            var queryText = string.Format(query, args);

            try
            {
                var cacheKey = String.Format("SboExtensions.QueryCache({0})", queryText);
                if (SboTemporaryCache.Contains(cacheKey))
                {
                    return(SboTemporaryCache.Get <T>(cacheKey));
                }

                recordset.DoQuery(queryText);
                return(SboTemporaryCache.Set(cacheKey, recordset.RecordCount < 1 ? default(T) : (T)recordset.Fields.Item(0).Value));
            }
            catch (Exception e)
            {
                Logger.Error(e, "Error running query: {0}", queryText);
                throw;
            }
        }
Пример #3
0
        public static SboReportDocument FromLayoutCode(string layoutCode)
        {
            Logger.Trace("Getting Crystal Report document from layoutCode {0}", layoutCode);

            string tempFilename = null;
            var    cacheKey     = $"SboReportDocument.FromLayoutCode({layoutCode})";

            if (SboTemporaryCache.Contains(cacheKey))
            {
                tempFilename = SboTemporaryCache.Get <string>(cacheKey);
            }

            if (tempFilename == null || !File.Exists(tempFilename))
            {
                using (var factory = new SboDisposableBusinessObjectFactory())
                {
                    var companyService = factory.GetCompanyService();
                    var blobParams     = (BlobParams)companyService.GetDataInterface(CompanyServiceDataInterfaces.csdiBlobParams);
                    blobParams.Table = "RDOC";
                    blobParams.Field = "Template";

                    BlobTableKeySegment keySegment = blobParams.BlobTableKeySegments.Add();
                    keySegment.Name  = "DocCode";
                    keySegment.Value = layoutCode;

                    var blob = (Blob)companyService.GetDataInterface(CompanyServiceDataInterfaces.csdiBlob);
                    blob = companyService.GetBlob(blobParams);

                    tempFilename = Path.GetTempFileName();
                    File.WriteAllBytes(tempFilename, Convert.FromBase64String(blob.Content));

                    SboTemporaryCache.Set(cacheKey, tempFilename);
                }
            }

            return(FromFile(tempFilename));
        }