Component Page /Log.cs (C#)
1: using System;  
2: using Microsoft.ApplicationBlocks.Data;  
3: using System.Data.SqlClient;  
4: using System.Data;  
5: using System.Collections.Generic;  
6:   
7: namespace QuizNetOnline.Logic  
8: {  
9:     [Serializable]  
10:     public class Log  
11:     {  
12:         public int LogId { get; set; }  
13:         public string Email { get; set; }  
14:         public string LogIp { get; set; }  
15:   
16:         public string LogArea { get; set; }  
17:   
18:         public string LogLocation { get; set; }  
19:   
20:         public double LogLatitude { get; set; }  
21:         public double LogLongitude { get; set; }  
22:   
23:         public DateTime LogDateTime { get; set; }  
24:   
25:         public UserWeb UserWeb { get; set; }  
26:   
27:         private static Log _instance;  
28:   
29:   
30:   
31:         public List<Log> GetLog(int logId, bool onlyRegisteredUsers,string logArea, string logLocation,ISqlWrapper isqlWrapper)  
32:         {  
33:             List<Log> logs = new List<Log>();  
34:   
35:             string connStr = isqlWrapper.GetConnectionString();  
36:             const string sproc = "GetLog";  
37:             var parameters = new SqlParameter[4];  
38:             parameters[0] = new SqlParameter("LogID", LogId);  
39:             parameters[1] = new SqlParameter("LogArea", logArea);  
40:             parameters[2] = new SqlParameter("LogLocation", logLocation);  
41:             parameters[3] = new SqlParameter("OnlyRegisteredUsers", onlyRegisteredUsers);  
42:   
43:             try  
44:             {  
45:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
46:   
47:                 foreach(DataRow row in tbl.Rows)  
48:                 {  
49:                     var log=new Log();  
50:                     log.LogArea = row["LogArea"].ToString();  
51:                     log.LogId = Convert.ToInt32(row["logId"]);  
52:                     log.LogIp = row["LogIP"].ToString();  
53:                     log.LogLocation = row["LogLocation"].ToString();  
54:                     log.LogDateTime = Convert.ToDateTime(row["LogDateTime"].ToString());  
55:                     log.LogLongitude = Convert.ToDouble(row["LogLongitude"].ToString());  
56:                     log.LogLatitude = Convert.ToDouble(row["LogLatitude"].ToString());  
57:                     log.Email = row["Email"].ToString();  
58:                     logs.Add(log);  
59:                 }  
60:   
61:                 return logs;  
62:             }  
63:             catch (Exception ex)  
64:             {  
65:                 ErrorLog errorLog = new ErrorLog();  
66:                 errorLog.LogException("GetLog", ex, isqlWrapper);  
67:                 throw;  
68:             }  
69:         }  
70:   
71:         public static Log Instance  
72:         {  
73:             get { return _instance ?? (_instance = new Log()); }  
74:         }  
75:   
76:   
77:         public void Save(ISqlWrapper isqlWrapper)  
78:         {  
79:   
80:             float latitude = 0;  
81:             float longitude = 0;  
82:   
83:             if (UserWeb != null && UserWeb.UserLocation != null)  
84:             {  
85:                 LogLocation = UserWeb.UserLocation.FullLocationName;  
86:                 latitude = UserWeb.UserLocation.Latitude;  
87:                 longitude = UserWeb.UserLocation.Longitude;  
88:                 LogIp = UserWeb.UserLocation.IPaddress;  
89:                 Email = UserWeb.UserName;  
90:             }  
91:   
92:             string connStr = isqlWrapper.GetConnectionString();  
93:             const string sproc = "SaveIPAddress";  
94:             var parameters = new SqlParameter[7];  
95:             parameters[0] = new SqlParameter("LogID", LogId);  
96:             parameters[1] = new SqlParameter("LogIP", LogIp);  
97:             parameters[2] = new SqlParameter("LogArea", LogArea);  
98:             parameters[3] = new SqlParameter("LogLocation", LogLocation);  
99:             parameters[4] = new SqlParameter("LogLatitude", latitude);  
100:             parameters[5] = new SqlParameter("LogLongitude", longitude);  
101:             parameters[6] = new SqlParameter("Email", Email);  
102:             try  
103:             {  
104:                 Object result = isqlWrapper.ExecuteScalar(connStr, CommandType.StoredProcedure, sproc, parameters);  
105:                 LogId = Convert.ToInt32(result.ToString());  
106:             }  
107:             catch (Exception ex)  
108:             {  
109:                 ErrorLog errorLog = new ErrorLog();  
110:                 errorLog.LogException("Log.Save", ex, isqlWrapper);  
111:                 throw;  
112:             }  
113:         }  
114:   
115:         public void ClearLog()  
116:         {  
117:             ISqlWrapper isqlWrapper = new SqlWrapper();  
118:             string connStr = isqlWrapper.GetConnectionString();  
119:             const string sproc = "DeleteLog";  
120:   
121:             try  
122:             {  
123:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc);  
124:             }  
125:             catch (Exception ex)  
126:             {  
127:                 ErrorLog errorLog = new ErrorLog();  
128:                 errorLog.LogException("ClearLog", ex, isqlWrapper);  
129:                 throw;  
130:             }  
131:         }  
132:     }  
133: }  

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