diff --git a/qcbadge/Controllers/HomeController.cs b/qcbadge/Controllers/HomeController.cs index d5ca3b4..2a8e6ff 100644 --- a/qcbadge/Controllers/HomeController.cs +++ b/qcbadge/Controllers/HomeController.cs @@ -59,15 +59,17 @@ namespace qcbadge.Controllers if ((String.Compare(Startup.scode, s, true) == 0)) { ViewData["Message"] = ""; - ViewData["0"] = 0; - ViewData["1"] = 0; - ViewData["38"] = 0; + ViewData["lastseen"] = ""; + ViewData["indv"] = 0; + ViewData["curr"] = 99; bool[] imglist = new bool[48]; + if (String.IsNullOrEmpty(id)) { imglist = sql.selectGlobalView(); + ViewData["lastseen"] = sql.selectGlobalLastSeen(); for (int i = 0; i < 48; i++) { @@ -76,9 +78,17 @@ namespace qcbadge.Controllers } else { + ViewData["indv"] = 1; int badgeid = Convert.ToInt32(id); badgeid = badgeid + 1; imglist = sql.selectIndervidualView(badgeid); + string[] listdata = sql.selectIndervidualLastSeen(badgeid); + ViewData["lastseen"] = listdata[0]; + + if(!String.IsNullOrEmpty(listdata[1])) + { + ViewData["curr"] = Convert.ToInt32(listdata[1]); + } for (int i = 0; i < 48; i++) { diff --git a/qcbadge/Helpers/Sql.cs b/qcbadge/Helpers/Sql.cs index 986815e..6d28beb 100644 --- a/qcbadge/Helpers/Sql.cs +++ b/qcbadge/Helpers/Sql.cs @@ -73,6 +73,105 @@ namespace qcbadge.Helpers return rtn; } + public string selectGlobalLastSeen() + { + //System.Diagnostics.Debug.WriteLine("Got to selectGlobalView"); + string rtn = ""; + + + //System.Diagnostics.Debug.WriteLine("Into loop " + i); + + try + { + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); + builder.DataSource = DataSource; + builder.UserID = UserID; + builder.Password = Password; + builder.InitialCatalog = db; + + using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) + { + connection.Open(); + StringBuilder sb = new StringBuilder(); + sb.Append("SELECT [lastseen] "); + sb.Append("FROM " + table); + sb.Append(" WHERE [lastseen] IN (SELECT max([lastseen]) FROM [qcbadge]);"); + String sql = sb.ToString(); + //System.Diagnostics.Debug.WriteLine(sql); + + + using (SqlCommand command = new SqlCommand(sql, connection)) + { + using (SqlDataReader reader = command.ExecuteReader()) + { + while (reader.Read()) + { + rtn = reader[0].ToString(); + } + } + } + } + } + catch (SqlException e) + { + System.Diagnostics.Debug.WriteLine(e.ToString()); + } + + + + return rtn; + } + + public string[] selectIndervidualLastSeen(int badgeid) + { + //System.Diagnostics.Debug.WriteLine("Got to selectGlobalView"); + string[] rtn = new string[2]; + + + //System.Diagnostics.Debug.WriteLine("Into loop " + i); + + try + { + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); + builder.DataSource = DataSource; + builder.UserID = UserID; + builder.Password = Password; + builder.InitialCatalog = db; + + using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) + { + connection.Open(); + StringBuilder sb = new StringBuilder(); + sb.Append("SELECT [lastseen], [curr] "); + sb.Append("FROM " + table); + sb.Append(" WHERE [badgeid] = '" + badgeid + "';"); + String sql = sb.ToString(); + //System.Diagnostics.Debug.WriteLine(sql); + + + using (SqlCommand command = new SqlCommand(sql, connection)) + { + using (SqlDataReader reader = command.ExecuteReader()) + { + while (reader.Read()) + { + rtn[0] = reader[0].ToString(); + rtn[1] = reader[1].ToString(); + } + } + } + } + } + catch (SqlException e) + { + System.Diagnostics.Debug.WriteLine(e.ToString()); + } + + + + return rtn; + } + public bool[] selectIndervidualView(int badgeid) { bool[] rtn = new bool[48]; diff --git a/qcbadge/Views/Home/List.cshtml b/qcbadge/Views/Home/List.cshtml index a48f2e5..9e0071b 100644 --- a/qcbadge/Views/Home/List.cshtml +++ b/qcbadge/Views/Home/List.cshtml @@ -2,6 +2,9 @@ ViewData["Title"] = "Map View"; bool[] showimg = new bool[50]; + bool indv = Convert.ToBoolean(ViewData["indv"]); + int curr = Convert.ToInt32(ViewData["curr"]); + for (int i = 0; i < 50; i++) { @@ -114,7 +117,7 @@ imgdesc[47] = "/images/48-eb4ce412-61c2-11e7-a915-d794e6b54cea.png"; - imgdesc[99] = "???????"; + imgdesc[99] = " "; string[] img = new string[48]; string[] desc = new string[48]; @@ -151,4 +154,17 @@ } -
@ViewData["Message"]
\ No newline at end of file +@if (indv) +{ + + + Your Current Icon + + + +} +
Last Updated: @ViewData["lastseen"]
+
@ViewData["Message"]
+ + +