-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamCreator.aspx.cs
More file actions
221 lines (190 loc) · 7.58 KB
/
ExamCreator.aspx.cs
File metadata and controls
221 lines (190 loc) · 7.58 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Globalization;
public partial class ExamCreator : System.Web.UI.Page
{
string conString = ConfigurationManager.ConnectionStrings["DatabaseConnecting"].ConnectionString;
protected override void OnPreRenderComplete(EventArgs e)
{
txtQuestion.Attributes.Add("value", txtQuestion.Text);
if (ddlQuestionType.SelectedValue == "MCQ")
{
ChoiceA.Attributes.Add("value", ChoiceA.Text);
ChoiceB.Attributes.Add("value", ChoiceB.Text);
ChoiceC.Attributes.Add("value", ChoiceC.Text);
ChoiceD.Attributes.Add("value", ChoiceD.Text);
}
else if (ddlQuestionType.SelectedValue == "True OR False")
{
ChoiceA.Text = "True";
ChoiceB.Text = "False";
ChoiceC.Text = null;
ChoiceD.Text = null;
ChoiceC.Enabled = false;
ChoiceC.BackColor = System.Drawing.Color.Gray;
ChoiceD.Enabled = false;
ChoiceD.BackColor = System.Drawing.Color.Gray;
}
base.OnPreRenderComplete(e);
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Name"] != null && Session.Timeout != 0)
{
if (Session["UserType"].ToString() == "professor" && Session["Status"].ToString() == "1")
{
Master.lblusername.Text = "Hi " + Session["Name"].ToString();
Master.logout.Visible = true;
Master.login.Visible = false;
Master.signup.Visible = false;
Master.imgprofile.Visible = true;
Master.home.PostBackUrl = "ProfessorHome.aspx";
fillData();
GetSubjectID();
txtQuestion.Focus();
}
else
{
Response.Redirect("StudentHome.aspx");
}
}
else
{
Response.Redirect("Login.aspx");
Master.home.Enabled = true;
}
}
private void fillData()
{
SqlConnection con = new SqlConnection(conString);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Tbl_User WHERE Username = '" + Session["Name"].ToString() + "'", con);
SqlDataReader read = cmd.ExecuteReader();
while(read.Read())
{
lblFName.Text = read["FName"].ToString();
lblLName.Text = read["LName"].ToString();
//sessions
Session["Subject"] = lblSubject.Text = read["Subject"].ToString();
Session["EduLevel"] = read["EduLevel"];
}
con.Close();
}
protected void txtCancel_Click(object sender, EventArgs e)
{
Response.Redirect("ProfessorHome.aspx");
}
protected void tbnNextQuestion_Click(object sender, EventArgs e)
{
NewRecord();
Reset();
}
protected void Reset()
{
if (txtQuestion.Text != string.Empty && ChoiceA.Text != string.Empty && ChoiceB.Text != string.Empty && RadioButtonList1.SelectedValue != string.Empty && ddlQuestionChapter.SelectedValue != "0" && ddlQuestionLevel.SelectedValue != "0")
{
// Design And Validation
txtQuestion.Text = null;
ChoiceA.Text = null;
ChoiceB.Text = null;
ChoiceC.Text = null;
ChoiceD.Text = null;
lblSuccess.Text = "A NEW QUESTION ADDED";
lblSuccess.ForeColor = System.Drawing.Color.Green;
}
else
{
// PROCESS IS NOT COMPLETED YET...!!
lblSuccess.Text = "PLEASE FILL ALL DATA..!";
lblSuccess.ForeColor = System.Drawing.Color.Red;
}
}
protected void ddlQuestionType_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlQuestionType.SelectedIndex == 1)
{
ChoiceA.Text = "True";
ChoiceB.Text = "False";
ChoiceC.Text = null;
ChoiceD.Text = null;
RequiredFieldValidator3.ValidationGroup = "NULL";
RequiredFieldValidator4.ValidationGroup = "NULL";
ChoiceC.Enabled = false;
ChoiceD.Enabled = false;
}
else if(ddlQuestionType.SelectedIndex == 0)
{
ChoiceA.Text = null;
ChoiceB.Text = null;
ChoiceC.Text = null;
ChoiceD.Text = null;
RequiredFieldValidator3.ValidationGroup = "Exam";
RequiredFieldValidator4.ValidationGroup = "Exam";
ChoiceC.Enabled = true;
ChoiceC.BackColor = System.Drawing.Color.White;
ChoiceD.Enabled = true;
ChoiceD.BackColor = System.Drawing.Color.White;
ChoiceA.Attributes.Add("value", ChoiceA.Text);
ChoiceB.Attributes.Add("value", ChoiceB.Text);
ChoiceC.Attributes.Add("value", ChoiceC.Text);
ChoiceD.Attributes.Add("value", ChoiceD.Text);
}
}
//important call subject id
private void GetSubjectID()
{
SqlConnection con = new SqlConnection(conString);
con.Open();
SqlCommand cmd = new SqlCommand("select EduLevelID from Tbl_EduLevel where EduLevelName = '" + Session["EduLevel"].ToString() + "'", con);
SqlDataReader read2 = cmd.ExecuteReader();
while (read2.Read())
{
Session["EduLevelID"] = read2["EduLevelID"];
}
con.Close();
con.Open();
cmd = new SqlCommand("select SubjectID from Tbl_Subject where SubjectName = '" + Session["Subject"] + "' and EduLevelID = '" + Session["EduLevelID"] + "'", con);
SqlDataReader read3 = cmd.ExecuteReader();
while (read3.Read())
{
Session["SubjectID"] = read3["SubjectID"].ToString() ;
}
con.Close();
}
//important insert questions and answers
private void NewRecord()
{
SqlConnection con = new SqlConnection(conString);
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO [Tbl_Ques_Ans](QuestionDesc,AnswerA,AnswerB,AnswerC,AnswerD,CorrectAnswer,QuestionType,Username,SubjectID,QuestionLevel,Chapter,DateTime) VALUES (N'" + txtQuestion.Text + "',N'" + ChoiceA.Text + "',N'" + ChoiceB.Text + "',N'" + ChoiceC.Text + "',N'" + ChoiceD.Text + "',N'" + RadioButtonList1.SelectedValue.ToString() + "','" + ddlQuestionType.SelectedValue.ToString() + "','" + Session["Name"].ToString() + "','" + Session["SubjectID"].ToString() + "','" + ddlQuestionLevel.SelectedValue.ToString() + "', '" + ddlQuestionChapter.SelectedValue.ToString() + "','" + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture) + "')", con);
cmd.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Javascript", "alert('Questions and Answers : success insert!'); ", true);
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if(RadioButtonList1.SelectedIndex==0)
{
RadioButtonList1.SelectedItem.Value = ChoiceA.Text;
}
else if (RadioButtonList1.SelectedIndex == 1)
{
RadioButtonList1.SelectedItem.Value = ChoiceB.Text;
}
else if (RadioButtonList1.SelectedIndex == 2)
{
RadioButtonList1.SelectedItem.Value = ChoiceC.Text;
}
else if (RadioButtonList1.SelectedIndex == 3)
{
RadioButtonList1.SelectedItem.Value = ChoiceD.Text;
}
}
}