Programmatically hide text/lines in a Crystal Report - c#

I have a Crystal Report that I populate before displaying to the user using a CrystalReportViewer.
I have some static text items and line segments that I would like to show and hide programatically depending on conditions in the business logic. Is there a way I can group a bunch of these items together and hide them as a group?
At the moment, my other option is to have two separate reports that are identical except for these superficial differences.

By all means, please don't create two separate reports :)
In the Report Design view, you should be able to create sub-sections of your detail section (assuming you're talking about the detail section), right-clicking on the Detail section and selecting "Insert Section Below".
You should now have "Details a" and "Details b" sections. You can put your text in the "Details b" section, and apply a conditional suppression formula to it.
To conditionally suppress the "Details b" section, right-click on it in the Design View, select "Format section...", click on the button next to the "Suppress" checkbox, and add your formula there.

Do the following steps :
1-Add the required field to the report canvas
2-Right click on the field
3-Select the Format Field menu option
4-On the Common Tab in the Format Editor dialog box, press the Conditional Format button [x+2] button for the Display String option
5-In the Formula Workshop enter the following formula:
if {Tablename.Fieldname}= True then Totext(CurrentFieldValue)
else Totext((CurrentFieldValue)) + " Outstanding"
6-Press the [Save & Close] button
7-Press the OK button of the Format Editor dialog box

Related

How to load two RDLC reports in same report viewer?

I have two reports the first one to show general information and the second one to show details and I need to show each one in a different page in report viewer
can you help me to do that
thanks
like the image
Hopefully, the following can help guide you into what you are looking for. First, you will need THREE reports and TWO datatables (or other lists as you have to build your report).
First, On the 3 reports I describe, I would not worry about any of the report final formatting to be perfectly aligned, bold, spacing... get it to work, then you can make it pretty after all is functional.
Next, create a bogus datatable "MyTable" for the sole purpose of creating two records. Even if a single column of "MyGroup" and having it as an int (just for sample purposes).
Now, create two records and set the values in each row to 1 and 2 respectively so your table has
MyGroup
1
2
Now, for the other two reports. It is my understanding that you want the first report to show a summary of each department's totals with a grand-total. The second report is showing the details of all the activity per department. So this is basically using the same dataset returned from whatever query. For this example, I will refer to the datatable as "SalesData".
CREATING THE REPORTS
Create your first report, put a table control on the report, full width you will have for your current reports as landscape or portrait as long as both the same size, you want this report to be the same. Ex: ALL will be portrait. Add your Report Data source to show the "MyTable" and assign that to the table control. Also add the "SalesData" table to the report as well so it is available to the future sub-reports.
On the table control, below where it shows the "Row Groups", add a "Group By" for the "MyGroup" column. This is so we can force a page-break between each group. Once added, right-click on the parent group "MyGroup" and select "Group Properties". This will show an option on the left side to allow you to set page breaks, click the checkbox for "Between each instance of a group". For now, just have the one column in the table control as the "MyGroup" column. Save the report ex: "MySalesRpt.rdlc". Then compile and run the report. You should get this simple report with 2 pages, each showing just the number 1 and 2 respectively. NOTE: You will also want to add the datatable reference for your secondary reports to this main report as well so they are available as sub-reports of the first.
Create a new report ex: "MySalesDetail.rdlc", add the "SalesData" to it. Add a table control to the report and set its source to the "SalesData" table. Include whatever for your detail columns you want to show of the sales activity. Add a data group based on the department, get your sum( salesDollarColumn ). Add a new row outside/below the group footer so you can have the report grand totals as a sum of all ex: SalesDollarColumn. You can test and run this report on its own until it looks correct.
Now, your third report. Copy/paste the MySalesDetail.rdlc report and change it to MySalesSummary.rdlc. So you don't this summary report showing every row that builds the grand total sum() per each department, right-click on the row that represents the details of the group and delete. It will ask if you want to delete rows and associated groups? Reply yes as it will just remove the details row, but keep the group footer that will retain your sum() total per department. Save, test / run this report.
Once all 3 reports work individually, now we can go back to the "MySalesRpt". Add an additional DETAIL row in this otherwise simple 1-detail report. Right-click on the existing detail row and then pick "Insert Row" -> "Inside Group - Below". This will now show as two rows.
Now, in the first row of the report where it did have just a simple textbox, go to your report Toolbox and pick Subreport and put one instance into each row.
On the first row, subreport, right-click and set properties. Set both the Name and "Use this report as a subreport" to the summary report "MySalesSummary". On the second row subreport, do the same but with "MySalesDetail".
Final step. Click on the Subreport representing the "MySalesSummary". Go to the properties of that and scroll down to the "Hidden" property. You want to have this value set to the expression: ex: "=Fields!MyGroup.Value = 2". This way the report will ONLY be generate when it is on the first record where MyGroup = 1.
Similarly, on the second subreport representing the detail, set the hidden equal to the opposite.. "=Fields!MyGroup.Value = 1". Hide when the MyGroup = 1. This way you can have each report on their own page, but only one will show up per group.
I know is sounds deep, but do it slowly and it should work for you. I already did and confirmed this process works. Sorry so many steps, but it has to be broken into multiple parts to tie them all together as you are requesting.
One rdlc in main local report and the other in subreport. Then set InteractiveSize in the main local report to break it to show each one in a different page in report viewer.

How to generate product receipt in winform application?

I am working on a winform application for the first time and I have a gridview which contains a list of products users have bought.
I have a Print button on click which allows the user to generate a receipt like the one below:
So here I am confused whether I should use "winform default RDLC or Crystal Report" or whether I should generate PDF and then let it print out as receipt, but I am not sure if PDF is a good option for receipt generation or not.
For Crystal Report, I have read that I need to install it and client (who will use this desktop application) had to install Crystal Report and also there is some licensing involve with Crystal Report which I don't want.
Also if I use Crystal Report then I am not sure if it would be possible to generate exactly above receipt (with table formatting) and will it be complicated?
Receipt is bit complicated so is there a better tool or way, or how should I generate receipt I have shown in above image?
Update : Printing paper total size is : 7.50 centimeter and user wants to print all the content in center.
Discount = FinalAmount - MRP;
Customer Name, Mobile No, Bill No, Payment Mode values are entered on the form by user itself.
I am having a Excel file which contains list of products and with each products I have information like ProductId,ProductName,MRP,Tax information like CGST,SGST.
Code to fill gridview from excel file based on Product Id:
using (OleDbConnection cnnxls = new OleDbConnection(strConn))
using (OleDbDataAdapter oda = new OleDbDataAdapter(query, cnnxls))
{
oda.Fill(dtProductList);
DataColumnCollection columns = dtProductList.Columns;
if (!columns.Contains("FinalAmount"))
{
dtProductList.Columns.Add(new DataColumn() { ColumnName = "FinalAmount", DataType = typeof(decimal) });
}
if (!columns.Contains("Quantity"))
{
dtProductList.Columns.Add(new DataColumn() { ColumnName = "Quantity", DataType = typeof(int) });
}
DataRow lastRow = dtProductList.Rows[dtProductList.Rows.Count - 1];
lastRow["FinalAmount"] = Convert.ToDecimal(lastRow["MRP"]);
lastRow["Quantity"] = 1;
}
Generate and print the receipts
You can use any report designer tool like RDLC Reports or Crystal Reports to generate a report. RDLC reports are good enough. You can print the RDLC report with or without showing the print dialog. You can also easily export the RDLC report manually or using the code.
If for any reason you don't want to use a reporting tool, as another option you can consider generating HTML report easily using Run-time T4 templates.
Using an RDLC report, how to show multiple fields in a single cell
You can easily use an expression to show multiple values in a single cell. Also as another option, you can use rows in a single row group and show different fields in a single column.
Example 1 - RDLC - Show multiple fields in a single column using expression
The following steps show you how you can display multiple fields in a single column using expression. I assume you have set up the data source and have ProductName, UnitPrice and Quantity fields. Then, follow these steps:
Drop a Table from toolbox on the report design surface.
In first column, first data row (not the header row), right click and choose ProductName (image)
Select the header of the second column and type UnitPrice/Quantity (image)
In second column, first data row, right click and choose Expression. (image)
In the expression window, enter the desired expression, for example:
= "UnitPrice: " & Fields!UnitPrice.Value.ToString() & System.Environment.NewLine & "Quantitye: " & Fields!Quantity.Value.ToString()
Example 2 - RDLC - Show multiple fields in a single column using row group
The following steps show you how you can display multiple fields in a single column. I assume you have set up the data source and have ProductName, UnitPrice and Quantity fields. Then, follow these steps:
Drop a Table from toolbox on the report design surface.
In first column, first data row (not the header row), right click and choose ProductName (image)
Select the header of the second column and type UnitPrice/Quantity (image)
Right click on row header of the first data row and choose Insert Row → Inside Group - Below (image)
In second column, first data row, right click and choose UnitPrice. (image)
Click on the [UnitPrice], and then press Home and type UnitPrice: (image)
Do the same for Quantity, in the next row in the group.
If you need another row in the group, repeat step 3.
You can setup borders of the cells by selecting them and setting BorderStyle individually for top, left, bottom and right.
Download
You can clone or download an example using expression here:
repository
zip file
A quick and easy way I used before was to generate a html page, and then use the html2pdf library to convert it to a pdf file.
You may also consider this approach since the RDLC reports/Crystal reports may be a overkill for your case.
The RDLC is powerful as well as Crystal reports. You may choose the rdlc which comes close in eliminating licensing costs.
Using RDLC
Data
You need to add datasets Here or data sources to the report which you will manipulate to meet the design and data you want.
Design
On design you just drag and drop controls to your taste. There is a challenge that sometimes what you see on the design may not what be you see on final output so you need to test much.
Printing
You can put a print preview or send directly to a pdf viewer using rdlc. Here is an example.
Conclusion
I think If you have your data generated well on the report, the design and layout won't be much of a problem using both rdlc and crystal reports.
UPDATE
Based on further information provided I have tried to do something that may come close to what you want to achieve.
I have used crystal reports as well as database table to simulate because of time. Otherwise the same can be achieved using rdlc.
The sample table i created
Here is the sample query and results from the database. I have made groups that can be accomodated by the crystal reports. You can do calculated text values using the same to put distinction between the Tax information as well as Transaction Memo.
Here is the final look after tweaking the design. The page layout may also be tweaked with regards to your taste.
Update.
For RDLC I think you need to add datasets for memo data and tax information. Take a look at the below if it comes close. I failed to make a preview there were components I hadn't installed.
for adding 3 columns in one cell
you have two options:
1- Use new line expression
=Fields!MyField1.Value + System.Environment.NewLine + Fields!MyField2.Value
2- Use something like subreport or grouping in rdlc.
the first option seams easier

How to toggle (Expand/Collapse) group data in rdlc

In my rdlc report,I want to show my group data just like this example--
When I click (+) sign group data under the name will expand and When I click (-) sign group data under the name will collapse.I find resources for SSRS report, but nothing useful for rdlc report in recent times.So I followed in my rdlc according to those SSRC report resources if i can get some result.I followed this two specially--
SQL Server Reporting Services(SSRS)
Expand or Collapse All Grouped Items on SSRS Report
I took a table.take "GROUP2" as row details.add group parent "GROUP1" for "GROUP2".Like---
I select group properties for "GROUP2" like--
then i set visibility hide for "GROUP2" , checked "display can be toggled by this group item" and select "GROUP1" as item.like--
It gives me report like this--
there is "GROUP1" item visible, "GROUP2" is hidden but no (+) or (-) sign or button to expand or collapse group data.
Any one have any idea,What i am missing? or how can i do this in rdlc report like the top example of this question and also i want to set button for "Expand All" and "Collapse All" for this report.
EDIT: I am using asp.net mvc, web api-2 controller.I am tring to get report in pdf format.
First you need to select your column/row group and select group properties.
And then select the grouping item from your DataSource
There you go:
Before expanding of group
After expanding of group
First select the table cell showing [GROUP1], and in the Text Box Properties note the Name. This is not necessarily GROUP1, it could well be Textbox10 etc.
Then in the Text Box Properties for the table cell showing [GROUP2], select that Text Box name below "Display can be toggled by this report item:".
BTW you are likely wasting your time trying to use the expand/collapse functionality in SSRS. It is generally considered flaky and unreliable, and does not scale.
PDF format does not support toggling.
Ref:
https://msdn.microsoft.com/en-us/library/dd255288.aspx
(section titled: Toggle items within a report)
"PDF - The report server exports the current show or hide state of the report to PDF. Interactive toggling is not supported"
#MohammadSadiqurRahman Not sure if you got this problem solved but this is something I do that I hope may help you out.
You will need to make sure that your row groupings have been applied correctly. In the example you gave at the top of your post the row group parent would have been set to account type. You would need to make sure this is done for your 'GROUP1'.
Once you have done this set the row visibility for your collapsed row to 'Hide'. Now check the checkbox 'Display can be toggled by this report item' and set the report item to the cell name for the grouped account types.
Personally I attach it to a new label outside of the tablix which will allow for the entire table to expand/collapse with one click. Just depends on how you want it to work.
I hope this helps you out.

C# RDLC Expand All / Collapse All SubReport

I am using following tools: -
Visual Studio.NET 2013
C#
SQL Server 2014
I have created a report, which contains a sub report. The main report displays the Sale records, while the sub report displays the details of each Sale record (Item details). Each Sale record displays a + sign on the start of the record. User click the + sign and the sub report (details for that specific Sale record) opens.
I want to add a Expand All / Collapse All option to the report.
I have searched a lot but all the articles are related to Groups not to the Sub Reports.
Please tell how to expand/collapse all the records at once.
You can enable a user to interactively expand or collapse report items, or expand or collapse rows and columns associated with a group for a table or matrix. To allow users to expand or collapse an item, you set the visibility properties for that item. Setting visibility works in an HTML report viewer, and is sometimes called a drilldown action.
In report design view, you specify the name of the text box where you want to display the expand and collapse toggle icons. In the rendered report, the text box displays a plus (+) or minus (-) sign in addition to its contents. When the user clicks the toggle, the report display is refreshed to show or hide the report item, based on the current visibility settings for items in the report.
Typically, the expand and collapse action is used to initially display only summary data and to enable the user to click the plus sign to show detail data. For example, you can initially hide a table that displays values for a chart, or hide child groups for a table with nested row or column groups, as in a drilldown report.
To add expand and collapse action to a group
1. In report design view, click the table or matrix to select it. The Grouping pane displays the row and column groups.
If the Grouping pane does not appear, click the View menu and then click Grouping.
Right-click anywhere in the title bar of the Grouping pane, and then click Advanced. The Grouping pane mode toggles to show the underlying display structure for rows and columns on the design surface.
In the appropriate group pane, click the name of the row group or column group for which you want to hide the associated rows or columns. The group is selected and the Properties pane shows the Tablix Member properties.
In Hidden, choose one of the following options to set the visibility of this report item the first time you run a report:
Select False to display the report item.
Select True to hide the report item.
Select to open the Expression dialog box to create an expression that is evaluated at run time to determine the visibility.
In ToggleItem, from the drop-down box, select the name of a text box to which to add the toggle image.
In the following image, the Color row group is configured enable users to expand and collapse associated rows.
To test the toggle, run the report and click the text box with the toggle image. The report display refreshes to show row groups and column groups with their toggled visibility.
To add expand and collapse action to a report item
In report design view, right-click the report item to show or hide, and then click Properties. The Properties dialog box for the report item opens.
Click Visibility.
In When the report is initially run, choose one of the following options to set the visibility of this report item the first time you run a report:
Select Show to display the report item.
Select Hide to hide the report item.
Select Show or hide based on an expression to use an expression evaluated at run time to determine the visibility. Click (fx) to open the Expression dialog box to create an expression.
In Display can be toggled by this report item, from the drop-down box, type or select the name of a text box in the report in which to display a toggle image; for example, Textbox1.
In the following image, the table is configured to enable users to expand and collapse it. The display of the table is toggled by the Products Table text box.
To test the toggle, run the report and click the text box with the toggle image. The report display refreshes to show report items with their toggled visibility.

Crystal Report Cross Tab Custom Total

Scenario is,
I want to make cross tab crystal report like below image
I made cross tab report shown below but it showing obtain marks total only, I want proper percentage at end ((ObtainMarks/TotalMarks)*100)
help me to sort out pls. im new to corss tab. Its my 4th day on seraching about this topic
You need to use calculated member to achieve this.
Go to preview on last column right click --> calculated member --> insert
You will get a new column added and in that edit the formula for the column and write your formula
#Siva this is my Preview Tab for Report, It showing empty Cross tab options.
Dataset for this report is made in Visual studio. I Select that Dataset as ADO.NET(XML)
I have resolved my Issue on SCN Forum at
http://scn.sap.com/thread/3871853
.#Siva's Answer is start point to solution

Categories