From fdcefed085179099b4786d862964438b1681776f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 28 Apr 2018 14:39:21 +0100 Subject: [PATCH] Update DB to version 16: Machines can have an arbitrary number of gpus, so use an interconnection table, `gpus_by_machine`. --- Cicm.Database/Operations/GpuByMachine.cs | 149 +++++++++++++++ Cicm.Database/Operations/Init.cs | 54 +++--- Cicm.Database/Operations/Machine.cs | 84 ++++----- Cicm.Database/Operations/Operations.cs | 2 +- Cicm.Database/Operations/Update.cs | 83 +++++++++ Cicm.Database/Schemas/GpuByMachine.cs | 41 +++++ Cicm.Database/Schemas/Machine.cs | 2 - Cicm.Database/Schemas/Sql/V16.cs | 139 ++++++++++++++ cicm_web/Models/GpuByMachine.cs | 57 ++++++ cicm_web/Models/Machine.cs | 4 +- cicm_web/Views/Machine/View.cshtml | 222 ++++++++++++----------- cicm_web/cicm_web.csproj | 2 +- 12 files changed, 655 insertions(+), 184 deletions(-) create mode 100644 Cicm.Database/Operations/GpuByMachine.cs create mode 100644 Cicm.Database/Schemas/GpuByMachine.cs create mode 100644 Cicm.Database/Schemas/Sql/V16.cs create mode 100644 cicm_web/Models/GpuByMachine.cs diff --git a/Cicm.Database/Operations/GpuByMachine.cs b/Cicm.Database/Operations/GpuByMachine.cs new file mode 100644 index 00000000..3de94984 --- /dev/null +++ b/Cicm.Database/Operations/GpuByMachine.cs @@ -0,0 +1,149 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : GpuByMachine.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Contains operations to manage gpus. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Data; +using Cicm.Database.Schemas; + +namespace Cicm.Database +{ + public partial class Operations + { + /// + /// Gets all gpus in machine + /// + /// All CPUs + /// true if is correct, false otherwise + public bool GetGpusByMachines(out List entries, int machineId) + { + #if DEBUG + Console.WriteLine("Getting all gpus for machine {0}...", machineId); + #endif + + try + { + string sql = $"SELECT * FROM gpus_by_machine WHERE machine = {machineId}"; + + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbCmd.CommandText = sql; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbCmd; + dataAdapter.Fill(dataSet); + + entries = GpuByMachinesFromDataTable(dataSet.Tables[0]); + + return true; + } + catch(Exception ex) + { + Console.WriteLine("Error getting gpus by machine."); + Console.WriteLine(ex); + entries = null; + return false; + } + } + + /// + /// Gets all machines with specified gpu + /// + /// All CPUs + /// true if is correct, false otherwise + public bool GetMachinesByGpu(out List entries, int gpuId) + { + #if DEBUG + Console.WriteLine("Getting all machines with gpu {0}...", gpuId); + #endif + + try + { + string sql = $"SELECT * FROM gpus_by_machine WHERE gpu = {gpuId}"; + + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbCmd.CommandText = sql; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbCmd; + dataAdapter.Fill(dataSet); + + entries = GpuByMachinesFromDataTable(dataSet.Tables[0]); + + return true; + } + catch(Exception ex) + { + Console.WriteLine("Error getting machines by gpu."); + Console.WriteLine(ex); + entries = null; + return false; + } + } + + IDbCommand GetCommandGpuByMachine(GpuByMachine entry) + { + IDbCommand dbcmd = dbCon.CreateCommand(); + + IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param2 = dbcmd.CreateParameter(); + + param1.ParameterName = "@gpu"; + param2.ParameterName = "@machine"; + + param1.DbType = DbType.Int32; + param2.DbType = DbType.Int32; + + param1.Value = entry.Gpu; + param2.Value = entry.Machine; + + dbcmd.Parameters.Add(param1); + + return dbcmd; + } + + static List GpuByMachinesFromDataTable(DataTable dataTable) + { + List entries = new List(); + + foreach(DataRow dataRow in dataTable.Rows) + { + GpuByMachine entry = new GpuByMachine + { + Machine = (int)dataRow["machine"], + Gpu = (int)dataRow["gpu"] + }; + + entries.Add(entry); + } + + return entries; + } + } +} \ No newline at end of file diff --git a/Cicm.Database/Operations/Init.cs b/Cicm.Database/Operations/Init.cs index 2ed2e347..b70962fc 100644 --- a/Cicm.Database/Operations/Init.cs +++ b/Cicm.Database/Operations/Init.cs @@ -49,103 +49,107 @@ namespace Cicm.Database IDbCommand dbCmd = dbCon.CreateCommand(); Console.WriteLine("Creating table `admins`"); - dbCmd.CommandText = V15.Admins; + dbCmd.CommandText = V16.Admins; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `browser_tests`"); - dbCmd.CommandText = V15.BrowserTests; + dbCmd.CommandText = V16.BrowserTests; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `cicm_db`"); - dbCmd.CommandText = V15.CicmDb; + dbCmd.CommandText = V16.CicmDb; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `companies`"); - dbCmd.CommandText = V15.Companies; + dbCmd.CommandText = V16.Companies; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `machines`"); - dbCmd.CommandText = V15.Machines; + dbCmd.CommandText = V16.Machines; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `disk_formats`"); - dbCmd.CommandText = V15.DiskFormats; + dbCmd.CommandText = V16.DiskFormats; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `forbidden`"); - dbCmd.CommandText = V15.Forbidden; + dbCmd.CommandText = V16.Forbidden; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `gpus`"); - dbCmd.CommandText = V15.Gpus; + dbCmd.CommandText = V16.Gpus; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `log`"); - dbCmd.CommandText = V15.Logs; + dbCmd.CommandText = V16.Logs; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `money_donations`"); - dbCmd.CommandText = V15.MoneyDonations; + dbCmd.CommandText = V16.MoneyDonations; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `news`"); - dbCmd.CommandText = V15.News; + dbCmd.CommandText = V16.News; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_computers`"); - dbCmd.CommandText = V15.OwnedComputers; + dbCmd.CommandText = V16.OwnedComputers; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_consoles`"); - dbCmd.CommandText = V15.OwnedConsoles; + dbCmd.CommandText = V16.OwnedConsoles; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_sets`"); - dbCmd.CommandText = V15.InstructionSets; + dbCmd.CommandText = V16.InstructionSets; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_set_extensions`"); - dbCmd.CommandText = V15.InstructionSetExtensions; + dbCmd.CommandText = V16.InstructionSetExtensions; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `processors`"); - dbCmd.CommandText = V15.Processors; + dbCmd.CommandText = V16.Processors; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_set_extensions_by_processor`"); - dbCmd.CommandText = V15.InstructionSetExtensionsByProcessor; + dbCmd.CommandText = V16.InstructionSetExtensionsByProcessor; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `sound_synths`"); - dbCmd.CommandText = V15.SoundSynths; + dbCmd.CommandText = V16.SoundSynths; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `iso3166_1_numeric`"); - dbCmd.CommandText = V15.Iso3166Numeric; + dbCmd.CommandText = V16.Iso3166Numeric; dbCmd.ExecuteNonQuery(); Console.WriteLine("Filling table `iso3166_1_numeric`"); - dbCmd.CommandText = V15.Iso3166NumericValues; + dbCmd.CommandText = V16.Iso3166NumericValues; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `companies`"); - dbCmd.CommandText = V15.CompaniesForeignKeys; + dbCmd.CommandText = V16.CompaniesForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `machines`"); - dbCmd.CommandText = V15.MachinesForeignKeys; + dbCmd.CommandText = V16.MachinesForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `company_logos`"); - dbCmd.CommandText = V15.CompanyLogos; + dbCmd.CommandText = V16.CompanyLogos; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `company_descriptions`"); - dbCmd.CommandText = V15.CompanyDescriptions; + dbCmd.CommandText = V16.CompanyDescriptions; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `processors_by_machine`"); - dbCmd.CommandText = V15.ProcessorsByMachine; + dbCmd.CommandText = V16.ProcessorsByMachine; + dbCmd.ExecuteNonQuery(); + + Console.WriteLine("Creating table `gpus_by_machine`"); + dbCmd.CommandText = V16.GpusByMachine; dbCmd.ExecuteNonQuery(); return true; diff --git a/Cicm.Database/Operations/Machine.cs b/Cicm.Database/Operations/Machine.cs index 6f0a200c..09b67ff5 100644 --- a/Cicm.Database/Operations/Machine.cs +++ b/Cicm.Database/Operations/Machine.cs @@ -214,9 +214,9 @@ namespace Cicm.Database dbcmd.Transaction = trans; const string SQL = - "INSERT INTO machines (company, year, model, ram, rom, gpu, vram, colors, res, sound_synth, music_synth, " + + "INSERT INTO machines (company, year, model, ram, rom, vram, colors, res, sound_synth, music_synth, " + "sound_channels, music_channels, hdd1, hdd2, hdd3, disk1, cap1, disk2, cap2, type)" + - " VALUES (@company, @year, @model, @ram, @rom, @gpu, @vram, @colors, @res, @sound_synth, @music_synth, " + + " VALUES (@company, @year, @model, @ram, @rom, @vram, @colors, @res, @sound_synth, @music_synth, " + "@sound_channels, @music_channels, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, @cap2, @type)"; dbcmd.CommandText = SQL; @@ -251,7 +251,7 @@ namespace Cicm.Database string sql = "UPDATE machines SET company = @company, year = @year, model = @model, ram = @ram, rom = @rom, " + - "gpu = @gpu, vram = @vram, colors = @colors, res = @res, sound_synth = @sound_synth, " + + "vram = @vram, colors = @colors, res = @res, sound_synth = @sound_synth, " + "music_synth = @music_synth, sound_channels = @sound_channels, music_channels = @music_channels, " + "hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, cap1 = @cap1, disk2 = @disk2, cap2 = @cap2, " + "type = @type " + @@ -304,7 +304,7 @@ namespace Cicm.Database IDbDataParameter param6 = dbcmd.CreateParameter(); IDbDataParameter param7 = dbcmd.CreateParameter(); IDbDataParameter param8 = dbcmd.CreateParameter(); - IDbDataParameter param9 = dbcmd.CreateParameter(); + IDbDataParameter param9 = dbcmd.CreateParameter(); IDbDataParameter param10 = dbcmd.CreateParameter(); IDbDataParameter param11 = dbcmd.CreateParameter(); IDbDataParameter param12 = dbcmd.CreateParameter(); @@ -316,29 +316,27 @@ namespace Cicm.Database IDbDataParameter param18 = dbcmd.CreateParameter(); IDbDataParameter param19 = dbcmd.CreateParameter(); IDbDataParameter param20 = dbcmd.CreateParameter(); - IDbDataParameter param21 = dbcmd.CreateParameter(); param1.ParameterName = "@company"; param2.ParameterName = "@year"; param3.ParameterName = "@model"; param4.ParameterName = "@ram"; param5.ParameterName = "@rom"; - param6.ParameterName = "@gpu"; - param7.ParameterName = "@vram"; - param8.ParameterName = "@colors"; - param9.ParameterName = "@res"; - param10.ParameterName = "@sound_synth"; - param11.ParameterName = "@music_synth"; - param12.ParameterName = "@sound_channels"; - param13.ParameterName = "@music_channels"; - param14.ParameterName = "@hdd1"; - param15.ParameterName = "@hdd2"; - param16.ParameterName = "@hdd3"; - param17.ParameterName = "@disk1"; + param6.ParameterName = "@vram"; + param7.ParameterName = "@colors"; + param8.ParameterName = "@res"; + param9.ParameterName = "@sound_synth"; + param10.ParameterName = "@music_synth"; + param11.ParameterName = "@sound_channels"; + param12.ParameterName = "@music_channels"; + param13.ParameterName = "@hdd1"; + param14.ParameterName = "@hdd2"; + param15.ParameterName = "@hdd3"; + param16.ParameterName = "@disk1"; param17.ParameterName = "@cap1"; - param19.ParameterName = "@disk2"; - param20.ParameterName = "@cap2"; - param21.ParameterName = "@type"; + param18.ParameterName = "@disk2"; + param19.ParameterName = "@cap2"; + param20.ParameterName = "@type"; param1.DbType = DbType.Int32; param2.DbType = DbType.Int32; @@ -347,8 +345,8 @@ namespace Cicm.Database param5.DbType = DbType.Int32; param6.DbType = DbType.Int32; param7.DbType = DbType.Int32; - param8.DbType = DbType.Int32; - param9.DbType = DbType.String; + param8.DbType = DbType.String; + param9.DbType = DbType.Int32; param10.DbType = DbType.Int32; param11.DbType = DbType.Int32; param12.DbType = DbType.Int32; @@ -356,33 +354,31 @@ namespace Cicm.Database param14.DbType = DbType.Int32; param15.DbType = DbType.Int32; param16.DbType = DbType.Int32; - param17.DbType = DbType.Int32; - param18.DbType = DbType.String; - param19.DbType = DbType.Int32; - param20.DbType = DbType.String; - param21.DbType = DbType.Int32; + param17.DbType = DbType.String; + param18.DbType = DbType.Int32; + param19.DbType = DbType.String; + param20.DbType = DbType.Int32; param1.Value = entry.Company; param2.Value = entry.Year; param3.Value = entry.Model; param4.Value = entry.Ram; param5.Value = entry.Rom; - param6.Value = entry.Gpu; - param7.Value = entry.Vram; - param8.Value = entry.Colors; - param9.Value = entry.Resolution; - param10.Value = entry.SoundSynth; - param11.Value = entry.MusicSynth; - param12.Value = entry.SoundChannels; - param13.Value = entry.MusicChannels; - param14.Value = entry.Hdd1; - param15.Value = entry.Hdd2; - param16.Value = entry.Hdd3; - param17.Value = entry.Disk1; - param18.Value = entry.Cap1; - param19.Value = entry.Disk2; - param20.Value = entry.Cap2; - param21.Value = entry.Type; + param6.Value = entry.Vram; + param7.Value = entry.Colors; + param8.Value = entry.Resolution; + param9.Value = entry.SoundSynth; + param10.Value = entry.MusicSynth; + param11.Value = entry.SoundChannels; + param12.Value = entry.MusicChannels; + param13.Value = entry.Hdd1; + param14.Value = entry.Hdd2; + param15.Value = entry.Hdd3; + param16.Value = entry.Disk1; + param17.Value = entry.Cap1; + param18.Value = entry.Disk2; + param19.Value = entry.Cap2; + param20.Value = entry.Type; dbcmd.Parameters.Add(param1); dbcmd.Parameters.Add(param2); @@ -404,7 +400,6 @@ namespace Cicm.Database dbcmd.Parameters.Add(param18); dbcmd.Parameters.Add(param19); dbcmd.Parameters.Add(param20); - dbcmd.Parameters.Add(param21); return dbcmd; } @@ -423,7 +418,6 @@ namespace Cicm.Database Model = (string)dataRow["model"], Ram = (int)dataRow["ram"], Rom = (int)dataRow["rom"], - Gpu = dataRow["gpu"] == DBNull.Value ? 0 : (int)dataRow["gpu"], Vram = (int)dataRow["vram"], Colors = (int)dataRow["colors"], Resolution = (string)dataRow["res"], diff --git a/Cicm.Database/Operations/Operations.cs b/Cicm.Database/Operations/Operations.cs index 0315b0f4..92d120df 100644 --- a/Cicm.Database/Operations/Operations.cs +++ b/Cicm.Database/Operations/Operations.cs @@ -35,7 +35,7 @@ namespace Cicm.Database public partial class Operations { /// Last known database version - const int DB_VERSION = 15; + const int DB_VERSION = 16; /// The column with this value indicates there is no item of this type. public const int DB_NONE = -1; /// This value indicates there's no GPU, but a direct memory->display connection (a framebuffer). diff --git a/Cicm.Database/Operations/Update.cs b/Cicm.Database/Operations/Update.cs index d04d4c49..0fc709dc 100644 --- a/Cicm.Database/Operations/Update.cs +++ b/Cicm.Database/Operations/Update.cs @@ -144,6 +144,11 @@ namespace Cicm.Database UpdateDatabaseToV15(); break; } + case 15: + { + UpdateDatabaseToV16(); + break; + } } OptimizeDatabase(); @@ -1687,6 +1692,84 @@ namespace Cicm.Database dbCmd.Dispose(); } + void UpdateDatabaseToV16() + { + Console.WriteLine("Updating database to version 15"); + + Console.WriteLine("Creating table `gpus_by_machine`"); + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbTransaction trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = V16.GpusByMachine; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Getting all items from `machines`"); + + dbCmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbCmd.CommandText = "SELECT * from machines"; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbCmd; + dataAdapter.Fill(dataSet); + + foreach(DataRow dataRow in dataSet.Tables[0].Rows) + { + IDbCommand dbcmd = dbCon.CreateCommand(); + + IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param2 = dbcmd.CreateParameter(); + + param1.ParameterName = "@machine"; + param2.ParameterName = "@gpu"; + + param1.DbType = DbType.Int32; + param2.DbType = DbType.Int32; + + param1.Value = (int)dataRow["id"]; + + const string SQL = + "INSERT INTO gpus_by_machine (machine, gpu) VALUES (@machine, @gpu)"; + + dbcmd.Parameters.Add(param1); + dbcmd.Parameters.Add(param2); + + if(dataRow["gpu"] != DBNull.Value) + { + param2.Value = (int)dataRow["gpu"]; + + trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + Console.WriteLine("Adding gpu {0} to machine {1}", (int)param2.Value, (int)param1.Value); + + dbcmd.CommandText = SQL; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + } + + dbcmd.Dispose(); + } + + Console.WriteLine("Removing processor columns from table `machines`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = "ALTER TABLE `machines` DROP FOREIGN KEY `fk_machines_gpu`;\n" + + "ALTER TABLE `machines` DROP COLUMN `gpu`;"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Setting new database version to 16..."); + dbCmd = dbCon.CreateCommand(); + dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('16')"; + dbCmd.ExecuteNonQuery(); + dbCmd.Dispose(); + } + void OptimizeDatabase() { IDbCommand dbCmd = dbCon.CreateCommand(); diff --git a/Cicm.Database/Schemas/GpuByMachine.cs b/Cicm.Database/Schemas/GpuByMachine.cs new file mode 100644 index 00000000..9551f810 --- /dev/null +++ b/Cicm.Database/Schemas/GpuByMachine.cs @@ -0,0 +1,41 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Computer.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// High level representation of a computer. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +namespace Cicm.Database.Schemas +{ + /// Computer + public class GpuByMachine + { + /// Machine ID + public int Machine; + /// GPU ID + public int Gpu; + } +} \ No newline at end of file diff --git a/Cicm.Database/Schemas/Machine.cs b/Cicm.Database/Schemas/Machine.cs index 95b855a8..06836de4 100644 --- a/Cicm.Database/Schemas/Machine.cs +++ b/Cicm.Database/Schemas/Machine.cs @@ -45,8 +45,6 @@ namespace Cicm.Database.Schemas public int Disk1; /// ID of second removable disk format public int Disk2; - /// ID of GPU - public int Gpu; /// ID of first hard disk format public int Hdd1; /// ID of second hard disk format diff --git a/Cicm.Database/Schemas/Sql/V16.cs b/Cicm.Database/Schemas/Sql/V16.cs new file mode 100644 index 00000000..2f6af889 --- /dev/null +++ b/Cicm.Database/Schemas/Sql/V16.cs @@ -0,0 +1,139 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : V16.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Contains SQL queries to create the database version 7. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +namespace Cicm.Database.Schemas.Sql +{ + public static class V16 + { + public static readonly string Admins = V15.Admins; + + public static readonly string BrowserTests = V15.BrowserTests; + + public static readonly string CicmDb = "CREATE TABLE `cicm_db` (\n" + + "`id` int(11) NOT NULL AUTO_INCREMENT,\n" + + "`version` int(11) NOT NULL,\n" + + "`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" + + "PRIMARY KEY (`id`)\n" + ");\n" + + "INSERT INTO cicm_db (version) VALUES ('16');"; + + public static readonly string Companies = V15.Companies; + + public static readonly string Machines = "CREATE TABLE `machines` (;\n" + + "`id` int(11) NOT NULL AUTO_INCREMENT,;\n" + + "`company` int(11) NOT NULL DEFAULT '0',;\n" + + "`year` int(11) NOT NULL DEFAULT '0',;\n" + + "`model` char(50) NOT NULL DEFAULT '',;\n" + + "`ram` int(11) NOT NULL DEFAULT '0',;\n" + + "`rom` int(11) NOT NULL DEFAULT '0',;\n" + + "`vram` int(11) NOT NULL DEFAULT '0',;\n" + + "`colors` int(11) NOT NULL DEFAULT '0',;\n" + + "`res` char(10) NOT NULL DEFAULT '',;\n" + + "`sound_synth` int(11) NOT NULL DEFAULT '0',;\n" + + "`music_synth` int(11) NOT NULL DEFAULT '0',;\n" + + "`sound_channels` int(11) NOT NULL DEFAULT '0',;\n" + + "`music_channels` int(11) NOT NULL DEFAULT '0',;\n" + + "`hdd1` int(11) NOT NULL DEFAULT '0',;\n" + + "`hdd2` int(11) DEFAULT NULL,;\n" + + "`hdd3` int(11) DEFAULT NULL,;\n" + + "`disk1` int(11) NOT NULL DEFAULT '0',;\n" + + "`cap1` char(25) NOT NULL DEFAULT '0',;\n" + + "`disk2` int(11) DEFAULT NULL,;\n" + + "`cap2` char(25) DEFAULT NULL,;\n" + + "`type` int(11) NOT NULL DEFAULT '0',;\n" + + "PRIMARY KEY (`id`),;\n" + + "KEY `idx_machines_company` (`company`),;\n" + + "KEY `idx_machines_year` (`year`),;\n" + + "KEY `idx_machines_model` (`model`),;\n" + + "KEY `idx_machines_ram` (`ram`),;\n" + + "KEY `idx_machines_rom` (`rom`),;\n" + + "KEY `idx_machines_vram` (`vram`),;\n" + + "KEY `idx_machines_colors` (`colors`),;\n" + + "KEY `idx_machines_res` (`res`),;\n" + + "KEY `idx_machines_sound_synth` (`sound_synth`),;\n" + + "KEY `idx_machines_music_synth` (`music_synth`),;\n" + + "KEY `idx_machines_hdd1` (`hdd1`),;\n" + + "KEY `idx_machines_hdd2` (`hdd2`),;\n" + + "KEY `idx_machines_hdd3` (`hdd3`),;\n" + + "KEY `idx_machines_disk1` (`disk1`),;\n" + + "KEY `idx_machines_disk2` (`disk2`),;\n" + + "KEY `idx_machines_cap1` (`cap1`),;\n" + + "KEY `idx_machines_cap2` (`cap2`),;\n" + + "KEY `idx_machines_type` (`type`));"; + + public static readonly string DiskFormats = V15.DiskFormats; + + public static readonly string Forbidden = V15.Forbidden; + + public static readonly string Gpus = V15.Gpus; + + public static readonly string Logs = V15.Logs; + + public static readonly string MoneyDonations = V15.MoneyDonations; + + public static readonly string News = V15.News; + + public static readonly string OwnedComputers = V15.OwnedComputers; + + public static readonly string OwnedConsoles = V15.OwnedConsoles; + + public static readonly string Processors = V15.Processors; + + public static readonly string SoundSynths = V15.SoundSynths; + + public static readonly string MachinesForeignKeys = V15.MachinesForeignKeys; + + public static readonly string Iso3166Numeric = V15.Iso3166Numeric; + + public static readonly string Iso3166NumericValues = V15.Iso3166NumericValues; + + public static readonly string CompaniesForeignKeys = V15.CompaniesForeignKeys; + + public static readonly string CompanyLogos = V15.CompanyLogos; + + public static readonly string CompanyDescriptions = V15.CompanyDescriptions; + + public static readonly string InstructionSets = V15.InstructionSets; + + public static readonly string InstructionSetExtensions = V15.InstructionSetExtensions; + + public static readonly string InstructionSetExtensionsByProcessor = V15.InstructionSetExtensionsByProcessor; + + public static readonly string ProcessorsByMachine = V15.ProcessorsByMachine; + + public static readonly string GpusByMachine = + "CREATE TABLE `gpus_by_machine` (\n" + + "`gpu` INT NOT NULL, \n" + + "`machine` INT NOT NULL,\n" + + "KEY `idx_gpus_by_machine_gpus` (`gpu`),\n" + + "KEY `idx_gpus_by_machine_machine` (`machine`),\n" + + "CONSTRAINT `fk_gpus_by_machine_machine` FOREIGN KEY (`machine`) REFERENCES `machines` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,\n" + + "CONSTRAINT `fk_gpus_by_machine_gpu` FOREIGN KEY (`gpu`) REFERENCES `gpus` (`id`) ON UPDATE CASCADE ON DELETE CASCADE);"; + } +} \ No newline at end of file diff --git a/cicm_web/Models/GpuByMachine.cs b/cicm_web/Models/GpuByMachine.cs new file mode 100644 index 00000000..4d2ac9f9 --- /dev/null +++ b/cicm_web/Models/GpuByMachine.cs @@ -0,0 +1,57 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : GpuByMachine.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Gpu by machine model +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +using System.Collections.Generic; + +namespace cicm_web.Models +{ + public class GpuByMachine + { + public Gpu Gpu; + + public static GpuByMachine[] GetAllItems(int machineId) + { + List dbItems = null; + bool? result = + Program.Database?.Operations.GetGpusByMachines(out dbItems, machineId); + if(result == null || result.Value == false || dbItems == null) return null; + + List items = new List(); + + foreach(Cicm.Database.Schemas.GpuByMachine dbItem in dbItems) + items.Add(new GpuByMachine + { + Gpu = Gpu.GetItem(dbItem.Gpu) + }); + + return items.ToArray(); + } + } +} \ No newline at end of file diff --git a/cicm_web/Models/Machine.cs b/cicm_web/Models/Machine.cs index ea0455d5..9db3575c 100644 --- a/cicm_web/Models/Machine.cs +++ b/cicm_web/Models/Machine.cs @@ -43,7 +43,7 @@ namespace cicm_web.Models public Company Company; public DiskFormat Disk1; public DiskFormat Disk2; - public Gpu Gpu; + public GpuByMachine[] Gpus; public DiskFormat Hdd1; public DiskFormat Hdd2; public DiskFormat Hdd3; @@ -94,7 +94,7 @@ namespace cicm_web.Models { Colors = dbItem.Colors, Company = Company.GetItem(dbItem.Company), - Gpu = Gpu.GetItem(dbItem.Gpu), + Gpus = GpuByMachine.GetAllItems(dbItem.Id), Hdd1 = DiskFormat.GetItem(dbItem.Hdd1), Hdd2 = DiskFormat.GetItem(dbItem.Hdd2), Hdd3 = DiskFormat.GetItem(dbItem.Hdd3), diff --git a/cicm_web/Views/Machine/View.cshtml b/cicm_web/Views/Machine/View.cshtml index 817cbae4..66f3f460 100644 --- a/cicm_web/Views/Machine/View.cshtml +++ b/cicm_web/Views/Machine/View.cshtml @@ -387,122 +387,128 @@ } } -@if(Model.Gpu == null || Model.Gpu != null && Model.Gpu.Id != -1) +@if(Model.Gpus != null && Model.Gpus.Length > 0) {
- Graphics processor + Graphics processing units
- - @if(Model.Gpu != null) - { - if(Model.Gpu.Id == -2) - { - - Framebuffer - -
-
- This computer directly draws pixels from software to a memory region that's converted to video output by a DAC or similar without using any specific graphics processing unit. -
-
- - } - else - { - - @($"{Model.Gpu.Name}") - -
-
- - @if(Model.Gpu.ModelCode != null && Model.Gpu.ModelCode != Model.Gpu.Name) - { - - - - - } - - - - - @if(Model.Gpu.Introduced != DateTime.MinValue) - { - - - - - } - @if(Model.Gpu.Package != null) - { - - - - - } - @if(Model.Gpu.Process != null || Model.Gpu.ProcessNm > 0) - { - - - + } + } + else + { + + } + } +
Model@Model.Gpu.ModelCode
Manufacturer - - @Model.Gpu.Company.Name -
Introduction date@($"{Model.Gpu.Introduced:yyyy}")
Package@Model.Gpu.Package
Manufacturing process - @if(Model.Gpu.Process != null && Model.Gpu.ProcessNm > 0) + + + @for(int i = 0; i < Model.Gpus.Length; i++) + { + if(Model.Gpus[i] != null) + { + if(Model.Gpus[i].Gpu.Id == -2) + { + + } + else + { + - } - } - else - { - - } + + + + + @if(Model.Gpus[i].Gpu.Introduced != DateTime.MinValue) + { + + + + + } + @if(Model.Gpus[i].Gpu.Package != null) + { + + + + + } + @if(Model.Gpus[i].Gpu.Process != null || Model.Gpus[i].Gpu.ProcessNm > 0) + { + + + + + } + @if(Model.Gpus[i].Gpu.DieSize > 0) + { + + + + + } + @if(Model.Gpus[i].Gpu.Transistors > 0) + { + + + + + } +
+ Framebuffer + +
+
+ This computer directly draws pixels from software to a memory region that's converted to video output by a DAC or similar without using any specific graphics processing unit. +
+
+
+ @($"{Model.Gpus[i].Gpu.Name}") + +
+
+ + @if(Model.Gpus[i].Gpu.ModelCode != null && Model.Gpus[i].Gpu.ModelCode != Model.Gpus[i].Gpu.Name) { - @Model.Gpu.Process - @("@") - @(Model.Gpu.ProcessNm > 100 ? $"{Model.Gpu.ProcessNm / 100}µm" : $"{Model.Gpu.ProcessNm}nm") + + + + } - else if(Model.Gpu.ProcessNm > 0) { @(Model.Gpu.ProcessNm > 100 ? $"{Model.Gpu.ProcessNm / 100}µm" : $"{Model.Gpu.ProcessNm}nm") } - else - { @Model.Gpu.Process } - - - } - @if(Model.Gpu.DieSize > 0) - { - - - - - } - @if(Model.Gpu.Transistors > 0) - { - - - - - } -
Model@Model.Gpus[i].Gpu.ModelCode
Die size@Model.Gpu.DieSize mm²
Transistors@Model.Gpu.Transistors
-
-
-
Unknown data
Manufacturer + + @Model.Gpus[i].Gpu.Company.Name +
Introduction date@($"{Model.Gpus[i].Gpu.Introduced:yyyy}")
Package@Model.Gpus[i].Gpu.Package
Manufacturing process + @if(Model.Gpus[i].Gpu.Process != null && Model.Gpus[i].Gpu.ProcessNm > 0) + { + @Model.Gpus[i].Gpu.Process + @("@") + @(Model.Gpus[i].Gpu.ProcessNm > 100 ? $"{Model.Gpus[i].Gpu.ProcessNm / 100}µm" : $"{Model.Gpus[i].Gpu.ProcessNm}nm") + } + else if(Model.Gpus[i].Gpu.ProcessNm > 0) { @(Model.Gpus[i].Gpu.ProcessNm > 100 ? $"{Model.Gpus[i].Gpu.ProcessNm / 100}µm" : $"{Model.Gpus[i].Gpu.ProcessNm}nm") } + else + { @Model.Gpus[i].Gpu.Process } +
Die size@Model.Gpus[i].Gpu.DieSize mm²
Transistors@Model.Gpus[i].Gpu.Transistors
+ + +
Unknown data
+ } diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 807b6693..6fd1a965 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.0 - 3.0.99.206 + 3.0.99.207 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website