Component Page /VirtualLab.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 VirtualLab
10: {
11: public int VirtualLabID { get; set; }
12: public Topic Topic { get; set; }
13: public string VirtualLabDesc { get; set; }
14: public string VirtualLabUrl { get; set; }
15: public int VirtualLabPosition { get; set; }
16:
17: public void Delete()
18: {
19: ISqlWrapper isqlWrapper = new SqlWrapper();
20: string connStr = isqlWrapper.GetConnectionString();
21: const string sproc = "DeleteVirtualLab";
22:
23: var parameters = new SqlParameter[1];
24:
25: parameters[0] = new SqlParameter("@VirtualLabID", VirtualLabID);
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("DeleteVirtualLab", ex, isqlWrapper);
34: throw;
35: }
36: }
37:
38: public void Get(int virtualLabID)
39: {
40: ISqlWrapper isqlWrapper = new SqlWrapper();
41: string connStr = isqlWrapper.GetConnectionString();
42: const string sproc = "GetVirtualLab";
43:
44: var parameters = new SqlParameter[1];
45:
46: parameters[0] = new SqlParameter("@VirtualLabID", virtualLabID);
47: try
48: {
49: DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];
50: foreach (DataRow row in tbl.Rows)
51: {
52: VirtualLabID = Convert.ToInt32(row["VirtualLabID"]);
53: Topic = new Topic(row["TopicCode"].ToString());
54: VirtualLabDesc = row["VirtualLabDesc"].ToString();
55: VirtualLabUrl = row["VirtualLabURL"].ToString();
56: VirtualLabPosition = Convert.ToInt32(row["VirtualLabPosition"]);
57: }
58: }
59: catch (Exception ex)
60: {
61: ErrorLog errorLog = new ErrorLog();
62: errorLog.LogException("VirtualLabGetVirtualLabID", ex, isqlWrapper);
63: throw;
64: }
65: }
66:
67: public List<VirtualLab> Get(Topic topic)
68: {
69: ISqlWrapper isqlWrapper = new SqlWrapper();
70: string connStr = isqlWrapper.GetConnectionString();
71: const string sproc = "GetVirtualLabs";
72:
73: var parameters = new SqlParameter[1];
74:
75: parameters[0] = new SqlParameter("@TopicCode", topic.TopicCode);
76:
77: List<VirtualLab> virtualLabs = new List<VirtualLab>();
78: try
79: {
80: DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];
81: foreach (DataRow row in tbl.Rows)
82: {
83: VirtualLab virtualLab = new VirtualLab();
84: virtualLab.VirtualLabID = Convert.ToInt32(row["VirtualLabID"]);
85: virtualLab.Topic = new Topic(row["TopicCode"].ToString());
86: virtualLab.VirtualLabDesc = row["VirtualLabDesc"].ToString();
87: virtualLab.VirtualLabUrl = row["VirtualLabURL"].ToString();
88: virtualLab.VirtualLabPosition = Convert.ToInt32(row["VirtualLabPosition"]);
89: virtualLabs.Add(virtualLab);
90: }
91:
92: return virtualLabs;
93: }
94: catch (Exception ex)
95: {
96: ErrorLog errorLog = new ErrorLog();
97: errorLog.LogException("VirtualLabGetTopic", 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 = "InsertVirtualLab";
107:
108: var parameters = new SqlParameter[5];
109:
110: parameters[0] = new SqlParameter("@TopicCode", Topic.TopicCode);
111: parameters[1] = new SqlParameter("@VirtualLabDesc", VirtualLabDesc);
112: parameters[2] = new SqlParameter("@VirtualLabURL", VirtualLabUrl);
113: parameters[3] = new SqlParameter("@VirtualLabPosition", VirtualLabPosition);
114: parameters[4] = new SqlParameter("@VirtualLabID", Convert.ToInt32(0)) { Direction = ParameterDirection.InputOutput };
115:
116:
117: try
118: {
119: isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);
120: VirtualLabID = Convert.ToInt32(parameters[4].Value);
121: }
122: catch (Exception ex)
123: {
124: ErrorLog errorLog = new ErrorLog();
125: errorLog.LogException("VirtualLabAdd", 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 = "SaveVirtualLab";
135:
136: var parameters = new SqlParameter[5];
137:
138: parameters[0] = new SqlParameter("@VirtualLabID", VirtualLabID);
139: parameters[1] = new SqlParameter("@TopicCode", Topic.TopicCode);
140: parameters[2] = new SqlParameter("@VirtualLabDesc", VirtualLabDesc);
141: parameters[3] = new SqlParameter("@VirtualLabURL", VirtualLabUrl);
142: parameters[4] = new SqlParameter("@VirtualLabPosition", VirtualLabPosition);
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.