WorkCalendarSched workCalendarSched;
date dateOnlyWorking, dateAll;
workCalendarSched = new workCalendarSched();
dateOnlyWorking =
workCalendarSched.schedDate( SchedDirection::Backward, today(), 6, NoYes::Yes, "5x24" );
dateAll =
workCalendarSched.schedDate( SchedDirection::Backward, today(), 6, NoYes::No, "5x24" );
info( date2str( dateOnlyWorking, 321, DateDay::Digits2, DateSeparator::Hyphen,
DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4 ) );
info( date2str( dateAll, 321, DateDay::Digits2, DateSeparator::Hyphen,
DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4 ) );
Output: Microsoft AX 2012, X++, C#, SQL server, SSRS, Java, JavaFX, Oracle, PL/SQL, Delphi - codes examples, step-by-step tutorials, experiences.
Thursday, July 26, 2018
AX - How calculate only with opened days in calendar
Use WorkCalendarSched class:
Wednesday, July 25, 2018
SSRS - How use labels from AX in SSRS report
1) Click right mouse button on the field, select "Expression..".
2) Use "Labels!" prefix and then the number of AX label:
2) Use "Labels!" prefix and then the number of AX label:
Tuesday, July 3, 2018
POWERSHELL - How write colored text output
write-host 'This is with red backgroud' -BackgroundColor Red write-host '..and this is with yellow foretext' -ForegroundColor YellowOutput:
Monday, July 2, 2018
AX - How to run AX from command line with another language
..here it run it in Russian language:
"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe" -language=ru
Sunday, July 1, 2018
AX - How to use "display" method in forms datasource
This is useful if you need find some value in form. Parameter is source type for DataSource.
public display ItemNameDisplay ItemName( vm_data_detail _vm_data_detail )
{
return ProdTable::find( _vm_data_detail.ProdId ).ItemName;
}
Friday, June 29, 2018
SSRS - How add to TextBox HTML formatting support
When you need use HTML formatting in TextBox item:
1) Select text (not only click on item, you must select it).
2) Right mouse click, properties (placeholder).
3) On General page set formatting to HTML. Now you can use base HTML tags in source string.
1) Select text (not only click on item, you must select it).
2) Right mouse click, properties (placeholder).
3) On General page set formatting to HTML. Now you can use base HTML tags in source string.
SSRS - How return substring only to first occurrence of specified char
When field ItemId contains for example value "ABC-156032_0_0000" and you want only first part of this string to first occurrence of "_" char, use this code for expression:
=Mid( First( Fields!ItemId.Value, "ProdRouteCardDS" ), 1, InStr( First(Fields!ItemId.Value, "ProdRouteCardDS" ), "_" ) - 1 )Output will be:
ABC-156032
Wednesday, June 27, 2018
AX - How to split path to file - to path, filename and extension
static void test_job(Args _args)
{
Filename filepath;
Filename filename;
Filename filetype;
/* get info */
[ filepath, filename, filetype ] = Global::fileNameSplit( "c:\\temp\\readme.txt" );
/* show result */
info( filepath );
info( filename );
info( fileType );
}
Output:Friday, June 22, 2018
POWERSHELL - How to solve "import-module : the specified module 'activedirectory' was not loaded because no valid module file was found in any module directory." error
When you get for this powershell command,
The command get for you access to AD powershell functions.
Import-Module ActiveDirectorythis error:
import-module : the specified module 'activedirectory' was not loaded because no valid module file was found in any module directory., you have to install "Active Directory Management Gateway Service" at first, and then run command again.
The command get for you access to AD powershell functions.
SQL SERVER - How to solve problem "OLE DB error: OLE DB or ODBC error: Login failed for user" on BI cubes processing
This error occurs, when user (here NT SERVICE\MSOLAP$TSTINST) have not access to source DB.
Solution: Add to user db_datareader rights.
Solution: Add to user db_datareader rights.
Tuesday, June 19, 2018
AX - How to solve Error "This installation package could not be opened" (Visual Studio Tools)
This error can occur in installation "Visual Studio Tools" for AX 2012.
When you have VS 2013 (Professional and higher), installation is supported only from CU8.
-> check, if you have CU8 subdir in upgrade directory (in install AX 2012 R3 directory).
When you have VS 2013 (Professional and higher), installation is supported only from CU8.
-> check, if you have CU8 subdir in upgrade directory (in install AX 2012 R3 directory).
DELPHI - How to work with TDirectory (generic)
TDictionary is collection of key-value. In this example is it used for saving previous values - and its refreshing.
procedure TSQLParams.LoadForSQL( _iSQL_ID : integer ); var i : integer; b : boolean; vValue : variant; pParam : TSQLParam; pSQLParam : TSQLParam; pOldValues : TDictionary < string, variant >; begin pOldValues := TDictionary < string, variant >.Create; try { -- save old values of params } for i := 0 to self.Count - 1 do begin pParam := TSQLParam( Items[ i ] ); if not VarIsNull( pParam.vValue ) then pOldValues.Add( pParam.sIdent, pParam.vValue ); end; { -- clear all } clear; { - get info } if DB_SP.sp_params_by_sql_id.Active then DB_SP.sp__params_by_sql_id.Close; DB_SP.sp_params_by_sql_id.ParamByName( '@sql_id' ).AsInteger := _iSQL_ID; DB_SP.sp_sql_detail_params_by_sql_id.Open; DB_SP.sp_params_by_sql_id.First; while not DB_SP.sp_params_by_sql_id.Eof do begin { create new param } pSQLParam := TSQLParam( self.Add ); pSQLParam.sIdent := DB_SP.sp_params_by_sql_id.FieldByName( 'ident' ).AsString.ToLower; pSQLParam.vValue := Variants.null; { - try to find old saved value } b := pOldValues.TryGetValue( pSQLParam.sIdent, vValue ); if b then pSQLParam.vValue := vValue; { - next row } DB_SP.sp_params_by_sql_id.Next; end; finally pOldValues.Free; end; end;
Monday, June 18, 2018
Monday, June 11, 2018
DELPHI - How to split string with TStringList class support
For string split you can use class TStringList.
var
i : integer;
sResult : string;
pSplit : TStringList;
begin
pSplit := TStringList.Create;
try
{ define delimiter }
pSplit.Delimiter := ';';
{ - split it }
pSplit.Clear;
pSplit.DelimitedText := 'This;is;a;list';
{ - list it }
sResult := '';
for i := 0 to pSplit.Count - 1 do
begin
sResult := sResult + pSplit[i] + #13;
end;
ShowMessage( sResult );
finally
pSplit.Free;
end;
Output: Friday, June 1, 2018
POWERSHELL - Send output to file (with appending)
This example send first output to bothdirs.txt; second line with ">>" appends second output to end of file.
dir c:\tmp > c:\tmp\bothdirs.txt; dir C:\Intel >> c:\tmp\bothdirs.txt; notepad c:\tmp\bothdirs.txt;Output:
Directory: C:\tmp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 24. 5. 2018 11:05 png
-a--- 1. 6. 2018 10:50 0 bothdirs.txt
-a--- 31. 5. 2018 13:54 8304 export.txt
Directory: C:\Intel
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 14. 7. 2017 15:44 ExtremeGraphics
d---- 23. 5. 2018 12:47 gp
d---- 14. 7. 2017 15:41 Logs
Friday, May 4, 2018
DELPHI - How ensure (system) path delimiter to end of file path
One of the good technique to ensure, that file path is ended with system delimiter.
var
sMask : string;
begin
..
sMask := IncludeTrailingPathDelimiter( ExtractFilePath( Application.ExeName ) ) +
'*' + '.txt';
Output (should be): c:\dir\*.txt
Thursday, April 19, 2018
DELPHI - How check if OLE library is installed on client
When you use some special OLE object, you can check, if is installed on client (Winapi.ActiveX):
var classID: TCLSID; sOLEObject: string; bIsSupport : boolean; begin { is installed ? } sOLEObject := 'Microsoft.DirectMusic.1'; bIsSupport := CLSIDFromProgID( PWideChar( WideString( sOLEObject ) ), classID ) = S_OK; if bIsSupport then ShowMessage( 'Supported.' ); ...
AX - How to work with advanced filters (..with sql where condition)
When you need some special filters, especially in relation to another field(s) from table, you can write directly sql where code.
This example shows all production orders, where difference between Delivery date and End date is 10 days:
This example shows all production orders, where difference between Delivery date and End date is 10 days:
Wednesday, April 18, 2018
SQL SERVER - How and why use "N" prefix for unicode strings
N prefix before string takes string as unicode (without N is string converted to DB codepage). It is useful for some special chars in some alphabets.
select 'Počty vzrůstajících kusů' as description
union all
select N'Počty vzrůstajících kusů'
Output: description ------------------------ Pocty vzrustajících kusu Počty vzrůstajících kusů (2 row(s) affected)
Tuesday, April 17, 2018
DELPHI - How to create new directory (..and check if directory exists)
var sBackupPath : string; begin ... sBackupPath := gsExePath + gcsDictionarySubDir; { check if not exists } if not DirectoryExists( sBackupPath ) then begin { try to create new directory } b := ForceDirectories( sBackupPath ); if not b then begin ShowMessage( 'Backup directory cannot be created.' ); exit; end; end; ...
Thursday, April 12, 2018
DELPHI - How to make tray icon with WIN API support only (without TTrayIcon)
trayIconData : TNotifyIconData; ... { add icon } with TrayIconData do begin cbSize := sizeOf( trayIconData ); Wnd := Handle; uID := 0; uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP; uCallbackMessage := WM_ICONTRAY; hIcon := Application.Icon.Handle; StrPCopy( szTip, self.Caption ); end; Shell_NotifyIcon( NIM_ADD, @TrayIconData );And callback procedure:
procedure TFMain.WMIconTray( var msg : TMessage ); var pt : TPoint; begin case msg.lParam of { popup menu } WM_RBUTTONDOWN: begin GetCursorPos( pt ); PopupTray.Popup( pt.x, pt.y ); end; { doubleclick } WM_LBUTTONDBLCLK : begin MPopup_NextClick( nil ); end; { mouse over } WM_MOUSEMOVE : begin self.Caption := gcsTitle + GetNextWordTime; with TrayIconData do begin StrPCopy( szTip, self.Caption ); uFlags := NIF_TIP; Shell_NotifyIcon( NIM_MODIFY, @TrayIconData ); end; end; end; end;And removing after destroy:
procedure TFMain.FormDestroy(Sender: TObject);
begin
...
Shell_NotifyIcon( NIM_DELETE, @trayIconData );
end;
Output:Wednesday, April 11, 2018
AX - How to round values
Second parameter from round() function define how will be rounded.
real iValue = 15.5678532;
real iResult1, iResult2;
// round to 0.1
iResult1 = round( iValue, 0.1 );
// round to all number */
iResult2 = round( iValue, 1 );
info( num2str( iResult1, 15, 2, 1, 0 ) + " - " + num2str( iResult2, 15, 2, 1, 0 ) );
Output: 15.60 - 16.00
DELPHI - How to make rotation of shape around point
Suppose this easy class for shape - triangle:
TShape = class( TObject ) p1 : TPoint; p2 : TPoint; p3 : TPoint; procedure Moving( _iDeltaX, _iDeltaY : integer ); procedure Rotation( _iAngle : integer ); procedure RotationAroundXY( _x, _y : integer; _iAngle : integer ); end;And initialization:
pShape := TShape.Create; pShape.p1.X := 300; pShape.p1.Y := 250; pShape.p2.X := 250; pShape.p2.Y := 280; pShape.p3.X := 350; pShape.p3.Y := 330;For rotation shape around point use this code:
procedure TShape.RotationAroundXY( _x, _y : integer; _iAngle : integer ); var iNewX, iNewY : integer; dCos, dSin : double; dRadian : double; p1x, p1y, p2x, p2y, p3x, p3y : integer; begin { -- angle } dRadian := ( 2 * pi ) / ( 360 / _iAngle ); dCos := cos( dRadian ); dSin := sin( dRadian ); { -- point for rotation around (in other case the rotation is around start of coords) } p1x := p1.x - _x; p1y := p1.y - _y; p2x := p2.x - _x; p2y := p2.y - _y; p3x := p3.x - _x; p3y := p3.y - _y; { -- calculation of the positions } iNewX := round( ( p1x * dCos ) - ( p1y * dSin ) ); iNewY := round( ( p1y * dCos ) + ( p1x * dSin ) ); p1.X := iNewX + _x; p1.Y := iNewY + _y; iNewX := round( ( p2x * dCos ) - ( p2y * dSin ) ); iNewY := round( ( p2y * dCos ) + ( p2x * dSin ) ); p2.X := iNewX + _x; p2.Y := iNewY + _y; iNewX := round( ( p3x * dCos ) - ( p3y * dSin ) ); iNewY := round( ( p3y * dCos ) + ( p3x * dSin ) ); p3.X := iNewX + _x; p3.Y := iNewY + _y; end;Output:
Tuesday, April 3, 2018
JAVA, JAVAFX - listener and lambda expression
Since JDK 1.8 you can use lambda expression. This article compares old and new variants on one example with CheckBox listener.
Old variant (response for change in CheckBox):
Both variant have same result:
Old variant (response for change in CheckBox):
@FXML CheckBox checkbox1;
@FXML Label label1;
@Override
public void initialize( URL url, ResourceBundle rb ) {
/* variant without lambda expression */
checkbox1.selectedProperty().addListener( new ChangeListener< boolean >() {
@Override
public void changed( ObservableValue observable, Boolean oldValue, Boolean newValue ) {
label1.setText( newValue.toString() );
}
} );
/* -- init */
checkbox1.selectedProperty().set( true );
}
And new (optional - old variant is still working) with lambda expression:@FXML CheckBox checkbox1;
@FXML Label label1;
@Override
public void initialize( URL url, ResourceBundle rb ) {
/* variant with lambda expression */
checkbox1.selectedProperty().addListener(
( ObservableValue observable, Boolean oldValue, Boolean newValue ) -> {
label1.setText( newValue.toString() );
}
);
/* -- init */
checkbox1.selectedProperty().set( true );
}
Both variant have same result:
SSRS - How disable fitting chart axis (..to more columns)
Sometimes SSRS chart left axis is fitted to more columns.
For solving that, set left axis property LabelsAutoFitDisabled to true.
For solving that, set left axis property LabelsAutoFitDisabled to true.
Subscribe to:
Posts (Atom)














