-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.cs
225 lines (200 loc) · 6.32 KB
/
Main.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Forms;
using _3080ReleaseTool.Models;
using Microsoft.Win32.SafeHandles;
//NSOMNIC
namespace _3080ReleaseTool
{
public partial class Main : Form
{
private const bool APPLICATION_DISABLED = true;
Library library = new Library();
public Main()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
UpdateProductQty();
}
private void UpdateProductQty()
{
if (!APPLICATION_DISABLED)
{
InventoryTool inventoryTool = new InventoryTool();
RegionQuantities quantities = inventoryTool.GetStockLevels();
int ukQty = quantities.UK;
int usQty = quantities.US;
txtQtyUk.Text = ukQty.ToString();
txtQtyUs.Text = usQty.ToString();
lbLogs.Items.Add("[" + library.getCurrentTime() + "] " + "UK Stock: " + ukQty + " " + "US Stock: " + usQty + ".");
}
else
{
MessageBox.Show("Application has been disabled");
}
}
private void btnManualUpdate_Click(object sender, EventArgs e)
{
UpdateProductQty();
}
private void tmrAutoRefresh_Tick(object sender, EventArgs e)
{
if(cbAutoRefresh.Checked)
{
UpdateProductQty();
checkAlerts();
}
}
private void cbAutoRefresh_CheckedChanged(object sender, EventArgs e)
{
if(cbAutoRefresh.Checked)
{
tmrAutoRefresh.Start();
cbAlertUk.Enabled = true;
cbAlertUs.Enabled = true;
lbLogs.Items.Add("Auto Refresh Started");
}
else
{
cbAlertUk.Enabled = false;
cbAlertUs.Enabled = false;
tmrAutoRefresh.Stop();
lbLogs.Items.Add("Auto Refresh Stopped");
}
}
private void CheckForCartButton(string region)
{
var soundPlayer = new SoundPlayer(@"c:\Windows\Media\Alarm01.wav");
CartAlert cartAlert = new CartAlert();
if (cartAlert.checkForCartButton(region))
{
tmrCartAlert.Stop();
cbCartChecker.Checked = false;
lbCartLog.Items.Add("[" + library.getCurrentTime() + "] " + "Cart Button Found!");
soundPlayer.Play();
}
else
{
//Out of Stock or Error
lbCartLog.Items.Add("[" + library.getCurrentTime() + "]Region: " + region + " - Out of Stock.");
}
}
private void cbCartChecker_CheckedChanged(object sender, EventArgs e)
{
if(cbCartChecker.Checked)
{
if(cbRegion.Text != "")
{
tmrCartAlert.Start();
lbCartLog.Items.Add("Started checking for cart button.");
CheckForCartButton(cbRegion.Text);
}
else
{
cbCartChecker.Checked = false;
MessageBox.Show("Please select a region before starting the checker.");
}
}
else
{
if(cbRegion.Text == "")
{
lbCartLog.Items.Add("Check not started: No region selected.");
}
else
{
tmrCartAlert.Stop();
lbCartLog.Items.Add("Stopped checking for cart button.");
}
}
}
private void tmrCartAlert_Tick(object sender, EventArgs e)
{
if (cbRegion.Text != "")
{
CheckForCartButton(cbRegion.Text);
}
}
private void cbAlertUk_CheckedChanged(object sender, EventArgs e)
{
if(cbAlertUk.Checked)
{
numUkAlert.Enabled = true;
}
else
{
numUkAlert.Enabled = false;
numUkAlert.Value = 0;
}
}
private void cbAlertUs_CheckedChanged(object sender, EventArgs e)
{
if (cbAlertUs.Checked)
{
numUsAlert.Enabled = true;
}
else
{
numUsAlert.Enabled = false;
numUsAlert.Value = 0;
}
}
private void checkAlerts()
{
var soundPlayer = new SoundPlayer(@"c:\Windows\Media\notify.wav");
if (cbAlertUk.Checked)
{
if(Convert.ToInt32(txtQtyUk.Text) >= numUkAlert.Value)
{
cbAlertUk.Checked = false;
soundPlayer.Play();
}
}
if (cbAlertUs.Checked)
{
if (Convert.ToInt32(txtQtyUs.Text) >= numUsAlert.Value)
{
cbAlertUs.Checked = false;
soundPlayer.Play();
}
}
}
private void saveLogContents()
{
if(lbLogs.Items.Count > 0)
{
saveFile.ShowDialog();
if(saveFile.FileName != "")
{
string path = Path.GetFullPath(saveFile.FileName);
TextWriter writer = new StreamWriter(path);
foreach (var listBoxItem in lbLogs.Items)
{
writer.WriteLine(listBoxItem.ToString());
}
writer.Close();
}
}
else
{
MessageBox.Show("Unable to save an empty log!");
}
}
private void lblSaveLog_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
saveLogContents();
}
}
}