Tuesday, March 27, 2012

Bread crumb bar event firing

 
//Add new variable and parm method to info class
Class declaration
boolean                 addressBarEvent; 

boolean parmAddressBarEvent(boolean _addressBarEvent = addressBarEvent)
{
    ;
    addressBarEvent = _addressBarEvent;
    return  addressBarEvent;
}

Do a forward compile

//Add a container object and parse the path to check if the user has selected change company option.
//If Yes, set the parm method info class.
\Classes\SysTaskRecorder_AddressbarEvents\fire_BreadcrumbBarNodeNavigate

    container   conStr;     infolog.parmAddressBarEvent(false);
    conStr = str2con(path,"\\");
    if (conlen(conStr)== 2)
        infolog.parmAddressBarEvent(true);
    
Do a forward compile

//In change default company check if the info parm method is set and perform the required action.
\Classes\Application\setDefaultCompany
    if (dialog)
    {
        //set the applicable user groups
        CAP_UserCompanyGroupServer::addUserGroupList();
        SysSecurity::reload(false);
        //infolog.runStartupMenu();
    }
    else if (infolog.parmAddressBarEvent())
    {
        //set the applicable user groups
        CAP_UserCompanyGroupServer::addUserGroupList();
        SysSecurity::reload(false);
        //infolog.runStartupMenu();
        infolog.parmAddressBarEvent(false);        
    }


Friday, March 16, 2012

Expr In Query For Dates

 
Class CustTransQueryAgingBucktetStat:


    str                     dateNull;
    Range                   rangeDocDate;
    date                    sqlFromDate;
    date                    sqlToDate;

    str date2SqlStr(date _date)
    {
        str sqlDate;

        if (_date == dateNull())
        {
            sqlDate = '01\\01\\1901';
        }
        else
        {
            if(_date == maxdate())
            {
                sqlDate = '31\\12\\2150';
            }
            else
            {
                sqlDate = date2str(_date, 123, 2, 3, 2, 3, 4);
                sqlDate = strReplace(sqlDate, '-', '\\');
            }
        }
        return sqlDate;
    }

    ;



    range = transDataSource.addRange(fieldnum(CustTrans, RecId));
    sqlFromDate = statementEndDate ? statementStartDate : dateNull();
    sqlToDate   = statementEndDate   ? statementEndDate   : maxdate();
    dateNull = date2StrXpp(dateNull());
    rangeDocDate  = '((DocumentDate >= ' + date2SqlStr(sqlFromDate) + ') &&';
    rangeDocDate += '(DocumentDate <= ' + date2SqlStr(sqlToDate) + ')) ||';
    rangeDocDate += '((DocumentDate = ' + dateNull + ') &&';
    rangeDocDate += '(TransDate >= ' + date2SqlStr(sqlFromDate) + ') && ';
    rangeDocDate += '(TransDate <= ' + date2SqlStr(sqlToDate) + '))';

    range.value(rangeDocDate);

Using joins in Query

void initParmDefault()
{
    Query                       query;
    QueryBuildDataSource        queryBuildDataSource,queryBuildDSProd;
    QueryBuildRange queryBuildRange,queryBuildRangeStatus;
    ;
    super();

    query = new Query();
    queryBuildDataSource = query.addDataSource(tablenum(InventTable));
    queryBuildDataSource.addSelectionField(fieldnum(InventTable, ItemId));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable, ItemType));
    queryBuildRange.value(SysQuery::value(ItemType::BOM));
    queryBuildRange.status(RangeStatus::Locked);
    queryBuildDataSource.addRange(fieldnum(InventTable, itemId));

    queryBuildDSProd = queryBuildDataSource.addDataSource(tablenum(ProdTable));
    queryBuildDSProd.addSelectionField(fieldnum(prodTable,itemId));
    queryBuildRangeStatus = queryBuildDSProd.addRange(fieldnum(ProdTable,ProdStatus));
    queryBuildRangeStatus.value(SysQuery::range(ProdStatus::Created,ProdStatus::StartedUp));
    queryBuildRangeStatus.status(RangeStatus::Locked);

    queryBuildDSProd.joinMode(JoinMode::ExistsJoin);
    queryBuildDSProd.fetchMode(QueryFetchMode::One2One);
    queryBuildDSProd.addLink(fieldnum(inventTable,itemid),fieldnum(prodTable,itemId));

    queryRun = new QueryRun(query);

    //QueryRun = new QueryRun(querystr(InventTable));


}

Using Expression in Query

Note: when string field is used in filteration then "" should be used. In the below example GroupId is string and when integer fields is used, no need to used "".
void queryFilter()
{
    AA_PriceDiscGroupBrand      priceDiscGroupBrand;
    str                         qbrValue,qbrGroupValue, qbrGroupValueAll;
    int                         relationVal;
    boolean                     recordFound = false;
    ;
    while select Type, GroupId from priceDiscGroupBrand  where
        (prevDate                >= priceDiscGroupBrand.FromDate  || ! priceDiscGroupBrand.FromDate)       &&
        (prevDate                  <= priceDiscGroupBrand.ToDate    || ! priceDiscGroupBrand.ToDate) &&
        priceDiscGroupBrand.CustAccount == custAccount

    {
        recordFound = true;
        if (priceDiscGroupBrand.Type == PriceGroupType::LineDiscGroup)
            relationVal = 5;
        if (priceDiscGroupBrand.Type == PriceGroupType::PriceGroup)
            relationVal = 4;

        qbrGroupValue = strFmt('(' +
                           '((%1.%2 == "%3") && (%1.%4 == %5) && (%1.%6 == %7))' +
                          ')',
                        this.query().dataSourceNo(1).name(),
                        fieldStr(PriceDiscTable,AccountRelation),
                        priceDiscGroupBrand.GroupId,
                        fieldStr(PriceDiscTable,AccountCode),
                        1,
                        fieldStr(PriceDiscTable,Relation),
                        relationVal
                        );
        if (!qbrGroupValueAll)
            qbrGroupValueAll = qbrGroupValue;
        else
            qbrGroupValueAll = qbrGroupValueAll + '||' + qbrGroupValue;
    }

    if (recordFound)
    {
        qbrGroupValueAll = '(' + qbrGroupValueAll + ')';
        qbrValue = strFmt('(' +
                          '((%1.%2 == "%3") && (%1.%4 == %5) && ((%1.%6 == %7) || (%1.%6 == %8)))'
                          + '||' +
                          '((%1.%2 == "%9") && (%1.%4 == %10) && ((%1.%6 == %7) || (%1.%6 == %8)))'
                          + '||' + qbrGroupValueAll +
                          ')',
                            this.query().dataSourceNo(1).name(),
                            fieldStr(PriceDiscTable,AccountRelation),
                            custAccount,
                            fieldStr(PriceDiscTable,AccountCode),
                            0,
                            fieldStr(PriceDiscTable,Relation),
                            4,5,
                            "",
                            2
                            );
    }
    else
    {

          qbrValue = strFmt('(' +
                          '((%1.%2 == "%3") && (%1.%4 == %5) && ((%1.%6 == %7) || (%1.%6 == %8)))'
                          + '||' +
                          '((%1.%2 == "%9") && (%1.%4 == %10) && ((%1.%6 == %7) || (%1.%6 == %8)))' + ')',
                            this.query().dataSourceNo(1).name(),
                            fieldStr(PriceDiscTable,AccountRelation),
                            custAccount,
                            fieldStr(PriceDiscTable,AccountCode),
                            0,
                            fieldStr(PriceDiscTable,Relation),
                            4,5,
                            "",
                            2
                            );
    }
    this.query().dataSourceNo(1).clearDynalinks();
    this.query().dataSourceNo(1).clearRanges();
    this.query().dataSourceTable(tableNum(PriceDiscTable)).addRange(fieldNum(PriceDiscTable,recid)).value(qbrValue);

}