Component Page /UserSetting.cs (C#)
1: using System;  
2: using Microsoft.ApplicationBlocks.Data;  
3: using System.Data.SqlClient;  
4: using System.Data;  
5:   
6: namespace QuizNetOnline.Logic  
7: {  
8:     [Serializable]  
9:     public class UserSetting  
10:     {  
11:         private bool _isNew;  
12:   
13:         public bool IsNew  
14:         {  
15:             get { return _isNew; }  
16:             set { _isNew = value; }  
17:         }  
18:   
19:         private bool _isTestTaken;  
20:         private int _numberOfTestsTaken;  
21:         private bool _unlimitedQuestions;  
22:   
23:         private string _userName = "";  
24:         private int _numberOfQuestionsCorrect;  
25:   
26:         public bool IsTestTaken  
27:         {  
28:             get { return _isTestTaken; }  
29:             set { _isTestTaken = value; }  
30:         }  
31:   
32:         public string UserName  
33:         {  
34:             get { return _userName; }  
35:             set { _userName = value; }  
36:         }  
37:   
38:         public bool UnlimitedQuestions  
39:         {  
40:             get { return _unlimitedQuestions; }  
41:             set { _unlimitedQuestions = value; }  
42:         }  
43:   
44:         public int NumberOfTestsTaken  
45:         {  
46:             get { return _numberOfTestsTaken; }  
47:             set { _numberOfTestsTaken = value; }  
48:         }  
49:   
50:         public int NumberOfQuestionsCorrect  
51:         {  
52:             get { return _numberOfQuestionsCorrect; }  
53:             set { _numberOfQuestionsCorrect = value; }  
54:         }  
55:   
56:         public int NumberOfQuestionsIncorrect { get; set; }  
57:   
58:         public DateTime DateOfLastTest { get; set; }  
59:   
60:         public DataTable GetHistory(string userName)  
61:         {  
62:             ISqlWrapper iSqlWrapper = new SqlWrapper();  
63:             string connStr = iSqlWrapper.GetConnectionString();  
64:             const string sproc = "GetResults";  
65:             var parameters = new SqlParameter[2];  
66:             parameters[0] = new SqlParameter("UserName", userName);  
67:             parameters[1] = new SqlParameter("ResultID", Convert.ToInt32(0));  
68:             try  
69:             {  
70:                 DataTable tbl = iSqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
71:                 return tbl;  
72:             }  
73:             catch (Exception ex)  
74:             {  
75:                 ErrorLog errorLog = new ErrorLog();  
76:                 errorLog.LogException("GetHistory", ex, iSqlWrapper);  
77:                 throw;  
78:             }  
79:         }  
80:   
81:         public void Load(string userName, ISqlWrapper iSqlWrapper)  
82:         {  
83:             string connStr = iSqlWrapper.GetConnectionString();  
84:             const string sproc = "GetUserSetting";  
85:             var parameters = new SqlParameter[1];  
86:             parameters[0] = new SqlParameter("@UserName", userName);  
87:             try  
88:             {  
89:                 DataTable tbl = iSqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
90:                 UserName = userName;  
91:   
92:                 foreach (DataRow row in tbl.Rows)  
93:                 {  
94:                     UnlimitedQuestions = Convert.ToBoolean(row["UnlimitedQuestions"]);  
95:                     NumberOfTestsTaken = Convert.ToInt32(row["NumberOfTestsTaken"]);  
96:                     NumberOfQuestionsCorrect = Convert.ToInt32(row["NumberOfQuestionsCorrect"]);  
97:                     NumberOfQuestionsIncorrect = Convert.ToInt32(row["NumberOfQuestionsIncorrect"]);  
98:                     DateOfLastTest = Convert.ToDateTime(row["DateOfLastTest"]);  
99:                     IsNew = false;  
100:                     UserName = userName;  
101:                 }  
102:             }  
103:             catch (Exception ex)  
104:             {  
105:                 ErrorLog errorLog = new ErrorLog();  
106:                 errorLog.LogException("UserSetting Load", ex, iSqlWrapper);  
107:                 throw;  
108:             }  
109:         }  
110:   
111:         public void Save(ISqlWrapper iSqlWrapper)  
112:         {  
113:             string connStr = iSqlWrapper.GetConnectionString();  
114:             const string sproc = "SaveUserSettings";  
115:             var parameters = new SqlParameter[6];  
116:             parameters[0] = new SqlParameter("@QuestionTaken", IsTestTaken);  
117:             parameters[1] = new SqlParameter("@UserName", UserName);  
118:             parameters[2] = new SqlParameter("@UnlimitedQuestions", UnlimitedQuestions);  
119:             parameters[3] = new SqlParameter("@NumberOfTestsTaken", NumberOfTestsTaken);  
120:             parameters[4] = new SqlParameter("@NumberOfQuestionsCorrect", NumberOfQuestionsCorrect);  
121:             parameters[5] = new SqlParameter("@NumberOfQuestionsIncorrect", NumberOfQuestionsIncorrect);  
122:             try  
123:             {  
124:                 iSqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
125:             }  
126:             catch (Exception ex)  
127:             {  
128:                 ErrorLog errorLog = new ErrorLog();  
129:                 errorLog.LogException("Save", ex, iSqlWrapper);  
130:                 throw;  
131:             }  
132:         }  
133:     }  
134: }  

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