Code Behind Page Page /AddPracticeQuestion.aspx.cs (C#)
Used by Page /AddPracticeQuestion.aspx (C#)
1: using System;  
2: using System.Web;  
3: using System.Web.UI;  
4: using QuizNetOnline.Logic;  
5: using Microsoft.ApplicationBlocks.Data;  
6:   
7: namespace QuiznetOnline.Web.UI  
8: {  
9:     public partial class AddPracticeQuestion : QuiznetOnline.Web.UI.BusinessClasses.BasePage  
10:     {  
11:         protected override void Page_Load(object sender, EventArgs e)  
12:         {  
13:             PopupQuestionSaved.Enabled = false;  
14:             if (!Page.IsPostBack)  
15:             {  
16:                 base.Page_Load(sender, e);  
17:   
18:                 if (((UserWeb)Session["userWeb"]).UserName == "guest@quiznetonline.com")  
19:                 {  
20:                     lblNoUser.Text = @"Please note that you have not registered or you have not signed in";  
21:                     lblNoUser.Text = lblNoUser.Text + Environment.NewLine + Environment.NewLine;  
22:                     lblNoUser.Text = lblNoUser.Text + @"Please sign in or register";  
23:                     ModalPopupNoUser.Enabled = true;  
24:                     ModalPopupNoUser.Show();  
25:                 }  
26:             }  
27:         }  
28:   
29:   
30:   
31:         protected void cmdsubmit_Click(object sender, EventArgs e)  
32:         {  
33:             if (txtquestion.ToString() != String.Empty && cmbanswer.SelectedValue != "0" && Page.IsValid)  
34:             {  
35:                 if (txtquestion.Text.ToUpper().IndexOf("Which of the following is not a C# keyword".ToUpper()) >= 0)  
36:                 {  
37:                     lblStatus.Text = @"Question already exists. Please supply another question";  
38:                     lblStatusTop.Text = lblStatus.Text;  
39:   
40:                     return;  
41:                 }  
42:   
43:                 if (txtanswers1.Text == txtanswers2.Text)  
44:                 {  
45:                     lblStatus.Text = @"Answers cannot be the same";  
46:                     lblStatusTop.Text = lblStatus.Text;  
47:   
48:                     return;  
49:                 }  
50:   
51:                 if (txtanswers1.ToString() != String.Empty || txtanswers2.ToString() != String.Empty ||  
52:                     txtanswers3.ToString() != String.Empty || txtanswers4.ToString() != String.Empty ||  
53:                     txtanswers5.ToString() != String.Empty)  
54:                 {  
55:                     SaveRecord();  
56:                 }  
57:                 else  
58:                 {  
59:                     lblStatus.Text = @"Please give some possible answers";  
60:                     lblStatusTop.Text = lblStatus.Text;  
61:                 }  
62:             }  
63:             else  
64:             {  
65:                 lblStatus.Text = @"Please fill in the question and the choose the answer";  
66:                 lblStatusTop.Text = @"Please fill in the question and the choose the answer";  
67:             }  
68:         }  
69:   
70:         private void SaveRecord()  
71:         {  
72:             var user = new UserSetting();  
73:             SqlWrapper sqlWrapper=new SqlWrapper();  
74:   
75:             string question = HttpUtility.HtmlEncode(txtquestion.Text);  
76:             string answers1 = HttpUtility.HtmlEncode(txtanswers1.Text);  
77:             string answers2 = HttpUtility.HtmlEncode(txtanswers2.Text);  
78:             string answers3 = HttpUtility.HtmlEncode(txtanswers3.Text);  
79:             string answers4 = HttpUtility.HtmlEncode(txtanswers4.Text);  
80:             string answers5 = HttpUtility.HtmlEncode(txtanswers5.Text);  
81:             string answer = cmbanswer.SelectedValue;  
82:             string explaination = HttpUtility.HtmlEncode(txtexplain.Text);  
83:             string username = ((UserWeb)Session["userWeb"]).UserName;  
84:             string email = ((UserWeb)Session["userWeb"]).UserName;  
85:   
86:             UserQuestion userQuestion = new UserQuestion();  
87:             userQuestion.QuestionDesc = question;  
88:             userQuestion.Answer1 = answers1;  
89:             userQuestion.Answer2 = answers2;  
90:             userQuestion.Answer3 = answers3;  
91:             userQuestion.Answer4 = answers4;  
92:             userQuestion.Answer5 = answers5;  
93:             userQuestion.Answer = Convert.ToInt32(answer);  
94:             userQuestion.Explaination = explaination;  
95:             userQuestion.UserName = username;  
96:             userQuestion.Email = email;  
97:             userQuestion.IpAddress = Request.ServerVariables["REMOTE_HOST"];  
98:             userQuestion.Topic = new Topic("new");  
99:   
100:             userQuestion.Create(sqlWrapper);  
101:   
102:             ClearFields();  
103:   
104:             PopupQuestionSaved.Enabled = true;  
105:             lblStatusTop.Text = lblQuestionStatus.Text =  
106:                 @"Record Successfully Added...<br> - You will now full access to all the questions<br><br>";  
107:             PopupQuestionSaved.Show();  
108:             try  
109:             {  
110:                 user.Load(username, new SqlWrapper());  
111:                 user.UnlimitedQuestions = true;  
112:                 user.Save(new SqlWrapper());  
113:             }  
114:             catch (Exception ex)  
115:             {  
116:                 ErrorLog errorLog = new ErrorLog();  
117:                 errorLog.LogException("AddPracticeQuestion.SaveRecord", ex, sqlWrapper);  
118:             }  
119:         }  
120:   
121:         private void ClearFields()  
122:         {  
123:             txtquestion.Text = "";  
124:             txtanswers1.Text = "";  
125:             txtanswers2.Text = "";  
126:             txtanswers3.Text = "";  
127:             txtanswers4.Text = "";  
128:             txtanswers5.Text = "";  
129:             txtexplain.Text = "";  
130:             cmbanswer.SelectedItem.Selected = false;  
131:             cmbanswer.Items[0].Selected = true;  
132:   
133:             //RequiredFieldValidatorQuestion.Enabled = false;  
134:   
135:             //RequiredFieldValidatorQuestion.Enabled = false;  
136:         }  
137:   
138:         protected void cmdMainMenu_Click(object sender, EventArgs e)  
139:         {  
140:             Response.Redirect("Default.aspx");  
141:         }  
142:     }  
143: }

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.