Use of Switch case and add data field to grid at runtime.
public void Bind_Total()
{
FormControl FC1, FC2, FC3, FC4, FC5, FC6, FC7;
delete_from SD_AllDetails_Total;
select sum(NoofSP), sum(Area), sum(ApproxYield), sum(ActualYield), sum(NoLot), from SD_AllDetails_1;
SD_AllDetails_Total1.NoofSP = SD_AllDetails_1.NoofSP;
SD_AllDetails_Total1.Area = SD_AllDetails_1.Area;
SD_AllDetails_Total1.ApproxYield = SD_AllDetails_1.ApproxYield;
SD_AllDetails_Total1.ActualYield = SD_AllDetails_1.ActualYield;
SD_AllDetails_Total1.NoLot = SD_AllDetails_1.NoLot;
SD_AllDetails_Total1.insert();
SD_AllDetails_Total_ds.refresh();
SD_AllDetails_Total_ds.reread();
SD_AllDetails_Total_ds.research();
GridTotal = GroupTotal.addControl(FormControlType::Grid, "GridTotal", StaticText);
GridTotal.dataSource(SD_AllDetails_Total_ds.id());
while select * from SD_Columns3 order by SD_Columns3.ID where SD_Columns3.YesNo == true && SD_Columns3.GroupBy == false
{
switch(SD_Columns3.ID)
{
case 21:
if(SD_Columns3.YesNo == true)
FC1 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, NoofSP));
break;
case 22:
if(SD_Columns3.YesNo == true)
FC2 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, Area));
break;
case 23:
if(SD_Columns3.YesNo == true)
FC3 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, ApproxYield));
break;
case 24:
if(SD_Columns3.YesNo == true)
FC4 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, ActualYield));
break;
case 25:
if(SD_Columns3.YesNo == true)
FC5 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, NoLot));
break;
}
}
GridTotal.width(950);
GridTotal.height(50);
GridTotal.visibleRows(2);
GridTotal.controlNum(1).setFocus();
GridTotal.dataSource(SD_AllDetails_Total_ds);
SD_AllDetails_Total_ds.refresh();
SD_AllDetails_Total_ds.reread();
SD_AllDetails_Total_ds.research();
// GridTotal.update();
}
public void Bind_Total()
{
FormControl FC1, FC2, FC3, FC4, FC5, FC6, FC7;
delete_from SD_AllDetails_Total;
select sum(NoofSP), sum(Area), sum(ApproxYield), sum(ActualYield), sum(NoLot), from SD_AllDetails_1;
SD_AllDetails_Total1.NoofSP = SD_AllDetails_1.NoofSP;
SD_AllDetails_Total1.Area = SD_AllDetails_1.Area;
SD_AllDetails_Total1.ApproxYield = SD_AllDetails_1.ApproxYield;
SD_AllDetails_Total1.ActualYield = SD_AllDetails_1.ActualYield;
SD_AllDetails_Total1.NoLot = SD_AllDetails_1.NoLot;
SD_AllDetails_Total1.insert();
SD_AllDetails_Total_ds.refresh();
SD_AllDetails_Total_ds.reread();
SD_AllDetails_Total_ds.research();
GridTotal = GroupTotal.addControl(FormControlType::Grid, "GridTotal", StaticText);
GridTotal.dataSource(SD_AllDetails_Total_ds.id());
while select * from SD_Columns3 order by SD_Columns3.ID where SD_Columns3.YesNo == true && SD_Columns3.GroupBy == false
{
switch(SD_Columns3.ID)
{
case 21:
if(SD_Columns3.YesNo == true)
FC1 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, NoofSP));
break;
case 22:
if(SD_Columns3.YesNo == true)
FC2 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, Area));
break;
case 23:
if(SD_Columns3.YesNo == true)
FC3 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, ApproxYield));
break;
case 24:
if(SD_Columns3.YesNo == true)
FC4 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, ActualYield));
break;
case 25:
if(SD_Columns3.YesNo == true)
FC5 = GridTotal.addDataField(SD_AllDetails_Total_ds.id(), fieldnum(SD_AllDetails, NoLot));
break;
}
}
GridTotal.width(950);
GridTotal.height(50);
GridTotal.visibleRows(2);
GridTotal.controlNum(1).setFocus();
GridTotal.dataSource(SD_AllDetails_Total_ds);
SD_AllDetails_Total_ds.refresh();
SD_AllDetails_Total_ds.reread();
SD_AllDetails_Total_ds.research();
// GridTotal.update();
}