Component Page /QuestionImage.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:   
9:     [Serializable]  
10:     public class QuestionImage  
11:     {  
12:   
13:         private byte[] _image;  
14:         private int? _imageId;  
15:   
16:         private int _questionId;  
17:   
18:         public int? ImageId  
19:         {  
20:             get { return _imageId; }  
21:             set { _imageId = value; }  
22:         }  
23:   
24:         public int QuestionId  
25:         {  
26:             get { return _questionId; }  
27:             set { _questionId = value; }  
28:         }  
29:   
30:         public byte[] Image  
31:         {  
32:             get { return _image; }  
33:             set { _image = value; }  
34:         }  
35:   
36:         public void Load(int? questionId, ISqlWrapper isqlWrapper)  
37:         {  
38:             string connStr = isqlWrapper.GetConnectionString();  
39:   
40:             if (connStr == null)  
41:                 throw new NotImplementedException();  
42:   
43:             const string sproc = "GetQuestionImage";  
44:             var parameters = new SqlParameter[1];  
45:             parameters[0] = new SqlParameter("QuestionID", questionId);  
46:             try  
47:             {  
48:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
49:                 if (tbl.Rows.Count > 0)  
50:                 {  
51:                     ImageId = Convert.ToInt32(tbl.Rows[0]["ImageID"]);  
52:                     QuestionId = Convert.ToInt32(tbl.Rows[0]["QuestionID"]);  
53:                     Image = (byte[])tbl.Rows[0]["Image"];  
54:                 }  
55:   
56:             }  
57:             catch (Exception ex)  
58:             {  
59:                 ErrorLog errorLog = new ErrorLog();  
60:                 errorLog.LogException("HasUserFavourites", ex, isqlWrapper);  
61:                 throw;  
62:             }  
63:         }  
64:   
65:         public void Save()  
66:         {  
67:             ImageId = 0;  
68:             ISqlWrapper isqlWrapper = new SqlWrapper();  
69:             string connStr = isqlWrapper.GetConnectionString();  
70:             const string sproc = "CreateQuestionImage";  
71:             var parameters = new SqlParameter[3];  
72:             parameters[0] = new SqlParameter("@QuestionID", QuestionId);  
73:             parameters[1] = new SqlParameter("@Image", Image);  
74:             parameters[2] = new SqlParameter("@NewID", ImageId)  
75:             {  
76:                 Direction = ParameterDirection.Output  
77:             };  
78:             try  
79:             {  
80:                 SqlHelper.ExecuteScalar(connStr, CommandType.StoredProcedure, sproc, parameters);  
81:                 ImageId = (int)parameters[2].Value;  
82:             }  
83:             catch (Exception ex)  
84:             {  
85:                 ErrorLog errorLog = new ErrorLog();  
86:                 errorLog.LogException("QuestionImage.Save", ex, isqlWrapper);  
87:                 throw;  
88:             }  
89:   
90:         }  
91:     }  
92: }  

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