Component Page /Article.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:     public class Article  
10:     {  
11:         public int ArticleID { get; set; }  
12:         public Topic Topic { get; set; }  
13:         public string ArticleDesc { get; set; }  
14:         public string ArticleURL { get; set; }  
15:         public int ArticlePosition { get; set; }  
16:   
17:         public void Delete()  
18:         {  
19:             ISqlWrapper isqlWrapper = new SqlWrapper();  
20:             string connStr = isqlWrapper.GetConnectionString();  
21:             const string sproc = "DeleteArticle";  
22:   
23:             var parameters = new SqlParameter[1];  
24:   
25:             parameters[0] = new SqlParameter("@ArticleID", ArticleID);  
26:             try  
27:             {  
28:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
29:             }  
30:             catch (Exception ex)  
31:             {  
32:                 ErrorLog errorLog = new ErrorLog();  
33:                 errorLog.LogException("DeleteArticle", ex, isqlWrapper);  
34:                 throw;  
35:             }  
36:         }  
37:   
38:         public void Get(int articleID)  
39:         {  
40:             ISqlWrapper isqlWrapper = new SqlWrapper();  
41:             string connStr = isqlWrapper.GetConnectionString();  
42:             const string sproc = "GetArticle";  
43:   
44:             var parameters = new SqlParameter[1];  
45:   
46:             parameters[0] = new SqlParameter("@ArticleID", articleID);  
47:             try  
48:             {  
49:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
50:                 foreach (DataRow row in tbl.Rows)  
51:                 {  
52:                     ArticleID = Convert.ToInt32(row["ArticleID"]);  
53:                     Topic = new Topic(row["TopicCode"].ToString());  
54:                     ArticleDesc = row["ArticleDesc"].ToString();  
55:                     ArticleURL = row["ArticleURL"].ToString();  
56:                     ArticlePosition = Convert.ToInt32(row["ArticlePosition"]);  
57:                 }  
58:             }  
59:             catch (Exception ex)  
60:             {  
61:                 ErrorLog errorLog = new ErrorLog();  
62:                 errorLog.LogException("ArticleGetArticleID", ex, isqlWrapper);  
63:                 throw;  
64:             }  
65:         }  
66:   
67:         public List<Article> Get(Topic topic)  
68:         {  
69:             ISqlWrapper isqlWrapper = new SqlWrapper();  
70:             string connStr = isqlWrapper.GetConnectionString();  
71:             const string sproc = "GetArticles";  
72:   
73:             var parameters = new SqlParameter[1];  
74:   
75:             parameters[0] = new SqlParameter("@TopicCode", topic.TopicCode);  
76:   
77:             List<Article> Articles = new List<Article>();  
78:             try  
79:             {  
80:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
81:                 foreach (DataRow row in tbl.Rows)  
82:                 {  
83:                     Article Article = new Article();  
84:                     Article.ArticleID = Convert.ToInt32(row["ArticleID"]);  
85:                     Article.Topic = new Topic(row["TopicCode"].ToString());  
86:                     Article.ArticleDesc = row["ArticleDesc"].ToString();  
87:                     Article.ArticleURL = row["ArticleURL"].ToString();  
88:                     Article.ArticlePosition = Convert.ToInt32(row["ArticlePosition"]);  
89:                     Articles.Add(Article);  
90:                 }  
91:   
92:                 return Articles;  
93:             }  
94:             catch (Exception ex)  
95:             {  
96:                 ErrorLog errorLog = new ErrorLog();  
97:                 errorLog.LogException("ArticleGetTopic", ex, isqlWrapper);  
98:                 throw;  
99:             }  
100:         }  
101:   
102:         public void Add()  
103:         {  
104:             ISqlWrapper isqlWrapper = new SqlWrapper();  
105:             string connStr = isqlWrapper.GetConnectionString();  
106:             const string sproc = "InsertArticle";  
107:   
108:             var parameters = new SqlParameter[5];  
109:   
110:             parameters[0] = new SqlParameter("@TopicCode", Topic.TopicCode);  
111:             parameters[1] = new SqlParameter("@ArticleDesc", ArticleDesc);  
112:             parameters[2] = new SqlParameter("@ArticleURL", ArticleURL);  
113:             parameters[3] = new SqlParameter("@ArticlePosition", ArticlePosition);  
114:             parameters[4] = new SqlParameter("@ArticleID", Convert.ToInt32(0)) { Direction = ParameterDirection.InputOutput };  
115:   
116:   
117:             try  
118:             {  
119:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
120:                 ArticleID = Convert.ToInt32(parameters[4].Value);  
121:             }  
122:             catch (Exception ex)  
123:             {  
124:                 ErrorLog errorLog = new ErrorLog();  
125:                 errorLog.LogException("ArticleAdd", ex, isqlWrapper);  
126:                 throw;  
127:             }  
128:         }  
129:   
130:         public void Save()  
131:         {  
132:             ISqlWrapper isqlWrapper = new SqlWrapper();  
133:             string connStr = isqlWrapper.GetConnectionString();  
134:             const string sproc = "SaveArticle";  
135:   
136:             var parameters = new SqlParameter[5];  
137:   
138:             parameters[0] = new SqlParameter("@ArticleID", ArticleID);  
139:             parameters[1] = new SqlParameter("@TopicCode", Topic.TopicCode);  
140:             parameters[2] = new SqlParameter("@ArticleDesc", ArticleDesc);  
141:             parameters[3] = new SqlParameter("@ArticleURL", ArticleURL);  
142:             parameters[4] = new SqlParameter("@ArticlePosition", ArticlePosition);  
143:   
144:   
145:             try  
146:             {  
147:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
148:             }  
149:             catch (Exception ex)  
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
154: There is a limit of 150 source code lines in the evaluation version
155: There is a limit of 150 source code lines in the evaluation version
156: There is a limit of 150 source code lines in the evaluation version
157: There is a limit of 150 source code lines in the evaluation version

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