-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmStudent.cs
153 lines (139 loc) · 4.94 KB
/
frmStudent.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using MySql.Data.MySqlClient;
namespace Gradon
{
public partial class frmStudent : Form
{
string id;
bool exflag = false;
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["Gradon.My.MySettings.gradonConnectionString"].ConnectionString;
MySqlConnection mConn;
public frmStudent(string i)
{
InitializeComponent();
id = i;
mConn = new MySqlConnection(connStr);
}
private void frmStudent_Load(object sender, EventArgs e)
{
Thread t1 = new Thread(i => loadSub());
t1.Start();
}
private void loadSub()
{
this.Invoke(new MethodInvoker(delegate
{
lbSub.Items.Clear();
}));
mConn.Open();
MySqlCommand mCmd = new MySqlCommand("SELECT classes.classid, subjects.subcode, sections.section FROM subjects INNER JOIN classes ON subjects.subid = classes.subid INNER JOIN sections ON sections.secid = classes.secid INNER JOIN students ON students.classid = classes.classid WHERE students.id = '" + id + "'", mConn);
MySqlDataReader reader = mCmd.ExecuteReader();
while (reader.Read())
{
ListItem l = new ListItem();
l.Text = reader.GetString("section") + " - " + reader.GetString("subcode");
l.Value = reader.GetString("classid");
this.Invoke(new MethodInvoker(delegate
{
lbSub.Items.Add(l);
}));
}
mConn.Close();
}
private void lbSub_SelectedIndexChanged(object sender, EventArgs e)
{
string cid = (lbSub.SelectedItem as ListItem).Value.ToString();
Thread t1 = new Thread(n => opG(cid));
t1.Start();
}
private void opG(string classid)
{
mConn.Open();
MySqlCommand mCmd = new MySqlCommand("SELECT mg, cp, sfe, fe, fg, fnum, remark FROM grades WHERE id = '" + id + "' AND classid = '" + classid + "'", mConn);
MySqlDataReader reader = mCmd.ExecuteReader();
if (reader.Read())
{
this.Invoke(new MethodInvoker(delegate
{
if (reader.GetInt32("mg") == 0)
{
txtMg.Text = "--";
}
else
{
txtMg.Text = reader.GetInt32("mg").ToString();
}
if (reader.GetInt32("cp") == 0)
{
txtCp.Text = "--";
}
else
{
txtCp.Text = reader.GetInt32("cp").ToString();
}
if (reader.GetInt32("sfe") == 0)
{
txtSfe.Text = "--";
}
else
{
txtSfe.Text = reader.GetInt32("sfe").ToString();
}
if (reader.GetInt32("fe") == 0)
{
txtFe.Text = "--";
}
else
{
txtFe.Text = reader.GetInt32("fe").ToString();
}
if (reader.GetInt32("fg") == 0)
{
txtFg.Text = "--";
}
else
{
txtFg.Text = reader.GetInt32("fg").ToString();
}
if (reader.GetDouble("fnum") == 0)
{
txtEq.Text = "--";
}
else
{
txtEq.Text = reader.GetDouble("fnum").ToString();
}
txtRem.Text = reader.GetString("remark");
}));
}
mConn.Close();
}
private void frmStudent_FormClosing(object sender, FormClosingEventArgs e)
{
if (exflag)
{
e.Cancel = false;
}
else if (MessageBox.Show("This will log you out, do you want to continue?", "Log out", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
e.Cancel = true;
frmLogin lg = new frmLogin();
lg.Show();
exflag = true;
this.Close();
}
else
{
e.Cancel = true;
}
}
}
}