Programming

You are currently browsing the articles from KomKid.Net matching the category Programming.

Axapta : Execute SQL command

Axapta มีคำสั่ง SQL รวมอยู่ใน X++ อยู่แล้ว
แต่ถ้าอยากใช้คำสั่ง SQL อื่น ๆ เช่น ใช้ประโยชน์จาก NewID() ของ MS SQL Server เพื่อ random ก็ทำได้ ดังตัวอย่าง

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
static void Job3(Args _args)
{
    LogInProperty   Lp = new LogInProperty();
    OdbcConnection  myConnection;
    Statement       myStatement;
    ResultSet       myResult;
    str             sqlQuery;
;

    sqlQuery = 'SELECT TOP 10 * FROM CustTable ORDER BY NewID()';

    LP.setServer("Server");
    LP.setDatabase("db");
    Lp.setUsername("user");
    Lp.setPassword("password");

    try{
        myConnection = new OdbcConnection(LP);
    }
    catch{
        info("Check username/password.");
        return;
    }

    myStatement = myConnection.createStatement();
    myResult = myStatement.executeQuery(sqlQuery);

    while (myResult.next()){
        box::info(myResult.getString(1));
    }
}

Written by Komkid on October 20th, 2010 with no comments.
Read more articles on Axapta and Database and Programming.

Axapta : Find user group of current userid

กันลืม

1
2
3
4
5
6
7
8
9
 UserGroupList   userGroupList;
;
    WHILE SELECT userGroupList
    WHERE userGroupList.userId == curuserid()
//    && userGroupList.groupId == 'searchGroup';
    {
        print userGroupList.groupId;
    }
    pause;

Written by Komkid on October 20th, 2010 with no comments.
Read more articles on Axapta and Programming.

Set homepage by code

วันก่อนมีรุ่นน้องที่เคารพ โทรมาหาถามว่า

พี่ เซ็ต homepage ทำยังไงอ่ะ พอดีไปเผลอกดตอบรับเซ็ต homepage ของเว็บนึงเข้า

คิดในใจ “โห โง่ว่ะ” แต่ตอบไปว่า

เข้าไปที่ Tools -> Internet option …

สวนกลับมาก่อนจะบอกจบว่า

ไม่ได้พี่ IT บล็อก

ค่อยเริ่มน่าสนใจหน่อย จะบอกให้ไปแก้จาก registry ก็คงจะโดนบล็อกอีก ก็เลยหาวิธีอื่นให้ สรุปได้ว่าใช้ code ข้างล่าง

1
2
3
4
5
6
7
8
9
10
11
12
<html>
<head>
<title>Set homepage</title>
</head>
<body>
<form name="HomepageForm">
<input type="text" name="urlbox">
<input type="button" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage(document.HomepageForm.urlbox.value);" value="Set">
</form>

</body>
</html>

upload ให้ด้วยที่ http://tools.komkid.net/homepage.html เผื่อใครจะเจอสถานการณ์แบบนี้บ้าง (ใช้ได้เฉพาะ IE เท่านั้นเด้อ)

——————————————
อันนี้แปะไว้กันลืม Registry สำหรับ IE

1
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Start Page

Written by Komkid on April 27th, 2010 with no comments.
Read more articles on Internet and JavaScript and Programming.

Axapta : Posting journal by code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
static void InventJournalCheckPost(Args _args)
{
InventJournalTable      inventJournalTable;
InventJournalCheckPost  journalCheckPost;    
;
ttsbegin;
inventJournalTable =  InventJournalTable::find("xxx",true);
//Remove Journal "xxx" has not been locked by system
inventJournalTable.SystemBlocked = true;
inventJournalTable.update();

journalCheckPost   =  InventJournalCheckPost::newJournalCheckPost  (JournalCheckPostType::Post,inventJournalTable);
journalCheckPost.run();

inventJournalTable.SystemBlocked = false;
inventJournalTable.update();
ttscommit;
}

Written by Komkid on February 11th, 2010 with no comments.
Read more articles on Axapta and Programming.

Squid : Custom error page

blocked
หน้าตาสำหรับแสดงผลกรณีมี error ของ squid เช่น กรณีถูกบล็อก(ERR_ACCESS_DENIED) แก้ไขได้ที่ /usr/share/squod/errors/
โดยสามารถใช้ Variable ได้ด้วย ดังนี้

%B URL with FTP %2f hack
%c Squid error code
%d seconds elapsed since request received (not yet implemented)
%e errno
%E strerror()
%f FTP request line
%F FTP reply line
%g FTP server message
%h cache hostname
%H server host name
%i client IP address
%I server IP address
%L contents of err_html_text config option
%M Request Method
%m Error message returned by external auth helper
%p URL port
%P Protocol
%R Full HTTP Request
%S squid default signature
%s caching proxy software with version
%t local time
%T UTC
%U URL without password
%u URL with password (Squid-2.5 and later only)
%w cachemgr email address
%z dns server error message

ตัวอย่าง ERR_ACCESS_DENIED

1
2
3
4
5
6
7
8
9
10
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF8">
<TITLE>ERROR: The requested URL could not be retrieved</TITLE>
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
</HEAD><BODY bgcolor="#000000">
 <div align="center">
  <img src="http://intranet.sci.com/sci/blocked.jpg" border="0" alt="Access dinied">
  </div>
<br>
<div align="center">Web นี้ถูก block ในช่วงเวลา 8:00-12:00 น. และ 13:00-17:40 น. หากมีความจำเป็นต้องใช้งาน กรุณาแจ้ง งทส.</div>

Written by Komkid on January 28th, 2010 with no comments.
Read more articles on Admin and Networking and Programming and Ubuntu.

« Older articles

No newer articles