-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewQuestions.cs
156 lines (136 loc) · 6.04 KB
/
ViewQuestions.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
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;
using System.Data.SqlClient;
namespace QuestionPaper_Genration
{
public partial class ViewQuestions : Form
{
public ViewQuestions()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
//try
//{
// SqlCommand cmd = new SqlCommand("select Q.QuestionName,F.FacultyName,S.SubName,L.LevelName,QM.Marks from QuestionBank Q join Faculty_Master F On Q.FId=F.FId join Level_Master L on Q.LId=L.LId join QuestionSection QM on Q.QsId=QM.QsId join Subject_Master S on Q.SubId= S.SubId where F.FId='" + DtConnection.FId + "'", DtConnection.Con);
// SqlDataAdapter adp = new SqlDataAdapter(cmd);
// DataTable dt = new System.Data.DataTable();
// adp.Fill(dt);
// dataGridView1.DataSource = dt;
//}
//catch (Exception)
//{
// throw;
//}
}
private void ViewQuestions_Load(object sender, EventArgs e)
{
DtConnection.Con.Close();
SqlCommand cmd = new SqlCommand("select distinct * from Faculty_Master", DtConnection.Con);
DtConnection.Con.Open();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
DataRow row = dt.NewRow();
row["FId"] = 0;
row["FacultyName"] = "--Select Faculty--";
dt.Rows.InsertAt(row, 0);
cmbfaculty.DataSource = dt;
cmbfaculty.DisplayMember = "FacultyName";
cmbfaculty.ValueMember = "FId";
DtConnection.Con.Close();
DtConnection.Con.Open();
SqlCommand cmd2 = new SqlCommand("select * from Subject_Master", DtConnection.Con);
SqlDataAdapter adp2 = new SqlDataAdapter(cmd2);
DataTable dt2 = new DataTable();
adp2.Fill(dt2);
DataRow row2 = dt2.NewRow();
row2["SubId"] = 0;
row2["SubName"] = "--Select Subject--";
dt2.Rows.InsertAt(row2, 0);
cmbsubject.DataSource = dt2;
cmbsubject.DisplayMember = "SubName";
cmbsubject.ValueMember = "SubId";
DtConnection.Con.Close();
if (DtConnection.Type == "Faculty")
{
SqlCommand cmd1 = new SqlCommand("select Q.QuestionName,F.FacultyName,S.SubName,L.LevelName,QM.Marks from QuestionBank Q join Faculty_Master F On Q.FId=F.FId join Level_Master L on Q.LId=L.LId join QuestionSection QM on Q.QsId=QM.QsId join Subject_Master S on Q.SubId= S.SubId where F.FId='" + DtConnection.FId + "' and S.SubId='" + DtConnection.SubId + "'", DtConnection.Con);
SqlDataAdapter adp1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
dataGridView1.DataSource = dt1;
cmbfaculty.Visible = false;
cmbsubject.Visible = false;
BtnViewQuestionForAdmin.Visible = false;
}
if (DtConnection.Type == "Admin")
{
//button2.Visible = false;
}
}
private void ViewQuestionForAdmin_Click(object sender, EventArgs e)
{
try
{
if (cmbsubject.Text == "--Select Subject--")
{
MessageBox.Show("Select Subject.");
}
else if (cmbfaculty.Text == "--Select Faculty--")
{
MessageBox.Show("Select Faculty.");
}
else
{
dataGridView1.DataSource = null;
DtConnection.Con.Close();
SqlCommand cmd = new SqlCommand("select Q.QuestionName,F.FacultyName,S.SubName,L.LevelName,QM.Marks from QuestionBank Q join Faculty_Master F On Q.FId=F.FId join Level_Master L on Q.LId=L.LId join QuestionSection QM on Q.QsId=QM.QsId join Subject_Master S on Q.SubId= S.SubId where F.FId='" + cmbfaculty.SelectedValue + "' and S.SubId='" + cmbsubject.SelectedValue + "'", DtConnection.Con);
DtConnection.Con.Open();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
}
else
{
MessageBox.Show("No Data Found.");
}
DtConnection.Con.Close();
}
}
catch (Exception)
{
throw;
}
}
private void cmbfaculty_SelectedIndexChanged(object sender, EventArgs e)
{
DtConnection.Con.Close();
SqlCommand cmd2 = new SqlCommand("select * from dbo.Subject_Master where subid in(select SubId from dbo.Faculty_Master where FacultyName=@FacultyName)", DtConnection.Con);
cmd2.Parameters.AddWithValue("@FacultyName", cmbfaculty.Text);
DtConnection.Con.Open();
SqlDataAdapter adp2 = new SqlDataAdapter(cmd2);
DataTable dt2 = new DataTable();
adp2.Fill(dt2);
DataRow row2 = dt2.NewRow();
row2["SubId"] = 0;
row2["SubName"] = "--Select Subject--";
dt2.Rows.InsertAt(row2, 0);
cmbsubject.DataSource = dt2;
cmbsubject.DisplayMember = "SubName";
cmbsubject.ValueMember = "SubId";
DtConnection.Con.Close();
}
}
}