-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
92 lines (76 loc) · 2.81 KB
/
Form1.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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using StarLabs.CashDrawer;
namespace CashDrawerDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private async void btnDiscovery_Click(object sender, EventArgs e)
{
if (drawerListView1.Items.Count != 0) { drawerListView1.Items.Clear(); }
List<StarUsbCashDrawer> connectedCashDrawers = await StarUsbCashDrawer.Discover();
if (connectedCashDrawers.Count == 0)
{
btnGetStatus.Enabled = false; btnOpenTill.Enabled = false;
textBox1.Visible = true;
}
else
{
textBox1.Visible = false;
foreach (StarUsbCashDrawer cashDrawer in connectedCashDrawers)
{
drawerListView1.Items.Add(cashDrawer.modelName).SubItems.Add(cashDrawer.port.ToString());
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private async void btnOpenTill_Click(object sender, EventArgs e)
{
int drawerNumber = Int32.Parse(drawerListView1.SelectedItems[0].SubItems[1].Text);
StarUsbCashDrawer cashDrawer = new StarUsbCashDrawer(drawerNumber);
bool success = await cashDrawer.OpenTill(cashDrawer.port);
if (!success) {
MessageBox.Show($"Could not open Cash Drawer { cashDrawer.port }", "OpenTill Result");
}
}
private async void btnGetStatus_Click(object sender, EventArgs e)
{
string strStatus = "";
int drawerNumber = Int32.Parse(drawerListView1.SelectedItems[0].SubItems[1].Text);
StarUsbCashDrawer cashDrawer = new StarUsbCashDrawer(drawerNumber);
int status = await cashDrawer.GetDrawerStatus(cashDrawer.port);
// 0 = not connected/couldn't get status
// 1 = closed
// 2 = open
switch (status) {
case 0:
strStatus = "Not Connected";
break;
case 1:
strStatus = "Closed";
break;
case 2:
strStatus = "Open";
break;
}
MessageBox.Show($"Cash Drawer {cashDrawer.port} status: {strStatus}");
}
private void drawerListView1_SelectedIndexChanged(object sender, EventArgs e)
{
btnGetStatus.Enabled = false;
btnOpenTill.Enabled = false;
if (drawerListView1.Items.Count > 0)
{
btnGetStatus.Enabled = true;
btnOpenTill.Enabled = true;
}
}
}
}