using InTheHand.Net.Bluetooth; using MonitoringTechnology.Models; using MonitoringTechnology.ViewModels; using MonitoringTechnology.Views; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; using WpfBleApp.Ble; namespace MonitoringTechnology { /// /// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : Window { private DispatcherTimer ShowTimer; public static ErrorMessageModel EM { get; set; } = new ErrorMessageModel(); public static MainViewModel mainViewModel = new MainViewModel(); public static BleDevice _bleDevice = new BleDevice(); //保存已选择的蓝牙设备信息 public static SystemOperationView systemOperationView = new SystemOperationView(); public MainWindow() { InitializeComponent(); this.DataContext = mainViewModel; this.MaxHeight = SystemParameters.PrimaryScreenHeight;//防止最大化时系统任务栏被遮盖 //添加timer ShowTimer = new System.Windows.Threading.DispatcherTimer(); ShowTimer.Tick += new EventHandler(showTimer); ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); ShowTimer.Start(); } //日期 public void showTimer(object sender, EventArgs e) { this.Datatime.Text = ""; this.Date.Text = ""; this.week.Text = ""; //获得年月日 //this.Datatime.Text += " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //yyyy年MM月dd日 this.Datatime.Text += " " + DateTime.Now.ToString("HH:mm:ss"); //yyyy年MM月dd日 this.Date.Text += " " + DateTime.Now.ToString("yyyy-MM-dd"); this.week.Text += System.DateTime.Today.ToString("dddd", new System.Globalization.CultureInfo("zh-CN")); } /// /// 主窗口移动事件 /// /// /// private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); } /// /// 主窗口双击最大化事件 /// /// /// private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e) { //判断窗口是否正常,正常则放大,否则还原正常窗口 if (this.WindowState == WindowState.Normal) this.WindowState = WindowState.Maximized; else this.WindowState = WindowState.Normal; } /// /// 主窗口关闭按钮事件 /// /// /// private void Button_Click(object sender, RoutedEventArgs e) { if (systemOperationView.buttonConnect.Content.ToString() == "断开连接") { systemOperationView.AddLog("蓝牙连接未断开!请先断开后,再关闭主窗口!"); MessageBox.Show("蓝牙连接未断开!请先断开后,再关闭主窗口!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } else { this.Close(); } } /// /// 主窗口最小化事件 /// /// /// private void Button_Click_1(object sender, RoutedEventArgs e) { this.WindowState = WindowState.Minimized; } /// /// 主窗口最大化事件 /// /// /// private void Button_Click_2(object sender, RoutedEventArgs e) { //判断是否以及最大化,最大化就还原窗口,否则最大化 if (this.WindowState == WindowState.Maximized) this.WindowState = WindowState.Normal; else this.WindowState = WindowState.Maximized; } BluetoothRadio Radio = null; //蓝牙适配器 /// /// 初始化窗口之后判断当前电脑蓝牙是否已开启 /// /// /// private void Window_Loaded(object sender, RoutedEventArgs e) { Radio = BluetoothRadio.PrimaryRadio;//获取当前PC的蓝牙适配器 if (Radio == null) { //SystemOperationView.EM.BlueConnectionMessage = "电脑蓝牙未打开或者未发现!请打开电脑蓝牙后重新尝试!"; MessageBox.Show("电脑蓝牙未打开或者未发现!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } } } }