-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathForm1.cs
More file actions
1636 lines (1481 loc) · 66.4 KB
/
Form1.cs
File metadata and controls
1636 lines (1481 loc) · 66.4 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
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Data.Sqlite;
namespace pomidor
{
public partial class Form1 : Form
{
readonly System.Windows.Forms.Timer timerx = new System.Windows.Forms.Timer();
int year = DateTimeOffset.Now.Year;
long startTime = 0;
long stopTime = 0;
long pauseMoment = 0;
long focus_time = 25;
long break_time = 5;
long long_break_time = 15;
int long_break_n = 4;
string f1_sound = "";
string f2_sound = "";
string b_sound = "";
string lb_sound = "";
string pl_folder = "playlist";
bool ofs_timer = true;
bool lb_logic = false;
bool pl_status = false;
bool pl_repeat = true;
bool pl_break = true;
bool pl_paused = false;
private bool _timer_work = false;
private bool _timer_pause = false;
private short _timer_type = 0;
readonly WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
readonly WMPLib.WindowsMediaPlayer pl_main = new WMPLib.WindowsMediaPlayer();
public Form1()
{
InitializeComponent();
SetDoubleBuffered(tableLayoutPanel1);
SetDoubleBuffered(tabPage1);
SetDoubleBuffered(tabPage2);
SetDoubleBuffered(panel1);
SetDoubleBuffered(panel3);
SetDoubleBuffered(groupBox2);
SetDoubleBuffered(groupBox3);
SetDoubleBuffered(groupBox4);
timerx.Interval = 1000;
tableLayoutPanel1.SuspendLayout();
for (int i = 0; i < 53; i++)
{
for (int j = 0; j < 7; j++)
{
PictureBox pB = new PictureBox
{
Size = MaximumSize,
Dock = DockStyle.Fill,
SizeMode = PictureBoxSizeMode.StretchImage
};
pB.BackColor = System.Drawing.Color.Transparent;
pB.Paint += pictureBox1_Paint_1;
pB.Margin = new Padding(0);
tableLayoutPanel1.Controls.Add(pB, i, j);
}
}
tableLayoutPanel1.ResumeLayout();
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
this.notifyIcon1.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
this.notifyIcon1.ContextMenuStrip.Items.Add("Приостановить таймер", null, this.PauseClick);
this.notifyIcon1.ContextMenuStrip.Items.Add("Остановить таймер", null, this.StopClick);
this.notifyIcon1.ContextMenuStrip.Items.Add("Перезапустить...", null);
this.notifyIcon1.ContextMenuStrip.Items.Add("Запустить фокусировку", null, this.StartFocus);
this.notifyIcon1.ContextMenuStrip.Items.Add("Запустить перерыв", null, this.StartBreak);
this.notifyIcon1.ContextMenuStrip.Items.Add("Запустить длинный перерыв", null, this.StartLongBreak);
this.notifyIcon1.ContextMenuStrip.Items.Add("Настройки", null, this.OpenSettings);
this.notifyIcon1.ContextMenuStrip.Items.Add("Импорт данных", null, this.ImportDataBase);
this.notifyIcon1.ContextMenuStrip.Items.Add("Выйти", null, this.ExitApp);
(this.notifyIcon1.ContextMenuStrip.Items[2] as ToolStripMenuItem).DropDownItems.Add("Запустить фокусировку", null, this.StartFocus);
(this.notifyIcon1.ContextMenuStrip.Items[2] as ToolStripMenuItem).DropDownItems.Add("Запустить перерыв", null, this.StartBreak);
(this.notifyIcon1.ContextMenuStrip.Items[2] as ToolStripMenuItem).DropDownItems.Add("Запустить длинный перерыв", null, this.StartLongBreak);
DirectoryInfo di = new DirectoryInfo("playlist\\");
di.Create();
di = new DirectoryInfo("sounds\\");
di.Create();
var f = Directory.GetFiles("sounds\\", "*.mp3");
foreach (string f2 in f)
{
var temp = f2.Split('\\')[1].Split('.')[0];
this.comboBox1.Items.Add(temp);
this.comboBox2.Items.Add(temp);
this.comboBox3.Items.Add(temp);
this.comboBox4.Items.Add(temp);
}
TimersHide();
if (!System.IO.File.Exists("userdata.db"))
{
using (var connection = new SqliteConnection("Data Source=userdata.db;Mode=ReadWriteCreate"))
{
connection.Open();
SqliteCommand command = new SqliteCommand
{
Connection = connection
};
var SQL = "CREATE TABLE \"timers\" (\"date\" INTEGER NOT NULL,\"type\" INTEGER NOT NULL,\"id\" INTEGER NOT NULL UNIQUE,\"length\" INTEGER NOT NULL,\"start\" INTEGER NOT NULL,\"end\" INTEGER NOT NULL,PRIMARY KEY(\"id\" AUTOINCREMENT))";
command.CommandText = SQL;
_ = command.ExecuteNonQuery();
SQL = "CREATE TABLE \"user_pref\" (" +
"\"id\" INTEGER NOT NULL," +
"\"focus_time\" INTEGER NOT NULL DEFAULT 25," +
"\"break_time\" INTEGER NOT NULL DEFAULT 5," +
"\"lbreak_time\" INTEGER NOT NULL DEFAULT 15," +
"\"before_lbreak\" INTEGER NOT NULL DEFAULT 4," +
"\"f1_sound\" TEXT DEFAULT \'нет\'," +
"\"f2_sound\" TEXT DEFAULT \'нет\'," +
"\"b_sound\" TEXT DEFAULT \'нет\'," +
"\"lb_sound\" TEXT DEFAULT \'нет\', " +
"\"nort_timer\" INTEGER DEFAULT 1, " +
"\"nort_lb_logic\" INTEGER DEFAULT 0," +
"\"pl_status\" INTEGER DEFAULT 0," +
"\"pl_repeat\" INTEGER DEFAULT 1," +
"\"pl_break\" INTEGER DEFAULT 1," +
"\"pl_folder\" TEXT DEFAULT 'playlist'" +
")";
command.CommandText = SQL;
_ = command.ExecuteNonQuery();
SQL = "INSERT INTO user_pref(id) VALUES(0)";
command.CommandText = SQL;
_ = command.ExecuteNonQuery();
connection.Close();
}
}
fixDataBase();
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand();
command.Connection = connection;
command.CommandText = "SELECT * FROM user_pref";
using (SqliteDataReader reader = command.ExecuteReader())
{
if (reader.HasRows) // если есть данные
{
while (reader.Read())
{
object id = reader[0];
focus_time = (long)reader.GetValue(1);
break_time = (long)reader.GetValue(2);
long_break_time = (long)reader.GetValue(3);
long_break_n = Convert.ToInt32(reader.GetValue(4));
f1_sound = Convert.ToString(reader.GetValue(5));
f2_sound = Convert.ToString(reader.GetValue(6));
b_sound = Convert.ToString(reader.GetValue(7));
lb_sound = Convert.ToString(reader.GetValue(8));
ofs_timer = Convert.ToBoolean(reader.GetValue(9));
lb_logic = Convert.ToBoolean(reader.GetValue(10));
pl_status = Convert.ToBoolean(reader.GetValue(11));
pl_repeat = Convert.ToBoolean(reader.GetValue(12));
pl_break = Convert.ToBoolean(reader.GetValue(13));
pl_folder = Convert.ToString(reader.GetValue(14));
if (pl_status && this.notifyIcon1.ContextMenuStrip.Items[this.notifyIcon1.ContextMenuStrip.Items.Count - 2].Text != "Следующий трек")
{
this.notifyIcon1.ContextMenuStrip.Items.Insert(this.notifyIcon1.ContextMenuStrip.Items.Count - 1, new ToolStripMenuItem("Приостановить плеер", null, pl_pause));
this.notifyIcon1.ContextMenuStrip.Items.Insert(this.notifyIcon1.ContextMenuStrip.Items.Count - 1, new ToolStripMenuItem("Следующий трек", null, pl_nextTrack));
}
}
}
}
connection.Close();
}
if (!System.IO.Directory.Exists(pl_folder))
{
MessageBox.Show("Указанная папка не существует, установлена папка по умолчанию - playlist.");
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand();
command.Connection = connection;
pl_folder = "playlist";
command.CommandText = "UPDATE user_pref SET pl_folder = \"playlist\" WHERE id=0";
command.ExecuteNonQuery();
connection.Close();
}
}
pl_main.currentPlaylist = pl_main.newPlaylist("main", "");
var rng = new Random();
f = Directory.GetFiles(pl_folder + "\\", "*.mp3").OrderBy(x => rng.Next()).ToArray();
foreach (string f1 in f)
{
pl_main.currentPlaylist.appendItem(pl_main.newMedia(f1));
}
pl_main.settings.setMode("shuffle", true);
pl_main.settings.setMode("loop", pl_repeat);
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand
{
Connection = connection
};
int temp_year = 0;
command = new SqliteCommand("SELECT COUNT(*) FROM timers WHERE type = 1", connection);
int current_n = 0;
current_n = Convert.ToInt32(command.ExecuteScalar());
if (current_n != 0)
{
command.CommandText = "SELECT * FROM timers ORDER BY date LIMIT 1";
using (SqliteDataReader reader = command.ExecuteReader())
{
if (reader.HasRows) // если есть данные
{
while (reader.Read())
{
temp_year = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt32(reader.GetValue(0))).Year;
}
}
}
while (temp_year < Convert.ToInt32(DateTimeOffset.Now.Year))
{
_ = comboBox6.Items.Add(temp_year);
temp_year++;
}
}
connection.Close();
}
_ = comboBox6.Items.Add(DateTimeOffset.Now.Year);
comboBox6.SelectedItem = DateTimeOffset.Now.Year;
}
private void fixDataBase()
{
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand
{
Connection = connection
};
#region --# nort_timer #--
command = new SqliteCommand(" ALTER TABLE user_pref ADD nort_timer INTEGER NOT NULL DEFAULT 1", connection);
try
{
command.ExecuteNonQuery();
}
catch
{
}
#endregion
#region --# nort_lb_logic #--
command = new SqliteCommand(" ALTER TABLE user_pref ADD nort_lb_logic INTEGER NOT NULL DEFAULT 0", connection); // 0 - обработка по кукумберам, 1 - обработка по перерывам
try
{
command.ExecuteNonQuery();
}
catch
{
}
#endregion
#region --# pl_status #--
command = new SqliteCommand(" ALTER TABLE user_pref ADD pl_status INTEGER NOT NULL DEFAULT 0", connection);
try
{
command.ExecuteNonQuery();
}
catch
{
}
#endregion
#region --# pl_repeat #--
command = new SqliteCommand(" ALTER TABLE user_pref ADD pl_repeat INTEGER NOT NULL DEFAULT 1", connection);
try
{
command.ExecuteNonQuery();
}
catch
{
}
#endregion
#region --# pl_break #--
command = new SqliteCommand(" ALTER TABLE user_pref ADD pl_break INTEGER NOT NULL DEFAULT 1", connection);
try
{
command.ExecuteNonQuery();
}
catch
{
}
#endregion
#region --# pl_folder #--
command = new SqliteCommand(" ALTER TABLE user_pref ADD pl_folder TEXT NOT NULL DEFAULT \"playlist\"", connection);
try
{
command.ExecuteNonQuery();
}
catch
{
}
#endregion
connection.Close();
}
}
private void ImportDataBase(object sender, EventArgs e)
{
OpenFileDialog theDialog = new OpenFileDialog();
theDialog.Title = "Выберите SQLite базу данных";
theDialog.Filter = "SQLite format|*.db";
theDialog.InitialDirectory = @"C:\";
if (theDialog.ShowDialog() == DialogResult.OK)
{
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
string SQL = "ATTACH '" + theDialog.FileName + "' AS TOMERGE";
SqliteCommand cmd = new SqliteCommand(SQL);
cmd.Connection = connection;
connection.Open();
int retval = 0;
try
{
retval = cmd.ExecuteNonQuery();
}
catch (Exception Er)
{
MessageBox.Show("An error occurred, your import was not completed.\n" + Er.Message);
}
finally
{
cmd.Dispose();
}
SQL = "INSERT INTO timers(date,type,length,start,end) SELECT date,type,length,start,end FROM TOMERGE.timers";
cmd = new SqliteCommand(SQL);
cmd.Connection = connection;
retval = 0;
try
{
retval = cmd.ExecuteNonQuery();
}
catch (Exception Er)
{
MessageBox.Show("An error occurred, your import was not completed.\n" + Er.Message);
}
finally
{
cmd.Dispose();
}
SQL = "DETACH TOMERGE";
cmd.Connection = connection;
connection.Open();
retval = 0;
try
{
retval = cmd.ExecuteNonQuery();
}
catch (Exception Er)
{
MessageBox.Show("An error occurred, your import was not completed.\n" + Er.Message);
}
finally
{
cmd.Dispose();
connection.Close();
}
}
comboBox6.Items.Clear();
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand
{
Connection = connection
};
int temp_year = 0;
command = new SqliteCommand("SELECT COUNT(*) FROM timers WHERE type = 1", connection);
int current_n = 0;
current_n = Convert.ToInt32(command.ExecuteScalar());
if (current_n != 0)
{
command.CommandText = "SELECT * FROM timers ORDER BY date LIMIT 1";
using (SqliteDataReader reader = command.ExecuteReader())
{
if (reader.HasRows) // если есть данные
{
while (reader.Read())
{
temp_year = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt32(reader.GetValue(0))).Year;
}
}
}
while (temp_year < Convert.ToInt32(DateTimeOffset.Now.Year))
{
_ = comboBox6.Items.Add(temp_year);
temp_year++;
}
}
connection.Close();
}
_ = comboBox6.Items.Add(DateTimeOffset.Now.Year);
comboBox6.SelectedItem = DateTimeOffset.Now.Year;
}
}
private void ExitApp(object sender, EventArgs e)
{
base.Close();
}
private void OpenSettings(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 0;
string[] installs;
if (!lb_logic)
{
installs = new string[] { "никогда",
"через каждый кукумбер",
"через каждый 2-ой кукумбер",
"через каждый 3-ий кукумбер",
"через каждый 4-ый кукумбер",
"через каждый 5-ый кукумбер",
"через каждый 6-ой кукумбер",
"через каждый 7-ой кукумбер",
"через каждый 8-ой кукумбер",
"через каждый 9-ый кукумбер",
"через каждый 10-ый кукумбер"};
}
else
{
installs = new string[] { "никогда",
"каждый перерыв",
"каждый 2-ой перерыв",
"каждый 3-ий перерыв",
"каждый 4-ый перерыв",
"каждый 5-ый перерыв",
"каждый 6-ой перерыв",
"каждый 7-ой перерыв",
"каждый 8-ой перерыв",
"каждый 9-ый перерыв",
"каждый 10-ый перерыв"};
}
comboBox5.Items.Clear();
comboBox5.Items.AddRange(installs);
if (long_break_n < 0)
{
this.comboBox5.SelectedIndex = 0;
}
else
{
this.comboBox5.SelectedIndex = long_break_n;
}
this.comboBox1.SelectedItem = f1_sound;
this.comboBox2.SelectedItem = f2_sound;
this.comboBox3.SelectedItem = b_sound;
this.comboBox4.SelectedItem = lb_sound;
this.textBox1.Text = Convert.ToString(focus_time);
this.textBox2.Text = Convert.ToString(break_time);
this.textBox3.Text = Convert.ToString(long_break_time);
this.groupBox2.Visible = true;
this.groupBox3.Visible = true;
this.groupBox4.Visible = true;
this.offsetTimer.Checked = ofs_timer;
this.lbLogic.Checked = lb_logic;
this.playerEnabled.Checked = pl_status;
this.repeatPlaylist.Checked = pl_repeat;
this.playlistFolder.Text = pl_folder;
this.pauseMusicBreak.Checked = pl_break;
this.button3.BackColor = System.Drawing.Color.SeaGreen;
this.button4.BackColor = System.Drawing.Color.MediumSeaGreen;
this.Focus();
this.Visible = true;
this.WindowState = FormWindowState.Normal;
}
private void TimersHide()
{
this.notifyIcon1.ContextMenuStrip.Items[0].Visible = false;
this.notifyIcon1.ContextMenuStrip.Items[1].Visible = false;
this.notifyIcon1.ContextMenuStrip.Items[2].Visible = false;
this.notifyIcon1.ContextMenuStrip.Items[3].Visible = true;
this.notifyIcon1.ContextMenuStrip.Items[4].Visible = true;
this.notifyIcon1.ContextMenuStrip.Items[5].Visible = true;
}
private void TimersShow()
{
this.notifyIcon1.ContextMenuStrip.Items[0].Visible = true;
this.notifyIcon1.ContextMenuStrip.Items[1].Visible = true;
this.notifyIcon1.ContextMenuStrip.Items[2].Visible = true;
this.notifyIcon1.ContextMenuStrip.Items[3].Visible = false;
this.notifyIcon1.ContextMenuStrip.Items[4].Visible = false;
this.notifyIcon1.ContextMenuStrip.Items[5].Visible = false;
}
public void StartLongBreak(object sender, EventArgs e)
{
startTime = DateTimeOffset.Now.ToUnixTimeSeconds();
stopTime = DateTimeOffset.Now.AddMinutes(long_break_time).ToUnixTimeSeconds();
timerx.Enabled = true;
_timer_work = true;
_timer_type = 3;
timerx.Tick += new EventHandler(Timer_Tick);
TimersShow();
this.notifyIcon1.ContextMenuStrip.Items[0].Text = "Приостановить таймер";
if (System.IO.File.Exists("images/delay.ico"))
{
this.notifyIcon1.Icon = new Icon("images/delay.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.delay;
}
if (pl_status && !pl_paused && pl_break)
{
pl_main.controls.pause();
}
}
public void StartBreak(object sender, EventArgs e)
{
startTime = DateTimeOffset.Now.ToUnixTimeSeconds();
stopTime = DateTimeOffset.Now.AddMinutes(break_time).ToUnixTimeSeconds();
timerx.Enabled = true;
_timer_work = true;
_timer_type = 2;
timerx.Tick += new EventHandler(Timer_Tick);
TimersShow();
this.notifyIcon1.ContextMenuStrip.Items[0].Text = "Приостановить таймер";
if (System.IO.File.Exists("images/delay.ico"))
{
this.notifyIcon1.Icon = new Icon("images/delay.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.delay;
}
if (pl_status && !pl_paused && pl_break)
{
pl_main.controls.pause();
}
}
public void StartFocus(object sender, EventArgs e)
{
startTime = DateTimeOffset.Now.ToUnixTimeSeconds();
stopTime = DateTimeOffset.Now.AddMinutes(focus_time).ToUnixTimeSeconds();
timerx.Enabled = true;
_timer_work = true;
_timer_type = 1;
timerx.Tick += new EventHandler(Timer_Tick);
TimersShow();
this.notifyIcon1.ContextMenuStrip.Items[0].Text = "Приостановить таймер";
if (System.IO.File.Exists("images/focus.ico"))
{
this.notifyIcon1.Icon = new Icon("images/focus.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.focus;
}
if (f1_sound != "нет")
{
wplayer.URL = "sounds/" + f1_sound + ".mp3";
wplayer.controls.play();
}
if (pl_status && !pl_paused)
{
pl_main.controls.play();
}
}
public void PauseClick(object sender, EventArgs e)
{
if (!_timer_pause)
{
pauseMoment = DateTimeOffset.Now.ToUnixTimeSeconds();
timerx.Stop();
_timer_pause = true;
this.notifyIcon1.ContextMenuStrip.Items[0].Text = "Возобновить таймер";
var date = DateTimeOffset.FromUnixTimeSeconds(stopTime - DateTimeOffset.Now.ToUnixTimeSeconds());
switch (_timer_type)
{
case 1:
notifyIcon1.Text = "Режим: Фокусировка";
break;
case 2:
notifyIcon1.Text = "Режим: Короткий перерыв";
break;
case 3:
notifyIcon1.Text = "Режим: Длинный перерыв";
break;
}
if (_timer_pause)
{
notifyIcon1.Text += "\nСтатус: Пауза";
}
else
{
notifyIcon1.Text += "\nСтатус: Активен";
}
notifyIcon1.Text += "\nОсталось: " + date.ToString("HH:mm:ss");
if (System.IO.File.Exists("images/pause.ico"))
{
this.notifyIcon1.Icon = new Icon("images/pause.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.pause;
}
if (pl_status && !pl_paused && pl_break)
{
pl_main.controls.pause();
}
}
else
{
stopTime += (DateTimeOffset.Now.ToUnixTimeSeconds() - pauseMoment);
timerx.Start();
timerx.Enabled = true;
_timer_pause = false;
this.notifyIcon1.ContextMenuStrip.Items[0].Text = "Приостановить таймер";
switch (_timer_type)
{
case 1:
if (System.IO.File.Exists("images/focus.ico"))
{
this.notifyIcon1.Icon = new Icon("images/focus.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.focus;
}
if (pl_status && !pl_paused)
{
pl_main.controls.play();
}
break;
case 2:
if (System.IO.File.Exists("images/delay.ico"))
{
this.notifyIcon1.Icon = new Icon("images/delay.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.delay;
}
break;
case 3:
if (System.IO.File.Exists("images/delay.ico"))
{
this.notifyIcon1.Icon = new Icon("images/delay.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.delay;
}
break;
}
}
}
public void StopClick(object sender, EventArgs e)
{
if (_timer_work)
{
startTime = -1;
stopTime = -1;
timerx.Enabled = false;
_timer_work = false;
_timer_pause = false;
TimersHide();
this.notifyIcon1.ContextMenuStrip.Items[0].Text = "Приостановить таймер";
notifyIcon1.Text = "Нет активных таймеров.";
if (System.IO.File.Exists("images/none.ico"))
{
this.notifyIcon1.Icon = new Icon("images/none.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.none;
}
if (pl_status && !pl_paused)
{
pl_main.controls.pause();
}
}
}
private void NotifyIcon1_MClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (_timer_work)
{
PauseClick(sender, e);
}
else
{
startTime = DateTimeOffset.Now.ToUnixTimeSeconds();
switch (_timer_type)
{
default:
stopTime = DateTimeOffset.Now.AddMinutes(focus_time).ToUnixTimeSeconds();
_timer_type = 1;
if (System.IO.File.Exists("images/focus.ico"))
{
this.notifyIcon1.Icon = new Icon("images/focus.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.focus;
}
if (pl_status && !pl_paused)
{
pl_main.controls.play();
}
break;
case 2:
stopTime = DateTimeOffset.Now.AddMinutes(break_time).ToUnixTimeSeconds();
if (System.IO.File.Exists("images/delay.ico"))
{
this.notifyIcon1.Icon = new Icon("images/delay.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.delay;
}
if (pl_status && !pl_paused && pl_break)
{
pl_main.controls.pause();
}
break;
case 3:
stopTime = DateTimeOffset.Now.AddMinutes(long_break_time).ToUnixTimeSeconds();
if (System.IO.File.Exists("images/delay.ico"))
{
this.notifyIcon1.Icon = new Icon("images/delay.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.delay;
}
if (pl_status && !pl_paused && pl_break)
{
pl_main.controls.pause();
}
break;
}
timerx.Enabled = true;
_timer_work = true;
timerx.Tick += new EventHandler(Timer_Tick);
TimersShow();
this.notifyIcon1.ContextMenuStrip.Items[0].Text = "Приостановить таймер";
notifyIcon1.Text = "Нет активных таймеров.";
}
}
}
private void Timer_Tick(object sender, EventArgs e)
{
if (stopTime - DateTimeOffset.Now.ToUnixTimeSeconds() <= 0 && _timer_work)
{
_timer_work = false;
timerx.Enabled = false;
_timer_pause = false;
timerx.Stop();
timerx.Tick -= Timer_Tick;
TimersHide();
this.notifyIcon1.ContextMenuStrip.Items[0].Text = "Приостановить таймер";
notifyIcon1.Text = "Нет активных таймеров.";
if (System.IO.File.Exists("images/none.ico"))
{
this.notifyIcon1.Icon = new Icon("images/none.ico");
}
else
{
this.notifyIcon1.Icon = pomidor.Properties.Resources.none;
}
switch (_timer_type)
{
case 1:
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand("INSERT INTO timers(`date`, `start`, `end`, `length`,`type`) VALUES(" + Convert.ToString(DateTimeOffset.Now.ToUnixTimeSeconds()) + "," + Convert.ToString(startTime) + "," + Convert.ToString(stopTime) + "," + Convert.ToString(stopTime - startTime) + "," + Convert.ToString(_timer_type) + ")", connection);
command.ExecuteNonQuery();
command = new SqliteCommand("SELECT COUNT(*) FROM timers WHERE (date-(date%86400))/86400 = " + Convert.ToString(DateTimeOffset.Now.ToUnixTimeSeconds() / 86400) + " AND type = 2", connection);
int current_n = 0;
int current_lb = 0;
int current_t = 0;
current_n = Convert.ToInt32(command.ExecuteScalar());
command = new SqliteCommand("SELECT COUNT(*) FROM timers WHERE (date-(date%86400))/86400 = " + Convert.ToString(DateTimeOffset.Now.ToUnixTimeSeconds() / 86400) + " AND type = 3", connection);
current_lb = Convert.ToInt32(command.ExecuteScalar());
command = new SqliteCommand("SELECT COUNT(*) FROM timers WHERE (date-(date%86400))/86400 = " + Convert.ToString(DateTimeOffset.Now.ToUnixTimeSeconds() / 86400) + " AND type = 1", connection);
current_t = Convert.ToInt32(command.ExecuteScalar());
if (f2_sound != "нет")
{
wplayer.URL = "sounds/" + f2_sound + ".mp3";
wplayer.controls.play();
}
if ((current_t % long_break_n == 0 && !lb_logic) || ((current_n + current_lb) % long_break_n == long_break_n - 1 && lb_logic))
{
_timer_type = 3;
Nortification("", 3);
}
else
{
_timer_type = 2;
Nortification("", 2);
}
StopClick(sender, e);
connection.Close();
}
break;
default:
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand("INSERT INTO timers(`date`, `start`, `end`, `length`,`type`) VALUES(" + Convert.ToString(DateTimeOffset.Now.ToUnixTimeSeconds()) + "," + Convert.ToString(startTime) + "," + Convert.ToString(stopTime) + "," + Convert.ToString(stopTime - startTime) + "," + Convert.ToString(_timer_type) + ")", connection);
command.ExecuteNonQuery();
connection.Close();
}
if (_timer_type == 2)
{
if (b_sound != "нет")
{
wplayer.URL = "sounds/" + b_sound + ".mp3";
wplayer.controls.play();
}
}
else if (_timer_type == 3)
{
if (lb_sound != "нет")
{
wplayer.URL = "sounds/" + lb_sound + ".mp3";
wplayer.controls.play();
}
}
_timer_type = 1;
if (f1_sound != "нет")
{
wplayer.URL = "sounds/" + f1_sound + ".mp3";
wplayer.controls.play();
}
Nortification("", 1);
StopClick(sender, e);
break;
}
Task.Run(Calc_heatmap);
}
else if (_timer_work)
{
var date = DateTimeOffset.FromUnixTimeSeconds(stopTime - DateTimeOffset.Now.ToUnixTimeSeconds());
switch (_timer_type)
{
case 1:
notifyIcon1.Text = "Режим: Фокусировка";
break;
case 2:
notifyIcon1.Text = "Режим: Короткий перерыв";
break;
case 3:
notifyIcon1.Text = "Режим: Длинный перерыв";
break;
}
if (_timer_pause)
{
notifyIcon1.Text += "\nСтатус: Пауза";
}
else
{
notifyIcon1.Text += "\nСтатус: Активен";
}
notifyIcon1.Text += "\nОсталось: " + date.ToString("HH:mm:ss");
}
}
public void Nortification(string msg, int type)
{
Form_Nortification frm = new Form_Nortification(this);
frm.showAlert(msg, type, long_break_n);
}
private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedState = comboBox5.SelectedIndex;
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand();
command.Connection = connection;
command.CommandText = "UPDATE user_pref SET before_lbreak = ";
if (selectedState == 0)
{
selectedState = -1;
}
command.CommandText += Convert.ToString(selectedState) + " WHERE id=0";
command.ExecuteNonQuery();
long_break_n = selectedState;
connection.Close();
}
}
private void TextBox1_TextChanged(object sender, EventArgs e)
{
string txt = this.textBox1.Text;
if (txt == "")
{
txt = "1";
this.textBox1.Text = txt;
}
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand();
command.Connection = connection;
command.CommandText = "UPDATE user_pref SET focus_time = ";
command.CommandText += txt + " WHERE id=0";
command.ExecuteNonQuery();
focus_time = Convert.ToInt64(txt);
connection.Close();
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
string txt = this.textBox2.Text;
if (txt == "")
{
txt = "1";
this.textBox2.Text = txt;
}
using (var connection = new SqliteConnection("Data Source=userdata.db"))
{
connection.Open();
SqliteCommand command = new SqliteCommand();
command.Connection = connection;
command.CommandText = "UPDATE user_pref SET break_time = ";
command.CommandText += txt + " WHERE id=0";
command.ExecuteNonQuery();
break_time = Convert.ToInt64(txt);
connection.Close();
}
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
string txt = this.textBox3.Text;
if (txt == "")