mercredi 20 juillet 2011

How to check inserting records in a table

Here is an example of a  method that sets conditions before inserting records in a table

public boolean validateField(fieldId _fieldIdToCheck)
{
    boolean ret;
    ThyVendAccreditTable    Accredit;
    Str                     _year1,_year2;
    ;

    ret = super(_fieldIdToCheck);
    if(ret)
    {
        switch(_fieldIdToCheck)
        {
            case (FieldNum(ThyVendAccreditTable,Thy_vendScore)):
                if(this.Thy_VendScore>100)
                {
                    ret =checkfailed(strfmt("@THY8"));
                }
            break;
            case(FieldNum(ThyVendAccreditTable,ThyAccreditDate)):
            _year1 = date2str(this.ThyAccreditDate,123,0,0,0,0,4);
            while select accredit where accredit.VendAccount == this.VendAccount
            {
                _year2 = date2str(accredit.ThyAccreditDate,123,0,0,0,0,4);
                if(_year1==_year2)
                {
                    ret =checkfailed(strfmt("@THY9"));
                    break;
                }
            }
            break;
        }
    }

    return ret;
}

here is an example  to abort inserting and displaying an error message

//<iba>
        if (!InventTrans::existThy_InventVendNum(thy_InventVendNum,_inventTrans.CustVendAC))
        {
            _inventTrans.Thy_InventVendNum = thy_InventVendNum;
            _inventTrans.update();
        }
        else
        {
            checkFailed(strfmt("@THY10",thy_InventVendNum,_inventTrans.CustVendAC));
            return;
        }
       //</iba>

Aucun commentaire:

Enregistrer un commentaire