LineObject in WebReport

edited November 2016 in FastReport .NET
referring to https://www.fast-report.com/en/forum/index....showtopic=13802

Line object is rendering if height property not zero. ???

Comments

  • edited 5:44PM
    http://www.fast-report.com/en/forum/?p=/discussion/13802 [/url]

    Line object is rendering if height property not zero. ???


    If we change the Height of Line object, it will not remain a straight line, it will be a ziczac... So even it display, this solution is not workable.
  • edited 5:44PM
    http://www.fast-report.com/en/forum/?p=/discussion/13802 [/url]

    Line object is rendering if height property not zero. ???


    If we change the Height of Line object, it will not remain a straight line, it will be a ziczac... So even it display, this solution is not workable.
    [/quote]


    FastReport.net 2017.1.0 - Still not Printing Horizontal Line Object in Web Report. Also I cannot use buttons on Viewer in Asp.net project, that can be used to drill down the report....Can anyone share how to use drill down (button events) in Asp.net Projects.


  • edited December 2016
    1. LINE OBJECT
    use textobject and border property as workaround, in fastreport user manual, stated :

    If possible, use the object's border instead of "Line" object. This will simplify the report and
    avoid possible problems with the export to different formats.


    2. DRILL DOWN REPORT
    I use workaround too, see attached pictures (I use google drive, download it) :
    Image 1 : basic report

    Image 2 : popup report/url]

    If you click nota or deposit in the report column (image 1), it will popup another report (image 2).
    To achieve that:

    in frx file, let's say 'nota' and 'deposit' are printed by textobject with name "Text14" :

    <TextObject Name="Text14" Left="120.96" Width="83.16" Height="22.68" Hyperlink.Expression=""java script:btnPopup(" + [MainReport.Urut] + "," + [MainReport.InvID] + ");"" Text="[MainReport.Uraian]" WordWrap="false" Font="Tahoma, 10pt"/>
    

    looks weird : Hyperlink.Expression actually contains this expression :
    "java script:btnPopup(" + [MainReport.Urut] + "," + [MainReport.InvID] + ");"

    and in html page, there is a script :
    <script type="text/javascript">
        var btnPopup = function (source, id) {
            var DTO = { "source": source, "id": id };
            //use ajax to load another report
            $.ajax({
                type: "POST",
                //I use asp.net MVC and WebAPI, this function will call a method in webapi to load second report
                url: "/api/report/load4",
                data: JSON.stringify(DTO),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    //a widget to simulate popup window and second report is in this window
                    $("#jqxHelper").jqxWindow("open");
                    $("#popup").html(data);
                },
                error: function (xhr, status, error) {
                    $.MessageBox({ top: "10%", message: "AJAX error." });
                }
            });
        };
    </script>
    
    <div id="fastreport"></div>
    <div id="jqxHelper"><div id="popup"></div></div>
    


    in WebAPI
    public class ReportController : ApiController
    {
            public class myAPILoad4
            {
                public int source { get; set; }
                public int id { get; set; }
            }
    
    
            [HttpPost]
            public string Load4([FromBody()]myAPILoad4 value)
            {
                string retval = string.Empty;
                try
                {
                    string mySQLConnString = WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
                    using (SqlConnection cnn = new SqlConnection(mySQLConnString))
                    {
                        cnn.Open();
    
                        using (SqlCommand cmd = new SqlCommand())
                        {
                            cmd.Connection = cnn;
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.CommandText = "your query name";
                            cmd.Parameters.AddWithValue("@ID", value.id);
                            using (FastReport.Web.WebReport wr = new FastReport.Web.WebReport())
                            {
                                wr.Width = System.Web.UI.WebControls.Unit.Percentage(100);
                                wr.Height = System.Web.UI.WebControls.Unit.Percentage(100);
                                wr.PrintInBrowser = false;
                                wr.ShowExports = false;
                                wr.ShowRefreshButton = false;
                                wr.Zoom = 1.14f;
                                wr.EnableMargins = true;
                                wr.ToolbarBackgroundStyle = FastReport.Web.ToolbarBackgroundStyle.Custom;
                                wr.ToolbarIconsStyle = FastReport.Web.ToolbarIconsStyle.Custom;
                                wr.ButtonsPath = "/content/";
                                wr.Report.Load(HttpContext.Current.Server.MapPath("~/App_Data/yourfrxfile.frx"));
    
                                using (SqlDataReader dr = cmd.ExecuteReader())
                                {
                                    using (DataTable dt = new DataTable())
                                    {
                                        dt.Load(dr);
                                        dt.TableName = "MainReport";
                                        if (dt.Rows.Count == 0)
                                        {
                                            throw (new Exception("Record not found."));
                                        }
                                        wr.Report.RegisterData(dt, dt.TableName);
                                    }
                                }
    
                                wr.BackColor = System.Drawing.Color.Black;
                                retval = wr.GetHtml().ToHtmlString();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    retval = "<h3>" + ex.Message + "</h3>";
                }
                return retval;
            }
    }
    

    Hope you get the idea...
  • edited 5:44PM
    Thanks for the detail and quickest reply.

    Can you please share similar code for calling Asp.net instead of MVC. One more point is that we not using .frx, rather we convert into class and add C# in project and then create its object. So should we defined the httplink.expression in frx file on a textbox and will this script transformed in C# Code ?

  • edited 5:44PM
    you may try, but..... the point is, use hyperlink expression in a textobject to execute javascript, for example :
        var btnOpenDrilldownReport = function (event) {
            window.open("/secondreport.aspx", "_blank");
        };
    
  • edited 5:44PM
    I am trying this in Report after getting it converted to C#, as we are using Class files instead of frx files.

    1. When I tried to add HyperLink Expression, when generated C# file, it added a code, which is throwing Error: CalcExpression ... Why designer adding URL Hyperlink Expression as Calculating Express method.

    2. So What I did is just added thru Code executing it. I added following code.
    rpt.txttbl_Countryname.Hyperlink.Expression = "\"java script:alert([myDataSource.CountryName]);\"";
    rpt.txttbl_Countryname.Text = "[myDataSource.CountryName]";

    Now Report is working, column is showing field value, but when I click HyperLink, It catch error that myDataSource is not Define... Can you guide me how to access the DataSourceName in Java Script.

  • edited 5:44PM
    1. that's how fastreport translates your expression into code.
    when you open your frx file in designer and save as 'class', the code :
         protected override object CalcExpression(string expression, Variant Value)
        {
          if (expression == "\"java script:window.open('/home','_blank');\"")
            return "java script:window.open('/home','_blank');";
          if (expression == "Value < 0")
            return Value < 0;
          return null;
        }
    

    2. See attachment :
    a. picture 1 : you need 'kind' property = URL and 'expression' property
    b. picture 2 : edit 'expression' property to access datasource

    on development stage, use frx template file, make sure it works as expected.
    on production stage, save frx file as a class
  • edited 5:44PM
    Thanks alot for quick reply. Actually, we are setting/registering data dynamically on report run. Data source is not defined in FRX and in design time. On Runtime we register Data and bind textboxes with particular fields. Can you give any idea how to access Datasource values/fields thru javascript in such designed reports.
  • edited 5:44PM
    sorry, i never use fastreport from code, but.....i tried this and success :
                                    using (FastReport.Web.WebReport wr = new FastReport.Web.WebReport())
                                    {
                                        wr.Width = System.Web.UI.WebControls.Unit.Percentage(100);
                                        wr.Height = System.Web.UI.WebControls.Unit.Percentage(100);
                                        wr.Report.Load(frxFile);
                                        wr.Report.RegisterData(dt, dt.TableName);
                                        
                                        //create hyperlink on the fly
                                        foreach (FastReport.Base obj in wr.Report.AllObjects)
                                        {
                                            if (obj.GetType() == typeof(FastReport.TextObject) && obj.Name.Equals("Text3"))
                                            {
                                                FastReport.TextObject textObject = (FastReport.TextObject) obj;
                                                textObject.Hyperlink.Kind = FastReport.HyperlinkKind.URL;
                                                textObject.Hyperlink.Expression = "\"java script:alert('\" + [MainReport.PostingName] + \"');\"";
                                                break;
                                            }
                                        }
    
                                        retval = wr.GetHtml().ToHtmlString();
                                    }
    
  • edited 5:44PM
    Really appreciate your effort to help me.

    Basically we are creating reports (frx) files without any predefined datasets, as we are attaching reports with Business objects at runtime, hence in frx files there is no DataSet defined. To run the report, we set following values at runtime. Now in this case, Javascript, cannot access the Datasource object may be because its not pre-defined.
    Is there any way to access these dynamic data source from Javascript.
                
                InternalDataSourceName = "MyDataSourceName"
                rpt.RegisterData(IList_DataSource, InternalDataSourceName);
                rpt.GetDataSource(InternalDataSourceName).Enabled = true;
                DataBand.DataSource = rpt.GetDataSource(InternalDataSourceName);
    
                rpt.txttbl_Countryname.Hyperlink.Expression = "\"java script:alert('\" + [MyDataSource.CountryName] + \"');\"";
                rpt.txttbl_Countryname.Text = "[myDataSource.CountryName]";
    
  • edited 5:44PM
    based on your code, InternalDataSourceName = "MyDataSourceName"

    why you set [MyDataSource.CountryName] in javascript, instead of [MyDataSourceName.CountryName]

  • edited 5:44PM
    Its just a typo error in copying part of text from actual code. As in actual code, this name is also passed by report caller... So corrected here
                InternalDataSourceName = "MyDataSource"
                rpt.RegisterData(IList_DataSource, InternalDataSourceName);
                rpt.GetDataSource(InternalDataSourceName).Enabled = true;
                DataBand.DataSource = rpt.GetDataSource(InternalDataSourceName);
    
                rpt.txttbl_Countryname.Hyperlink.Expression = "\"java script:alert('\" + [MyDataSource.CountryName] + \"');\"";
                rpt.txttbl_Countryname.Text = "[MyDataSource.CountryName]";
    

    The report is running, showing data column, hyperlink is also shown but when clicked nothing happen and browser debugger show "UnCatught Reference Error: MyDataSource is not Defined"
  • edited December 2016
    i changed my own code, from datatable to businessobject, but the answer is still same, it works!!! >
    //iList as datasource
            public class myDataSource
            {
                public int CompanyID { get; set; }
                public string CompanyName { get; set; }
                public int RekeningID { get; set; }
                public string RekeningName { get; set; }
                public string RekeningCurrency { get; set; }
                public int PostingSequence { get; set; }
                public string PostingName { get; set; }
                public decimal TransaksiBase { get; set; }
                public decimal TransaksiAmount { get; set; }
            }
    
    //code to create fastreport
                                    using (FastReport.Web.WebReport wr = new FastReport.Web.WebReport())
                                    {
                                        wr.Width = System.Web.UI.WebControls.Unit.Percentage(100);
                                        wr.Height = System.Web.UI.WebControls.Unit.Percentage(100);
                                        wr.Report.Load(frxFile);
    
                                        //Convert datatable to businessobject
                                        List<myDataSource> ds = new List<myDataSource>();
                                        System.Threading.Tasks.Parallel.ForEach(dt.AsEnumerable(), row =>
                                        {
                                            ds.Add(new myDataSource()
                                            {
                                                CompanyID = (int)row[0],
                                                CompanyName = (string)row[1],
                                                RekeningID = (int)row[2],
                                                RekeningName = (string)row[3],
                                                RekeningCurrency = (string)row[4],
                                                PostingSequence = (int)row[5],
                                                PostingName = (string)row[6],
                                                TransaksiBase = (decimal)row[7],
                                                TransaksiAmount = (decimal)row[8]
                                            });
                                        });
                                        //push data at runtime
                                        wr.Report.RegisterData(ds, "MainReport");
    
    
                                        //create hyperlink at runtime
                                        foreach (FastReport.Base obj in wr.Report.AllObjects)
                                        {
                                            if (obj.GetType() == typeof(FastReport.TextObject) && obj.Name.Equals("Text3"))
                                            {
                                                FastReport.TextObject textObject = (FastReport.TextObject)obj;
                                                textObject.Hyperlink.Kind = FastReport.HyperlinkKind.URL;
                                                textObject.Hyperlink.Expression = "\"java script:alert('\" + [MainReport.PostingName] + \"');\"";
                                                break;
                                            }
                                        }
    
                                        retval = wr.GetHtml().ToHtmlString();
                                    }
    
    //in frx file, open with notepad
      <Dictionary>
        <BusinessObjectDataSource Name="MainReport" ReferenceName="MainReport" Enabled="true">
          <Column Name="CompanyID" DataType="System.Int32"/>
          <Column Name="CompanyName" DataType="System.String"/>
          <Column Name="RekeningID" DataType="System.Int32"/>
          <Column Name="RekeningName" DataType="System.String"/>
          <Column Name="RekeningCurrency" DataType="System.String"/>
          <Column Name="PostingSequence" DataType="System.Int32"/>
          <Column Name="PostingName" DataType="System.String"/>
          <Column Name="TransaksiBase" DataType="System.Decimal"/>
          <Column Name="TransaksiAmount" DataType="System.Decimal"/>
        </BusinessObjectDataSource>
      </Dictionary>
    
  • edited 5:44PM
    Finally get this working. You are my hero. Thanks alot. I made a mistake and that was removing the method CalcExpression, which was initially causing error from generated C# file. That is why in javascript call instead of value, it was [Datasource.Fieldname] and I was in impression that it will evaluate in JS .... But now I found that this method convert the expression to actual value and link automatically converted to correct call like javascript.alert('USA'); .....

    Once again I am really thankful for your constant and detail replied.
  • edited 5:44PM
    Hi Ipong,

    I just saw new version of FastReport 2017.1.13, changes say
    [WebReport]
    - fixed bug with handling of onClick event in WebReport

    Just to test, I made a report, with Hyperlink Type Custom and attach Click Event but its now showing a clickable on viewer and click even also not working. So feature like drill down (expanding/collapsing) any group still not achievable.

    Can you please help on this.
  • edited 5:44PM
    it's working, your dream comes true
    namespace FastReport
    {
      public class ReportScript
      {
        private List<string> expandedGroups = new List<string>();
        
         private void Text1_Click(object sender, EventArgs e)
        {
          string groupName = (sender as TextObject).Text;
          if (expandedGroups.Contains(groupName))
            expandedGroups.Remove(groupName);
          else
            expandedGroups.Add(groupName);
          
          // refresh the report
          Report.Refresh();
        }
    
        private void GroupHeader1_BeforePrint(object sender, EventArgs e)
        {
          string groupName = ((String)Report.GetColumnValue("MainReport.Acc1Name"));
          bool groupVisible = expandedGroups.Contains(groupName);
          
          // toggle objects visibility
          Data1.Visible = groupVisible;
          GroupFooter1.Visible = groupVisible;
        }
      }
    }
    
  • edited December 2016
    but.....it doesnt work when use it as a class, only works with frx file.


    FastReport.Web.WebReport wr = new FastReport.Web.WebReport();
    wr.Report = new frBS();
    wr.Report.RegisterData(dt, dt.TableName);
    .........

    don't know why....
  • edited 5:44PM
    and for lineobject, i debug in firefox, actually the line is rendering as a picture, but.... sadly, css ruins it with height:0px; , that's why not showing in web browser..... waiting for the next service release... >
  • edited December 2016
    finally got it to work, click event in webreport as a class
    using System;
    using FastReport;
    
    namespace FastReport
    {
      public class frOnMyOwn: Report
      {
            public FastReport.Report Report;
            public FastReport.Engine.ReportEngine Engine;
    
            protected override object CalcExpression(string expression, Variant Value)
            {
                return null;
            }
    
            private void InitializeComponent()
            {
                string reportString =  " ...INSERT  ClickEvent=\"Text1_Click\" ... ";
                LoadFromString(reportString);            
                InternalInit();
    
                //COMMENT THIS CODE BELOW, WE'VE MANUALLY INSERT, SEE CODE ABOVE
                //Text1.Click += Text1_Click;
            }
    
            public frOnMyOwn()
            {
                InitializeComponent();
            }
    
            private void Text1_Click(object sender, EventArgs e)
            {
                Console.Beep();
            }
      }
    }
    
  • edited 5:44PM
    I am still not able to run this. Can you please post complete class file for a simple report. I tried inputting following text in Custom Hyperlink but its not showing clickable on preview, neither any click event working. HyperLinkExpression= " INSERT ClickEvent=\"Text1_Click\"" and HyperLinkKind = Custom


  • edited December 2016
    drilldown report doesnt need hyperlink, do not mixed up with javascript click action sample.

    1. original frx file, rptCOA.frx
    2. picture drilldown report, before click
    3. picture drilldown report, after click
    4. converted frx file to class (i renamed frCOA.cs to frCOA.txt)
    5. code in asp.net
    FastReport.Web.WebReport wr1 = new FastReport.Web.WebReport();
    wr1.Report = new frCOA();
    wr1.Report.RegisterData(dt, dt.TableName);
    .......
    

    notes :
    1. i can't test in medium trust hosting environment because my project uses ms.access database
    2. in frCOA.txt :
    //before edit
    "=\"255, 128, 0\" LineHeight=\"22.68\" />\r\n
    
    //after edit
    "=\"255, 128, 0\" LineHeight=\"22.68\" ClickEvent=\"Text3_Click\"/>\r\n
    
    //and comment this
    //Text3.Click += Text3_Click;
    
  • edited 5:44PM
    WOW, its working, I used your frx file and attached Business Object to test it and its working .... For just a test, i added ClickEvent=\"Text3_Click\ on text2 and text5.... Noted that test2 responded for Click Event but text5 which is from Detail Band did not responded to click Event.... Does this means ClickEvent can only be attached on GroupHeaders ? is this assumption right ...?

  • edited 5:44PM
    yes, because it is drilldown report, when you click an object in group header, it will expand/collapse data1 or footer.

    thanks for your info, now I can create an interactive report, for example : sort column at runtime, when you click an object in column header, it will sort the column in data1

  • edited December 2016
    Happy-new-year-2017-wallpapers-hd.jpg
  • edited 5:44PM
    Happy New Year!.

    Its really good idea to enable click event on Column headers and sort report based on it. If you create any sample pls do share here.

    My question was that ClickEvent as per documentation can be attached on any object. But if you try to attach click Event on any object other than Group header, it will not respond to click Event, neither it will show as clickable in preview nor it will come to click Event code if you apply break point. So why this has such behavior, If click event can work on Detail Object smoothly, we don't need to use Javascript to open separate report, we can call directly from open thru C# Code (code behind). What is your input on this.

  • edited March 2017
    sort at runtime
      public class ReportScript
      {
        private bool toggle = false;
        
        private void Text4_Click(object sender, EventArgs e)
        {
          toggle = !toggle;
          Sort abc = Data1.Sort[0];
          abc.Descending = toggle;      
          Report.Refresh();
        }
      }
    

    wrote:
    If click event can work on Detail Object smoothly, we don't need to use Javascript to open separate report, we can call directly from open thru C# Code (code behind). What is your input on this.

    click event and javascript are two different beasts and for two different intents
    there is a reason why you must use javascript to open subreport, for example :
    main report contains 100 rows
    sub report contains 1000 rows for each row in main report

    non javascript method : you must register all data (100 + (100 * 1000) rows) at once
    javascript method : only register 100 rows at first time, when user need details, open another report to register 1000 rows dynamically
  • edited 5:44PM
    lineobject in webreport has been fixed in version 2017.2.14

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.