Skip to content

Commit 1462385

Browse files
committed
#254 Screens - Timer Control is now editable like most other controls. CLOSE #254
1 parent dedfe3b commit 1462385

4 files changed

Lines changed: 396 additions & 286 deletions

File tree

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
<UserControl x:Class="OSAE.UI.Controls.AddControlTimerLabel"
2-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
mc:Ignorable="d" Height="148" Width="446" Margin="20">
7-
<Grid>
8-
<Button Name="btnAdd" Content="Add" HorizontalAlignment="Left" Margin="10,113,0,0" VerticalAlignment="Top" Width="75" Click="btnAdd_Click"/>
9-
<Button Name="btnCancel" Content="Cancel" HorizontalAlignment="Left" Margin="361,113,0,0" VerticalAlignment="Top" Width="75" Click="btnCancel_Click"/>
10-
<Label Content="Object" HorizontalAlignment="Left" Margin="10,6,0,0" VerticalAlignment="Top"/>
11-
<ComboBox Name="objectComboBox" HorizontalAlignment="Left" Margin="81,8,0,0" VerticalAlignment="Top" Width="337" ItemsSource="{Binding Path=object_name}" DisplayMemberPath="object_name" SelectedValuePath="object_name" IsEditable="False"/>
12-
<TextBox x:Name="txtFont" HorizontalAlignment="Left" Height="23" Margin="82,39,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="145" PreviewMouseDown="txtFont_MouseLeftButtonUp"/>
13-
<Label Content="Font" HorizontalAlignment="Left" Margin="10,36,0,0" VerticalAlignment="Top"/>
14-
<TextBox x:Name="txtSize" HorizontalAlignment="Left" Height="23" Margin="275,40,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="145" MouseLeftButtonUp="txtFont_MouseLeftButtonUp" PreviewMouseDown="txtFont_MouseLeftButtonUp"/>
15-
<Label Content="Size" HorizontalAlignment="Left" Margin="231,39,0,0" VerticalAlignment="Top"/>
16-
<Label Content="Back Color" HorizontalAlignment="Left" Margin="231,72,0,0" VerticalAlignment="Top"/>
17-
<Label Content="Fore Color" HorizontalAlignment="Left" Margin="10,70,0,0" VerticalAlignment="Top"/>
18-
<ComboBox x:Name="foreColorComboBox" HorizontalAlignment="Left" Margin="81,72,0,0" VerticalAlignment="Top" Width="115"/>
19-
<ComboBox x:Name="backColorComboBox" HorizontalAlignment="Left" Margin="304,74,0,0" VerticalAlignment="Top" Width="114"/>
20-
21-
</Grid>
22-
</UserControl>
1+
<UserControl x:Class="OSAE.UI.Controls.AddControlTimerLabel"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
mc:Ignorable="d" Height="221" Width="446" Margin="20">
7+
<Grid>
8+
<Button Name="btnAdd" Content="Add" HorizontalAlignment="Left" Margin="10,188,0,0" VerticalAlignment="Top" Width="75" Click="btnAdd_Click"/>
9+
<Button Name="btnCancel" Content="Cancel" HorizontalAlignment="Left" Margin="361,188,0,0" VerticalAlignment="Top" Width="75" Click="btnCancel_Click"/>
10+
<Label Content="Object" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top"/>
11+
<ComboBox Name="objectComboBox" HorizontalAlignment="Left" Margin="81,43,0,0" VerticalAlignment="Top" Width="337" ItemsSource="{Binding Path=object_name}" DisplayMemberPath="object_name" SelectedValuePath="object_name" IsEditable="False" SelectionChanged="objectComboBox_SelectionChanged"/>
12+
<TextBox x:Name="txtFont" HorizontalAlignment="Left" Height="23" Margin="82,74,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="145" PreviewMouseDown="txtFont_MouseLeftButtonUp"/>
13+
<Label Content="Font" HorizontalAlignment="Left" Margin="10,71,0,0" VerticalAlignment="Top"/>
14+
<TextBox x:Name="txtSize" HorizontalAlignment="Left" Height="23" Margin="275,75,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="145" MouseLeftButtonUp="txtFont_MouseLeftButtonUp" PreviewMouseDown="txtFont_MouseLeftButtonUp"/>
15+
<Label Content="Size" HorizontalAlignment="Left" Margin="231,74,0,0" VerticalAlignment="Top"/>
16+
<Label Content="Back Color" HorizontalAlignment="Left" Margin="231,107,0,0" VerticalAlignment="Top"/>
17+
<Label Content="Fore Color" HorizontalAlignment="Left" Margin="10,105,0,0" VerticalAlignment="Top"/>
18+
<ComboBox x:Name="foreColorComboBox" HorizontalAlignment="Left" Margin="81,107,0,0" VerticalAlignment="Top" Width="115"/>
19+
<ComboBox x:Name="backColorComboBox" HorizontalAlignment="Left" Margin="304,109,0,0" VerticalAlignment="Top" Width="114"/>
20+
<Button x:Name="btnUpdate" Content="Update" HorizontalAlignment="Left" Margin="97,188,0,0" VerticalAlignment="Top" Width="75" Click="btnUpdate_Click"/>
21+
<Button x:Name="btnDelete" Content="Delete" HorizontalAlignment="Left" Margin="187,188,0,0" VerticalAlignment="Top" Width="75" Click="btnDelete_Click"/>
22+
<TextBox x:Name="txtX" HorizontalAlignment="Left" Height="26" Margin="172,148,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="45" Text="100"/>
23+
<TextBox x:Name="txtY" HorizontalAlignment="Left" Height="26" Margin="247,148,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="42" RenderTransformOrigin="0.534,2.077" Text="100"/>
24+
<Label Content="Y" HorizontalAlignment="Left" Margin="230,148,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.588,1.846"/>
25+
<Label Content="X" HorizontalAlignment="Left" Margin="155,148,0,0" VerticalAlignment="Top"/>
26+
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="10,9,0,0" x:Name="label3_Copy" VerticalAlignment="Top" Width="53" />
27+
<Label x:Name="lblName" Content="" HorizontalAlignment="Left" Margin="82,11,0,0" VerticalAlignment="Top" Width="336"/>
28+
29+
</Grid>
30+
</UserControl>
Lines changed: 205 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,205 @@
1-
namespace OSAE.UI.Controls
2-
{
3-
using System;
4-
using System.Drawing;
5-
using System.IO;
6-
using System.Data;
7-
using System.Windows;
8-
using System.Windows.Controls;
9-
using System.Collections.Generic;
10-
using System.Windows.Media.Imaging;
11-
12-
/// <summary>
13-
/// Interaction logic for AddControlStaticLabel.xaml
14-
/// </summary>
15-
public partial class AddControlTimerLabel : UserControl
16-
{
17-
private string currentScreen;
18-
19-
public AddControlTimerLabel(string screen)
20-
{
21-
InitializeComponent();
22-
currentScreen = screen;
23-
LoadObjects();
24-
LoadColors();
25-
}
26-
27-
/// <summary>
28-
/// Load the screens from the DB into the combo box
29-
/// </summary>
30-
private void LoadObjects()
31-
{
32-
DataSet dataSet = OSAESql.RunSQL("SELECT object_name FROM osae_v_object order by object_name");
33-
objectComboBox.ItemsSource = dataSet.Tables[0].DefaultView;
34-
}
35-
36-
private void LoadColors()
37-
{
38-
//create a generic list of strings
39-
//Dim colors As New List(Of String)()
40-
//get the color names from the Known color enum
41-
string[] colorNames = Enum.GetNames(typeof(KnownColor));
42-
//iterate thru each string in the colorNames array
43-
foreach (string colorName in colorNames)
44-
{
45-
//cast the colorName into a KnownColor
46-
//KnownColor. knownColor;// = (KnownColor)Enum.Parse(typeof(KnownColor), colorName);
47-
//check if the knownColor variable is a System color
48-
//if (knownColor > knownColor.)
49-
//{
50-
//add it to our list
51-
foreColorComboBox.Items.Add(colorName);
52-
backColorComboBox.Items.Add(colorName);
53-
//}
54-
}
55-
//return the color list
56-
foreColorComboBox.Text = "Black";
57-
backColorComboBox.Text = "White";
58-
59-
}
60-
61-
private void txtFont_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
62-
{
63-
try
64-
{
65-
System.Windows.Forms.FontDialog dlgFont = null;
66-
dlgFont = new System.Windows.Forms.FontDialog();
67-
68-
//dlgFont.Font = set your font here
69-
70-
if (dlgFont.ShowDialog() == System.Windows.Forms.DialogResult.OK)
71-
{
72-
txtFont.Text = dlgFont.Font.FontFamily.Name;
73-
txtSize.Text = dlgFont.Font.Size.ToString();
74-
}
75-
}
76-
catch (Exception ex)
77-
{
78-
79-
}
80-
}
81-
82-
private void btnAdd_Click(object sender, RoutedEventArgs e)
83-
{
84-
string sName = "Screen - " + currentScreen + " - " + objectComboBox.Text + "(Off Timer)";
85-
OSAEObjectManager.ObjectAdd(sName, sName, "CONTROL TIMER LABEL", "", currentScreen, true);
86-
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Font Name", txtFont.Text, "GUI");
87-
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Font Size", txtSize.Text, "GUI");
88-
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Fore Color", foreColorComboBox.Text, "GUI");
89-
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Back Color", backColorComboBox.Text, "GUI");
90-
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Object Name", objectComboBox.Text, "GUI");
91-
OSAEObjectPropertyManager.ObjectPropertySet(sName, "X", "100", "GUI");
92-
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Y", "100", "GUI");
93-
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Zorder", "1", "GUI");
94-
95-
OSAEScreenControlManager.ScreenObjectAdd(currentScreen, objectComboBox.Text, sName);
96-
97-
98-
NotifyParentFinished();
99-
}
100-
101-
private void btnCancel_Click(object sender, RoutedEventArgs e)
102-
{
103-
NotifyParentFinished();
104-
}
105-
106-
/// <summary>
107-
/// Let the hosting contol know that we are done
108-
/// </summary>
109-
/// <remarks>At present it tells the parent to close, this could later be altered to have a event that fires to
110-
/// the parent allowing them to decide what to do when the control is finished. If the control is being hosted in
111-
/// an element host this will have no affect as the parent is the element host and not the form.</remarks>
112-
private void NotifyParentFinished()
113-
{
114-
// Get the window hosting us so we can ask it to close
115-
Window parentWindow = Window.GetWindow(this);
116-
parentWindow.Close();
117-
}
118-
}
119-
}
1+
namespace OSAE.UI.Controls
2+
{
3+
using System;
4+
using System.Drawing;
5+
using System.IO;
6+
using System.Data;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Collections.Generic;
10+
using System.Windows.Media.Imaging;
11+
12+
/// <summary>
13+
/// Interaction logic for AddControlStaticLabel.xaml
14+
/// </summary>
15+
public partial class AddControlTimerLabel : UserControl
16+
{
17+
private string currentScreen;
18+
string sOriginalName = "";
19+
string sMode = "";
20+
21+
public AddControlTimerLabel(string screen, string controlName = "")
22+
{
23+
InitializeComponent();
24+
currentScreen = screen;
25+
LoadObjects();
26+
LoadColors();
27+
28+
//Check if controlName was passed in, if so, goto edit mode
29+
if (controlName != "")
30+
{
31+
//Let's validate the controlName and then call a Pre-Load of its properties
32+
DataSet dsScreenControl = OSAESql.RunSQL("SELECT COUNT(object_name) FROM osae_v_object where object_name = '" + controlName + "'");
33+
if (dsScreenControl.Tables[0].Rows[0][0].ToString() == "1")
34+
{
35+
// We have a hit, this is an Update call, se call the preload
36+
sMode = "Update";
37+
sOriginalName = controlName;
38+
lblName.Content = controlName;
39+
LoadCurrentScreenObject(controlName);
40+
}
41+
}
42+
43+
if (controlName == "")
44+
{
45+
sMode = "Add";
46+
}
47+
Enable_Buttons();
48+
}
49+
50+
/// <summary>
51+
/// Load the screens from the DB into the combo box
52+
/// </summary>
53+
private void LoadObjects()
54+
{
55+
DataSet dataSet = OSAESql.RunSQL("SELECT object_name FROM osae_v_object order by object_name");
56+
objectComboBox.ItemsSource = dataSet.Tables[0].DefaultView;
57+
}
58+
59+
private void LoadColors()
60+
{
61+
//create a generic list of strings
62+
//Dim colors As New List(Of String)()
63+
//get the color names from the Known color enum
64+
string[] colorNames = Enum.GetNames(typeof(KnownColor));
65+
//iterate thru each string in the colorNames array
66+
foreach (string colorName in colorNames)
67+
{
68+
//cast the colorName into a KnownColor
69+
//KnownColor. knownColor;// = (KnownColor)Enum.Parse(typeof(KnownColor), colorName);
70+
//check if the knownColor variable is a System color
71+
//if (knownColor > knownColor.)
72+
//{
73+
//add it to our list
74+
foreColorComboBox.Items.Add(colorName);
75+
backColorComboBox.Items.Add(colorName);
76+
//}
77+
}
78+
//return the color list
79+
foreColorComboBox.Text = "Black";
80+
backColorComboBox.Text = "White";
81+
txtFont.Text = "Arial";
82+
// txtFont.FontFamily = new System.Windows.Media.FontFamily("Arial");
83+
txtSize.Text = "8.5";
84+
85+
}
86+
87+
private void txtFont_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
88+
{
89+
try
90+
{
91+
System.Windows.Forms.FontDialog dlgFont = null;
92+
dlgFont = new System.Windows.Forms.FontDialog();
93+
94+
95+
if (dlgFont.ShowDialog() == System.Windows.Forms.DialogResult.OK)
96+
{
97+
txtFont.Text = dlgFont.Font.FontFamily.Name;
98+
txtFont.FontFamily = new System.Windows.Media.FontFamily(dlgFont.Font.FontFamily.Name);
99+
txtSize.Text = dlgFont.Font.Size.ToString();
100+
}
101+
}
102+
catch (Exception ex)
103+
{
104+
105+
}
106+
}
107+
108+
private void btnAdd_Click(object sender, RoutedEventArgs e)
109+
{
110+
string sName = lblName.Content.ToString();
111+
OSAEObjectManager.ObjectAdd(sName, sName, "CONTROL TIMER LABEL", "", currentScreen, true);
112+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Font Name", txtFont.Text, "GUI");
113+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Font Size", txtSize.Text, "GUI");
114+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Fore Color", foreColorComboBox.Text, "GUI");
115+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Back Color", backColorComboBox.Text, "GUI");
116+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Object Name", objectComboBox.Text, "GUI");
117+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "X", txtX.Text, "GUI");
118+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Y", txtY.Text, "GUI");
119+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Zorder", "1", "GUI");
120+
121+
OSAEScreenControlManager.ScreenObjectAdd(currentScreen, objectComboBox.Text, sName);
122+
NotifyParentFinished();
123+
}
124+
125+
private void btnUpdate_Click(object sender, RoutedEventArgs e)
126+
{
127+
string sName = lblName.Content.ToString();
128+
OSAEObjectManager.ObjectUpdate(sOriginalName, sName, sName, "CONTROL TIMER LABEL", "", currentScreen, 1);
129+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Font Name", txtFont.Text, "GUI");
130+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Font Size", txtSize.Text, "GUI");
131+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Fore Color", foreColorComboBox.Text, "GUI");
132+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Back Color", backColorComboBox.Text, "GUI");
133+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Object Name", objectComboBox.Text, "GUI");
134+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "X", txtX.Text, "GUI");
135+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Y", txtY.Text, "GUI");
136+
OSAEObjectPropertyManager.ObjectPropertySet(sName, "Zorder", "1", "GUI");
137+
138+
OSAEScreenControlManager.ScreenObjectAdd(currentScreen, objectComboBox.Text, sName);
139+
NotifyParentFinished();
140+
}
141+
142+
private void btnDelete_Click(object sender, RoutedEventArgs e)
143+
{
144+
OSAEObjectManager.ObjectDelete(sOriginalName);
145+
NotifyParentFinished();
146+
}
147+
148+
private void objectComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
149+
{
150+
lblName.Content = "Screen - " + currentScreen.Replace("Screen - ","") + " - " + (sender as ComboBox).SelectedValue.ToString() + " (Off Timer)";
151+
}
152+
153+
private void btnCancel_Click(object sender, RoutedEventArgs e)
154+
{
155+
NotifyParentFinished();
156+
}
157+
158+
/// <summary>
159+
/// Let the hosting contol know that we are done
160+
/// </summary>
161+
/// <remarks>At present it tells the parent to close, this could later be altered to have a event that fires to
162+
/// the parent allowing them to decide what to do when the control is finished. If the control is being hosted in
163+
/// an element host this will have no affect as the parent is the element host and not the form.</remarks>
164+
private void NotifyParentFinished()
165+
{
166+
// Get the window hosting us so we can ask it to close
167+
Window parentWindow = Window.GetWindow(this);
168+
parentWindow.Close();
169+
}
170+
171+
private void LoadCurrentScreenObject(string controlName)
172+
{
173+
objectComboBox.Text = OSAEObjectPropertyManager.GetObjectPropertyValue(controlName, "Object Name").Value;
174+
txtFont.Text = OSAEObjectPropertyManager.GetObjectPropertyValue(controlName, "Font Name").Value;
175+
txtSize.Text = OSAEObjectPropertyManager.GetObjectPropertyValue(controlName, "Font Size").Value;
176+
txtX.Text = OSAEObjectPropertyManager.GetObjectPropertyValue(controlName, "X").Value;
177+
txtY.Text = OSAEObjectPropertyManager.GetObjectPropertyValue(controlName, "Y").Value;
178+
}
179+
180+
private void Enable_Buttons()
181+
{
182+
//First Senerio is a New Control, not a rename or update.
183+
if (sMode == "Add")
184+
{
185+
btnAdd.IsEnabled = true;
186+
btnUpdate.IsEnabled = false;
187+
btnDelete.IsEnabled = false;
188+
}
189+
//Now we handle Updates with no name changes
190+
if (sMode == "Update" && sOriginalName == objectComboBox.Text)
191+
{
192+
btnAdd.IsEnabled = false;
193+
btnUpdate.IsEnabled = true;
194+
btnDelete.IsEnabled = true;
195+
}
196+
//Now we handle Updates WITH name changes
197+
if (sMode == "Update" && sOriginalName != objectComboBox.Text)
198+
{
199+
btnAdd.IsEnabled = true;
200+
btnUpdate.IsEnabled = true;
201+
btnDelete.IsEnabled = true;
202+
}
203+
}
204+
}
205+
}

0 commit comments

Comments
 (0)