-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLessons.cs
137 lines (133 loc) · 4.67 KB
/
Lessons.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using ZoomAutoRecorder.Utils;
using System.Text.RegularExpressions;
namespace ZoomAutoRecorder
{
public partial class Lessons : Form
{
Database.Lesson Manager;
public Lessons()
{
InitializeComponent();
Manager = new Database.Lesson();
}
private void RefreshOut()
{
Main.Manager.RefLessons();
(Application.OpenForms["Main"] as Main).RefProgram();
var addi = Application.OpenForms["AdditionalProgram"] as AdditionalProgram;
if (addi != null)
{
addi.ops.RefreshLessons();
addi.ops.RefreshList();
}
}
private void Clear()
{
lvLessons.Items.Clear();
txtLessonName.Clear();
txtLink.Clear();
txtTeacher.Clear();
txtZoomID.Clear();
txtZoomPass.Clear();
}
private void Lessons_Load(object sender, EventArgs e)
{
Manager.RefreshLessons();
}
private void btnRefresh_Click(object sender, EventArgs e)
{
Clear();
Manager.RefreshLessons();
}
private void btnSolve_Click(object sender, EventArgs e)
{
try
{
string part = txtLink.Text.Split('/')[4];
string id = part.Split('?')[0];
string pass = part.Split('?')[1].Replace("pwd=", "");
txtZoomID.Text = id;
txtZoomPass.Text = pass;
txtLink.Clear();
}
catch (IndexOutOfRangeException)
{
return;
}
}
private void lvLessons_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (lvLessons.SelectedItems.Count <= 0) return;
txtLessonName.Text = lvLessons.SelectedItems[0].SubItems[1].Text;
txtZoomID.Text = lvLessons.SelectedItems[0].SubItems[2].Text;
txtZoomPass.Text = lvLessons.SelectedItems[0].SubItems[3].Text;
txtTeacher.Text = lvLessons.SelectedItems[0].SubItems[4].Text;
}
private void btnAdd_Click(object sender, EventArgs e)
{
string lesson_name = txtLessonName.Text;
string zoomid = txtZoomID.Text.Replace(" ", "");
string zoompass = txtZoomPass.Text;
string teacher = txtTeacher.Text;
if (!string.IsNullOrWhiteSpace(lesson_name) &&
!string.IsNullOrWhiteSpace(zoomid) &&
!string.IsNullOrWhiteSpace(zoompass) &&
!string.IsNullOrWhiteSpace(teacher) &&
Regex.IsMatch(zoomid, @"^\d+$"))
{
if (Manager.CheckDup(lesson_name))
Main.ShowError("Bu isme sahip bir zoom linki daha var!");
else
{
Manager.AddLesson(lesson_name, zoomid, zoompass, teacher);
Clear();
Manager.RefreshLessons();
RefreshOut();
}
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (lvLessons.SelectedItems.Count <= 0) return;
int id = int.Parse(lvLessons.SelectedItems[0].SubItems[0].Text);
Manager.DeleteLesson(id);
Clear();
Manager.RefreshLessons();
RefreshOut();
}
private void btnSave_Click(object sender, EventArgs e)
{
string lesson_name = txtLessonName.Text;
string zoomid = txtZoomID.Text.Replace(" ", "");
string zoompass = txtZoomPass.Text;
string teacher = txtTeacher.Text;
if (lvLessons.SelectedItems.Count > 0 &&
!string.IsNullOrWhiteSpace(lesson_name) &&
!string.IsNullOrWhiteSpace(zoomid) &&
!string.IsNullOrWhiteSpace(zoompass) &&
!string.IsNullOrWhiteSpace(teacher) &&
Regex.IsMatch(zoomid, @"^\d+$"))
{
int id = int.Parse(lvLessons.SelectedItems[0].SubItems[0].Text);
Manager.UpdateLesson(id, lesson_name, zoomid, zoompass, teacher);
Clear();
Manager.RefreshLessons();
RefreshOut();
}
}
private void lvLessons_KeyDown(object sender, KeyEventArgs e)
{
btnDelete_Click(null, null);
}
}
}