Programming
You are currently browsing the articles from KomKid.Net matching the category Programming.
การรับตัวแปรเพิ่มเข้าไปเป็นเงื่อนไขในส่วนของ SQL เช่น รับค่าจาก Dialog แล้วเอามาเติม Wildcard ก่อนที่จะ query
หากใช้ตัวแปรที่เป็น str ธรรมดาจะมี error message
“Container and unbound string (text) fields are not allowed here in a WHERE expression”
แก้ไขได้โดย กำหนดขนาดของ string ให้แน่นอน หรือประกาศเป็น extended datatype ไปเลย
เช่น
1 2 3 4 5 6 7 8 9
| WrkCtrIdBase tmpStr;
str 10 tmpStr2;
;
tmpStr = strfmt("%1%2",wrkCtrIdBase,"-LA*");
SELECT SUM(Amount) FROM prodRouteTrans WHERE prodRouteTrans.CategoryId LIKE tmpStr;
tmpStr2 = strfmt("%1%2",wrkCtrIdBase,"-LB*");
SELECT SUM(Amount) FROM prodRouteTrans WHERE prodRouteTrans.CategoryId LIKE tmpStr2; |
Written by Komkid on August 13th, 2009 with no comments.
Read more articles on Axapta and Programming.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| function checkID(id) {
//ตรวจว่าป้อนถูกตามรูปแบบที่กำหนดมั้ย x-xxxx-xxxxx-xx-x
var regExpObj = /^\d{1}\-\d{1,4}\-\d{1,5}\-\d{1,2}\-\d{1}$/;
if (regExpObj.test(id) == false) return false;
//ตัด - เอาแต่เลขมาตรวจ
id = id.replace(/-/g,"");
//ตรวจว่ามี 13 หลักถูกมั้ย
if (id.length!=13) return false;
//เลขนำหน้าของมีได้แค่ 1-8
if( id.charAt(0) < 1 || id.charAt(0) > 8 ) return false;
//คำนวณหลักสุดท้าย
for(i=0,sum=0;i<12;i++)
sum += parseInt(id.charAt(i))*(13-i);
sum = sum%11;
if(sum <= 1)
sum = 1-sum;
else
sum = 11-sum;
return (sum == parseInt(id.charAt(12)));
} |
ข้อมูลจาก http://th.wikipedia.org/wiki/เลขประจำตัวประชาชนไทย
Written by Komkid on August 5th, 2009 with 1 comment.
Read more articles on JavaScript and Programming.
แก้ startupPost method ใน Info class ดังนี้
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
| void startupPost()
{
int counter;
int num = 0;
int maxSessions = Info::licensedUsersTotal();
xSession session;
UserInfo userInfo;
UserId currentUserId;
;
currentUserId = curuserid();
for(counter = 1; counter < maxSessions;counter++ )
{
session = new xSession(counter, true);
if(session && session.userId())
{
select firstOnly userInfo
where userInfo.id == session.userId();
if (userInfo && (currentUserId == session.userId()))
{
num++ ;
}
}
}
if (num > 1)
{
if(box::yesno("The same user id can't log in twice. Do you want to log in anyway? ",
DialogButton::Yes, "Log in", "Log out") == DialogButton::No)
{
infolog.shutDown(true);
}
}
} |
Written by Komkid on August 5th, 2009 with no comments.
Read more articles on Axapta and Programming.
การ Refresh หรือ Update Data ใน grid ทำได้โดยเรียกใช้ method ของ datasource
ทำได้สองวิธี คือ
1.ใช้
วิธีนี้จะเป็นการ query ใหม่ ทำให้เสีย focus ไปจาก record เดิม แต่ข้อมูล update ทันที
2. ใช้
วิธีนี้จะเป็นการอ่านขึ้นมา record เดียวคือ record ที่เลือกอยู่ แต่จะไม่เห็นผลทันที ต้องเปลี่ยน record จึงจะเห็นผล
3.ใช้
1 2 3
| xxx_ds.relead();
xxx_ds.research();
xxx_ds.findRecord(); |
เพื่อให้ record ที่ filter ไว้ยังคงอยู่ ดังตัวอย่าง
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
| void clicked()
{
PurchLine tmpPurchLine;
PurchLine updatePurchLine;
PurchLine selectedRecord;
Dialog dl;
DialogField dlfTransdate;
;
dl = new Dialog("Change confirmed date");
dlfTransdate = dl.addFieldValue(typeid("Transdate"),today(),"Confirmed date");
if(dl.run()){
selectedRecord = PurchLine_ds.cursor();
for (tmpPurchLine = PurchLine_ds.getFirst(true) ? PurchLine_ds.getFirst(true) : PurchLine_ds.cursor();
tmpPurchLine; tmpPurchLine = PurchLine_ds.getnext())
{
ttsbegin;
SELECT FORUPDATE updatePurchLine
WHERE updatePurchLine.PurchId == tmpPurchLine.PurchId
&& updatePurchLine.VendAccount == tmpPurchLine.VendAccount
&& updatePurchLine.LineNum == tmpPurchLine.LineNum
&& updatePurchLine.ItemId == tmpPurchLine.ItemId;
updatePurchLine.ConfirmedDlv = dlfTransdate.value();
updatePurchLine.update();
ttscommit;
}
PurchLine_ds.reread();
PurchLine_ds.research();
PurchLine_ds.findRecord(selectedRecord);
}
super();
} |
Written by Komkid on August 5th, 2009 with no comments.
Read more articles on Axapta and Programming.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| array i;
int n;
;
i = new array(types::String);
i.value(1,"1.");
i.value(2,"2.");
i.value(3,"3.");
i.value(4,"4.");
for(n =1; n <= i.lastIndex(); n++)
print i.value(n); |
Written by Komkid on August 5th, 2009 with no comments.
Read more articles on Axapta and Programming.