Component Page /Answer.cs (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using Microsoft.ApplicationBlocks.Data;  
4: using System.Data.SqlClient;  
5: using System.Data;  
6:   
7: namespace QuizNetOnline.Logic  
8: {  
9:     [Serializable]  
10:     public class Answer:IAnswer  
11:     {  
12:         private int _questionId;  
13:         public int QuestionId  
14:         {  
15:             get { return _questionId; }  
16:             set { _questionId = value; }  
17:         }  
18:         private int _value;  
19:         public int Value  
20:         {  
21:             get { return _value; }  
22:             set { _value = value; }  
23:         }  
24:         private string _answerDesc;  
25:         public string AnswerDesc  
26:         {  
27:             get { return _answerDesc; }  
28:             set { _answerDesc = value; }  
29:         }  
30:   
31:         public Answer(int questionID, int value, IAnswer answer)  
32:         {  
33:             List<Answer> answers = answer.LoadAnswers(questionID, value, new SqlWrapper());  
34:   
35:             if (answers.Count > 0)  
36:             {  
37:                 Value = answers[0].Value;  
38:                 QuestionId = answers[0].QuestionId;  
39:                 AnswerDesc = answers[0].AnswerDesc;  
40:             }  
41:         }  
42:   
43:         public Answer()  
44:         {  
45:         }  
46:   
47:         public virtual List<Answer> LoadAnswers(int? questionId, int? answerId, ISqlWrapper isqlWrapper)  
48:         {  
49:             List<Answer> answers = new List<Answer>();  
50:             string connStr = isqlWrapper.GetConnectionString();  
51:               
52:   
53:             if (connStr == null)  
54:                 throw new NotImplementedException();  
55:   
56:             const string sproc = "GetAnswers";  
57:             var parameters = new SqlParameter[2];  
58:             parameters[0] = new SqlParameter("@QuestionID", questionId);  
59:             parameters[1] = new SqlParameter("@AnswerID", answerId);  
60:             try  
61:             {  
62:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
63:   
64:                 foreach (DataRow row in tbl.Rows)  
65:                 {  
66:                     Answer answer = new Answer();  
67:                     answer.QuestionId = Convert.ToInt32(row["QuestionID"]);  
68:                     answer.Value = Convert.ToInt32(row["Value"]);  
69:                     answer.AnswerDesc = row["Answer"].ToString();  
70:   
71:                     answers.Add(answer);  
72:                 }  
73:   
74:             }  
75:             catch (Exception ex)  
76:             {  
77:                 ErrorLog errorLog = new ErrorLog();  
78:                 errorLog.LogException("LoadAnswers", ex, isqlWrapper);  
79:                 throw;  
80:             }  
81:             return answers;  
82:         }  
83:   
84:         public int Insert(ISqlWrapper isqlWrapper)  
85:         {  
86:             string connStr = isqlWrapper.GetConnectionString();  
87:             const string sproc = "CreateAnswer";  
88:   
89:             var parameters = new SqlParameter[3];  
90:   
91:             parameters[0] = new SqlParameter("@QuestionID", QuestionId);  
92:             parameters[1] = new SqlParameter("@Answer", AnswerDesc);  
93:             parameters[2] = new SqlParameter("@Value", Value);  
94:   
95:             try  
96:             {  
97:                 return isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
98:             }  
99:             catch (Exception ex)  
100:             {  
101:                 ErrorLog errorLog = new ErrorLog();  
102:                 errorLog.LogException("CreateAnswer", ex, isqlWrapper);  
103:                 throw;  
104:             }  
105:         }  
106:   
107:         public int Update(ISqlWrapper isqlWrapper)  
108:         {  
109:             string connStr = isqlWrapper.GetConnectionString();  
110:             const string sproc = "UpdateAnswer";  
111:   
112:             var parameters = new SqlParameter[3];  
113:   
114:             parameters[0] = new SqlParameter("@QuestionID", QuestionId);  
115:             parameters[1] = new SqlParameter("@Answer", AnswerDesc);  
116:             parameters[2] = new SqlParameter("@Value", Value);  
117:   
118:             try  
119:             {  
120:                 return isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
121:             }  
122:             catch (Exception ex)  
123:             {  
124:                 ErrorLog errorLog = new ErrorLog();  
125:                 errorLog.LogException("CreateAnswer", ex, isqlWrapper);  
126:                 throw;  
127:             }  
128:         }  
129:   
130:         public int Delete(ISqlWrapper isqlWrapper)  
131:         {  
132:             string connStr = isqlWrapper.GetConnectionString();  
133:             const string sproc = "DeleteAnswer";  
134:   
135:             var parameters = new SqlParameter[2];  
136:   
137:             parameters[0] = new SqlParameter("@QuestionID", QuestionId);  
138:             parameters[1] = new SqlParameter("@Value", Value);  
139:   
140:             try  
141:             {  
142:                 return isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
143:             }  
144:             catch (Exception ex)  
145:             {  
146:                 ErrorLog errorLog = new ErrorLog();  
147:                 errorLog.LogException("DeleteAnswer", ex, isqlWrapper);  
148:                 throw;  
149:             }  
150:         }  
151: There is a limit of 150 source code lines in the evaluation version
152: There is a limit of 150 source code lines in the evaluation version
153: There is a limit of 150 source code lines in the evaluation version

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