public void FillingCollections(EbReport Report)
        {
            foreach (EbReportHeader r_header in Report.ReportHeaders)
            {
                Fill(Report, r_header.GetFields(), EbReportSectionType.ReportHeader);
            }

            foreach (EbReportFooter r_footer in Report.ReportFooters)
            {
                Fill(Report, r_footer.GetFields(), EbReportSectionType.ReportFooter);
            }

            foreach (EbPageHeader p_header in Report.PageHeaders)
            {
                Fill(Report, p_header.GetFields(), EbReportSectionType.PageHeader);
            }

            foreach (EbReportDetail detail in Report.Detail)
            {
                Fill(Report, detail.GetFields(), EbReportSectionType.Detail);
            }

            foreach (EbPageFooter p_footer in Report.PageFooters)
            {
                Fill(Report, p_footer.GetFields(), EbReportSectionType.PageFooter);
            }

            foreach (EbReportGroup group in Report.ReportGroups)
            {
                Fill(Report, group.GroupHeader.GetFields(), EbReportSectionType.ReportGroups);
                Fill(Report, group.GroupFooter.GetFields(), EbReportSectionType.ReportGroups);
                foreach (EbReportField field in group.GroupHeader.GetFields())
                {
                    if (field is EbDataField)
                    {
                        Report.Groupheaders.Add((field as EbDataField).ColumnName, new ReportGroupItem
                        {
                            field         = field as EbDataField,
                            PreviousValue = string.Empty,
                            order         = group.GroupHeader.Order
                        });
                    }
                }
                foreach (EbReportField field in group.GroupFooter.GetFields())
                {
                    if (field is EbDataField)
                    {
                        Report.GroupFooters.Add((field as EbDataField).Name, new ReportGroupItem
                        {
                            field         = field as EbDataField,
                            PreviousValue = string.Empty,
                            order         = group.GroupHeader.Order
                        });
                    }
                }
            }
        }
        public IActionResult Index(string refid)
        {
            var resultlist = this.ServiceClient.Get <EbObjectParticularVersionResponse>(new EbObjectParticularVersionRequest {
                RefId = refid
            });

            Report                 = EbSerializers.Json_Deserialize <EbReport>(resultlist.Data[0].Json);
            Report.IsLastpage      = false;
            Report.watermarkImages = new Dictionary <string, byte[]>();
            Report.WaterMarkList   = new List <object>();
            if (Report.DataSourceRefId != string.Empty)
            {
                cresp = this.Redis.Get <DataSourceColumnsResponse>(string.Format("{0}_columns", Report.DataSourceRefId));
                if (cresp.IsNull)
                {
                    cresp = this.ServiceClient.Get <DataSourceColumnsResponse>(new DataSourceColumnsRequest {
                        RefId = Report.DataSourceRefId
                    });
                }

                Report.DataColumns = (cresp.Columns.Count > 1) ? cresp.Columns[1] : cresp.Columns[0];

                dresp = this.ServiceClient.Get <DataSourceDataResponse>(new DataSourceDataRequest {
                    RefId = Report.DataSourceRefId, Draw = 1, Start = 0, Length = 100
                });
                Report.DataRow = dresp.Data;
            }

            iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(Report.Width, Report.Height);

            d      = new Document(rec);
            ms1    = new MemoryStream();
            writer = PdfWriter.GetInstance(d, ms1);
            writer.Open();
            d.Open();
            writer.PageEvent   = new HeaderFooter(this);
            writer.CloseStream = true;//important
            canvas             = writer.DirectContent;
            Report.PageNumber  = writer.PageNumber;
            //Report.DataRow = __datarows;
            Report.InitializeSummaryFields();
            GetWatermarkImages();
            d.NewPage();

            DrawReportHeader();
            DrawDetail();
            d.Close();
            ms1.Position = 0;//important
            return(new FileStreamResult(ms1, "application/pdf"));
        }
        public IActionResult Index(string refid)
        {
            var resultlist = this.ServiceClient.Get <EbObjectParticularVersionResponse>(new EbObjectParticularVersionRequest {
                RefId = refid
            });

            Report = EbSerializers.Json_Deserialize <EbReport>(resultlist.Data[0].Json);

            if (Report.DataSourceRefId != string.Empty)
            {
                cresp = this.Redis.Get <DataSourceColumnsResponse>(string.Format("{0}_columns", Report.DataSourceRefId));
                if (cresp.IsNull)
                {
                    cresp = this.ServiceClient.Get <DataSourceColumnsResponse>(new DataSourceColumnsRequest {
                        RefId = Report.DataSourceRefId
                    });
                }

                __columns = (cresp.Columns.Count > 1) ? cresp.Columns[1] : cresp.Columns[0];

                dresp = this.ServiceClient.Get <DataSourceDataResponse>(new DataSourceDataRequest {
                    RefId = Report.DataSourceRefId, Draw = 1, Start = 0, Length = 100
                });
                dt = dresp.Data;
            }

            iTextSharp.text.Rectangle rec = (Report.IsLandscape) ?
                                            new iTextSharp.text.Rectangle(Report.Height, Report.Width) : new iTextSharp.text.Rectangle(Report.Width, Report.Height);

            d = new Document(rec);
            MemoryStream ms1 = new MemoryStream();

            writer = PdfWriter.GetInstance(d, ms1);
            writer.Open();
            d.Open();
            writer.PageEvent   = new HeaderFooter(this);
            writer.CloseStream = true;//important
            cb = writer.DirectContent;
            CalculateSectionHeights();
            d.NewPage();

            DrawReportHeader();
            DrawDetail();
            DrawReportFooter();
            d.Close();
            ms1.Position = 0;
            return(new FileStreamResult(ms1, "application/pdf"));
        }
 public void FillSummaryCollection(EbReport report, EbDataField field, EbReportSectionType section_typ)
 {
     if (section_typ == EbReportSectionType.ReportGroups)
     {
         if (!report.GroupSummaryFields.ContainsKey(field.SummaryOf))
         {
             report.GroupSummaryFields.Add(field.SummaryOf, new List <EbDataField> {
                 field
             });
         }
         else
         {
             report.GroupSummaryFields[field.SummaryOf].Add(field);
         }
     }
     if (section_typ == EbReportSectionType.PageFooter)
     {
         if (!report.PageSummaryFields.ContainsKey(field.SummaryOf))
         {
             report.PageSummaryFields.Add(field.SummaryOf, new List <EbDataField> {
                 field
             });
         }
         else
         {
             report.PageSummaryFields[field.SummaryOf].Add(field);
         }
     }
     if (section_typ == EbReportSectionType.ReportFooter)
     {
         if (!report.ReportSummaryFields.ContainsKey(field.SummaryOf))
         {
             report.ReportSummaryFields.Add(field.SummaryOf, new List <EbDataField> {
                 field
             });
         }
         else
         {
             report.ReportSummaryFields[field.SummaryOf].Add(field);
         }
     }
 }
        private void Fill(EbReport Report, List <EbReportField> fields, EbReportSectionType section_typ)
        {
            foreach (EbReportField field in fields)
            {
                if (!String.IsNullOrEmpty(field.HideExpression?.GetCode()))
                {
                    Report.ExecuteHideExpression(field);
                }
                if (!field.IsHidden && !String.IsNullOrEmpty(field.LayoutExpression?.GetCode()))
                {
                    Report.ExecuteLayoutExpression(field);
                }
                if (field is EbDataField)
                {
                    EbDataField field_org = field as EbDataField;

                    if (section_typ == EbReportSectionType.Detail)
                    {
                        FindLargerDataTable(Report, field_org);
                    }

                    if (field is IEbDataFieldSummary)
                    {
                        FillSummaryCollection(Report, field_org, section_typ);
                    }

                    if (field is EbCalcField && !Report.ValueScriptCollection.ContainsKey(field.Name) && !string.IsNullOrEmpty((field_org as EbCalcField).ValExpression?.Code))
                    {
                        string processedCode = Report.GetProcessedCodeForScriptCollection((field as EbCalcField).ValExpression.GetCode());
                        Report.ValueScriptCollection.Add(field.Name, processedCode);
                    }

                    if (!field.IsHidden && !Report.AppearanceScriptCollection.ContainsKey(field.Name) && !string.IsNullOrEmpty(field_org.AppearExpression?.Code))
                    {
                        string processedCode = Report.GetProcessedCodeForScriptCollection(field_org.AppearExpression.GetCode());
                        Report.AppearanceScriptCollection.Add(field.Name, processedCode);
                    }
                }
            }
        }
Beispiel #6
0
        public static List <Param> GetEmailParams(EbEmailTemplate enode, IRedisClient Redis, IDatabase ObjectsDB)
        {
            List <Param> p = new List <Param>();

            if (!string.IsNullOrEmpty(enode.AttachmentReportRefID))
            {
                EbReport o = GetEbObject <EbReport>(enode.AttachmentReportRefID, Redis, ObjectsDB);

                if (!string.IsNullOrEmpty(o.DataSourceRefId))
                {
                    EbDataSourceMain ob = GetEbObject <EbDataSourceMain>(o.DataSourceRefId, Redis, ObjectsDB);

                    p = p.Merge(ob.GetParams(Redis as RedisClient));
                }
            }
            if (!string.IsNullOrEmpty(enode.DataSourceRefId))
            {
                EbDataSourceMain ob = GetEbObject <EbDataSourceMain>(enode.DataSourceRefId, Redis, ObjectsDB);

                p = p.Merge(ob.GetParams(Redis as RedisClient));
            }
            return(p);
        }
 public void FindLargerDataTable(EbReport Report, EbDataField field)
 {
     if (!Report.HasRows || field.TableIndex != Report.DetailTableIndex)
     {
         if (Report.DataSet?.Tables.Count > 0)
         {
             if (Report.DataSet.Tables[field.TableIndex].Rows != null)
             {
                 Report.HasRows = true;
                 int r_count = Report.DataSet.Tables[field.TableIndex].Rows.Count;
                 Report.DetailTableIndex = (r_count > Report.MaxRowCount) ? field.TableIndex : Report.DetailTableIndex;
                 Report.MaxRowCount      = (r_count > Report.MaxRowCount) ? r_count : Report.MaxRowCount;
             }
             else
             {
                 Console.WriteLine("Report.DataSet.Tables[field.TableIndex].Rows is null");
             }
         }
         else
         {
             Console.WriteLine("Report.DataSet.Tables.Count is 0");
         }
     }
 }
Beispiel #8
0
        public ReportRenderResponse Post(ReportRenderMultipleMQRequest request)
        {
            string Displayname = "";

            this.Ms1 = new MemoryStream();
            this.EbConnectionFactory = new EbConnectionFactory(request.SolnId, this.Redis);

            JsonServiceClient      authClient   = this.ServiceStackClient;
            MyAuthenticateResponse authResponse = authClient.Get <MyAuthenticateResponse>(new Authenticate
            {
                provider = CredentialsAuthProvider.Name,
                UserName = GetUserObject(request.ReadingUserAuthId)?.Email,
                Password = "******",
                Meta     = new Dictionary <string, string> {
                    { RoutingConstants.WC, RoutingConstants.UC },
                    { TokenConstants.CID, request.SolnId },
                    { "sso", "true" },
                    { TokenConstants.IP, "" },
                    { RoutingConstants.USER_AGENT, "" }
                },
            });

            this.FileClient.BearerToken  = authResponse?.BearerToken;
            this.FileClient.RefreshToken = authResponse?.RefreshToken;

            List <EbObjectWrapper> resultlist = EbObjectsHelper.GetParticularVersion(this.EbConnectionFactory.ObjectsDB, request.RefId);
            EbReport ReportObject             = EbSerializers.Json_Deserialize <EbReport>(resultlist[0].Json);

            ReportObject.ObjectsDB     = this.EbConnectionFactory.ObjectsDB;
            ReportObject.Redis         = this.Redis;
            ReportObject.FileClient    = this.FileClient;
            ReportObject.Solution      = GetSolutionObject(request.SolnId);
            ReportObject.ReadingUser   = GetUserObject(request.ReadingUserAuthId);
            ReportObject.RenderingUser = GetUserObject(request.RenderingUserAuthId);

            ReportObject.CultureInfo = CultureHelper.GetSerializedCultureInfo(ReportObject.ReadingUser?.Preference.Locale ?? "en-US").GetCultureInfo();
            ReportObject.GetWatermarkImages();

            try
            {
                byte[] encodedDataAsBytes = System.Convert.FromBase64String(request.Params);
                string returnValue        = System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);

                List <Param> _paramlist = (returnValue == null) ? null : JsonConvert.DeserializeObject <List <Param> >(returnValue);
                if (_paramlist != null)
                {
                    for (int i = 0; i < _paramlist.Count; i++)
                    {
                        string[] values = _paramlist[i].Value.Split(',');

                        for (int j = 0; j < values.Length; j++)
                        {
                            List <Param> _newParamlist = new List <Param>
                            {
                                new Param {
                                    Name = "id", Value = values[j], Type = "7"
                                }
                            };

                            this.Report = ReportObject;

                            if (Report != null)
                            {
                                InitializePdfObjects();
                                Report.Doc.NewPage();
                                Report.GetData4Pdf(_newParamlist, EbConnectionFactory);

                                if (Report.DataSet != null)
                                {
                                    Report.Draw();
                                }
                                else
                                {
                                    throw new Exception();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception-reportService " + e.Message + e.StackTrace);
                Report.HandleExceptionPdf();
            }

            Report.Doc.Close();

            if (Report.DataSourceRefId != string.Empty && Report.DataSet != null)
            {
                Report.DataSet.Tables.Clear();
                Report.DataSet = null;
            }

            Displayname = Regex.Replace(((Displayname == "") ? Report.DisplayName : Displayname), @"\s+", "");

            Ms1.Position = 0;

            string uid = request.RefId + request.UserId + request.SubscriptionId;

            byte[] compressedData = Compress(Ms1.ToArray());

            this.Redis.Set("PdfReport" + uid, compressedData, DateTime.Now.AddMinutes(15));

            this.ServerEventClient.BearerToken     = authResponse?.BearerToken;
            this.ServerEventClient.RefreshToken    = authResponse?.RefreshToken;
            this.ServerEventClient.RefreshTokenUri = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_GET_ACCESS_TOKEN_URL);

            Console.WriteLine("Calling NotifySubscriptionRequest to subsc.id :" + request.SubscriptionId);
            this.ServerEventClient.Post <NotifyResponse>(new NotifySubscriptionRequest
            {
                Msg              = "/DV/GetPdf?refid=" + uid + "&filename=" + Displayname + ".pdf",
                Selector         = StaticFileConstants.PDFDOWNLOADSUCCESS,
                ToSubscriptionId = request.SubscriptionId
            });

            return(new ReportRenderResponse());
        }
 public HeaderFooter(EbReport _c) : base()
 {
     Report = _c;
 }
        public ReportRenderResponse GetPdfOffline(string refid, string param)
        {
            if (!string.IsNullOrEmpty(refid))
            {
                EbReport Report = null;
                try
                {
                    Report = (EbReport)EbPageHelper.GetWebObjects(refid);

                    Report.IsLastpage                 = false;
                    Report.WatermarkImages            = new Dictionary <int, byte[]>();
                    Report.WaterMarkList              = new List <object>();
                    Report.ValueScriptCollection      = new Dictionary <string, string>();
                    Report.AppearanceScriptCollection = new Dictionary <string, string>();
                    // Report.LinkCollection = new Dictionary<string, List<Common.Objects.EbControl>>();
                    Report.GroupSummaryFields  = new Dictionary <string, List <EbDataField> >();
                    Report.PageSummaryFields   = new Dictionary <string, List <EbDataField> >();
                    Report.ReportSummaryFields = new Dictionary <string, List <EbDataField> >();
                    Report.GroupFooters        = new Dictionary <string, ReportGroupItem>();
                    Report.Groupheaders        = new Dictionary <string, ReportGroupItem>();

                    Report.CultureInfo = new CultureInfo("en-IN", false);
                    Report.Parameters  = JsonConvert.DeserializeObject <List <Param> >(param);
                    Report.Ms1         = new MemoryStream();
                    if (Report?.OfflineQuery.Code != string.Empty)
                    {
                        string query = Report.OfflineQuery.GetCode();
                        Report.DataSet = App.DataDB.DoQueries(query, Report.Parameters.ToDbParams().ToArray());
                    }
                    float _width  = Report.WidthPt - Report.Margin.Left;// - Report.Margin.Right;
                    float _height = Report.HeightPt - Report.Margin.Top - Report.Margin.Bottom;
                    Report.HeightPt = _height;

                    iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(_width, _height);
                    Report.Doc = new Document(rec);
                    Report.Doc.SetMargins(Report.Margin.Left, Report.Margin.Right, Report.Margin.Top, Report.Margin.Bottom);
                    Report.Writer = PdfWriter.GetInstance(Report.Doc, Report.Ms1);
                    Report.Writer.Open();
                    Report.Doc.Open();
                    Report.Doc.AddTitle(Report.DocumentName);
                    Report.Writer.PageEvent   = new HeaderFooter(Report);
                    Report.Writer.CloseStream = true;//important
                    Report.Canvas             = Report.Writer.DirectContent;
                    Report.PageNumber         = Report.Writer.PageNumber;
                    FillingCollections(Report);
                    Report.Doc.NewPage();
                    Report.DrawReportHeader();

                    if (Report?.DataSet?.Tables.Count > 0 && Report?.DataSet?.Tables[Report.DetailTableIndex]?.Rows.Count > 0)
                    {
                        Report.DrawDetail();
                    }
                    else
                    {
                        Report.DrawPageHeader();
                        Report.detailEnd += 30;
                        Report.DrawPageFooter();
                        Report.DrawReportFooter();
                        throw new Exception("Dataset is null, refid " + Report.DataSourceRefId);
                    }

                    Report.DrawReportFooter();
                }
                catch (Exception e)
                {
                    ColumnText ct = new ColumnText(Report.Canvas);
                    Phrase     phrase;
                    if (Report?.DataSet?.Tables[Report.DetailTableIndex]?.Rows.Count > 0)
                    {
                        phrase = new Phrase("Something went wrong. Please check the parameters or contact admin");
                    }
                    else
                    {
                        phrase = new Phrase("No Data available. Please check the parameters or contact admin");
                    }
                    phrase.Font.Size = 10;
                    float y = Report.HeightPt - (Report.ReportHeaderHeight + Report.Margin.Top + Report.PageHeaderHeight);
                    ct.SetSimpleColumn(phrase, Report.LeftPt + 30, y - 30, Report.WidthPt - 30, y, 15, Element.ALIGN_CENTER);
                    ct.Go();
                }

                Report.Doc.Close();
                if (Report.UserPassword != string.Empty || Report.OwnerPassword != string.Empty)
                {
                    Report.SetPassword();
                }

                string name = Report.DocumentName;

                if (Report.DataSourceRefId != string.Empty)
                {
                    Report.DataSet.Tables.Clear();
                    Report.DataSet = null;
                }

                return(new ReportRenderResponse
                {
                    ReportName = name,
                    ReportBytea = Report.Ms1.ToArray(),
                    CurrentTimestamp = Report.CurrentTimestamp
                });
            }
            else
            {
                EbLog.Error(" PDF report Refid is null");
                return(null);
            }
        }