-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
478 lines (447 loc) · 18.4 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZoomAutoRecorder.Utils;
namespace ZoomAutoRecorder
{
public partial class Main : Form
{
public static List<Lesson> Lessons;
public readonly static List<string> Days = new List<string>() {
"Paz",
"Pzt",
"Sali",
"Cars",
"Pers",
"Cuma",
"Cumt"
};
public static Database.General Manager;
public static ZoomEntities ZoomEntities;
public static BGWorker BGWorker;
public static ConfigManagement Cfg;
string day = "";
ListBox lbToday => Controls.Find($"lb{day}", true)[0] as ListBox;
ListBox Selected;
public Main()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
Lessons = new List<Lesson>();
Manager = new Database.General();
ZoomEntities = new ZoomEntities();
BGWorker = new BGWorker(ref backgroundWorker1);
Cfg = new ConfigManagement();
}
private void Main_Load(object sender, EventArgs e)
{
Manager.RefLessons();
RefProgram();
RefBG();
Manager.Update.CheckUpdate();
ToolTip tip = new ToolTip();
tip.SetToolTip(btnReset, "Yenile");
tip.SetToolTip(btnProgramSettings, "Program Ayarları");
tip.SetToolTip(barDownload, "Yeni sürüm indiriliyor...");
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
//notify.BalloonTipClosed += (s, f) => { var thisIcon = (NotifyIcon)s; thisIcon.Visible = false; thisIcon.Dispose(); };
notify.Visible = false;
notify.Icon = null;
notify.Dispose();
try
{
if (CefSharp.Cef.IsInitialized) CefSharp.Cef.Shutdown();
}
catch (Exception)
{
}
Application.Exit();
}
private void Main_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
btnAppHS.Text = "Programı Göster";
this.Hide();
}
}
public static void ShowError(string message, string title = "HATA")
{
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
public static void ShowInfo(string message, string title)
{
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public static DialogResult ShowAsk(string message, string title)
{
return MessageBox.Show(message, title, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
}
public void ShowBalloon(string title, string message, int timeout = 2000)
{
notify.BalloonTipTitle = title;
notify.BalloonTipText = message;
notify.ShowBalloonTip(timeout);
}
public static bool CheckBetweenDates(DateTime date)
{
DateTime date1 = new DateTime(1, 1, 1, date.Hour, date.Minute, 0);
DateTime date2 = date1.AddMinutes(30);
date = new DateTime(1, 1, 1, DateTime.Now.Hour, DateTime.Now.Minute, 0);
return date >= date1 && date < date2;
}
public void RefProgram()
{
string[] spl = Properties.Settings.Default.LessonTime.Split('|');
ListBox nully = new ListBox();
for (int i = 0; i < spl.Count(); i++)
nully.Items.Add("Boş");
lbPzt.Items.Clear();
lbPzt.Items.AddRange(nully.Items);
lbSali.Items.Clear();
lbSali.Items.AddRange(nully.Items);
lbCars.Items.Clear();
lbCars.Items.AddRange(nully.Items);
lbPers.Items.Clear();
lbPers.Items.AddRange(nully.Items);
lbCuma.Items.Clear();
lbCuma.Items.AddRange(nully.Items);
lbCumt.Items.Clear();
lbCumt.Items.AddRange(nully.Items);
lbPaz.Items.Clear();
lbPaz.Items.AddRange(nully.Items);
Manager.RefreshProgram();
}
public void RefBG()
{
if (Properties.Settings.Default.AutoStart)
{
btnAutoZoom.Text = "Otomatik Toplantıyı Durdur";
if (!backgroundWorker1.IsBusy) backgroundWorker1.RunWorkerAsync();
}
else
{
btnAutoZoom.Text = "Otomatik Toplantıyı Başlat";
}
}
private void btnSettings_Click(object sender, EventArgs e)
{
if (Control.ModifierKeys == Keys.Shift) //YEDEKLE
{
Cfg.BackupConfig();
ShowInfo("Yedekleme başarılı.", "BAŞARILI");
}
else if (Control.ModifierKeys == Keys.Control) //YEDEKTEN GERİ YÜKLE
{
openFileDialog1.InitialDirectory = System.IO.Path.Combine(Application.StartupPath, "Backups");
var dialog = openFileDialog1.ShowDialog();
if (dialog != DialogResult.OK) return;
string path = openFileDialog1.FileName;
Cfg.RestoreConfig(path);
RefProgram();
ShowInfo("Geri yükleme başarılı.", "BAŞARILI");
}
else
MainClass.OpenForm(new Settings());
}
private void btnLessons_Click(object sender, EventArgs e)
{
MainClass.OpenForm(new Lessons());
}
private void btnProgramSettings_Click(object sender, EventArgs e)
{
MainClass.OpenForm(new SetProgram());
}
private void btnAppClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void lbDersler_MouseDown(object sender, MouseEventArgs e)
{
if (lbDersler.SelectedItems.Count > 0 && ModifierKeys == Keys.None)
{
DoDragDrop(lbDersler.SelectedItem, DragDropEffects.Move);
lbDersler.SelectedIndex = -1;
}
}
private async void lbDersler_MouseClick(object sender, MouseEventArgs e)
{
if (Control.ModifierKeys == Keys.Shift && lbDersler.SelectedItems.Count > 0)
{
Lesson lesson = Lessons.FirstOrDefault(x => x.Name == lbDersler.SelectedItem.ToString());
await ZoomEntities.StartLesson(false, false, lesson);
lbDersler.SelectedIndex = -1;
}
}
private void btnAppHS_Click(object sender, EventArgs e)
{
if (btnAppHS.Text == "Programı Gizle")
{
this.Hide();
btnAppHS.Text = "Programı Göster";
}
else
{
this.Show();
this.WindowState = FormWindowState.Normal;
btnAppHS.Text = "Programı Gizle";
}
}
private void btnAbout_Click(object sender, EventArgs e)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("Adı: Zoom Otomatik Kaydedici");
builder.AppendLine("Sürüm: " + MainClass.version);
builder.AppendLine("Firma: Corelium Development INC");
builder.AppendLine("Geliştirici: F.M. Yılmaz");
builder.AppendLine("Tüm Hakları Saklıdır @ 2021");
ShowInfo(builder.ToString(), "Z.O.K. Hakkında");
}
private void btnAutoZoom_Click(object sender, EventArgs e)
{
Properties.Settings.Default.AutoStart = !Properties.Settings.Default.AutoStart;
ShowInfo("Değişikliklerin uygulanması için uygulamayı yeniden başlatmanız gerekmektedir.", "UYARI");
RefBG();
}
private void btnReset_Click(object sender, EventArgs e)
{
Manager.RefLessons();
RefProgram();
BGWorker.isEBA = false;
BGWorker.isStarted = false;
RefBG();
btnAppHS.Text = "Programı Gizle";
if (Control.ModifierKeys == Keys.Control)
for (int i = 0; i < Days.Count; i++)
(Controls.Find($"lb{Days[i]}", true)[0] as ListBox).SelectedIndex = -1;
else if (Control.ModifierKeys == Keys.Shift && !string.IsNullOrEmpty(Properties.Settings.Default.LessonTime)) //Ders önceden açıldı mı?
{
string[] times = Properties.Settings.Default.LessonTime.Split('|');
bool y = false;
foreach (string time in times)
{
DateTime dtime = new DateTime(1, 1, 1, DateTime.Parse(time).Hour, DateTime.Parse(time).Minute, 0);
DateTime now = new DateTime(1, 1, 1, DateTime.Now.Hour, DateTime.Now.Minute, 0);
if (now >= dtime && now < dtime.AddMinutes(30)) y = true;
}
if (!y || !backgroundWorker1.IsBusy) return;
BGWorker.isStarted = true;
}
}
private void btnEBA_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(day)) return;
int lid = Lessons.FirstOrDefault(x => x.Name == lbToday.SelectedItem.ToString()).ID;
bool eba;
if (btnEBA.Text == "EBA Aç")
{
btnEBA.Text = "EBA Kapat";
eba = true;
}
else
{
btnEBA.Text = "EBA Aç";
eba = false;
}
Manager.EBASwitch(lid, Days.IndexOf(day), eba, lbToday.SelectedIndex);
lbToday.SelectedIndex = -1;
}
private void btnOnce_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(day)) return;
var sndr = sender as ToolStripMenuItem;
if (MainClass.OnceDontOpen.Contains(lbToday.SelectedIndex))
{
MainClass.OnceDontOpen.Remove(lbToday.SelectedIndex);
sndr.Text = "Bir Kereliğine Açma";
}
else
{
MainClass.OnceDontOpen.Add(lbToday.SelectedIndex);
sndr.Text = "Her Zaman Aç";
}
lbToday.SelectedIndex = -1;
}
private void notify_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
if (this.WindowState == FormWindowState.Minimized)
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
btnAppHS.Text = "Programı Gizle";
}
else
{
this.WindowState = FormWindowState.Minimized;
btnAppHS.Text = "Programı Göster";
}
}
private void btnBrowser_Click(object sender, EventArgs e)
{
string[] tcknpass = Properties.Settings.Default.TCKNPASS.Split('#');
if (tcknpass.Count() == 2)
{
new Browser(Encryption.Decrypt(tcknpass[0]), Encryption.Decrypt(tcknpass[1]), true).Show();
this.WindowState = FormWindowState.Minimized;
}
else
ShowError("EBA giriş bilgileri ayarlanmadı!");
}
private void btnProgDel_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(day)) return;
OnKeyDown(lbToday, new KeyEventArgs(Keys.Delete));
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
ListBox lb = sender as ListBox;
if (e.KeyData == Keys.Escape)
lb.SelectedIndex = -1;
else if (e.KeyData == Keys.Delete && lb.SelectedItems.Count > 0)
{
int day = Days.IndexOf(lb.Name.Replace("lb", ""));
Manager.DeleteLessonFromProgram(lb.SelectedIndex, day);
lb.Items[lb.SelectedIndex] = "Boş";
lb.SelectedIndex = -1;
}
}
private void OnClick(object sender, MouseEventArgs e)
{
Selected = sender as ListBox;
}
private void OnClickLB(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ListBox lb = sender as ListBox;
if (lb.SelectedIndex >= 0)
{
day = lb.Name.Replace("lb", "");
if (lb.SelectedItem.ToString() != "Boş")
{
Lesson lesson = Lessons.FirstOrDefault(x => x.Name == lb.SelectedItem.ToString());
lb.ContextMenuStrip.Items[0].Visible = true;
bool check = Manager.GetEBAState(lesson.ID, Days.IndexOf(day), lb.SelectedIndex);
if (check) lb.ContextMenuStrip.Items[0].Text = "EBA Kapat";
else lb.ContextMenuStrip.Items[0].Text = "EBA Aç";
lb.ContextMenuStrip.Items[1].Visible = true;
if ((int)DateTime.Now.DayOfWeek == Days.IndexOf(day))
{
lb.ContextMenuStrip.Items[2].Visible = true;
if (MainClass.OnceDontOpen.Contains(lb.SelectedIndex))
lb.ContextMenuStrip.Items[2].Text = "Her Zaman Aç";
else
lb.ContextMenuStrip.Items[2].Text = "Bir Kereliğine Açma";
}
else lb.ContextMenuStrip.Items[2].Visible = false;
lb.ContextMenuStrip.Items[3].Visible = true;
lb.ContextMenuStrip.Items[4].Visible = true;
string[] times = Properties.Settings.Default.LessonTime.Split('|');
if (BGWorker.isStarted && ZoomEntities.StartedLessonID == lesson.ID)
lb.ContextMenuStrip.Items[4].Text = "Durdur";
else
lb.ContextMenuStrip.Items[4].Text = "Başlat";
return;
}
}
lb.ContextMenuStrip.Items[0].Visible = false;
lb.ContextMenuStrip.Items[1].Visible = false;
lb.ContextMenuStrip.Items[2].Visible = false;
lb.ContextMenuStrip.Items[3].Visible = false;
lb.ContextMenuStrip.Items[4].Visible = false;
lb.SelectedIndex = -1;
}
}
private void OnDragDrop(object sender, DragEventArgs e)
{
ListBox lb = sender as ListBox;
if (lb.SelectedIndex >= 0)
{
string name = e.Data.GetData("System.String").ToString();
Lesson lesson = Lessons.FirstOrDefault(x => x.Name == name);
int day = Days.IndexOf(lb.Name.Replace("lb", ""));
Manager.AddLessonToProgram(lesson, lb.SelectedIndex, day);
lb.Items[lb.SelectedIndex] = name;
lb.SelectedIndex = -1;
}
}
private void OnDragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private async void OnDoubleClick(object sender, MouseEventArgs e)
{
ListBox lb = sender as ListBox;
if (lb.SelectedItems.Count <= 0 || lb.SelectedItem.ToString() == "Boş") return;
Lesson lesson = Lessons.FirstOrDefault(x => x.Name == lb.SelectedItem.ToString());
int index = lbDersler.Items.IndexOf(lb.SelectedItem.ToString());
bool check = Manager.GetEBAState(lesson.ID, Days.IndexOf(lb.Name.Replace("lb", "")), lb.SelectedIndex);
if (check)
{
string[] times = Properties.Settings.Default.LessonTime.Split('|');
if (!CheckBetweenDates(DateTime.Parse(times[lb.SelectedIndex])))
{
lb.SelectedIndex = -1;
return;
}
}
if (backgroundWorker1.IsBusy)
{
BGWorker.isStarted = true;
if (check)
{
BGWorker.isEBA = check;
BGWorker.ix = lb.SelectedIndex;
}
}
lb.SelectedIndex = -1;
await ZoomEntities.StartLesson(Properties.Settings.Default.RecordLesson, check, lesson);
}
private void btnLessonInfo_Click(object sender, EventArgs e)
{
StringBuilder builder = new StringBuilder();
if (Selected.SelectedItem.ToString() != "Boş")
{
Lesson lesson = Lessons.FirstOrDefault(x => x.Name == Selected.SelectedItem.ToString());
builder.AppendLine("Toplantı Adı: " + lesson.Name);
builder.AppendLine("Öğretmen: " + lesson.Teacher);
}
builder.AppendLine("Başlama Saati: " + DateTime.Parse(Properties.Settings.Default.LessonTime.Split('|')[Selected.SelectedIndex]).ToString("HH.mm"));
ShowInfo(builder.ToString(), "TOPLANTI HAKKINDA");
Selected.SelectedIndex = -1;
}
private void btnStartProgramLesson_Click(object sender, EventArgs e)
{
ToolStripItem item = sender as ToolStripItem;
if (item.Text == "Başlat")
{
OnDoubleClick(Selected, null);
item.Text = "Durdur";
}
else
{
if (backgroundWorker1.IsBusy)
{
BGWorker.ix = -1;
BGWorker.isStarted = false;
BGWorker.isEBA = false;
}
ZoomEntities.StopLesson(true);
item.Text = "Başlat";
}
Selected.SelectedIndex = -1;
}
private void btnAdditional_Click(object sender, EventArgs e)
{
if (Properties.Settings.Default.AutoStart)
MainClass.OpenForm(new AdditionalProgram());
else
ShowError("Bu özelliğin kullanılabilmesi için otomatik toplantı özelliğinin aktif olması gerekmektedir.");
}
}
}