-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
131 lines (116 loc) · 4.62 KB
/
MainWindow.xaml.cs
File metadata and controls
131 lines (116 loc) · 4.62 KB
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
using DymoSDK.Interfaces;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using DxTLabel.Properties;
namespace DxTLabel
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
AddressPrinter myPrinter;
public MainWindow()
{
InitializeComponent();
}
private void Main_Loaded(object sender, RoutedEventArgs e)
{
DymoSDK.App.Init();
myPrinter = new AddressPrinter();
// Printer Selection Binding
var printerListBinding = new Binding() { Source = myPrinter.Printers };
printerList.SetBinding(ItemsControl.ItemsSourceProperty, printerListBinding);
printerList.DisplayMemberPath = "Name";
printerList.SelectedValuePath = "Name";
if (myPrinter.Printers.Count() > 0)
{
printerList.SelectedIndex = 0;
}
var printerTypeBinding = new Binding("PrinterType") { Source = (IPrinter)printerList.SelectedItem };
PrinterType.SetBinding(TextBox.TextProperty, printerTypeBinding);
// Orders Binding
var orderListBinding = new Binding() { Source = myPrinter.Orders.orders };
OrdersListBox.SetBinding(ItemsControl.ItemsSourceProperty, orderListBinding);
Settings.Default.PropertyChanged += Default_PropertyChanged;
// Process args
var args = Environment.GetCommandLineArgs();
if (args.Length > 1)
{
var file = args[1];
try
{
myPrinter.Orders.LoadFromFile(file);
}
catch (Exception ex)
{
MessageBox.Show($"Failed to load addresses from \"{file}\".{Environment.NewLine}Exception: {ex}");
}
}
}
private void Default_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Settings.Default.Save();
}
private void LoadAddressesButton_Click(object sender, RoutedEventArgs e)
{
string filePath = string.Empty;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "csv files (*.csv)|*.csv";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() ?? false)
{
filePath = openFileDialog.FileName;
myPrinter.LoadAddresses(filePath);
OrdersListBox.Items.Refresh();
var fixAddresses = MessageBox.Show(
"Attempt to fix all addresses?"
, "Address Validation",
MessageBoxButton.YesNo,
MessageBoxImage.Question
);
if (fixAddresses == MessageBoxResult.Yes)
{
myPrinter.FixAllAddresses();
}
}
}
private void OrdersListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var order = (TCGPlayerOrder)OrdersListBox.SelectedItem; if (order == null) return;
myPrinter.SetLabelAddress(order.Address);
image.Source = myPrinter.render();
}
private void PrintAllButton_Click(object sender, RoutedEventArgs e)
{
foreach(TCGPlayerOrder order in myPrinter.Orders)
{
myPrinter.SetLabelAddress(order.Address);
myPrinter.PrintLabel((IPrinter)printerList.SelectedItem);
if (PrintReturnAddressLabels.IsChecked ?? false)
{
myPrinter.SetLabelAddress(Settings.Default.ReturnAddress);
myPrinter.PrintLabel((IPrinter) printerList.SelectedItem);
}
}
MessageBox.Show($"Printed {myPrinter.Orders.orders.Count} labels.", Title, MessageBoxButton.OK);
}
private void FixAddressButton_Click(object sender, RoutedEventArgs e)
{
var order = (TCGPlayerOrder)OrdersListBox.SelectedItem; if (order == null) return;
order.FixAddress();
myPrinter.SetLabelAddress(order.Address);
image.Source = myPrinter.render();
}
private void SettingsButton_Click(object sender, RoutedEventArgs e)
{
SettingsWindow settingsWindow = new SettingsWindow();
settingsWindow.ShowDialog();
}
}
}