Unable to create a QuickReport portraying a one-to-many relationship in C++ Builder 6 - c++builder-6

I am attempting to create a report using QuickReport in C++ Builder 6 and cannot produce the results I require.
I have attempted to create this report in two ways with marginal success. I've detailed one attempt below as it appears to be the most promising. I am new to QuickReport and have no idea where else to look for help. The documentation I've found online at http://www.quickreport.co.uk/ is minimal and does not adequately explain how to use the product beyond extremely simple reports.
The report should be formatted as such:
Manufacturer 1
A product
Another product
Yet another product
Manufacturer 2
My product
This product
Attempt 1: Two queries separating Manufacturer and Product data
Create a TQuery that gets a collection of Manufacturers by their IDs.
Create a Detail band.
Set the DataSet for the report to the Manufacturer TQuery.
Create Manufacturer Name QRDBText field on the Detail band associated with the Manufacturer TQuery and Manufacturer Name field.
Create a TQuery that gets a collection of Products by their Manufacturer's ID which is a parameter to the TQuery.
Create a Sub Detail band.
Set the DataSet for the Sub Detail band to the Product TQuery.
Create Product Name QRDBText field on the Sub Detail band associated with the Product TQuery and Product Name field.
Create events for the Sub Detail band:
BeforePrint:
Takes the current Manufacturer ID and insert it as a parameter to the Product TQuery
Activates the Product TQuery
AfterPrint:
Deactivates the Product TQuery
Result: This almost gets me what I require. It displays every Manufacturer properly, however it only displays the first Product for each Manufacturer. I'm not sure if I'm incorrectly expecting the Sub Detail band to iterate through the results as the Detail band does, or if I'm missing some other necessary step to make it work. I've also considered using Loop or Child bands, but neither appear to offer the functionality I expect. Again, I can't seem to find decent documentation explaining QuickReport at all.
In the end, I can't determine if I'm expecting functionality QuickReport doesn't offer or if I'm thinking about this all wrong.

The solution:
Create a TQuery that gets a collection of Manufacturers by their IDs.
Create a Detail band.
Set the DataSet for the report to the Manufacturer TQuery.
Create Manufacturer Name QRDBText field on the Detail band associated with the Manufacturer TQuery and Manufacturer Name field.
Create a TQuery that gets a collection of Products by their Manufacturer's ID which is a parameter to the TQuery.
Create a Sub Detail band.
Set the DataSet for the Sub Detail band to the Product TQuery.
Create Product Name QRDBText field on the Sub Detail band associated with the Product TQuery and Product Name field.
NEW! Set the Detail band's LinkBand property to the Sub Detail band.
NEW! Prior to Printing/Previewing/etc. the report, in code set each query's Active property to True.
NEW! After Printing/Previewing/etc. the report, in code set each query's Active property to False.
The part that really threw me off was the "magic" that occurs wherein you needn't specify the parameters between the data source and the query for Products. It appears that if you specify a parameter required for a query pointing at a dataset then the query will look for a field sharing that name and match them.
I hope this helps someone down the road.

Related

Creating a duplicate record in MS Access using Append Query

I have a table "Tbl_Invoice" with invoice details [Primary key "InvID"] and another table "Tbl_Invoice_Details" with the invoiced item details (items, quantity purchased, rate, amount, total) [primary key "InvDetID" and foreign key "InvID" linked to invoice table]. In the main form "Frm_Invoice" with data source "Tbl_Invoice", I have included a subform with item details from the "Tbl_Invoice_Details".
I have two problems -
The subform shows the total of all the items purchased in the footer (using the sum function from the menu bar). But I am unable to bring the total of the subform to the main form where the discount is calculated, tax added, rounded off (if necessary) and calculates the invoice amount.
I want to create a duplicate record (total invoice with items, etc.) only the customer name, invoice no., date changes. I am using two separate append queries, one for the invoice details and the other for the invoiced item details. Both works. The problem is I am unable to link the new records in the subform/subtable "Tbl_Invoice_Details" with the new record in the main form / main table "Tbl_Invoice".
I am a newbie and do not have much knowledge of VBA. Please help!
As for your second question, use the RecordsetClone of the main form and the subform respectively to copy the main record and the subrecords:
Duplicate records in Subform to New record
For Question one look at the two images, i have attached.
Name of subform in my case is BILLINGDETAILS
Name of control in subform is TOTALPAID,with caption Text2(caption is not relevant to the outcome)
Look closely at how the TOTALPAID control in subform is referenced from the Main form.
For your question two, if you can share the tables relationship window and image of the form link fields , you will get someone in this forum that will answer it.

Create relationship between two query delphi

I have two table Country and City (country_id is PK in Country table and country_id is FK in City table).
Which component use to create relation between two query for fast report.
Which structure should be:
Query 2. Client Data set .... 3. ? 4.?
This is usually called a Master-Detail relationship between the datasets involved.
In Delphi, you set one up by connecting the Detail dataset to a TDataSource whose dataset is the connected to the Master dataset. You can do this on the server side (i.e between the two queries, using the DataSource property of the Detail or between two clientdatasets using the MasterSource property of the.Detail. When doing it on the server side, you write the SQL for the query as a parameterised query, with the parameter being one whose value matches the Master's PK as in
Select * from mydetailtable where masterid = :masterid
Once a Master-Detail relationship has been set up between two datasets, it should work with virtually any report generator, FastReports included.
See e.g. http://docwiki.embarcadero.com/RADStudio/Rio/en/Setting_Up_Master-Detail_Linked_Relationships which talks about this in terms of DBExpress components, but the principle is applicable to other Delphi dataset components.

Sorting a nested collectionDatasource in Cuba Framework

I have a bookDatasource. One book has many authors. The collection is displayed in a grid on the book-edit-view. Now I want to sort by authors name. In the collectionDatasource properties I set sortable to true.
How can I do it?
If I understand correctly, you're binding Table and Book Authors using nested datasource, like that:
<datasource id="bookDs"
class="com.company.test.entity.Book"
view="book-edit-view">
<collectionDatasource id="authorsDs" property="authors"/>
</datasource>
If so, first, ensure that Book entity has collection of Authors attribute of ordered type (List or LinkedHashSet). If its not you can change collection type in Studio or manually in Book entity.
Then table column becomes sortable - when user clicks on column header table will sort rows accordingly. Also CUBA Platform will handle saving sorting setting as user settings - so next time user opens the screen table will be sorted.
In order to enable sorting of Book Authors by default you could do it on ORM level. In Studio open entity Book, click on authors attribute and set value name in Order by field in attribute properties panel. This will ensure that any instance of Book entity has authors sorted by name.

How to show selected items of certain table on the different table in Dynamics AX 2012?

So, I have two tables InventTable (for inverntory) and MyCartTable. I want to connect this tables so when I chose some item or items in InventTable to show in MyCartTable's grid. MyCartTable fields are ItemNumber, ProductName, PartyID;
Assuming you are working with AX 2012:
On your MyCartTable, remove the itemNumber field.
Open an other AOT windows go to Data Dictionary - Extended Data Types and locate the itemId data type. Drag and drop this data type on your table. AX will ask if you want to add a foreign key relation. Click yes, this will add a relation to the InventTable to the relations node of your table.
Now on your form, set the JoinSource property of your MyCartTable to you inventTable data source.
If you are having trouble making this work, create a new form with only those two datasources and a minimum amount of controls (like just 2 grids), this allows you to test this more easily.

How can I print different bands depending on the value of a Field in a DataSet using FastReport?

I have a product's dataset and I want to have distinct bands for each type of product, something like, if the product is a fruit, print it's weight, if the product is a car print its color and so on.
And I want to let my users customize it, so each band for each type o product will be perfect.
My DataSet have all fields from all type of products and I have a field which determines the product type of the actual record.
Is there some easy to way to do it?
FastReports allows you to intercept the program's default report construction process with events at several useful places. If you have, for example a master band, in its OnBeforePrint event, you can put code that checks out the type of product and then a case statement could set the visible property to true only on detail bands that are the right kind of property.
I have found the news group at news://newsgroups.fast-report.com/fast-reports.public.fastreport.4 to be an incredible source of help and encouragement. I am sure you can find a much better answer to your question there.

Resources