Monday, November 27, 2017

DELPHI - How copy file

First parameter is source file, second parameter is target location.
_sFileName : string
..
copyfile( PChar( _sFileName ), PChar( IncludeTrailingPathDelimiter( EPath.Text ) + 
          ExtractFileName( _sFileName ) ), false );

SSRS - How define expression for background color

In BackgroundColor property set expression:
= IIF(Fields!COUNT_DELAY.Value > 0, "Red", "SeaGreen")

AX - Error "An error occurred rendering the report. Accessing the report server URL caused an error. The remote server returned an error: (500) Internal Server Error."

This error inform you that connection between AX and SSRS was lost.















The solution should be:
  1. Stop AOS.
  2. Restart SSRS Reporting Service.
  3. Start AOS.

AX - How generate datetime with to 23:59:59 PM

Use this code (1 hour = 3600 seconds):

utcDateTime dDate = DateTimeUtil::newDateTime( today(),  3600 * 24 - 1 );
    
info( datetime2str( dDate ) );


AX - How add (next) row to StringEdit control

Used for example for logs.
  1. Add StringEdit control to form.
  2. Set name and set Autodeclaration to Yes.
  3. Set Multiline to Yes.
void AddText( str _sValue ) {
  EOutput.text( EOutput.text() + _sValue + num2char(10) );
}

AX - How pass table (datasource) as param to form

In menu item on caller form you must define DataSource property:







This ProdTable will be passed as parameter to called (here) form.

In called form you override init() method:

FormRun callerForm;
FormDataSource callerDataSource;
...
public void init()
{
    super();

    if ( element.args() && element.args().caller() )
    {
        callerForm = element.args().caller();

        if ( callerForm && callerForm.dataSource() ) {

            /* -- save DataSource */

            callerDataSource = callerForm.dataSource();

            /* -- call check method */

            this.check();
        }

    }
}

Sunday, November 26, 2017

JAVA - How to go through an array

Several method:

Variant 1

String[] array = new String[3];

array[0] = "One";
array[1] = "Two";
array[2] = "Three";

for ( int i = 0; i < array.length; i++ )
  System.out.println( array[i] );
Output is:
One 
Two 
Three 
Variant 2

String[] array = new String[3];

array[0] = "One";
array[1] = "Two";
array[2] = "Three";

for ( String item : array )
  System.out.println( item );

NOTE: Every next loop is into item variable filled next array item.

Saturday, November 25, 2017

DELPHI - How to generate file with record based type

When you need save some complex record type to file you can use this code:

{ header of admin file }
TRecFileAdmin = record
  sIdent              : string[15] ;
  dDateTo             : TDateTime;
end;
...
{ ---------------------------------------------------------------------------
  Function generate admin file into _FileName file.
  -------------------------------------------------------------------------- }
function GenerateAdminFile( _sFileName : string ) : boolean;
var
  f : TFile;
  recFileAdmin : TRecFileAdmin;
begin
  result := false;

  try
    try
      { every time establish new }
      f := TFile.Create( _sFileName, true );

      { three day validity }
      FillChar( recFileAdmin, sizeof( recFileAdmin ), 0 );
      recFileAdmin.sIdent  := gcsIdent;
      recFileAdmin.dDateTo := Now + 3;  
      f.FileWrite( recFileAdmin, sizeof( recFileAdmin ) );
    except
      on E : exception do
        begin
          doError( ERROR_SAVE, [ 'A9Admin.GenerateAdmin()', E.Message ] );
          exit;
        end;
    end;
  finally
    f.free;
  end;

  result := true;
end;

DELPHI - How get total physical memory and memory in use

LPhysMem: TLabel;
LMemoryInUse: TLabel;
MS : TMemoryStatus;
...
GlobalMemoryStatus( MS );
LPhysMem.Caption := FormatFloat( '#,###" KB"', MS.dwTotalPhys / 1024 );
LMemoryInUse.Caption := Format( '%d %%', [ MS.dwMemoryLoad ] );

It shows for example:



Friday, November 24, 2017

JAVAFX - How to play (youtube) video

/* control on form for media video */
private MediaView mediaView;
..
MediaPlayer mediaPlayer = new MediaPlayer( 
  new Media( "https://www.youtube.com/watch?v=gvKgvW9ujHo" ) );
MediaView.setMediaPlayer( mediaPlayer );            
MediaView.getMediaPlayer().play();

JAVAFX - How get Stage from control

From control you can get Stage; here used for form closing:
@FXML Button btnClose;

@FXML private void btnCloseAction( ActionEvent event ) {
  Stage stage = (Stage) btnClose.getScene().getWindow();    
  stage.close();    
}

Thursday, November 23, 2017

JAVA - How to quickly list (all) array elements

For quickly list array elements use class java.util.Arrays. This class contains static methods for work with arrays.
String[] array = new String[3];

array[0] = "One";
array[1] = "Two";
array[2] = "Three";

System.out.println( Arrays.toString( array ) );
The output is:
[One, Two, Three]

JAVA - How to copy array values between arrays

For copy array values between two arrays use System.arraycopy():
String[] array = new String[3];  

array[0] = "One"; 
array[1] = "Two"; 
array[2] = "Three"; 

String[] array1 = { "1", "2", "3" };

System.arraycopy( array1, 1, array, 0, 2 );

for ( int i = 0; i < array.length; i++ ) System.out.println( array[i] ); 
In this example are copied values of array1 (first param) from index 1 (second param) into array (third param). First value is inserted into 0 index (fourth param), copied are two (fifth param) items.

The output is:
2 3 Three

ORACLE - How get info about table

desc himtbw

Result (⇒information about himtbw table):

SQLWKS> desc himtbw
Column Name                    Null?    Type
------------------------------ -------- ----
TL_NR                          NOT NULL VARCHAR2(20)
TL_FAM                         NOT NULL VARCHAR2(6)
TL_ATN                         NOT NULL VARCHAR2(6)
BEW_MNG_MZ                              NUMBER(10,3)
BEW_MNG_ME                              VARCHAR2(2)
LAG_ORT                                 VARCHAR2(16)
LAG_REIHE                               VARCHAR2(2)
...

AX - How get list of active AX users

select a.id, a.name, substring( a.networkdomain, 1, 25 ) as networkdomain,
substring( a.networkalias, 1, 25 ) as networkalias
from [dbinst].[dbo].userinfo a
where
a.enable = 1
order by a.id

AX - How get aggregate select value - max(), count()

For aggregate x++ select functions you can use this form:
calcDate = ( select maxof( calcdate ) from ProdParmBomCalc 
where ProdParmBOMCalc.ProdId == source.TransRefId ).calcdate;
Supported aggregate functions: sum, avg, minof , maxof, count.

For count function you can use this code:
int iCount;

iCount =
  ( select count(recId) from prodRoute
    where
    prodRoute.ProdId == source.ProdId &&
    prodRoute.OprPriority == RouteOprPriority::Primary 
  ).recId;
        
if ( iCount != 0 ) {
  bError = true;            
}

AX - How set number sequence generation to manual

When you don`t want automatically generate number sequence, you can set it to manual (= manual inserting).
  • In area setup part select preferences dialog and find number sequence. Click View details for it.
  • In sequence set generation type to Manual.

AX - How call form with param

Calling form with passing parameter - here it is one passed value (ProdId type):
void Check()
{
  Args args;

  FormRun formRun;

  /* -- call check form */

  args = new args();

  if ( jmgJobTable )
    args.parm( JmgJobTable.ModuleRefId );
  else
    args.parm( "" );

  ags.name( formstr( CheckBus ) );
  formRun = classFactory.formRunClass( args );
  formRun.init();
  formrun.run();
  formrun.wait();
}
..and here is receiving part - in form init() method:
public void init()
{
  ProdId prodId;

  super();

  if( element.args() )
  {
    /* -- get param value */

    prodId = element.args().parm();     
    EProdId.text( prodId );
    EOutput.text( "" );

    EProdId.setFocus();
  }
}

Wednesday, November 22, 2017

JAVA - How to sort array elements

For sorting array elements use class java.util.Arrays. This class contains static methods for working with arrays.
String[] array = { "One", "Two", "Three", "Four", "Fight" };

Arrays.sort( array );

System.out.println( Arrays.toString( array ) );
The output is:
[Fight, Four, One, Three, Two] 
NOTE: This is the most simplest variant of array sorting.

JAVA - How to create array

Exists several ways for creating java array.

Variant 1

/* creating */ 

String[] array = new String[3];

/* initialization */ 

array[0] = "One"; 
array[1] = "Two"; 
array[2] = "Three";

Variant 2

String[] array = { "one", "two", "three" };

NOTE: Arrays are indexed from zero [0]. When you use non-existed index is raised java.lang.ArrayIndexOutOfBoundsException exception.

AX - How check if current user is SysAdmin

This code check, if current AX user is in System Administrator group:
if ( isSystemAdministrator() ) { ... }

AX - How check if (current) user is in group

AX 2012 define user groups (System administration\User groups):



if ( UserInfoHelp::userInUserGroup( curUserId(), 'PLANNING' ) ) { ... }

AX - How get enum labels to db table

When you have AX enum, often you need to read its labels externally - for example in SQL question.

In AX exists table SRSAnalysisEnums, which contain enum name, enum value and its label.
select * from SRSAnalysisEnums
where
enumname = 'NoYes' and
languageid in ( 'de', 'en-us' )
Output:
ENUMITEMVALUE ENUMITEMLABEL LANGUAGEID ENUMNAME ENUMITEMNAME RECVERSION RECID

0 Nein de NoYes No 1 5637179205
0 No en-us NoYes No 1 5637144576 1
Ja de NoYes Yes 1 5637179250 1 
Yes en-us NoYes Yes 1 5637144577
For rebuild this table (->new enum in AX) you can use class BIGenerator, method populateSRSAnalysisEnums(). Implicitly are generated enums from tables in AX BI perspectives.
static void cieb_updateSSRSEnums(Args _args)
{
    BIGenerator::populateSRSAnalysisEnums();
    info( "OK" );
}
Explicitly you can change in inner method addFrameworkEnumsToDictEnumSet(), where you can define some others special enums for SRSAnalysisEnums table:
void addFrameworkEnumsToDictEnumSet()
{
    addEnumToDictEnumSet(new DictEnum(enumNum(boolean)));
    addEnumToDictEnumSet(new DictEnum(enumNum(NoYes)));
    addEnumToDictEnumSet(new DictEnum(enumNum(AutoNoYes)));

    /* -- added - start */
    addEnumToDictEnumSet( new DictEnum( enumNum( cieb_technology_sale_type_enum ) ) );
    addEnumToDictEnumSet( new DictEnum( enumNum( cieb_technology_type_enum ) ) );
    addEnumToDictEnumSet( new DictEnum( enumNum( cieb_technology_type1_enum ) ) );
    /* -- added - end */

    addEdtEnumToDictEnumSet(new DictType(extendedTypeNum(BIIsNotApplicable)));
}

AX - Where are defined languages for BI generation

When you regenerate BI table SRSAnalysisEnums, languages for regeneration are defined in table BIUdmTranslations:
select * from BIUdmTranslations
where
generate = 1
Output:
LANGUAGEID GENERATE    RECVERSION  RECID
---------- ----------- ----------- --------------------
cs         1           1963884511  5637144578
en-us      1           2063432002  5637144591

2 row(s) affected)

Tuesday, November 21, 2017