Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm having trouble displaying the same level listing as a list that has been Group. Here I will try to explain most easily

My data is as follows:
Driver
{
0_Code: 01 | Name: A | Salary: 1000
1_Code: 02 | Name: B | Salary: 2000
}
Travel
{
0_DriverC: 01 | Name: A | Salary: 1000 | Date: 5/2 | Route: ABC 
1_DriverC: 01 | Name: A | Salary: 1000 | Date: 7/2 | Route: XYZ
2_DriverC: 02 | Name: B | Salary: 2000 | Date: 1/2 | Route: EFG
}
Expense
{
0_DriverC: 01 | ExpenseN: X | ExpenseMoney: 100
1_DriverC: 01 | ExpenseN: Y | ExpenseMoney: 500
2_DriverC: 01 | ExpenseN: Z | ExpenseMoney: 300
3_DriverC: 02 | ExpenseN: K | ExpenseMoney: 400
}

In CrystalReport i designed the following:
Section1(Report Header)
_____________________________
Section2(Page Header)
_____________________________
GroupHeaderSection2(Group Header#1: Travel.DriverC-A)
_____________________________
Section3(Details)
Driver Name: ?Name
?Date    ?DriverC     ?Nane    ?Route   ?Salary
_____________________________
GroupHeaderSection2(Group Footer#1: Travel.DriverC-A)
TotalSalary                                                 Sum of ?Salary
ExpenseN (Here i will list the costs by the Driver group)   ?ExpenseMoney
Total                                             Sum of (?Salary,?ExpenseMoney)

The results Report i want can be as follows:
Driver Name: A
5/2    01     A     ABC    1000
7/2    01     A     XYZ    1000
TotalSalary                2000
X                          100
Y                          500
Z                          300
Total                      4900
_____________________________
Driver Name: B
1/2    02     B     EFG    2000
TotalSalary                2000
K                          400
Total                      2400

This is the code that assigns values to DataRow:

var travel = TravelService.GetAllQueryable().ToList();
for(int i = 0; i < travel.Count; i++)
{
    row = dt.NewRow();
    row["Date"] = travel[i].Date;
    row["DriverC"] = travel[i].DriverC;
    row["Nane"] = travel[i].Nane;
    row["Route"] = travel[i].Route;
    row["Salary"] = travel[i].Salary;
    var expense = ExpenseService.Query(p => p.DriverC == travel[i].DriverC).ToList();
    for(int k = 0; k < expense.Count; k++)
    {
       row["ExpenseN"] = expense[k].ExpenseN;
       row["ExpenseMoney"] = expense[k].ExpenseMoney;
    }
    dt.Rows.Add(row);
}


What I have tried:

I think the code assigning value to Expense has a problem. I am confused when displaying a list of the same level. How can I display the list of Expense by Travel has been grouped?
Posted
Updated 8-Feb-18 14:38pm
v2

1 solution

I think you need to use a sub-report - I say I think because the question is not really clear.
My understanding is you have a One to Many join between Driver & Travel & another One to Many between Driver & Expenses.
Crystal will not allow you to list both as the details section, hence you would do as follows;
a) Create your Report using the sections identified above (Group by Driver, then display Travel in Details section)
b) Add a new Detail section (right-click on Details & select Insert Section Below)
c) Select Insert >> Subreport menu item
d) Create a report on the Expenses data
e) Set the Link to be the Driver ID - or whatever the link is between Driver and Expenses

Kind Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900