From 782e1e86197a848dd4bbaefd63c19afa1e1a8e70 Mon Sep 17 00:00:00 2001 From: Jake Visser Date: Wed, 5 Jul 2017 17:02:39 -0700 Subject: [PATCH] spelling... Indervidual view now working --- qcbadge/Controllers/HomeController.cs | 23 +++++- qcbadge/CreateDB.sql | 8 +- qcbadge/Helpers/Sql.cs | 103 +++++++++++++++++++++++++- 3 files changed, 126 insertions(+), 8 deletions(-) diff --git a/qcbadge/Controllers/HomeController.cs b/qcbadge/Controllers/HomeController.cs index 9138b15..481f86d 100644 --- a/qcbadge/Controllers/HomeController.cs +++ b/qcbadge/Controllers/HomeController.cs @@ -10,19 +10,36 @@ namespace qcbadge.Controllers { public IActionResult Index(string s, string id) { + Helpers.Sql sql = new Helpers.Sql(); + if ((String.Compare(Startup.scode, s, true) == 0)) { ViewData["Message"] = ""; - ViewData["0"] = 1; - ViewData["1"] = 1; - ViewData["38"] = 1; + ViewData["0"] = 0; + ViewData["1"] = 0; + ViewData["38"] = 0; + + bool[] imglist = new bool[50]; if (String.IsNullOrEmpty(id)) { + imglist = sql.selectGlobalView(); + for (int i = 0; i < 50; i++) + { + ViewData[i.ToString()] = imglist[i]; + } } else { + int badgeid = Convert.ToInt32(id); + badgeid = badgeid - 1; + imglist = sql.selectIndervidualView(badgeid); + + for (int i = 0; i < 50; i++) + { + ViewData[i.ToString()] = imglist[i]; + } } diff --git a/qcbadge/CreateDB.sql b/qcbadge/CreateDB.sql index 1830f9a..fea1ab5 100644 --- a/qcbadge/CreateDB.sql +++ b/qcbadge/CreateDB.sql @@ -1,7 +1,7 @@ USE [dcbadge] GO -DROP TABLE [dbo].[qcbdage] +DROP TABLE [dbo].[qcbadge] GO SET ANSI_NULLS ON @@ -10,7 +10,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE TABLE [dbo].[qcbdage]( +CREATE TABLE [dbo].[qcbadge]( [badgeid] [int] IDENTITY(1,1) NOT NULL, [0] [bit] DEFAULT 0 NOT NULL, [1] [bit] DEFAULT 0 NOT NULL, @@ -71,9 +71,9 @@ PRIMARY KEY CLUSTERED GO -WHILE (SELECT COUNT([badgeid]) FROM [qcbdage]) < 300 +WHILE (SELECT COUNT([badgeid]) FROM [qcbadge]) < 300 BEGIN -INSERT INTO [dbo].[qcbdage] +INSERT INTO [dbo].[qcbadge] ([0]) VALUES (0) diff --git a/qcbadge/Helpers/Sql.cs b/qcbadge/Helpers/Sql.cs index f0f77cc..8a2ca9b 100644 --- a/qcbadge/Helpers/Sql.cs +++ b/qcbadge/Helpers/Sql.cs @@ -13,12 +13,63 @@ namespace qcbadge.Helpers private static string UserID = Startup.dbuser; private static string Password = Startup.dbpass; private static string db = Startup.dbname; - private static string table = "qcbdage"; + private static string table = "[qcbadge]"; public bool[] selectGlobalView() { + //System.Diagnostics.Debug.WriteLine("Got to selectGlobalView"); bool[] rtn = new bool[50]; + for (int i = 0; i < 50; i++) + { + //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 COUNT([badgeid]) "); + sb.Append("FROM " + table); + sb.Append(" WHERE [" + i + "] = 1;"); + String sql = sb.ToString(); + //System.Diagnostics.Debug.WriteLine(sql); + + + using (SqlCommand command = new SqlCommand(sql, connection)) + { + using (SqlDataReader reader = command.ExecuteReader()) + { + while (reader.Read()) + { + int x = Convert.ToInt32(reader[0].ToString()); + if( x > 0 ) + { + rtn[i] = true; + } + else + { + rtn[i] = false; + } + } + } + } + } + } + catch (SqlException e) + { + System.Diagnostics.Debug.WriteLine(e.ToString()); + } + + } + return rtn; } @@ -26,6 +77,56 @@ namespace qcbadge.Helpers { bool[] rtn = new bool[50]; + for (int i = 0; i < 50; i++) + { + //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 COUNT([badgeid]) "); + sb.Append("FROM " + table); + sb.Append(" WHERE [badgeid] = '" + badgeid + "' AND [" + i + "] = 1;"); + String sql = sb.ToString(); + //System.Diagnostics.Debug.WriteLine(sql); + + + using (SqlCommand command = new SqlCommand(sql, connection)) + { + using (SqlDataReader reader = command.ExecuteReader()) + { + while (reader.Read()) + { + int x = Convert.ToInt32(reader[0].ToString()); + if (x > 0) + { + rtn[i] = true; + } + else + { + rtn[i] = false; + } + } + } + } + } + } + catch (SqlException e) + { + System.Diagnostics.Debug.WriteLine(e.ToString()); + } + + } + return rtn; }