Programming
You are currently browsing the articles from KomKid.Net matching the category Programming.
วิธีส่งข้อมูลที่มีการ enter (vbNewLine) ไปให้ Formulas ของ Crystal Report ทำได้โดย ใส่เครื่องหมาย chr(34) (qoute) คร่อม chr(10) (Line Feed) ไปอีกที ดังนี้
1
| CrysRpt.Formulas(0) = "FormulaName=" & Chr(34) & Replace$(txtName.Text, vbNewLine, Chr(34) & " & Chr(10) & " & Chr(34)) & Chr(34) |
ถ้าข้อมูล คือ
บรรทัดที่ 1
บรรทัดที่ 2
พอใช้คำสั่งแล้ว ข้อมูลที่จะส่งไปก็จะเป็น
FormulaName=”บรรทัดที่ 1″ & Chr(10) & “บรรทัดที่ 2″
Written by Komkid on October 19th, 2009 with no comments.
Read more articles on Programming.
วิธีสร้าง dialog แบบที่มี control ซึ่ง lookup ได้ เช่น เลือก SalesId แล้วให้อีก control นึง คือ ItemId lookup มาเฉพาะของ SalesId นั้น

ทำได้ดังนี้
1.declare control ไว้ ตาม extended data type ที่จะใช้
1 2 3 4
| class LookupDialog extends RunBase
{
FormStringControl SalesIdCtrl, ItemIdCtrl;
} |
2.สร้าง dialog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| protected Object dialog(Dialog dialog, boolean forceOnClient)
{
DialogRunBase ret;
;
ret = super(dialog, forceOnClient);
ret.caption('Costing report by order');
SalesIdCtrl = ret.formBuildDesign().addControl(FormControlType::String,'SalesId');
SalesIdCtrl.extendedDataType(extendedTypeNum('SalesId'));
ItemIdCtrl = ret.formBuildDesign().addControl(FormControlType::String,'ItemId');
ItemIdCtrl.extendedDataType(extendedTypeNum('ItemId'));
return ret;
} |
3.Set ให้ control สามารถ override method ตอน runtime ได้
1 2 3 4 5 6 7 8 9
| public void dialogPostRun(DialogRunbase dialog)
{
;
super(dialog);
dialog.dialogForm().formRun().controlMethodOverload(true);
dialog.dialogForm().formRun().controlMethodOverloadObject(this);
SalesIdCtrl = dialog.dialogForm().formRun().design().controlName('SalesId');
ItemIdCtrl = dialog.dialogForm().formRun().design().controlName('ItemId');
} |
4.สร้าง lookup method
1 2 3 4 5 6 7 8 9 10 11 12
| void ItemId_lookup()
{
Query query = new Query();
SysTableLookup sysTableLookup =
SysTableLookup::newParameters(tableNum(SalesLine), SalesIdCtrl);
;
sysTableLookup.addLookupField(fieldNum(SalesLine, ItemId));
sysTableLookup.addLookupField(fieldNum(SalesLine, Name));
query.addDataSource(tableNum(SalesLine)).addRange(fieldNum(SalesLine,SalesId)).value(SalesIdCtrl.text());
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
} |
5.เก็บรายละเอียด method อื่น ๆ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public container pack()
{
return conNull();
}
public boolean unpack(container packedClass)
{
return true;
}
static void main(Args _args)
{
LookupDialog test1 = new LookupDialog();
;
if (test1.prompt())
{
test1.run();
}
} |
ที่มา :
Written by Komkid on October 15th, 2009 with no comments.
Read more articles on Axapta and Programming.
การส่งข้อมูลจาก Axapta ไปให้ OpenOffice อีกวิธีก็คือ ใช้ API ที่ OpenOffice เตรียมไว้ให้ บวกกับคุณสมบัติด้าน COM ของ Axapta
ลักษณะโดยทั่วไปของโปรแกรมประเภท Spread Sheet ก็คือ
- 1 Document มีได้หลาย Sheets
- 1 Sheet มีได้หลาย Ranges หลาย Cells
- 1 Ranges สามารถประกอบได้จาก หลาย Cells
- 1 Cell ใส่ข้อมูลได้ 1 ชุด
ตามคู่มือของ OpenOffice ก็นำมาเขียนโดยใช้ X++ ได้ดังนี้
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| static void ooTest(Args _args)
{
COM OpenOffice;
COM oDeskTop;
COM oDocument;
COM oSheets;
COM oSheet;
COM oRange;
COM BorderStruct;
COMVariant arg;
COMVariant byte;
Array arr = new Array(Types::String);
str url;
int i;
;
OpenOffice = new Com("com.sun.star.ServiceManager");
oDeskTop = OpenOffice.CreateInstance("com.sun.star.frame.Desktop");
// create and initialize a COMVariant object
arg = COMVariant::createFromArray(arr);
//Create new document
oDocument = oDeskTop.LoadComponentFromURL("private:factory/scalc", "_blank", 0, arg);
oSheets = oDocument.getSheets(); //object นี้รับ sheet ทั้งหมด
oSheet = oSheets.getByIndex(0); // object นี้รับ sheet แรกมาเพื่อใช้ทำงาน
BorderStruct = OpenOffice.Bridge_GetStruct('com.sun.star.table.BorderLine');
BorderStruct.Color(24567057);
BorderStruct.LineDistance(0);
BorderStruct.InnerLineWidth(0);
BorderStruct.OuterLineWidth(1);
oRange = oSheet.getCellRangeByName("H2:I2");
oRange.merge(true); //รวม Cells
oRange.setPropertyValue("CellBackColor", 16764057); // format cell
oRange.SetPropertyValue("LeftBorder",BorderStruct);
oRange.SetPropertyValue("RightBorder",BorderStruct);
oRange.SetPropertyValue("TopBorder",BorderStruct);
oRange.SetPropertyValue("BottomBorder",BorderStruct);
//*****************************
for(i=1; i<10;i++)
{
oRange = oSheet.getCellByPosition(0,i);
oRange.SetValue(i);
oRange.setPropertyValue("CellStyle", "Result");
oRange = oSheet.getCellByPosition(1,i);
oRange.Setstring('????????');
oRange.setPropertyValue('CharPosture',100);
oRange = oSheet.getCellByPosition(2,i);
oRange.SetValue(i*i);
oRange.setPropertyValue('CharWeight',200);
oRange.setPropertyValue('CharUnderline',124);
oRange = oSheet.getCellByPosition(3,i);
oRange.SetString(date2str(today(),123,2,2,2,2,4));
oRange.setPropertyValue("CharColor", 500);
oRange.setPropertyValue('CharShadowed', True);
oRange = oSheet.getCellByPosition(4,i);
oRange.SetString(today());
oRange.setPropertyValue("CellBackColor", 0x99CCFF);
oRange.setPropertyValue("CharHeight", 12);
oRange.setPropertyValue("IsTextWrapped", True);
oRange = oSheet.getCellByPosition(5,i);
oRange.SetString(today());
oRange.setPropertyValue("CellStyle", "Date");
}
} |
ลองเล่นดูนะครับ ลองหลายแบบ ๆ ตามคู่มือได้เลย (ตัวอย่างผมได้มาจาก web เป็นภาษารัสเซียครับ http://axforum.info/forums/showthread.php?t=18722&highlight=openoffice)
Written by Komkid on August 13th, 2009 with no comments.
Read more articles on Axapta and OpenOffice and Programming.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| SysExcelApplication SysExcelApplication;
SysExcelWorksheet SysExcelWorksheet;
SysExcelWorksheets SysExcelWorksheets;
SysExcelWorkbooks SysExcelWorkbooks;
SysExcelWorkbook SysExcelWorkbook;
SysExcelRange SysExcelRange;
SysExcelCell SysExcelCell;
SysExcelCells SysExcelCells;
COMVariant COMVariant1;
#excel
// ข้างบนนี้ คือการ กำหนดตัวแปรกับ macro
;
sysExcelApplication = SysExcelApplication::construct();
sysExcelApplication.visible(false); //set ไม่ให้มัน show ตั้งแต่แรก
sysExcelWorkbooks = sysExcelApplication.workbooks();
COMVariant1 = new COMVariant();
COMVariant1.bStr('\\\\Axaptaserver\\AxaptaSP4\\Excel\\Losses.xls');
sysExcelWorkbook = sysExcelWorkbooks.add(COMVariant1); // สั่งให้เปิดไฟล์ที่กำหนดตามบรรทัดข้างบน
SysExcelWorksheets = sysExcelWorkbook.worksheets();
SysExcelWorksheet = SysExcelWorksheets.itemFromNum(1); // เลือกทำงานกับ Sheet ที่ 1
// SysExcelRange = SysExcelWorksheet.cells().range(#ExcelTotalRange);
SysExcelCell = SysExcelWorksheet.cells().item(1,1); // กำหนด cell ที่จะอ่านหรือเขียน
SysExcelCell.value(strfmt("Losses of %1 from %2 to %3",fromDate,toDate)); // เขียนข้อความลงไปใน cell ที่กำหนดเมื่อกี้ |
Written by Komkid on August 13th, 2009 with no comments.
Read more articles on Axapta and Programming.
วิธีการนี้ต้องใช้ตัวช่วยคือ OOCALCVB.dll
1.Download DLL OOCALCVB.dll ไปไว้ในเครื่อง ปกติก็คือที่ C:\Windows\System32\
2.ใน Axapta เลือกเมนู Tools > Development tools > Wizards > COM Class Wrapper Wizard

3.คลิก Next แล้วก็ Brows หาไฟล์ในข้อ 1 แล้วก็คลิก Next
4.ป้อน oo ตรงช่อง Element Mask เพื่อเอาไว้สังเกต Classes ที่จะได้ แล้วคลิก Next จะได้รายการของ Class ที่เกิดจาก OOCALCVB.dll

5.คลิก Next แล้วรอจนเสร็จ ก็คลิก Finish
6.เปิดดู AOT จะเห็นว่ามี Class ใหม่เกิดขึ้นมาดังรูป

ต่อไปก็ลองเขียน X++ ติดต่อดู ดังตัวอย่าง
1 2 3 4 5 6 7 8 9 10
| ooCalc ooCalc;
#ooCOMDEF
;
ooCalc = new ooCalc();
ooCalc.Workbooks().OpenFile("\\\\Axaptaserver\\AxaptaSP4\\Excel\\Losses.xls",false,"",false);
ooCalc.ActiveWorkbook().ActiveSheet().Cells().Item("A1").Value(66);
// ooCalc.ActiveWorkbook().ActiveSheet().Cells().Item("A1").SetString(strfmt("Losses of %1 from %2 to %3",fromDate,toDate)); //SetString อันนี้ใช้ไม่ได้
ooCalc.ActiveWorkbook().ActiveSheet().Cells().Item("A1").Formula(strfmt("Losses of %1 from %2 to %3",fromDate,toDate)); //SetString ไม่ได้ ใช้ Formula แทนไปก่อน |
Written by Komkid on August 13th, 2009 with no comments.
Read more articles on Axapta and OpenOffice and Programming.