How to change the text color in report according to the condition?

mohanarajmohanaraj 600001
edited December 2009 in FastReport .NET
Dear all,

I want to change the color of the text in the report by condition.
eg:
Extension Call-Description
315 Incoming
316 Incoming
317 Outgoing
318 Incoming


the above data is displayed in a report. In this report i want to change the text color for the Incoming records and another color for outgoing.

eg incoming records - blue color.
Outgoing records - Red color.

Please advice how to change the color of text according to the conditions.

thanks in advance.

Comments

  • mohanarajmohanaraj 600001
    edited 10:23AM
    Dear Alex,

    Thanks for the reply.

    How i do the same by program?
    Because the color of the font can be described dynamicaly from the program.

    thaks in advance.
  • edited 10:23AM
    Hello,

    The TextObject has Highlight property which is the collection of highlight conditions. Please refer to the Class Reference.
  • mohanarajmohanaraj 600001
    edited 10:23AM
    Hai Alex,

    How to compare the string value in this.

    Error Occurs throw as "The name 'Outgoing' does not exist in the current context"

    My code is

    <TextObject Name="Text5" Width="73.3" Height="18.9" Text="[dtAllCallDetailReport.Date]">
    <Highlight>
    <Condition Expression="[dtAllCallDetailReport.Call_Description] == Outgoing"/>
    </Highlight>
    </TextObject>

    please advice.
  • edited 10:23AM
    Hello,

    Don't you forget to add quotes?

    [dtAllCallDetailReport.Call_Description] == "Outgoing"
  • mohanarajmohanaraj 600001
    edited December 2009
    Dear Alex,

    In my report i change the color of the text according to the user changed colors.
    eg - For Report
    Extension - Call_Type
    315
    Incoming
    316
    13Calls
    317
    Outgoing
    318
    IDD

    I change the color in the report as per the data submitted by users this data is load from Database and registered as follows
    Call_Type - Color
    Incoming - Green
    13Call
    Blue
    Outgoing--- Red
    IDD
    Yellow

    This above details are load from database.

    Now i want to change the color according to the data submitted by user.
    Note : In calltype_Color table Call type is dynamic we can't hard code the call_Type in conditions.

    Please help me how to use the conditional highlight in this case [img]style_emoticons/<#EMO_DIR#>/huh.gif" style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" /> Thanks in advance.[/img]
  • edited 10:23AM
    Hello,

    You can't use highlight in this case.

    - set up the relation between two tables (main table and color table). Join them by Call_Type column;
    - write the script (TextObject.BeforePrint). Something like this:

    string colorName = (String)Report.GetColumnValue("MainTable.ColorTable.Color");
    Text1.TextColor = (Color)(new ColorConverter().ConvertFromInvariantString(colorName));
  • mohanarajmohanaraj 600001
    edited December 2009
    AlexTZ wrote: »
    string colorName = (String)Report.GetColumnValue("MainTable.ColorTable.Color");
    Text1.TextColor = (Color)(new ColorConverter().ConvertFromInvariantString(colorName));

    Dear Alex,

    I tried out , by create relation between the tables but in the result all data shown in single color that color is the first record of the color table. I can't found where it goes wrong.

    I attached my sample application in this application click the Email Icon and view the pdf file in "createdreports" folder.

    Please advise where i was wrong.

    Thanks in advance.
  • edited 10:23AM
    Hello,

    There are two errors in your report:

    1) The relation is incorrect, you have to switch Parent and Child tables (parent = dtColorDetail, child = dtAllCallDetailReport).
    2) Error in the script:
        private void txtCallDate_BeforePrint(object sender, EventArgs e)
        {
          string colorName = (String)Report.GetColumnValue("dtAllCallDetailReport.dtColorDetails.Color");
    
  • mohanarajmohanaraj 600001
    edited 10:23AM
    Dear Alex,

    Thanks its work fine thank you.

    But in the child table (dtAllCallDetail) table some time there may be possible to bind the empty data and the parent table (dtcolor) having data in this situation the relation fails the application with error "Cannot determine conversion method. "

    how i can overcome this issue?

    Before the Before_Print Event i have to check the row count of the child table ?

    Thanks in advance..
  • edited 10:23AM
    Probably the colorName is null or empty in this situation, so the next code line (new ColorConverter().ConvertFromInvariantString(colorName)) fails. Just check for this situation and use some default color:

    if (String.IsNullOrEmpty(colorName))
    Text1.TextColor = Color.Black
    else
    ...
  • mohanarajmohanaraj 600001
    edited 10:23AM
    Dear Alex,

    Thanks, But i found that the error occurs in this line "[SecondsToHHmmss([TotalDuration]/[Totalcalls])]"

    I use this function for calculate the total duration in HH:MM:SS in this function [TotalDuration] and [Totalcalls] are totals.

    In this, while the dtAllcallDetail's data table have the field Tduration this column is sum in [TotalDuration] and in the [TotalCalls] i use count.

    My procedure returns an empty dataset to dtAllcallDetail table at the same time the dtColortable have all records the [TotalDuration] total sum the duration of all the records ie empty so it have empty value. But the count [Totalcalls] return 0 by calculation, so now calculation comes to Emptyvalue / 0 in this case error occur how can i overcome this.

    Thanks in advance.
  • edited 10:23AM
    Hello,

    You can use IIF function to check for 0. Something like
    [IIF([Totalcalls] == 0, "", SecondsToHHmmss([TotalDuration]/[Totalcalls]))]
    -or-
    [[Totalcalls] == 0 ? "" : SecondsToHHmmss([TotalDuration]/[Totalcalls])]
  • mohanarajmohanaraj 600001
    edited 10:23AM
    AlexTZ wrote: »
    Hello,

    You can use IIF function to check for 0. Something like
    [IIF([Totalcalls] == 0, "", SecondsToHHmmss([TotalDuration]/[Totalcalls]))]
    -or-
    [[Totalcalls] == 0 ? "" : SecondsToHHmmss([TotalDuration]/[Totalcalls])]


    Hello,

    I use the following code TotalIncText.Text = "[[Totalcalls] == 0 ? '' : SecondsToHHmmss([TotalDuration]/[Totalcalls])]";
    it throw an error as "Empty character literal" how can i implement this. to the text property of text object.

  • edited 10:23AM
    TotalIncText.Text = "[[Totalcalls] == 0 ? \"\" : SecondsToHHmmss([TotalDuration]/[Totalcalls])]";

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.