4 changed files with 147 additions and 2 deletions
@ -0,0 +1,27 @@ |
|||
<Window x:Class="SunlightCentralizedControlManagement_SCCM_.WindowsView.MachineSelection" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.WindowsView" |
|||
xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" |
|||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" |
|||
mc:Ignorable="d" WindowStyle="None" |
|||
Title="MachineSelection" Height="300" Width="600"> |
|||
<Grid> |
|||
<ScrollViewer Margin="0" VerticalScrollBarVisibility="Auto"> |
|||
<WrapPanel Orientation="Horizontal" x:Name="MachineView" Background="White" Margin="0,0,0,60"> |
|||
</WrapPanel> |
|||
</ScrollViewer> |
|||
|
|||
<Button Content="{x:Static lang:Resources.YES}" HorizontalAlignment="Right" Height="35" Margin="0,0,50,10" |
|||
VerticalAlignment="Bottom" Width="80" Click="Button_Click"/> |
|||
<Button Content="{x:Static lang:Resources.Quit}" HorizontalAlignment="Right" Height="35" Margin="0,0,150,10" |
|||
VerticalAlignment="Bottom" Width="80" Click="Button_Quit"/> |
|||
<ComboBox HorizontalAlignment="Left" Height="30" Margin="150,80,0,10" x:Name="comboBoxMachine" |
|||
VerticalAlignment="Bottom" Width="200" FontSize="15" IsEditable="True" IsReadOnly="True" BorderBrush="#FF673AB7" |
|||
DropDownClosed="comboBoxMachine_DropDownClosed"/> |
|||
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,80,0,10" TextWrapping="Wrap" |
|||
Text="{x:Static lang:Resources.MachineGroup}" VerticalAlignment="Bottom" Width="120" FontSize="25"/> |
|||
</Grid> |
|||
</Window> |
@ -0,0 +1,102 @@ |
|||
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 |
|||
{ |
|||
/// <summary>
|
|||
/// MachineSelection.xaml 的交互逻辑
|
|||
/// </summary>
|
|||
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 SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|||
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
|
|||
private string MACHINEDATA; |
|||
DataTable machine_table; |
|||
private List<string> machine; |
|||
|
|||
CheckBox[] checkBoxes = new CheckBox[999]; |
|||
public MachineSelection() |
|||
{ |
|||
InitializeComponent(); |
|||
|
|||
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|||
SQLiteHelpers.Open(); //打开数据库
|
|||
comboBoxMachine.ItemsSource = SQLiteHelpers.ExecuteDataSet("select * from MachinesGroups order by Name desc", null).Tables[0]. |
|||
AsEnumerable().Select(rowdata => rowdata.Field<string>("Name")).ToList();//转换代码
|
|||
machine_table = SQLiteHelpers.ExecuteDataSet("select * from Machines order by Name desc", null).Tables[0]; |
|||
SQLiteHelpers.Close(); //关闭连接
|
|||
|
|||
machine = machine_table.AsEnumerable().Select(rowdata => rowdata.Field<string>("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 comboBoxMachine_DropDownClosed(object sender, EventArgs e)//选择设备组
|
|||
{ |
|||
MachineView.Children.Clear(); |
|||
machine = machine_table.Select("Groups='"+ comboBoxMachine.Text+"'"). |
|||
AsEnumerable().Select(rowdata => rowdata.Field<string>("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; |
|||
} |
|||
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; } |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue