ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us  

MAIN MENU
News
Php Tips
Android Programming
Design Pattern By PHP
C# using Linq น่าใช้จริงๆ
C# Tips & Technique
C# Design Pattern
Linux Quick Tips
Java & JavaScript Tips
Database
ZengCode Framework Guide
Zeng Code Code
Programming
IPhone (Tips and Trick)

 

สวัสดีครับแฟนๆ Madoogun.com ยินดีต้อนรับสู่บ้านใหม่ครับ

ZengCode framework ขอฝากเนื้อฝากตัวกับชาว Developer ทุกท่านด้วยนะครับ
ผู้พัฒนาเองไม่ได้หวังว่ามันจะใช้งานได้ดีขนาดไปเทียบกับจ้างยุทธจักรด้านนี้
ไม่ว่าจะเป็น Prado หรือแม้แต่ Cake ซึ่งนั้นเค้าระดับเทพเรียกพี่แล้วครับ
ผมก็เป็นแค่ Developer ธรรมดา ๆ คนนึงครับ
ที่สร้าง framework ตัวนี้ขึ้นมาก็เพื่อศึกษา และพัฒนาทักษะด้าน OOP ของตัวเอง
อีกทั้งปกติตัวผมเองเขียนโค้ดได้มั่วซั่วมาก ไม่มีระเบียบ อยากเขียนอะไรคิดออกก็เขียน
ไม่มีแบบแผน บางทีกลับมาแก้โค้ดตัวเอง บอกได้คำเดียวว่า เซ็งโครต เซ็ง โครต โครต
และนี่จึงเป็นที่มาของชื่อ framework ของผมครับ
และอีกประเด็นก็เพื่อจุดประการให้พี่น้องชาว Developer ทุกท่าน
ช่วยกันคิดพัฒนาสิ่งต่างๆ เพื่อวงการด้าน IT
ของเราได้ทัดเทียมนานาอารยะประเทศเค้านะคร ับผมขอเป็นจุดเล็กๆจุดนึงที่พร้อมจะมุ่งมั่น
พัฒนาผลงานด้านนี้ต่อไปครับ สู้ๆ นะพี่น้องชาว Developer ทุกท่าน

งานรับปริญา คลิกดูรูป

บทความล่าสุด

 Adapter Pattern  (2010-03-15)

หากว่าเรามี คลาสที่ใช้งานอยุ่ แล้วเรามี คลาสใหม่ที่สร้างมามีความสมารถใหม่(ซึ่งเราซื้อมาไม่สามารถแก้ไขโค้ดได้) เราต้องการคลาสใหม่ที่มี interface
เหมือนคลาสใหม่ที่ซื้อมาและทำงานสอดคล้องกับระบบเก่าที่เรามี(ใช้คลาสเดิม) นี่เลยครับ Adapter Pattern

namespace Adapter
{
    public class CanSwim
    {
        public string Swim()
        {
            return "I am swiming in the pool";
        }
    }//CanSwim

    public class Bird
    {
        public String Fly()
        {
            return "I can fly";
        }
    }//Bird

    public class CanSwimAdapter : Bird
    {
        public CanSwim swimable;
        public CanSwimAdapter(CanSwim swim)
        {
            this.swimable = swim;
        }
    }

}//Adapter

.............


อ่านต่อคลิกที่นี้


 Prototype Pattern  (2010-03-15)

Protype pattern is a pattern for produce new objects from a instance, of the same class, basically clonning objects.
For implement prototype pattern in c#, class must implement ICloneable interface ขออนุญาติไม่แปรนะครับ กัวจะแปลแล้วเข้าใจยากหนักกว่าเดิม

 namespace Prototype
{

public class MyPrototype : ICloneable
{
  public String myName;

  public MyPrototype(String myName)
  {
    this.myName = myName;
  }

  public object Clone()
  {
    MyPrototype newObj = new MyPrototype(this.myName);
    newObj.myName = this.myName;
    return newObj;
  }

}//class
}//Prototype

 ...........................


อ่านต่อคลิกที่นี้


 Builder Pattern  (2010-03-15)

Factory Method ที่ทำหน้าที่สร้าง Object ของ Class ที่ต่างกันแต่มี Super Class เดียวกันมาแล้ว ซึ่งเราทราบแล้วว่าการที่ Object ที่ถูกสร้างจาก Factory Method ต้องมาจาก Super Class เดียวกันนั้น ถือเป็นข้อจำกัดอันหนึ่งของ Factory Method ในบางโอกาส เราจำเป็นต้องใช้ Object ที่เกิดจากการรวมตัวกนของหลาย ๆ object การรวมหลาย ๆ object เข้าด้วยกัน ซึ่ง Design Pattern ที่เหมาะแก่การนำไปใช้เพื่อสร้าง Object ในลักษณะนี่เรียกว่า “Builder”

 

 namespace Builder
{
    public abstract class Animal
    {
        public String name;
        public String myFood;
        public String leg;
        public String animalType;
       
       

        public String getInformation()
        {
            return "I am " + this.animalType +"\n"+this.leg+ "\n My name is " + this.name + "\n I eat an " + this.myFood;
        }

    }//Animal

    public class Monkey : Animal
    {

        public Monkey()
        {
            this.animalType = "Monkey";
            this.myFood = "Banana";
        }


    }//Monkey

    public class Bird : Animal
    {
        public Bird()
        {
            this.animalType = "Bird";
            this.myFood = "Worm";
        }

       
    }//Bird


   public abstract class AnimalBuilder
   {
       public Animal aAnimal;
       public abstract void BuildName(String name);
       public abstract void BuildLeg();
   }//AnimalBuilder

   public class MonkeyBuilder : AnimalBuilder
   {
       public MonkeyBuilder()
       {
           aAnimal = new Monkey();
       }

       public override void BuildName(String name)
       {
           aAnimal.name = name;
       }

       public override void BuildLeg()
       {
           aAnimal.leg = "My leg was build for 4 legs "+MonkeyBuilderSpecial.MakeSpecial();
       }
   }//MonkeyBuilder

  public class MonkeyBuilderSpecial
  {
      public static String MakeSpecial()
      {
          return ", but i can walk by 2 legs.";
      }
  }

   public class BirdBuilder : AnimalBuilder
   {
       public BirdBuilder()
       {
           aAnimal = new Bird();
       }

       public override void BuildName(String name)
       {
           aAnimal.name = name;
       }

       public override void BuildLeg()
       {
           aAnimal.leg = "My leg was build for 2 legs";
       }
   }//MonkeyBuilder

    public class AnimalConstructor
    {
        public String name {get; set;}
        public void MakeAnimal(AnimalBuilder animalBuilder)
        {
            animalBuilder.BuildName(this.name);
            animalBuilder.BuildLeg();
        }
    }


}//Builder

..................................

 


อ่านต่อคลิกที่นี้


 Strategy Pattern   (2010-03-15)

Strategy Pattern เป็น design pattern ที่เอาไว้ใช้ตอนที่เราต้องเลือกทำสิ่งหนึ่ง แต่วิธีการหลากหลายออกไป เช่น นักเรียนแต่ละคนไปโรงเรียนได้หลายอย่าง
เช่นนักเรียนบางคนไปโดยรถยนต์ บางคนไปโดยรถมอเตอร์ไซด์ Pattern ตัวนี้ต้องการ interface ตัวหนึ่งในการเลือกว่านักเรียนจะไปโรงเรียนด้วยวิธีใด
ในที่นี้เราใช้ interface ที่ชื่อว่า IGo

 class Student
    {
        private String myName;
        private IGo goToSchoolBy;
        public Student(String myName)
        {
            this.myName = myName;
        }

        public String GoToSchoolBy(IGo igo)
        {
            goToSchoolBy = igo;
            return "I am "+this.myName+", "+goToSchoolBy.Go();
        }
    }

    interface IGo
    {
         String Go();
    }

    class goCar : IGo
    {
        public String Go()
        {
            return "I go to school by car";
        }
    }

    class goMotorcycle : IGo
    {
        public String Go()
        {
            return "I go to school by motorcycle";
        }
    }

 


อ่านต่อคลิกที่นี้


 Singleton Pattern   (2010-03-15)

ทำความรู้จักกับ Design Pattern

Gang of Four (GOF) patterns นั้นถือว่าเป็นพื้นฐานของ design patterns อื่น ๆ ทั้งหมด  ได้มีการแยกแยะออกเป็น กลุ่ม ได้ 3 กลุ่ม คือ   Creational  Structural และ Behavioral ซึ่งผมจะกล่าวถึง design pattern หมดในแต่ละกลุ่มโดยละเอียด – ดังนี้

Creational Patterns
- Abstract Factory  
- Builder  
- Factory Method  
- Prototype  
- Singleton  
Structural Patterns
- Adapter  
- Bridge  
- Composite  
- Decorator  
- Facade  
- Flyweight  
- Proxy  
Behavioral Patterns
- Chain of Resp.  
- Command  
- Interpreter  
- Iterator  
- Mediator  
- Memento  
- Observer  
- State  
- Strategy  
- Template Method  
- Visitor

Singleton Pattern คือ การจำกัดจำนวน object ที่สร้างจาก class บางตัวเพียงหนึ่งตัวหรือตามจำนวนที่ต้องการ
เพื่อเป็นการจำกัดหรือควบควม resource บางอย่างของระบบ

มีวิธีการหลักๆ ดังนี้ครับ

1. Class Constructor ต้องเป็นมี accessiblility เป็น private

  class TestSingleTon
    {
        private static TestSingleTon instant;

        private TestSingleTon() {}

....................................................................

 2.เมื่อเราจะสร้าง Constructor เป็นแบบ private การสร้าง Object โดย new จะใช้ไม่ได้จะต้องมี Method ในการสร้าง instant ขึ้นมาเช่น
และต้องมีตัวแปรที่เป็น private เพื่อควบคุมการสร้าง object เช่นถ้ามีการสร้างแล้วไม่ให้สร้างอีก หรือควบคุมจำนวน object ในตัวอย่างนี้ให้มีการสร้าง
object ได้ครั้งละ 1 object เท่านั้น

  class TestSingleTon
    {
        private static TestSingleTon instant; //อาจจะเป็น couter นับจำนวน object ที่จะให้สร้างได้พร้อมกัน

        private TestSingleTon() {}

        public static TestSingleTon GetTestSingleTon()
        {
            if (instant == null)
            {
                instant = new TestSingleTon();
                return instant;
            }
            return null;
        }

.................................................

 ........มีต่อ


อ่านต่อคลิกที่นี้


 ถามก่อนออกจากโปรแกรม เรื่องง่ายๆ ที่บางคนยังไม่รู้  (2010-03-15)

ถามก่อนออกจากโปรแกรม เรื่องง่ายๆ ที่บางคนยังไม่รู้

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            DialogResult dlg = MessageBox.Show("You want to terminate program?", "Warning", MessageBoxButtons.YesNo);
            if (dlg == DialogResult.No)
            {
                e.Cancel = true;
            }
            else if (dlg == DialogResult.Yes)
            {
                e.Cancel = false;
            }
        }

 


อ่านต่อคลิกที่นี้


 How to make a form full-screen in C#   (2010-03-11)

เรามาสร้าง Form ให้ เต็ม หน้าจอกันเถอะครับ

 [DllImport("user32.dll")]
        private static extern int FindWindow(string lpszClassName, string lpszWindowName);
        [DllImport("user32.dll")]
        private static extern int ShowWindow(int hWnd, int nCmdShow);
        private const int SW_HIDE = 0;
        private const int SW_SHOW = 1;

       

        public void FullScreen()
        {
            Screen currentScreen = Screen.FromRectangle(this.RectangleToScreen(ClientRectangle));

            // code to maximize form fullscreen mode  
            if (currentScreen.Primary)
            {
                int hWnd = FindWindow("Shell_TrayWnd", "");
                ShowWindow(hWnd, SW_HIDE);
                this.FormBorderStyle = FormBorderStyle.None;
                this.Location = new Point(0, 0);
                this.WindowState = FormWindowState.Maximized;
            }
            else
            {
                this.FormBorderStyle = FormBorderStyle.None;
                this.Location = new Point(currentScreen.Bounds.X, currentScreen.Bounds.Y);
                this.WindowState = FormWindowState.Maximized;
            }
        }

        public void NormalScreen()
        {
            Screen currentScreen = Screen.FromRectangle(this.RectangleToScreen(ClientRectangle));
            this.FormBorderStyle = FormBorderStyle.Sizable;
            if (currentScreen.Primary)
            {
                //show the hidden task bar  
                int hwnd = FindWindow("Shell_TrayWnd", "");
                ShowWindow(hwnd, SW_SHOW);
            }
            this.WindowState = FormWindowState.Maximized;  
        }

 


อ่านต่อคลิกที่นี้


 Diffirence แถว ระหว่าง Text File   (2010-03-10)

เปรียบเทียเอาค่าที่มีใน Text File1 ที่ไม่มีใน Text File 2 ไม่ต้อง loop เทียบแล้วครับ

           // Create the IEnumerable data sources.
            string[] list1 = System.IO.File.ReadAllLines(@"c:/test/list1.txt");
            string[] list2 = System.IO.File.ReadAllLines(@"c:/test/list2.txt");

            // หาแถวที่มีใน list1 แต่ไม่อยู่ใน list2
            IEnumerable<string> differenceQuery = list1.Except(list2);

            // loop ค่ามาแสดงใน rich Text
            foreach (string str in differenceQuery)
                richTextBox1.AppendText(str+"\n");

 


อ่านต่อคลิกที่นี้


 การอ้างถึง Control ที่อยู่ใน Master Page  (2010-03-04)

พอดีน้องที่ทำงานมีเรื่องชวนให้ปวดหัว ถามคำถามนี้ขึ้นมาว่า จะอ้างถึง Control ใน Master Page ยังไง
เอาหล่ะซิ่ ไม่เคยทำซะด้วยก็เลยช่วยกันหา ได้คำตอบประมาณนี้ครับ

อันแรกนี่เป็น หน้า HTML Code ของ Master File นะครับ

 <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
       
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>
 

 


อ่านต่อคลิกที่นี้


 C# สร้าง Object ตอน Runtime โดยการระบุ ชื่อ Class และ Method   (2010-03-04)

บางครั้งเราต้องการที่จะสร้าง Class ตอน Runtime โดยการระบุ เฉพาะชื่อ และ method ที่ต้องการจะเรียกตอน Runtime
ผมลองผิดลองถูกอยู่หลายวิธี อันนี้แหระครับเด็ดสุดแล้ว หรือใครมีเด็ดๆ ก็แนะนำกันมานะครับ ผมก็เพิ่งเขียน C# จริงจังไม่กี่เดือนเองครับ
ผมได้เขียนตัวอย่างการเรียกโดยใช้ Reflection ใน C# นะครับ พร้อมกันนี้ผมก็เขียน Class ที่มีการ Override Method จาก Class แม่
ซึ่งระบะ keyword virtual ไว้ (Polymophism) ยิงปืนนัดเดียวได้นกสองตัว

อันแรกเป็นคลาส Animal , Dog และ Cat ที่มีการทำ Override นะครับ

 class Animal
    {
        public virtual String Say(String myname)
        {
            return "I am the animal!!!!" + "\n My name is " + myname;
        }

    }

    class Dog : Animal
    {
        public override string Say(String myname)
        {
            return "I am a dog and " + base.Say(myname);
        }
    }

    class Cat : Animal
    {
        public override string Say(String myname)
        {
            return "I am a cat and " + base.Say(myname);
        }
    }

 


อ่านต่อคลิกที่นี้


 ใครว่าใน ASP.NET ด้วย C# สร้าง control ตอน runtime ไม่ได้  (2010-03-03)

ใครว่าใน ASP.NET ด้วย C# สร้าง control ตอน runtime ไม่ได้ อ่ะทำให้ดู ก็ทุกอย่างมันเป็น Oject นี่ครับ อย่าเถียง
ไปศึกษา OO มาอีกนิดนะ หุหุ

ส่วนที่แรกเป็นส่วน ของ MyButton.cs นะครับ (เป็นคลาส ฺButton ที่ inherite มาจาก คลาส Button)

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace ZengCodeNet
{
    public class ZCBtn : Button
    {

       //จะ implement อะไรต่อก็ทำไปสุดแต่ใจจะปราถนาครับ ไม่ว่าจะเป็ฯ property หรือ method ต่างๆ
    }
}

 

 


อ่านต่อคลิกที่นี้


 Regular Expression ขั้นพื้นฐาน ใน .NET   (2010-03-02)

Regular Expression ใน .NET (REF : http://www.9neung.com/index.php/2009/regular-expression-c-net/)

เห็นว่ามีประโยชน์ดีเรยนำมาฝากครับ อ่านเข้าใจง่ายมาก ขอบคุณเจ้าของบทความ เดี๋ยวผมจะเขียน class สำหรับเช็ค RegEx นะครับ รอสักแป๊บ คอยติดตามกระทู้นี้นะครับ


โดยสัญลักษณ์ของ Regular expression พื้นฐาน เราจะสรุปได้ดังนี้

^

หมายถึงข้อความที่ขึ้นต้นจะต้องเป็นคำที่ขึ้นต้นด้วย คำหรืออักษรที่อยู่หลังสัญลักษณ์นี้
เช่น "^My"  =  MyCom หรือ MyHome

$

หมายถึง ข้อความต้องปิดท้ายด้วย คำหรืออักษรที่อยู่หลังสัญลักษณ์นี้
เช่น "Home$" = ThisIsHome หรือ IloveHome

 


อ่านต่อคลิกที่นี้


 C# มาลองใช้ Class Dictionary กันครับ  (2010-03-02)

Dictionary/StringDictionary  เป็น Collection ที่ใช้ในการรวบรวมข้อมูลของ name/value ที่มีความใกล้เคียงกัน ( โดย name/value จะคือค่า key และ item ของออบเจกต์ ) โดยออบเจกต์นี้จะคล้ายกับการใช้งาน Array เพียงแต่มีการใช้งานที่ง่าย และไม่มีฟังก์ชั่นซับซ้อนเท่า Array แต่ก็ใช้งานได้ในวงจำกัด

อันแรกนี่ Bean Class นะครับ

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

namespace TestProgram
{
    class Student
    {
        public string id { get; set; }
        public string name { get; set; }
    }
}

 


อ่านต่อคลิกที่นี้


 C# consume Oil Price จาก PTT โดยไม่ผ่าน WS Proxy ครับ  (2010-02-26)

ไม่มีการ Add Web Refference (Web Service Proxy) จะใช้ HttpRequest และ HttpResponse นะครับ

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Xml;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //com.pttplc.www.PTTInfo a = new WindowsFormsApplication1.com.pttplc.www.PTTInfo();
            //MessageBox.Show(a.GetOilPrice("thai",25,02,2553));
        }

        private void button2_Click(object sender, EventArgs e)
        {
           // String strSoapMessage = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><HelloWorld xmlns='http://tempuri.org/' /></soap:Body></soap:Envelope>";
            String strSoapMessage = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetOilPrice xmlns='http://www.pttplc.com/ptt_webservice/'><Language>string</Language><DD>26</DD><MM>02</MM><YYYY>2553</YYYY></GetOilPrice></soap:Body></soap:Envelope>";

...............................................


อ่านต่อคลิกที่นี้


 C# Soap Client โดยไม่ผ่าน WS Proxy  (2010-02-25)

ที่ทำเช่นนี้ก็เพื่อนจะสามารถระบุ Web service และเรียก Method ได้ตอน runtime ไม่ต้องผ่าน Proxy นะครับ

 String strSoapMessage = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><HelloWorld xmlns='http://tempuri.org/' /></soap:Body></soap:Envelope>";
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:3421/Service1.asmx/HelloWorld");
            webRequest.Headers.Add("SOAPAction", "http://localhost:3421/Service1.asmx/HelloWorld");
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            StreamWriter stm = new StreamWriter(webRequest.GetRequestStream(), Encoding.UTF8);
            stm.Write(strSoapMessage);
            stm.Flush();
            stm.Close();
            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
            //รอจนกว่าจะตอบกลับ
            asyncResult.AsyncWaitHandle.WaitOne();
            // get the response
            string soapResult;
            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
            {
                soapResult = rd.ReadToEnd();
            }
            MessageBox.Show(soapResult);

 ที่ผมต้องทำอย่างนี้ก็เพราะว่าผมต้องเรียก webservice จากข้างใน DLL อ่ะครับ


อ่านต่อคลิกที่นี้


 Run only 1 instance of program.  (2010-02-19)

พอดีน้องที่ทำงานถามว่าทำยังไง ผมใช้วิธีนี้ครับ ใครใช้วิธีอื่นที่ดีกว่านี้ก็โพสบอกกันบ้างนะครับ

 bool mutexCreated = false;
System.Threading.Mutex mutex = new System.Threading.Mutex(true, "ZengcodeProgram", out mutexCreated);

            if (!mutexCreated)
            {
                MessageBox.Show("Another instance is already running.");
                System.Diagnostics.Process.GetCurrentProcess().Kill();
                Close();
            }


อ่านต่อคลิกที่นี้


 c# เรียก web หรือ webservice ผ่าน SSL ครับ  (2010-02-18)

    หลังจากที่ลองมาร้อยแปดวิธี วิธีนี้ใช้งานได้ แต่ไม่แน่ใจว่าทำงานได้จริงหรือเปล่า ถ้าใครมีวิธีดีๆ ก็ แนะนำมานะครับ
ผมลองวิธีนี้แล้วโอเค แต่ยังไม่ได้ลองกับ webservice  ครับผม

      using System.Security.Cryptography.X509Certificates;

     private void button1_Click(object sender, EventArgs e)
        {

            MessageBox.Show(GetSSLPage("https://www.zengcode.com"));
        }

  


อ่านต่อคลิกที่นี้


 การส่งค่าให้ thread และรอรับค่าจาก thread ครับ  (2010-02-16)

โดยใช้ DELEGATE นะครับ ลองเอาไปประยุกต์กันดูนะครับ

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

.........................................................................


อ่านต่อคลิกที่นี้


 มี DLL สำหรับเขียน Log มาฝากครับ   (2010-02-16)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ZCLogger;

namespace TestSolution
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Logger.writeLog = true;  //default is true    true= write log file , false = not write log file
            Logger.debugMode = true; //default is flase   true=write debug log, false = not write debug log
           

            Logger.loggerPath = "C://Logs";
            Logger.PutLog("Info", 0, "test info");
            Logger.PutLog("Info", 100, "test info");
            Logger.PutLog("Info", 2, "test info");

            Logger.PutLog("Exception", 0, "test Exception");
            Logger.PutLog("Exception", 100, "test Exception");
            Logger.PutLog("Exception", 2, "test Exception");

            Logger.PutLog("SQL", 0, "Test SQL LOG");
            Logger.PutLog("SQL", 100, "Test SQL LOG");
            Logger.PutLog("SQL", 2, "Test SQL LOG");
            Logger.PutLog("sql", 2, "Test SQL LOG");

            Logger.PutLog("Debug", 0, "Test Debug LOG");
            Logger.PutLog("Debug", 0, "Test Debug LOG");
            Logger.PutLog("Debug", 0, "Test Debug LOG");
        }
    }
}

DLL File คลิกอ่านต่อ


อ่านต่อคลิกที่นี้


 Run Dos Command by C#  (2010-02-09)

public String RunCMD(String cmd)
        {
            System.Diagnostics.ProcessStartInfo sdpsinfo = new System.Diagnostics.ProcessStartInfo
            (cmd);
            // The following commands are needed to
            //redirect the standard output.
            // This means that it will //be redirected to the
            // Process.StandardOutput StreamReader
            // u can try other console applications
            //such as  arp.exe, etc
            sdpsinfo.RedirectStandardOutput = true;
            // redirecting the standard output
            sdpsinfo.UseShellExecute = false;
            // without that console shell window
            sdpsinfo.CreateNoWindow = true;
            // Now we create a process,
            //assign its ProcessStartInfo and start it
            System.Diagnostics.Process p =
            new System.Diagnostics.Process();
            p.StartInfo = sdpsinfo;
            p.Start();
            // well, we should check the return value here...
            //  capturing the output into a string variable...
            string res = p.StandardOutput.ReadToEnd();
            // do whatever u want to do with that output
            return res;
        }


อ่านต่อคลิกที่นี้


easy tracking
avis car rental discount code

This page took 0.012391 seconds to load.