private void createQuery()
{
Query query = new Query();
QueryBuildDataSource qbdsCUstTable;
QueryBuildDataSource qbdsAccType;
QueryBuildDataSource qbdsConRes;
QueryBuildDataSource qbdsConnection;
QueryBuildDataSource qbdsConStatus;
QueryBuildDataSource qbdsDevice;
QueryBuildDataSource qbdsConfigHist;
QueryBuildDataSource qbdsDeviceStatus;
QueryBuildDataSource qbdsFreqHist;
QueryRun queryRn;
Name tmpName;
FcsDateTime tmpDateTime = FcsDateTimeAPI::dateNow();
McsConfigurationHistory configHistLocal;
FcsDateTime startDateLocal, endDateLocal;
str seprator = McsParameters::find(). FedSBMDownloadSeperator;
McsFedOMDivision division;
McsFedOMSubDivision subDivision;
McsFedOMSection section;
McsConnectionMember conMember;
;
qbdsCUstTable = query.addDataSource(tableNum( CustTable));
//.............added by aslam
if(DivisionId)
{
qbdsCUstTable.addRange(fieldNu m(CustTable,FedDivisionId)). value(DivisionId);
}
if(SubDivId)
{
qbdsCUstTable.addRange(fieldNu m(CustTable,FedSubDivId)). value(SubDivId);
}
if(SectionId)
{
qbdsCUstTable.addRange(fieldNu m(CustTable,FedSectionId)). value(SectionId);
}
if(cycleCode)
{
qbdsCUstTable.addRange(fieldNu m(CustTable,FedCycleCode)). value(cycleCode);
}
//...............end by aslam
qbdsAccType = qbdsCUstTable.addDataSource(ta bleNum(McsAccountTypeHistory)) ;
qbdsAccType.addLink(fieldNum( custTable,AccountNum),fieldNum (McsAccountTypeHistory, CustomerId));
// qbdsAccType.joinMode(JoinMode: :InnerJoin);
qbdsAccType.addRange(fieldNum( McsAccountTypeHistory, AccountType)).value( queryValue(McsGlobal:: getDefaultAccountTypeMainRelat ion()));
qbdsAccType.addRange(fieldNum( McsAccountTypeHistory, ValidUntilDate)).value( queryValue(FcsDateTimeAPI:: DateNull()));
qbdsConRes = qbdsAccType.addDataSource(tabl eNum(McsConnectionResponsible) );
qbdsConRes.addLink(fieldNum( McsAccountTypeHistory,Id),fiel dNum(McsConnectionResponsible, AccountTypeHistoryId));
qbdsConRes.addRange(fieldNum( McsConnectionResponsible, ValidUntilDate)).value( queryValue(FcsDateTimeAPI:: DateNull()));
//qbdsConRes.joinMode( JoinMode::InnerJoin);
qbdsConnection = qbdsConRes.addDataSource(table Num(McsConnection));
qbdsConnection.addLink(fieldNu m(McsConnectionResponsible, ConnectionId),fieldNum( McsConnection,Id));
//qbdsConnection. addOrderByField(fieldNum( McsConnection,Id),SortOrder:: Ascending);
//qbdsConnection.joinMode( JoinMode::InnerJoin);
qbdsConStatus = qbdsConnection.addDataSource(t ableNum( McsConnectionStatusHistory));
qbdsConStatus.addLink(fieldNum (McsConnection,Id),fieldNum( McsConnectionStatusHistory, ConnectionId));
qbdsConStatus.addRange(fieldNu m(McsConnectionStatusHistory, ConnectionStatus)).value( queryValue(McsStatuses:: Active));
qbdsConStatus.addRange(fieldNu m(McsConnectionStatusHistory, ValidUntilDate)).value( queryValue(FcsDateTimeAPI:: DateNull()));
//qbdsConStatus.joinMode( JoinMode::InnerJoin);
/*qbdsFreqHist = qbdsConnection.addDataSource( tableNum( McsCmBilBilFrequencyHistory));
qbdsFreqHist.addLink(fieldNum( McsConnection,Id),fieldNum( McsCmBilBilFrequencyHistory, Connectionid));
qbdsFreqHist.addRange( fieldNum( McsCmBilBilFrequencyHistory, ValidUntilDate)).value( queryValue(FcsDateTimeAPI:: DateNull()));
qbdsFreqHist.addRange( fieldNum( McsCmBilBilFrequencyHistory, DataAreaId)).value(queryValue( '((LastBillingDate < EndDate) || (EndDate == 0))'));
//qbdsFreqHist.addRange( fieldNum( McsCmBilBilFrequencyHistory, NextBillingDate)).value( queryValue(FcsDateTimeAPI:: addDayLocal(this.parmEndDate() ,1)));
qbdsFreqHist.addSortField( fieldNum( McsCmBilBilFrequencyHistory, StartDate),SortOrder:: Ascending);
qbdsFreqHist.joinMode( JoinMode::InnerJoin);*/
qbdsConfigHist = qbdsConStatus.addDataSource(ta bleNum( McsConfigurationHistory));
qbdsConfigHist.addLink(fieldNu m(McsConnectionStatusHistory, ConnectionId),fieldNum( McsConfigurationHistory, ConnectionId));
qbdsConfigHist.addRange(fieldN um(McsConfigurationHistory, ValidUntilDate)).value( queryValue(FcsDateTimeAPI:: DateNull()));
//qbdsConfigHist.joinMode( JoinMode::InnerJoin);
qbdsDevice = qbdsConfigHist.addDataSource(t ableNum(McsMeterDevice));
qbdsDevice.addLink(fieldNum( McsConfigurationHistory, MeterDeviceId),fieldNum( McsMeterDevice,Id));
qbdsDevice.addRange(fieldNum( McsMeterDevice,FedPhase)). value(queryValue(McsFedPhases: :ThreePhase));
//qbdsDevice.joinMode( JoinMode::InnerJoin);
qbdsDeviceStatus = qbdsDevice.addDataSource(table Num( McsMeterDeviceStatusHistory));
qbdsDeviceStatus.addLink(field Num(McsMeterDevice,Id),fieldNu m(McsMeterDeviceStatusHistory, MeterDeviceId));
qbdsDeviceStatus.addRange(fiel dNum( McsMeterDeviceStatusHistory, MeterDeviceStatus)).value( queryValue(McsStatuses:: Active));
qbdsDeviceStatus.addRange(fiel dNum( McsMeterDeviceStatusHistory, ValidUntilDate)).value( queryValue(FcsDateTimeAPI:: DateNull()));
//qbdsDeviceStatus.joinMode( JoinMode::InnerJoin);
queryRn = new QueryRun(query);
totalRecords = SysQuery::countLoops(queryRn);
progress.setCaption("Downlaod Customer");
progress.setAnimation(# aviUpdate);
progress.setTotal( totalRecords);
progress.update(true);
totalRecords = 0;
while (queryRn.next())
{
//custTable.clear();
//meterDevice.clear();
//Connection.clear();
//configHistLocal.clear();
custTable = queryRn.get(tableNum( CustTable));
meterDevice = queryRn.get(tableNum( McsMeterDevice));
Connection = queryRn.get(tableNum( McsConnection));
configHistLocal = queryRn.get(tableNum( McsConfigurationHistory));
progress.setText("Exporting Customer " + custTable.name());
progress.update(true);
//Consumer No. ---1
tb.setText(tb.getText() + strFmt("%1%2",custTable. McsExternalID1,seprator));
//Old K Number----2
tb.setText(tb.getText() + strfmt("%1%2",custTable. McsExternalId3,seprator));
//Tariff Code ----3
tb.setText(tb.getText() + strfmt("%1%2",custTable. CustGroup,seprator));
//Meter Serial Number---4
tb.setText(tb.getText() + strfmt("%1%2",meterDevice. MeterDeviceSerialNumber, seprator));
//Consumer Name---5
tb.setText(tb.getText() + strfmt("%1%2",subStr( custTable.name(),1,20), seprator));
//Address---6
tb.setText(tb.getText() + strfmt("%1%2",subStr( custTable.address(),1,20), seprator));
//Cycle Display Code----7
tb.setText(tb.getText() + strfmt("%1%2",custTable. FedCycleCode,seprator));
//Route Nbr---8
tb.setText(tb.getText() + strfmt("%1%2",custTable. FedRouteNbr,seprator));
//Division---9
division.clear();
select DisplayCode from division
where division.DivisionId == custTable.FedDivisionId;
tb.setText(tb.getText() + strfmt("%1%2",division. DisplayCode,seprator));
//SubDivision---10
subDivision.clear();
select DisplayCode from subDivision
where subDivision.SubDivId == custTable.FedSubDivId;
tb.setText(tb.getText() + strfmt("%1%2",subDivision. DisplayCode,seprator));
//section---11
section.clear();
select DisplayCode from section
where section.SectionId == custTable.FedSectionId;
tb.setText(tb.getText() + strfmt("%1%2",section. DisplayCode,seprator));
//BillMonth---12
select EndDate from calCOnsumption
order by EndDate desc
exists join conMember
where conMember.Id == calCOnsumption. ConnectionMemberId
&& calCOnsumption.ValidUntilDate == 0
&& conMember.ValidUntilDate == 0
&& conMember.ConnectionId == Connection.Id
&& conMember.ConnectionMemberType == McsConnectionMemberTypes:: mmrcons;
tb.setText(tb.getText() + strfmt("%1",date2str( FcsDateTimeAPI:: convertToDateLocal( calCOnsumption.EndDate),123,0, 0,3,3,2)));
tb.setText(tb.getText() + strfmt("\n"));
progress.incCount();
progress.update(true);
}
}
No comments:
Post a Comment