Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > (C#) .NET Smart Device เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6, Hand Held,...




Clound SSD Virtual Server

(C#) .NET Smart Device เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6, Hand Held,...

 
  .NET Smart Device Project เป็น Application ใช้สำหรับเขียนโปรแกรมเพื่อทำงานบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6, Hand Held,... ใน Visual Studio สามารถสร้าง Application ของ Smart Device นั้น สามารถทำได้อย่างง่ายได้ รูปแบบการเขียนหรือแม้แต่ Event ต่าง ๆ ก็ไม่ต่างอะไรกับ Windows Form Applciation และทั้งยังสามารถพัฒนาใช้งานได้กับหลาย ๆ Target platform เช่น

Framework : 1,2,3,4

- Pocket PC 2003
- Windows CE
- Windows Mobile 5.0 Pockget PC SDK
- Windows Mobile 5.0 Smartphone PC SDK

ในการเขียน Application ประเภท Smart Device สามารถทำการเชื่อมต่อกับอุปกรณ์ จริง หรือจะทำการใช้ตัว Emulator ที่อยู่ใน .NET Framework เพื่อทำการจำลองและใช้สำหรับ Debug โปรแกรม แต่ถ้าหากทำการเชื่อมต่อกับอุปกรณ์จริง ๆ จะต้องทำการติดตั้งตัวโปรแกรม Microsoft ActiveSync หรือใน Windows 7,Vista ขึ้นไปจะใช้ Windows Mobile Device Center สำหรับเชื่อมต่อกับอุปกรณ์

สำหรับบทความนี้มีทั้งที่เป็นภาษา VB.NET และ C# ครับ สามารถเลือกอ่านได้ตามความถนัดได้เลย

Language Code : VB.NET || C#


ในตัวอย่างนี้ผมได้ใช้ Tool ของ Visual Studio 2008 บน .NET Framework 3.5

ให้เปิด Tool ขึ้นมาพร้อมกับ New Project

.NET Smart Device

Project type เลือกเป็น VB.NET หรือ C# ก็แล้วแต่ความถนัด


.NET Smart Device

เลือกเป็น Device Application และเราจะต้องทดสอบบน platform ของ Windows Mobile 5.0 Pockget PC SDK


.NET Smart Device

หน้าจอของ Form ที่พร้อมจเขียนโปรแกรม มีตัวอย่างเป็นหน้าจอบน Pocket PC ให้ดูเป็นตัวอย่าง


.NET Smart Device

อันนี้เป็น Form Default ที่สร้างมาให้ หากไม่ต้องการก็ลบทิ้งได้เลย









.NET Smart Device

สามารถเพิ่ม Form ขึ้นมาใหม่โดยคลิกขวาที่ Project -> Add -> New Item....


.NET Smart Device

เลือก Windows Form และกำหนดชื่อ Form


.NET Smart Device

ได้ Form ขึ้นมาใหม่แล้ว


.NET Smart Device

กรณีที่มีการเปลี่ยน Form หลัก เราจะต้องกำหนด ตัว Form ที่เป็น Form แรกสุดที่จะใช้สำหรับการ Run application โดยให้แก้ไขที่ไฟล์ Program.cs ตามรูป Application.Run(new frmMain());


.NET Smart Device

ทดสอบการรัน Application โดยคลิกที่ปุ่ม Start Debugging


.NET Smart Device

กรณีที่เราไม่ได้ทำการเชื่อมต่อกับอุปกรณ์ที่มีอยู่จริงให้เลือก USA Windows Mobile 5.0 Pocket PC R2 Emulator หรือ กรณีที่ได้เชื่อมต่อแล้วก็ให้เลือก Windows Mobile 5.0 Packet PC Device R2 ได้เลย


.NET Smart Device

ในตัวอย่างได้เลือกเป็นแบบ Emulator ซึ่งก็จะได้ผลดังรูป ซึ่งตอนนี้เป็นหน้าว่างเปล่า เพราะยังไม่มีการใส่ข้อความหรือเขียนฟังก์ชั่นเข้าไป


ในตัวอย่างนี้มีการเรียกใช้งาน Database ของ SqlServerCe ด้วย

.NET Smart Device

ให้คลิกขวที่ Project -> Add -> New Item...


.NET Smart Device

เลือก Database File พร้อมกับกำหนดชื่อ Database ด้วย


.NET Smart Device

Database ถุกสร้างขึ้นมาแล้ว


.NET Smart Device

ทดสอบการสร้าง Table โดยไปที่ Server Explorer (อยู่ด้านซ้าย) คลิกที่ Database ที่เราสร้างขึ้นมา


.NET Smart Device

และภายใต้ Table ให้คลิกขวาเลือก Create Table ให้สร้างตารางชื่อ mytable โดยมีฟิว์ id,name,email (id เป็น primary key และ IdentityIncrement) และ save ถือเป็นเสร็จสิ้นการสร้าง Table




ในตัวอย่างนี้จะประกอบด้วย 4 Form คือ
1. frmMain เป็นหน้าแรกของ Application
2. frmHome เป็นหน้าหลักของโปรแกรมใช้ DataGrid สำหรับเรียกข้อมูลมาแสดง (เพื่อลิงค์ไปยังการ เพิ่ม/แก้ไข/ลบ ข้อมูล)
3. frmAdd เป็นหน้าสำหรับเพิ่มข้อมูล
4. frmEdit เป็นหน้าสำหรับแก้ไขข้อมูล

frmMain

.NET Smart Device

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

namespace SmartDeviceProject
{
    public partial class frmMain : Form
    {
        // By https://www.thaicreate.com (mr.win)//

        public frmMain()
        {
            InitializeComponent();
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            frmHome f = new frmHome();
            f.Show();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("Are you sure to exit?", "Confirm.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private readonly byte VK_OFF = 0xdf;
        private readonly byte KEYEVENTF_KEYUP = 0x2;

        [System.Runtime.InteropServices.DllImport("coredll.dll", SetLastError = true)]
        public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

        private void btnShutdown_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure to shutdown?", "Confirm.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                keybd_event(VK_OFF, 0, 0, 0);
                keybd_event(VK_OFF, 0, KEYEVENTF_KEYUP, 0);
            }
        }

    }
}



frmHome

.NET Smart Device

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

namespace SmartDeviceProject
{
    public partial class frmHome : Form
    {
        // By https://www.thaicreate.com (mr.win)//

        public frmHome()
        {
            InitializeComponent();
        }

        private void frmHome_Load(object sender, EventArgs e)
        {
            BindDataGrid();
        }

        private void BindDataGrid()
        {
                SqlCeConnection myConnection = default(SqlCeConnection);
                DataTable dt = new DataTable();
                SqlCeDataAdapter Adapter = default(SqlCeDataAdapter);
                myConnection = new SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ) + "\\AppDatabase1.sdf;"));
                myConnection.Open();
                SqlCeCommand myCommand = myConnection.CreateCommand();
                myCommand.CommandText = "SELECT [id], [name], [email] FROM [mytable]";
                myCommand.CommandType = CommandType.Text;

                Adapter = new SqlCeDataAdapter(myCommand);
                Adapter.Fill(dt);

                myConnection.Close();

                DataGridTableStyle tableStyle = new DataGridTableStyle();
                tableStyle.MappingName = dt.TableName;


                DataGridTextBoxColumn column = new DataGridTextBoxColumn();
                column.MappingName = "id";
                column.HeaderText = "ID";
                column.Width = 30;
                tableStyle.GridColumnStyles.Add(column);

                column = new DataGridTextBoxColumn();
                column.MappingName = "name";
                column.HeaderText = "Name";
                column.Width = 40;
                tableStyle.GridColumnStyles.Add(column);

                column = new DataGridTextBoxColumn();
                column.Width = 70;
                column.MappingName = "email";
                column.HeaderText = "Email";
                tableStyle.GridColumnStyles.Add(column);

                this.dgName.DataSource = dt;

                this.dgName.TableStyles.Clear();
                this.dgName.TableStyles.Add(tableStyle);

                dt = null;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAdd f = new frmAdd();
            f.Show();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
                   frmEdit f =  new frmEdit();
                    f._strID = this.dgName[this.dgName.CurrentRowIndex, 0].ToString();
                    f.Show();
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure to delete?", "Confirm.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                string strID = this.dgName[this.dgName.CurrentRowIndex, 0].ToString();

                SqlCeConnection myConnection = default(SqlCeConnection);
                myConnection = new SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ) + "\\AppDatabase1.sdf;"));
                myConnection.Open();
                SqlCeCommand myCommand = myConnection.CreateCommand();
                myCommand.CommandText = "DELETE FROM [mytable] WHERE id = '" + strID + "'";
                myCommand.CommandType = CommandType.Text;
                myCommand.ExecuteNonQuery();
                myConnection.Close();
                MessageBox.Show("Delete Successfully");

                BindDataGrid();
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            frmMain f =  new frmMain();
            f.Show();
        }

    }
}









frmAdd

.NET Smart Device

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

namespace SmartDeviceProject
{
    public partial class frmAdd : Form
    {
        // By https://www.thaicreate.com (mr.win)//

        public frmAdd()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtName.Text))
            {
                MessageBox.Show("Please input (Name)");
                this.txtName.Focus();
                return;
            }

            if (string.IsNullOrEmpty(this.txtEmail.Text))
            {
                MessageBox.Show("Please input (Email)");
                this.txtEmail.Focus();
                return;
            }

            SqlCeConnection myConnection = default(SqlCeConnection);
            myConnection = new SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ) + "\\AppDatabase1.sdf;"));
            myConnection.Open();
            SqlCeCommand myCommand = myConnection.CreateCommand();
            myCommand.CommandText = "INSERT INTO [mytable] ([name], [email]) VALUES  " + " ('" + this.txtName.Text + "','" + this.txtEmail.Text + "' ) ";
            myCommand.CommandType = CommandType.Text;
            myCommand.ExecuteNonQuery();
            myConnection.Close();

            MessageBox.Show("Save Successfully");

            frmHome f = new frmHome();
            f.Show();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            frmHome f = new frmHome();
            f.Show();
        }

        private void txtName_GotFocus(object sender, EventArgs e)
        {
            this.inputPanel1.Enabled = true;
        }

        private void txtEmail_GotFocus(object sender, EventArgs e)
        {
            this.inputPanel1.Enabled = true;
        }

        private void txtName_LostFocus(object sender, EventArgs e)
        {
            this.inputPanel1.Enabled = false;
        }

        private void txtEmail_LostFocus(object sender, EventArgs e)
        {
            this.inputPanel1.Enabled = false;
        }

    }
}



frmEdit

.NET Smart Device

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

namespace SmartDeviceProject
{
    public partial class frmEdit : Form
    {
        // By https://www.thaicreate.com (mr.win)//

        public frmEdit()
        {
            InitializeComponent();
        }

        string strID = "";
        public string _strID
        {
            get { return strID; }
            set { strID = value; }
        }

        private void frmEdit_Load(object sender, EventArgs e)
        {
            SqlCeConnection myConnection = default(SqlCeConnection);
            DataTable dt = new DataTable();
            SqlCeDataAdapter Adapter = default(SqlCeDataAdapter);
            myConnection = new SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ) + "\\AppDatabase1.sdf;"));
            myConnection.Open();
            SqlCeCommand myCommand = myConnection.CreateCommand();
            myCommand.CommandText = "SELECT [id], [name], [email] FROM [mytable] WHERE id = '" + strID + "' ";
            myCommand.CommandType = CommandType.Text;

            Adapter = new SqlCeDataAdapter(myCommand);
            Adapter.Fill(dt);

            myConnection.Close();

            if (dt.Rows.Count > 0)
            {
                this.txtName.Text = dt.Rows[0]["name"].ToString();
                this.txtEmail.Text = dt.Rows[0]["email"].ToString();
            }

            dt = null;
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtName.Text))
            {
                MessageBox.Show("Please input (Name)");
                this.txtName.Focus();
                return;
            }

            if (string.IsNullOrEmpty(this.txtEmail.Text))
            {
                MessageBox.Show("Please input (Email)");
                this.txtEmail.Focus();
                return;
            }

            SqlCeConnection myConnection = default(SqlCeConnection);
            myConnection = new SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ) + "\\AppDatabase1.sdf;"));
            myConnection.Open();
            SqlCeCommand myCommand = myConnection.CreateCommand();
            myCommand.CommandText = "UPDATE [mytable] SET " + " [name] = '" + this.txtName.Text + "', [email] = '" + this.txtEmail.Text + "'  " + " WHERE id = '" + strID + "' ";
            myCommand.CommandType = CommandType.Text;
            myCommand.ExecuteNonQuery();
            myConnection.Close();

            MessageBox.Show("Update Successfully");

            frmHome f = new frmHome();
            f.Show();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            frmHome f = new frmHome();
            f.Show();
        }

        private void txtEmail_GotFocus(object sender, EventArgs e)
        {
            this.inputPanel1.Enabled = true;
        }

        private void txtEmail_LostFocus(object sender, EventArgs e)
        {
            this.inputPanel1.Enabled = true;
        }

        private void txtName_GotFocus(object sender, EventArgs e)
        {
            this.inputPanel1.Enabled = false;
        }

        private void txtName_LostFocus(object sender, EventArgs e)
        {
            this.inputPanel1.Enabled = false;
        }

    }
}





ทดสอบการรันโปรแกรมโดยคิกที่ Start Debugging

.NET Smart Device

เข้าสู่หน้า Main


.NET Smart Device

หน้า Home


.NET Smart Device

หน้า Add ข้อมูล


.NET Smart Device

หร้า Edit ข้อมูล


.NET Smart Device

สำหรับลบข้อมูล


สำหรับตัวอย่างทั้งหมดนี้สามารถดาวน์โหลด Code ได้จากข้างล่าง โดยมีทั้งภาษา VB.NET และ C# และบทความนี้เป็นเพียงการสอนเบื้องต้นเท่านั้น เพื่อเป็นพื้นฐานในการต่อยอดในการพัฒนาโปรแกรมที่มีความซับซ้อนและการใช้งานที่หลากหลาย



บทความที่เกี่ยวข้อง
Go to : Shared Folder or Map Drive in Emulator Smart Device Mobile Application
Go to : Smart Device Mobile Application Read and Write Text File


       
Bookmark.   
       

 

  By : TC Admin
  Score Rating : -
  Create Date : 2010-09-02 21:19:09
  Download : Download  (C#) .NET Smart Device  เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window  Mobile 5-6, Hand Held,... (1.50 MB)
     

Clound SSD Virtual Server
-->
Related Links
ASP.NET เรียก PHP กับฐานข้อมูล MySQL ผ่าน Web Service และการรับส่งค่าผ่านเว็บเซอร์วิส
ASP.NET เรียก PHP กับฐานข้อมูล MySQL ผ่าน Web Service และการรับส่งค่าผ่านเว็บเซอร์วิส
การสร้างเว็บเซอร์วิสด้วย php กับฐานข้อมูล mysql และทำการเรียก web service ด้วย asp.net ซึ่งอยู่ในฝั่ง client โดยทำการรับส่งข้อมูลระหว่าง php กับ asp.net
Rating :
Update :
2017-03-17 21:21:37 View : 17,041
Generating Word Document in .NET Framework
Generating Word Document in .NET Framework
สร้างไฟล์เอกสาร Word Document บน Windows Application และ Console Application ด้วย Framework
Rating :
Update :
2017-03-24 21:20:55 View : 6,557
VB.NET/C# Connect to SQL Server Using ADO.NET พื้นฐานกับ SQL Server and ADO.NET
VB.NET/C# Connect to SQL Server Using ADO.NET พื้นฐานกับ SQL Server and ADO.NET
SQL Server เชื่อมติดต่อผ่าน ADO.NET เพื่อเขียนโปรแกรมด้วยภาษา VB.NET และ C#
Rating :
Update :
2017-03-24 21:30:04 View : 62,301
ออกรายงาน Crystal Report บน Web(ASP.NET) Step by Step
ออกรายงาน Crystal Report บน Web(ASP.NET) Step by Step
ตัวอย่างการออกรายงานบน crystal report บนเว็บ web(asp.net) อธิบายขั้นตอนทีล่ะ step เข้าใจง่าย ทำงานได้จริง
Rating :
Update :
2017-03-17 21:19:24 View : 62,197
VB.NET/C# Create JSON (DataContractJsonSerializer) Serialize and Deserialize
VB.NET/C# Create JSON (DataContractJsonSerializer) Serialize and Deserialize
มาใช้ DataContractJsonSerializer ในการสร้างไฟล์ JSON และ อ่านค่า JSON (Serialize and Deserialize) กันดีกว่า
Rating :
Update :
2017-03-17 21:27:34 View : 21,017
สร้าง Sub Report (Subreport) บน Crystal Report แบบ Step by Step (VB.NET /C#)
สร้าง Sub Report (Subreport) บน Crystal Report แบบ Step by Step (VB.NET /C#)
การสร้าง Sub Report บน Crystal Report และการ Link ข้อมูลระหว่าง Main Report กับ Sub Report รวมทั้งการ Set DataSource ให้กับ Sub Report
Rating :
Update :
2017-03-24 21:34:46 View : 53,804
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่

Inline