using Bro.UI.Config.Helper;
|
using System;
|
using System.Collections.Generic;
|
using System.Threading;
|
using System.Windows.Forms;
|
|
namespace Bro.UI.Config.MenuForms
|
{
|
//[DockOption(WeifenLuo.WinFormsUI.Docking.DockState.DockLeft, 150, 0)]
|
//[MenuNode("Device", "设备列表", 1, "View1", true)]
|
public partial class FrmDevices : MenuFrmBase
|
{
|
public event Action<List<string>> OnCheckedDeviceListChanged;
|
|
readonly System.Threading.Timer _checkChangedTimer = null;
|
public FrmDevices()
|
{
|
InitializeComponent();
|
|
_checkChangedTimer = new System.Threading.Timer(OnCheckChangedDone, null, Timeout.Infinite, Timeout.Infinite);
|
}
|
|
private void OnCheckChangedDone(object state)
|
{
|
List<string> checkedDeviceIdList = new List<string>();
|
foreach (Control ctrl in plMain.Controls)
|
{
|
var c = (ctrl as CtrlDeviceState);
|
|
if (c != null && c.IsChecked)
|
{
|
checkedDeviceIdList.Add(c.Device.Id);
|
}
|
}
|
|
OnCheckedDeviceListChanged?.Invoke(checkedDeviceIdList);
|
}
|
|
public void OnDeviceDisplayFrmClosed(string deviceId)
|
{
|
foreach (Control ctrl in plMain.Controls)
|
{
|
var c = (ctrl as CtrlDeviceState);
|
|
if (c != null && c.Device.Id == deviceId)
|
{
|
c.IsChecked = false;
|
}
|
}
|
}
|
|
public override void OnProcessUpdated()
|
{
|
if (InvokeRequired)
|
{
|
Invoke(new Action(() => OnProcessUpdated()));
|
}
|
else
|
{
|
plMain.Controls.Clear();
|
|
Process.DeviceCollection.ForEach(d =>
|
{
|
CtrlDeviceState deviceStateCtrl = new CtrlDeviceState(d);
|
deviceStateCtrl.OnDeviceCheckedChanged += DeviceStateCtrl_OnDeviceCheckedChanged;
|
plMain.Controls.Add(deviceStateCtrl);
|
});
|
|
DeviceStateCtrl_OnDeviceCheckedChanged(null, true);
|
}
|
}
|
|
private void DeviceStateCtrl_OnDeviceCheckedChanged(string deviceId, bool isChecked)
|
{
|
_checkChangedTimer.Change(1000, Timeout.Infinite);
|
}
|
}
|
}
|