Tuesday, December 19, 2017

JAVAFX - How add support for CSS to your application

Three main ways:

1) For every Scene instance you can add support for css:
Scene scene = new Scene( root );
scene.getStylesheets().add( getClass().getResource( "style.css" ).toExternalForm() );

2) For every control item you can call setStyle() method:
button.setStyle( "-fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 );");



3) In .fxml editor (scene builder) in menu Preview:

Monday, December 18, 2017

AX - Missing button "View details" on form

When on form is missing button "View details",



















the reason could be in IgnoreEDTRelation=Yes on table field. Set this property to value No.







Now is all OK, button is visible:



DELPHI - Yes/No dialog

Easy yes/no dialog:
if MessageDlg( 'Already delete ?', mtConfirmation, [ mbYes, mbNo ], 0 ) = mrNo then exit;
Output:

DELPHI - How show base info dialog

This is an easiest way how to show info dialog in Delphi:
ShowMessage( 'This is an info dialog.' );
Output:







Another variant is advanced version, where you can specify type, buttons and help context:
MessageDlg( 'This is an info dialog.', mtInformation, [ mbOk ], 0 );

Sunday, December 17, 2017

JAVAFX - How to use Platform.runLater()

@Override
public void initialize( URL url, ResourceBundle rb ) {
                    
  Platform.runLater( new Runnable() {
    @Override
    public void run() {
        
      prepare();                
 
    }   
  } );
    
}  

Friday, December 15, 2017

AX - errror by SSRS report run: "Error while setting server report parameters. Error message: Failed to load expression host assembly. Details: Could not load file or assembly 'InventTableOverviewReport.BusinessLogic, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. (rsErrorLoadingExprHostAssembly)"

Solutions:

  • Not installed "AX reporting services extensions" on SQL side.
  • Try again re-deploy all SSRS reports.

AX - error "The AOS server name or instance name is not correctly configured" by installing Reporting Services Extensions

SSRS reporting services extension you must install on SQL side.

This error code is probably caused by missing WCF configuration.
  1. Run "Microsoft Dynamics AX 2012 configuration".
  2. For local and bussiness connection import right configuration and then press "Refresh configuration" button. This action refresh WCF configuration.
  3. Do it for SQL and AOS servers.

Thursday, December 14, 2017

DELPHI - How get default decimal separator

var
  DefaultLCID: LCID;
  sDefaultDecimalSeparator : string;
begin
  ...
  { read default decimal separator }
  DefaultLCID := GetThreadLocale;
  try
    sDefaultDecimalSeparator := trim( GetLocaleChar( DefaultLCID, LOCALE_SDECIMAL, '.' ) );
  except
    sDefaultDecimalSeparator := '.';
  end;

DELPHI - How change file extension

var
  sFileName : string;
begin
  ...
  sFileName := 'c:\temp\file.txt';
  ShowMessage( sFileName + #13 + changeFileExt( sFileName, '.exe' ) );
Output:

DELPHI - How set active printer to color/monochrome

When is parameter TRUE -> set active printer to color.
function SetPrinterColor( _b : boolean ) : boolean;
var
  buffer1 : array[0..250] of char;
  buffer2 : array[0..250] of char;
  buffer3 : array[0..250] of char;
  ADevice, ADriver, APort : pchar;
  hDm : THandle;
  pdm : PDEVMODE;
begin
  ADevice := buffer1;
  ADriver := buffer2;
  APort   := buffer3;

  { get active printer }

  Printer.GetPrinter( ADevice, ADriver, APort, hDm );

  { make change }

  Pdm := globalLock ( hDm );
  if _b then
    pdm^.dmColor := DMCOLOR_COLOR
  else
    pdm^.dmColor := DMCOLOR_MONOCHROME;
  globalUnlock(hDm);

  { set value }

  Printer.SetPrinter( ADevice, ADriver, APort, hDm );

  result := true;
end;

DELPHI - How get computer name

function My_GetComputerName : string;
var
  buffer : array[ 0..255 ] of char;
  i      : dword;
begin
  fillChar( buffer, sizeof( buffer ), #0 );
  i := sizeof( buffer );
  GetComputerName( @buffer, i );
  result := strPas( Buffer );
end;
When you call it:
ShowMessage( My_GetComputerName );
Output could be:

Wednesday, December 13, 2017

JAVAFX - How show base info dialog (Alert class)

Since java version 8u40 is available javafx.scene.control.Alert for easy info/warning/error dialog.

1) Base form:
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
...
Alert alert = new Alert( AlertType.INFORMATION, "This is alert." );
alert.showAndWait();










2) You can specify button (or more buttons):
alert = new Alert( AlertType.INFORMATION, "This is alert.\n\nSecond line.", 
                   new ButtonType( "Close it" ) );
alert.showAndWait();












3) Or you can specify dialog title and remove header text:
Alert alert = new Alert( AlertType.INFORMATION );
alert.setTitle( "Info" );
alert.setHeaderText( null );
alert.setContentText( "This is alert.\n\nSecond line." );
alert.showAndWait();


DELPHI - How get username of connected user

function My_GetUserName : string;
var
  buffer : array[ 0..255 ] of char;
  i      : dword;
begin
  fillChar( buffer, sizeof( buffer ), #0 );
  i := sizeof( buffer );
  getUserName( @buffer, i );
  result := strPas( buffer );
end;
When you call it:
ShowMessage( My_GetUserName );
Output could be:

ORACLE - How get name of connected DB instance

select sys_context( 'USERENV','DB_NAME' ) as instance from dual;
Output (for example):
INSTANCE                                                                        
--------------------------------------------------------------------------------
ORCL                                                                            
1 row selected.

SQL SERVER - How convert date/datetime to string

You can use convert() function with last parameter which tells how to convert.
select convert( varchar(10), getdate() ) union
select convert( varchar(10), getdate(), 101 ) union
select convert( varchar(10), getdate(), 102 ) union
select convert( nvarchar(10), getdate(), 103 ) union
select convert( varchar(10), getdate(), 104 ) union
select convert( nvarchar(10), getdate(), 105 ) 
Output:
----------
12/13/2017
13.12.2017
13/12/2017
13-12-2017
2017.12.13
Dec 13 201

(6 row(s) affected)

Tuesday, December 12, 2017

AX - How validate ComboBox value (validate() method)

With validate() method you can define check(s) for control on form (return FALSE when is something wrong).
When combobox is bound to Enun, use this form:
public boolean validate()
{
  boolean ret;

  ret = super();

  /* do check */
    
  if ( JmgFeedbackStatus.selection() == JmgFeedbackStatus::Completed ) {
    ret = false;
    warning( "@SYS316081" );
    //throw Global::error( "The parameter value is invalid." );
  }    

  return ret;
}
When combobox is bound to DataSource, you can add validate() directly to datasource field:
public boolean validate()
{
  boolean ret;

  ret = super();

  /* do check */
    
  if ( JmgTmpJobBundleProdFeedback.ReportAsFinished == JmgFeedbackStatus::Completed ) {
    ret = false;
    warning( "@SYS316081" );
    //throw Global::error( "The parameter value is invalid." );
  }  

  return ret;
}

ORACLE - How connect to DB

Typical form is: username/password@db_instance
connect scott/tiger@orcl
When is db_instance set in registry, you can use directly only username and password:
connect scott/tiger
When connection is OK:
SQLWKS> connect scoot/tiger@orcl
ORA-01017: invalid username/password; logon denied
SQLWKS> connect scott/tiger@orcl
Connected.

SQL SERVER - How get info about SQL server

When you need some base settings about SQL server, call sp_server_info stored procedure:
exec sp_server_info
Output:
attribute_id attribute_name attribute_value
1 DBMS_NAME Microsoft SQL Server
2 DBMS_VER Microsoft SQL Server 2014 - 12.0.5000.0
10 OWNER_TERM owner
11 TABLE_TERM table
12 MAX_OWNER_NAME_LENGTH 128
13 TABLE_LENGTH 128
14 MAX_QUAL_LENGTH 128
15 COLUMN_LENGTH 128
16 IDENTIFIER_CASE MIXED
17 TX_ISOLATION 2
18 COLLATION_SEQ charset=iso_1 sort_order=nocase_iso charset_num=1 sort_order_num=52
19 SAVEPOINT_SUPPORT Y
20 MULTI_RESULT_SETS Y
22 ACCESSIBLE_TABLES Y
100 USERID_LENGTH 128
101 QUALIFIER_TERM database
102 NAMED_TRANSACTIONS Y
103 SPROC_AS_LANGUAGE Y
104 ACCESSIBLE_SPROC Y
105 MAX_INDEX_COLS 16
106 RENAME_TABLE Y
107 RENAME_COLUMN Y
108 DROP_COLUMN Y
109 INCREASE_COLUMN_LENGTH Y
110 DDL_IN_TRANSACTION Y
111 DESCENDING_INDEXES Y
112 SP_RENAME Y
113 REMOTE_SPROC Y
500 SYS_SPROC_VERSION 12.00.5000

Monday, December 11, 2017

JAVAFX - How select file (FileChooser)

Typical open file dialog:
/* - select file */

FileChooser fileChooser = new FileChooser();
fileChooser.setTitle( "Select image.." );
    
/* - get saved directory - or get user`s home dir */

File pDir = new File( app.pSetup.getData().sLastPath );
if ( ! ( pDir.exists() && pDir.isDirectory() ) ) {      
  pDir = new File( System.getProperty( "user.home" ) );      
}  
 fileChooser.setInitialDirectory( pDir );
    
/* - set filters */
    
fileChooser.getExtensionFilters().addAll(
  new FileChooser.ExtensionFilter( "All Images", "*.*" ),
  new FileChooser.ExtensionFilter( "JPG", "*.jpg" ),
  new FileChooser.ExtensionFilter( "PNG", "*.png" ),
  new FileChooser.ExtensionFilter( "BMP", "*.bmp" )
);
    
/* - open dialog */
    
File pfile = fileChooser.showOpenDialog( scrollPane.getScene().getWindow() );

/* - draw image */
    
if ( pfile != null )
{      
      
  /* -- read image */
      
  Image image = new Image( pfile.toURI().toURL().toExternalForm() );
  ...
}
Output:

SQL SERVER - How get difference between dates (here in days)

Here is example difference between two dates in days (first parameter), but you can use for example hour or month, etc.
select salesid, linenum, itemid, qtyordered, createddatetime, confirmeddlv, 
datediff( day, createddatetime, confirmeddlv ) as diffdays 
from salesline
where
confirmeddlv > '2017/12/01' and
datediff( day, createddatetime, confirmeddlv )  <= 7
Output:
salesid              createddatetime         confirmeddlv            diffdays
-------------------- ----------------------- ----------------------- -----------
PO171475             2017-12-08 10:51:45.000 2017-12-10 00:00:00.000 2
PO171475             2017-12-08 10:52:03.000 2017-12-10 00:00:00.000 2
PO171675             2017-11-27 19:58:26.000 2017-12-04 00:00:00.000 7
...

ORACLE - How make cursor and how go through its rows

With Oracle cursor you can read table data by SQL.
is
  /* person`s list */

  cursor c_persons is
    select a.id, a.email
    from factory.an_users a
    where
    nvl( a.active, 'N' ) = 'A'
    ;

  pc_persons c_persons%rowtype;

  sEmail varchar2( 4000 );
begin
  ...
  sEmail := '';
  
  /* open cursor */ 
  open c_persons;
  loop

    /* read every rows of the cursor */
    fetch c_persons into pc_persons;
    exit when c_persons%notfound;

    /* -- action with row data.. */
    if pc_persons.email is not null then
      sEmail := sEmail || pc_persons.email || ';';
    end if;
    
  end loop;
  close c_persons;
  ...
end;

SQL SERVER - How check if database exists

Use this script code:
use master;

/* -- define DB name */

declare @database_name nvarchar( max );  
set @database_name = 'framework'; 

/* -- check if DB exists yet */

if db_id( @database_name ) is not null
begin
  print 'DB exists.';
  /* db exists -> end */
  return;
end;
...

Sunday, December 10, 2017

DELPHI - How check if file exists

var
  sPath : string;
begin
  ...
  if not FileExists( sPath ) then
    begin
      MessageDlg( Format( 'File "%s" not found.', [sPath] ), mtError, [mbOk], 0 );
      exit;
    end;
  ...
end;

JAVAFX - How get Controller after form load

When you want to call some method on loaded form, you need at first controller:
public class App extends Application {
    
  @Override
  public void start( Stage stage ) throws Exception {
        
    /* load form FXMLMain */
    
    FXMLLoader fLoader = new FXMLLoader( getClass().getResource( "FXMLMain.fxml" ) );
    Parent root = fLoader.load();

    /* ..get its controller..and call some method */

    FXMLMain controller = fLoader.getController();
    controller.prepare( this );
    ...
  }

Saturday, December 9, 2017

JAVA - How to convert String to time

For conversion use SimpleDateFormat class where you can specify date mask.
import java.text.*;
...
/* - value for conversion */
    
String s = "13:52:10";
    
/* - specify format mask */
   
DateFormat df = new SimpleDateFormat( "H:m:s" );
    
try {
  /* - try to convert */
      
  Date d = df.parse( s );              
      
  /* - print result */
      
  System.out.println( df.format( d ) );

  /* - print time hour part (in 24-format) */

  Calendar c = df.getCalendar();
  c.setTime( d );

  System.out.println( c.get( Calendar.HOUR_OF_DAY ) );
} 
catch ( ParseException ex ) {}
Output:
13:52:10
13