16 Ekim 2015 Cuma

AXAPTA - Pack-unpack at forms

ClassDeclaration method:

    Container   packedQuery;
    SysQueryRun qRun;
    s
tr dummy;
    #DEFINE.CurrentVersion(1)
    #LOCALMACRO.CurrentList
        dummy,
        packedQuery
    #ENDMACRO


Other methods:

container pack()
{
    ;
    dummy      = txtDummy.valuestr();
    return [#CurrentVersion,#CurrentList];
}


public boolean unpack(container _packedClass)
{
    int version = conPeek(_packedClass,1);

    switch (version)
   {
        case #CurrentVersion:
            [version,#CurrentList] = _packedClass;
            break;
        default:
            return false;
    }
    return true;
}


public void init()
{
    ;
    xSysLastValue::getLast(this);
    super();
    txtDummy(dummy);
    element.initQuery();
}


public void close()
{
    super();
    xSysLastValue::saveLast(this);
}


void initParmDefault()
{
}


private IdentifierName lastValueDesignName()
{
    return '';
}


private IdentifierName lastValueElementName()
{
    return this.name();
}


private UtilElementType lastValueType()
{
    return UtilElementType::Form;
}


private UserId lastValueUserId()
{
    return curuserid();
}


public dataAreaId lastValueDataAreaId()
{
    return curExt();
}


This method is not mandatory, but you may write like this if you would like to use query:


void initQuery()
{
  Query                q;
  QueryBuildDataSource qbds;
  QueryBuildDataSource qbds2;
  QueryBuildRange      qRange;
  ;
  if (packedQuery)
      qRun = new SysQueryRun(packedQuery);
  else
  {
      q = new query();
      qbds = q.addDataSource(tablenum(EmplTable));
      qRun = new SysQueryRun(q);
  }
  qRun.promptLoadLastUsedQuery(false);
}


This one is for select button of query, so of course not mandatory too:

 void clicked()
{
    ;
    super();
    if (qRun.prompt())
        packedQuery = qRun.pack();
}

12 Ekim 2015 Pazartesi

AXAPTA - Add right click menu popup to form control

You can do this with overwrite control's showContextMenu method:

public int showContextMenu(int _menuHandle)
{
    int                 ret;
    int                bar1,bar2;
    PopupMenu           pMenu = PopupMenu::create(_menuHandle,element.hWnd());
    ;
        bar1 = pMenu.insertItem("Selection 1");
        bar2 = pMenu.insertItem("Selection 2");

    ret = pMenu.draw();
    switch (ret)
    {
    case -1 :
        break;
    case bar1:

...
    case bar2:
...
    default :
        break;
    }
    return ret;

}

8 Ekim 2015 Perşembe

Axapta - Send and receive dataset

I took this code part from Fatih Demirci's developments.

Send dataset:
 

    System.Data.DataTable               dataTable;
    System.Data.DataColumnCollection    dataTableColumns;
    System.Data.DataRowCollection       DataRowCollection;
    System.Data.DataRow                 tmpRow;
    System.Data.DataSet dataset = new System.Data.DataSet();
    System.Data.DataTableCollection     dataTableCollection;


    dataTable = new System.Data.DataTable();
    dataTableColumns = dataTable.get_Columns();

//Describe lines
    dataTableColumns.Add("ACCOUNTNO", System.Type::GetType("System.String"));
    dataTableColumns.Add("ITEMNO", System.Type::GetType("System.String"));
    dataTableColumns.Add("TOACCOUNTNUM", System.Type::GetType("System.String"));
    dataTableColumns.Add("RETURNREASONIDD", System.Type::GetType("System.String"));
    dataTableColumns.Add("QUANTITY", System.Type::GetType("System.Double"));
    dataTableColumns.Add("DESCRIPTION", System.Type::GetType("System.String"));
//bir satır al
    DataRowCollection = dataTable.get_Rows();
        tmpRow = dataTable.NewRow();
//fill lines
    tmpRow.set_Item("ACCOUNTNO","MU_014600");
    tmpRow.set_Item("ITEMNO","200.05.01.0306");
    tmpRow.set_Item("TOACCOUNTNUM","MU_014600");
    tmpRow.set_Item("RETURNREASONIDD","");
    tmpRow.set_Item("QUANTITY",11);
    tmpRow.set_Item("DESCRIPTION","");

    DataRowCollection.Add(tmpRow);

     dataTable.AcceptChanges();
//At this time if opposite side needs data table, it's ready

//In the other case if wants dataset, tie to dataset
     dataTableCollection     = dataSet.get_Tables();
     dataTableCollection.Add(datatable);
//now dataset ready too


Receive dataset:

    System.Data.DataTable               dataTable;
    System.Data.DataTableCollection     dataTableCollection;
    System.Data.DataColumnCollection    dataColumnCollection;
    System.Data.DataRowCollection       dataRowCollection;
    System.Data.DataRow                 dataRow;
    System.Data.DataColumn              dataColumn;
    System.Data.DataTable               returnData;
;


        dataTableCollection     = dataSet.get_Tables();
        totalTable              = dataTableCollection.get_Count();
        for(i = 0; i < totalTable; i ++)
        {
            dataTable               = dataTableCollection.get_Item(i);
            dataColumnCollection    = dataTable.get_Columns();
            DataRowCollection       = dataTable.get_Rows();
            totalRow                = dataRowCollection.get_Count();
            totalCol                = dataColumnCollection.get_Count();
            for( j = 0; j < totalRow; j ++)
            {
                dataRow         = dataRowCollection.get_Item(j);
                custAccount     = dataRow.get_Item("ACCOUNTNO");
                itemId          = dataRow.get_Item("ITEMNO");
                toCustAccount   = dataRow.get_Item("TOACCOUNTNUM");
                strtext         = dataRow.get_Item("RETURNREASONIDD");
                krc_DefectiveId = str2int64(strtext);
                strtext         = dataRow.get_Item("QUANTITY");
                _b2bdesc        = dataRow.get_Item("DESCRIPTION");
...