-
Notifications
You must be signed in to change notification settings - Fork 4
/
StartupPage.xaml.cs
174 lines (155 loc) · 6.96 KB
/
StartupPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// <copyright>
// Copyright 2013 by the Spark Development Network
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//
using System;
using System.Runtime.Caching;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace CheckinClient
{
/// <summary>
/// Interaction logic for StartupPage.xaml
/// </summary>
public partial class StartupPage : Page
{
/// <summary>
/// Initializes a new instance of the <see cref="StartupPage"/> class.
/// </summary>
public StartupPage()
{
InitializeComponent();
// clear cache
MemoryCache cache = new MemoryCache("RockCheckinClient");
cache.Dispose();
}
/// <summary>
/// Handles the Click event of the btnCancel control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void btnCancel_Click( object sender, RoutedEventArgs e )
{
Application.Current.Shutdown();
}
/// <summary>
/// Handles the Click event of the btnStart control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void btnStart_Click( object sender, RoutedEventArgs e )
{
// save settings
RockConfig rockConfig = RockConfig.Load();
rockConfig.CheckinAddress = txtCheckinAddress.Text;
int cacheLabelDuration;
if (int.TryParse(txtCacheLabelDuration.Text, out cacheLabelDuration))
{
rockConfig.CacheLabelDuration = cacheLabelDuration;
}
rockConfig.IsCachingEnabled = cbEnableLabelCaching.IsChecked.HasValue ? cbEnableLabelCaching.IsChecked.Value : true;
rockConfig.HasPrinterCutter = cbPrinterHasCutter.IsChecked.HasValue ? cbPrinterHasCutter.IsChecked.Value : true;
rockConfig.IsPrintingDisabled = cbDisablePrinter.IsChecked.HasValue ? cbDisablePrinter.IsChecked.Value : true;
/*double zoomLevel;
if (double.TryParse(txtZoomLevel.Text, out zoomLevel))
{
rockConfig.ZoomLevel = zoomLevel;
}*/
rockConfig.PrinterOverrideIp = txtPrinterOverrideIp.Text;
rockConfig.PrinterOverrideLocal = string.Empty;
if ( txtPrinterOverrideIp.Text == string.Empty )
{
foreach ( Control control in spUsbPrinterList.Children )
{
if ( control is ToggleButton )
{
ToggleButton tbControl = control as ToggleButton;
if ( tbControl.IsChecked != null && tbControl.IsChecked.Value == true )
{
rockConfig.PrinterOverrideLocal = tbControl.Content.ToString();
}
}
}
}
rockConfig.Save();
Uri uriTest;
if ( !Uri.TryCreate(txtCheckinAddress.Text, UriKind.Absolute, out uriTest ))
{
MessageBox.Show( "You must enter a valid URL for the Check-in Address Field.", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation );
}
else
{
BrowserPage browserPage = new BrowserPage();
this.NavigationService.Navigate( browserPage );
}
}
/// <summary>
/// Handles the Loaded event of the pStartupPage control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void pStartupPage_Loaded( object sender, RoutedEventArgs e )
{
int printerCounter = 0;
RockConfig rockConfig = RockConfig.Load();
// set save configuration settings
txtCheckinAddress.Text = rockConfig.CheckinAddress;
txtPrinterOverrideIp.Text = rockConfig.PrinterOverrideIp;
txtCacheLabelDuration.Text = rockConfig.CacheLabelDuration.ToString();
cbEnableLabelCaching.IsChecked = rockConfig.IsCachingEnabled;
cbPrinterHasCutter.IsChecked = rockConfig.HasPrinterCutter;
cbDisablePrinter.IsChecked = rockConfig.IsPrintingDisabled;
//txtZoomLevel.Text = rockConfig.ZoomLevel.ToString();
string localPrinterName = rockConfig.PrinterOverrideLocal;
foreach ( string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters )
{
// MessageBox.Show( printer );
ToggleButton btnToggle = new ToggleButton();
btnToggle.Content = printer;
btnToggle.Name = "btnPrinter" + printerCounter;
btnToggle.Margin = new Thickness( 0, 12, 0, 0 );
btnToggle.Padding = new Thickness( 0, 12, 0, 8 );
btnToggle.FontSize = 18;
btnToggle.Style = this.FindResource( "toggleButtonStyle" ) as Style;
if ( printer == localPrinterName )
{
btnToggle.IsChecked = true;
}
spUsbPrinterList.Children.Add( btnToggle );
btnToggle.Click += new RoutedEventHandler( btnToggle_Click );
printerCounter++;
}
}
/// <summary>
/// Handles the Click event of the btnToggle control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void btnToggle_Click( object sender, RoutedEventArgs e )
{
ToggleButton btnClicked = sender as ToggleButton;
// ensure only one toggle button is selected at a time
foreach ( Control control in spUsbPrinterList.Children )
{
if ( control is ToggleButton && control.Name != btnClicked.Name )
{
ToggleButton tbControl = control as ToggleButton;
tbControl.IsChecked = false;
}
}
}
}
}