Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test button for client printers #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions RockLabelPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ private void PrintLabel( string labelContents, string labelPrinterIp )
}
}

/// <summary>
/// Prints a test label to the chosen hardware printer.
/// </summary>
public void TestPrint()
{
var text = @"CT~~CD,~CC^~CT~
^XA~TA000~JSN^LT0^MNW^MTD^PON^PMN^LH0,0^JMA^PR4,4~SD15^JUS^LRN^CI0^XZ
^XA
^MMT
^PW609
^LL0406
^LS0
^FT275,210^A0N,28,28^FH\^FDTEST^FS
^PQ1,0,1,Y^XZ
";
var rockConfig = RockConfig.Load();
RawPrinterHelper.SendStringToPrinter( rockConfig.PrinterOverrideLocal, text );
}

/// <summary>
/// Prints the via ip.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions StartupPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<StackPanel x:Name="spUsbPrinterList" Orientation="Vertical">
</StackPanel>
</ScrollViewer>
<Button Content="Test Printer" x:Name="btnTest" Style="{StaticResource buttonStyleAction}" VerticalAlignment="Top" Width="280" Height="40" Margin="0,0,0,0" FontSize="18" Click="btnTest_Click"/>
</StackPanel>

</Grid>
Expand Down
55 changes: 55 additions & 0 deletions StartupPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ public partial class StartupPage : Page
public StartupPage()
{
InitializeComponent();

btnTest.Visibility = TestButtonVisiblity();
}

/// <summary>
/// Determines if the test button should be visible.
/// </summary>
/// <returns></returns>
private Visibility TestButtonVisiblity()
{
foreach ( Control control in spUsbPrinterList.Children )
{
if ( control is ToggleButton )
{
ToggleButton tbControl = control as ToggleButton;
if ( tbControl.IsChecked == true )
{
// show if a client printer is checked
return Visibility.Visible;
}
}
}
// don't show if no printer selected
return Visibility.Hidden;
}

/// <summary>
Expand Down Expand Up @@ -158,6 +182,37 @@ private void btnToggle_Click( object sender, RoutedEventArgs e )
tbControl.IsChecked = false;
}
}
btnTest.Visibility = TestButtonVisiblity();
}

/// <summary>
/// Handles the Click event of the btnTest 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 btnTest_Click( object sender, RoutedEventArgs e )
{
var rockConfig = RockConfig.Load();
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();
var printer = new RockLabelPrinter();
printer.TestPrint();
}
}
}