private void btnSendFiles_Click(object sender, EventArgs e) { try { var sbdd = new InTheHand.Windows.Forms.SelectBluetoothDeviceDialog(); sbdd.ShowAuthenticated = true; sbdd.ShowRemembered = true; sbdd.ShowUnknown = true; InTheHand.Net.Sockets.BluetoothDeviceInfo deviceInfo = null; OpenFileDialog openFileDialog = new OpenFileDialog(); if (sbdd.ShowDialog() == DialogResult.OK) { deviceInfo = sbdd.SelectedDevice; if (openFileDialog.ShowDialog() == DialogResult.OK) { var file = openFileDialog.FileName; var uri = new Uri("obex://" + deviceInfo.DeviceAddress + "/" + file); var request = new InTheHand.Net.ObexWebRequest(uri); request.ReadFile(file); var response = (InTheHand.Net.ObexWebResponse)request.GetResponse(); MessageBox.Show(response.StatusCode.ToString()); response.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public Form1() { InitializeComponent(); InTheHand.Windows.Forms.SelectBluetoothDeviceDialog sbdd = new InTheHand.Windows.Forms.SelectBluetoothDeviceDialog(); sbdd.Info = "Testing dialog"; sbdd.ShowDialog(); }
private void buttonSelectBluetooth_Click(object sender, EventArgs e)//选择远程蓝牙设备 { InTheHand.Windows.Forms.SelectBluetoothDeviceDialog dialog = new InTheHand.Windows.Forms.SelectBluetoothDeviceDialog(); dialog.ShowRemembered = true; //显示已经记住的蓝牙设备 dialog.ShowAuthenticated = true; //显示认证过的蓝牙设备 dialog.ShowUnknown = true; //显示位置蓝牙设备 if (dialog.ShowDialog() == DialogResult.OK) { sendAddress = dialog.SelectedDevice.DeviceAddress;//获取选择的远程蓝牙地址 labelAddress.Text = "地址:" + sendAddress.ToString() + " 设备名:" + dialog.SelectedDevice.DeviceName; } }
private InTheHand.Net.BluetoothAddress UserSelectDev() { InTheHand.Windows.Forms.SelectBluetoothDeviceDialog dialog = new InTheHand.Windows.Forms.SelectBluetoothDeviceDialog(); dialog.ShowRemembered = true; dialog.ShowAuthenticated = true; dialog.ShowUnknown = true; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { return(dialog.SelectedDevice.DeviceAddress); } return(null); }
private void button1_Click(object sender, EventArgs e) { if (this.Text.Equals("Thay đổi Câu hỏi Bí mật")) { using (Form3 frm3 = new Form3()) { frm3.ShowDialog(); } Close(); return; } if (this.Text.Equals("Thay đổi thiết bị")) { InTheHand.Windows.Forms.SelectBluetoothDeviceDialog dialog = new InTheHand.Windows.Forms.SelectBluetoothDeviceDialog(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { BluetoothDeviceInfo selected = dialog.SelectedDevice; BluetoothClient bc = new BluetoothClient(); if (selected.Authenticated == false) { bool paired = BluetoothSecurity.PairRequest(selected.DeviceAddress, null); if (!paired) { //Không thể repair MessageBox.Show("Không thể Pair thiết bị", "Pair không thành công", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (bc.Connected == false) { try { bc.Connect(new BluetoothEndPoint(selected.DeviceAddress, InTheHand.Net.Bluetooth.BluetoothService.Handsfree)); //.BluetoothService.SerialPort selected.SetServiceState(InTheHand.Net.Bluetooth.BluetoothService.Handsfree, true); //.BluetoothService.SerialPort } catch (Exception) { MessageBox.Show("Thiết bị Bluetooth không hỗ trợ dịch vụ Hands-Free", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } selected.Refresh(); if (selected.Connected) { try { connectDatabase(); string stm1 = "UPDATE `folderlock`.`device` SET `MacAddress`='" + selected.DeviceAddress.ToString() + "' WHERE `id`='1'"; MySqlCommand cmd1 = new MySqlCommand(stm1, conn); cmd1.ExecuteNonQuery(); AnswerSuccess = true; Close(); } catch (Exception ex) { MessageBox.Show("Không thể thay đổi thiết bị trong cơ sở dữ liệu", "Không thể thay đổi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { //Không thể connect MessageBox.Show("Không thể kết nối với thiết bị", "Không thành công", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } return; } if (textBox2.Text.Trim().Equals("")) { MessageBox.Show("Bạn vui lòng chọn câu hỏi", "Chọn câu hỏi", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (textBox1.Text.Trim().Equals("")) { MessageBox.Show("Bạn vui lòng nhập vào câu trả lời", "Trả lời câu hỏi", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } connectDatabase(); string stm = "SELECT answer FROM folderlock.recovery where question like '" + textBox2.Text + "'"; MySqlCommand cmd = new MySqlCommand(stm, conn); MySqlDataReader rdr = null; rdr = cmd.ExecuteReader(); if (rdr.Read()) { if (rdr.GetString(0).Equals(textBox1.Text)) { //trả lời đúng DialogResult mess = MessageBox.Show("Đã trả lời đúng câu hỏi. Bạn có muốn chọn thiết bị điện thoại khác để đăng nhập?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (mess == DialogResult.Yes) { InTheHand.Windows.Forms.SelectBluetoothDeviceDialog dialog = new InTheHand.Windows.Forms.SelectBluetoothDeviceDialog(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { BluetoothDeviceInfo selected = dialog.SelectedDevice; //BluetoothDeviceInfo bd; BluetoothClient bc = new BluetoothClient(); if (selected.Authenticated == false) { bool paired = BluetoothSecurity.PairRequest(selected.DeviceAddress, null); if (!paired) { //Không thể repair MessageBox.Show("Không thể Pair thiết bị", "Pair không thành công", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (bc.Connected == false) { try { bc.Connect(new BluetoothEndPoint(selected.DeviceAddress, InTheHand.Net.Bluetooth.BluetoothService.Handsfree)); //.BluetoothService.SerialPort selected.SetServiceState(InTheHand.Net.Bluetooth.BluetoothService.Handsfree, true); //.BluetoothService.SerialPort } catch (Exception) { MessageBox.Show("Thiết bị Bluetooth không hỗ trợ dịch vụ Hands-Free", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } selected.Refresh(); if (selected.Connected) { try { connectDatabase(); string stm1 = "UPDATE `folderlock`.`device` SET `MacAddress`='" + selected.DeviceAddress.ToString() + "' WHERE `id`='1'"; MySqlCommand cmd1 = new MySqlCommand(stm1, conn); cmd1.ExecuteNonQuery(); MessageBox.Show("Đã thay đổi thành công thiết bị đăng truy cập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); AnswerSuccess = false; getMacEvent(); Close(); } catch (Exception ex) { MessageBox.Show("Không thể thay đổi thiết bị trong cơ sở dữ liệu", "Không thể thay đổi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { //Không thể connect MessageBox.Show("Không thể kết nối với thiết bị", "Không thành công", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } return; } else { if (ChangeSizeMainFormEvent != null) { ChangeSizeMainFormEvent(463, 383); } AnswerSuccess = true; this.Close(); return; } //Close(); } else { //trả lời sai DialogResult mess1 = MessageBox.Show("Bạn đã trả lời sai câu hỏi. Bạn có muốn trả lời lại câu hỏi không?", "Trả lời sai câu hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (mess1 == DialogResult.No) { this.Close(); } } } else { MessageBox.Show("Không tìm thấy câu hỏi trong Cơ Sở Dữ Liệu", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } }