Update DB to version 22: Machine families, machine model separate from name.

This commit is contained in:
2018-04-29 02:02:33 +01:00
parent 349a941392
commit 736b98b754
21 changed files with 874 additions and 220 deletions

View File

@@ -49,123 +49,127 @@ namespace Cicm.Database
IDbCommand dbCmd = dbCon.CreateCommand(); IDbCommand dbCmd = dbCon.CreateCommand();
Console.WriteLine("Creating table `admins`"); Console.WriteLine("Creating table `admins`");
dbCmd.CommandText = V21.Admins; dbCmd.CommandText = V22.Admins;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `browser_tests`"); Console.WriteLine("Creating table `browser_tests`");
dbCmd.CommandText = V21.BrowserTests; dbCmd.CommandText = V22.BrowserTests;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `cicm_db`"); Console.WriteLine("Creating table `cicm_db`");
dbCmd.CommandText = V21.CicmDb; dbCmd.CommandText = V22.CicmDb;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `companies`"); Console.WriteLine("Creating table `companies`");
dbCmd.CommandText = V21.Companies; dbCmd.CommandText = V22.Companies;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `machine_families`");
dbCmd.CommandText = V22.MachineFamilies;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `machines`"); Console.WriteLine("Creating table `machines`");
dbCmd.CommandText = V21.Machines; dbCmd.CommandText = V22.Machines;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `forbidden`"); Console.WriteLine("Creating table `forbidden`");
dbCmd.CommandText = V21.Forbidden; dbCmd.CommandText = V22.Forbidden;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus`"); Console.WriteLine("Creating table `gpus`");
dbCmd.CommandText = V21.Gpus; dbCmd.CommandText = V22.Gpus;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `log`"); Console.WriteLine("Creating table `log`");
dbCmd.CommandText = V21.Logs; dbCmd.CommandText = V22.Logs;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `money_donations`"); Console.WriteLine("Creating table `money_donations`");
dbCmd.CommandText = V21.MoneyDonations; dbCmd.CommandText = V22.MoneyDonations;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `news`"); Console.WriteLine("Creating table `news`");
dbCmd.CommandText = V21.News; dbCmd.CommandText = V22.News;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_computers`"); Console.WriteLine("Creating table `owned_computers`");
dbCmd.CommandText = V21.OwnedComputers; dbCmd.CommandText = V22.OwnedComputers;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_consoles`"); Console.WriteLine("Creating table `owned_consoles`");
dbCmd.CommandText = V21.OwnedConsoles; dbCmd.CommandText = V22.OwnedConsoles;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_sets`"); Console.WriteLine("Creating table `instruction_sets`");
dbCmd.CommandText = V21.InstructionSets; dbCmd.CommandText = V22.InstructionSets;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions`"); Console.WriteLine("Creating table `instruction_set_extensions`");
dbCmd.CommandText = V21.InstructionSetExtensions; dbCmd.CommandText = V22.InstructionSetExtensions;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `processors`"); Console.WriteLine("Creating table `processors`");
dbCmd.CommandText = V21.Processors; dbCmd.CommandText = V22.Processors;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions_by_processor`"); Console.WriteLine("Creating table `instruction_set_extensions_by_processor`");
dbCmd.CommandText = V21.InstructionSetExtensionsByProcessor; dbCmd.CommandText = V22.InstructionSetExtensionsByProcessor;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `sound_synths`"); Console.WriteLine("Creating table `sound_synths`");
dbCmd.CommandText = V21.SoundSynths; dbCmd.CommandText = V22.SoundSynths;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `iso3166_1_numeric`"); Console.WriteLine("Creating table `iso3166_1_numeric`");
dbCmd.CommandText = V21.Iso3166Numeric; dbCmd.CommandText = V22.Iso3166Numeric;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Filling table `iso3166_1_numeric`"); Console.WriteLine("Filling table `iso3166_1_numeric`");
dbCmd.CommandText = V21.Iso3166NumericValues; dbCmd.CommandText = V22.Iso3166NumericValues;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `companies`"); Console.WriteLine("Creating foreign keys for table `companies`");
dbCmd.CommandText = V21.CompaniesForeignKeys; dbCmd.CommandText = V22.CompaniesForeignKeys;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `machines`"); Console.WriteLine("Creating foreign keys for table `machines`");
dbCmd.CommandText = V21.MachinesForeignKeys; dbCmd.CommandText = V22.MachinesForeignKeys;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_logos`"); Console.WriteLine("Creating table `company_logos`");
dbCmd.CommandText = V21.CompanyLogos; dbCmd.CommandText = V22.CompanyLogos;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_descriptions`"); Console.WriteLine("Creating table `company_descriptions`");
dbCmd.CommandText = V21.CompanyDescriptions; dbCmd.CommandText = V22.CompanyDescriptions;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `processors_by_machine`"); Console.WriteLine("Creating table `processors_by_machine`");
dbCmd.CommandText = V21.ProcessorsByMachine; dbCmd.CommandText = V22.ProcessorsByMachine;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus_by_machine`"); Console.WriteLine("Creating table `gpus_by_machine`");
dbCmd.CommandText = V21.GpusByMachine; dbCmd.CommandText = V22.GpusByMachine;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `sound_by_machine`"); Console.WriteLine("Creating table `sound_by_machine`");
dbCmd.CommandText = V21.SoundByMachine; dbCmd.CommandText = V22.SoundByMachine;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `memory_by_machine`"); Console.WriteLine("Creating table `memory_by_machine`");
dbCmd.CommandText = V21.MemoryByMachine; dbCmd.CommandText = V22.MemoryByMachine;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `resolutions`"); Console.WriteLine("Creating table `resolutions`");
dbCmd.CommandText = V21.Resolutions; dbCmd.CommandText = V22.Resolutions;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `resolutions_by_gpu`"); Console.WriteLine("Creating table `resolutions_by_gpu`");
dbCmd.CommandText = V21.ResolutionsByGpu; dbCmd.CommandText = V22.ResolutionsByGpu;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `storage_by_machine`"); Console.WriteLine("Creating table `storage_by_machine`");
dbCmd.CommandText = V21.StorageByMachine; dbCmd.CommandText = V22.StorageByMachine;
dbCmd.ExecuteNonQuery(); dbCmd.ExecuteNonQuery();
return true; return true;

View File

@@ -206,7 +206,7 @@ namespace Cicm.Database
public bool AddMachine(Machine entry, out long id) public bool AddMachine(Machine entry, out long id)
{ {
#if DEBUG #if DEBUG
Console.Write("Adding machine `{0}`...", entry.Model); Console.Write("Adding machine `{0}`...", entry.Name);
#endif #endif
IDbCommand dbcmd = GetCommandMachine(entry); IDbCommand dbcmd = GetCommandMachine(entry);
@@ -214,7 +214,7 @@ namespace Cicm.Database
dbcmd.Transaction = trans; dbcmd.Transaction = trans;
const string SQL = const string SQL =
"INSERT INTO machines (company, introduced, model, type) VALUES (@company, @introduced, @model, @type)"; "INSERT INTO machines (company, introduced, name, type, model, family) VALUES (@company, @introduced, @name, @type, @model, @family)";
dbcmd.CommandText = SQL; dbcmd.CommandText = SQL;
@@ -239,7 +239,7 @@ namespace Cicm.Database
public bool UpdateMachine(Machine entry) public bool UpdateMachine(Machine entry)
{ {
#if DEBUG #if DEBUG
Console.WriteLine("Updating machine `{0}`...", entry.Model); Console.WriteLine("Updating machine `{0}`...", entry.Name);
#endif #endif
IDbCommand dbcmd = GetCommandMachine(entry); IDbCommand dbcmd = GetCommandMachine(entry);
@@ -247,7 +247,7 @@ namespace Cicm.Database
dbcmd.Transaction = trans; dbcmd.Transaction = trans;
string sql = string sql =
"UPDATE machines SET company = @company, introduced = @introduced, model = @model, type = @type " + "UPDATE machines SET company = @company, introduced = @introduced, name = @name, type = @type, model = @model, family = @family " +
$"WHERE id = {entry.Id}"; $"WHERE id = {entry.Id}";
dbcmd.CommandText = sql; dbcmd.CommandText = sql;
@@ -293,26 +293,36 @@ namespace Cicm.Database
IDbDataParameter param2 = dbcmd.CreateParameter(); IDbDataParameter param2 = dbcmd.CreateParameter();
IDbDataParameter param3 = dbcmd.CreateParameter(); IDbDataParameter param3 = dbcmd.CreateParameter();
IDbDataParameter param4 = dbcmd.CreateParameter(); IDbDataParameter param4 = dbcmd.CreateParameter();
IDbDataParameter param5 = dbcmd.CreateParameter();
IDbDataParameter param6 = dbcmd.CreateParameter();
param1.ParameterName = "@company"; param1.ParameterName = "@company";
param2.ParameterName = "@introduced"; param2.ParameterName = "@introduced";
param3.ParameterName = "@model"; param3.ParameterName = "@name";
param4.ParameterName = "@type"; param4.ParameterName = "@type";
param5.ParameterName = "@model";
param6.ParameterName = "@family";
param1.DbType = DbType.Int32; param1.DbType = DbType.Int32;
param2.DbType = DbType.DateTime; param2.DbType = DbType.DateTime;
param3.DbType = DbType.String; param3.DbType = DbType.String;
param4.DbType = DbType.Int32; param4.DbType = DbType.Int32;
param5.DbType = DbType.String;
param6.DbType = DbType.Int32;
param1.Value = entry.Company; param1.Value = entry.Company;
param2.Value = entry.Introduced; param2.Value = entry.Introduced;
param3.Value = entry.Model; param3.Value = entry.Name;
param4.Value = entry.Type; param4.Value = entry.Type;
param5.Value = entry.Model;
param6.Value = entry.Family == 0 ? (object)null : entry.Family;
dbcmd.Parameters.Add(param1); dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2); dbcmd.Parameters.Add(param2);
dbcmd.Parameters.Add(param3); dbcmd.Parameters.Add(param3);
dbcmd.Parameters.Add(param4); dbcmd.Parameters.Add(param4);
dbcmd.Parameters.Add(param5);
dbcmd.Parameters.Add(param6);
return dbcmd; return dbcmd;
} }
@@ -329,8 +339,10 @@ namespace Cicm.Database
Company = (int)dataRow["company"], Company = (int)dataRow["company"],
Introduced = Introduced =
dataRow["introduced"] == DBNull.Value ? DateTime.MinValue : (DateTime)dataRow["introduced"], dataRow["introduced"] == DBNull.Value ? DateTime.MinValue : (DateTime)dataRow["introduced"],
Model = (string)dataRow["model"], Name = (string)dataRow["name"],
Type = (MachineType)dataRow["type"] Type = (MachineType)dataRow["type"],
Model = dataRow["model"] == DBNull.Value ? null : (string)dataRow["model"],
Family = dataRow["family"] == DBNull.Value ? 0 : (int)dataRow["family"]
}; };
entries.Add(entry); entries.Add(entry);

View File

@@ -0,0 +1,326 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : MachineFamily.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains operations to manage machine_families.
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// 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
{
/// <summary>
/// Gets all machine_families
/// </summary>
/// <param name="entries">All machine_families</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMachineFamilies(out List<MachineFamily> entries)
{
#if DEBUG
Console.WriteLine("Getting all machine_families...");
#endif
try
{
const string SQL = "SELECT * from machine_families";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting machine_families.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets all machine_families from specified company
/// </summary>
/// <param name="entries">All machine_families</param>
/// <param name="company">Company id</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMachineFamilies(out List<MachineFamily> entries, int company)
{
#if DEBUG
Console.WriteLine("Getting all machine_families from company id {0}...", company);
#endif
try
{
string sql = $"SELECT * from machine_families WHERE company = '{company}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting machine_families.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets the specified number of machine_families since the specified start
/// </summary>
/// <param name="entries">List of machine_families</param>
/// <param name="start">Start of query</param>
/// <param name="count">How many entries to retrieve</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMachineFamilies(out List<MachineFamily> entries, ulong start, ulong count)
{
#if DEBUG
Console.WriteLine("Getting {0} machine_families from {1}...", count, start);
#endif
try
{
string sql = $"SELECT * FROM machine_families 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 = MachineFamiliesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting machine_families.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets machine_families by specified id
/// </summary>
/// <param name="id">Id</param>
/// <returns>MachineFamily with specified id, <c>null</c> if not found or error</returns>
public MachineFamily GetMachineFamily(int id)
{
#if DEBUG
Console.WriteLine("Getting machine_families with id {0}...", id);
#endif
try
{
string sql = $"SELECT * from machine_families 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<MachineFamily> entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting machine_families.");
Console.WriteLine(ex);
return null;
}
}
/// <summary>
/// Counts the number of machine_families in the database
/// </summary>
/// <returns>Entries in database</returns>
public long CountMachineFamilies()
{
#if DEBUG
Console.WriteLine("Counting machine_families...");
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = "SELECT COUNT(*) FROM machine_families";
object count = dbcmd.ExecuteScalar();
dbcmd.Dispose();
try { return Convert.ToInt64(count); }
catch { return 0; }
}
/// <summary>
/// Adds a new administrator to the database
/// </summary>
/// <param name="entry">Entry to add</param>
/// <param name="id">ID of added entry</param>
/// <returns><c>true</c> if added correctly, <c>false</c> otherwise</returns>
public bool AddMachineFamily(MachineFamily entry, out long id)
{
#if DEBUG
Console.Write("Adding machine_families `{0}`...", entry.Name);
#endif
IDbCommand dbcmd = GetCommandMachineFamily(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
const string SQL = "INSERT INTO machine_families (company, name) VALUES (@company, @name)";
dbcmd.CommandText = SQL;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
id = dbCore.LastInsertRowId;
#if DEBUG
Console.WriteLine(" id {0}", id);
#endif
return true;
}
/// <summary>
/// Updated a machine_families in the database
/// </summary>
/// <param name="entry">Updated entry</param>
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
public bool UpdateMachineFamily(MachineFamily entry)
{
#if DEBUG
Console.WriteLine("Updating machine_families `{0}`...", entry.Name);
#endif
IDbCommand dbcmd = GetCommandMachineFamily(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = "UPDATE machine_families SET company = @company, name = @name " + $"WHERE id = {entry.Id}";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
/// <summary>
/// Removes a machine_families from the database
/// </summary>
/// <param name="id">ID of entry to remove</param>
/// <returns><c>true</c> if removed correctly, <c>false</c> otherwise</returns>
public bool RemoveMachineFamily(long id)
{
#if DEBUG
Console.WriteLine("Removing machine_families widh id `{0}`...", id);
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = $"DELETE FROM machine_families WHERE id = '{id}';";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
IDbCommand GetCommandMachineFamily(MachineFamily entry)
{
IDbCommand dbcmd = dbCon.CreateCommand();
IDbDataParameter param1 = dbcmd.CreateParameter();
IDbDataParameter param2 = dbcmd.CreateParameter();
param1.ParameterName = "@company";
param2.ParameterName = "@name";
param1.DbType = DbType.Int32;
param2.DbType = DbType.String;
param1.Value = entry.Company;
param2.Value = entry.Name;
dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2);
return dbcmd;
}
static List<MachineFamily> MachineFamiliesFromDataTable(DataTable dataTable)
{
List<MachineFamily> entries = new List<MachineFamily>();
foreach(DataRow dataRow in dataTable.Rows)
{
MachineFamily entry = new MachineFamily
{
Id = (int)dataRow["id"],
Company = (int)dataRow["company"],
Name = (string)dataRow["name"]
};
entries.Add(entry);
}
return entries;
}
}
}

View File

@@ -35,7 +35,7 @@ namespace Cicm.Database
public partial class Operations public partial class Operations
{ {
/// <summary>Last known database version</summary> /// <summary>Last known database version</summary>
const int DB_VERSION = 21; const int DB_VERSION = 22;
/// <summary>The column with this value indicates there is no item of this type.</summary> /// <summary>The column with this value indicates there is no item of this type.</summary>
public const int DB_NONE = -1; public const int DB_NONE = -1;
/// <summary> /// <summary>

View File

@@ -174,6 +174,11 @@ namespace Cicm.Database
UpdateDatabaseToV21(); UpdateDatabaseToV21();
break; break;
} }
case 21:
{
UpdateDatabaseToV22();
break;
}
} }
OptimizeDatabase(); OptimizeDatabase();
@@ -2486,6 +2491,59 @@ namespace Cicm.Database
dbCmd.Dispose(); dbCmd.Dispose();
} }
void UpdateDatabaseToV22()
{
Console.WriteLine("Updating database to version 22");
Console.WriteLine("Creating new table table `machine_families`");
IDbCommand dbCmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = V22.MachineFamilies;
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Adding new columns to table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "ALTER TABLE `machines` ADD COLUMN `family` INT DEFAULT NULL;\n" +
"ALTER TABLE `machines` CHANGE COLUMN `model` `name` VARCHAR(255) NOT NULL;\n" +
"ALTER TABLE `machines` DROP INDEX `idx_machines_model`;\n" +
"ALTER TABLE `machines` ADD COLUMN `model` VARCHAR(50) DEFAULT NULL;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Adding new indexes to table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "CREATE INDEX `idx_machines_family` ON `machines` (`family`);\n" +
"CREATE INDEX `idx_machines_name` ON `machines` (`name`);\n" +
"CREATE INDEX `idx_machines_model` ON `machines` (`model`);";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Adding new foreign keys to table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText =
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_family` (family) REFERENCES machine_families (`id`) ON UPDATE CASCADE";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Setting new database version to 22...");
dbCmd = dbCon.CreateCommand();
dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('22')";
dbCmd.ExecuteNonQuery();
dbCmd.Dispose();
}
void OptimizeDatabase() void OptimizeDatabase()
{ {
IDbCommand dbCmd = dbCon.CreateCommand(); IDbCommand dbCmd = dbCon.CreateCommand();

View File

@@ -37,12 +37,16 @@ namespace Cicm.Database.Schemas
{ {
/// <summary>Manufacturer's company ID</summary> /// <summary>Manufacturer's company ID</summary>
public int Company; public int Company;
/// <summary>Machine family</summary>
public int Family;
/// <summary>ID</summary> /// <summary>ID</summary>
public int Id; public int Id;
/// <summary>Introduction date, null if unknown, 1000 if prototype</summary> /// <summary>Introduction date, null if unknown, 1000 if prototype</summary>
public DateTime Introduced; public DateTime Introduced;
/// <summary>Model name</summary> /// <summary>Machine model/SKU</summary>
public string Model; public string Model;
/// <summary>Model name</summary>
public string Name;
/// <summary>Machine type</summary> /// <summary>Machine type</summary>
public MachineType Type; public MachineType Type;
} }

View File

@@ -0,0 +1,43 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Computer.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
namespace Cicm.Database.Schemas
{
/// <summary>Computer</summary>
public class MachineFamily
{
/// <summary>Manufacturer's company ID</summary>
public int Company;
/// <summary>ID</summary>
public int Id;
/// <summary>Model name</summary>
public string Name;
}
}

View File

@@ -41,7 +41,7 @@ namespace Cicm.Database.Schemas.Sql
"`version` int(11) NOT NULL,\n" + "`version` int(11) NOT NULL,\n" +
"`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" + "`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
"PRIMARY KEY (`id`));\n" + "PRIMARY KEY (`id`));\n" +
"INSERT INTO cicm_db (version) VALUES ('20');"; "INSERT INTO cicm_db (version) VALUES ('21');";
public static readonly string Companies = V20.Companies; public static readonly string Companies = V20.Companies;

View File

@@ -0,0 +1,125 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : V22.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
namespace Cicm.Database.Schemas.Sql
{
public static class V22
{
public static readonly string Admins = V21.Admins;
public static readonly string BrowserTests = V21.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 ('22');";
public static readonly string Companies = V21.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" +
"`name` varchar(255) NOT NULL,\n" +
"`type` int(11) NOT NULL DEFAULT '0',\n" +
"`introduced` datetime DEFAULT NULL,\n" +
"`family` int(11) DEFAULT NULL,\n" +
"`model` varchar(50) DEFAULT NULL,\n" +
"PRIMARY KEY (`id`),\n" +
"KEY `idx_machines_company` (`company`),\n" +
"KEY `idx_machines_type` (`type`),\n" +
"KEY `idx_machines_introduced` (`introduced`),\n" +
"KEY `idx_machines_family` (`family`),\n" +
"KEY `idx_machines_name` (`name`),\n" +
"KEY `idx_machines_model` (`model`));";
public static readonly string Forbidden = V21.Forbidden;
public static readonly string Gpus = V21.Gpus;
public static readonly string Logs = V21.Logs;
public static readonly string MoneyDonations = V21.MoneyDonations;
public static readonly string News = V21.News;
public static readonly string OwnedComputers = V21.OwnedComputers;
public static readonly string OwnedConsoles = V21.OwnedConsoles;
public static readonly string Processors = V21.Processors;
public static readonly string SoundSynths = V21.SoundSynths;
public static readonly string MachinesForeignKeys =
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_company` (company) REFERENCES `companies` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_family` (family) REFERENCES `machine_families` (`id`) ON UPDATE CASCADE;";
public static readonly string Iso3166Numeric = V21.Iso3166Numeric;
public static readonly string Iso3166NumericValues = V21.Iso3166NumericValues;
public static readonly string CompaniesForeignKeys = V21.CompaniesForeignKeys;
public static readonly string CompanyLogos = V21.CompanyLogos;
public static readonly string CompanyDescriptions = V21.CompanyDescriptions;
public static readonly string InstructionSets = V21.InstructionSets;
public static readonly string InstructionSetExtensions = V21.InstructionSetExtensions;
public static readonly string InstructionSetExtensionsByProcessor = V21.InstructionSetExtensionsByProcessor;
public static readonly string ProcessorsByMachine = V21.ProcessorsByMachine;
public static readonly string GpusByMachine = V21.GpusByMachine;
public static readonly string SoundByMachine = V21.SoundByMachine;
public static readonly string MemoryByMachine = V21.MemoryByMachine;
public static readonly string Resolutions = V21.Resolutions;
public static readonly string ResolutionsByGpu = V21.ResolutionsByGpu;
public static readonly string StorageByMachine = V21.StorageByMachine;
public static readonly string MachineFamilies = "CREATE TABLE `machine_families` (\n" +
"`id` INT NOT NULL AUTO_INCREMENT,\n" +
"`company` INT NOT NULL,\n" +
"`name` VARCHAR(255) NOT NULL,\n" +
"PRIMARY KEY (`id`),\n" +
"KEY `idx_machine_families_company` (`company`),\n" +
"KEY `idx_machine_families_name` (`name`),\n" +
"CONSTRAINT `fk_machine_families_company` FOREIGN KEY (`company`) REFERENCES `companies` (`id`) ON UPDATE CASCADE ON DELETE CASCADE);";
}
}

View File

@@ -44,7 +44,7 @@ namespace cicm_web.Models
List<Machine> items = new List<Machine>(); List<Machine> items = new List<Machine>();
return dbItems.Select(Machine.TransformItem).OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return dbItems.Select(Machine.TransformItem).OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static Machine[] GetItemsFromCompany(int id) public static Machine[] GetItemsFromCompany(int id)
@@ -54,7 +54,7 @@ namespace cicm_web.Models
if(result == null || result.Value == false || dbItems == null) return null; if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB // TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(Machine.TransformItem).OrderBy(t => t.Model).ToArray(); return dbItems.Where(t => t.Company == id).Select(Machine.TransformItem).OrderBy(t => t.Name).ToArray();
} }
public static Machine GetItem(int id) public static Machine GetItem(int id)
@@ -76,7 +76,7 @@ namespace cicm_web.Models
List<MachineMini> items = new List<MachineMini>(); List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) items.Add(MachineMini.TransformItem(dbItem)); foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsStartingWithLetter(char letter) public static MachineMini[] GetItemsStartingWithLetter(char letter)
@@ -87,10 +87,10 @@ namespace cicm_web.Models
List<MachineMini> items = new List<MachineMini>(); List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
if(dbItem.Model.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase)) if(dbItem.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
items.Add(MachineMini.TransformItem(dbItem)); items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsFromYear(int year) public static MachineMini[] GetItemsFromYear(int year)
@@ -104,7 +104,7 @@ namespace cicm_web.Models
if(dbItem.Introduced.Year == year) if(dbItem.Introduced.Year == year)
items.Add(MachineMini.TransformItem(dbItem)); items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsWithCompany(int id, string companyName) public static MachineMini[] GetItemsWithCompany(int id, string companyName)
@@ -119,8 +119,8 @@ namespace cicm_web.Models
{ {
Company = new Company {Id = id, Name = companyName}, Company = new Company {Id = id, Name = companyName},
Id = t.Id, Id = t.Id,
Model = t.Model Name = t.Name
}).OrderBy(t => t.Model).ToArray(); }).OrderBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsFromCompany(int id) public static MachineMini[] GetItemsFromCompany(int id)
@@ -130,8 +130,7 @@ namespace cicm_web.Models
if(result == null || result.Value == false || dbItems == null) return null; if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB // TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(MachineMini.TransformItem).OrderBy(t => t.Model) return dbItems.Where(t => t.Company == id).Select(MachineMini.TransformItem).OrderBy(t => t.Name).ToArray();
.ToArray();
} }
} }
} }

View File

@@ -52,7 +52,7 @@ namespace cicm_web.Models
if(result == null || result.Value == false || dbItems == null) return null; if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB // TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(Machine.TransformItem).OrderBy(t => t.Model).ToArray(); return dbItems.Where(t => t.Company == id).Select(Machine.TransformItem).OrderBy(t => t.Name).ToArray();
} }
public static Machine GetItem(int id) public static Machine GetItem(int id)
@@ -74,7 +74,7 @@ namespace cicm_web.Models
List<MachineMini> items = new List<MachineMini>(); List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) items.Add(MachineMini.TransformItem(dbItem)); foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsStartingWithLetter(char letter) public static MachineMini[] GetItemsStartingWithLetter(char letter)
@@ -85,10 +85,10 @@ namespace cicm_web.Models
List<MachineMini> items = new List<MachineMini>(); List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
if(dbItem.Model.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase)) if(dbItem.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
items.Add(MachineMini.TransformItem(dbItem)); items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsFromYear(int year) public static MachineMini[] GetItemsFromYear(int year)
@@ -102,7 +102,7 @@ namespace cicm_web.Models
if(dbItem.Introduced.Year == year) if(dbItem.Introduced.Year == year)
items.Add(MachineMini.TransformItem(dbItem)); items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsWithCompany(int id, string companyName) public static MachineMini[] GetItemsWithCompany(int id, string companyName)
@@ -117,8 +117,8 @@ namespace cicm_web.Models
{ {
Company = new Company {Id = id, Name = companyName}, Company = new Company {Id = id, Name = companyName},
Id = t.Id, Id = t.Id,
Model = t.Model Name = t.Name
}).OrderBy(t => t.Model).ToArray(); }).OrderBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsFromCompany(int id) public static MachineMini[] GetItemsFromCompany(int id)
@@ -128,8 +128,7 @@ namespace cicm_web.Models
if(result == null || result.Value == false || dbItems == null) return null; if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB // TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(MachineMini.TransformItem).OrderBy(t => t.Model) return dbItems.Where(t => t.Company == id).Select(MachineMini.TransformItem).OrderBy(t => t.Name).ToArray();
.ToArray();
} }
} }
} }

View File

@@ -38,11 +38,13 @@ namespace cicm_web.Models
public class Machine public class Machine
{ {
public Company Company; public Company Company;
public MachineFamily Family;
public GpuByMachine[] Gpus; public GpuByMachine[] Gpus;
public int Id; public int Id;
public DateTime Introduced; public DateTime Introduced;
public MemoryByMachine[] Memories; public MemoryByMachine[] Memories;
public string Model; public string Model;
public string Name;
public ProcessorByMachine[] Processors; public ProcessorByMachine[] Processors;
public SoundByMachine[] SoundSynths; public SoundByMachine[] SoundSynths;
public StorageByMachine[] Storage; public StorageByMachine[] Storage;
@@ -56,7 +58,7 @@ namespace cicm_web.Models
List<Machine> items = new List<Machine>(); List<Machine> items = new List<Machine>();
return dbItems.Select(TransformItem).OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return dbItems.Select(TransformItem).OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static Machine[] GetItemsFromCompany(int id) public static Machine[] GetItemsFromCompany(int id)
@@ -66,7 +68,7 @@ namespace cicm_web.Models
if(result == null || result.Value == false || dbItems == null) return null; if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB // TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(TransformItem).OrderBy(t => t.Model).ToArray(); return dbItems.Where(t => t.Company == id).Select(TransformItem).OrderBy(t => t.Name).ToArray();
} }
public static Machine GetItem(int id) public static Machine GetItem(int id)
@@ -82,13 +84,15 @@ namespace cicm_web.Models
Company = Company.GetItem(dbItem.Company), Company = Company.GetItem(dbItem.Company),
Gpus = GpuByMachine.GetAllItems(dbItem.Id), Gpus = GpuByMachine.GetAllItems(dbItem.Id),
Id = dbItem.Id, Id = dbItem.Id,
Model = dbItem.Model, Name = dbItem.Name,
Introduced = dbItem.Introduced, Introduced = dbItem.Introduced,
Type = dbItem.Type, Type = dbItem.Type,
Processors = ProcessorByMachine.GetAllItems(dbItem.Id), Processors = ProcessorByMachine.GetAllItems(dbItem.Id),
SoundSynths = SoundByMachine.GetAllItems(dbItem.Id), SoundSynths = SoundByMachine.GetAllItems(dbItem.Id),
Memories = MemoryByMachine.GetAllItems(dbItem.Id), Memories = MemoryByMachine.GetAllItems(dbItem.Id),
Storage = StorageByMachine.GetAllItems(dbItem.Id) Storage = StorageByMachine.GetAllItems(dbItem.Id),
Family = MachineFamily.GetItem(dbItem.Family),
Model = dbItem.Model
}; };
} }
} }
@@ -97,7 +101,7 @@ namespace cicm_web.Models
{ {
public Company Company; public Company Company;
public int Id; public int Id;
public string Model; public string Name;
public static MachineMini[] GetAllItems() public static MachineMini[] GetAllItems()
{ {
@@ -109,7 +113,7 @@ namespace cicm_web.Models
List<MachineMini> items = new List<MachineMini>(); List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) items.Add(TransformItem(dbItem)); foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) items.Add(TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsStartingWithLetter(char letter) public static MachineMini[] GetItemsStartingWithLetter(char letter)
@@ -120,10 +124,10 @@ namespace cicm_web.Models
List<MachineMini> items = new List<MachineMini>(); List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
if(dbItem.Model.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase)) if(dbItem.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
items.Add(TransformItem(dbItem)); items.Add(TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsFromYear(int year) public static MachineMini[] GetItemsFromYear(int year)
@@ -137,7 +141,7 @@ namespace cicm_web.Models
if(dbItem.Introduced.Year == year) if(dbItem.Introduced.Year == year)
items.Add(TransformItem(dbItem)); items.Add(TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsWithCompany(int id, string companyName) public static MachineMini[] GetItemsWithCompany(int id, string companyName)
@@ -152,8 +156,8 @@ namespace cicm_web.Models
{ {
Company = new Company {Id = id, Name = companyName}, Company = new Company {Id = id, Name = companyName},
Id = t.Id, Id = t.Id,
Model = t.Model Name = t.Name
}).OrderBy(t => t.Model).ToArray(); }).OrderBy(t => t.Name).ToArray();
} }
public static MachineMini[] GetItemsFromCompany(int id) public static MachineMini[] GetItemsFromCompany(int id)
@@ -163,12 +167,12 @@ namespace cicm_web.Models
if(result == null || result.Value == false || dbItems == null) return null; if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB // TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(TransformItem).OrderBy(t => t.Model).ToArray(); return dbItems.Where(t => t.Company == id).Select(TransformItem).OrderBy(t => t.Name).ToArray();
} }
internal static MachineMini TransformItem(Cicm.Database.Schemas.Machine dbItem) internal static MachineMini TransformItem(Cicm.Database.Schemas.Machine dbItem)
{ {
return new MachineMini {Company = Company.GetItem(dbItem.Company), Id = dbItem.Id, Model = dbItem.Model}; return new MachineMini {Company = Company.GetItem(dbItem.Company), Id = dbItem.Id, Name = dbItem.Name};
} }
} }
} }

View File

@@ -0,0 +1,47 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : GpuByMachine.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
namespace cicm_web.Models
{
public class MachineFamily
{
public int Id;
public string Name;
public static MachineFamily GetItem(int familyId)
{
Cicm.Database.Schemas.MachineFamily result = Program.Database?.Operations.GetMachineFamily(familyId);
if(result == null || result.Id != familyId) return null;
return new MachineFamily {Name = result.Name, Id = familyId};
}
}
}

View File

@@ -87,56 +87,56 @@ namespace cicm_web.Models
imageUrl = "assets/photos/computers/"; imageUrl = "assets/photos/computers/";
targetView = "Computer"; targetView = "Computer";
computer = Computer.GetItem(dbItem.AffectedId); computer = Computer.GetItem(dbItem.AffectedId);
subtext = $"{computer.Company.Name} - {computer.Model}"; subtext = $"{computer.Company.Name} - {computer.Name}";
break; break;
case NewsType.NewConsoleInDb: case NewsType.NewConsoleInDb:
text = "New videoconsole added to the database."; text = "New videoconsole added to the database.";
imageUrl = "assets/photos/consoles/"; imageUrl = "assets/photos/consoles/";
targetView = "Console"; targetView = "Console";
console = Console.GetItem(dbItem.AffectedId); console = Console.GetItem(dbItem.AffectedId);
subtext = $"{console.Company.Name} - {console.Model}"; subtext = $"{console.Company.Name} - {console.Name}";
break; break;
case NewsType.NewComputerInCollection: case NewsType.NewComputerInCollection:
text = "New computer added to the museum's collection."; text = "New computer added to the museum's collection.";
imageUrl = "assets/photos/computers/"; imageUrl = "assets/photos/computers/";
targetView = "CollectionComputer"; targetView = "CollectionComputer";
owncomputer = OwnedComputer.GetItem(dbItem.AffectedId); owncomputer = OwnedComputer.GetItem(dbItem.AffectedId);
subtext = $"{owncomputer.Computer.Company.Name} - {owncomputer.Computer.Model}"; subtext = $"{owncomputer.Computer.Company.Name} - {owncomputer.Computer.Name}";
break; break;
case NewsType.NewConsoleInCollection: case NewsType.NewConsoleInCollection:
text = "New videoconsole added to the museum's collection."; text = "New videoconsole added to the museum's collection.";
imageUrl = "assets/photos/consoles/"; imageUrl = "assets/photos/consoles/";
targetView = "CollectionConsole"; targetView = "CollectionConsole";
ownconsole = OwnedConsole.GetItem(dbItem.AffectedId); ownconsole = OwnedConsole.GetItem(dbItem.AffectedId);
subtext = $"{ownconsole.Console.Company.Name} - {ownconsole.Console.Model}"; subtext = $"{ownconsole.Console.Company.Name} - {ownconsole.Console.Name}";
break; break;
case NewsType.UpdatedComputerInDb: case NewsType.UpdatedComputerInDb:
text = "Updated computer from the database."; text = "Updated computer from the database.";
imageUrl = "assets/photos/computers/"; imageUrl = "assets/photos/computers/";
targetView = "Computer"; targetView = "Computer";
computer = Computer.GetItem(dbItem.AffectedId); computer = Computer.GetItem(dbItem.AffectedId);
subtext = $"{computer.Company.Name} - {computer.Model}"; subtext = $"{computer.Company.Name} - {computer.Name}";
break; break;
case NewsType.UpdatedConsoleInDb: case NewsType.UpdatedConsoleInDb:
text = "Updated videoconsole from the database."; text = "Updated videoconsole from the database.";
imageUrl = "assets/photos/consoles/"; imageUrl = "assets/photos/consoles/";
targetView = "Console"; targetView = "Console";
console = Console.GetItem(dbItem.AffectedId); console = Console.GetItem(dbItem.AffectedId);
subtext = $"{console.Company.Name} - {console.Model}"; subtext = $"{console.Company.Name} - {console.Name}";
break; break;
case NewsType.UpdatedComputerInCollection: case NewsType.UpdatedComputerInCollection:
text = "Updated computer from museum's collection."; text = "Updated computer from museum's collection.";
imageUrl = "assets/photos/computers/"; imageUrl = "assets/photos/computers/";
targetView = "CollectionComputer"; targetView = "CollectionComputer";
owncomputer = OwnedComputer.GetItem(dbItem.AffectedId); owncomputer = OwnedComputer.GetItem(dbItem.AffectedId);
subtext = $"{owncomputer.Computer.Company.Name} - {owncomputer.Computer.Model}"; subtext = $"{owncomputer.Computer.Company.Name} - {owncomputer.Computer.Name}";
break; break;
case NewsType.UpdatedConsoleInCollection: case NewsType.UpdatedConsoleInCollection:
text = "Updated videoconsole from museum's collection."; text = "Updated videoconsole from museum's collection.";
imageUrl = "assets/photos/consoles/"; imageUrl = "assets/photos/consoles/";
targetView = "CollectionConsole"; targetView = "CollectionConsole";
ownconsole = OwnedConsole.GetItem(dbItem.AffectedId); ownconsole = OwnedConsole.GetItem(dbItem.AffectedId);
subtext = $"{ownconsole.Console.Company.Name} - {ownconsole.Console.Model}"; subtext = $"{ownconsole.Console.Company.Name} - {ownconsole.Console.Name}";
break; break;
case NewsType.NewMoneyDonation: case NewsType.NewMoneyDonation:
text = "New money donation."; text = "New money donation.";

View File

@@ -370,7 +370,7 @@
<a asp-controller="Machine" <a asp-controller="Machine"
asp-action="View" asp-action="View"
asp-route-id="@computer.Id"> asp-route-id="@computer.Id">
@computer.Model</a> @computer.Name</a>
<br /> <br />
} }
</div> </div>
@@ -412,7 +412,7 @@
<a asp-controller="Machine" <a asp-controller="Machine"
asp-action="View" asp-action="View"
asp-route-id="@console.Id"> asp-route-id="@console.Id">
@console.Model</a> @console.Name</a>
<br /> <br />
} }
</div> </div>

View File

@@ -51,7 +51,7 @@
<a asp-controller="Machine" <a asp-controller="Machine"
asp-action="View" asp-action="View"
asp-route-id="@computer.Id"> asp-route-id="@computer.Id">
@computer.Company.Name @computer.Model</a> @computer.Company.Name @computer.Name</a>
<br /> <br />
} }
</p> </p>

View File

@@ -47,7 +47,7 @@
<a asp-controller="Machine" <a asp-controller="Machine"
asp-action="View" asp-action="View"
asp-route-id="@computer.Id"> asp-route-id="@computer.Id">
@computer.Company.Name @computer.Model</a> @computer.Company.Name @computer.Name</a>
<br /> <br />
} }
</p> </p>

View File

@@ -51,7 +51,7 @@
<a asp-controller="Machine" <a asp-controller="Machine"
asp-action="View" asp-action="View"
asp-route-id="@console.Id"> asp-route-id="@console.Id">
@console.Company.Name @console.Model</a> @console.Company.Name @console.Name</a>
<br /> <br />
} }
</p> </p>

View File

@@ -47,7 +47,7 @@
<a asp-controller="Machine" <a asp-controller="Machine"
asp-action="View" asp-action="View"
asp-route-id="@console.Id"> asp-route-id="@console.Id">
@console.Company.Name @console.Model</a> @console.Company.Name @console.Name</a>
<br /> <br />
} }
</p> </p>

View File

@@ -70,7 +70,7 @@
<a asp-controller=Company <a asp-controller=Company
asp-action=View asp-action=View
asp-route-id=@Model.Company.Id> asp-route-id=@Model.Company.Id>
@Model.Company.Name</a> @Model.Model</b> @Model.Company.Name</a> @Model.Name</b>
<table width=100%> <table width=100%>
@if(Model.Introduced.Year != 1000) @if(Model.Introduced.Year != 1000)
@@ -90,6 +90,37 @@
</td> </td>
</tr> </tr>
} }
@if(Model.Family != null)
{
<tr>
<th scope=row
width="37%">
<div align=right>
Family
</div>
</th>
<td width="63%">
<a asp-controller="Computer"
asp-action="ByFamily"
asp-route-id="@Model.Family.Id">
@Model.Family.Name</a>
</td>
</tr>
}
@if(Model.Model != null)
{
<tr>
<th scope=row
width="37%">
<div align=right>
Model
</div>
</th>
<td width="63%">
@Model.Model
</td>
</tr>
}
@if(Model.Processors != null && Model.Processors.Length > 0) @if(Model.Processors != null && Model.Processors.Length > 0)
{ {
<tr> <tr>
@@ -504,143 +535,145 @@
<table> <table>
@for(int i = 0; i < Model.SoundSynths.Length; i++) @for(int i = 0; i < Model.SoundSynths.Length; i++)
{ {
if(Model.SoundSynths[i] != null) <tr>
{ @if(Model.SoundSynths[i] != null)
if(Model.SoundSynths[i].SoundSynth.Id == -2)
{ {
<td> if(Model.SoundSynths[i].SoundSynth.Id == -2)
Software {
<a aria-controls="@($"synthInfo{i}")" <td>
aria-expanded="false" Software
class="btn btn-link" <a aria-controls="@($"synthInfo{i}")"
data-toggle="collapse" aria-expanded="false"
href="@($"#synthInfo{i}")"> class="btn btn-link"
+info data-toggle="collapse"
</a> href="@($"#synthInfo{i}")">
<div class="collapse" +info
id="@($"synthInfo{i}")"> </a>
<div class="card card-body"> <div class="collapse"
This computer directly sends data to a <abbr title="Digital to Analog Converter">DAC</abbr> or similar connected to the audio output. id="@($"synthInfo{i}")">
<div class="card card-body">
This computer directly sends data to a <abbr title="Digital to Analog Converter">DAC</abbr> or similar connected to the audio output.
</div>
</div> </div>
</div> </td>
</td> }
else
{
<td>
@($"{Model.SoundSynths[i].SoundSynth.Name}")
<a aria-controls="@($"synthInfo{i}")"
aria-expanded="false"
class="btn btn-link"
data-toggle="collapse"
href="@($"#synthInfo{i}")">
+info
</a>
<div class="collapse"
id="@($"synthInfo{i}")">
<div class="card card-body">
<table>
@if(Model.SoundSynths[i].SoundSynth.ModelCode != null && Model.SoundSynths[i].SoundSynth.ModelCode != Model.SoundSynths[i].SoundSynth.Name)
{
<tr>
<td>Model</td>
<td>@Model.SoundSynths[i].SoundSynth.ModelCode</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Company != null)
{
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company
asp-action=View
asp-route-id=@Model.SoundSynths[i].SoundSynth.Company.Id>
@Model.SoundSynths[i].SoundSynth.Company.Name</a>
</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Introduced != DateTime.MinValue)
{
<tr>
<td>Introduction date</td>
<td>@($"{Model.Gpus[i].Gpu.Introduced:yyyy}")</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Voices != 0 || Model.SoundSynths[i].SoundSynth.SquareWave != 0 || Model.SoundSynths[i].SoundSynth.WhiteNoise != 0)
{
<tr>
<td>Generators</td>
<td>
<table>
@if(Model.SoundSynths[i].SoundSynth.Voices != 0)
{
<tr>
<td>@Model.SoundSynths[i].SoundSynth.Voices voices</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.SquareWave != 0)
{
<tr>
<td>@Model.SoundSynths[i].SoundSynth.SquareWave square wave</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.WhiteNoise != 0)
{
<tr>
<td>@Model.SoundSynths[i].SoundSynth.WhiteNoise white noise</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Depth != 0 || Model.SoundSynths[i].SoundSynth.Frequency > 0)
{
<tr>
<td>Sample rate</td>
<td>
<table>
@if(Model.SoundSynths[i].SoundSynth.Depth != 0 && Model.SoundSynths[i].SoundSynth.Frequency > 0)
{
<tr>
<td>@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")</td>
</tr>
}
else if(Model.SoundSynths[i].SoundSynth.Depth != 0)
{
<tr>
<td>@Model.SoundSynths[i].SoundSynth.Depth bits</td>
</tr>
}
else
{
<tr>
<td>@(Model.SoundSynths[i].SoundSynth.Frequency > 1000 ? $"{Model.SoundSynths[i].SoundSynth.Frequency / 1000}KHz" : $"{Model.SoundSynths[i].SoundSynth.Frequency}Hz")</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Type != 0)
{
<tr>
<td>Synthetizer type</td>
<td>
@Model.SoundSynths[i].SoundSynth.Type
</td>
</tr>
}
</table>
</div>
</div>
</td>
}
} }
else else
{ {
<td> <td>Unknown data</td>
@($"{Model.Gpus[i].Gpu.Name}")
<a aria-controls="@($"synthInfo{i}")"
aria-expanded="false"
class="btn btn-link"
data-toggle="collapse"
href="@($"#synthInfo{i}")">
+info
</a>
<div class="collapse"
id="@($"synthInfo{i}")">
<div class="card card-body">
<table>
@if(Model.SoundSynths[i].SoundSynth.ModelCode != null && Model.SoundSynths[i].SoundSynth.ModelCode != Model.SoundSynths[i].SoundSynth.Name)
{
<tr>
<td>Model</td>
<td>@Model.SoundSynths[i].SoundSynth.ModelCode</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Company != null)
{
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company
asp-action=View
asp-route-id=@Model.SoundSynths[i].SoundSynth.Company.Id>
@Model.SoundSynths[i].SoundSynth.Company.Name</a>
</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Introduced != DateTime.MinValue)
{
<tr>
<td>Introduction date</td>
<td>@($"{Model.Gpus[i].Gpu.Introduced:yyyy}")</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Voices != 0 || Model.SoundSynths[i].SoundSynth.SquareWave != 0 || Model.SoundSynths[i].SoundSynth.WhiteNoise != 0)
{
<tr>
<td>Generators</td>
<td>
<table>
@if(Model.SoundSynths[i].SoundSynth.Voices != 0)
{
<tr>
<td>@Model.SoundSynths[i].SoundSynth.Voices voices</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.SquareWave != 0)
{
<tr>
<td>@Model.SoundSynths[i].SoundSynth.SquareWave square wave</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.WhiteNoise != 0)
{
<tr>
<td>@Model.SoundSynths[i].SoundSynth.WhiteNoise white noise</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Depth != 0 || Model.SoundSynths[i].SoundSynth.Frequency > 0)
{
<tr>
<td>Sample rate</td>
<td>
<table>
@if(Model.SoundSynths[i].SoundSynth.Depth != 0 && Model.SoundSynths[i].SoundSynth.Frequency > 0)
{
<tr>
<td>@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")</td>
</tr>
}
else if(Model.SoundSynths[i].SoundSynth.Depth != 0)
{
<tr>
<td>@Model.SoundSynths[i].SoundSynth.Depth bits</td>
</tr>
}
else
{
<tr>
<td>@(Model.SoundSynths[i].SoundSynth.Frequency > 1000 ? $"{Model.SoundSynths[i].SoundSynth.Frequency / 1000}KHz" : $"{Model.SoundSynths[i].SoundSynth.Frequency}Hz")</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.SoundSynths[i].SoundSynth.Type != 0)
{
<tr>
<td>Synthetizer type</td>
<td>
@Model.SoundSynths[i].SoundSynth.Type
</td>
</tr>
}
</table>
</div>
</div>
</td>
} }
} </tr>
else
{
<td>Unknown data</td>
}
} }
</table> </table>
</td> </td>

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<Version>3.0.99.226</Version> <Version>3.0.99.232</Version>
<Company>Canary Islands Computer Museum</Company> <Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright> <Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product> <Product>Canary Islands Computer Museum Website</Product>