Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Added Turn On and Off buttons on device grid
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondrabeck committed Dec 28, 2014
1 parent 14f35ac commit e9f8258
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
42 changes: 40 additions & 2 deletions zvs.WPF/DeviceControls/DeviceDataGridUC.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,46 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
<Button Margin="0 0 10 0"
Content="&#xe01d;" FontFamily="zVirtualScenes"
Click="ButtonOn_OnClick"
ToolTip="Turn-on">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialToolbarButton}">
<Setter Property="IsEnabled" Value="False" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=DeviceGrid, Path=SelectedItem.Type.UniqueIdentifier}" Value="Switch">
<Setter Property="IsEnabled" Value="True" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=DeviceGrid, Path=SelectedItem.Type.UniqueIdentifier}" Value="Dimmer">
<Setter Property="IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button Grid.Column="1" Margin="0 0 10 0"
Content="&#xe01e;" FontFamily="zVirtualScenes"
Click="ButtonOff_OnClick"
ToolTip="Turn-off">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialToolbarButton}">
<Setter Property="IsEnabled" Value="False" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=DeviceGrid, Path=SelectedItem.Type.UniqueIdentifier}" Value="Switch">
<Setter Property="IsEnabled" Value="True" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=DeviceGrid, Path=SelectedItem.Type.UniqueIdentifier}" Value="Dimmer">
<Setter Property="IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button Grid.Column="2"
Content="&#xe01a;" FontFamily="zVirtualScenes"
Click="ButtonDeleteDevice_OnClick"
ToolTip="Delete Device">
Expand All @@ -251,7 +289,7 @@
</Style>
</Button.Style>
</Button>
<Button Grid.Column="1" Margin="10 0 0 0"
<Button Grid.Column="3" Margin="10 0 0 0"
Content="&#xe01f;" FontFamily="zVirtualScenes"
Click="SettingBtn_Click_1"
ToolTip="Device Settings">
Expand Down
35 changes: 35 additions & 0 deletions zvs.WPF/DeviceControls/DeviceDataGridUc.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.ComponentModel;
using zvs.DataModel;
using System.Data.Entity;
using System.Threading;
using System.Threading.Tasks;
using zvs.Processor;

Expand Down Expand Up @@ -433,5 +434,39 @@ private async void ButtonDeleteDevice_OnClick(object sender, RoutedEventArgs e)
await DeleteSelectedItemsAsync();
}
}

private async void ButtonOn_OnClick(object sender, RoutedEventArgs e)
{
var selectedItems = DeviceGrid.SelectedItems.OfType<Device>().Where(o => o.Type.UniqueIdentifier == "Dimmer" || o.Type.UniqueIdentifier == "Switch");

foreach (var device in selectedItems)
{
var device1 = device;
var commandId = await Context.DeviceTypeCommands
.Where(o => o.DeviceTypeId == device1.DeviceTypeId && o.UniqueIdentifier == "TURNON")
.Select(o => o.Id)
.FirstOrDefaultAsync();

if (commandId > 0)
await _app.ZvsEngine.RunCommandAsync(commandId, string.Empty, device1.Id.ToString(), CancellationToken.None);
}
}

private async void ButtonOff_OnClick(object sender, RoutedEventArgs e)
{
var selectedItems = DeviceGrid.SelectedItems.OfType<Device>().Where(o => o.Type.UniqueIdentifier == "Dimmer" || o.Type.UniqueIdentifier == "Switch");

foreach (var device in selectedItems)
{
var device1 = device;
var commandId = await Context.DeviceTypeCommands
.Where(o => o.DeviceTypeId == device1.DeviceTypeId && o.UniqueIdentifier == "TURNOFF")
.Select(o => o.Id)
.FirstOrDefaultAsync();

if (commandId > 0)
await _app.ZvsEngine.RunCommandAsync(commandId, string.Empty, device1.Id.ToString(), CancellationToken.None);
}
}
}
}

0 comments on commit e9f8258

Please sign in to comment.