Thursday, May 27, 2010

create comma seperated file.

Use CommaIO file to create comma separated records or create CSV file.

create an instance of CommaIO and provide the operating mode.

These are the following modes, you can find it in FILE Macro under io_write.
'R' - Read
'W' - Write
'A' - Append
'T' - Translate
'B' - Binary

You need to assign the value of inrecorddelimeter.
and then use write method to write it. Multiple arguments can be passed in the write method of CommaIO.
CommaIO commaIO;
CustTable custTable;

//File name with the operating mode append.
commaIO = new CommaIO(@"C:\Cust.txt", 'A');
commaIO.inRecordDelimiter('\n');


while select CustTable
{
commaIO.write(custTable.AccountNum,custTable.AccountStatement, custTable.CashDisc);
}
Find the sample here.

read text file in axapta

TextBuffer is used to read the whole text file. Load file using textBuffer.fromFile and fetch the whole file string from the .getText

TextBuffer textBuffer;

textBuffer = new TextBuffer();
textBuffer.fromFile(@"C:\sohail.txt");
print textBuffer.getText();
pause;

Find the sample here.

create text file in axapta


Use BinData class to create a simple text file using axapta.
Firstly create an instance of a TextBuffer class and append text using textBuffer.AppendText. Pass it to binData what you want to write using binData.setStrData and then write using binData.saveFile.

Sample

BinData binData;
TextBuffer textBuffer;

textBuffer = new TextBuffer();
textBuffer.setText('This is a demo program');

binData = new BinData();
binData.setStrData(textBuffer.getText());
binData.saveFile(@"c:\sohail.txt");

Demo is attached here.

Saturday, December 26, 2009

Folder creation and deletion, POPUp Window C#

Folder can be created in C# by
Directory.CreateDirectory("C:\TmpFolder");

This line will create TmpFolder in C drive.

Folder can be deleted in a same way by
Directory.DeleteDirectory("C:\TmpFolder");

This line will delete TmpFolder from C drive.

Folders can be retrieve from a specific location
Directory.GetDirectories, it returns in a string array format.

Logical drives can be retrived by the method
Environment.GetLogicalDrives, it returns all the logical drives in a string array format.

Environment.username returns the name of the user who logged in the application.

POPUp Window
___________

PopUp window is nothing, it is just the movement of height & set the location in the starting of a form.

You just need to know screen resolution by Screen.PrimaryScreen.
set the width and height of the form and its size. drop a timer and on the interval event decrease the height of the popupWindow...

Don't forget to mention ShowInTaskbar = false, ControlBox=false on form level...

An small application is created that create and delete folder and shows a pop-up window on the folder creation and deletion event.

You can download code from here

Thursday, December 24, 2009

Display caching mechanism

What is display method?

display method is a calculated value that may be calculated via different table fields and classes and on the basis of calculation display method returns a value, it may be used on report and forms.

Disadvantage:
when a display method is called on a form, usually its calling is very frequent to get the calculated value.

Solution:
display caching mechanism provides the way to reduce the calling of its function or call whenever it is necessary...
In the display caching mechanism it is necessary that the method should be on the table level.
In the init method of data source (where the method is written on the table level) on form, display method should be added there by using init datasource.cacheAddMethod & then method name.
for example. emp_ds.cacheAddMethod(methodstr(Emp,displayJobDescription))
emp_ds is datasource and displayJobDescription is the display method.

if we want to call it explicitly on the basis of some modifications of other fields, datasource_cacheCalculatedMethod is used.

a sample code can be downloaded from here.

Tuesday, December 22, 2009

how to create project and add AOT objects and groups in it.

can we create project by code and can add the AOT objects in the project & can we add groups?

Yes, we can do it easily. Find the attached xpo.

You can download a simple job from here