|
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