Search

Wednesday, May 21, 2008

DataGridView Connect SQL SERVER

วันนี้ลองมาใช้ DataGridView ในการเขียน C# Window Application กันนะครับ ผมจะดึงข้อมูลใน SQL Server ซึ่งผมใช้ version 2005 มาแสดงที่ DataGridView เริ่มกันเลยครับ
ให้ new project c# window application ขึ้นมาก่อนเลยครับ แล้วลาก DataGridView และ Button มาวางจัดให้ได้
แก้ชื่อ Button ให้เรียนร้อย ผมแก้เป็น
button1 >> button_LoadData
datagridview1 อันนี้ผมไม่แก้ละกันนะครับ
โดยในตัว DataGridView เองเราไม่จำเป็นที่จะต้องเขียน Code แม้แต่น้อยเราก็สามารถติดต่อกับดาต้าเบสได้แล้ว ใช้เวลาเพียงนิดเดียวไม่น่าจะถึงนาทีด้วยซ้ำ
สำหรับการติดต่อดาต้าเบสก็ทำตามขั้นตอนเลยนะครับ
ให้ไปที่ window property ให้หา คำว่า DataSource แล้วเราจะทำการเลือก DataSource กัน ให้คลิกที่ ด้านขวาของคำว่า DataSource นะครับ จาำกนั้นคลิก Add Project Data Source

Thursday, May 15, 2008

Hello Client .net webservice

หลังจากที่เราได้สร้าง Mathservice เรียบร้อยแล้วนะครับ ต่อไปเราก็จะมาเรียกใช้ว่ามันจะใช้งานได้หรือเปล่าว
เริ่มกันเลย

Create new window application project in ProjectType select Visual C# template : Window Application then rename project to MachClient in Name field. Drag textbox , lable and button to From like this.
Then right click on MathClient project contectype munu are appear select Add web refference...
Select browse to : Web service in this solution
Select you service in my solution contain two service. I select MathService.
Wait for vs search webservice in solution and then you can view service list

Back to Form1 click button1 and put this code

if (comboBox_Operator.SelectedIndex == -1)
{
MessageBox.Show("กรุณาเลือก operator");
return;
}

MyService.Service myservice = new HelloClient.MyService.Service();

if (comboBox_Operator.SelectedIndex == 0)
{
label_Result.Text = myservice.add(Int32.Parse(textBox1.Text), Int32.Parse(textBox2.Text)).ToString();
}
else if (comboBox_Operator.SelectedIndex == 1)
{
label_Result.Text = myservice.sub(Int32.Parse(textBox1.Text), Int32.Parse(textBox2.Text)).ToString();
}
else if (comboBox_Operator.SelectedIndex == 2)
{
label_Result.Text = myservice.multi(Int32.Parse(textBox1.Text), Int32.Parse(textBox2.Text)).ToString();
}

Explain:
Read text check condition if textbox1 and textbox2 is not empty.
Green text create instance of MathService.

แล้วทีนี้ก็ลอง รันโปรเจคดูนะครับจะได้ผลเป็นยังไงบวกลบคูณเลขถูกเปล่าว อันนี้ผมเขียนแบบง่าย ๆ ไม่มีการรตรวจสอบว่าถ้า input เป็น text จะทำยังไง ง่ายอีกละ ก็ให้ exception แล้วบอกว่า อะไรก็ได้เช่น กรุณาป้อนตัวเลขค่ะ เอาไว้มาต่อกันครั้งหน้าดีกว่าครับ

Wednesday, May 14, 2008

How to user UDDI

สำหรับหลาย ๆ คนที่ชอบเล่นเว็บเซอร์วิสก็คงรู้ดีครับว่า UDDI คืออะไรและใช้งานอย่างไร ส่วนตัวผมแล้วไม่ค่อยได้ Deploy หรอกครับเพราะไม่มี Host เป็นของตัวเองเลยไม่่รู้ว่าจะเอาไป Deploy ที่ไหนดี

สำหรับคนที่เริ่มจะศึกษา หรืออยากลองเรียก service เล่น ๆ อยากทราบถึงวิธีการใช้ UDDI และจะหา UDDI ได้ที่ไหน ที่นี่มีคำตอบครับ

Create simple ASP.NET webservice

วันนี้ว่าง ๆ ก็เลยลองสร้าง asp.net webservice เล่นดูบ้าง
สิ่งที่ต้องเตรียม
1. Visual Studio 2005.
2. เตรียมใจ (เหอะๆ )


บอกก่อนว่าเว็บเซอร์วิสที่จะสร้างเนี่ยมันง่ายแสนจะง่ายแค่คลิก ๆ ไม่กี่คลิกก็ได้แล้ว
เซอร์วิสที่จะทำ ก็มี
1. บวกเลข
2. ลบเลข

3. คูณเลข


มาลงมือกันเลย

On the File menu, click New and then click Project. Under Project types click Visual C# Projects, then click ASP.NET Web Service under Templates. Type MathService in the Location text box to change the default name (WebService1) to MathService

Click OK after visual studio create initial c# code like below.

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}
}

Change a namespace to http://localhost/mathservice and create method add , sub and multi


[WebMethod]
public int add(int a, int b)
{
return a + b;
}

[WebMethod]
public int sub(int a, int b)
{
return a - b;
}

[WebMethod]
public int multi(int a, int b)
{
return a * b;
}

Save and right click on service.asmx select view in browser from pop up menu then you see mathservice list on your browser.

Make it easy enjoy it.

Monday, May 12, 2008

Build wysiwyg editor in asp.net

หายหน้าหายตาไปหลายวันไม่ได้มาโพสต์นาน มัวแต่ไปปั้ม Blogger อยู่ ฮ่า ๆ กะว่าจะปั้มสักพัน ให้ได้ภายในเดือนเดียว

พอดีที่ฝึกงานจำเป็นที่จะต้องสร้างเว็บด้วย ASP.NET และีมีหน้าที่ให้ user ป้อน input และสามารถแก้ไขทำตัวหนา ตัวเอง หรือทำลิงค์ ได้ทุกอย่างเหมือนกับ ms word ไม่รู้จะำทำไงดีทางเดียวที่จะอยู่ลอดได้ นึกถึงแต่พี่กูละวะ ก็เลยไปเจอกับเจ้า FCKeditor เข้าและเป็น opensource ด้วยซึ่งตัวนี้สามารถนำไป adap เข้ากับหลายภาษาเช่น Java, php ,asp, asp.net
ก็ลองดู Feature มันล่ะกันครับ

On the server side, FCKeditor offers a complete integration pack for:

  • ASP.Net
  • ASP
  • ColdFusion
  • PHP
  • Java
  • Active-FoxPro
  • Lasso
  • Perl
  • Python

  • Multi browser compatibility
  • Outputs XHTML 1.0
  • CSS support for better integration with your web site
  • Font formatting: type, size, color, style, bold, italic, etc
  • Text formatting: alignment, indentation, bullets list, etc
  • Cut, Paste, and Paste as Plain Text, Undo and Redo
  • Paste from Word cleanup with auto detection
  • Link and anchors support
  • Image insertion, with upload and server browsing support
  • Table creation and editing (add, delete rows, etc) - one of the best systems on the market.
  • Table cells editing (size, colors, etc)
  • Form fields
  • Right click context menus support
  • Complete toolbar customization
  • Skins support
  • Plugins support
  • Spell checker
  • Multi-language support with automatic user language detection. Including Right to Left scripting.
  • Complete page editing (from to ) or just contents.
  • Lightweight and fast
  • Automatic browser detection and customization
  • Integration with ASP, ASP.NET, Java, ColdFusion, Perl, PHP, JavaScript and more.
  • Image and file links upload and server repository browser.
  • For web developers it is easy to install and customize
  • For web users it's simple and easy to use!
ดู Feature แล้วน่า่ใช้ใช่ไหมละครับ
ดู Demo กันได้ที่ http://www.fckeditor.net/demo
ดาวโหลดกันได http://www.fckeditor.net/download


Tuesday, May 6, 2008

Create .exe file (setup file)

สำหรับนักพัฒนาโปรแกรมหลาย ๆ คนทีไม่รู้ว่าพอเราเขียนโปรแกรมที่เราอดหลับอดนอนมาหลายวัน หลายเดือน เนี่ย ตอนจะ deploy จะทำยังไงหว่า ถ้าเขียนด้วย visual studio 2003/2005 /2008 ก็ยังพอว่ากันได้ มีวิธีการสร้างตัว setup ไม่ว่าจะเป็น oneclick หรือ การสร้าง setup project แล้วถ้าเป็น java ละ กรำเลยจะทำยังไงดีรู้แต่วิธีการสร้างเป็น .jar ทำ .exe ไม่ได้เป็น

วันนี้ผมก็เลยมีโปรแกรมดี ๆ มาแนะนำครับคิดว่าบางคนคงเคยใช้กันแล้วละ ใช้ทำตัว setup file หรือ .exe สามารถทำได้ทั้ง เกือบทุกภาษาเลยก็ว่าได้ ส่วนวิธีการนั้นไม่บอก ก๊าก ๆ ลองไปอ่านเองที่
http://www.innosetup.com
ขอบอก ว่าดีจริง ๆ