Saturday 21 October 2017

disable the form datasource from the class.

We can easily disable the form datasource from the class.

Practically there should be no code in the form except calling the methods all the codes should ne on form or tables.

lets have this code in form datasource active and modified method :

[DataSource]
    class WHSPhysDimUOM
    {
        public int active()
        {
            int ret = super();

            whsPhysDimUOMForm.setAllowEditPhysicalDimUOMDataSourc(WHSPhysDimUOM_ds);
                     
            return ret;
        }
        [DataField]
        class UOM
        {
            public void modified()
            {
                super();
                whsPhysDimUOMForm.setAllowEditPhysicalDimUOMDataSource(WHSPhysDimUOM_ds);
            }
        }
    }


Now go to the class write the code as :

    /// <summary>
    /// Sets the allow edit property for the passed <c>WHSPhysDimUOM</c> form data source.
    /// The passed data source must be <c>WHSPhysDimUOM</c>.
    /// </summary>
    public void setAllowEditPhysicalDimUOMDataSource(FormDataSource _formDataSource)
    {
        if (_formDataSource.cursor() is WHSPhysDimUOM)
        {
            WHSPhysDimUOM physDimUOM = _formDataSource.cursor();
            _formDataSource.allowEdit(!physDimUOM.isUnitSameAsItemInventoryUnit());
        }
        else
        {
            throw error(Error::wrongUseOfFunction(funcName()));
        }
    }



write the code in the table  :


    /// <summary>
    /// Checks if the unit is the same as the item's inventory unit, if the item is set.
    /// </summary>
    /// <returns>true, if the unit is the same as the item's inventory unit and the item is set; otherwise false.</returns>
    public boolean isUnitSameAsItemInventoryUnit()
    {
        return (this.ItemId
                && this.UOM == InventTableModule::find(this.ItemId, ModuleInventPurchSales::Invent).UnitId);
    }

No comments:

Post a Comment

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...