using SunlightCentralizedControlManagement_SCCM_.ViewModel; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; 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.Shapes; using System.Xml.Linq; using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; namespace SunlightCentralizedControlManagement_SCCM_.WindowsView { /// /// MachineSelection.xaml 的交互逻辑 /// public partial class MachineSelection : Window { public string data { get; set; } //声明一个更新Address的委托 public delegate void AddressUpdateHandler(object sender, AddressUpdateEventArgs e); //声明一个更新Address的事件 public event AddressUpdateHandler AddressUpdated; private string MACHINEDATA; DataTable machine_table; private List machine; CheckBox[] checkBoxes = new CheckBox[999]; public MachineSelection() { InitializeComponent(); comboBoxMachine.ItemsSource = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from MachinesGroups order by Name desc", null).Tables[0]. AsEnumerable().Select(rowdata => rowdata.Field("Name")).ToList();//转换代码 machine_table = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from Machines order by Name desc", null).Tables[0]; machine = machine_table.AsEnumerable().Select(rowdata => rowdata.Field("Name")).ToList();//转换代码 for (int i = 0; i < machine.Count; i++) { checkBoxes[i] = new CheckBox(); checkBoxes[i].Content = machine[i].ToString(); checkBoxes[i].FontSize = 20; checkBoxes[i].Width = 80; checkBoxes[i].Height = 50; checkBoxes[i].IsEnabled = false; MachineView.Children.Add(checkBoxes[i]); } } private void comboBoxMachine_DropDownClosed(object sender, EventArgs e)//选择设备组 { MachineView.Children.Clear(); machine = machine_table.Select("Groups='"+ comboBoxMachine.Text+"'"). AsEnumerable().Select(rowdata => rowdata.Field("Name")).ToList();//转换代码 for (int i = 0; i < machine.Count; i++) { checkBoxes[i] = new CheckBox(); checkBoxes[i].Content = machine[i].ToString(); checkBoxes[i].FontSize = 20; checkBoxes[i].Width = 80; checkBoxes[i].Height = 50; MachineView.Children.Add(checkBoxes[i]); } } private void Button_Click(object sender, RoutedEventArgs e)//确认按钮 { for (int i = 0; i < machine.Count; i++) { if((bool)checkBoxes[i].IsChecked) MACHINEDATA= MACHINEDATA+"+"+ checkBoxes[i].Content; } if(!String.IsNullOrEmpty(MACHINEDATA)) AddressUpdated(this, new AddressUpdateEventArgs(MACHINEDATA.Remove(0, 1))); this.Close(); //关闭窗口 } private void Button_Quit(object sender, RoutedEventArgs e)//退出 { this.Close(); } public class AddressUpdateEventArgs : System.EventArgs { public AddressUpdateEventArgs(string dGroups) { this.Groups = dGroups; } public string Groups { get; set; } } } }