diff --git a/Cicm.Database/Operations/Init.cs b/Cicm.Database/Operations/Init.cs index b70962fc..d3d73552 100644 --- a/Cicm.Database/Operations/Init.cs +++ b/Cicm.Database/Operations/Init.cs @@ -49,107 +49,111 @@ namespace Cicm.Database IDbCommand dbCmd = dbCon.CreateCommand(); Console.WriteLine("Creating table `admins`"); - dbCmd.CommandText = V16.Admins; + dbCmd.CommandText = V17.Admins; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `browser_tests`"); - dbCmd.CommandText = V16.BrowserTests; + dbCmd.CommandText = V17.BrowserTests; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `cicm_db`"); - dbCmd.CommandText = V16.CicmDb; + dbCmd.CommandText = V17.CicmDb; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `companies`"); - dbCmd.CommandText = V16.Companies; + dbCmd.CommandText = V17.Companies; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `machines`"); - dbCmd.CommandText = V16.Machines; + dbCmd.CommandText = V17.Machines; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `disk_formats`"); - dbCmd.CommandText = V16.DiskFormats; + dbCmd.CommandText = V17.DiskFormats; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `forbidden`"); - dbCmd.CommandText = V16.Forbidden; + dbCmd.CommandText = V17.Forbidden; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `gpus`"); - dbCmd.CommandText = V16.Gpus; + dbCmd.CommandText = V17.Gpus; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `log`"); - dbCmd.CommandText = V16.Logs; + dbCmd.CommandText = V17.Logs; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `money_donations`"); - dbCmd.CommandText = V16.MoneyDonations; + dbCmd.CommandText = V17.MoneyDonations; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `news`"); - dbCmd.CommandText = V16.News; + dbCmd.CommandText = V17.News; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_computers`"); - dbCmd.CommandText = V16.OwnedComputers; + dbCmd.CommandText = V17.OwnedComputers; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_consoles`"); - dbCmd.CommandText = V16.OwnedConsoles; + dbCmd.CommandText = V17.OwnedConsoles; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_sets`"); - dbCmd.CommandText = V16.InstructionSets; + dbCmd.CommandText = V17.InstructionSets; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_set_extensions`"); - dbCmd.CommandText = V16.InstructionSetExtensions; + dbCmd.CommandText = V17.InstructionSetExtensions; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `processors`"); - dbCmd.CommandText = V16.Processors; + dbCmd.CommandText = V17.Processors; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_set_extensions_by_processor`"); - dbCmd.CommandText = V16.InstructionSetExtensionsByProcessor; + dbCmd.CommandText = V17.InstructionSetExtensionsByProcessor; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `sound_synths`"); - dbCmd.CommandText = V16.SoundSynths; + dbCmd.CommandText = V17.SoundSynths; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `iso3166_1_numeric`"); - dbCmd.CommandText = V16.Iso3166Numeric; + dbCmd.CommandText = V17.Iso3166Numeric; dbCmd.ExecuteNonQuery(); Console.WriteLine("Filling table `iso3166_1_numeric`"); - dbCmd.CommandText = V16.Iso3166NumericValues; + dbCmd.CommandText = V17.Iso3166NumericValues; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `companies`"); - dbCmd.CommandText = V16.CompaniesForeignKeys; + dbCmd.CommandText = V17.CompaniesForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `machines`"); - dbCmd.CommandText = V16.MachinesForeignKeys; + dbCmd.CommandText = V17.MachinesForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `company_logos`"); - dbCmd.CommandText = V16.CompanyLogos; + dbCmd.CommandText = V17.CompanyLogos; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `company_descriptions`"); - dbCmd.CommandText = V16.CompanyDescriptions; + dbCmd.CommandText = V17.CompanyDescriptions; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `processors_by_machine`"); - dbCmd.CommandText = V16.ProcessorsByMachine; + dbCmd.CommandText = V17.ProcessorsByMachine; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `gpus_by_machine`"); - dbCmd.CommandText = V16.GpusByMachine; + dbCmd.CommandText = V17.GpusByMachine; + dbCmd.ExecuteNonQuery(); + + Console.WriteLine("Creating table `sound_by_machine`"); + dbCmd.CommandText = V17.SoundByMachine; dbCmd.ExecuteNonQuery(); return true; diff --git a/Cicm.Database/Operations/Machine.cs b/Cicm.Database/Operations/Machine.cs index 09b67ff5..fce34edd 100644 --- a/Cicm.Database/Operations/Machine.cs +++ b/Cicm.Database/Operations/Machine.cs @@ -214,10 +214,9 @@ namespace Cicm.Database dbcmd.Transaction = trans; const string SQL = - "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, @vram, @colors, @res, @sound_synth, @music_synth, " + - "@sound_channels, @music_channels, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, @cap2, @type)"; + "INSERT INTO machines (company, year, model, ram, rom, vram, colors, res, hdd1, hdd2, hdd3, disk1, " + + "cap1, disk2, cap2, type) VALUES (@company, @year, @model, @ram, @rom, @vram, @colors, @res, @hdd1, " + + "@hdd2, @hdd3, @disk1, @cap1, @disk2, @cap2, @type)"; dbcmd.CommandText = SQL; @@ -251,10 +250,8 @@ namespace Cicm.Database string sql = "UPDATE machines SET company = @company, year = @year, model = @model, ram = @ram, rom = @rom, " + - "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 " + + "vram = @vram, colors = @colors, res = @res, hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, " + + "cap1 = @cap1, disk2 = @disk2, cap2 = @cap2, type = @type " + $"WHERE id = {entry.Id}"; dbcmd.CommandText = sql; @@ -304,7 +301,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(); @@ -312,10 +309,6 @@ namespace Cicm.Database IDbDataParameter param14 = dbcmd.CreateParameter(); IDbDataParameter param15 = dbcmd.CreateParameter(); IDbDataParameter param16 = dbcmd.CreateParameter(); - IDbDataParameter param17 = dbcmd.CreateParameter(); - IDbDataParameter param18 = dbcmd.CreateParameter(); - IDbDataParameter param19 = dbcmd.CreateParameter(); - IDbDataParameter param20 = dbcmd.CreateParameter(); param1.ParameterName = "@company"; param2.ParameterName = "@year"; @@ -325,18 +318,14 @@ namespace Cicm.Database 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"; - param18.ParameterName = "@disk2"; - param19.ParameterName = "@cap2"; - param20.ParameterName = "@type"; + param9.ParameterName = "@hdd1"; + param10.ParameterName = "@hdd2"; + param11.ParameterName = "@hdd3"; + param12.ParameterName = "@disk1"; + param13.ParameterName = "@cap1"; + param14.ParameterName = "@disk2"; + param15.ParameterName = "@cap2"; + param16.ParameterName = "@type"; param1.DbType = DbType.Int32; param2.DbType = DbType.Int32; @@ -346,18 +335,14 @@ namespace Cicm.Database param6.DbType = DbType.Int32; param7.DbType = DbType.Int32; param8.DbType = DbType.String; - param9.DbType = DbType.Int32; + param9.DbType = DbType.Int32; param10.DbType = DbType.Int32; param11.DbType = DbType.Int32; param12.DbType = DbType.Int32; - param13.DbType = DbType.Int32; + param13.DbType = DbType.String; param14.DbType = DbType.Int32; - param15.DbType = DbType.Int32; + param15.DbType = DbType.String; param16.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; @@ -367,18 +352,14 @@ namespace Cicm.Database 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; + param9.Value = entry.Hdd1; + param10.Value = entry.Hdd2; + param11.Value = entry.Hdd3; + param12.Value = entry.Disk1; + param13.Value = entry.Cap1; + param14.Value = entry.Disk2; + param15.Value = entry.Cap2; + param16.Value = entry.Type; dbcmd.Parameters.Add(param1); dbcmd.Parameters.Add(param2); @@ -396,10 +377,6 @@ namespace Cicm.Database dbcmd.Parameters.Add(param14); dbcmd.Parameters.Add(param15); dbcmd.Parameters.Add(param16); - dbcmd.Parameters.Add(param17); - dbcmd.Parameters.Add(param18); - dbcmd.Parameters.Add(param19); - dbcmd.Parameters.Add(param20); return dbcmd; } @@ -412,27 +389,23 @@ namespace Cicm.Database { Machine entry = new Machine { - Id = (int)dataRow["id"], - Company = (int)dataRow["company"], - Year = (int)dataRow["year"], - Model = (string)dataRow["model"], - Ram = (int)dataRow["ram"], - Rom = (int)dataRow["rom"], - Vram = (int)dataRow["vram"], - Colors = (int)dataRow["colors"], - Resolution = (string)dataRow["res"], - SoundSynth = (int)dataRow["sound_synth"], - MusicSynth = (int)dataRow["music_synth"], - SoundChannels = (int)dataRow["sound_channels"], - MusicChannels = (int)dataRow["music_channels"], - Hdd1 = (int)dataRow["hdd1"], - Hdd2 = dataRow["hdd2"] == DBNull.Value ? 0 : (int)dataRow["hdd2"], - Hdd3 = dataRow["hdd3"] == DBNull.Value ? 0 : (int)dataRow["hdd3"], - Disk1 = (int)dataRow["disk1"], - Cap1 = (string)dataRow["cap1"], - Disk2 = dataRow["disk2"] == DBNull.Value ? 0 : (int)dataRow["disk2"], - Cap2 = dataRow["cap2"] == DBNull.Value ? null : (string)dataRow["cap2"], - Type = (MachineType)dataRow["type"] + Id = (int)dataRow["id"], + Company = (int)dataRow["company"], + Year = (int)dataRow["year"], + Model = (string)dataRow["model"], + Ram = (int)dataRow["ram"], + Rom = (int)dataRow["rom"], + Vram = (int)dataRow["vram"], + Colors = (int)dataRow["colors"], + Resolution = (string)dataRow["res"], + Hdd1 = (int)dataRow["hdd1"], + Hdd2 = dataRow["hdd2"] == DBNull.Value ? 0 : (int)dataRow["hdd2"], + Hdd3 = dataRow["hdd3"] == DBNull.Value ? 0 : (int)dataRow["hdd3"], + Disk1 = (int)dataRow["disk1"], + Cap1 = (string)dataRow["cap1"], + Disk2 = dataRow["disk2"] == DBNull.Value ? 0 : (int)dataRow["disk2"], + Cap2 = dataRow["cap2"] == DBNull.Value ? null : (string)dataRow["cap2"], + Type = (MachineType)dataRow["type"] }; entries.Add(entry); diff --git a/Cicm.Database/Operations/Operations.cs b/Cicm.Database/Operations/Operations.cs index 92d120df..48535df7 100644 --- a/Cicm.Database/Operations/Operations.cs +++ b/Cicm.Database/Operations/Operations.cs @@ -35,11 +35,14 @@ namespace Cicm.Database public partial class Operations { /// Last known database version - const int DB_VERSION = 16; + const int DB_VERSION = 17; /// 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). - public const int DB_FRAMEBUFFER = -2; + /// + /// This value indicates there's no processing unit, but a direct memory connection (a framebuffer or sound + /// buffer). + /// + public const int DB_SOFTWARE = -2; readonly IDbConnection dbCon; readonly IDbCore dbCore; diff --git a/Cicm.Database/Operations/SoundByMachine.cs b/Cicm.Database/Operations/SoundByMachine.cs new file mode 100644 index 00000000..c9446b88 --- /dev/null +++ b/Cicm.Database/Operations/SoundByMachine.cs @@ -0,0 +1,149 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : SoundByMachine.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Contains operations to manage sound. +// +// --[ 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 sound in machine + /// + /// All CPUs + /// true if is correct, false otherwise + public bool GetSoundsByMachines(out List entries, int machineId) + { + #if DEBUG + Console.WriteLine("Getting all sound synths for machine {0}...", machineId); + #endif + + try + { + string sql = $"SELECT * FROM sound_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 = SoundByMachinesFromDataTable(dataSet.Tables[0]); + + return true; + } + catch(Exception ex) + { + Console.WriteLine("Error getting sound 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 GetMachinesBySound(out List entries, int gpuId) + { + #if DEBUG + Console.WriteLine("Getting all machines with sound synth {0}...", gpuId); + #endif + + try + { + string sql = $"SELECT * FROM sound_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 = SoundByMachinesFromDataTable(dataSet.Tables[0]); + + return true; + } + catch(Exception ex) + { + Console.WriteLine("Error getting machines by sound synth."); + Console.WriteLine(ex); + entries = null; + return false; + } + } + + IDbCommand GetCommandSoundByMachine(SoundByMachine entry) + { + IDbCommand dbcmd = dbCon.CreateCommand(); + + IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param2 = dbcmd.CreateParameter(); + + param1.ParameterName = "@sound_synth"; + param2.ParameterName = "@machine"; + + param1.DbType = DbType.Int32; + param2.DbType = DbType.Int32; + + param1.Value = entry.SoundSynth; + param2.Value = entry.Machine; + + dbcmd.Parameters.Add(param1); + + return dbcmd; + } + + static List SoundByMachinesFromDataTable(DataTable dataTable) + { + List entries = new List(); + + foreach(DataRow dataRow in dataTable.Rows) + { + SoundByMachine entry = new SoundByMachine + { + Machine = (int)dataRow["machine"], + SoundSynth = (int)dataRow["sound_synth"] + }; + + entries.Add(entry); + } + + return entries; + } + } +} \ No newline at end of file diff --git a/Cicm.Database/Operations/SoundSynth.cs b/Cicm.Database/Operations/SoundSynth.cs index 23812bab..ceb4ce33 100644 --- a/Cicm.Database/Operations/SoundSynth.cs +++ b/Cicm.Database/Operations/SoundSynth.cs @@ -32,7 +32,6 @@ using System; using System.Collections.Generic; using System.Data; using Cicm.Database.Schemas; -using Console = System.Console; namespace Cicm.Database { @@ -178,7 +177,9 @@ namespace Cicm.Database IDbTransaction trans = dbCon.BeginTransaction(); dbcmd.Transaction = trans; - const string SQL = "INSERT INTO sound_synths (name)" + " VALUES (@name)"; + const string SQL = "INSERT INTO sound_synths (name, company, model_code, introduced, voices, frequency, " + + "depth, square_wave, white_noise, type) VALUES (@name, @company, @model_code, " + + "@introduced, @voices, @frequency, @depth, @square_wave, @white_noise, @type)"; dbcmd.CommandText = SQL; @@ -210,7 +211,10 @@ namespace Cicm.Database IDbTransaction trans = dbCon.BeginTransaction(); dbcmd.Transaction = trans; - string sql = "UPDATE sound_synths SET name = @name " + $"WHERE id = {entry.Id}"; + string sql = "UPDATE sound_synths SET name = @name, company = @company, model_code = @model_code, " + + "introduced = @introduced, voices = @voices, frequency = @frequency, depth = @depth, " + + "square_wave = @square_wave, white_noise = @white_noise, type = @type, " + + $"WHERE id = {entry.Id}"; dbcmd.CommandText = sql; @@ -251,26 +255,86 @@ namespace Cicm.Database { IDbCommand dbcmd = dbCon.CreateCommand(); - IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param2 = dbcmd.CreateParameter(); + IDbDataParameter param3 = dbcmd.CreateParameter(); + IDbDataParameter param4 = dbcmd.CreateParameter(); + IDbDataParameter param5 = dbcmd.CreateParameter(); + IDbDataParameter param6 = dbcmd.CreateParameter(); + IDbDataParameter param7 = dbcmd.CreateParameter(); + IDbDataParameter param8 = dbcmd.CreateParameter(); + IDbDataParameter param9 = dbcmd.CreateParameter(); + IDbDataParameter param10 = dbcmd.CreateParameter(); - param1.ParameterName = "@name"; + param1.ParameterName = "@name"; + param2.ParameterName = "@company"; + param3.ParameterName = "@model_code"; + param4.ParameterName = "@introduced"; + param5.ParameterName = "@voices"; + param6.ParameterName = "@frequency"; + param7.ParameterName = "@depth"; + param8.ParameterName = "@square_wave"; + param9.ParameterName = "@white_noise"; + param10.ParameterName = "@type"; - param1.DbType = DbType.String; + param1.DbType = DbType.String; + param2.DbType = DbType.Int32; + param3.DbType = DbType.String; + param4.DbType = DbType.DateTime; + param5.DbType = DbType.Int32; + param6.DbType = DbType.Double; + param7.DbType = DbType.Int32; + param8.DbType = DbType.Int32; + param9.DbType = DbType.Int32; + param10.DbType = DbType.Int32; - param1.Value = entry.Name; + param1.Value = entry.Name; + param2.Value = entry.Company?.Id; + param3.Value = entry.ModelCode; + param4.Value = entry.Introduced == DateTime.MinValue ? (object)null : entry.Introduced; + param5.Value = entry.Voices == 0 ? (object)null : entry.Voices; + param6.Value = entry.Frequency <= 0 ? (object)null : entry.Frequency; + param7.Value = entry.Depth == 0 ? (object)null : entry.Depth; + param8.Value = entry.SquareWave == 0 ? (object)null : entry.SquareWave; + param9.Value = entry.WhiteNoise == 0 ? (object)null : entry.WhiteNoise; + param10.Value = entry.Type == 0 ? (object)null : entry.Type; dbcmd.Parameters.Add(param1); + dbcmd.Parameters.Add(param2); + dbcmd.Parameters.Add(param3); + dbcmd.Parameters.Add(param4); + dbcmd.Parameters.Add(param5); + dbcmd.Parameters.Add(param6); + dbcmd.Parameters.Add(param7); + dbcmd.Parameters.Add(param8); + dbcmd.Parameters.Add(param9); + dbcmd.Parameters.Add(param10); return dbcmd; } - static List SoundSynthFromDataTable(DataTable dataTable) + List SoundSynthFromDataTable(DataTable dataTable) { List entries = new List(); foreach(DataRow dataRow in dataTable.Rows) { - SoundSynth entry = new SoundSynth {Id = (int)dataRow["id"], Name = (string)dataRow["name"]}; + SoundSynth entry = new SoundSynth + { + Id = (int)dataRow["id"], + Name = (string)dataRow["name"], + ModelCode = dataRow["model_code"] == DBNull.Value ? null : (string)dataRow["model_code"], + Voices = dataRow["voices"] == DBNull.Value ? 0 : (int)dataRow["voices"], + Frequency = dataRow["frequency"] == DBNull.Value ? 0 : (double)dataRow["frequency"], + Depth = dataRow["depth"] == DBNull.Value ? 0 : (int)dataRow["depth"], + SquareWave = dataRow["square_wave"] == DBNull.Value ? 0 : (int)dataRow["square_wave"], + WhiteNoise = dataRow["white_noise"] == DBNull.Value ? 0 : (int)dataRow["white_noise"], + Type = dataRow["type"] == DBNull.Value ? 0 : (int)dataRow["type"], + Company = dataRow["company"] == DBNull.Value ? null : GetCompany((int)dataRow["company"]), + Introduced = dataRow["introduced"] == DBNull.Value + ? DateTime.MinValue + : Convert.ToDateTime(dataRow["introduced"]) + }; entries.Add(entry); } diff --git a/Cicm.Database/Operations/Update.cs b/Cicm.Database/Operations/Update.cs index 0fc709dc..a672665f 100644 --- a/Cicm.Database/Operations/Update.cs +++ b/Cicm.Database/Operations/Update.cs @@ -149,6 +149,11 @@ namespace Cicm.Database UpdateDatabaseToV16(); break; } + case 16: + { + UpdateDatabaseToV17(); + break; + } } OptimizeDatabase(); @@ -1063,7 +1068,7 @@ namespace Cicm.Database trans = dbCon.BeginTransaction(); dbCmd.Transaction = trans; dbCmd.CommandText = $"INSERT INTO `gpus` (`id`, `name`) VALUES ({DB_NONE}, 'DB_NONE');\n" + - $"INSERT INTO `gpus` (`id`, `name`) VALUES ({DB_FRAMEBUFFER}, 'DB_FRAMEBUFFER');"; + $"INSERT INTO `gpus` (`id`, `name`) VALUES ({DB_SOFTWARE}, 'DB_FRAMEBUFFER');"; dbCmd.ExecuteNonQuery(); trans.Commit(); dbCmd.Dispose(); @@ -1074,7 +1079,7 @@ namespace Cicm.Database dbCmd.Transaction = trans; dbCmd.CommandText = $"UPDATE `computers` SET `gpu` = {DB_NONE} WHERE `gpu` = 1;\n" + "UPDATE `computers` SET `gpu` = NULL WHERE `gpu` = 2;\n" + - $"UPDATE `computers` SET `gpu` = {DB_FRAMEBUFFER} WHERE `gpu` = 3;"; + $"UPDATE `computers` SET `gpu` = {DB_SOFTWARE} WHERE `gpu` = 3;"; dbCmd.ExecuteNonQuery(); trans.Commit(); dbCmd.Dispose(); @@ -1085,7 +1090,7 @@ namespace Cicm.Database dbCmd.Transaction = trans; dbCmd.CommandText = $"UPDATE `consoles` SET `gpu` = {DB_NONE} WHERE `gpu` = 1;\n" + "UPDATE `consoles` SET `gpu` = NULL WHERE `gpu` = 2;\n" + - $"UPDATE `consoles` SET `gpu` = {DB_FRAMEBUFFER} WHERE `gpu` = 3;"; + $"UPDATE `consoles` SET `gpu` = {DB_SOFTWARE} WHERE `gpu` = 3;"; dbCmd.ExecuteNonQuery(); trans.Commit(); dbCmd.Dispose(); @@ -1694,7 +1699,7 @@ namespace Cicm.Database void UpdateDatabaseToV16() { - Console.WriteLine("Updating database to version 15"); + Console.WriteLine("Updating database to version 16"); Console.WriteLine("Creating table `gpus_by_machine`"); IDbCommand dbCmd = dbCon.CreateCommand(); @@ -1729,8 +1734,7 @@ namespace Cicm.Database param1.Value = (int)dataRow["id"]; - const string SQL = - "INSERT INTO gpus_by_machine (machine, gpu) VALUES (@machine, @gpu)"; + const string SQL = "INSERT INTO gpus_by_machine (machine, gpu) VALUES (@machine, @gpu)"; dbcmd.Parameters.Add(param1); dbcmd.Parameters.Add(param2); @@ -1770,6 +1774,134 @@ namespace Cicm.Database dbCmd.Dispose(); } + void UpdateDatabaseToV17() + { + Console.WriteLine("Updating database to version 17"); + + Console.WriteLine("Creating table `sound_by_machine`"); + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbTransaction trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = V17.SoundByMachine; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Adding new special items to table `sound_synths`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = $"INSERT INTO `sound_synths` (`id`, `name`) VALUES ({DB_SOFTWARE}, 'DB_SOFTWARE');"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Changing sound and music synths in machine from 27 to {0}", DB_SOFTWARE); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = $"UPDATE `machines` SET sound_synth = {DB_SOFTWARE} WHERE sound_synth = 27;\n" + + $"UPDATE `machines` SET music_synth = {DB_SOFTWARE} WHERE music_synth = 27;"; + 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 = "@sound_synth"; + + param1.DbType = DbType.Int32; + param2.DbType = DbType.Int32; + + param1.Value = (int)dataRow["id"]; + + const string SQL = + "INSERT INTO sound_by_machine (machine, sound_synth) VALUES (@machine, @sound_synth)"; + + dbcmd.Parameters.Add(param1); + dbcmd.Parameters.Add(param2); + + if(dataRow["sound_synth"] != DBNull.Value && (int)dataRow["sound_synth"] != 1 && + (int)dataRow["sound_synth"] != 2) + { + param2.Value = (int)dataRow["sound_synth"]; + + trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + Console.WriteLine("Adding sound {0} to machine {1}", (int)param2.Value, (int)param1.Value); + + dbcmd.CommandText = SQL; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + } + + if(dataRow["music_synth"] != DBNull.Value && (int)dataRow["music_synth"] != 1 && + (int)dataRow["music_synth"] != 2) + { + param2.Value = (int)dataRow["music_synth"]; + + trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + Console.WriteLine("Adding sound {0} to machine {1}", (int)param2.Value, (int)param1.Value); + + dbcmd.CommandText = SQL; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + } + + dbcmd.Dispose(); + } + + Console.WriteLine("Removing sound columns from table `machines`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = "ALTER TABLE `machines` DROP FOREIGN KEY `fk_machines_sound_synth`;\n" + + "ALTER TABLE `machines` DROP FOREIGN KEY `fk_machines_music_synth`;\n" + + "ALTER TABLE `machines` DROP COLUMN `sound_channels`;\n" + + "ALTER TABLE `machines` DROP COLUMN `music_channels`;\n" + + "ALTER TABLE `machines` DROP COLUMN `sound_synth`;\n" + + "ALTER TABLE `machines` DROP COLUMN `music_synth`;"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Removing old sound items `sound_synths`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = "DELETE FROM sound_synths WHERE id = 1;\n" + + "DELETE FROM sound_synths WHERE id = 2;\n" + "DELETE FROM sound_synths WHERE id = 27;"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Setting new database version to 17..."); + dbCmd = dbCon.CreateCommand(); + dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('17')"; + dbCmd.ExecuteNonQuery(); + dbCmd.Dispose(); + } + void OptimizeDatabase() { IDbCommand dbCmd = dbCon.CreateCommand(); diff --git a/Cicm.Database/Schemas/Machine.cs b/Cicm.Database/Schemas/Machine.cs index 06836de4..6f468f01 100644 --- a/Cicm.Database/Schemas/Machine.cs +++ b/Cicm.Database/Schemas/Machine.cs @@ -55,20 +55,12 @@ namespace Cicm.Database.Schemas public int Id; /// Model name public string Model; - /// Audio channels supported by the MPU - public int MusicChannels; - /// ID of MPU - public int MusicSynth; /// Size in kibibytes of program RAM public int Ram; /// Resolution in WxH pixels public string Resolution; /// Size in kibibytes of firmware public int Rom; - /// Audio channels supported by the DSP - public int SoundChannels; - /// ID of DSP - public int SoundSynth; /// Machine type public MachineType Type; /// Size in kibibytes for video RAM diff --git a/Cicm.Database/Schemas/SoundByMachine.cs b/Cicm.Database/Schemas/SoundByMachine.cs new file mode 100644 index 00000000..cea55662 --- /dev/null +++ b/Cicm.Database/Schemas/SoundByMachine.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 SoundByMachine + { + /// Machine ID + public int Machine; + /// Sound synth ID + public int SoundSynth; + } +} \ No newline at end of file diff --git a/Cicm.Database/Schemas/SoundSynth.cs b/Cicm.Database/Schemas/SoundSynth.cs index 07a5e103..04236a45 100644 --- a/Cicm.Database/Schemas/SoundSynth.cs +++ b/Cicm.Database/Schemas/SoundSynth.cs @@ -28,14 +28,34 @@ // Copyright © 2003-2018 Natalia Portillo *******************************************************************************/ +using System; + namespace Cicm.Database.Schemas { /// Sound synthetizer public class SoundSynth { + /// Company + public Company Company; + /// Sample rate in bits of the generate sound + public int Depth; + /// Frequency in Hz of the generated sound + public double Frequency; /// ID public int Id; + /// Datetime of introduction + public DateTime Introduced; + /// Model/SKU code + public string ModelCode; /// Name public string Name; + /// Simultaneous square wave generators + public int SquareWave; + /// Type of sound synthetizer + public int Type; + /// Simultaneous voices that can be generated + public int Voices; + /// Simultaneous white noise generators + public int WhiteNoise; } } \ No newline at end of file diff --git a/Cicm.Database/Schemas/Sql/V12.cs b/Cicm.Database/Schemas/Sql/V12.cs index 3bb551f2..c670a1a2 100644 --- a/Cicm.Database/Schemas/Sql/V12.cs +++ b/Cicm.Database/Schemas/Sql/V12.cs @@ -168,7 +168,7 @@ namespace Cicm.Database.Schemas.Sql public static readonly string Gpus = V11.Gpus + "\n" + $"INSERT INTO `gpus` (`id`, `name`) VALUES ({Operations.DB_NONE}, `DB_NONE`);\n" + - $"INSERT INTO `gpus` (`id`, `name`) VALUES ({Operations.DB_FRAMEBUFFER}, `DB_FRAMEBUFFER`);"; + $"INSERT INTO `gpus` (`id`, `name`) VALUES ({Operations.DB_SOFTWARE}, `DB_FRAMEBUFFER`);"; public static readonly string Logs = V11.Logs; diff --git a/Cicm.Database/Schemas/Sql/V17.cs b/Cicm.Database/Schemas/Sql/V17.cs new file mode 100644 index 00000000..c9d5aa22 --- /dev/null +++ b/Cicm.Database/Schemas/Sql/V17.cs @@ -0,0 +1,135 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : V17.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 V17 + { + public static readonly string Admins = V16.Admins; + + public static readonly string BrowserTests = V16.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" + + "INSERT INTO cicm_db (version) VALUES ('17');"; + + public static readonly string Companies = V16.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" + + "`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_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 = V16.DiskFormats; + + public static readonly string Forbidden = V16.Forbidden; + + public static readonly string Gpus = V16.Gpus; + + public static readonly string Logs = V16.Logs; + + public static readonly string MoneyDonations = V16.MoneyDonations; + + public static readonly string News = V16.News; + + public static readonly string OwnedComputers = V16.OwnedComputers; + + public static readonly string OwnedConsoles = V16.OwnedConsoles; + + public static readonly string Processors = V16.Processors; + + public static readonly string SoundSynths = V16.SoundSynths; + + public static readonly string MachinesForeignKeys = V16.MachinesForeignKeys; + + public static readonly string Iso3166Numeric = V16.Iso3166Numeric; + + public static readonly string Iso3166NumericValues = V16.Iso3166NumericValues; + + public static readonly string CompaniesForeignKeys = V16.CompaniesForeignKeys; + + public static readonly string CompanyLogos = V16.CompanyLogos; + + public static readonly string CompanyDescriptions = V16.CompanyDescriptions; + + public static readonly string InstructionSets = V16.InstructionSets; + + public static readonly string InstructionSetExtensions = V16.InstructionSetExtensions; + + public static readonly string InstructionSetExtensionsByProcessor = V16.InstructionSetExtensionsByProcessor; + + public static readonly string ProcessorsByMachine = V16.ProcessorsByMachine; + + public static readonly string GpusByMachine = V16.GpusByMachine; + + public static readonly string SoundByMachine = + "CREATE TABLE `sound_by_machine` (\n" + + "`sound_synth` INT NOT NULL, \n" + + "`machine` INT NOT NULL,\n" + + "KEY `idx_sound_by_machine_sound_synth` (`sound_synth`),\n" + + "KEY `idx_sound_by_machine_machine` (`machine`),\n" + + "CONSTRAINT `fk_sound_by_machine_machine` FOREIGN KEY (`machine`) REFERENCES `machines` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,\n" + + "CONSTRAINT `fk_sound_by_machine_sound_synth` FOREIGN KEY (`sound_synth`) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE ON DELETE CASCADE);"; + } +} \ No newline at end of file diff --git a/cicm_web/Models/Machine.cs b/cicm_web/Models/Machine.cs index 9db3575c..01a1b755 100644 --- a/cicm_web/Models/Machine.cs +++ b/cicm_web/Models/Machine.cs @@ -43,20 +43,17 @@ namespace cicm_web.Models public Company Company; public DiskFormat Disk1; public DiskFormat Disk2; - public GpuByMachine[] Gpus; + public GpuByMachine[] Gpus; public DiskFormat Hdd1; public DiskFormat Hdd2; public DiskFormat Hdd3; public int Id; public string Model; - public int MusicChannels; - public SoundSynth MusicSynth; public ProcessorByMachine[] Processors; public int Ram; public string Resolution; public int Rom; - public int SoundChannels; - public SoundSynth SoundSynth; + public SoundByMachine[] SoundSynths; public MachineType Type; public int Vram; public int Year; @@ -92,21 +89,22 @@ namespace cicm_web.Models { Machine item = new Machine { - Colors = dbItem.Colors, - Company = Company.GetItem(dbItem.Company), + Colors = dbItem.Colors, + Company = Company.GetItem(dbItem.Company), Gpus = GpuByMachine.GetAllItems(dbItem.Id), - Hdd1 = DiskFormat.GetItem(dbItem.Hdd1), - Hdd2 = DiskFormat.GetItem(dbItem.Hdd2), - Hdd3 = DiskFormat.GetItem(dbItem.Hdd3), - Id = dbItem.Id, - Model = dbItem.Model, - Ram = dbItem.Ram, - Resolution = dbItem.Resolution, - Rom = dbItem.Rom, - Vram = dbItem.Vram, - Year = dbItem.Year, - Type = dbItem.Type, - Processors = ProcessorByMachine.GetAllItems(dbItem.Id) + Hdd1 = DiskFormat.GetItem(dbItem.Hdd1), + Hdd2 = DiskFormat.GetItem(dbItem.Hdd2), + Hdd3 = DiskFormat.GetItem(dbItem.Hdd3), + Id = dbItem.Id, + Model = dbItem.Model, + Ram = dbItem.Ram, + Resolution = dbItem.Resolution, + Rom = dbItem.Rom, + Vram = dbItem.Vram, + Year = dbItem.Year, + Type = dbItem.Type, + Processors = ProcessorByMachine.GetAllItems(dbItem.Id), + SoundSynths = SoundByMachine.GetAllItems(dbItem.Id) }; if(dbItem.Disk1 > 0) @@ -121,18 +119,6 @@ namespace cicm_web.Models item.Disk2 = DiskFormat.GetItem(dbItem.Disk2); } - if(dbItem.MusicSynth > 0) - { - item.MusicSynth = SoundSynth.GetItem(dbItem.MusicSynth); - item.MusicChannels = dbItem.MusicChannels; - } - - if(dbItem.SoundSynth > 0) - { - item.SoundSynth = SoundSynth.GetItem(dbItem.SoundSynth); - item.SoundChannels = dbItem.SoundChannels; - } - return item; } } diff --git a/cicm_web/Models/SoundByMachine.cs b/cicm_web/Models/SoundByMachine.cs new file mode 100644 index 00000000..3ebcfd39 --- /dev/null +++ b/cicm_web/Models/SoundByMachine.cs @@ -0,0 +1,54 @@ +/****************************************************************************** +// 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 SoundByMachine + { + public SoundSynth SoundSynth; + + public static SoundByMachine[] GetAllItems(int machineId) + { + List dbItems = null; + bool? result = + Program.Database?.Operations.GetSoundsByMachines(out dbItems, machineId); + if(result == null || result.Value == false || dbItems == null) return null; + + List items = new List(); + + foreach(Cicm.Database.Schemas.SoundByMachine dbItem in dbItems) + items.Add(new SoundByMachine {SoundSynth = SoundSynth.GetItem(dbItem.SoundSynth)}); + + return items.ToArray(); + } + } +} \ No newline at end of file diff --git a/cicm_web/Models/SoundSynth.cs b/cicm_web/Models/SoundSynth.cs index 31ff84a3..5b2facca 100644 --- a/cicm_web/Models/SoundSynth.cs +++ b/cicm_web/Models/SoundSynth.cs @@ -28,19 +28,44 @@ // Copyright © 2003-2018 Natalia Portillo *******************************************************************************/ +using System; using System.Collections.Generic; namespace cicm_web.Models { public class SoundSynth { - public int Id; - public string Name; + public Company Company; + public int Depth; + public double Frequency; + public int Id; + public DateTime Introduced; + public string ModelCode; + public string Name; + public int SquareWave; + public int Type; + public int Voices; + public int WhiteNoise; public static SoundSynth GetItem(int id) { Cicm.Database.Schemas.SoundSynth dbItem = Program.Database?.Operations.GetSoundSynth(id); - return dbItem == null ? null : new SoundSynth {Name = dbItem.Name, Id = dbItem.Id}; + return dbItem == null + ? null + : new SoundSynth + { + Name = dbItem.Name, + Id = dbItem.Id, + Company = dbItem.Company == null ? null : Company.GetItem(dbItem.Company.Id), + ModelCode = dbItem.ModelCode, + Introduced = dbItem.Introduced, + Voices = dbItem.Voices, + Frequency = dbItem.Frequency, + Depth = dbItem.Depth, + SquareWave = dbItem.SquareWave, + WhiteNoise = dbItem.WhiteNoise, + Type = dbItem.Type + }; } public static SoundSynth[] GetAllItems() @@ -52,7 +77,20 @@ namespace cicm_web.Models List items = new List(); foreach(Cicm.Database.Schemas.SoundSynth dbItem in dbItems) - items.Add(new SoundSynth {Id = dbItem.Id, Name = dbItem.Name}); + items.Add(new SoundSynth + { + Name = dbItem.Name, + Id = dbItem.Id, + Company = dbItem.Company == null ? null : Company.GetItem(dbItem.Company.Id), + ModelCode = dbItem.ModelCode, + Introduced = dbItem.Introduced, + Voices = dbItem.Voices, + Frequency = dbItem.Frequency, + Depth = dbItem.Depth, + SquareWave = dbItem.SquareWave, + WhiteNoise = dbItem.WhiteNoise, + Type = dbItem.Type + }); return items.ToArray(); } diff --git a/cicm_web/Views/Machine/View.cshtml b/cicm_web/Views/Machine/View.cshtml index 66f3f460..1d48ae76 100644 --- a/cicm_web/Views/Machine/View.cshtml +++ b/cicm_web/Views/Machine/View.cshtml @@ -424,15 +424,15 @@ { @($"{Model.Gpus[i].Gpu.Name}") -
+ id="@($"gpuInfo{i}")">
@if(Model.Gpus[i].Gpu.ModelCode != null && Model.Gpus[i].Gpu.ModelCode != Model.Gpus[i].Gpu.Name) @@ -571,60 +571,160 @@ } - - - @if(Model.SoundSynth.Id > 1) - { - if(Model.SoundSynth.Id > 2) - { - if(Model.SoundChannels > 0) - { - - } - else - { - - } - } - else - { - - } - } - else - { } - - - - @if(Model.MusicSynth.Id > 1) - { - if(Model.MusicSynth.Id > 2) - { - if(Model.MusicChannels > 0) - { - - } - else - { - - } - } - else - { - - } - } - else - { } - +@if(Model.SoundSynths != null && Model.SoundSynths.Length > 0) +{ + + + + +} @if(Model.Hdd1 != null && Model.Hdd1.Id > 0 && Model.Hdd1.Id != 30) { diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 6fd1a965..55cdc653 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.0 - 3.0.99.207 + 3.0.99.209 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website
Unknown data
-
- Sound processor -
-
@Model.SoundSynth.Name (@Model.SoundChannels channels)@Model.SoundSynth.NameUnknown dataNone
-
- Music synthetizer -
-
@Model.MusicSynth.Name (@Model.MusicChannels channels)@Model.MusicSynth.NameUnknown dataNone
+
+ Sound synthetizers +
+
+ + @for(int i = 0; i < Model.SoundSynths.Length; i++) + { + if(Model.SoundSynths[i] != null) + { + if(Model.SoundSynths[i].SoundSynth.Id == -2) + { + + } + else + { + + } + } + else + { + + } + } +
+ Software + +
+
+ This computer directly sends data to a DAC or similar connected to the audio output. +
+
+
+ @($"{Model.Gpus[i].Gpu.Name}") + +
+
+ + @if(Model.SoundSynths[i].SoundSynth.ModelCode != null && Model.SoundSynths[i].SoundSynth.ModelCode != Model.SoundSynths[i].SoundSynth.Name) + { + + + + + } + @if(Model.SoundSynths[i].SoundSynth.Company != null) + { + + + + + } + @if(Model.SoundSynths[i].SoundSynth.Introduced != DateTime.MinValue) + { + + + + + } + @if(Model.SoundSynths[i].SoundSynth.Voices != 0 || Model.SoundSynths[i].SoundSynth.SquareWave != 0 || Model.SoundSynths[i].SoundSynth.WhiteNoise != 0) + { + + + + + } + @if(Model.SoundSynths[i].SoundSynth.Depth != 0 || Model.SoundSynths[i].SoundSynth.Frequency > 0) + { + + + + + } + @if(Model.SoundSynths[i].SoundSynth.Type != 0) + { + + + + + } +
Model@Model.SoundSynths[i].SoundSynth.ModelCode
Manufacturer + + @Model.SoundSynths[i].SoundSynth.Company.Name +
Introduction date@($"{Model.Gpus[i].Gpu.Introduced:yyyy}")
Generators + + @if(Model.SoundSynths[i].SoundSynth.Voices != 0) + { + + + + } + @if(Model.SoundSynths[i].SoundSynth.SquareWave != 0) + { + + + + } + @if(Model.SoundSynths[i].SoundSynth.WhiteNoise != 0) + { + + + + } +
@Model.SoundSynths[i].SoundSynth.Voices voices
@Model.SoundSynths[i].SoundSynth.SquareWave square wave
@Model.SoundSynths[i].SoundSynth.WhiteNoise white noise
+
Sample rate + + @if(Model.SoundSynths[i].SoundSynth.Depth != 0 && Model.SoundSynths[i].SoundSynth.Frequency > 0) + { + + + + } + else if(Model.SoundSynths[i].SoundSynth.Depth != 0) + { + + + + } + else + { + + + + } +
@Model.SoundSynths[i].SoundSynth.Depth bits at @(Model.SoundSynths[i].SoundSynth.Frequency > 1000 ? $"{Model.SoundSynths[i].SoundSynth.Frequency / 1000}KHz" : $"{Model.SoundSynths[i].SoundSynth.Frequency}Hz")
@Model.SoundSynths[i].SoundSynth.Depth bits
@(Model.SoundSynths[i].SoundSynth.Frequency > 1000 ? $"{Model.SoundSynths[i].SoundSynth.Frequency / 1000}KHz" : $"{Model.SoundSynths[i].SoundSynth.Frequency}Hz")
+
Synthetizer type + @Model.SoundSynths[i].SoundSynth.Type +
+
+
+
Unknown data
+