ASP.NET Page /Admin/QuestionPositioning.aspx.cs (C#)
1: using System;  
2: using System.Data;  
3: using System.Configuration;  
4: using System.Collections.Generic;  
5: using System.Collections.ObjectModel;  
6: using System.Web;  
7: using System.Web.Security;  
8: using System.Web.UI;  
9: using System.Web.UI.WebControls;  
10: using System.Web.UI.WebControls.WebParts;  
11: using System.Web.UI.HtmlControls;  
12: using System.Data.SqlClient;  
13: using QuiznetOnline.Data;  
14: using QuizNetOnline.Logic;  
15: using Microsoft.ApplicationBlocks.Data;  
16: using AjaxControlToolkit;  
17:   
18: public partial class QuestionPositioning : System.Web.UI.Page  
19: {  
20:     protected void Page_Load(object sender, EventArgs e)  
21:     {  
22:         DataFunctions dataFunctions = DataFunctions.GetInstance();  
23:         if (Session["Validated"] == null || (bool)Session["Validated"] == false)  
24:             Response.Redirect("Default.aspx");  
25:   
26:         if (!Page.IsPostBack)  
27:         {  
28:             PopulateTopics();  
29:         }  
30:         ReorderList1.DataSource = GetWorkItems();  
31:         ReorderList1.DataBind();  
32:   
33:   
34:     }  
35:   
36:   
37:     protected void ReorderList1_ItemReorder(object sender, AjaxControlToolkit.ReorderListItemReorderEventArgs e)  
38:     {  
39:         Session["Questions"] = (List<Question>)ReorderList1.DataSource;  
40:     }  
41:   
42:     private void PopulateTopics()  
43:     {  
44:         ISqlWrapper sqlWrapper = new SqlWrapper();  
45:         Topics topics = new Topics();  
46:         topics.LoadTopics(sqlWrapper);  
47:   
48:         cmbTopic.DataSource = topics.Topiclist;  
49:         cmbTopic.DataTextField = "TopicCode";  
50:         cmbTopic.DataValueField = "TopicCode";  
51:         cmbTopic.DataBind();  
52:     }  
53:   
54:     protected void cmbTopic_SelectedIndexChanged(Object sender, EventArgs e)  
55:     {  
56:         Session["Questions"] = null;  
57:     }  
58:   
59:     protected void cmdSave_Click(object sender, EventArgs e)  
60:     {  
61:         int pos = 0;  
62:         QuizNetSystem quizNetSystem=new QuizNetSystem();  
63:         Question question = new Question();  
64:   
65:         foreach (ReorderListItem item in ReorderList1.Items)  
66:         {  
67:             if((Label)item.FindControl("lblQuestionID")!=null)  
68:             {  
69:                 int questionid = Convert.ToInt32(((Label)item.FindControl("lblQuestionID")).Text);  
70:                 bool isFree = Convert.ToBoolean(((CheckBox)item.FindControl("chkIsFree")).Checked);  
71:                 question = new Question();  
72:                 question.LoadQuestion(questionid, new SqlWrapper());  
73:                 question.Position = pos;  
74:                 question.IsFree = isFree;  
75:                 question.Save();  
76:             }  
77:         }  
78:   
79:         foreach (Question item in GetWorkItems())  
80:         {  
81:             pos++;  
82:             Question ques = item;  
83:             ques.Position = pos;  
84:             ques.Save();  
85:         }  
86:         ReorderList1.DataBind();  
87:     }  
88:   
89:     public List<Question> GetWorkItems()  
90:     {  
91:         QuizNetSystem quizNetSystem = new QuizNetSystem();  
92:         if (Session["Questions"] == null)  
93:         {  
94:             return quizNetSystem.LoadQuestions(cmbTopic.SelectedItem.Value, new SqlWrapper());  
95:         }  
96:         return (List<Question>)Session["Questions"];  
97:     }  
98: }  

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