Suppressing individual values on report based on querying SQL value

Hello,

I am working with a vendor software that uses FastReport.Net v2018.4.13 for reporting. I was instructed to type the following code verbatim, including the commented-out line. It would appear they do not have a subject matter expert and I am struggling with the syntax. I am curious if there is someone here that can help me figure out what I'm missing, or share code snippets I can Frankenstein together for this purpose or any supplemental materials to the user manual.


Scenario:

I have a MS SQL database containing a flag (non-null, 0 or 1) that I want to query. If the flag is set to '1' this will indicate that the text object should be visible on the resulting report. I have two records for testing, one with a '0' and the other with a '1' yet the following code is not honoring this flag value. Can you help me figure out what I'm missing?



private void Text27_BeforePrint(object sender, EventArgs e)

{

//string TransType=((Boolean)Report.GetColumnValue("sqltable.FLAG"));

int TransType = Convert.ToInt32 ((Boolean)Report.GetColumnValue("sqltable.FLAG"));

if (TransType==1)

{

Text27.Visible = true;

}

else

{

Text27.Visible = false;

}

}

Comments

  • After removing the nonsense, and adjusting from BeforePrint to AfterData, here's what I have. This gives me what I need, however I added the entire table as the data source so I need to filter the data available for the report in the most streamlined fashion.



      private void Text27_AfterData(object sender, EventArgs e)
      {
       bool TransType = (Boolean)Report.GetColumnValue("sqltable.FLAG");
       if (TransType==true)
       {
        Text27.Visible = true;
       }
       else
       {            
        Text27.Visible = false; 
       }
      }
    


  • You can filter data using the 'Filter' property in the DataBand object.

  • I am a Fast-Report novice, but I'm not sure if that will give me the dynamic functionality I need. The report has several data sources out-of-the-box, but not quite enough functionality for what we need. The following refers to the linked screenshot.


    ORDR_CMDSERIES
    

    contains one record only to be printed.


    I need to query the following bit in a sql table based on the cust code value in the above data source field.

    CUST_CMDSERIES.dbo_cust.cc_print_tkt_prices_flag
    

    If true, Text##.Visible = true;

    else Text##.Visible = false;


    Is this possible?



    https://i.imgur.com/gYgz8GC.png

  • Could anyone share example code demonstrating the correct syntax to declare and call a variable from data source A in my sql query filter on data source B?

  • We have an article on creating relations. Most likely this is what you need:

    https://www.fast-report.com/public_download/html/UserManFrNET-en/index.html?relations.htm

  • Created parameter to receive the variable from the application and add to sql where clause.


    SELECT cust_code.... from "cust" C where cust_code = @custParam


    then entered the following which now does what i need.


    namespace FastReport

    {

    public class ReportScript

    {


    private void _StartReport(object sender, EventArgs e)

    {

    Report.SetParameterValue("ReportParamCust",((String)Report.GetColumnValue("ORDR_CMDSERIES.CUST_CODE_ORDR_CMDSERIES")));

    }


    private void Data7_AfterData(object sender, EventArgs e)

    {

    bool TransType = (Boolean)Report.GetColumnValue("cust.cc_print_tkt_prices_flag");

    if (TransType==true)

    {

    //TKTL

    Text27.Visible = true;

    Text34.Visible = true;

    //TLAP

    Text47.Visible = true;

    Text48.Visible = true;

    //TKTC

    Text50.Visible = true;

    Text52.Visible = true;

    //TLAC

    Text56.Visible = true;

    Text57.Visible = true;

    }

    else

    {

    //TKTL

    Text27.Visible = false;

    Text34.Visible = false;

    //TLAP

    Text47.Visible = false;

    Text48.Visible = false;

    //TKTC

    Text50.Visible = false;

    Text52.Visible = false;

    //TLAC

    Text56.Visible = false;

    Text57.Visible = false;

    }

    }

    }

    }


    Thank you for everyone's assistance.

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.