|
 |
|
ช่วยหน่อยครับ....ผมเขียนให้โปรแกรม C# วนลูปไม่ได้ครับ... |
|
 |
|
|
 |
 |
|
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace BluetoothOPPClientDemo
{
public partial class fmMain : Form
{
public fmMain()
{
InitializeComponent();
}
private void fmMain_Load(object sender, EventArgs e)
{
wclAPI.Load();
}
private void fmMain_FormClosed(object sender, FormClosedEventArgs e)
{
wclAPI.Unload();
}
private void btDiscover_Click(object sender, EventArgs e)
{
wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
{
Radios = null;
return;
}
wcl.wclErrors.wclShowError(wclBluetoothDiscovery.Discovery(Radios[0]));
Radios = null;
}
private void wclBluetoothDiscovery_OnDiscoveryStarted(object sender, wcl.wclBluetoothDiscoveryStartedEventArgs e)
{
lvDevices.Items.Clear();
}
private void wclBluetoothDiscovery_OnDiscoveryComplete(object sender, wcl.wclBluetoothDiscoveryCompleteEventArgs e)
{
if (e.Devices == null)
MessageBox.Show("Error discovering");
else
if (e.Devices.Count == 0)
MessageBox.Show("Nothing found");
else
for (uint i = 0; i < e.Devices.Count; i++)
{
wcl.wclBluetoothDevice Device = e.Devices[i];
ListViewItem Item = lvDevices.Items.Add(Device.Address);
string str = "";
Device.GetName(e.Radio, ref str);
Item.SubItems.Add(str);
}
//__________________________________วนลูปทั้งชุดด้านล่างพร้อมทั้งเพิ่มค่า [ ] ในฟังก์ชัน ขึ้นรอบละหนึ่ง lvDevices.Items[0].Text; จนครบจำนวน Items ใน lvDevices
if (lvDevices.Items.Count == 0)
MessageBox.Show("Select device");
else
{
wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
{
Radios = null;
return;
}
string DeAddress = lvDevices.Items[0].Text;
wclClient.BluetoothParams.Address = DeAddress;
wclClient.BluetoothParams.Radio = Radios[0];
wclClient.Transport = wcl.wclClientTransport.ctBluetooth;
wcl.wclErrors.wclShowError(wclClient.Connect());
Radios = null;
}
}
private void wclClient_OnConnect(object sender, wcl.wclConnectEventArgs e)
{
}
private void wclClient_OnDisconnect(object sender, EventArgs e)
{
}
private void btDisconnect_Click(object sender, EventArgs e)
{
wclClient.Disconnect();
}
private void btOpenOBEX_Click(object sender, EventArgs e)
{
wcl.wclErrors.wclShowError(wclClient.OpenOBEXSession());
if (OpenFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.FileStream Stream = new System.IO.FileStream(OpenFileDialog.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
String AFile = System.IO.Path.GetFileName(OpenFileDialog.FileName);
wcl.wclErrors.wclShowError(wclClient.Put(AFile, Stream));
}
}
private void wclClient_OnOBEXConnect(object sender, wcl.wclConnectEventArgs e)
{
}
private void wclClient_OnOBEXDisconnect(object sender, EventArgs e)
{
}
private void wclClient_OnOBEXProgress(object sender, wcl.wclOBEXProgressEventArgs e)
{
ProgressBar.Maximum = (int)e.Size;
ProgressBar.Value = (int)e.Position;
}
private void wclClient_OnOBEXPutComplete(object sender, wcl.wclConnectEventArgs e)
{
ProgressBar.Value = 0;
if (e.Error == wcl.wclErrors.WCL_E_SUCCESS)
MessageBox.Show("Put complete with success");
else
MessageBox.Show("Put complete with error: " + e.Error.ToString());
wclClient.Disconnect();
wcl.wclErrors.wclShowError(wclClient.CloseOBEXSession());
}
}
}
Tag : .NET, C#, VS 2008 (.NET 3.x)

|
|
 |
 |
 |
 |
Date :
2012-01-31 17:04:14 |
By :
konmuen |
View :
1295 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Error ตรงไหน และ Error ว่าอะไรครับ 
|
 |
 |
 |
 |
Date :
2012-01-31 19:31:43 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
//วนลูปทั้งชุดด้านล่างและเพิ่มค่า [ ] ในฟังก์ชัน ขึ้นรอบละหนึ่ง lvDevices.Items[0].Text; จนครบจำนวน Items ใน lvDevices
if (lvDevices.Items.Count == 0)
MessageBox.Show("Select device");
else
{
wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
{
Radios = null;
return;
}
string DeAddress = lvDevices.Items[0].Text;
wclClient.BluetoothParams.Address = DeAddress;
wclClient.BluetoothParams.Radio = Radios[0];
wclClient.Transport = wcl.wclClientTransport.ctBluetooth;
wcl.wclErrors.wclShowError(wclClient.Connect());
Radios = null;
}
}
private void wclClient_OnConnect(object sender, wcl.wclConnectEventArgs e)
{
}
private void wclClient_OnDisconnect(object sender, EventArgs e)
{
}
private void btDisconnect_Click(object sender, EventArgs e)
{
wclClient.Disconnect();
}
private void btOpenOBEX_Click(object sender, EventArgs e)
{
wcl.wclErrors.wclShowError(wclClient.OpenOBEXSession());
if (OpenFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.FileStream Stream = new System.IO.FileStream(OpenFileDialog.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
String AFile = System.IO.Path.GetFileName(OpenFileDialog.FileName);
wcl.wclErrors.wclShowError(wclClient.Put(AFile, Stream));
}
}
private void wclClient_OnOBEXConnect(object sender, wcl.wclConnectEventArgs e)
{
}
private void wclClient_OnOBEXDisconnect(object sender, EventArgs e)
{
}
private void wclClient_OnOBEXProgress(object sender, wcl.wclOBEXProgressEventArgs e)
{
ProgressBar.Maximum = (int)e.Size;
ProgressBar.Value = (int)e.Position;
}
private void wclClient_OnOBEXPutComplete(object sender, wcl.wclConnectEventArgs e)
{
ProgressBar.Value = 0;
if (e.Error == wcl.wclErrors.WCL_E_SUCCESS)
MessageBox.Show("Put complete with success");
else
MessageBox.Show("Put complete with error: " + e.Error.ToString());
wclClient.Disconnect();
wcl.wclErrors.wclShowError(wclClient.CloseOBEXSession());
}
}
}
ในส่วนฟังก์ชันด้านล่างนี้จะเป็นการคอนเนคและส่งไฟล์ในหนึ่งครั้ง...แต่ตอนนี้ต้องการเขียนให้คอนเนคและส่งไฟล์ไปจนครบจำนวน Items ที่คนหาเจอแล้วมาแสดงใน lvDevices (ListView) และในแต่ละรอบที่ทำจะต้องให้ค่าใน [ ] ที่ฟังชัน lvDevices.Items[0].Text เพิ่มขึ้นจาก 0,1,2,3,ไปจนครบเท่ากับจำนวนที่มันมีใน lvDevices (ListView)
|
ประวัติการแก้ไข 2012-02-01 03:11:33
 |
 |
 |
 |
Date :
2012-01-31 22:32:29 |
By :
konmuen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|