static void JobDownloadFromURL(Args _args)
{
Url url;
int iHandle;
WinInet winInet;
Filename filename;
TextBuffer textBuffer;
;
winInet = new WinInet();
textBuffer = new TextBuffer();
filename = "c:\\temp\\valuta_dag.sdv";
url =
"http://www.norges-bank.no/webdav/stat/no/valutakurser/valuta_dag.sdv";
iHandle = winInet.internetOpenUrl(url);
if (iHandle == 0)
{
error(strfmt("Error open: %1", url));
return;
}
textBuffer.appendText(winInet.internetReadFile(iHandle));
winInet.internetCloseHandle(iHandle);
textBuffer.toFile(filename);
info(strfmt("Lines: %1", textBuffer.numLines()));
}
Wednesday, December 10, 2008
Thursday, May 15, 2008
Spell checking from AX
The AX class SysSpellChecker is a wrapper for the spellchecker of Word. Using this class you can offer spellchecking from AX.
Here is some sample code, checking text from a form string control:
SysSpellChecker spellChecker = SysSpellChecker::newCurrentLanguage();
TextBuffer textBuffer = new TextBuffer();
int wordStart;
int startSeparator;
int endSeparator;
str wordToCheck;
List spellingSuggestions;
ListEnumerator listEnumerator;
;
super();
startLengthyOperation();
setPrefix("Spell check");
textBuffer.setText(stringEdit.text());
startSeparator = 1;
while (startSeparator)
{
wordStart = textBuffer.find('[^ \n\t\\<\\>\\!\\\'\\\\\\#\\¤\\%\\&\\/\\(\\)\\=\\?\\,\\.\\:\\;\\*\\}\\{\\]', startSeparator) ? textBuffer.matchPos():0;
if (!wordStart)
break;
endSeparator = textBuffer.find('[ \n\t\\<\\>\\!\\\'\\\\\\#\\¤\\%\\&\\/\\(\\)\\=\\?\\,\\.\\:\\;\\*\\}\\{\\]', wordStart)? textBuffer.matchPos():0;
wordToCheck = textBuffer.subStr(wordStart, (endseparator ? endseparator : textBuffer.size()+1) - wordStart);
if (spellChecker.checkSpelling(wordToCheck) == false)
{
warning (strfmt("@SYS84009", wordToCheck));
spellingSuggestions = spellChecker.getSpellingSuggestions(wordToCheck);
listEnumerator = spellingSuggestions.getEnumerator();
while (listEnumerator.moveNext())
{
info (strFmt("Suggestion: %1", listEnumerator.current()));
}
}
startSeparator = endSeparator;
}
spellChecker.finalize();
info ("Spell check done");
endLengthyOperation();
Unfortunately there is a bug in the checkSpelling method of the COM object from Word, so it will always use the default language of your Office setup as the language to check your text against. So you can't spellcheck for other languages than your default language of Office. You can change the default language from the Office Tools however.
Here is some sample code, checking text from a form string control:
SysSpellChecker spellChecker = SysSpellChecker::newCurrentLanguage();
TextBuffer textBuffer = new TextBuffer();
int wordStart;
int startSeparator;
int endSeparator;
str wordToCheck;
List spellingSuggestions;
ListEnumerator listEnumerator;
;
super();
startLengthyOperation();
setPrefix("Spell check");
textBuffer.setText(stringEdit.text());
startSeparator = 1;
while (startSeparator)
{
wordStart = textBuffer.find('[^ \n\t\\<\\>\\!\\\'\\\\\\#\\¤\\%\\&\\/\\(\\)\\=\\?\\,\\.\\:\\;\\*\\}\\{\\]', startSeparator) ? textBuffer.matchPos():0;
if (!wordStart)
break;
endSeparator = textBuffer.find('[ \n\t\\<\\>\\!\\\'\\\\\\#\\¤\\%\\&\\/\\(\\)\\=\\?\\,\\.\\:\\;\\*\\}\\{\\]', wordStart)? textBuffer.matchPos():0;
wordToCheck = textBuffer.subStr(wordStart, (endseparator ? endseparator : textBuffer.size()+1) - wordStart);
if (spellChecker.checkSpelling(wordToCheck) == false)
{
warning (strfmt("@SYS84009", wordToCheck));
spellingSuggestions = spellChecker.getSpellingSuggestions(wordToCheck);
listEnumerator = spellingSuggestions.getEnumerator();
while (listEnumerator.moveNext())
{
info (strFmt("Suggestion: %1", listEnumerator.current()));
}
}
startSeparator = endSeparator;
}
spellChecker.finalize();
info ("Spell check done");
endLengthyOperation();
Unfortunately there is a bug in the checkSpelling method of the COM object from Word, so it will always use the default language of your Office setup as the language to check your text against. So you can't spellcheck for other languages than your default language of Office. You can change the default language from the Office Tools however.
Monday, January 21, 2008
How to get the PC Name and IP
static void JobGetServerInfo(Args _args)
{
xSession curXS;
int i;
str GetIP(str Hostname)
{
DLL DLL = new DLL("ws2_32.dll");
DLL DLL2 = new DLL("kernel32");
DLLFunction CopyMemory = new DLLFunction(Dll2, "RtlMoveMemory");
DLLFunction HostInfo = new DLLFunction(DLL, "gethostbyname");
binary Dest = new binary(100);
int Host;
str IP;
HostInfo.arg(ExtTypes::String);
HostInfo.returns(ExtTypes::DWord);
Host = HostInfo.call(Hostname);
CopyMemory.arg(ExtTypes::Pointer,
ExtTypes::DWord,
ExtTypes::DWord);
if(Host)
{
CopyMemory.call(Dest, Host, 16);
if(Dest.dWord(12))
{
CopyMemory.call(Dest, Dest.dWord(12), 4);
if(Dest.dWord(0))
{
CopyMemory.call(Dest, Dest.dWord(0), 4);
IP = int2str(Dest.byte(0)) + "." +
int2str(Dest.byte(1)) + "." +
int2str(Dest.byte(2)) + "." +
int2str(Dest.byte(3));
}
}
}
return IP;
}
;
for(i = 1; i <= Info::licensedUsersTotal(); i++)
{
curXS = new xSession(i, true);
if(curXS && curXS.sessionId() &&
curXS.clientKind() == ClientType::Client && curXS.userId())
{
info( "PC Name:"+curXS.clientComputerName() + ", IP:"+getIP( curXS.clientComputerName())); //pause;
}
}
}
{
xSession curXS;
int i;
str GetIP(str Hostname)
{
DLL DLL = new DLL("ws2_32.dll");
DLL DLL2 = new DLL("kernel32");
DLLFunction CopyMemory = new DLLFunction(Dll2, "RtlMoveMemory");
DLLFunction HostInfo = new DLLFunction(DLL, "gethostbyname");
binary Dest = new binary(100);
int Host;
str IP;
HostInfo.arg(ExtTypes::String);
HostInfo.returns(ExtTypes::DWord);
Host = HostInfo.call(Hostname);
CopyMemory.arg(ExtTypes::Pointer,
ExtTypes::DWord,
ExtTypes::DWord);
if(Host)
{
CopyMemory.call(Dest, Host, 16);
if(Dest.dWord(12))
{
CopyMemory.call(Dest, Dest.dWord(12), 4);
if(Dest.dWord(0))
{
CopyMemory.call(Dest, Dest.dWord(0), 4);
IP = int2str(Dest.byte(0)) + "." +
int2str(Dest.byte(1)) + "." +
int2str(Dest.byte(2)) + "." +
int2str(Dest.byte(3));
}
}
}
return IP;
}
;
for(i = 1; i <= Info::licensedUsersTotal(); i++)
{
curXS = new xSession(i, true);
if(curXS && curXS.sessionId() &&
curXS.clientKind() == ClientType::Client && curXS.userId())
{
info( "PC Name:"+curXS.clientComputerName() + ", IP:"+getIP( curXS.clientComputerName())); //pause;
}
}
}
Tuesday, September 18, 2007
How to Run Time Add Code to AOT
static str 60 addValidateCode(FormName formname, TableId refTableId, FieldId
refFieldId)
{
#AOT
TreeNode treeNode;
TreeNode methodsTreeNode;
str oldsource;
str newsource;
str superString = "super()";
str busRuleString;
str newMethodName;
str newMethodCode;
;
treeNode = TreeNode::findNode(#FormsPath + "\\" + formName);
treeNode = treeNode.AOTfindChild("Data Sources");
treeNode = treeNode.AOTfindChild(tableId2Name(refTableId));
if(refFieldId)
{
newMethodName = "validate";
newMethodCode = "public boolean validate()\n{\n boolean ret;\n
;\n ret = super() && PABusInessRules::CheckRules(element, this," +
strfmt(' %1',refFieldId) + ");\n\n return ret;\n}\n";
//bus rule string is different if applied to a fieldId
busRuleString = "super() && PABusInessRules::CheckRules(element,
this," + strfmt(' %1)',refFieldId);
treeNode = treeNode.AOTfindChild("fields");
treeNode = treeNode.AOTfindChild(fieldId2Name(refTableId,RefFieldId));
}
else
{
newMethodName = "validateWrite";
newMethodCode = "public boolean validateWrite()\n{\n boolean
ret;\n ;\n ret = super() && PABusInessRules::CheckRules(element,
this);\n\n return ret;\n}\n";
busRuleString = "super() && PABusinessRules::CheckRules(element,
this)";
}
methodsTreeNode = treeNode.AOTfindChild("Methods");
treeNode = methodsTreeNode.AOTfindChild(newMethodName);
if(!treeNode)
{
methodsTreeNode.AOTadd(newMethodName);
methodsTreeNode.AOTsave();
treeNode = methodsTreeNode.AOTfindChild(newMethodName);
newSource = newMethodCode;
treeNode.AOTsetSource(newsource,false);
}
else
{
oldsource = treeNode.AOTgetSource();
// check if rule already applied
if(strscan(oldSource,busRuleString,1,strlen(oldSource)) == 0)
{
newSource = strReplace(oldsource,superString,busRuleString);
//new line to be inserted
treeNode.AOTsetSource(newsource);
}
}
TreeNode = TreeNode::findNode(#FormsPath + "\\" + formName);
treeNode.AOTcompile();
treeNode.AOTsave();
return busRuleString;
}
refFieldId)
{
#AOT
TreeNode treeNode;
TreeNode methodsTreeNode;
str oldsource;
str newsource;
str superString = "super()";
str busRuleString;
str newMethodName;
str newMethodCode;
;
treeNode = TreeNode::findNode(#FormsPath + "\\" + formName);
treeNode = treeNode.AOTfindChild("Data Sources");
treeNode = treeNode.AOTfindChild(tableId2Name(refTableId));
if(refFieldId)
{
newMethodName = "validate";
newMethodCode = "public boolean validate()\n{\n boolean ret;\n
;\n ret = super() && PABusInessRules::CheckRules(element, this," +
strfmt(' %1',refFieldId) + ");\n\n return ret;\n}\n";
//bus rule string is different if applied to a fieldId
busRuleString = "super() && PABusInessRules::CheckRules(element,
this," + strfmt(' %1)',refFieldId);
treeNode = treeNode.AOTfindChild("fields");
treeNode = treeNode.AOTfindChild(fieldId2Name(refTableId,RefFieldId));
}
else
{
newMethodName = "validateWrite";
newMethodCode = "public boolean validateWrite()\n{\n boolean
ret;\n ;\n ret = super() && PABusInessRules::CheckRules(element,
this);\n\n return ret;\n}\n";
busRuleString = "super() && PABusinessRules::CheckRules(element,
this)";
}
methodsTreeNode = treeNode.AOTfindChild("Methods");
treeNode = methodsTreeNode.AOTfindChild(newMethodName);
if(!treeNode)
{
methodsTreeNode.AOTadd(newMethodName);
methodsTreeNode.AOTsave();
treeNode = methodsTreeNode.AOTfindChild(newMethodName);
newSource = newMethodCode;
treeNode.AOTsetSource(newsource,false);
}
else
{
oldsource = treeNode.AOTgetSource();
// check if rule already applied
if(strscan(oldSource,busRuleString,1,strlen(oldSource)) == 0)
{
newSource = strReplace(oldsource,superString,busRuleString);
//new line to be inserted
treeNode.AOTsetSource(newsource);
}
}
TreeNode = TreeNode::findNode(#FormsPath + "\\" + formName);
treeNode.AOTcompile();
treeNode.AOTsave();
return busRuleString;
}
Tuesday, August 7, 2007
Encryption and Decryption in AX
Encryption and Decryption in Axapta
TextBuffer textBuffer = new TextBuffer();
;
textBuffer.setText(_text);
textBuffer.encrypt(987654123); // Basic encryption
To decrypt the string again, use the following code:
TextBuffer textBuffer = new TextBuffer();
;
textBuffer.setText(_text);
textBuffer.decrypt(987654123);
decryptedString = textBuffer.getText();
TextBuffer textBuffer = new TextBuffer();
;
textBuffer.setText(_text);
textBuffer.encrypt(987654123); // Basic encryption
To decrypt the string again, use the following code:
TextBuffer textBuffer = new TextBuffer();
;
textBuffer.setText(_text);
textBuffer.decrypt(987654123);
decryptedString = textBuffer.getText();
Monday, July 16, 2007
valueEmptyString
If you want to query the empty (“ ”) value in queryBuildRange, you have to use valueEmptyString.
myOdrTrkQBR1.value(myOrdTracking.avOrderStatus ? myOrdTracking.avOrderStatus : sysQuery::valueEmptyString());
myOdrTrkQBR1.value(myOrdTracking.avOrderStatus ? myOrdTracking.avOrderStatus : sysQuery::valueEmptyString());
Set Control and Keyborad Enter
Set Control and Keyborad Enter
public int task(int _taskId)
{
int ret;
#Task
switch (_taskId)
{
case #taskEnter :
{
if(element.selectedControl().name() == NumReceipt.name())
{
MenuItemButton.clicked();
return 0;
}
return super(_taskId);
}
default :
return super(_taskId);
}
}
public int task(int _taskId)
{
int ret;
#Task
switch (_taskId)
{
case #taskEnter :
{
if(element.selectedControl().name() == NumReceipt.name())
{
MenuItemButton.clicked();
return 0;
}
return super(_taskId);
}
default :
return super(_taskId);
}
}
Subscribe to:
Posts (Atom)