Code Behind Page Page /Admin/AssignTagToQuestion.aspx.cs (C#)
Used by Page /Admin/AssignTagToQuestion.aspx (C#)
1: using System;  
2: using System.Data;  
3: using System.Configuration;  
4: using System.Collections;  
5: using System.Web;  
6: using System.Web.Security;  
7: using System.Web.UI;  
8: using System.Web.UI.WebControls;  
9: using System.Web.UI.WebControls.WebParts;  
10: using System.Web.UI.HtmlControls;  
11: using System.Data.SqlClient;  
12: using Microsoft.ApplicationBlocks.Data;  
13: using QuizNetOnline.Logic;  
14: using QuiznetOnline.Data;  
15: using System.Linq;  
16: using System.Collections.Generic;  
17:   
18: public partial class AssignTagToQuestion : 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:             cmbTopics.DataSource = Topic.LoadTopics(null, false, new SqlWrapper());  
29:             cmbTopics.DataTextField = "TopicDesc";  
30:             cmbTopics.DataValueField = "TopicCode";  
31:             cmbTopics.DataBind();  
32:   
33:             cmbExcludeTopics.DataSource = Topic.LoadTopics(null, false, new SqlWrapper());  
34:             cmbExcludeTopics.DataTextField = "TopicDesc";  
35:             cmbExcludeTopics.DataValueField = "TopicCode";  
36:             cmbExcludeTopics.DataBind();  
37:               
38:   
39:             Tag tag = new Tag();  
40:             cmbTags.DataSource = tag.GetTags();  
41:             cmbTags.DataTextField = "TagDesc";  
42:             cmbTags.DataValueField = "TagID";  
43:             cmbTags.DataBind();  
44:   
45:   
46:         }  
47:   
48:     }  
49:   
50:     protected void repeatQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e)  
51:     {  
52:         if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)  
53:         {  
54:             int i = 1;  
55:             foreach (var answer in ((Question)e.Item.DataItem).Answers)  
56:             {  
57:                 Label lblAnswer = ((Label)e.Item.FindControl("lblAnswer" + i));  
58:                 lblAnswer.Text = answer.AnswerDesc;  
59:                 i++;  
60:             }  
61:   
62:             Tag tag = new Tag();  
63:             tag.TagDesc = cmbTags.SelectedItem.Text;  
64:             tag.TagId = Convert.ToInt32(cmbTags.SelectedItem.Value);  
65:   
66:             CheckBox chkTag = ((CheckBox)e.Item.FindControl("chkTag"));  
67:   
68:             if (((Question)e.Item.DataItem).Tags.Any(_tag => _tag.Tag.TagId == Convert.ToInt32(cmbTags.SelectedItem.Value) && _tag.QuestionID == ((Question)e.Item.DataItem).QuestionId))  
69:             {  
70:                 chkTag.Checked = true;  
71:             }  
72:             else  
73:             {  
74:                 chkTag.Checked = false;  
75:             }  
76:   
77:               
78:             if (e.Item.ItemType == ListItemType.AlternatingItem)  
79:             {  
80:                 Table tbl = ((Table)e.Item.FindControl("tbl"));  
81:                 tbl.BackColor = System.Drawing.Color.LightCyan;  
82:             }  
83:         }  
84:     }  
85:   
86:     protected void butChooseTopic_Click(object sender, EventArgs e)  
87:     {  
88:         QuizNetSystem quizNetSystem = new QuizNetSystem();  
89:         List<string> arr=new List<string>();  
90:   
91:         foreach(ListItem item in cmbExcludeTopics.Items)  
92:         {  
93:             if (item.Selected)  
94:                 arr.Add(item.Value);  
95:         }  
96:   
97:         List<Question> questions = quizNetSystem.LoadQuestions(cmbTopics.SelectedItem.Value, new SqlWrapper());  
98:         questions.RemoveAll(_question => arr.Contains(_question.Topic.TopicCode));  
99:         repeatQuestion.DataSource = questions;  
100:         repeatQuestion.DataBind();  
101:     }  
102:   
103:     protected void butSaveComments_Click(object sender, EventArgs e)  
104:     {  
105:         foreach(RepeaterItem item in repeatQuestion.Items)  
106:         {  
107:             CheckBox chkTag = ((CheckBox)item.FindControl("chkTag"));  
108:   
109:             QuestionTag QuestionTag = new QuestionTag();  
110:             QuestionTag.Load(Convert.ToInt32(((HiddenField)item.FindControl("hiddenQuestionID")).Value), Convert.ToInt32(cmbTags.SelectedItem.Value));  
111:   
112:             if (QuestionTag.QuestionID > 0)  
113:             {  
114:                 QuestionTag.Delete();  
115:             }  
116:   
117:             if (chkTag.Checked)  
118:             {  
119:                 Tag tag = new Tag();  
120:                 tag.TagId = Convert.ToInt32(cmbTags.SelectedItem.Value);  
121:                 QuestionTag.QuestionID = Convert.ToInt32(((HiddenField)item.FindControl("hiddenQuestionID")).Value);  
122:                 QuestionTag.Tag = tag;  
123:                 QuestionTag.Save();  
124:             }  
125:         }  
126:     }  
127: }  

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