Using Crystal reports to generate ID card dynamically - c#

i want to generate an ID card for various group members belonging to different section. Each has a different format depending on what user selects e.g
What i also want is the photo portion should be adjustable in the area where the user wants to amd also the photo that comes from database should be able to crop as per the user requirements.
Is this possible doing using Crystal Reports.Any tutorials and guidelines will be helpful as i am absolutely new to using Crystal Reports.
If not using=Crystal Reports,what is the other best option.
Please help me to get the ID card to be generated dynamically.

If you wanted to narrow it down to just one report you could something similar to what MD-Tech suggested but use sections that are hidden or shown depending on the user selection.

There are three options:
two reports - like what MD-Tech is suggesting. two reports, on average, are more difficult to maintain.
one report/two sections - like what BUkHix suggests. you create the desired formatting in two separate sections, then use a parameter to hide/show the desired section
one report/two sub-reports - this gives you the most, finely-grained control over the formatting. the sub-reports display can also be controlled by a parameter.
In any case, you can control the image's X (distance from left margin) in v 11.0 using a conditional formula. In v 12.0, you can also control the Width property with a conditional formula. A conditional formula can reference a parameter field, so the positioning can make use of a user-supplied value.
You will also need to experiment with the image types, as Crystal Reports supports a limited set (JPG and BMP for sure).

Splitting this into 2 answers so much info incoming; firstly loading separate reports:
it is possible to select which reports are loaded at runtime by conditionally calling the Load() function of the document class. An example of this would be (in c++):
ReportDocument myDocument = gcnew myDocument();
if(wideIDcard)
{
myDocument->Load("wideIDCard.rpt");
}
else
{
myDocument->Load("narrowIDCard.rpt");
}
where the boolean wideIDCard is set from a dropdown box etc. from a front end. The ReportDocument myDocument can then be sent to the report viewer to view that report.

The quickest way to do this whould be to have 2 separate reports and then have the code Load() the correct one dependent on the user selection, which would come from a separate windows form. It is possible (though difficult) to create this form in such a way as to use it to set all the parameters for the report if you need it to be a single entry form.

Related

C# Windows Forms

I am new here and startig to learn C#. Before I programed in C and Windows.Forms in VBA.
Now I have a Project where I receive serial port data from a device, that sends the contents of various C-structs (some nested). I want to display these Datasets in Windows.Forms each labeled, edit the values and send it back to the device. So it can easily copy the received data into its structures.
Now I don't know an easy way to get the structured data inside a c#-byte-list into various text boxes(?) that have describing labels to it. I would like to design the layout in Form Designer, so not want to create the controls dynamically. But maybe this is the best way?
Does someone know a good strategy / a best suited control to achieve this?
Thanks in advance.
You could use a DataGridView with control buttons inside each row or external buttons that handle selected row(s). In order to see and change the details a corresponding dialog form comes in handy in which I would implement a hex editor with the byte/hex values on the left and the readable value on the right.
To display the byte data just convert it to a hexadecimal string so you can display it in one column inside the DataGridView.
For the nesting part, you could either implement child elements inside the DataGridView itself (you need to either code this yourself or use some 3rd party extensions like this or Telerik, e.g., which also has the possibility of including button columns) or open a conditional dialog form which again shows a DataGridView for the child elements and so on (so you would open the same form as child form ad infinitum).
Thereby you are as flexible as possible and do not rely on fixed text box elements which you have to add or extend on further information.

How can I set Report Viewer language the same as CultureInfo.CurrentUICulture?

As I understood, by default, the language of report viewer is set by "CultureInfo.InstalledUICulture" (not that simple). That means, if my computer is from Brazil, then it will format numbers with Brazil's culture. Altought my data may be formatted with United States' culture, so my report viewer display things incorrectly. I guess one solution to solve it, is by changing the language of the report viewer as the same of my CultureInfo.CurrentUICulture.
How can I achieve that in the simplest way, please?
In the report properties set the Language property as:
=System.Threading.Thread.CurrentThread.CurrentUICulture.ToString()
Or to whatever you need. I'm using a report parameter for example. The value must resolve to a string.
You can access the report properties via the properties window, and then from the top list select "Report". Or you could simply click in the gray area of the report, and press F4.
.
There are two (+1) separate things here:
The language of the controls, tooltips, etc. inside the ReportViewer control. This depends on the System.Threading.Thread.CurrentThread.CurrentUICulture.
The number, date, currency, etc. formats within the report. These are controlled by changing the Language property of the rdlc file in use.
The actual content of the report which is controlled via your DataSource(s). This one is pretty obvious, but I mentioned it for sake of completeness.

Rendering image in BandedGridColumn from MySQL Blob field

I have a number of images stored in a Blob type field inside a MySQL InnoDB database along with other information pertaining to those images stored in another fields.
As you know the Banded Grid View distributed in DevExpress version 11.2, with the help of Banded Grid Columns, is capable of rendering several types of data, most notably images.
So far I'm able to create every control and load any kind of data required, including the images, using the common MySqlDataReader and DataSet approach, through the Grid Control DataSource property, that owns the BandedGridView.
However as you know, when you load a Blob field from MySQL you are returned a byte array with the content of the file, in this case the image in question.
I was hoping DevExpress would recognize the binary data and realize it was a image file, and automatically render the image in all the rows under the Column assigned to handle the database Image field, however it did not and now that I think of it, it was probably far fetched hope.
Instead of rendering the image, each row of the column shows a simple string output referencing what type of object the field contains. In this case since its a binary representation of a file, it outputs System.Byte[].
I've search the DevExpress documentation and generally on the web, nothing clear was found that could solve my problem. There is a example of my desired result packed along with DevExpress, the solution named "GridMainDemo" under the WinForms -> XtraGrid section. Once your running the demo, change into Alternate Views and into Banded Grid View, then just click on any row under the picture column, and you will see a clear example of my desired result.
Of course I've looked into the source of that demo, however I cannot say that clarification and explanation was a clear aim of the DevExpress team that built such demo, and unfortunately I didn't had much time to look at it deeply. However from what I've seen this demo differs from the point that the images are stored locally as files, and already properly reference in some sort of repository, which doesn't help much with my problem.
To finish my question, sorry for the long reading, just wanted to give a clear idea of what my aim is, what stands in the way, and how all things are set in order to find a way to reach my aim.
Now to cut a long story short. A simple example of how to load a image from a MySQL Blob field into a column in a Banded Grid View and have it rendered after load or when the user clicks the field cell, would be ideal and with it I would be able to understand and do the necessary code so that my View also renders my images.
My biggest thanks with this, really.
Note: Unfortunately, using local or even remote stored files is not
a option. The images must be kept within the confinements of the
database.
It wasn't so hard after all, and seems hope was well place and DevExpress did most of the work.
So, to help those who have a similar question, here is what you have to do, so you can have a certain column showing a image stored in a Blob type field.
Assuming you already loaded the data to your grid and it's being displayed correctly with the exception of the image of course.
First: You must declare a RepositoryItemImageEdit type object, that will simply implement a ImageEdit type control in the cell, which when trying to edit the cell value it will show your image, the goal of this question. If your goal differs on that point simply read the note after this answer afterwards.
Second: You must add the previously last declared object to your GridControl.RepositoryItems collection property. You can easily accomplish it using the Add method.
Third: Now you must define what type of control will be used to render the data for you Image column, for that you simple reference the BandedGridColumn.ColumnEdit property to be equal to the object you just added before.
Example
/* Create your columns, bands etc manually or
have it done automatically after loading the data.*/
...
// Load the data from the database to your gridControl
...
// Step one
RepositoryItemImageEdit imageControl = new RepositoryItemImageEdit();
// Step two
gridControl.RepositoryItems.Add(imageControl);
// Step three
/* view is the View assigned to your grid control
where your data and columns are being shown.*/
// Assuming your database blob field is named `Image`
view.Columns["Image"].ColumnEdit = imageControl;
If your data was loaded correctly and your columns assigned properly to their respective fields then this should render a small icon on each cell of your Image column and once your click or focus on it, a ImageEdit control will be rendered and show your image.
Note:
There are other controls besides ImageEdit capable of rendering images, for those others you will have to find
theirRepositoryItem based implementation.
Also, your Image column must be editable, otherwise this approach won't
work. Bare in mind that allowing edition at the column level will not work if it is denied at the View level through the OptionsBehavior.Editable property.
I will mark my answer as the correct one since no one else provided any insight on how to solve my problem, however you are welcome to post any other working approaches to this problem. Thank you.

Paragraph breakage, one page to the other page, in detail section of Crystal Reports

I have made a report in Crystal Reports, it has a detail section, i have dragged a variable carrying text and if the paragraph of the text longer, i want its half of the part should be gone to the next page, as we see in text books and as it is a standward way on A4 paper.
When i write a variable carrying data in text for detail, this problem occurs. I had used some algorithm or like that to divide the data into two parts and made two variables, but as data can be html also so that algorithm does not work in very good manner. I just want to use crystal reports functionality. Thanks in advance.I am attaching an image for further understanding.
The history field should have a property called 'keep together'. I'm guessing its set to true and should be changed to false to allow the field to be split across a page break.

How to change the subreport source in a run time?

I'm creating some report in C# and I have 2 types of them. The header and footer are the same but the middle part is different. I have a type parameter to determine which type report is it. But I don't know how to change the source subreport. The field "Use this report as subreport" unfortunately doesn't allow to enter the expression so I cannot define the necessary report by condition. And I don't know how to do that from the code.
I've found the solution. Just put 2 different subreports on the main report and use expression to determine which one should be shown, which - to be hidden. Stupid but works.

Categories