-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
381 lines (296 loc) · 10.2 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*
date: feb 02,2024 - BY erj.a: https://github.com/SilverTaurus21
methods :
GET_COUNTER - triggers only in RESET_DATA AND BUTTON EVENTS OR KEYS - will pass string data
RESET_DATA - Will delete current file in the .json and reset the deafault strings assign / static to two counters
REFRESH_DATA - Will occured during RESET and FORM_LOAD initialize();
SettingJsonActive - retrieve and read .json file
RESET_BUTTON_STAT - read if the dafaut string is made and it will disable the RESET BUTTON , trigger on reset and btn_
COUNTER1 - for btn event counter1
COUNTER2 - for btn event counter2
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ComponentFactory.Krypton;
using ComponentFactory.Krypton.Toolkit;
using Newtonsoft.Json;
using System.Media;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Globalization;
namespace countersystemV1
{
public partial class Form1 : KryptonForm
{
int num = 1, c1=1, c2=1;
string lastInput = string.Empty;
bool EXIT = false;
bool firstTrigger = true;
bool isConnectToTV;
public Form1()
{
InitializeComponent();
clock();
SettingJsonActive();
REFRESH_DATA();
RESET_BUTTON_STAT();
GET_COUNTER(); // initial Form1_Load temporary code here
}
/* ***************** FORMLOAD ******************/
private void Form1_Load(object sender, EventArgs e)
{
if (Screen.AllScreens.Length > 1)
{
BTN_CONNECTTV.Visible = true;
isConnectToTV = RelayTrigger.gettrigger;
}
else
{
BTN_CONNECTTV.Visible = false;
isConnectToTV = false;
}
}
/* ***************** METHOD SECTION ONLY ******************/
private void setFormLocation(Form form, Screen screen)
{
Rectangle bounds = screen.Bounds;
form.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
}
public void DETECT_SCREEN()
{
do
{
if (Screen.AllScreens.Length > 1)
{
GET_COUNTER();
// will set second screen in default screen 1 - you can edit this dynamically if you want by user - ff
secondscreenFRM frm = new secondscreenFRM();
Screen[] screens = Screen.AllScreens;
setFormLocation(frm, screens[1]);
frm.Show();
}
else
{
BTN_CONNECTTV.Visible = false;
isConnectToTV = false;
}
}
while (!isConnectToTV);
// Load the image from the file
BTN_CONNECTTV.Enabled = false;
isConnectToTV = false;
}
public void clock()
{
Timer timer1 = new Timer();
timer1.Interval = 1000; // 1 second interval
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
public void SettingJsonActive()
{
if (File.Exists("counter.json"))
{
string json = File.ReadAllText("counter.json");
dynamic data = JsonConvert.DeserializeObject(json);
c1 = (int)data.c1;
c2 = (int)data.c2;
}
else
{
c1 = 1;
c2 = 1;
}
}
public void REFRESH_DATA(){
string json = File.ReadAllText("counter.json");
dynamic data = JsonConvert.DeserializeObject(json);
TXT_COUNTER1.Text = Convert.ToString(data.c1);
TXT_COUNTER2.Text= Convert.ToString(data.c2);
}
public void RESET_BUTTON_STAT(){
if (TXT_COUNTER1.Text.Equals("1") && TXT_COUNTER2.Text.Equals("2"))
{
BTN_TRIGGER_RESET.Enabled = false;
}
else
{
BTN_TRIGGER_RESET.Enabled = true;
}
}
public void COUNTER_1()
{
c1 = Convert.ToInt32(TXT_COUNTER1.Text);
c2 = Convert.ToInt32(TXT_COUNTER2.Text);
if (c1 == 0 || c2 == 0) {
c1++;
c2 = 2;
}
else {
if (c1 > c2)
{
c1++;
c2 = c2;
}
else if (c1 < c2)
{
c1 = c2;
c1++;
c2 = c2;
}
}
dynamic data = new
{
c1 = c1,
c2 = c2
};
string json = JsonConvert.SerializeObject(data);
File.WriteAllText("counter.json", json);
TXT_COUNTER1.Text = Convert.ToString(c1);
RESET_BUTTON_STAT();
}
public void COUNTER_2()
{
c1 = Convert.ToInt32(TXT_COUNTER1.Text);
c2 = Convert.ToInt32(TXT_COUNTER2.Text);
if (c2 == 0 || c1 == 0)
{
c2++;
c1 = 2;
}
else {
if (c2 > c1)
{
c2++;
c1 = c1;
}
else if (c2 < c1) {
c2 = c1;
c2++;
c1 = c1;
}
}
dynamic data = new
{
c1 = c1,
c2 = c2,
};
string json = JsonConvert.SerializeObject(data);
File.WriteAllText("counter.json", json);
TXT_COUNTER2.Text = Convert.ToString(c2);
RESET_BUTTON_STAT();
}
public void GET_COUNTER(){
try
{
RelayTrigger.getcounter1 = TXT_COUNTER1.Text;
RelayTrigger.getcounter2 = TXT_COUNTER2.Text;
}
catch(Exception e){ }
}
public void RESET_DATA(){
DialogResult result = MessageBox.Show("are you sure you want to RESET?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
// Check the user's input
if (result == DialogResult.Yes)
{
File.Delete("counter.json");
if (!File.Exists("counter.json"))
{
dynamic data = new
{
// THIS DATA WILL ASSIGN STATIC VALUES TO EACH COUNTER
c1 = 1,
c2 = 2,
};
string json = JsonConvert.SerializeObject(data);
File.WriteAllText("counter.json", json);
// c1 and c2
TXT_COUNTER1.Text = Convert.ToString(c1);
TXT_COUNTER2.Text = Convert.ToString(c2);
REFRESH_DATA();
RESET_BUTTON_STAT();
// The user clicked 'Yes'
MessageBox.Show("Data Been RESET");
GET_COUNTER(); // temp
}
else if (result == DialogResult.No)
{
// The user clicked 'No'
MessageBox.Show("Cancelled");
}
}
}
public void RECALL_VOICE(){
if (TXT_COUNTER1.Text != "")
{
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
synthesizer.Volume = 100;
// Get the installed voices
foreach (InstalledVoice voice in synthesizer.GetInstalledVoices())
{
VoiceInfo info = voice.VoiceInfo;
Console.WriteLine("Name: {0}, Culture: {1}, Gender: {2}",
info.Name, info.Culture, info.Gender);
}
// Set the voice to be used by the synthesizer
synthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Senior, 0, new CultureInfo("en-US"));
// Generate speech from text here.. waaaaaaaah!
synthesizer.SpeakAsync("Calling Counter one, number " + TXT_COUNTER1.Text + ", and Calling Counter two, number " + TXT_COUNTER2.Text);
}
}
/* ***************** EVENT SECTION ONLY ******************/
private void timer1_Tick(object sender, EventArgs e)
{
DateTime currentTime = DateTime.Now;
if (currentTime.Hour >= 12)
{
currentDateTime.Text = $"{currentTime.Hour % 12:00}:{currentTime.Minute:00}:{currentTime.Second:00} PM";
}
else
{
currentDateTime.Text = $"{currentTime.Hour:00}:{currentTime.Minute:00}:{currentTime.Second:00} AM";
}
}
private void button1_Click(object sender, EventArgs e)
{
splashFRM sp = new splashFRM();
sp.Show();
}
private void BTN_COUNTER1_Click(object sender, EventArgs e)
{
COUNTER_1();
GET_COUNTER();
}
private void BTN_COUNTER2_Click(object sender, EventArgs e)
{
COUNTER_2();
GET_COUNTER();
}
private void BTN_SETTINGS_Click(object sender, EventArgs e)
{
settingsFRM setFRM = new settingsFRM();
setFRM.ShowDialog();
}
private void BTN_RECALL_Click(object sender, EventArgs e)
{
RECALL_VOICE();
}
private void BTN_TRIGGER_RESET_Click(object sender, EventArgs e)
{
RESET_DATA();
}
private void BTN_CONNECTTV_Click_1(object sender, EventArgs e)
{
DETECT_SCREEN();
}
}
}