Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.55 KB | None | 0 0
  1. <asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server">
  2. <asp:View ID="View1" runat="server">
  3. <table>
  4. <tr>
  5. <td>
  6. <asp:Label ID="QuizName" runat="server" Text="Quiz Name: "></asp:Label>
  7. </td>
  8. <td>
  9. <asp:TextBox ID="QuizNameTextBox" Placeholder="Enter Quiz Name" runat="server"></asp:TextBox>
  10. <asp:Label ID="nameerror" runat="server" ForeColor="Red" Visible="false" Text="The quiz name already exists, please create another."></asp:Label>
  11. <asp:RequiredFieldValidator ID="QuizNameRequired" ForeColor="Red" Display="Dynamic" ControlToValidate="QuizNameTextBox" runat="server" ErrorMessage="The quiz name is required."></asp:RequiredFieldValidator>
  12. </td>
  13. </tr>
  14. <tr>
  15. <td>
  16. <asp:Label ID="ForCourse" runat="server" Text="For Course: "></asp:Label>
  17. </td>
  18. <td>
  19. <asp:DropDownList ID="DropDownList1" runat="server">
  20. <asp:ListItem value="1">Course51531</asp:ListItem>
  21. <asp:ListItem value="7">Course6</asp:ListItem>
  22. <asp:ListItem value="9">Course8</asp:ListItem>
  23. <asp:ListItem value="12">Course 11</asp:ListItem>
  24. <asp:ListItem value="35">Course 1sdwd</asp:ListItem>
  25. <asp:ListItem value="36">ewfwef</asp:ListItem>
  26. </asp:DropDownList>
  27. </td>
  28. </tr>
  29. <tr>
  30. <td>
  31. <asp:Label ID="Reattempt" runat="server" Text="Can this be re-attempted?: "></asp:Label>
  32. </td>
  33. <td>
  34. <asp:RadioButtonList AutoPostBack="true" ID="Reattemptradio" runat="server">
  35. <asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
  36. <asp:ListItem Text="No" Value="No"></asp:ListItem>
  37. </asp:RadioButtonList>
  38. <asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="Reattemptradio" Display="Dynamic" ForeColor="Red" runat="server" ErrorMessage="Please select a value."></asp:RequiredFieldValidator>
  39. </td>
  40. </tr>
  41. <tr>
  42. <td>
  43. <asp:Label ID="Reattemp1" Visible="false" runat="server" Text="How many times?: "></asp:Label>
  44. </td>
  45. <td>
  46. <asp:TextBox ID="reattemptbox1" Visible="false" runat="server"></asp:TextBox>
  47. </td>
  48. </tr>
  49. <tr>
  50. <td></td>
  51. <td>
  52. <asp:Button ID="Continue" CommandName="SwitchViewByID" CommandArgument="View2" ToolTip="Click here to create questions for the quiz." runat="server" Text="Continue" OnClick="Continue_Click" />
  53. </td>
  54. </tr>
  55. </table>
  56. </asp:View>
  57. <asp:View ID="View2" runat="server">
  58. <table>
  59. <tr>
  60. <td>
  61. <asp:Label ID="Label1" runat="server" Text="Question No: "></asp:Label>
  62. </td>
  63. <td>
  64. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  65. </td>
  66. </tr>
  67. <tr>
  68. <td>
  69. <asp:Label ID="Label2" runat="server" Text="Question Name"></asp:Label>
  70. </td>
  71. <td>
  72. <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  73. </td>
  74. </tr>
  75. <tr>
  76. <td>
  77. <asp:Label ID="Label3" runat="server" Text="Question Type:"></asp:Label>
  78. </td>
  79. <td>
  80. <asp:DropDownList ID="DropDownList2" runat="server">
  81. <asp:ListItem Text="---Select---" Value="---Select---"></asp:ListItem>
  82. <asp:ListItem Text="Drop Down Menu" Value="Drop Down Menu"></asp:ListItem>
  83. <asp:ListItem Text="Radio Buttons" Value="Radio Buttons"></asp:ListItem>
  84. <asp:ListItem Text="Check Box" Value="Check Box"></asp:ListItem>
  85. <asp:ListItem Text="TextBox" Value="TextBox"></asp:ListItem>
  86. <asp:ListItem Text="Multi Line Response" Value="Multi Line Response"></asp:ListItem>
  87. </asp:DropDownList>
  88. </td>
  89. </tr>
  90. <tr>
  91. <td>
  92. <asp:Label ID="Label4" runat="server" Text="Pass Mark: "></asp:Label>
  93. </td>
  94. <td>
  95. <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
  96. </td>
  97. </tr>
  98. <tr>
  99. <td>&nbsp;</td>
  100. <td>
  101. <asp:Button ID="Button1" CommandName="SwitchViewByID" CommandArgument="View3" OnClick="Button1_Click" runat="server" Text="Button" />
  102. </td>
  103. </tr>
  104. </table>
  105. </asp:View>
  106. <asp:View ID="View3" runat="server">
  107. <table>
  108. <tr>
  109. <td>
  110. <asp:Label ID="ResponseLabel11" runat="server" Text="Enter another Response: "></asp:Label>
  111. </td>
  112. <td>
  113. <asp:TextBox ID="ResponseTextBox11" runat="server"></asp:TextBox>
  114. <asp:RequiredFieldValidator ID="RequiredFieldValidator5" ControlToValidate="ResponseTextBox11" Display="Dynamic" ForeColor="Red" runat="server" ErrorMessage="A response is required."></asp:RequiredFieldValidator>
  115. </td>
  116. <td>Note: The response in this textbox should be an answer.
  117. </td>
  118. </tr>
  119. <tr>
  120. <td>
  121. <asp:Label ID="ResponseLabel12" runat="server" Text="Enter another Response: "></asp:Label>
  122. </td>
  123. <td>
  124. <asp:TextBox ID="ResponseTextBox12" runat="server"></asp:TextBox>
  125. <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="ResponseTextBox12" Display="Dynamic" ForeColor="Red" runat="server" ErrorMessage="Another response is required."></asp:RequiredFieldValidator>
  126. </td>
  127. <td>
  128. <asp:CheckBox ID="Answer12" Text="Is Answer?" runat="server" />
  129. </td>
  130. </tr>
  131. <tr>
  132. <td></td>
  133. <td>
  134. <asp:Button ID="Button2" OnClick="Button2_Click" runat="server" Text="Button" />
  135. </td>
  136. </tr>
  137. </table>
  138. </asp:View>
  139. </asp:MultiView>
  140.  
  141. using System;
  142. using System.Collections.Generic;
  143. using System.Data;
  144. using System.Data.SqlClient;
  145. using System.Linq;
  146. using System.Web;
  147. using System.Web.UI;
  148. using System.Web.UI.WebControls;
  149.  
  150. public partial class Default3 : System.Web.UI.Page
  151. {
  152. int quizid = 0;
  153. int check = 0;
  154. int questid = 0;
  155. int counter = 1;
  156. int count = 0;
  157. protected void Page_Load(object sender, EventArgs e)
  158. {
  159. }
  160. protected void Page_PreRender(object sender, EventArgs e)
  161. {
  162.  
  163. }
  164. protected void Continue_Click(object sender, EventArgs e)
  165. {
  166. DropDownList1.SelectedValue = DropDownList1.SelectedValue;
  167. using (var connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
  168. {
  169. connection.Open();
  170. using (var command = connection.CreateCommand())
  171. {
  172. command.CommandText = "INSERT INTO [Quiz] ([QuizName], [CourseId], [AllowedAttempts]) VALUES (@QuizName, @CourseId, @AllowedAttempts)";
  173. command.Parameters.AddWithValue("@QuizName", SqlDbType.NVarChar).Value = QuizNameTextBox.Text;
  174. command.Parameters.AddWithValue("@CourseId", SqlDbType.Int).Value = Convert.ToInt32(DropDownList1.SelectedValue.ToString());
  175. if (Reattemptradio.SelectedValue.ToString() == "Yes")
  176. {
  177. command.Parameters.AddWithValue("@AllowedAttempts", SqlDbType.Int).Value = Convert.ToInt32(reattemptbox1.Text);
  178. command.ExecuteNonQuery();
  179. }
  180. else
  181. {
  182. command.Parameters.AddWithValue("@AllowedAttempts", SqlDbType.Int).Value = 0;
  183. command.ExecuteNonQuery();
  184. }
  185. }
  186. }
  187. }
  188. protected void Button1_Click(object sender, EventArgs e)
  189. {
  190. using (var connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
  191. {
  192. connection.Open();
  193. using (var command = connection.CreateCommand())
  194. {
  195. command.CommandText = "SELECT QuizId FROM Quiz WHERE (QuizName = '" + QuizNameTextBox.Text + "')";
  196. using (var reader = command.ExecuteReader())
  197. {
  198. while (reader.Read())
  199. {
  200. quizid = Convert.ToInt32(reader["QuizId"]);
  201. ViewState["quiz"] = quizid;
  202. }
  203. }
  204. }
  205. using (var command = connection.CreateCommand())
  206. {
  207. command.CommandText = "INSERT INTO [QuizQuestion] ([QuizId], [QuestionNo], [QuestionType], [QuestionName], [QuestionMark]) VALUES (@QuizId, @QuestionNo, @QuestionType, @QuestionName, @QuestionMark)";
  208. command.Parameters.AddWithValue("@QuizId", SqlDbType.Int).Value = quizid;
  209. command.Parameters.AddWithValue("@QuestionNo", SqlDbType.Int).Value = TextBox1.Text;
  210. command.Parameters.AddWithValue("@QuestionName", SqlDbType.NVarChar).Value = TextBox2.Text;
  211. command.Parameters.AddWithValue("@QuestionType", SqlDbType.NVarChar).Value = DropDownList2.SelectedValue.ToString();
  212. command.Parameters.AddWithValue("@QuestionMark", SqlDbType.NVarChar).Value = TextBox4.Text;
  213. command.ExecuteNonQuery();
  214.  
  215. }
  216. }
  217. }
  218. protected void Button2_Click(object sender, EventArgs e)
  219. {
  220. ViewState["count"] = Convert.ToInt32(ViewState["count"]) + counter + 1;
  221. using (var connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
  222. {
  223. connection.Open();
  224. using (var command = connection.CreateCommand())
  225. {
  226. command.CommandText = "SELECT QuizQuestionId FROM QuizQuestion WHERE (QuestionName = '" + TextBox2.Text + "')";
  227. using (var reader = command.ExecuteReader())
  228. {
  229. while (reader.Read())
  230. {
  231. questid = Convert.ToInt32(reader["QuizQuestionId"].ToString());
  232. }
  233. }
  234. }
  235. using (var command = connection.CreateCommand())
  236. {
  237. command.CommandText = "INSERT INTO [QuizAnswer] ([QuizId], [QuizQuestionId], [Response], [Sequence], [CorrectResponse]) VALUES (@QuizId, @QuizQuestionId, @Response, @Sequence, @CorrectResponse)";
  238. command.Parameters.AddWithValue("@QuizId", SqlDbType.Int).Value = Convert.ToInt32(ViewState["quiz"]);
  239. command.Parameters.AddWithValue("@QuizQuestionId", SqlDbType.Int).Value = Convert.ToInt32(questid);
  240. command.Parameters.AddWithValue("@Response", SqlDbType.NVarChar).Value = ResponseTextBox11.Text;
  241. command.Parameters.AddWithValue("@Sequence", SqlDbType.Int).Value = count;
  242. command.Parameters.AddWithValue("@CorrectResponse", SqlDbType.Bit).Value = Convert.ToBoolean("True");
  243. command.ExecuteNonQuery();
  244. }
  245. }
  246. }}
  247.  
  248. CREATE TABLE [dbo].[QuizAnswer] (
  249. [QuizAnswerId] INT IDENTITY (1, 1) NOT NULL,
  250. [QuizQuestionId] INT NOT NULL,
  251. [QuizId] INT NOT NULL,
  252. [Response] NVARCHAR (MAX) NOT NULL,
  253. [Sequence] INT NOT NULL,
  254. [CorrectResponse] BIT DEFAULT ((0)) NOT NULL,
  255. PRIMARY KEY CLUSTERED ([QuizAnswerId] ASC),
  256. CONSTRAINT [FK_QuizAnswer_ToQuizQuestion] FOREIGN KEY ([QuizQuestionId]) REFERENCES [dbo].[QuizQuestion] ([QuizQuestionId]),
  257. CONSTRAINT [FK_QuizAnswer_ToQuiz] FOREIGN KEY ([QuizId]) REFERENCES [dbo].[Quiz] ([QuizId])
  258.  
  259. CREATE TABLE [dbo].[Quiz] (
  260. [QuizId] INT IDENTITY (1, 1) NOT NULL,
  261. [QuizName] NVARCHAR (50) NOT NULL,
  262. [CourseId] INT NOT NULL,
  263. [TotalMarks] INT DEFAULT ((1)) NULL,
  264. [PassMarks] INT NULL,
  265. [AllowedAttempts] INT DEFAULT ((0)) NOT NULL,
  266. [IsActive] BIT DEFAULT ((0)) NOT NULL,
  267. PRIMARY KEY CLUSTERED ([QuizId] ASC),
  268. CONSTRAINT [FK_Quiz_ToCourse] FOREIGN KEY ([CourseId]) REFERENCES [dbo].[Course] ([CourseId])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement