-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.cs
136 lines (115 loc) · 4.48 KB
/
Menu.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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace TrainerSpace
{
public partial class Menu : Form
{
List<List<string>> ListOfComboBoxItems = new List<List<string>>();
SystemMenuManager menuManager;
List<List<string>> result = new List<List<string>>();
public Menu()
{
InitializeComponent();
ThemesCombo.DropDownStyle = ComboBoxStyle.DropDownList;
if (ListOfComboBoxItems.Count == 0)
{
ThemesCombo.Enabled = false;
}
lbUser.Text = $"Пользователь:{User.GetSurname()} {User.GetName()},\n ID: {User.GetId().ToString()}";
this.menuManager = new SystemMenuManager(this, SystemMenuManager.MenuItemState.Removed); //прячем крестик от юзера
if (User.IsAdmin() || User.IsModer())
{
btnAdminpanel.Enabled = true;
btnCheckstat.Enabled = btnCheckstat.Visible = false;
}
else
{
btnAdminpanel.Enabled = btnAdminpanel.Visible = false;
btnCheckstat.Enabled = btnCheckstat.Visible = true;
}
string Query = "select * from subjects order by id asc";
ListOfComboBoxItems = Database.SendReadQuery(Query);
if (ListOfComboBoxItems.Count > 0)
{
ThemesCombo.Enabled = true;
int i = 0;
while (i < ListOfComboBoxItems.Count)
{
ThemesCombo.Items.Add(ListOfComboBoxItems[i][1]);
i++;
}
}
}
private void btnAdminpanel_Click(object sender, EventArgs e)
{
Admin form = new Admin();
if (!(form.ShowDialog() == DialogResult.OK))
{
string Query = "select * from subjects order by id asc";
ListOfComboBoxItems = Database.SendReadQuery(Query);
if (ListOfComboBoxItems.Count > 0)
{
ThemesCombo.Enabled = true;
ThemesCombo.Items.Clear();
int i = 0;
while (i < ListOfComboBoxItems.Count)
{
ThemesCombo.Items.Add(ListOfComboBoxItems[i][1]);
i++;
}
}
else {
ThemesCombo.Items.Clear();
ThemesCombo.Enabled = false;
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnPlay_Click(object sender, EventArgs e)
{
string query = $"select * from questions WHERE subject_id ='{Trainer.Properties.Settings.Default.theme_id}' order by id asc";
result = Database.SendReadQuery(query);
if (ThemesCombo.SelectedIndex == -1) {
MessageBox.Show("Вы не выбрали предмет", "Ошибка!"); }
else if (result.Count == 0) {
MessageBox.Show("Не найдено вопросов по данной теме", "Ошибка!");
}
else
{
Quiz form = new Quiz();
form.ShowDialog();
}
}
private void btnLogOut_Click(object sender, EventArgs e)
{
User.LogOut();
Application.Restart();
}
private void ThemesCombo_SelectedIndexChanged(object sender, EventArgs e)
{
Trainer.Properties.Settings.Default.theme_id = Convert.ToInt32(ListOfComboBoxItems[ThemesCombo.SelectedIndex][0]);
Trainer.Properties.Settings.Default.subject_sel = ThemesCombo.SelectedIndex;
Trainer.Properties.Settings.Default.Save();
}
private void btnCheckstat_Click(object sender, EventArgs e)
{
Results form = new Results();
form.ShowDialog();
}
private void AboutBtn_Click(object sender, EventArgs e)
{
Productinfo form = new Productinfo();
form.ShowDialog();
}
private void SettingsButton_Click(object sender, EventArgs e)
{
Usettings form = new Usettings();
form.Owner = this;
form.ShowDialog();
}
}
}