spelling...

Indervidual view now working
This commit is contained in:
Jake Visser 2017-07-05 17:02:39 -07:00
commit 782e1e8619
3 changed files with 126 additions and 8 deletions

View file

@ -10,19 +10,36 @@ namespace qcbadge.Controllers
{ {
public IActionResult Index(string s, string id) public IActionResult Index(string s, string id)
{ {
Helpers.Sql sql = new Helpers.Sql();
if ((String.Compare(Startup.scode, s, true) == 0)) if ((String.Compare(Startup.scode, s, true) == 0))
{ {
ViewData["Message"] = ""; ViewData["Message"] = "";
ViewData["0"] = 1; ViewData["0"] = 0;
ViewData["1"] = 1; ViewData["1"] = 0;
ViewData["38"] = 1; ViewData["38"] = 0;
bool[] imglist = new bool[50];
if (String.IsNullOrEmpty(id)) if (String.IsNullOrEmpty(id))
{ {
imglist = sql.selectGlobalView();
for (int i = 0; i < 50; i++)
{
ViewData[i.ToString()] = imglist[i];
}
} }
else 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];
}
} }

View file

@ -1,7 +1,7 @@
USE [dcbadge] USE [dcbadge]
GO GO
DROP TABLE [dbo].[qcbdage] DROP TABLE [dbo].[qcbadge]
GO GO
SET ANSI_NULLS ON SET ANSI_NULLS ON
@ -10,7 +10,7 @@ GO
SET QUOTED_IDENTIFIER ON SET QUOTED_IDENTIFIER ON
GO GO
CREATE TABLE [dbo].[qcbdage]( CREATE TABLE [dbo].[qcbadge](
[badgeid] [int] IDENTITY(1,1) NOT NULL, [badgeid] [int] IDENTITY(1,1) NOT NULL,
[0] [bit] DEFAULT 0 NOT NULL, [0] [bit] DEFAULT 0 NOT NULL,
[1] [bit] DEFAULT 0 NOT NULL, [1] [bit] DEFAULT 0 NOT NULL,
@ -71,9 +71,9 @@ PRIMARY KEY CLUSTERED
GO GO
WHILE (SELECT COUNT([badgeid]) FROM [qcbdage]) < 300 WHILE (SELECT COUNT([badgeid]) FROM [qcbadge]) < 300
BEGIN BEGIN
INSERT INTO [dbo].[qcbdage] INSERT INTO [dbo].[qcbadge]
([0]) ([0])
VALUES VALUES
(0) (0)

View file

@ -13,12 +13,63 @@ namespace qcbadge.Helpers
private static string UserID = Startup.dbuser; private static string UserID = Startup.dbuser;
private static string Password = Startup.dbpass; private static string Password = Startup.dbpass;
private static string db = Startup.dbname; private static string db = Startup.dbname;
private static string table = "qcbdage"; private static string table = "[qcbadge]";
public bool[] selectGlobalView() public bool[] selectGlobalView()
{ {
//System.Diagnostics.Debug.WriteLine("Got to selectGlobalView");
bool[] rtn = new bool[50]; 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; return rtn;
} }
@ -26,6 +77,56 @@ namespace qcbadge.Helpers
{ {
bool[] rtn = new bool[50]; 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; return rtn;
} }