diff --git a/Cicm.Database/Operations/DiskFormat.cs b/Cicm.Database/Operations/DiskFormat.cs deleted file mode 100644 index f8cedcd1..00000000 --- a/Cicm.Database/Operations/DiskFormat.cs +++ /dev/null @@ -1,282 +0,0 @@ -/****************************************************************************** -// Canary Islands Computer Museum Website -// ---------------------------------------------------------------------------- -// -// Filename : DiskFormat.cs -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Contains operations to manage disk formats. -// -// --[ 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; -using Console = System.Console; - -namespace Cicm.Database -{ - public partial class Operations - { - /// - /// Gets all disk formats - /// - /// All disk formats - /// true if is correct, false otherwise - public bool GetDiskFormats(out List entries) - { - #if DEBUG - Console.WriteLine("Getting all disk formats..."); - #endif - - try - { - const string SQL = "SELECT * from disk_formats"; - - IDbCommand dbCmd = dbCon.CreateCommand(); - IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); - dbCmd.CommandText = SQL; - DataSet dataSet = new DataSet(); - dataAdapter.SelectCommand = dbCmd; - dataAdapter.Fill(dataSet); - - entries = DiskFormatsFromDataTable(dataSet.Tables[0]); - - return true; - } - catch(Exception ex) - { - Console.WriteLine("Error getting disk formats."); - Console.WriteLine(ex); - entries = null; - return false; - } - } - - /// - /// Gets the specified number of disk formats since the specified start - /// - /// List of disk formats - /// Start of query - /// How many entries to retrieve - /// true if is correct, false otherwise - public bool GetDiskFormats(out List entries, ulong start, ulong count) - { - #if DEBUG - Console.WriteLine("Getting {0} disk formats from {1}...", count, start); - #endif - - try - { - string sql = $"SELECT * FROM disk_formats LIMIT {start}, {count}"; - - IDbCommand dbCmd = dbCon.CreateCommand(); - IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); - dbCmd.CommandText = sql; - DataSet dataSet = new DataSet(); - dataAdapter.SelectCommand = dbCmd; - dataAdapter.Fill(dataSet); - - entries = DiskFormatsFromDataTable(dataSet.Tables[0]); - - return true; - } - catch(Exception ex) - { - Console.WriteLine("Error getting disk formats."); - Console.WriteLine(ex); - entries = null; - return false; - } - } - - /// - /// Gets disk format by specified id - /// - /// Id - /// Disk format with specified id, null if not found or error - public DiskFormat GetDiskFormat(int id) - { - #if DEBUG - Console.WriteLine("Getting disk format with id {0}...", id); - #endif - - try - { - string sql = $"SELECT * from disk_formats WHERE id = '{id}'"; - - IDbCommand dbCmd = dbCon.CreateCommand(); - IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); - dbCmd.CommandText = sql; - DataSet dataSet = new DataSet(); - dataAdapter.SelectCommand = dbCmd; - dataAdapter.Fill(dataSet); - - List entries = DiskFormatsFromDataTable(dataSet.Tables[0]); - - return entries == null || entries.Count == 0 ? null : entries[0]; - } - catch(Exception ex) - { - Console.WriteLine("Error getting disk format."); - Console.WriteLine(ex); - return null; - } - } - - /// - /// Counts the number of disk formats in the database - /// - /// Entries in database - public long CountDiskFormats() - { - #if DEBUG - Console.WriteLine("Counting disk formats..."); - #endif - - IDbCommand dbcmd = dbCon.CreateCommand(); - dbcmd.CommandText = "SELECT COUNT(*) FROM disk_formats"; - object count = dbcmd.ExecuteScalar(); - dbcmd.Dispose(); - try { return Convert.ToInt64(count); } - catch { return 0; } - } - - /// - /// Adds a new disk format to the database - /// - /// Entry to add - /// ID of added entry - /// true if added correctly, false otherwise - public bool AddDiskFormat(DiskFormat entry, out long id) - { - #if DEBUG - Console.Write("Adding disk format `{0}`...", entry.Description); - #endif - - IDbCommand dbcmd = GetCommandDiskFormat(entry); - IDbTransaction trans = dbCon.BeginTransaction(); - dbcmd.Transaction = trans; - - const string SQL = "INSERT INTO disk_formats (description)" + " VALUES (@description)"; - - dbcmd.CommandText = SQL; - - dbcmd.ExecuteNonQuery(); - trans.Commit(); - dbcmd.Dispose(); - - id = dbCore.LastInsertRowId; - - #if DEBUG - Console.WriteLine(" id {0}", id); - #endif - - return true; - } - - /// - /// Updated a disk format in the database - /// - /// Updated entry - /// true if updated correctly, false otherwise - public bool UpdateDiskFormat(DiskFormat entry) - { - #if DEBUG - Console.WriteLine("Updating disk format `{0}`...", entry.Description); - #endif - - IDbCommand dbcmd = GetCommandDiskFormat(entry); - IDbTransaction trans = dbCon.BeginTransaction(); - dbcmd.Transaction = trans; - - string sql = "UPDATE disk_formats SET description = @description " + $"WHERE id = {entry.Id}"; - - dbcmd.CommandText = sql; - - dbcmd.ExecuteNonQuery(); - trans.Commit(); - dbcmd.Dispose(); - - return true; - } - - /// - /// Removes a disk format from the database - /// - /// ID of entry to remove - /// true if removed correctly, false otherwise - public bool RemoveDiskFormat(long id) - { - #if DEBUG - Console.WriteLine("Removing disk format widh id `{0}`...", id); - #endif - - IDbCommand dbcmd = dbCon.CreateCommand(); - IDbTransaction trans = dbCon.BeginTransaction(); - dbcmd.Transaction = trans; - - string sql = $"DELETE FROM disk_formats WHERE id = '{id}';"; - - dbcmd.CommandText = sql; - - dbcmd.ExecuteNonQuery(); - trans.Commit(); - dbcmd.Dispose(); - - return true; - } - - IDbCommand GetCommandDiskFormat(DiskFormat entry) - { - IDbCommand dbcmd = dbCon.CreateCommand(); - - IDbDataParameter param1 = dbcmd.CreateParameter(); - - param1.ParameterName = "@description"; - - param1.DbType = DbType.String; - - param1.Value = entry.Description; - - dbcmd.Parameters.Add(param1); - - return dbcmd; - } - - static List DiskFormatsFromDataTable(DataTable dataTable) - { - List entries = new List(); - - foreach(DataRow dataRow in dataTable.Rows) - { - DiskFormat entry = - new DiskFormat {Id = (int)dataRow["id"], Description = (string)dataRow["description"]}; - - 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 12bed6e3..368b247c 100644 --- a/Cicm.Database/Operations/Init.cs +++ b/Cicm.Database/Operations/Init.cs @@ -49,123 +49,123 @@ namespace Cicm.Database IDbCommand dbCmd = dbCon.CreateCommand(); Console.WriteLine("Creating table `admins`"); - dbCmd.CommandText = V19.Admins; + dbCmd.CommandText = V20.Admins; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `browser_tests`"); - dbCmd.CommandText = V19.BrowserTests; + dbCmd.CommandText = V20.BrowserTests; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `cicm_db`"); - dbCmd.CommandText = V19.CicmDb; + dbCmd.CommandText = V20.CicmDb; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `companies`"); - dbCmd.CommandText = V19.Companies; + dbCmd.CommandText = V20.Companies; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `machines`"); - dbCmd.CommandText = V19.Machines; - dbCmd.ExecuteNonQuery(); - - Console.WriteLine("Creating table `disk_formats`"); - dbCmd.CommandText = V19.DiskFormats; + dbCmd.CommandText = V20.Machines; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `forbidden`"); - dbCmd.CommandText = V19.Forbidden; + dbCmd.CommandText = V20.Forbidden; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `gpus`"); - dbCmd.CommandText = V19.Gpus; + dbCmd.CommandText = V20.Gpus; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `log`"); - dbCmd.CommandText = V19.Logs; + dbCmd.CommandText = V20.Logs; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `money_donations`"); - dbCmd.CommandText = V19.MoneyDonations; + dbCmd.CommandText = V20.MoneyDonations; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `news`"); - dbCmd.CommandText = V19.News; + dbCmd.CommandText = V20.News; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_computers`"); - dbCmd.CommandText = V19.OwnedComputers; + dbCmd.CommandText = V20.OwnedComputers; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_consoles`"); - dbCmd.CommandText = V19.OwnedConsoles; + dbCmd.CommandText = V20.OwnedConsoles; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_sets`"); - dbCmd.CommandText = V19.InstructionSets; + dbCmd.CommandText = V20.InstructionSets; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_set_extensions`"); - dbCmd.CommandText = V19.InstructionSetExtensions; + dbCmd.CommandText = V20.InstructionSetExtensions; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `processors`"); - dbCmd.CommandText = V19.Processors; + dbCmd.CommandText = V20.Processors; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_set_extensions_by_processor`"); - dbCmd.CommandText = V19.InstructionSetExtensionsByProcessor; + dbCmd.CommandText = V20.InstructionSetExtensionsByProcessor; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `sound_synths`"); - dbCmd.CommandText = V19.SoundSynths; + dbCmd.CommandText = V20.SoundSynths; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `iso3166_1_numeric`"); - dbCmd.CommandText = V19.Iso3166Numeric; + dbCmd.CommandText = V20.Iso3166Numeric; dbCmd.ExecuteNonQuery(); Console.WriteLine("Filling table `iso3166_1_numeric`"); - dbCmd.CommandText = V19.Iso3166NumericValues; + dbCmd.CommandText = V20.Iso3166NumericValues; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `companies`"); - dbCmd.CommandText = V19.CompaniesForeignKeys; + dbCmd.CommandText = V20.CompaniesForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `machines`"); - dbCmd.CommandText = V19.MachinesForeignKeys; + dbCmd.CommandText = V20.MachinesForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `company_logos`"); - dbCmd.CommandText = V19.CompanyLogos; + dbCmd.CommandText = V20.CompanyLogos; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `company_descriptions`"); - dbCmd.CommandText = V19.CompanyDescriptions; + dbCmd.CommandText = V20.CompanyDescriptions; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `processors_by_machine`"); - dbCmd.CommandText = V19.ProcessorsByMachine; + dbCmd.CommandText = V20.ProcessorsByMachine; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `gpus_by_machine`"); - dbCmd.CommandText = V19.GpusByMachine; + dbCmd.CommandText = V20.GpusByMachine; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `sound_by_machine`"); - dbCmd.CommandText = V19.SoundByMachine; + dbCmd.CommandText = V20.SoundByMachine; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `memory_by_machine`"); - dbCmd.CommandText = V19.MemoryByMachine; + dbCmd.CommandText = V20.MemoryByMachine; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `resolutions`"); - dbCmd.CommandText = V19.Resolutions; + dbCmd.CommandText = V20.Resolutions; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `resolutions_by_gpu`"); - dbCmd.CommandText = V19.ResolutionsByGpu; + dbCmd.CommandText = V20.ResolutionsByGpu; + dbCmd.ExecuteNonQuery(); + + Console.WriteLine("Creating table `storage_by_machine`"); + dbCmd.CommandText = V20.StorageByMachine; dbCmd.ExecuteNonQuery(); return true; diff --git a/Cicm.Database/Operations/Machine.cs b/Cicm.Database/Operations/Machine.cs index 259a4292..7f835954 100644 --- a/Cicm.Database/Operations/Machine.cs +++ b/Cicm.Database/Operations/Machine.cs @@ -214,9 +214,7 @@ namespace Cicm.Database dbcmd.Transaction = trans; const string SQL = - "INSERT INTO machines (company, year, model, colors, res, hdd1, hdd2, hdd3, disk1, cap1, disk2, cap2, " + - "type) VALUES (@company, @year, @model, @colors, @res, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, " + - "@cap2, @type)"; + "INSERT INTO machines (company, year, model, type) VALUES (@company, @year, @model, @type)"; dbcmd.CommandText = SQL; @@ -248,11 +246,8 @@ namespace Cicm.Database IDbTransaction trans = dbCon.BeginTransaction(); dbcmd.Transaction = trans; - string sql = - "UPDATE machines SET company = @company, year = @year, model = @model, colors = @colors, res = @res, " + - "hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, cap1 = @cap1, disk2 = @disk2, cap2 = @cap2, " + - "type = @type " + - $"WHERE id = {entry.Id}"; + string sql = "UPDATE machines SET company = @company, year = @year, model = @model, type = @type " + + $"WHERE id = {entry.Id}"; dbcmd.CommandText = sql; @@ -293,65 +288,30 @@ namespace Cicm.Database { IDbCommand dbcmd = dbCon.CreateCommand(); - 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(); - IDbDataParameter param11 = dbcmd.CreateParameter(); + IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param2 = dbcmd.CreateParameter(); + IDbDataParameter param3 = dbcmd.CreateParameter(); + IDbDataParameter param4 = dbcmd.CreateParameter(); - param1.ParameterName = "@company"; - param2.ParameterName = "@year"; - param3.ParameterName = "@model"; - param4.ParameterName = "@hdd1"; - param5.ParameterName = "@hdd2"; - param6.ParameterName = "@hdd3"; - param7.ParameterName = "@disk1"; - param8.ParameterName = "@cap1"; - param9.ParameterName = "@disk2"; - param10.ParameterName = "@cap2"; - param11.ParameterName = "@type"; + param1.ParameterName = "@company"; + param2.ParameterName = "@year"; + param3.ParameterName = "@model"; + param4.ParameterName = "@type"; - param1.DbType = DbType.Int32; - param2.DbType = DbType.Int32; - param3.DbType = DbType.String; - param4.DbType = DbType.Int32; - param5.DbType = DbType.Int32; - param6.DbType = DbType.Int32; - param7.DbType = DbType.Int32; - param8.DbType = DbType.String; - param9.DbType = DbType.Int32; - param10.DbType = DbType.String; - param11.DbType = DbType.Int32; + param1.DbType = DbType.Int32; + param2.DbType = DbType.Int32; + param3.DbType = DbType.String; + param4.DbType = DbType.Int32; - param1.Value = entry.Company; - param2.Value = entry.Year; - param3.Value = entry.Model; - param4.Value = entry.Hdd1; - param5.Value = entry.Hdd2; - param6.Value = entry.Hdd3; - param7.Value = entry.Disk1; - param8.Value = entry.Cap1; - param9.Value = entry.Disk2; - param10.Value = entry.Cap2; - param11.Value = entry.Type; + param1.Value = entry.Company; + param2.Value = entry.Year; + param3.Value = entry.Model; + param4.Value = 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); - dbcmd.Parameters.Add(param11); return dbcmd; } @@ -368,13 +328,6 @@ namespace Cicm.Database Company = (int)dataRow["company"], Year = (int)dataRow["year"], Model = (string)dataRow["model"], - 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"] }; diff --git a/Cicm.Database/Operations/Operations.cs b/Cicm.Database/Operations/Operations.cs index b4914631..6f62502c 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 = 19; + const int DB_VERSION = 20; /// The column with this value indicates there is no item of this type. public const int DB_NONE = -1; /// diff --git a/Cicm.Database/Operations/OwnedComputer.cs b/Cicm.Database/Operations/OwnedComputer.cs index 58766573..2fac249f 100644 --- a/Cicm.Database/Operations/OwnedComputer.cs +++ b/Cicm.Database/Operations/OwnedComputer.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 { @@ -269,10 +268,6 @@ namespace Cicm.Database IDbDataParameter param11 = dbcmd.CreateParameter(); IDbDataParameter param12 = dbcmd.CreateParameter(); IDbDataParameter param13 = dbcmd.CreateParameter(); - IDbDataParameter param14 = dbcmd.CreateParameter(); - IDbDataParameter param15 = dbcmd.CreateParameter(); - IDbDataParameter param16 = dbcmd.CreateParameter(); - IDbDataParameter param17 = dbcmd.CreateParameter(); param1.ParameterName = "@db_id"; param2.ParameterName = "@date"; @@ -287,10 +282,6 @@ namespace Cicm.Database param11.ParameterName = "@ram"; param12.ParameterName = "@vram"; param13.ParameterName = "@rigid"; - param14.ParameterName = "@disk1"; - param15.ParameterName = "@cap1"; - param16.ParameterName = "@disk2"; - param17.ParameterName = "@cap2"; param1.DbType = DbType.Int32; param2.DbType = DbType.String; @@ -305,10 +296,6 @@ namespace Cicm.Database param11.DbType = DbType.Int32; param12.DbType = DbType.Int32; param13.DbType = DbType.String; - param14.DbType = DbType.Int32; - param15.DbType = DbType.Int32; - param16.DbType = DbType.Int32; - param17.DbType = DbType.Int32; param1.Value = entry.ComputerId; param2.Value = entry.Acquired; @@ -323,10 +310,6 @@ namespace Cicm.Database param11.Value = entry.Ram; param12.Value = entry.Vram; param13.Value = entry.Rigid; - param14.Value = entry.Disk1; - param15.Value = entry.Cap1; - param16.Value = entry.Disk2; - param17.Value = entry.Cap2; dbcmd.Parameters.Add(param1); dbcmd.Parameters.Add(param2); @@ -341,10 +324,6 @@ namespace Cicm.Database dbcmd.Parameters.Add(param11); dbcmd.Parameters.Add(param12); dbcmd.Parameters.Add(param13); - dbcmd.Parameters.Add(param14); - dbcmd.Parameters.Add(param15); - dbcmd.Parameters.Add(param16); - dbcmd.Parameters.Add(param17); return dbcmd; } @@ -370,11 +349,7 @@ namespace Cicm.Database Mhz2 = (float)dataRow["mhz2"], Ram = (int)dataRow["ram"], Vram = (int)dataRow["vram"], - Rigid = (string)dataRow["rigid"], - Disk1 = (int)dataRow["disk1"], - Cap1 = (int)dataRow["cap1"], - Disk2 = (int)dataRow["disk2"], - Cap2 = (int)dataRow["cap2"] + Rigid = (string)dataRow["rigid"] }; entries.Add(entry); diff --git a/Cicm.Database/Operations/StorageByMachine.cs b/Cicm.Database/Operations/StorageByMachine.cs new file mode 100644 index 00000000..e68be245 --- /dev/null +++ b/Cicm.Database/Operations/StorageByMachine.cs @@ -0,0 +1,127 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : StorageByMachine.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Contains operations to manage storage. +// +// --[ 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 storage in machine + /// + /// All CPUs + /// true if is correct, false otherwise + public bool GetStorageByMachines(out List entries, int machineId) + { + #if DEBUG + Console.WriteLine("Getting all storage for machine {0}...", machineId); + #endif + + try + { + string sql = $"SELECT * FROM storage_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 = StorageByMachinesFromDataTable(dataSet.Tables[0]); + + return true; + } + catch(Exception ex) + { + Console.WriteLine("Error getting storage by machine."); + Console.WriteLine(ex); + entries = null; + return false; + } + } + + IDbCommand GetCommandStorageByMachine(StorageByMachine entry) + { + IDbCommand dbcmd = dbCon.CreateCommand(); + + IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param2 = dbcmd.CreateParameter(); + IDbDataParameter param3 = dbcmd.CreateParameter(); + IDbDataParameter param4 = dbcmd.CreateParameter(); + + param1.ParameterName = "@machine"; + param2.ParameterName = "@type"; + param3.ParameterName = "@interface"; + param4.ParameterName = "@capacity"; + + param1.DbType = DbType.Int32; + param2.DbType = DbType.Int32; + param3.DbType = DbType.Int32; + param4.DbType = DbType.Int64; + + param1.Value = entry.Machine; + param2.Value = entry.Type; + param3.Value = entry.Interface; + param4.Value = entry.Capacity == 0 ? (object)null : entry.Capacity; + + dbcmd.Parameters.Add(param1); + dbcmd.Parameters.Add(param2); + dbcmd.Parameters.Add(param3); + dbcmd.Parameters.Add(param4); + + return dbcmd; + } + + static List StorageByMachinesFromDataTable(DataTable dataTable) + { + List entries = new List(); + + foreach(DataRow dataRow in dataTable.Rows) + { + StorageByMachine entry = new StorageByMachine + { + Machine = (int)dataRow["machine"], + Type = (StorageType)dataRow["type"], + Interface = (StorageInterface)dataRow["interface"], + Capacity = dataRow["capacity"] == DBNull.Value ? 0 : (long)dataRow["capacity"] + }; + + entries.Add(entry); + } + + return entries; + } + } +} \ No newline at end of file diff --git a/Cicm.Database/Operations/Update.cs b/Cicm.Database/Operations/Update.cs index 8fed8bb1..3b744854 100644 --- a/Cicm.Database/Operations/Update.cs +++ b/Cicm.Database/Operations/Update.cs @@ -164,6 +164,11 @@ namespace Cicm.Database UpdateDatabaseToV19(); break; } + case 19: + { + UpdateDatabaseToV20(); + break; + } } OptimizeDatabase(); @@ -2172,6 +2177,240 @@ namespace Cicm.Database dbCmd.Dispose(); } + void UpdateDatabaseToV20() + { + Console.WriteLine("Updating database to version 20"); + + Console.WriteLine("Creating table `storage_by_machine`"); + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbTransaction trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = V20.StorageByMachine; + 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(); + IDbDataParameter param3 = dbcmd.CreateParameter(); + IDbDataParameter param4 = dbcmd.CreateParameter(); + + param1.ParameterName = "@machine"; + param2.ParameterName = "@type"; + param3.ParameterName = "@interface"; + param4.ParameterName = "@capacity"; + + param1.DbType = DbType.Int32; + param2.DbType = DbType.Int32; + param3.DbType = DbType.Int32; + param4.DbType = DbType.Int64; + + param1.Value = (int)dataRow["id"]; + + const string SQL = + "INSERT INTO `storage_by_machine` (`machine`, `type`, `interface`, `capacity`) VALUES (@machine, @type, @interface, @capacity)"; + + dbcmd.Parameters.Add(param1); + dbcmd.Parameters.Add(param2); + dbcmd.Parameters.Add(param3); + dbcmd.Parameters.Add(param4); + + foreach(string media in new[] {"hdd1", "hdd2", "hdd3", "disk1", "disk2"}) + { + if(dataRow[media] == DBNull.Value || (int)dataRow[media] == 30) continue; + + param3.Value = StorageInterface.Unknown; + + switch((int)dataRow[media]) + { + case 1: + param2.Value = StorageType.CompactFloppy; + break; + case 3: + case 5: + param2.Value = StorageType.Microfloppy; + break; + case 4: + param2.Value = StorageType.Minifloppy; + break; + case 7: + param2.Value = StorageType.CompactDisc; + break; + case 8: + param2.Value = StorageType.CompactCassette; + break; + case 9: + param2.Value = StorageType.CompactFlash; + break; + case 11: + param2.Value = StorageType.Dvd; + break; + case 12: + param2.Value = StorageType.GDROM; + break; + case 13: + param2.Value = StorageType.ZIP100; + break; + case 14: + param2.Value = StorageType.LS120; + break; + case 15: + param2.Value = StorageType.MagnetoOptical; + break; + case 17: + param2.Value = StorageType.Microdrive; + break; + case 18: + param2.Value = StorageType.MMC; + break; + case 20: + param2.Value = StorageType.SecureDigital; + break; + case 21: + param2.Value = StorageType.SmartMedia; + break; + case 23: + param2.Value = StorageType.PunchedCard; + break; + case 24: + param2.Value = StorageType.HardDisk; + param3.Value = StorageInterface.ACSI; + break; + case 25: + case 29: + param2.Value = StorageType.HardDisk; + param3.Value = StorageInterface.ATA; + break; + case 26: + param2.Value = StorageType.HardDisk; + param3.Value = StorageInterface.ESDI; + break; + case 27: + param2.Value = StorageType.HardDisk; + param3.Value = StorageInterface.FireWire; + break; + case 28: + param2.Value = StorageType.CompactFloppy; + break; + case 32: + case 35: + param2.Value = StorageType.HardDisk; + param3.Value = StorageInterface.ST506; + break; + case 33: + param2.Value = StorageType.HardDisk; + param3.Value = StorageInterface.SASI; + break; + case 34: + case 41: + param2.Value = StorageType.HardDisk; + param3.Value = StorageInterface.SCSI; + break; + case 40: + param2.Value = StorageType.Floppy; + break; + case 43: + param2.Value = StorageType.Bluray; + break; + case 44: + param2.Value = StorageType.GOD; + break; + case 45: + param2.Value = StorageType.WOD; + break; + default: + param2.Value = StorageType.Unknown; + break; + } + + param4.Value = null; + + switch(media) + { + case "disk1": + if(dataRow["cap1"] != DBNull.Value) + if(int.TryParse((string)dataRow["cap1"], out int cap)) + param4.Value = cap == 0 + ? (object)null + : (StorageType)param2.Value == StorageType.CompactCassette + ? cap + : cap * 1024; + break; + case "disk2": + if(dataRow["cap2"] != DBNull.Value) + if(int.TryParse((string)dataRow["cap2"], out int cap)) + param4.Value = cap == 0 + ? (object)null + : (StorageType)param2.Value == StorageType.CompactCassette + ? cap + : cap * 1024; + break; + } + + trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + Console.WriteLine("Adding storage type {0} with interface {1} to machine {2}", + (StorageType)param2.Value, (StorageInterface)param3.Value, (int)param1.Value); + + dbcmd.CommandText = SQL; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + } + + dbcmd.Dispose(); + } + + Console.WriteLine("Removing memory columns from table `machines`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = "ALTER TABLE `machines` DROP FOREIGN KEY `fk_machines_disk1`;\n" + + "ALTER TABLE `machines` DROP FOREIGN KEY `fk_machines_disk2`;\n" + + "ALTER TABLE `machines` DROP FOREIGN KEY `fk_machines_hdd1`;\n" + + "ALTER TABLE `machines` DROP FOREIGN KEY `fk_machines_hdd2`;\n" + + "ALTER TABLE `machines` DROP FOREIGN KEY `fk_machines_hdd3`;\n" + + "ALTER TABLE `machines` DROP COLUMN `hdd1`;\n" + + "ALTER TABLE `machines` DROP COLUMN `hdd2`;\n" + + "ALTER TABLE `machines` DROP COLUMN `hdd3`;\n" + + "ALTER TABLE `machines` DROP COLUMN `disk1`;\n" + + "ALTER TABLE `machines` DROP COLUMN `cap1`;\n" + + "ALTER TABLE `machines` DROP COLUMN `disk2`;\n" + + "ALTER TABLE `machines` DROP COLUMN `cap2`;"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Removing table `disk_formats`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = "DROP TABLE `disk_formats`;"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Setting new database version to 20..."); + dbCmd = dbCon.CreateCommand(); + dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('20')"; + dbCmd.ExecuteNonQuery(); + dbCmd.Dispose(); + } + void OptimizeDatabase() { IDbCommand dbCmd = dbCon.CreateCommand(); diff --git a/Cicm.Database/Schemas/Enums.cs b/Cicm.Database/Schemas/Enums.cs index 64d0e738..1860ca5f 100644 --- a/Cicm.Database/Schemas/Enums.cs +++ b/Cicm.Database/Schemas/Enums.cs @@ -184,4 +184,237 @@ namespace Cicm.Database.Schemas /// Unified = 10 } + + public enum StorageType + { + /// Contains an empty interface for user connection + Empty = -1, + /// Unknown + Unknown = 0, + /// Unknown magneto-optical + MagnetoOptical = 1, + /// Generic hard disk + HardDisk = 2, + /// Microdrive type hard disk + Microdrive = 3, + /// Zoned hard disk + ZonedHardDisk = 4, + /// USB flash drives + FlashDrive = 5, + /// CompactDisc + CompactDisc = 6, + /// Double-Density CompactDisc (Purple Book) + DDCD = 7, + /// 120mm, Phase-Change, 1298496 sectors, 512 bytes/sector, PD650, ECMA-240, ISO 15485 + PD650 = 8, + /// DVD + Dvd = 9, + /// DVD-RAM (cartridge only) + DVDRAM = 10, + /// HD DVD + HDDVDROM = 11, + /// Blu-ray Disc + Bluray = 12, + /// Enhanced Versatile Disc + EVD = 13, + /// Forward Versatile Disc + FVD = 14, + /// Holographic Versatile Disc + HVD = 15, + /// China Blue High Definition + CBHD = 16, + /// High Definition Versatile Multilayer Disc + HDVMD = 17, + /// Versatile Compact Disc High Density + VCDHD = 18, + /// Stacked Volumetric Optical Disc + SVOD = 19, + /// Five Dimensional disc + FDDVD = 20, + /// Pioneer LaserDisc + LD = 21, + /// Pioneer LaserDisc data + LDROM = 22, + LDROM2 = 23, + LVROM = 24, + MegaLD = 254, + /// Sony Hi-MD + HiMD = 26, + /// Sony MiniDisc + MD = 27, + MDData = 28, + MDData2 = 29, + /// 5.25", Phase-Change, 1834348 sectors, 8192 bytes/sector, Ultra Density Optical, ECMA-350, ISO 17345 + UDO = 30, + /// 5.25", Phase-Change, 3669724 sectors, 8192 bytes/sector, Ultra Density Optical 2, ECMA-380, ISO 11976 + UDO2 = 31, + PlayStationMemoryCard = 32, + PlayStationMemoryCard2 = 33, + /// Sony PlayStation game CD + PS1CD = 34, + /// Sony PlayStation 2 game CD + PS2CD = 35, + /// Sony PlayStation 2 game DVD + PS2DVD = 36, + /// Sony PlayStation 3 game DVD + PS3DVD = 37, + /// Sony PlayStation 3 game Blu-ray + PS3BD = 38, + /// Sony PlayStation 4 game Blu-ray + PS4BD = 39, + /// Sony PlayStation Portable Universal Media Disc (ECMA-365) + UMD = 40, + /// Microsoft X-box Game Disc + XGD = 41, + /// Microsoft X-box 360 Game Disc + XGD2 = 42, + /// Microsoft X-box 360 Game Disc + XGD3 = 43, + /// Microsoft X-box One Game Disc + XGD4 = 44, + /// Sega MegaCD + MEGACD = 45, + /// Sega Saturn disc + SATURNCD = 46, + /// Sega/Yamaha Gigabyte Disc + GDROM = 47, + SegaCard = 48, + /// PC-Engine / TurboGrafx cartridge + HuCard = 49, + /// PC-Engine / TurboGrafx CD + SuperCDROM2 = 50, + /// Atari Jaguar CD + JaguarCD = 51, + /// 3DO CD + ThreeDO = 52, + /// NEC PC-FX + PCFX = 53, + /// NEO-GEO CD + NeoGeoCD = 54, + /// 8" floppy + Floppy = 55, + /// 5.25" floppy + Minifloppy = 56, + /// 3.5" floppy + Microfloppy = 57, + /// 5.25", DS, ?D, ?? tracks, ?? spt, 512 bytes/sector, GCR, opposite side heads, aka Twiggy + AppleFileWare = 58, + Bernoulli = 59, + Bernoulli2 = 60, + Ditto = 61, + DittoMax = 62, + Jaz = 63, + Jaz2 = 64, + PocketZip = 65, + REV120 = 66, + REV35 = 67, + REV70 = 68, + ZIP100 = 69, + ZIP250 = 70, + ZIP750 = 71, + CompactCassette = 72, + Data8 = 73, + MiniDV = 74, + CFast = 75, + CompactFlash = 76, + CompactFlashType2 = 77, + EZ135 = 78, + EZ230 = 79, + Quest = 80, + SparQ = 81, + SQ100 = 82, + SQ200 = 83, + SQ300 = 84, + SQ310 = 85, + SQ327 = 86, + SQ400 = 87, + SQ800 = 88, + SQ1500 = 89, + SQ2000 = 90, + SyJet = 91, + FamicomGamePak = 92, + GameBoyAdvanceGamePak = 93, + GameBoyGamePak = 94, + GOD = 95, + N64DD = 96, + N64GamePak = 97, + NESGamePak = 98, + Nintendo3DSGameCard = 99, + NintendoDiskCard = 100, + NintendoDSGameCard = 101, + NintendoDSiGameCard = 102, + SNESGamePak = 103, + SNESGamePakUS = 104, + WOD = 105, + WUOD = 106, + SwitchGameCard = 107, + MemoryStick = 108, + MemoryStickDuo = 109, + MemoryStickMicro = 110, + MemoryStickPro = 111, + MemoryStickProDuo = 112, + microSD = 113, + miniSD = 114, + SecureDigital = 115, + MMC = 116, + MMCmicro = 117, + RSMMC = 118, + MMCplus = 118, + MMCmobile = 119, + eMMC = 120, + MO120 = 121, + MO90 = 122, + MO300 = 123, + MO356 = 124, + CompactFloppy = 125, + DemiDiskette = 126, + /// 3.5", 652 tracks, 2 sides, 512 bytes/sector, Floptical, ECMA-207, ISO 14169 + Floptical = 127, + HiFD = 128, + QuickDisk = 129, + UHD144 = 130, + VideoFloppy = 131, + Wafer = 132, + ZXMicrodrive = 133, + BeeCard = 134, + Borsu = 135, + DataStore = 136, + MiniCard = 137, + Orb = 138, + Orb5 = 139, + SmartMedia = 140, + xD = 141, + XQD = 142, + DataPlay = 143, + LS120 = 144, + LS240 = 145, + FD32MB = 146, + RDX = 147, + PunchedCard = 148 + } + + public enum StorageInterface + { + Unknown = 0, + ACSI = 1, + ATA = 2, + XTA = 3, + ESDI = 4, + SCSI = 5, + USB = 6, + FireWire = 7, + SASI = 8, + ST506 = 9, + IPI = 10, + SMD = 11, + SATA = 12, + SSA = 13, + DSSI = 14, + HIPPI = 15, + SAS = 16, + FC = 17, + PCIe = 18, + M2 = 19, + SataExpress = 20 + } } \ No newline at end of file diff --git a/Cicm.Database/Schemas/Machine.cs b/Cicm.Database/Schemas/Machine.cs index 1945078d..dde08e87 100644 --- a/Cicm.Database/Schemas/Machine.cs +++ b/Cicm.Database/Schemas/Machine.cs @@ -33,22 +33,8 @@ namespace Cicm.Database.Schemas /// Computer public class Machine { - /// Capacity of first removable disk format - public string Cap1; - /// Capacity of second removable disk format - public string Cap2; /// Manufacturer's company ID public int Company; - /// ID of first removable disk format - public int Disk1; - /// ID of second removable disk format - public int Disk2; - /// ID of first hard disk format - public int Hdd1; - /// ID of second hard disk format - public int Hdd2; - /// ID of third hard disk format - public int Hdd3; /// ID public int Id; /// Model name diff --git a/Cicm.Database/Schemas/OwnedComputer.cs b/Cicm.Database/Schemas/OwnedComputer.cs index 3a3a7d5d..1c5847a4 100644 --- a/Cicm.Database/Schemas/OwnedComputer.cs +++ b/Cicm.Database/Schemas/OwnedComputer.cs @@ -37,20 +37,12 @@ namespace Cicm.Database.Schemas public string Acquired; /// Box present in collection public bool Boxed; - /// Capacity of first removable disk format - public int Cap1; - /// Capacity of second removable disk format - public int Cap2; /// Computer's ID public int ComputerId; /// Primary CPU public int Cpu1; /// Secondary CPU public int Cpu2; - /// ID of first removable disk format - public int Disk1; - /// ID of second removable disk format - public int Disk2; /// ID public int Id; /// Original manuals present in collection diff --git a/Cicm.Database/Schemas/Sql/V20.cs b/Cicm.Database/Schemas/Sql/V20.cs new file mode 100644 index 00000000..8ff60757 --- /dev/null +++ b/Cicm.Database/Schemas/Sql/V20.cs @@ -0,0 +1,120 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : V20.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 V20 + { + public static readonly string Admins = V19.Admins; + + public static readonly string BrowserTests = V19.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 ('20');"; + + public static readonly string Companies = V19.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" + + "`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_type` (`type`));"; + + public static readonly string Forbidden = V19.Forbidden; + + public static readonly string Gpus = V19.Gpus; + + public static readonly string Logs = V19.Logs; + + public static readonly string MoneyDonations = V19.MoneyDonations; + + public static readonly string News = V19.News; + + public static readonly string OwnedComputers = V19.OwnedComputers; + + public static readonly string OwnedConsoles = V19.OwnedConsoles; + + public static readonly string Processors = V19.Processors; + + public static readonly string SoundSynths = V19.SoundSynths; + + public static readonly string MachinesForeignKeys = + "ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_company` (company) REFERENCES `companies` (`id`) ON UPDATE CASCADE;"; + + public static readonly string Iso3166Numeric = V19.Iso3166Numeric; + + public static readonly string Iso3166NumericValues = V19.Iso3166NumericValues; + + public static readonly string CompaniesForeignKeys = V19.CompaniesForeignKeys; + + public static readonly string CompanyLogos = V19.CompanyLogos; + + public static readonly string CompanyDescriptions = V19.CompanyDescriptions; + + public static readonly string InstructionSets = V19.InstructionSets; + + public static readonly string InstructionSetExtensions = V19.InstructionSetExtensions; + + public static readonly string InstructionSetExtensionsByProcessor = V19.InstructionSetExtensionsByProcessor; + + public static readonly string ProcessorsByMachine = V19.ProcessorsByMachine; + + public static readonly string GpusByMachine = V19.GpusByMachine; + + public static readonly string SoundByMachine = V19.SoundByMachine; + + public static readonly string MemoryByMachine = V19.MemoryByMachine; + + public static readonly string Resolutions = V19.Resolutions; + + public static readonly string ResolutionsByGpu = V19.ResolutionsByGpu; + + public static readonly string StorageByMachine = "CREATE TABLE `storage_by_machine` (\n" + + "`machine` INT NOT NULL,\n" + + "`type` INT NOT NULL DEFAULT 0,\n" + + "`interface` INT NOT NULL DEFAULT 0,\n" + + "`capacity` BIGINT DEFAULT NULL,\n" + + "KEY `idx_storage_machine` (`machine`),\n" + + "KEY `idx_storage_type` (`type`),\n" + + "KEY `idx_storage_interface` (`interface`),\n" + + "KEY `idx_storage_capacity` (`capacity`),\n" + + "CONSTRAINT `fk_storage_by_machine_machine` FOREIGN KEY (`machine`) REFERENCES `machines` (`id`) ON UPDATE CASCADE ON DELETE CASCADE);"; + } +} \ No newline at end of file diff --git a/Cicm.Database/Schemas/DiskFormat.cs b/Cicm.Database/Schemas/StorageByMachine.cs similarity index 74% rename from Cicm.Database/Schemas/DiskFormat.cs rename to Cicm.Database/Schemas/StorageByMachine.cs index 13255086..213fd7b0 100644 --- a/Cicm.Database/Schemas/DiskFormat.cs +++ b/Cicm.Database/Schemas/StorageByMachine.cs @@ -2,12 +2,12 @@ // Canary Islands Computer Museum Website // ---------------------------------------------------------------------------- // -// Filename : DiskFormat.cs +// Filename : Computer.cs // Author(s) : Natalia Portillo // // --[ Description ] ---------------------------------------------------------- // -// High level representation of a disk format. +// High level representation of a computer. // // --[ License ] -------------------------------------------------------------- // @@ -30,12 +30,16 @@ namespace Cicm.Database.Schemas { - /// Storage format - public class DiskFormat + /// Computer + public class StorageByMachine { - /// Description - public string Description; - /// ID - public int Id; + /// Capacity in bytes + public long Capacity; + /// Storage interface + public StorageInterface Interface; + /// Machine ID + public int Machine; + /// Storage type + public StorageType Type; } } \ No newline at end of file diff --git a/cicm_web/Models/Machine.cs b/cicm_web/Models/Machine.cs index 44b82119..cad82133 100644 --- a/cicm_web/Models/Machine.cs +++ b/cicm_web/Models/Machine.cs @@ -37,20 +37,14 @@ namespace cicm_web.Models { public class Machine { - public string Cap1; - public string Cap2; public Company Company; - public DiskFormat Disk1; - public DiskFormat Disk2; public GpuByMachine[] Gpus; - public DiskFormat Hdd1; - public DiskFormat Hdd2; - public DiskFormat Hdd3; public int Id; public MemoryByMachine[] Memories; public string Model; public ProcessorByMachine[] Processors; public SoundByMachine[] SoundSynths; + public StorageByMachine[] Storage; public MachineType Type; public int Year; @@ -83,35 +77,19 @@ namespace cicm_web.Models internal static Machine TransformItem(Cicm.Database.Schemas.Machine dbItem) { - Machine item = new Machine + return new Machine { 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, Year = dbItem.Year, Type = dbItem.Type, Processors = ProcessorByMachine.GetAllItems(dbItem.Id), SoundSynths = SoundByMachine.GetAllItems(dbItem.Id), - Memories = MemoryByMachine.GetAllItems(dbItem.Id) + Memories = MemoryByMachine.GetAllItems(dbItem.Id), + Storage = StorageByMachine.GetAllItems(dbItem.Id) }; - - if(dbItem.Disk1 > 0) - { - item.Cap1 = dbItem.Cap1; - item.Disk1 = DiskFormat.GetItem(dbItem.Disk1); - } - - if(dbItem.Disk2 > 0) - { - item.Cap2 = dbItem.Cap2; - item.Disk2 = DiskFormat.GetItem(dbItem.Disk2); - } - - return item; } } diff --git a/cicm_web/Models/OwnedComputer.cs b/cicm_web/Models/OwnedComputer.cs index 75543b3e..7ed7d008 100644 --- a/cicm_web/Models/OwnedComputer.cs +++ b/cicm_web/Models/OwnedComputer.cs @@ -40,13 +40,9 @@ namespace cicm_web.Models { public DateTime Acquired; public bool Boxed; - public int Cap1; - public int Cap2; public Machine Computer; public Processor Cpu1; public Processor Cpu2; - public DiskFormat Disk1; - public DiskFormat Disk2; public int Id; public bool Manuals; public float Mhz1; @@ -91,18 +87,6 @@ namespace cicm_web.Models Vram = dbItem.Vram }; - if(dbItem.Disk1 > 0) - { - item.Cap1 = dbItem.Cap1; - item.Disk1 = DiskFormat.GetItem(dbItem.Disk1); - } - - if(dbItem.Disk2 > 0) - { - item.Cap2 = dbItem.Cap2; - item.Disk2 = DiskFormat.GetItem(dbItem.Disk2); - } - if(dbItem.Cpu1 > 0) { item.Cpu1 = Processor.GetItem(dbItem.Cpu1); diff --git a/cicm_web/Models/DiskFormat.cs b/cicm_web/Models/StorageByMachine.cs similarity index 60% rename from cicm_web/Models/DiskFormat.cs rename to cicm_web/Models/StorageByMachine.cs index c185a393..39070459 100644 --- a/cicm_web/Models/DiskFormat.cs +++ b/cicm_web/Models/StorageByMachine.cs @@ -2,12 +2,12 @@ // Canary Islands Computer Museum Website // ---------------------------------------------------------------------------- // -// Filename : DiskFormat.cs +// Filename : StorageByMachine.cs // Author(s) : Natalia Portillo // // --[ Description ] ---------------------------------------------------------- // -// Disk format model +// Storage by machine model // // --[ License ] -------------------------------------------------------------- // @@ -29,30 +29,35 @@ *******************************************************************************/ using System.Collections.Generic; +using Cicm.Database.Schemas; namespace cicm_web.Models { - public class DiskFormat + public class StorageByMachine { - public string Description; - public int Id; + /// Capacity in bytes + public long Capacity; + /// Storage interface + public StorageInterface Interface; + /// Storage type + public StorageType Type; - public static DiskFormat GetItem(int id) + public static StorageByMachine[] GetAllItems(int machineId) { - Cicm.Database.Schemas.DiskFormat dbItem = Program.Database?.Operations.GetDiskFormat(id); - return dbItem == null ? null : new DiskFormat {Description = dbItem.Description, Id = dbItem.Id}; - } - - public static DiskFormat[] GetAllItems() - { - List dbItems = null; - bool? result = Program.Database?.Operations.GetDiskFormats(out dbItems); + List dbItems = null; + bool? result = + Program.Database?.Operations.GetStorageByMachines(out dbItems, machineId); if(result == null || result.Value == false || dbItems == null) return null; - List items = new List(); + List items = new List(); - foreach(Cicm.Database.Schemas.DiskFormat dbItem in dbItems) - items.Add(new DiskFormat {Id = dbItem.Id, Description = dbItem.Description}); + foreach(Cicm.Database.Schemas.StorageByMachine dbItem in dbItems) + items.Add(new StorageByMachine + { + Type = dbItem.Type, + Interface = dbItem.Interface, + Capacity = dbItem.Capacity + }); return items.ToArray(); } diff --git a/cicm_web/Views/Machine/View.cshtml b/cicm_web/Views/Machine/View.cshtml index 2486ccb9..bc138b63 100644 --- a/cicm_web/Views/Machine/View.cshtml +++ b/cicm_web/Views/Machine/View.cshtml @@ -32,7 +32,10 @@ ViewData["Title"] = "Computer"; } @using System.IO -@model Machine +@using Cicm.Database.Schemas +@using MemoryByMachine = cicm_web.Models.MemoryByMachine +@using StorageByMachine = cicm_web.Models.StorageByMachine +@model cicm_web.Models.Machine

@if(Model.Company.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Company.LastLogo.Guid + ".svg"))) @@ -643,214 +646,70 @@ } -@if(Model.Hdd1 != null && Model.Hdd1.Id > 0 && Model.Hdd1.Id != 30) +@if(Model.Storage != null && Model.Storage.Length > 0) {

- Disk interfaces + Storage
- @Model.Hdd1.Description - @if(Model.Hdd2 != null && Model.Hdd2.Id > 0 && Model.Hdd2.Id != 30) - { -
- @Model.Hdd2.Description - } - @if(Model.Hdd3 != null && Model.Hdd3.Id > 0 && Model.Hdd3.Id != 30) - { -
- @Model.Hdd3.Description - } + + @foreach(StorageByMachine storage in Model.Storage) + { + string capString = null; + + if(storage.Capacity != 0) + { + if(storage.Type == StorageType.CompactCassette) { capString = $"{storage.Capacity} bps"; } + else + { + if(storage.Capacity > 1073741824) { capString = $"{storage.Capacity / 1073741824} GiB"; } + else if(storage.Capacity > 1048576) { capString = $"{storage.Capacity / 1048576} MiB"; } + else if(storage.Capacity > 1024) { capString = $"{storage.Capacity / 1024} KiB"; } + else if(storage.Capacity > 0) { capString = $"{storage.Capacity} bytes"; } + else + { capString = null; } + } + } + + + @if(storage.Interface != StorageInterface.Unknown) + { + if(storage.Type == StorageType.Empty) + { + + } + else + { + if(capString != null) + { + + } + else + { + + } + } + } + else + { + if(capString != null) + { + + } + else + { + + } + } + + } +
Available @storage.Interface interface.@storage.Type connected thru a @storage.Interface interface with a nominal capacity of @capString@storage.Type connected thru a @storage.Interface interface@storage.Type with a nominal capacity of @capString@storage.Type
} - -@if(Model.Disk1 != null) -{ - - -
- Primary disk -
- - @if(Model.Disk1.Id != 30) - { - int cap1 = int.Parse(Model.Cap1); - - if(Model.Disk1.Id != 8) - { - if(Model.Disk1.Id != 6) - { - string cap1Bytes = cap1 > 1024 ? (cap1 > 1048576 ? $"{cap1 / 1048576} GBytes" : $"{cap1 / 1024} MBytes") : (cap1 > 0 ? $"{cap1} Kbytes" : "Unknown capacity"); - - if(Model.Disk1.Id != 10) - { - if(Model.Disk1.Id != 15) - { - if(Model.Disk1.Id != 16) - { - if(Model.Disk1.Id != 36) - { - if(Model.Disk1.Id != 22) - { - if(Model.Disk1.Id != 23) - { - if(Model.Disk1.Id != 39) - { - if(Model.Disk1.Id != 31) - { - @Model.Disk1.Description (@cap1Bytes) - } - else - { - Propietary (@cap1Bytes) - } - } - else - { - Digital tape (@cap1Bytes) - } - } - else - { - Punched card (@cap1Bytes) - } - } - else - { - Chip card (@cap1Bytes) - } - } - else - { - Magnetic card (@cap1Bytes) - } - } - else - { - Memory (@cap1Bytes) - } - } - else - { - Magneto-optical (@cap1Bytes) - } - } - else - { - Optical disk (@cap1Bytes) - } - } - else - { - string cap1Bits = cap1 > 1000 ? (cap1 > 1000000 ? $"{cap1 / 1000000} GBits" : $"{cap1 / 1000} MBits") : (cap1 > 0 ? $"{cap1} KBits" : "Unknown capacity"); - - Cartridge (@cap1Bits) - } - } - else - { - Standard audio cassette (@cap1 bps) - } - } - else - { None } - -} -@if(Model.Disk2 != null) -{ - - -
- Secondary disk -
- - @if(Model.Disk2.Id != 30) - { - int cap2 = int.Parse(Model.Cap2); - - if(Model.Disk2.Id != 8) - { - if(Model.Disk2.Id != 6) - { - string cap2Bytes = cap2 > 1024 ? (cap2 > 1048576 ? $"{cap2 / 1048576} GBytes" : $"{cap2 / 1024} MBytes") : (cap2 > 0 ? $"{cap2} Kbytes" : "Unknown capacity"); - - if(Model.Disk2.Id != 10) - { - if(Model.Disk2.Id != 15) - { - if(Model.Disk2.Id != 16) - { - if(Model.Disk2.Id != 36) - { - if(Model.Disk2.Id != 22) - { - if(Model.Disk2.Id != 23) - { - if(Model.Disk2.Id != 39) - { - if(Model.Disk2.Id != 31) - { - @Model.Disk2.Description (@cap2Bytes) - } - else - { - Propietary (@cap2Bytes) - } - } - else - { - Digital tape (@cap2Bytes) - } - } - else - { - Punched card (@cap2Bytes) - } - } - else - { - Chip card (@cap2Bytes) - } - } - else - { - Magnetic card (@cap2Bytes) - } - } - else - { - Memory (@cap2Bytes) - } - } - else - { - Magneto-optical (@cap2Bytes) - } - } - else - { - Optical disk (@cap2Bytes) - } - } - else - { - string cap2Bits = cap2 > 1000 ? (cap2 > 1000000 ? $"{cap2 / 1000000} GBits" : $"{cap2 / 1000} MBits") : (cap2 > 0 ? $"{cap2} KBits" : "Unknown capacity"); - - Cartridge (@cap2Bits) - } - } - else - { - Standard audio cassette (@cap2 bps) - } - } - else - { None } - -} @if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/photos/computers", Model.Id + ".jpg"))) diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 65be754e..cf74104c 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.0 - 3.0.99.220 + 3.0.99.222 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website