Thursday, August 02, 2007

Introducing Service-Oriented Architecture



Service-Oriented Architecture ( SOA ) represents a new and evolving model for building distributed applications. Services are distributed components that provide well-defined interface that process and deliver XML messages. A service-based approach makes sense for building solutions that cross organizational, departmental, and corporate domain boundaries. A business with multiple systems and applications on different platforms can use SOA to build a loosely coupled integration solution that implements unified workflows .

Overview of Service-Oriented Architecture


     The concept of services is familiar to anyone who shops online at an e-commerce web site. Once you place your order, you have to supply your credit card information, which is typically authorized and charged by an outside service vendor. Once the order has been committed, the e-commerce company coordinates with a shipping service vendor to deliver your purchase. E-commerce applications provide a perfect illustration of the need for an SOA. if the credit card billing component is offline or unresponsive, you do not want the sales order process to fail. Instead, you want the order to be collected and the billing operation to proceed at a later time. Figure 1-1 provides a conceptual workflow for an e-commerce business that uses multiple services to process orders.

Friday, February 23, 2007

การอ้างอิงฟอร์มหลัก สำหรับ SDI หรือ MDI Form

วิธีการอ้างอิงฟอร์มหลักสำหรับการใช้ ShowDialog() และเมื่อปิดแล้วให้ย้อนกลับ
มาที่ฟอร์มแรกที่ทำงาน . .

ตัวอย่าง

frmLogon logonForm = (frmLogon)this;

logonForm.hide(); // ฟอร์มหาย

frmShowMem showmemForm = new frmShowMem();
showmemForm.showDialog();
// แสดง และ ทำงานบน ShowMem เมื่อทำงานเสร็จก็จะปิด

logonForm.show(); // แสดงฟอร์มแรกก่อนไป showmemForm

Thursday, February 22, 2007

การป้องกัน SQL Injection ด้วย Parameter ใน .net

ตัวอย่าง

string ins_Sql;
ins_Sql = "INSERT INTO TBIPDPLIST(HN,DRUGCODE,RX_DATE)";
ins_Sql += " VALUES(@HN,@DRUGCODE,@RX_DATE)";
OleDbCommand insCmd = new OleDbCommand(ins_Sql, oledb_Conn);
insCmd.Parameters.Add("@HN", dbRead["HN"].ToString());

insCmd.Parameters.Add("@DRUGCODE", dbRead["DRUGCODE"].ToString());
insCmd.Parameters.Add("@RX_DATE", dbRead["RX_DATE"].ToString());

insCmd.ExecuteNonQuery();

จะเห็นว่าเราใช้วิธีการ @ นำหน้าชื่อ parameters

แล้วก็ใช้ method Parameters.Add ของ OleDbCommand ในการแทนที่ Parameter
เพียงเท่านี้ก็ป้องกัน SQL Injection ได้แล้วครับ

การนำข้อมูลจาก DataSet เข้า MS Excel 2003

ปกติแล้วมีบ่อยครั้งที่เราจำเป็นต้องนำข้อมูลไปใช้ ในรูปแบบของ Excel File
ซึ่งที่จริงแล้วมีหลายวิธีที่เราจะสร้างออกมา

แต่ในหัวข้อนี้ผมจะอธิบายการนำ XML ที่ได้จาก DataSet มาใช้กับ Excel 2003

ตัวอย่าง

string sql = "SELECT * FROM NATION";

FbConnection fbConn = new FbConnection(ConStr);
fbConn.Open();

DataSet ds = new DataSet();

FbDataAdapter fbAdap = new FbDataAdapter(sql,fbConn);
fbAdap.Fill(ds);

ds.Tables[0].WriteXml("NATION.xml");

แล้วเราก็เปิดไฟล์ NATION.xml ด้วยโปรแกรม Microsoft Excel ( รุ่น 2003 )
จากนั้นเราก็ทำการ Save ออกมา . . ก็จะได้เป็น File .xls ที่ใช้ MS Excel เปิดได้

หรืออีกวิธีหนึ่ง . . คือการใช้ . . CrystalReportViewer Object ของตัว .Net เอง

Friday, February 16, 2007

วิธีการใช้ Embeded Firebird

วิธีการที่เราจะใช้ Embeded Firebird นั้น เราต้องไปดาวโหลด firebird1.5-embeded
จากนั้นเวลาเราจะนำมาใช้ ให้ใช้วิธีการดังต่อไปนี้

1. Copy ตัว fbembed.dll มาไว้ใน Directory ของโปรแกรมที่พัฒนา
2. Copy หรือทำการ Add Reference ตัว Firebird Client DLL มาใน Directory

สำหรับ ConnectionString

string ConStr = "Database=databasepath;ServerType=1;";

Tuesday, October 17, 2006

วิธีการให้กด Enter เพื่อเลื่อน Focus ของ WebForm

ในการ Key ข้อมูลที่เป็นตัวเลขนั้นจะเห็นได้ว่า ผู้ใช้นิยมจะกด Enter เพื่อเลื่อน Cursor
ให้มา Focus อยู่ที่อีก Object หนึ่งไม่ว่าจะเป็น Win app หรือ Web app

สำหรับ Win App นั้นเราก็ใช้วิธีการตั้ง TabIndex และ Setfocus ร่วมกับ Keypress
ซึ่งเป็น Events อยู่แล้วสำหรับ Windows Object..

แต่ถ้าเป็น Web App เราก็อาจจะใช้ JavaScript ได้ ซึ่งวิธีการก็คือ การกำหนด onKeyPress
ลงไปเป็น Parameter สำหรับพวก INPUT ของ HTML Form ดังตัวอย่างต่อไปนี้



Name:


Address:


City:






SELECT แบบเลือก Record บน Firebird

วันนี้ค้นหาข้อมูลเกี่ยวกับคำสั่งในการดึงข้อมูลแบบระบุ Record บน Firebird
ซึ่งการดึงข้อมูลแบบนี้เราจะใช้เมื่อข้อมูลมีปริมาณมากๆ . . .

คำสั่ง
SELECT FIRST 10 SKIP 20 column1, column2, column3 FROM foo

ความหมายของ SQL ด้านบนคือ

ดึงข้อมูล 10 Record ของ Columns ที่กำหนดนับตั้งแต่ Record ที่ 20 จาก Table foo

^ ^

สมมติถ้าต้องการหา 100 อันแรกก็ใช้แค่

คำสั่ง
SELECT FIRST 100 Column From Table

แค่นี้เองครับ ( แต่ถ้าหากจะนับไปกี่ Record จากไหนก็ใช้คำสั่งอันแรกที่มี Skip )

อีกนิดไม่แน่ใจว่า Reference Community ของ Firebird ไว้หรือยัง . .

Firebird Thai

Thursday, October 12, 2006

ปิด Regedit บน Win XP Pro

ก่อนหน้านี้ได้ลงวิธีการปิด Regedit ด้วย Registry Code ไปแล้ว ในตอนนี้จะแนะนำ
การปิด Regedit ด้วยการใช้ GUI บน Windows XP Professional

หมายเหตุ ( ไม่สามารถใช้บน XP Home ได้เพราะไม่มี Group Policy )

วิธีการง่ายๆโดยการพิมพ์ gpedit.msc ที่ Start -> Run

แล้วเลือกตรงส่วนของ
User Configuration -> Administrative Templates -> System

แล้วเลือกมาท่ Prevent access to registry editting tool คลิกขวา
เลือกเป็น Enable จะเป็นการปิดการใช้งาน Regedit

การ Disable Regedit เพื่อความปลอดภัย

ช่วงนี้เป็นอีกช่วงที่ทำให้รู้สึกเหมือนตอนทำงานที่ทำงานเก่า
ที่จะต้องรับหน้าที่ Computer Security Admin ในระบบ server

ส่วนหนึ่งของวิธีการที่เราจะทำการ Disable Regedit ก็เพื่อความปลอดภัยและป้องกัน
การเขียนตัวเองลงระบบของไวรัส ( ซึ่งมักจะเริ่มจาก Regeistry )

วิธีการที่เราจะ Disable Regedit ก็คือ

HKEY_LOCAL_USER -> Software -> Microsoft -> Windows ->
CurrentVersion -> Policy -> System ->

ให้เพิ่มประเภทเป็น แบบ DWORD ตั้งชื่อว่า "DisableRegistryTools" ให้มีค่าเป็น 1

แค่นี้ผู้ใช้ก็ไม่สามารถที่จะสั่งเปิด regedit ได้อีกต่อไป .. วะ หะ หะ หะ ^ ^

Script สำหรับปลด Lock การ Disable Regedit

ต่อไปนี้เป็น SCRIPT จาก Symantec นะครับ ไว้ใช้สำหรับปลด Lock สิทธิการใช้งาน
Regedit ทั้งบน Windows 95/98/ME/XP

[Version]
Signature="$Chicago$"
Provider=Symantec

[DefaultInstall]
AddReg=UnhookRegKey

[UnhookRegKey]
HKLM, Software\CLASSES\batfile\shell\open\command,,,"""%1"" %*"
HKLM, Software\CLASSES\comfile\shell\open\command,,,"""%1"" %*"
HKLM, Software\CLASSES\exefile\shell\open\command,,,"""%1"" %*"
HKLM, Software\CLASSES\piffile\shell\open\command,,,"""%1"" %*"
HKLM, Software\CLASSES\regfile\shell\open\command,,,"regedit.exe ""%1"""
HKLM, Software\CLASSES\scrfile\shell\open\command,,,"""%1"" %*"
HKCU, Software\Microsoft\Windows\CurrentVersion
\Policies\System,DisableRegistryTools,0x00000020,0


จากนั้นให้ Save เป็นไฟล์ชื่อ UnHookExec.inf

ถ้าต้องการใช้ก็ให้คลิกขวาที่ไฟล์ แล้วเลือก Install จะเป็นการ Enable Regedit นะครับ ^^

Monday, October 02, 2006

NGen Revs Up Your Performance with Powerful New Features

วิธีการใช้ Ngen เพื่อช่วยเพิ่มความเร็ว เอกสารเป็นทางการของ Microsoft

NGen Revs Up Your Performance with Powerful New Features

Friday, September 22, 2006

วิธีการสั่งรัน Process โดยไม่เริ่มหน้าต่างใหม่

Capturing the output from a console application in C#
Submitted by rlipscombe on Mon, 2005-02-07 21:35.C#
The .NET framework class library provides a handy Process class for running (and monitoring) other applications.

Here's how to grab hold of a Stream object for the input and output of a process.


Process process = new Process();
process.StartInfo.FileName = fileName;
process.StartInfo.Arguments = arguments;

// We have to turn off UseShellExecute to redirect the input and output.
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;

// If we're a Windows.Forms application, we'll want to turn
// off the new console window that appears.
process.StartInfo.CreateNoWindow = true;

// We have to turn on EnableRaisingEvents to enable the Exited event.
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(OnExited);

// We can't get at the StandardInput and StandardOutput properties until
// after the process is started.
process.Start();

// The Process class gives us StandardInput and StandardOutput
// properties, but they're a StreamWriter and StreamReader.
StreamWriter inputWriter = process.StandardInput;
Stream inputStream = inputWriter.BaseStream;

// If you want the underlying stream, you need the BaseStream
// property.
StreamReader outputReader = process.StandardOutput;
Stream outputStream = outputReader.BaseStream;

StreamReader errorReader = process.StandardError;
Stream errorStream = errorReader.BaseStream;

Ref :: Capturing the output from a console application in C#

Tuesday, September 19, 2006

Netsh อีกแล้ว . . .

ตัวอย่างการสั่งเปลี่ยน IP ให้ NIC โดยไม่ต้องอ่านจาก TextFile เหมือนรอบก่อน
ทำดังนี้ครับ

netsh interface ip set address "Local Area Connection" static 10.0.0.123 255.255.0.0 10.0.0.1 1
netsh interface ip set dns "Local Area Connection" static 10.0.0.1

ง่ายๆครับเห็นป่ะ . . .

แต่ก็ comment อย่างเดิมใช้ได้แต่กับ XP ขึ้นไปนะครับ

ใช้เวลาในการเปลี่ยน 15 วินาทีขึ้นไป ( ในการประมวลผลคำสั่ง ) ขึ้นกับความเร็ว
ผมว่าเปลี่ยนเองก็พอๆกัน . . ทำไว้เป็น Bat ก็ได้นะครับ

แต่ผมจะเขียนเป็นโปรแกรม อิอิ

Monday, September 18, 2006

การเปลี่ยน IP ผ่าน Commad Line

วันนี้ผมได้ทดลองทำการเปลี่ยน IP Address ผ่าน Command Line นะครับ
โดยวิธีการคือผมทำ TextFile ไว้เพื่อเก็บข้อมูลเกี่ยวกับ IP Address ดังนี้

# ----------------------------------
# Interface IP Configuration
# ----------------------------------

pushd interface ip

set address name = "Internet" source = static addr = 10.0.0.109 mask = 255.0.0.0
set address name = "Internet" gateway = 10.0.0.2 gwmetric = 1

set dns name = "Internet" source = static addr = 203.146.237.237
add dns name = "Internet" addr = 203.146.237.222
popd

# End of interface IP configuration

จากนั้นก็ Save เช่นผมเซฟ เป็นชื่อ TOT.txt

เวลาจะใช้งานก็เปิด Command Line ขึ้น แล้วพิมพ์คำสั่ง

netsh -f (ชื่อไฟล์)

รอสักครู่ ค่าของ IP ที่ตั้งไว้ใน NIC จะถูกเปลี่ยนตามที่กำหนดครับ

ทั้งหมดนี้ผมทดสอบบน Windows XP Pro นะครับ ^-^ ทำงานได้ดีมั๊กๆ ^ ^

Saturday, September 16, 2006

Login root ด้วย ssh บน FreeBSD 6.0

วันนี้ผมว่างครับเลยกลับมาลองงม FreeBSD อีกรอบ แผ่นที่มีก็เป็นรุ่น 6.0
ตอนนี้ใหม่สุดจากเวบเค้าก็เป็นรุ่น 6.1 ผมเลยไม่ซีเรียด

ตอนนี้ลงเสร็จแล้วเซทต่อเนทแล้ว ติดปัญหาอย่างเดียวครับ คือ ผมลง SSH ไป
แต่ผม Login ด้วย root ไม่ได้

แต่ตอนนี้ผมได้คำตอบเลยเลยขอ Note ไว้สักหน่อย

วิธีก็คือ

แก้ไขไฟล์ /etc/ssh/sshd_config
หา #PermitRootLogin no

ให้ลบ # ออก แล้วแก้ no เป็น yes จะได้เป็น
PermitRootLogin yes

ความจริงแล้วเค้าไม่แนะนำให้ทำแบบนี้นะครับ ( แต่ผมจะทำเพราะยังไม่ได้ออนไลน์ )

Thursday, September 14, 2006

Access Point 2 Access Point

วันนี้รุ่นพี่ที่ทำงาน โทรมาถามว่า AP มันสามารถทำ Repeat กับ AP ด้วยกันได้ไหม
ผมเองจำได้นะว่ามันทำได้ แต่ก็ไม่เคยมี AP หลายๆตัวเลยไม่เคยได้ทำสักที

หลังจากวางสายก็เลยหาข้อมูลเกี่ยวกับการทำ Repeat สัญญานด้วย AP ก็ได้ข้อมูลมาดังนี้

- AP ทุกตัวที่จะใช้จะต้องมี Mode Repeat ด้วย
- AP ควรจะเป็น ยี่ห้อ และ รุ่นเดียวกัน ( ให้ตรวจสอบ Firmware ด้วย )

ผมเองก็ยังไม่ได้ลองทำ แต่เร็วๆนี้คงได้ลองเพราะต้องไปวางระบบเครือข่าย ที่ส่วนของห้องตรวจ
และจะต้อง Hybrid เข้ากับ Wire Network

งานนี้สั่ง Access Point ไป 4 ตัว กะจะให้สัญญานในย่านนั้น แรงๆ ( มีสำรองเสีย 1 ตัว )
จะลองทำ Repeat ก็งานนี้แหละครับ ^ ^

อีกเรื่องหนึ่ง ผมได้ข้อมูลมาว่า ทั่วๆไปแล้ว AP สามารถส่งสัญญานได้ประมาณรัศมี 100 เมตร
และสามารถรองรับการเชื่อมต่อเข้ามา ตั้งแต่ 100 เครื่องขึ้นไป แต่ถึงเท่าไร ไม่มีระบุ

Ref :: The Lord Of Wireless

Tuesday, September 12, 2006

ตัวอย่างการสร้าง Assembly ใน .Net

วันนี้ผมทดลองเขียน Assembly เกี่ยวกับ Network ของผมเอง เพื่อความสะดวกในการทำงาน

ตัวอย่าง CODE พัฒนาโดย C# หลังคอมไฟล์จะได้เป็นไฟล์ Stamp.Net.DLL

using System;
using System.Net;
using System.Collections.Generic;
using System.Text;

namespace Stamp.Net
{
public class IPClass
{
private string IP;
private string host;

public string version()
{
string APIversion = "1.0";

return APIversion;
}

public string hostName()
{
string hName = Dns.GetHostName();

host = hName;

return host;
}

public string getHostname()
{
hostName();
return host;
}

public string getMyIP()
{
string ip = null;

getHostname();

IPHostEntry ipEntry = Dns.GetHostEntry(host);
IPAddress[] addr = ipEntry.AddressList;

for (int i = 0; i < addr.Length; i++)
{
ip += addr[i].ToString();
}

IP = ip;
return IP;
}

public string getOtherIP(string domain)
{
string ip = null;

IPHostEntry ipEntry = Dns.GetHostEntry(domain);
IPAddress[] addr = ipEntry.AddressList;

for (int i = 0; i < addr.Length; i++)
{
ip += addr[i].ToString();
}

IP = ip;
return IP;
}
}
}

ผมทดลองใช้แล้วนะครับ ^^ พูดได้แค่ว่า Yes !! It work..

วิธีการนำข้อมูลใน DataSet ออกมาเป็น XML

วิธีในการนำ DataSet ออกมาเป็น XML วันนี้จะ Note การนำข้อมูลใน DataSet ออกมาเป็น
ไฟล์ XML โดยการดึงข้อมูลใน DataBase มาทำเป็น XML File สามารถทำได้ผ่าน DataSet
โดยวิธีการใช้งาน Method

DataSet.WriteXML(Filename.XML);

ซึ่ง Method นี้จะทำการนำข้อมูลใน DataSet มาเขียนใส่ไฟล์ XML

สำหรับวิธีการนำเข้าก็ใช้ Method

DataSet.ReadXML(Filename.XML);

###########################################################

วิธีการนี้เราสามารถที่จะนำไปประยุกต์ใช้กับโปรแกรมแปลงประเภทฐานข้อมูลได้ . . หรือนำไป
ประยุกต์ใช้กับโปรแกรมประเภทอื่นๆ ^ ^

Monday, September 11, 2006

โปรแกรมติดต่อ WMI ที่ผมลองเขียน

วันนี้ผมลองเขียนโปรแกรมติดต่อ WMI เพื่อเรียกดู Memory ที่เหลือให้ใช้ในระบบ
และ ชื่อของ SoundCard ในเครื่องของผม Sourcecode ดังนี้ครับ

using System;
using System.Management;
using System.Collections.Generic;
using System.Text;

namespace CS_TestWMI
{
class Program
{
static void Main(string[] args)
{
SelectQuery query = new SelectQuery("Win32_OperatingSystem");
ManagementObjectSearcher search = new ManagementObjectSearcher(query);

foreach (ManagementObject read in search.Get())
{
Console.WriteLine("Query From Win32_OperatingSystem");
Console.WriteLine(read.GetPropertyValue("FreePhysicalMemory"));
Console.WriteLine(read.GetPropertyValue("Caption"));
Console.WriteLine(read.GetPropertyValue("SerialNumber"));
Console.ReadLine();
}

SelectQuery query2 = new SelectQuery("Win32_SoundDevice");
ManagementObjectSearcher search2 = new ManagementObjectSearcher(query2);

foreach (ManagementObject read2 in search2.Get())
{
Console.WriteLine("Query From Win32_SoundDevice");
Console.WriteLine(read2.GetPropertyValue("ProductName"));
Console.ReadLine();
}
}
}
}

ทดสอบแล้วทำงานได้ครับ ^^ เป็น ConSole Application ครับผม

MySQL Storage Engine Detail

รายละเอียด Storage Engine ประเภทต่างๆใน MySQL

mysql> show engines;
+------------+---------+-------------------------------------------------------+
| Engine | Support | Comment |
+------------+---------+-------------------------------------------------------+
| MyISAM | YES | Default engine as of MySQL 3.23 with great performance |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables |
| HEAP | YES | Alias for MEMORY |
| MERGE | YES | Collection of identical MyISAM tables |
| MRG_MYISAM | YES | Alias for MERGE |
| ISAM | NO | Obsolete storage engine, now replaced by MyISAM |
| MRG_ISAM | NO | Obsolete storage engine, now replaced by MERGE |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys |
| INNOBASE | YES | Alias for INNODB |
| BDB | YES | Supports transactions and page-level locking |
| BERKELEYDB | YES | Alias for BDB |
| NDBCLUSTER | NO | Clustered, fault-tolerant, memory-based tables |
| NDB | NO | Alias for NDBCLUSTER |
| EXAMPLE | NO | Example storage engine |
| ARCHIVE | YES | Archive storage engine |
| CSV | NO | CSV storage engine |
| FEDERATED | YES | Federated MySQL storage engine |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) |
+------------+---------+--------------------------------------------+

Ref:: MySQL Storage Engine Detail