Update DB to version 14: Computers and consoles are now machines with different type.

This commit is contained in:
2018-04-28 02:10:03 +01:00
parent 40d07af9c5
commit d8127630b3
28 changed files with 1694 additions and 2209 deletions

View File

@@ -32,7 +32,6 @@ using System;
using System.Collections.Generic;
using System.Data;
using Cicm.Database.Schemas;
using Console = System.Console;
namespace Cicm.Database
{
@@ -43,7 +42,7 @@ namespace Cicm.Database
/// </summary>
/// <param name="entries">All computers</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetComputers(out List<Computer> entries)
public bool GetComputers(out List<Machine> entries)
{
#if DEBUG
Console.WriteLine("Getting all computers...");
@@ -51,16 +50,16 @@ namespace Cicm.Database
try
{
const string SQL = "SELECT * from computers";
string sql = $"SELECT * FROM machines WHERE type = '{(int)MachineType.Computer}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = ComputersFromDataTable(dataSet.Tables[0]);
entries = MachinesFromDataTable(dataSet.Tables[0]);
return true;
}
@@ -79,7 +78,7 @@ namespace Cicm.Database
/// <param name="entries">All computers</param>
/// <param name="company">Company id</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetComputers(out List<Computer> entries, int company)
public bool GetComputers(out List<Machine> entries, int company)
{
#if DEBUG
Console.WriteLine("Getting all computers from company id {0}...", company);
@@ -87,16 +86,16 @@ namespace Cicm.Database
try
{
const string SQL = "SELECT * from computers WHERE company = '{id}'";
string sql = $"SELECT * FROM machines WHERE company = '{company}' AND type = '{(int)MachineType.Computer}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = ComputersFromDataTable(dataSet.Tables[0]);
entries = MachinesFromDataTable(dataSet.Tables[0]);
return true;
}
@@ -116,7 +115,7 @@ namespace Cicm.Database
/// <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 GetComputers(out List<Computer> entries, ulong start, ulong count)
public bool GetComputers(out List<Machine> entries, ulong start, ulong count)
{
#if DEBUG
Console.WriteLine("Getting {0} computers from {1}...", count, start);
@@ -124,7 +123,7 @@ namespace Cicm.Database
try
{
string sql = $"SELECT * FROM computers LIMIT {start}, {count}";
string sql = $"SELECT * FROM machines LIMIT {start}, {count} WHERE type = '{(int)MachineType.Computer}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
@@ -133,7 +132,7 @@ namespace Cicm.Database
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = ComputersFromDataTable(dataSet.Tables[0]);
entries = MachinesFromDataTable(dataSet.Tables[0]);
return true;
}
@@ -151,33 +150,9 @@ namespace Cicm.Database
/// </summary>
/// <param name="id">Id</param>
/// <returns>Computer with specified id, <c>null</c> if not found or error</returns>
public Computer GetComputer(int id)
public Machine GetComputer(int id)
{
#if DEBUG
Console.WriteLine("Getting computer with id {0}...", id);
#endif
try
{
string sql = $"SELECT * from computers 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<Computer> entries = ComputersFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting computer.");
Console.WriteLine(ex);
return null;
}
return GetMachine(id);
}
/// <summary>
@@ -191,7 +166,7 @@ namespace Cicm.Database
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = "SELECT COUNT(*) FROM computers";
dbcmd.CommandText = $"SELECT COUNT(*) FROM computers WHERE type = '{(int)MachineType.Computer}'";
object count = dbcmd.ExecuteScalar();
dbcmd.Dispose();
try { return Convert.ToInt64(count); }
@@ -204,33 +179,10 @@ namespace Cicm.Database
/// <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 AddComputer(Computer entry, out long id)
public bool AddComputer(Machine entry, out long id)
{
#if DEBUG
Console.Write("Adding computer `{0}`...", entry.Model);
#endif
IDbCommand dbcmd = GetCommandComputer(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
const string SQL =
"INSERT INTO computers (company, year, model, cpu1, mhz1, cpu2, mhz2, bits, ram, rom, gpu, vram, colors, res, sound_synth, music_synth, sound_channels, music_channels, hdd1, hdd2, hdd3, disk1, cap1, disk2, cap2)" +
" VALUES (@company, @year, @model, @cpu1, @mhz1, @cpu2, @mhz2, @bits, @ram, @rom, @gpu, @vram, @colors, @res, @sound_synth, @music_synth, @sound_channels, @music_channels, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, @cap2)";
dbcmd.CommandText = SQL;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
id = dbCore.LastInsertRowId;
#if DEBUG
Console.WriteLine(" id {0}", id);
#endif
return true;
entry.Type = MachineType.Computer;
return AddMachine(entry, out id);
}
/// <summary>
@@ -238,29 +190,9 @@ namespace Cicm.Database
/// </summary>
/// <param name="entry">Updated entry</param>
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
public bool UpdateComputer(Computer entry)
public bool UpdateComputer(Machine entry)
{
#if DEBUG
Console.WriteLine("Updating computer `{0}`...", entry.Model);
#endif
IDbCommand dbcmd = GetCommandComputer(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql =
"UPDATE computers SET company = @company, year = @year, model = @model, cpu1 = @cpu1, mhz1 = @mhz1, cpu2 = @cpu2, " +
"mhz2 = @mhz2, bits = @bits, ram = @ram, rom = @rom, gpu = @gpu, vram = @vram, colors = @colors, res = @res, sound_synth = @sound_synth, music_synth = @music_synth " +
"sound_channels = @sound_channels, music_channels = @music_channels, hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, cap1 = @cap1, disk2 = @disk2, cap2 = @cap2 " +
$"WHERE id = {entry.Id}";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
return UpdateMachine(entry);
}
/// <summary>
@@ -270,202 +202,7 @@ namespace Cicm.Database
/// <returns><c>true</c> if removed correctly, <c>false</c> otherwise</returns>
public bool RemoveComputer(long id)
{
#if DEBUG
Console.WriteLine("Removing computer widh id `{0}`...", id);
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = $"DELETE FROM computers WHERE id = '{id}';";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
IDbCommand GetCommandComputer(Computer entry)
{
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 param12 = dbcmd.CreateParameter();
IDbDataParameter param13 = dbcmd.CreateParameter();
IDbDataParameter param14 = dbcmd.CreateParameter();
IDbDataParameter param15 = dbcmd.CreateParameter();
IDbDataParameter param16 = dbcmd.CreateParameter();
IDbDataParameter param17 = dbcmd.CreateParameter();
IDbDataParameter param18 = dbcmd.CreateParameter();
IDbDataParameter param19 = dbcmd.CreateParameter();
IDbDataParameter param20 = dbcmd.CreateParameter();
IDbDataParameter param21 = dbcmd.CreateParameter();
IDbDataParameter param22 = dbcmd.CreateParameter();
IDbDataParameter param23 = dbcmd.CreateParameter();
IDbDataParameter param24 = dbcmd.CreateParameter();
IDbDataParameter param25 = dbcmd.CreateParameter();
param1.ParameterName = "@company";
param2.ParameterName = "@year";
param3.ParameterName = "@model";
param4.ParameterName = "@cpu1";
param5.ParameterName = "@mhz1";
param6.ParameterName = "@cpu2";
param7.ParameterName = "@mhz2";
param8.ParameterName = "@bits";
param9.ParameterName = "@ram";
param10.ParameterName = "@rom";
param11.ParameterName = "@gpu";
param12.ParameterName = "@vram";
param13.ParameterName = "@colors";
param14.ParameterName = "@res";
param15.ParameterName = "@sound_synth";
param16.ParameterName = "@music_synth";
param17.ParameterName = "@sound_channels";
param18.ParameterName = "@music_channels";
param19.ParameterName = "@hdd1";
param20.ParameterName = "@hdd2";
param21.ParameterName = "@hdd3";
param22.ParameterName = "@disk1";
param23.ParameterName = "@cap1";
param24.ParameterName = "@disk2";
param25.ParameterName = "@cap2";
param1.DbType = DbType.Int32;
param2.DbType = DbType.Int32;
param3.DbType = DbType.String;
param4.DbType = DbType.Int32;
param5.DbType = DbType.Double;
param6.DbType = DbType.Int32;
param7.DbType = DbType.Double;
param8.DbType = DbType.Int32;
param9.DbType = DbType.Int32;
param10.DbType = DbType.Int32;
param11.DbType = DbType.Int32;
param12.DbType = DbType.Int32;
param13.DbType = DbType.Int32;
param14.DbType = DbType.String;
param15.DbType = DbType.Int32;
param16.DbType = DbType.Int32;
param17.DbType = DbType.Int32;
param18.DbType = DbType.Int32;
param19.DbType = DbType.Int32;
param20.DbType = DbType.Int32;
param21.DbType = DbType.Int32;
param22.DbType = DbType.Int32;
param23.DbType = DbType.String;
param24.DbType = DbType.Int32;
param25.DbType = DbType.String;
param1.Value = entry.Company;
param2.Value = entry.Year;
param3.Value = entry.Model;
param4.Value = entry.Cpu1;
param5.Value = entry.Mhz1;
param6.Value = entry.Cpu2;
param7.Value = entry.Mhz2;
param8.Value = entry.Bits;
param9.Value = entry.Ram;
param10.Value = entry.Rom;
param11.Value = entry.Gpu;
param12.Value = entry.Vram;
param13.Value = entry.Colors;
param14.Value = entry.Resolution;
param15.Value = entry.SoundSynth;
param16.Value = entry.MusicSynth;
param17.Value = entry.SoundChannels;
param18.Value = entry.MusicChannels;
param19.Value = entry.Hdd1;
param20.Value = entry.Hdd2;
param21.Value = entry.Hdd3;
param22.Value = entry.Disk1;
param23.Value = entry.Cap1;
param24.Value = entry.Disk2;
param25.Value = entry.Cap2;
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);
dbcmd.Parameters.Add(param12);
dbcmd.Parameters.Add(param13);
dbcmd.Parameters.Add(param14);
dbcmd.Parameters.Add(param15);
dbcmd.Parameters.Add(param16);
dbcmd.Parameters.Add(param17);
dbcmd.Parameters.Add(param18);
dbcmd.Parameters.Add(param19);
dbcmd.Parameters.Add(param20);
dbcmd.Parameters.Add(param21);
dbcmd.Parameters.Add(param22);
dbcmd.Parameters.Add(param23);
dbcmd.Parameters.Add(param24);
dbcmd.Parameters.Add(param25);
return dbcmd;
}
static List<Computer> ComputersFromDataTable(DataTable dataTable)
{
List<Computer> entries = new List<Computer>();
foreach(DataRow dataRow in dataTable.Rows)
{
Computer entry = new Computer
{
Id = (int)dataRow["id"],
Company = (int)dataRow["company"],
Year = (int)dataRow["year"],
Model = (string)dataRow["model"],
Cpu1 = dataRow["cpu1"] == DBNull.Value ? 0 : (int)dataRow["cpu1"],
Mhz1 = dataRow["mhz1"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz1"].ToString()),
Cpu2 = dataRow["cpu2"] == DBNull.Value ? 0 : (int)dataRow["cpu2"],
Mhz2 = dataRow["mhz2"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz2"].ToString()),
Bits = (int)dataRow["bits"],
Ram = (int)dataRow["ram"],
Rom = (int)dataRow["rom"],
Gpu = dataRow["gpu"] == DBNull.Value ? 0 : (int)dataRow["gpu"],
Vram = (int)dataRow["vram"],
Colors = (int)dataRow["colors"],
Resolution = (string)dataRow["res"],
SoundSynth = (int)dataRow["sound_synth"],
MusicSynth = (int)dataRow["music_synth"],
SoundChannels = (int)dataRow["sound_channels"],
MusicChannels = (int)dataRow["music_channels"],
Hdd1 = (int)dataRow["hdd1"],
Hdd2 = dataRow["hdd2"] == DBNull.Value ? 0 : (int)dataRow["hdd2"],
Hdd3 = dataRow["hdd3"] == DBNull.Value ? 0 : (int)dataRow["hdd3"],
Disk1 = (int)dataRow["disk1"],
Cap1 = (string)dataRow["cap1"],
Disk2 = dataRow["disk2"] == DBNull.Value ? 0 : (int)dataRow["disk2"],
Cap2 = dataRow["cap2"] == DBNull.Value ? null : (string)dataRow["cap2"]
};
entries.Add(entry);
}
return entries;
return RemoveMachine(id);
}
}
}

View File

@@ -31,7 +31,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using Console = Cicm.Database.Schemas.Console;
using Cicm.Database.Schemas;
namespace Cicm.Database
{
@@ -42,31 +42,31 @@ namespace Cicm.Database
/// </summary>
/// <param name="entries">All consoles</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetConsoles(out List<Console> entries)
public bool GetConsoles(out List<Machine> entries)
{
#if DEBUG
System.Console.WriteLine("Getting all consoles...");
Console.WriteLine("Getting all consoles...");
#endif
try
{
const string SQL = "SELECT * from consoles";
string sql = $"SELECT * FROM machines WHERE type = '{(int)MachineType.Console}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = ConsolesFromDataTable(dataSet.Tables[0]);
entries = MachinesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
System.Console.WriteLine("Error getting consoles.");
System.Console.WriteLine(ex);
Console.WriteLine("Error getting consoles.");
Console.WriteLine(ex);
entries = null;
return false;
}
@@ -78,31 +78,31 @@ namespace Cicm.Database
/// <param name="entries">All consoles</param>
/// <param name="company">Company id</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetConsoles(out List<Console> entries, int company)
public bool GetConsoles(out List<Machine> entries, int company)
{
#if DEBUG
System.Console.WriteLine("Getting all consoles from company id {0}...", company);
Console.WriteLine("Getting all consoles from company id {0}...", company);
#endif
try
{
const string SQL = "SELECT * from consoles WHERE company = '{id}'";
string sql = $"SELECT * FROM machines WHERE company = '{company}' AND type = '{(int)MachineType.Console}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = ConsolesFromDataTable(dataSet.Tables[0]);
entries = MachinesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
System.Console.WriteLine("Error getting consoles.");
System.Console.WriteLine(ex);
Console.WriteLine("Error getting consoles.");
Console.WriteLine(ex);
entries = null;
return false;
}
@@ -115,15 +115,15 @@ namespace Cicm.Database
/// <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 GetConsoles(out List<Console> entries, ulong start, ulong count)
public bool GetConsoles(out List<Machine> entries, ulong start, ulong count)
{
#if DEBUG
System.Console.WriteLine("Getting {0} consoles from {1}...", count, start);
Console.WriteLine("Getting {0} consoles from {1}...", count, start);
#endif
try
{
string sql = $"SELECT * FROM consoles LIMIT {start}, {count}";
string sql = $"SELECT * FROM machines WHERE type = '{(int)MachineType.Console}' LIMIT {start}, {count}";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
@@ -132,14 +132,14 @@ namespace Cicm.Database
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = ConsolesFromDataTable(dataSet.Tables[0]);
entries = MachinesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
System.Console.WriteLine("Error getting consoles.");
System.Console.WriteLine(ex);
Console.WriteLine("Error getting consoles.");
Console.WriteLine(ex);
entries = null;
return false;
}
@@ -150,33 +150,9 @@ namespace Cicm.Database
/// </summary>
/// <param name="id">Id</param>
/// <returns>Videogame console with specified id, <c>null</c> if not found or error</returns>
public Console GetConsole(int id)
public Machine GetConsole(int id)
{
#if DEBUG
System.Console.WriteLine("Getting console with id {0}...", id);
#endif
try
{
string sql = $"SELECT * from consoles 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<Console> entries = ConsolesFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
System.Console.WriteLine("Error getting console.");
System.Console.WriteLine(ex);
return null;
}
return GetMachine(id);
}
/// <summary>
@@ -186,11 +162,11 @@ namespace Cicm.Database
public long CountConsoles()
{
#if DEBUG
System.Console.WriteLine("Counting consoles...");
Console.WriteLine("Counting consoles...");
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = "SELECT COUNT(*) FROM consoles";
dbcmd.CommandText = $"SELECT COUNT(*) FROM consoles WHERE type = '{(int)MachineType.Console}'";
object count = dbcmd.ExecuteScalar();
dbcmd.Dispose();
try { return Convert.ToInt64(count); }
@@ -203,33 +179,10 @@ namespace Cicm.Database
/// <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 AddConsole(Console entry, out long id)
public bool AddConsole(Machine entry, out long id)
{
#if DEBUG
System.Console.Write("Adding console `{0}`...", entry.Model);
#endif
IDbCommand dbcmd = GetCommandConsole(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
const string SQL =
"INSERT INTO consoles (company, year, model, cpu1, mhz1, cpu2, mhz2, bits, ram, rom, gpu, vram, colors, res, sound_synth, music_synth, schannels, mchannels, palette, format, cap)" +
" VALUES (@company, @year, @model, @cpu1, @mhz1, @cpu2, @mhz2, @bits, @ram, @rom, @gpu, @vram, @colors, @res, @sound_synth, @music_synth, @schannels, @mchannels, @palette, @format, @cap)";
dbcmd.CommandText = SQL;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
id = dbCore.LastInsertRowId;
#if DEBUG
System.Console.WriteLine(" id {0}", id);
#endif
return true;
entry.Type = MachineType.Console;
return AddMachine(entry, out id);
}
/// <summary>
@@ -237,29 +190,9 @@ namespace Cicm.Database
/// </summary>
/// <param name="entry">Updated entry</param>
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
public bool UpdateConsole(Console entry)
public bool UpdateConsole(Machine entry)
{
#if DEBUG
System.Console.WriteLine("Updating console `{0}`...", entry.Model);
#endif
IDbCommand dbcmd = GetCommandConsole(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql =
"UPDATE consoles SET company = @company, year = @year, model = @model, cpu1 = @cpu1, mhz1 = @mhz1, cpu2 = @cpu2, " +
"mhz2 = @mhz2, bits = @bits, ram = @ram, rom = @rom, gpu = @gpu, vram = @vram, colors = @colors, res = @res, sound_synth = @sound_synth, music_synth = @music_synth " +
"schannels = @schannels, mchannels = @mchannels, palette = @palette, format = @format, cap = @cap " +
$"WHERE id = {entry.Id}";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
return UpdateMachine(entry);
}
/// <summary>
@@ -269,178 +202,7 @@ namespace Cicm.Database
/// <returns><c>true</c> if removed correctly, <c>false</c> otherwise</returns>
public bool RemoveConsole(long id)
{
#if DEBUG
System.Console.WriteLine("Removing console widh id `{0}`...", id);
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = $"DELETE FROM consoles WHERE id = '{id}';";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
IDbCommand GetCommandConsole(Console entry)
{
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 param12 = dbcmd.CreateParameter();
IDbDataParameter param13 = dbcmd.CreateParameter();
IDbDataParameter param14 = dbcmd.CreateParameter();
IDbDataParameter param15 = dbcmd.CreateParameter();
IDbDataParameter param16 = dbcmd.CreateParameter();
IDbDataParameter param17 = dbcmd.CreateParameter();
IDbDataParameter param18 = dbcmd.CreateParameter();
IDbDataParameter param19 = dbcmd.CreateParameter();
IDbDataParameter param20 = dbcmd.CreateParameter();
IDbDataParameter param21 = dbcmd.CreateParameter();
param1.ParameterName = "@company";
param2.ParameterName = "@year";
param3.ParameterName = "@model";
param4.ParameterName = "@cpu1";
param5.ParameterName = "@mhz1";
param6.ParameterName = "@cpu2";
param7.ParameterName = "@mhz2";
param8.ParameterName = "@bits";
param9.ParameterName = "@ram";
param10.ParameterName = "@rom";
param11.ParameterName = "@gpu";
param12.ParameterName = "@vram";
param13.ParameterName = "@colors";
param14.ParameterName = "@res";
param15.ParameterName = "@sound_synth";
param16.ParameterName = "@music_synth";
param17.ParameterName = "@schannels";
param18.ParameterName = "@mchannels";
param19.ParameterName = "@palette";
param20.ParameterName = "@format";
param21.ParameterName = "@cap";
param1.DbType = DbType.Int32;
param2.DbType = DbType.Int32;
param3.DbType = DbType.String;
param4.DbType = DbType.Int32;
param5.DbType = DbType.Double;
param6.DbType = DbType.Int32;
param7.DbType = DbType.Double;
param8.DbType = DbType.Int32;
param9.DbType = DbType.Int32;
param10.DbType = DbType.Int32;
param11.DbType = DbType.Int32;
param12.DbType = DbType.Int32;
param13.DbType = DbType.Int32;
param14.DbType = DbType.String;
param15.DbType = DbType.Int32;
param16.DbType = DbType.Int32;
param17.DbType = DbType.Int32;
param18.DbType = DbType.Int32;
param19.DbType = DbType.Int32;
param20.DbType = DbType.Int32;
param21.DbType = DbType.Int32;
param1.Value = entry.Company;
param2.Value = entry.Year;
param3.Value = entry.Model;
param4.Value = entry.Cpu1;
param5.Value = entry.Mhz1;
param6.Value = entry.Cpu2;
param7.Value = entry.Mhz2;
param8.Value = entry.Bits;
param9.Value = entry.Ram;
param10.Value = entry.Rom;
param11.Value = entry.Gpu;
param12.Value = entry.Vram;
param13.Value = entry.Colors;
param14.Value = entry.Resolution;
param15.Value = entry.SoundSynth;
param16.Value = entry.MusicSynth;
param17.Value = entry.SoundChannels;
param18.Value = entry.MusicChannels;
param19.Value = entry.Palette;
param20.Value = entry.Format;
param21.Value = entry.Cap;
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);
dbcmd.Parameters.Add(param12);
dbcmd.Parameters.Add(param13);
dbcmd.Parameters.Add(param14);
dbcmd.Parameters.Add(param15);
dbcmd.Parameters.Add(param16);
dbcmd.Parameters.Add(param17);
dbcmd.Parameters.Add(param18);
dbcmd.Parameters.Add(param19);
dbcmd.Parameters.Add(param20);
dbcmd.Parameters.Add(param21);
return dbcmd;
}
static List<Console> ConsolesFromDataTable(DataTable dataTable)
{
List<Console> entries = new List<Console>();
foreach(DataRow dataRow in dataTable.Rows)
{
Console entry = new Console
{
Id = (int)dataRow["id"],
Company = (int)dataRow["company"],
Year = (int)dataRow["year"],
Model = (string)dataRow["model"],
Cpu1 = dataRow["cpu1"] == DBNull.Value ? 0 : (int)dataRow["cpu1"],
Mhz1 = dataRow["mhz1"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz1"].ToString()),
Cpu2 = dataRow["cpu2"] == DBNull.Value ? 0 : (int)dataRow["cpu2"],
Mhz2 = dataRow["mhz2"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz2"].ToString()),
Bits = (int)dataRow["bits"],
Ram = (int)dataRow["ram"],
Rom = (int)dataRow["rom"],
Gpu = dataRow["gpu"] == DBNull.Value ? 0 : (int)dataRow["gpu"],
Vram = (int)dataRow["vram"],
Colors = (int)dataRow["colors"],
Resolution = (string)dataRow["res"],
SoundSynth = (int)dataRow["sound_synth"],
MusicSynth = (int)dataRow["music_synth"],
SoundChannels = (int)dataRow["schannels"],
MusicChannels = (int)dataRow["mchannels"],
Palette = (int)dataRow["palette"],
Format = (int)dataRow["format"],
Cap = (int)dataRow["cap"]
};
entries.Add(entry);
}
return entries;
return RemoveMachine(id);
}
}
}

View File

@@ -49,107 +49,99 @@ namespace Cicm.Database
IDbCommand dbCmd = dbCon.CreateCommand();
Console.WriteLine("Creating table `admins`");
dbCmd.CommandText = V13.Admins;
dbCmd.CommandText = V14.Admins;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `browser_tests`");
dbCmd.CommandText = V13.BrowserTests;
dbCmd.CommandText = V14.BrowserTests;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `cicm_db`");
dbCmd.CommandText = V13.CicmDb;
dbCmd.CommandText = V14.CicmDb;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `companies`");
dbCmd.CommandText = V13.Companies;
dbCmd.CommandText = V14.Companies;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `computers`");
dbCmd.CommandText = V13.Computers;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `consoles`");
dbCmd.CommandText = V13.Consoles;
Console.WriteLine("Creating table `machines`");
dbCmd.CommandText = V14.Machines;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `disk_formats`");
dbCmd.CommandText = V13.DiskFormats;
dbCmd.CommandText = V14.DiskFormats;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `forbidden`");
dbCmd.CommandText = V13.Forbidden;
dbCmd.CommandText = V14.Forbidden;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus`");
dbCmd.CommandText = V13.Gpus;
dbCmd.CommandText = V14.Gpus;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `log`");
dbCmd.CommandText = V13.Logs;
dbCmd.CommandText = V14.Logs;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `money_donations`");
dbCmd.CommandText = V13.MoneyDonations;
dbCmd.CommandText = V14.MoneyDonations;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `news`");
dbCmd.CommandText = V13.News;
dbCmd.CommandText = V14.News;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_computers`");
dbCmd.CommandText = V13.OwnedComputers;
dbCmd.CommandText = V14.OwnedComputers;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_consoles`");
dbCmd.CommandText = V13.OwnedConsoles;
dbCmd.CommandText = V14.OwnedConsoles;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_sets`");
dbCmd.CommandText = V13.InstructionSets;
dbCmd.CommandText = V14.InstructionSets;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions`");
dbCmd.CommandText = V13.InstructionSetExtensions;
dbCmd.CommandText = V14.InstructionSetExtensions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `processors`");
dbCmd.CommandText = V13.Processors;
dbCmd.CommandText = V14.Processors;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions_by_processor`");
dbCmd.CommandText = V13.InstructionSetExtensionsByProcessor;
dbCmd.CommandText = V14.InstructionSetExtensionsByProcessor;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `sound_synths`");
dbCmd.CommandText = V13.SoundSynths;
dbCmd.CommandText = V14.SoundSynths;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `iso3166_1_numeric`");
dbCmd.CommandText = V13.Iso3166Numeric;
dbCmd.CommandText = V14.Iso3166Numeric;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Filling table `iso3166_1_numeric`");
dbCmd.CommandText = V13.Iso3166NumericValues;
dbCmd.CommandText = V14.Iso3166NumericValues;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `companies`");
dbCmd.CommandText = V13.CompaniesForeignKeys;
dbCmd.CommandText = V14.CompaniesForeignKeys;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `computers`");
dbCmd.CommandText = V13.ComputersForeignKeys;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `consoles`");
dbCmd.CommandText = V13.ConsolesForeignKeys;
Console.WriteLine("Creating foreign keys for table `machines`");
dbCmd.CommandText = V14.MachinesForeignKeys;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_logos`");
dbCmd.CommandText = V13.CompanyLogos;
dbCmd.CommandText = V14.CompanyLogos;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_descriptions`");
dbCmd.CommandText = V13.CompanyDescriptions;
dbCmd.CommandText = V14.CompanyDescriptions;
dbCmd.ExecuteNonQuery();
return true;

View File

@@ -0,0 +1,470 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Machine.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains operations to manage machines.
//
// --[ 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 machines
/// </summary>
/// <param name="entries">All machines</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMachines(out List<Machine> entries)
{
#if DEBUG
Console.WriteLine("Getting all machines...");
#endif
try
{
const string SQL = "SELECT * from machines";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = MachinesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting machines.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets all machines from specified company
/// </summary>
/// <param name="entries">All machines</param>
/// <param name="company">Company id</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMachines(out List<Machine> entries, int company)
{
#if DEBUG
Console.WriteLine("Getting all machines from company id {0}...", company);
#endif
try
{
const string SQL = "SELECT * from machines WHERE company = '{id}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = MachinesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting machines.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets the specified number of machines since the specified start
/// </summary>
/// <param name="entries">List of machines</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 GetMachines(out List<Machine> entries, ulong start, ulong count)
{
#if DEBUG
Console.WriteLine("Getting {0} machines from {1}...", count, start);
#endif
try
{
string sql = $"SELECT * FROM machines 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 = MachinesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting machines.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets machine by specified id
/// </summary>
/// <param name="id">Id</param>
/// <returns>Machine with specified id, <c>null</c> if not found or error</returns>
public Machine GetMachine(int id)
{
#if DEBUG
Console.WriteLine("Getting machine with id {0}...", id);
#endif
try
{
string sql = $"SELECT * from machines 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<Machine> entries = MachinesFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting machine.");
Console.WriteLine(ex);
return null;
}
}
/// <summary>
/// Counts the number of machines in the database
/// </summary>
/// <returns>Entries in database</returns>
public long CountMachines()
{
#if DEBUG
Console.WriteLine("Counting machines...");
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = "SELECT COUNT(*) FROM machines";
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 AddMachine(Machine entry, out long id)
{
#if DEBUG
Console.Write("Adding machine `{0}`...", entry.Model);
#endif
IDbCommand dbcmd = GetCommandMachine(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
const string SQL =
"INSERT INTO machines (company, year, model, cpu1, mhz1, cpu2, mhz2, ram, rom, gpu, vram, colors, res, sound_synth, music_synth, sound_channels, music_channels, hdd1, hdd2, hdd3, disk1, cap1, disk2, cap2, type)" +
" VALUES (@company, @year, @model, @cpu1, @mhz1, @cpu2, @mhz2, @ram, @rom, @gpu, @vram, @colors, @res, @sound_synth, @music_synth, @sound_channels, @music_channels, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, @cap2, @type)";
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 in the database
/// </summary>
/// <param name="entry">Updated entry</param>
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
public bool UpdateMachine(Machine entry)
{
#if DEBUG
Console.WriteLine("Updating machine `{0}`...", entry.Model);
#endif
IDbCommand dbcmd = GetCommandMachine(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql =
"UPDATE machines SET company = @company, year = @year, model = @model, cpu1 = @cpu1, mhz1 = @mhz1, cpu2 = @cpu2, " +
"mhz2 = @mhz2, ram = @ram, rom = @rom, gpu = @gpu, vram = @vram, colors = @colors, res = @res, sound_synth = @sound_synth, music_synth = @music_synth " +
"sound_channels = @sound_channels, music_channels = @music_channels, hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, cap1 = @cap1, disk2 = @disk2, cap2 = @cap2, type = @type " +
$"WHERE id = {entry.Id}";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
/// <summary>
/// Removes a machine 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 RemoveMachine(long id)
{
#if DEBUG
Console.WriteLine("Removing machine widh id `{0}`...", id);
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = $"DELETE FROM machines WHERE id = '{id}';";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
IDbCommand GetCommandMachine(Machine entry)
{
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 param12 = dbcmd.CreateParameter();
IDbDataParameter param13 = dbcmd.CreateParameter();
IDbDataParameter param14 = dbcmd.CreateParameter();
IDbDataParameter param15 = dbcmd.CreateParameter();
IDbDataParameter param16 = dbcmd.CreateParameter();
IDbDataParameter param17 = dbcmd.CreateParameter();
IDbDataParameter param18 = dbcmd.CreateParameter();
IDbDataParameter param19 = dbcmd.CreateParameter();
IDbDataParameter param20 = dbcmd.CreateParameter();
IDbDataParameter param21 = dbcmd.CreateParameter();
IDbDataParameter param22 = dbcmd.CreateParameter();
IDbDataParameter param23 = dbcmd.CreateParameter();
IDbDataParameter param24 = dbcmd.CreateParameter();
IDbDataParameter param25 = dbcmd.CreateParameter();
param1.ParameterName = "@company";
param2.ParameterName = "@year";
param3.ParameterName = "@model";
param4.ParameterName = "@cpu1";
param5.ParameterName = "@mhz1";
param6.ParameterName = "@cpu2";
param7.ParameterName = "@mhz2";
param8.ParameterName = "@ram";
param9.ParameterName = "@rom";
param10.ParameterName = "@gpu";
param11.ParameterName = "@vram";
param12.ParameterName = "@colors";
param13.ParameterName = "@res";
param14.ParameterName = "@sound_synth";
param15.ParameterName = "@music_synth";
param16.ParameterName = "@sound_channels";
param17.ParameterName = "@music_channels";
param18.ParameterName = "@hdd1";
param19.ParameterName = "@hdd2";
param20.ParameterName = "@hdd3";
param21.ParameterName = "@disk1";
param22.ParameterName = "@cap1";
param23.ParameterName = "@disk2";
param24.ParameterName = "@cap2";
param25.ParameterName = "@type";
param1.DbType = DbType.Int32;
param2.DbType = DbType.Int32;
param3.DbType = DbType.String;
param4.DbType = DbType.Int32;
param5.DbType = DbType.Double;
param6.DbType = DbType.Int32;
param7.DbType = DbType.Double;
param8.DbType = DbType.Int32;
param9.DbType = DbType.Int32;
param10.DbType = DbType.Int32;
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;
param18.DbType = DbType.Int32;
param19.DbType = DbType.Int32;
param20.DbType = DbType.Int32;
param21.DbType = DbType.Int32;
param22.DbType = DbType.String;
param23.DbType = DbType.Int32;
param24.DbType = DbType.String;
param25.DbType = DbType.Int32;
param1.Value = entry.Company;
param2.Value = entry.Year;
param3.Value = entry.Model;
param4.Value = entry.Cpu1;
param5.Value = entry.Mhz1;
param6.Value = entry.Cpu2;
param7.Value = entry.Mhz2;
param8.Value = entry.Ram;
param9.Value = entry.Rom;
param10.Value = entry.Gpu;
param11.Value = entry.Vram;
param12.Value = entry.Colors;
param13.Value = entry.Resolution;
param14.Value = entry.SoundSynth;
param15.Value = entry.MusicSynth;
param16.Value = entry.SoundChannels;
param17.Value = entry.MusicChannels;
param18.Value = entry.Hdd1;
param19.Value = entry.Hdd2;
param20.Value = entry.Hdd3;
param21.Value = entry.Disk1;
param22.Value = entry.Cap1;
param23.Value = entry.Disk2;
param24.Value = entry.Cap2;
param25.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);
dbcmd.Parameters.Add(param12);
dbcmd.Parameters.Add(param13);
dbcmd.Parameters.Add(param14);
dbcmd.Parameters.Add(param15);
dbcmd.Parameters.Add(param16);
dbcmd.Parameters.Add(param17);
dbcmd.Parameters.Add(param18);
dbcmd.Parameters.Add(param19);
dbcmd.Parameters.Add(param20);
dbcmd.Parameters.Add(param21);
dbcmd.Parameters.Add(param22);
dbcmd.Parameters.Add(param23);
dbcmd.Parameters.Add(param24);
dbcmd.Parameters.Add(param25);
return dbcmd;
}
static List<Machine> MachinesFromDataTable(DataTable dataTable)
{
List<Machine> entries = new List<Machine>();
foreach(DataRow dataRow in dataTable.Rows)
{
Machine entry = new Machine
{
Id = (int)dataRow["id"],
Company = (int)dataRow["company"],
Year = (int)dataRow["year"],
Model = (string)dataRow["model"],
Cpu1 = dataRow["cpu1"] == DBNull.Value ? 0 : (int)dataRow["cpu1"],
Mhz1 = dataRow["mhz1"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz1"].ToString()),
Cpu2 = dataRow["cpu2"] == DBNull.Value ? 0 : (int)dataRow["cpu2"],
Mhz2 = dataRow["mhz2"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz2"].ToString()),
Ram = (int)dataRow["ram"],
Rom = (int)dataRow["rom"],
Gpu = dataRow["gpu"] == DBNull.Value ? 0 : (int)dataRow["gpu"],
Vram = (int)dataRow["vram"],
Colors = (int)dataRow["colors"],
Resolution = (string)dataRow["res"],
SoundSynth = (int)dataRow["sound_synth"],
MusicSynth = (int)dataRow["music_synth"],
SoundChannels = (int)dataRow["sound_channels"],
MusicChannels = (int)dataRow["music_channels"],
Hdd1 = (int)dataRow["hdd1"],
Hdd2 = dataRow["hdd2"] == DBNull.Value ? 0 : (int)dataRow["hdd2"],
Hdd3 = dataRow["hdd3"] == DBNull.Value ? 0 : (int)dataRow["hdd3"],
Disk1 = (int)dataRow["disk1"],
Cap1 = (string)dataRow["cap1"],
Disk2 = dataRow["disk2"] == DBNull.Value ? 0 : (int)dataRow["disk2"],
Cap2 = dataRow["cap2"] == DBNull.Value ? null : (string)dataRow["cap2"],
Type = (MachineType)dataRow["type"]
};
entries.Add(entry);
}
return entries;
}
}
}

View File

@@ -35,7 +35,7 @@ namespace Cicm.Database
public partial class Operations
{
/// <summary>Last known database version</summary>
const int DB_VERSION = 13;
const int DB_VERSION = 14;
/// <summary>The column with this value indicates there is no item of this type.</summary>
public const int DB_NONE = -1;
/// <summary>This value indicates there's no GPU, but a direct memory->display connection (a framebuffer).</summary>

View File

@@ -32,6 +32,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using Cicm.Database.Schemas;
using Cicm.Database.Schemas.Sql;
namespace Cicm.Database
@@ -133,6 +134,11 @@ namespace Cicm.Database
UpdateDatabaseToV13();
break;
}
case 13:
{
UpdateDatabaseToV14();
break;
}
}
OptimizeDatabase();
@@ -1290,6 +1296,281 @@ namespace Cicm.Database
dbCmd.Dispose();
}
void UpdateDatabaseToV14()
{
Console.WriteLine("Updating database to version 14");
Console.WriteLine("Renaming table `computers` to `machines`");
IDbCommand dbCmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "ALTER TABLE `computers` RENAME TO `machines`;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Removing column `bits` from table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "ALTER TABLE `machines` DROP COLUMN `bits`;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Creating column `type` in table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText =
$"ALTER TABLE `machines` ADD COLUMN `type` INT NOT NULL DEFAULT '{(int)MachineType.Unknown}';";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Updating all entries in table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = $"UPDATE `machines` SET `type` = '{(int)MachineType.Computer}';";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Renaming all indexes on table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText =
"ALTER TABLE `machines` DROP INDEX `idx_computers_company`, ADD INDEX `idx_machines_company` (`company`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_year`, ADD INDEX `idx_machines_year` (`year`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_model`, ADD INDEX `idx_machines_model` (`model`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_cpu1`, ADD INDEX `idx_machines_cpu1` (`cpu1`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_cpu2`, ADD INDEX `idx_machines_cpu2` (`cpu2`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_mhz1`, ADD INDEX `idx_machines_mhz1` (`mhz1`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_mhz2`, ADD INDEX `idx_machines_mhz2` (`mhz2`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_ram`, ADD INDEX `idx_machines_ram` (`ram`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_rom`, ADD INDEX `idx_machines_rom` (`rom`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_gpu`, ADD INDEX `idx_machines_gpu` (`gpu`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_vram`, ADD INDEX `idx_machines_vram` (`vram`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_colors`, ADD INDEX `idx_machines_colors` (`colors`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_res`, ADD INDEX `idx_machines_res` (`res`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_sound_synth`, ADD INDEX `idx_machines_sound_synth` (`sound_synth`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_music_synth`, ADD INDEX `idx_machines_music_synth` (`music_synth`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_hdd1`, ADD INDEX `idx_machines_hdd1` (`hdd1`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_hdd2`, ADD INDEX `idx_machines_hdd2` (`hdd2`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_hdd3`, ADD INDEX `idx_machines_hdd3` (`hdd3`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_disk1`, ADD INDEX `idx_machines_disk1` (`disk1`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_disk2`, ADD INDEX `idx_machines_disk2` (`disk2`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_cap1`, ADD INDEX `idx_machines_cap1` (`cap1`);\n" +
"ALTER TABLE `machines` DROP INDEX `idx_computers_cap2`, ADD INDEX `idx_machines_cap2` (`cap2`);";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Removing old foreign keys from table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_company`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_cpu1`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_cpu2`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_disk1`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_disk2`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_gpu`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_hdd1`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_hdd2`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_hdd3`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_music_synth`;\n" +
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_sound_synth`;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Adding foreign keys in table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText =
"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_cpu1` (cpu1) REFERENCES `processors` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_cpu2` (cpu2) REFERENCES `processors` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_disk1` (disk1) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_disk2` (disk2) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_gpu` (gpu) REFERENCES `gpus` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd1` (hdd1) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd2` (hdd2) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd3` (hdd3) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_music_synth` (music_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_sound_synth` (sound_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Adding new index for `type` in table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "CREATE INDEX `idx_machines_type` ON `machines` (`type`);";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Getting all items from `consoles`");
dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = "SELECT * from consoles";
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();
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 param12 = dbcmd.CreateParameter();
IDbDataParameter param13 = dbcmd.CreateParameter();
IDbDataParameter param14 = dbcmd.CreateParameter();
IDbDataParameter param15 = dbcmd.CreateParameter();
IDbDataParameter param16 = dbcmd.CreateParameter();
IDbDataParameter param17 = dbcmd.CreateParameter();
IDbDataParameter param18 = dbcmd.CreateParameter();
IDbDataParameter param19 = dbcmd.CreateParameter();
IDbDataParameter param20 = dbcmd.CreateParameter();
IDbDataParameter param21 = dbcmd.CreateParameter();
param1.ParameterName = "@company";
param2.ParameterName = "@year";
param3.ParameterName = "@model";
param4.ParameterName = "@cpu1";
param5.ParameterName = "@mhz1";
param6.ParameterName = "@cpu2";
param7.ParameterName = "@mhz2";
param8.ParameterName = "@ram";
param9.ParameterName = "@rom";
param10.ParameterName = "@gpu";
param11.ParameterName = "@vram";
param12.ParameterName = "@colors";
param13.ParameterName = "@res";
param14.ParameterName = "@sound_synth";
param15.ParameterName = "@music_synth";
param16.ParameterName = "@sound_channels";
param17.ParameterName = "@music_channels";
param18.ParameterName = "@type";
param19.ParameterName = "@hdd1";
param20.ParameterName = "@disk1";
param21.ParameterName = "@cap1";
param1.DbType = DbType.Int32;
param2.DbType = DbType.Int32;
param3.DbType = DbType.String;
param4.DbType = DbType.Int32;
param5.DbType = DbType.Double;
param6.DbType = DbType.Int32;
param7.DbType = DbType.Double;
param8.DbType = DbType.Int32;
param9.DbType = DbType.Int32;
param10.DbType = DbType.Int32;
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;
param18.DbType = DbType.Int32;
param19.DbType = DbType.Int32;
param20.DbType = DbType.Int32;
param21.DbType = DbType.Int32;
param1.Value = (int)dataRow["company"];
param2.Value = (int)dataRow["year"];
param3.Value = (string)dataRow["model"];
param4.Value = dataRow["cpu1"] == DBNull.Value ? (object)null : (int)dataRow["cpu1"];
param5.Value = dataRow["mhz1"] == DBNull.Value ? (object)null : float.Parse(dataRow["mhz1"].ToString());
param6.Value = dataRow["cpu2"] == DBNull.Value ? (object)null : (int)dataRow["cpu2"];
param7.Value = dataRow["mhz2"] == DBNull.Value ? (object)null : float.Parse(dataRow["mhz2"].ToString());
param8.Value = (int)dataRow["ram"];
param9.Value = (int)dataRow["rom"];
param10.Value = dataRow["gpu"] == DBNull.Value ? (object)null : (int)dataRow["gpu"];
param11.Value = (int)dataRow["vram"];
param12.Value = (int)dataRow["colors"];
param13.Value = (string)dataRow["res"];
param14.Value = (int)dataRow["sound_synth"];
param15.Value = (int)dataRow["music_synth"];
param16.Value = (int)dataRow["schannels"];
param17.Value = (int)dataRow["mchannels"];
param18.Value = MachineType.Console;
param19.Value = 30;
param20.Value = 30;
param21.Value = 0;
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);
dbcmd.Parameters.Add(param12);
dbcmd.Parameters.Add(param13);
dbcmd.Parameters.Add(param14);
dbcmd.Parameters.Add(param15);
dbcmd.Parameters.Add(param16);
dbcmd.Parameters.Add(param17);
dbcmd.Parameters.Add(param18);
dbcmd.Parameters.Add(param19);
dbcmd.Parameters.Add(param20);
dbcmd.Parameters.Add(param21);
trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
Console.WriteLine("Converting console \"{0}\" to machine", (string)param3.Value);
const string SQL =
"INSERT INTO machines (company, year, model, cpu1, mhz1, cpu2, mhz2, ram, rom, gpu, vram, colors, res, sound_synth, music_synth, sound_channels, music_channels, type, hdd1, disk1, cap1)" +
" VALUES (@company, @year, @model, @cpu1, @mhz1, @cpu2, @mhz2, @ram, @rom, @gpu, @vram, @colors, @res, @sound_synth, @music_synth, @sound_channels, @music_channels, @type, @hdd1, @disk1, @cap1)";
dbcmd.CommandText = SQL;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
}
Console.WriteLine("Dropping table `consoles`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "DROP TABLE `consoles`;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Setting new database version to 14...");
dbCmd = dbCon.CreateCommand();
dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('14')";
dbCmd.ExecuteNonQuery();
dbCmd.Dispose();
}
void OptimizeDatabase()
{
IDbCommand dbCmd = dbCon.CreateCommand();

View File

@@ -1,80 +0,0 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Console.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// High level representation of a videogame console.
//
// --[ 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
{
public class Console
{
/// <summary>Bits of GPRs of primary CPU</summary>
public int Bits;
/// <summary>Capacity in kibibytes of storage format</summary>
public int Cap;
/// <summary>Maximum colors on screen</summary>
public int Colors;
/// <summary>Manufacturer's company ID</summary>
public int Company;
/// <summary>Primary CPU</summary>
public int Cpu1;
/// <summary>Secondary CPU</summary>
public int Cpu2;
/// <summary>ID of storage format</summary>
public int Format;
/// <summary>ID of GPU</summary>
public int Gpu;
/// <summary>ID</summary>
public int Id;
/// <summary>Frequency in MHz of primary CPU</summary>
public float Mhz1;
/// <summary>Frequency in MHz of secondary CPU</summary>
public float Mhz2;
/// <summary>Model name</summary>
public string Model;
/// <summary>Audio channels supported by the MPU</summary>
public int MusicChannels;
/// <summary>ID of MPU</summary>
public int MusicSynth;
/// <summary>Colors on palette</summary>
public int Palette;
/// <summary>Size in kibibytes of program RAM</summary>
public int Ram;
/// <summary>Resolution in WxH pixels</summary>
public string Resolution;
/// <summary>Size in kibibytes of firmware</summary>
public int Rom;
/// <summary>Audio channels supported by the DSP</summary>
public int SoundChannels;
/// <summary>ID of DSP</summary>
public int SoundSynth;
/// <summary>Size in kibibytes for video RAM</summary>
public int Vram;
/// <summary>Introduction date, 0 if unknown, 1000 if prototype</summary>
public int Year;
}
}

View File

@@ -67,4 +67,14 @@ namespace Cicm.Database.Schemas
/// <summary>Company renamed possibly with a change of intentions</summary>
Renamed = 6
}
public enum MachineType
{
/// <summary>Unknown machine type, should not happen</summary>
Unknown = 0,
/// <summary>Computer</summary>
Computer = 1,
/// <summary>Videogame console</summary>
Console = 2
}
}

View File

@@ -31,10 +31,8 @@
namespace Cicm.Database.Schemas
{
/// <summary>Computer</summary>
public class Computer
public class Machine
{
/// <summary>Bits of GPRs of primary CPU</summary>
public int Bits;
/// <summary>Capacity of first removable disk format</summary>
public string Cap1;
/// <summary>Capacity of second removable disk format</summary>
@@ -81,6 +79,8 @@ namespace Cicm.Database.Schemas
public int SoundChannels;
/// <summary>ID of DSP</summary>
public int SoundSynth;
/// <summary>Machine type</summary>
public MachineType Type;
/// <summary>Size in kibibytes for video RAM</summary>
public int Vram;
/// <summary>Introduction date, 0 if unknown, 1000 if prototype</summary>

View File

@@ -0,0 +1,149 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : V14.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 V14
{
public static readonly string Admins = V13.Admins;
public static readonly string BrowserTests = V13.BrowserTests;
public static readonly string CicmDb = "CREATE TABLE `cicm_db` (\n" +
"`id` int(11) NOT NULL AUTO_INCREMENT,\n" +
"`version` int(11) NOT NULL,\n" +
"`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
"PRIMARY KEY (`id`)\n" + ");\n" +
"INSERT INTO cicm_db (version) VALUES ('14');";
public static readonly string Companies = V13.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" +
"`cpu1` int(11) DEFAULT NULL,;\n" +
"`mhz1` int(11) DEFAULT NULL,;\n" +
"`cpu2` int(11) DEFAULT NULL,;\n" +
"`mhz2` decimal(11,2) DEFAULT NULL,;\n" +
"`ram` int(11) NOT NULL DEFAULT '0',;\n" +
"`rom` int(11) NOT NULL DEFAULT '0',;\n" +
"`gpu` int(11) DEFAULT NULL,;\n" +
"`vram` int(11) NOT NULL DEFAULT '0',;\n" +
"`colors` int(11) NOT NULL DEFAULT '0',;\n" +
"`res` char(10) NOT NULL DEFAULT '',;\n" +
"`sound_synth` int(11) NOT NULL DEFAULT '0',;\n" +
"`music_synth` int(11) NOT NULL DEFAULT '0',;\n" +
"`sound_channels` int(11) NOT NULL DEFAULT '0',;\n" +
"`music_channels` int(11) NOT NULL DEFAULT '0',;\n" +
"`hdd1` int(11) NOT NULL DEFAULT '0',;\n" +
"`hdd2` int(11) DEFAULT NULL,;\n" +
"`hdd3` int(11) DEFAULT NULL,;\n" +
"`disk1` int(11) NOT NULL DEFAULT '0',;\n" +
"`cap1` char(25) NOT NULL DEFAULT '0',;\n" +
"`disk2` int(11) DEFAULT NULL,;\n" +
"`cap2` char(25) DEFAULT NULL,;\n" +
"`type` int(11) NOT NULL DEFAULT '0',;\n" +
"PRIMARY KEY (`id`),;\n" +
"KEY `idx_machines_company` (`company`),;\n" +
"KEY `idx_machines_year` (`year`),;\n" +
"KEY `idx_machines_model` (`model`),;\n" +
"KEY `idx_machines_cpu1` (`cpu1`),;\n" +
"KEY `idx_machines_cpu2` (`cpu2`),;\n" +
"KEY `idx_machines_mhz1` (`mhz1`),;\n" +
"KEY `idx_machines_mhz2` (`mhz2`),;\n" +
"KEY `idx_machines_ram` (`ram`),;\n" +
"KEY `idx_machines_rom` (`rom`),;\n" +
"KEY `idx_machines_gpu` (`gpu`),;\n" +
"KEY `idx_machines_vram` (`vram`),;\n" +
"KEY `idx_machines_colors` (`colors`),;\n" +
"KEY `idx_machines_res` (`res`),;\n" +
"KEY `idx_machines_sound_synth` (`sound_synth`),;\n" +
"KEY `idx_machines_music_synth` (`music_synth`),;\n" +
"KEY `idx_machines_hdd1` (`hdd1`),;\n" +
"KEY `idx_machines_hdd2` (`hdd2`),;\n" +
"KEY `idx_machines_hdd3` (`hdd3`),;\n" +
"KEY `idx_machines_disk1` (`disk1`),;\n" +
"KEY `idx_machines_disk2` (`disk2`),;\n" +
"KEY `idx_machines_cap1` (`cap1`),;\n" +
"KEY `idx_machines_cap2` (`cap2`),;\n" +
"KEY `idx_machines_type` (`type`));";
public static readonly string DiskFormats = V13.DiskFormats;
public static readonly string Forbidden = V13.Forbidden;
public static readonly string Gpus = V13.Gpus;
public static readonly string Logs = V13.Logs;
public static readonly string MoneyDonations = V13.MoneyDonations;
public static readonly string News = V13.News;
public static readonly string OwnedComputers = V13.OwnedComputers;
public static readonly string OwnedConsoles = V13.OwnedConsoles;
public static readonly string Processors = V13.Processors;
public static readonly string SoundSynths = V13.SoundSynths;
public static readonly string MachinesForeignKeys = V13.ComputersForeignKeys;
public static readonly string Iso3166Numeric = V13.Iso3166Numeric;
public static readonly string Iso3166NumericValues = V13.Iso3166NumericValues;
public static readonly string CompaniesForeignKeys =
"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_cpu1` (cpu1) REFERENCES `processors` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_cpu2` (cpu2) REFERENCES `processors` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_disk1` (disk1) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_disk2` (disk2) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_gpu` (gpu) REFERENCES `gpus` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd1` (hdd1) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd2` (hdd2) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd3` (hdd3) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_music_synth` (music_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_sound_synth` (sound_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;";
public static readonly string CompanyLogos = V13.CompanyLogos;
public static readonly string CompanyDescriptions = V13.CompanyDescriptions;
public static readonly string InstructionSets = V13.InstructionSets;
public static readonly string InstructionSetExtensions = V13.InstructionSetExtensions;
public static readonly string InstructionSetExtensionsByProcessor = V13.InstructionSetExtensionsByProcessor;
}
}

View File

@@ -33,7 +33,7 @@ using System.Linq;
using cicm_web.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Computer = Cicm.Database.Schemas.Computer;
using Machine = Cicm.Database.Schemas.Machine;
namespace cicm_web.Controllers
{
@@ -48,7 +48,7 @@ namespace cicm_web.Controllers
public IActionResult Index()
{
Program.Database.Operations.GetComputers(out List<Computer> computers);
Program.Database.Operations.GetComputers(out List<Machine> computers);
ViewBag.ItemCount = computers.Count;
@@ -67,7 +67,7 @@ namespace cicm_web.Controllers
ViewBag.Letter = id;
ComputerMini[] computers =
MachineMini[] computers =
id == '\0' ? ComputerMini.GetAllItems() : ComputerMini.GetItemsStartingWithLetter(id);
return View(computers);
@@ -79,12 +79,5 @@ namespace cicm_web.Controllers
return View(ComputerMini.GetItemsFromYear(id));
}
public IActionResult View(int id)
{
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
return View(Models.Computer.GetItem(id));
}
}
}

View File

@@ -7,7 +7,7 @@
//
// --[ Description ] ----------------------------------------------------------
//
// Videograme console controller
// Videogame console controller
//
// --[ License ] --------------------------------------------------------------
//
@@ -33,7 +33,7 @@ using System.Linq;
using cicm_web.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Computer = Cicm.Database.Schemas.Computer;
using Machine = Cicm.Database.Schemas.Machine;
namespace cicm_web.Controllers
{
@@ -48,7 +48,7 @@ namespace cicm_web.Controllers
public IActionResult Index()
{
Program.Database.Operations.GetConsoles(out List<Cicm.Database.Schemas.Console> consoles);
Program.Database.Operations.GetConsoles(out List<Machine> consoles);
ViewBag.ItemCount = consoles.Count;
@@ -67,7 +67,7 @@ namespace cicm_web.Controllers
ViewBag.Letter = id;
ConsoleMini[] consoles =
MachineMini[] consoles =
id == '\0' ? ConsoleMini.GetAllItems() : ConsoleMini.GetItemsStartingWithLetter(id);
return View(consoles);
@@ -79,12 +79,5 @@ namespace cicm_web.Controllers
return View(ConsoleMini.GetItemsFromYear(id));
}
public IActionResult View(int id)
{
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
return View(Models.Console.GetItem(id));
}
}
}

View File

@@ -0,0 +1,53 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : ConsoleController.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Machine controller
//
// --[ 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 cicm_web.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
namespace cicm_web.Controllers
{
public class MachineController : Controller
{
readonly IHostingEnvironment hostingEnvironment;
public MachineController(IHostingEnvironment env)
{
hostingEnvironment = env;
}
public IActionResult View(int id)
{
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
return View(Machine.GetItem(id));
}
}
}

View File

@@ -40,8 +40,8 @@ namespace cicm_web.Models
{
public string Address;
public string City;
public ComputerMini[] Computers;
public ConsoleMini[] Consoles;
public MachineMini[] Computers;
public MachineMini[] Consoles;
public Iso3166 Country;
public string Description;
public string Facebook;

View File

@@ -34,178 +34,88 @@ using System.Linq;
namespace cicm_web.Models
{
public class Computer
public static class Computer
{
public int Bits;
public string Cap1;
public string Cap2;
public int Colors;
public Company Company;
public Processor Cpu1;
public Processor Cpu2;
public DiskFormat Disk1;
public DiskFormat Disk2;
public Gpu Gpu;
public DiskFormat Hdd1;
public DiskFormat Hdd2;
public DiskFormat Hdd3;
public int Id;
public float Mhz1;
public float Mhz2;
public string Model;
public int MusicChannels;
public SoundSynth MusicSynth;
public int Ram;
public string Resolution;
public int Rom;
public int SoundChannels;
public SoundSynth SoundSynth;
public int Vram;
public int Year;
public static Computer[] GetAllItems()
public static Machine[] GetAllItems()
{
List<Cicm.Database.Schemas.Computer> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetComputers(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<Computer> items = new List<Computer>();
List<Machine> items = new List<Machine>();
return dbItems.Select(TransformItem).OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
return dbItems.Select(Machine.TransformItem).OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
public static Computer[] GetItemsFromCompany(int id)
public static Machine[] GetItemsFromCompany(int id)
{
List<Cicm.Database.Schemas.Computer> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetComputers(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
// 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(Machine.TransformItem).OrderBy(t => t.Model).ToArray();
}
public static Computer GetItem(int id)
public static Machine GetItem(int id)
{
Cicm.Database.Schemas.Computer dbItem = Program.Database?.Operations.GetComputer(id);
return dbItem == null ? null : TransformItem(dbItem);
}
static Computer TransformItem(Cicm.Database.Schemas.Computer dbItem)
{
Computer item = new Computer
{
Bits = dbItem.Bits,
Colors = dbItem.Colors,
Company = Company.GetItem(dbItem.Company),
Gpu = Gpu.GetItem(dbItem.Gpu),
Hdd1 = DiskFormat.GetItem(dbItem.Hdd1),
Hdd2 = DiskFormat.GetItem(dbItem.Hdd2),
Hdd3 = DiskFormat.GetItem(dbItem.Hdd3),
Id = dbItem.Id,
Model = dbItem.Model,
Ram = dbItem.Ram,
Resolution = dbItem.Resolution,
Rom = dbItem.Rom,
Vram = dbItem.Vram,
Year = dbItem.Year
};
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);
item.Mhz1 = dbItem.Mhz1;
}
if(dbItem.Cpu2 > 0)
{
item.Cpu2 = Processor.GetItem(dbItem.Cpu2);
item.Mhz2 = dbItem.Mhz2;
}
if(dbItem.MusicSynth > 0)
{
item.MusicSynth = SoundSynth.GetItem(dbItem.MusicSynth);
item.MusicChannels = dbItem.MusicChannels;
}
if(dbItem.SoundSynth > 0)
{
item.SoundSynth = SoundSynth.GetItem(dbItem.SoundSynth);
item.SoundChannels = dbItem.SoundChannels;
}
return item;
Cicm.Database.Schemas.Machine dbItem = Program.Database?.Operations.GetComputer(id);
return dbItem == null ? null : Machine.TransformItem(dbItem);
}
}
public class ComputerMini
public static class ComputerMini
{
public Company Company;
public int Id;
public string Model;
public static ComputerMini[] GetAllItems()
public static MachineMini[] GetAllItems()
{
List<Cicm.Database.Schemas.Computer> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetComputers(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<ComputerMini> items = new List<ComputerMini>();
foreach(Cicm.Database.Schemas.Computer dbItem in dbItems) items.Add(TransformItem(dbItem));
List<MachineMini> items = new List<MachineMini>();
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();
}
public static ComputerMini[] GetItemsStartingWithLetter(char letter)
public static MachineMini[] GetItemsStartingWithLetter(char letter)
{
List<Cicm.Database.Schemas.Computer> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetComputers(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<ComputerMini> items = new List<ComputerMini>();
foreach(Cicm.Database.Schemas.Computer dbItem in dbItems)
List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
if(dbItem.Model.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
items.Add(TransformItem(dbItem));
items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
public static ComputerMini[] GetItemsFromYear(int year)
public static MachineMini[] GetItemsFromYear(int year)
{
List<Cicm.Database.Schemas.Computer> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetComputers(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<ComputerMini> items = new List<ComputerMini>();
foreach(Cicm.Database.Schemas.Computer dbItem in dbItems)
List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
if(dbItem.Year == year)
items.Add(TransformItem(dbItem));
items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
public static ComputerMini[] GetItemsWithCompany(int id, string companyName)
public static MachineMini[] GetItemsWithCompany(int id, string companyName)
{
List<Cicm.Database.Schemas.Computer> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetComputers(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id)
.Select(t => new ComputerMini
.Select(t => new MachineMini
{
Company = new Company {Id = id, Name = companyName},
Id = t.Id,
@@ -213,19 +123,15 @@ namespace cicm_web.Models
}).OrderBy(t => t.Model).ToArray();
}
public static ComputerMini[] GetItemsFromCompany(int id)
public static MachineMini[] GetItemsFromCompany(int id)
{
List<Cicm.Database.Schemas.Computer> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetComputers(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(TransformItem).OrderBy(t => t.Model).ToArray();
}
static ComputerMini TransformItem(Cicm.Database.Schemas.Computer dbItem)
{
return new ComputerMini {Company = Company.GetItem(dbItem.Company), Id = dbItem.Id, Model = dbItem.Model};
return dbItems.Where(t => t.Company == id).Select(MachineMini.TransformItem).OrderBy(t => t.Model)
.ToArray();
}
}
}

View File

@@ -34,164 +34,86 @@ using System.Linq;
namespace cicm_web.Models
{
public class Console
public static class Console
{
public int Bits;
public int Cap;
public int Colors;
public Company Company;
public Processor Cpu1;
public Processor Cpu2;
public DiskFormat Format;
public Gpu Gpu;
public int Id;
public float Mhz1;
public float Mhz2;
public string Model;
public int MusicChannels;
public SoundSynth MusicSynth;
public int Palette;
public int Ram;
public string Resolution;
public int Rom;
public int SoundChannels;
public SoundSynth SoundSynth;
public int Vram;
public int Year;
public static Console[] GetAllItems()
public static Machine[] GetAllItems()
{
List<Cicm.Database.Schemas.Console> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
return dbItems.OrderByDescending(i => i.Id).Select(TransformItem) as Console[];
return dbItems.OrderByDescending(i => i.Id).Select(Machine.TransformItem) as Machine[];
}
public static Console[] GetItemsFromCompany(int id)
public static Machine[] GetItemsFromCompany(int id)
{
List<Cicm.Database.Schemas.Console> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
// 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(Machine.TransformItem).OrderBy(t => t.Model).ToArray();
}
public static Console GetItem(int id)
public static Machine GetItem(int id)
{
Cicm.Database.Schemas.Console dbItem = Program.Database?.Operations.GetConsole(id);
return dbItem == null ? null : TransformItem(dbItem);
}
static Console TransformItem(Cicm.Database.Schemas.Console dbItem)
{
Console item = new Console
{
Bits = dbItem.Bits,
Colors = dbItem.Colors,
Company = Company.GetItem(dbItem.Company),
Gpu = Gpu.GetItem(dbItem.Gpu),
Id = dbItem.Id,
Model = dbItem.Model,
Palette = dbItem.Palette,
Ram = dbItem.Ram,
Resolution = dbItem.Resolution,
Rom = dbItem.Rom,
Vram = dbItem.Vram,
Year = dbItem.Year
};
if(dbItem.Format > 0)
{
item.Cap = dbItem.Cap;
item.Format = DiskFormat.GetItem(dbItem.Format);
}
if(dbItem.Cpu1 > 0)
{
item.Cpu1 = Processor.GetItem(dbItem.Cpu1);
item.Mhz1 = dbItem.Mhz1;
}
if(dbItem.Cpu2 > 0)
{
item.Cpu2 = Processor.GetItem(dbItem.Cpu2);
item.Mhz2 = dbItem.Mhz2;
}
if(dbItem.MusicSynth > 0)
{
item.MusicSynth = SoundSynth.GetItem(dbItem.MusicSynth);
item.MusicChannels = dbItem.MusicChannels;
}
if(dbItem.SoundSynth > 0)
{
item.SoundSynth = SoundSynth.GetItem(dbItem.SoundSynth);
item.SoundChannels = dbItem.SoundChannels;
}
return item;
Cicm.Database.Schemas.Machine dbItem = Program.Database?.Operations.GetConsole(id);
return dbItem == null ? null : Machine.TransformItem(dbItem);
}
}
public class ConsoleMini
public static class ConsoleMini
{
public Company Company;
public int Id;
public string Model;
public static ConsoleMini[] GetAllItems()
public static MachineMini[] GetAllItems()
{
List<Cicm.Database.Schemas.Console> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<ConsoleMini> items = new List<ConsoleMini>();
foreach(Cicm.Database.Schemas.Console dbItem in dbItems) items.Add(TransformItem(dbItem));
List<MachineMini> items = new List<MachineMini>();
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();
}
public static ConsoleMini[] GetItemsStartingWithLetter(char letter)
public static MachineMini[] GetItemsStartingWithLetter(char letter)
{
List<Cicm.Database.Schemas.Console> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<ConsoleMini> items = new List<ConsoleMini>();
foreach(Cicm.Database.Schemas.Console dbItem in dbItems)
List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
if(dbItem.Model.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
items.Add(TransformItem(dbItem));
items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
public static ConsoleMini[] GetItemsFromYear(int year)
public static MachineMini[] GetItemsFromYear(int year)
{
List<Cicm.Database.Schemas.Console> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<ConsoleMini> items = new List<ConsoleMini>();
foreach(Cicm.Database.Schemas.Console dbItem in dbItems)
List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
if(dbItem.Year == year)
items.Add(TransformItem(dbItem));
items.Add(MachineMini.TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
public static ConsoleMini[] GetItemsWithCompany(int id, string companyName)
public static MachineMini[] GetItemsWithCompany(int id, string companyName)
{
List<Cicm.Database.Schemas.Console> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id)
.Select(t => new ConsoleMini
.Select(t => new MachineMini
{
Company = new Company {Id = id, Name = companyName},
Id = t.Id,
@@ -199,19 +121,15 @@ namespace cicm_web.Models
}).OrderBy(t => t.Model).ToArray();
}
public static ConsoleMini[] GetItemsFromCompany(int id)
public static MachineMini[] GetItemsFromCompany(int id)
{
List<Cicm.Database.Schemas.Console> dbItems = null;
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(TransformItem).OrderBy(t => t.Model).ToArray();
}
static ConsoleMini TransformItem(Cicm.Database.Schemas.Console dbItem)
{
return new ConsoleMini {Company = Company.GetItem(dbItem.Company), Id = dbItem.Id, Model = dbItem.Model};
return dbItems.Where(t => t.Company == id).Select(MachineMini.TransformItem).OrderBy(t => t.Model)
.ToArray();
}
}
}

232
cicm_web/Models/Machine.cs Normal file
View File

@@ -0,0 +1,232 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Machine.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// 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
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using Cicm.Database.Schemas;
namespace cicm_web.Models
{
public class Machine
{
public string Cap1;
public string Cap2;
public int Colors;
public Company Company;
public Processor Cpu1;
public Processor Cpu2;
public DiskFormat Disk1;
public DiskFormat Disk2;
public Gpu Gpu;
public DiskFormat Hdd1;
public DiskFormat Hdd2;
public DiskFormat Hdd3;
public int Id;
public float Mhz1;
public float Mhz2;
public string Model;
public int MusicChannels;
public SoundSynth MusicSynth;
public int Ram;
public string Resolution;
public int Rom;
public int SoundChannels;
public SoundSynth SoundSynth;
public MachineType Type;
public int Vram;
public int Year;
public static Machine[] GetAllItems()
{
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetMachines(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<Machine> items = new List<Machine>();
return dbItems.Select(TransformItem).OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
public static Machine[] GetItemsFromCompany(int id)
{
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetMachines(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(TransformItem).OrderBy(t => t.Model).ToArray();
}
public static Machine GetItem(int id)
{
Cicm.Database.Schemas.Machine dbItem = Program.Database?.Operations.GetMachine(id);
return dbItem == null ? null : TransformItem(dbItem);
}
internal static Machine TransformItem(Cicm.Database.Schemas.Machine dbItem)
{
Machine item = new Machine
{
Colors = dbItem.Colors,
Company = Company.GetItem(dbItem.Company),
Gpu = Gpu.GetItem(dbItem.Gpu),
Hdd1 = DiskFormat.GetItem(dbItem.Hdd1),
Hdd2 = DiskFormat.GetItem(dbItem.Hdd2),
Hdd3 = DiskFormat.GetItem(dbItem.Hdd3),
Id = dbItem.Id,
Model = dbItem.Model,
Ram = dbItem.Ram,
Resolution = dbItem.Resolution,
Rom = dbItem.Rom,
Vram = dbItem.Vram,
Year = dbItem.Year,
Type = dbItem.Type
};
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);
item.Mhz1 = dbItem.Mhz1;
}
if(dbItem.Cpu2 > 0)
{
item.Cpu2 = Processor.GetItem(dbItem.Cpu2);
item.Mhz2 = dbItem.Mhz2;
}
if(dbItem.MusicSynth > 0)
{
item.MusicSynth = SoundSynth.GetItem(dbItem.MusicSynth);
item.MusicChannels = dbItem.MusicChannels;
}
if(dbItem.SoundSynth > 0)
{
item.SoundSynth = SoundSynth.GetItem(dbItem.SoundSynth);
item.SoundChannels = dbItem.SoundChannels;
}
return item;
}
}
public class MachineMini
{
public Company Company;
public int Id;
public string Model;
public static MachineMini[] GetAllItems()
{
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetMachines(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) items.Add(TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
public static MachineMini[] GetItemsStartingWithLetter(char letter)
{
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetMachines(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
if(dbItem.Model.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
items.Add(TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
public static MachineMini[] GetItemsFromYear(int year)
{
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetMachines(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<MachineMini> items = new List<MachineMini>();
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
if(dbItem.Year == year)
items.Add(TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
public static MachineMini[] GetItemsWithCompany(int id, string companyName)
{
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetMachines(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id)
.Select(t => new MachineMini
{
Company = new Company {Id = id, Name = companyName},
Id = t.Id,
Model = t.Model
}).OrderBy(t => t.Model).ToArray();
}
public static MachineMini[] GetItemsFromCompany(int id)
{
List<Cicm.Database.Schemas.Machine> dbItems = null;
bool? result = Program.Database?.Operations.GetMachines(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
// TODO: Company chosen by DB
return dbItems.Where(t => t.Company == id).Select(TransformItem).OrderBy(t => t.Model).ToArray();
}
internal static MachineMini TransformItem(Cicm.Database.Schemas.Machine dbItem)
{
return new MachineMini {Company = Company.GetItem(dbItem.Company), Id = dbItem.Id, Model = dbItem.Model};
}
}
}

View File

@@ -75,9 +75,9 @@ namespace cicm_web.Models
string text;
string targetView;
string subtext;
Computer computer;
Machine computer;
OwnedComputer owncomputer;
Console console;
Machine console;
OwnedConsole ownconsole;
switch(dbItem.Type)

View File

@@ -42,7 +42,7 @@ namespace cicm_web.Models
public bool Boxed;
public int Cap1;
public int Cap2;
public Computer Computer;
public Machine Computer;
public Processor Cpu1;
public Processor Cpu2;
public DiskFormat Disk1;
@@ -75,7 +75,7 @@ namespace cicm_web.Models
static OwnedComputer TransformItem(Cicm.Database.Schemas.OwnedComputer dbItem)
{
Computer computer = Computer.GetItem(dbItem.ComputerId);
Machine computer = Machine.GetItem(dbItem.ComputerId);
OwnedComputer item = new OwnedComputer
{

View File

@@ -40,7 +40,7 @@ namespace cicm_web.Models
{
public DateTime Acquired;
public bool Boxed;
public Console Console;
public Machine Console;
public int Id;
public bool Manuals;
public StatusType Status;
@@ -64,7 +64,7 @@ namespace cicm_web.Models
static OwnedConsole TransformItem(Cicm.Database.Schemas.OwnedConsole dbItem)
{
Console console = Console.GetItem(dbItem.ConsoleId);
Machine console = Machine.GetItem(dbItem.ConsoleId);
return console == null
? null

View File

@@ -33,7 +33,6 @@
}
@using System.IO
@using Cicm.Database.Schemas
@using Markdig
@model CompanyWithItems
@if(Model != null)
@@ -140,7 +139,9 @@
<tr>
<th>Country</th>
<td>
<a asp-action="ByCountry" asp-controller="Company" asp-route-id="@Model.Country.Id">
<a asp-action="ByCountry"
asp-controller="Company"
asp-route-id="@Model.Country.Id">
@if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/flags/countries", Model.Country.Id + ".svg")))
{
<picture>
@@ -364,9 +365,9 @@
data-parent="#itemsAccordion"
id="collapseComputers">
<div class="card-body">
@foreach(ComputerMini computer in Model.Computers)
@foreach(MachineMini computer in Model.Computers)
{
<a asp-controller="Computer"
<a asp-controller="Machine"
asp-action="View"
asp-route-id="@computer.Id">
@computer.Model</a>
@@ -406,9 +407,9 @@
data-parent="#itemsAccordion"
id="collapseConsoles">
<div class="card-body">
@foreach(ConsoleMini console in Model.Consoles)
@foreach(MachineMini console in Model.Consoles)
{
<a asp-controller="Console"
<a asp-controller="Machine"
asp-action="View"
asp-route-id="@console.Id">
@console.Model</a>
@@ -433,7 +434,7 @@
@if(Model.Description != null)
{
<div class="row container-fluid">
<div class="container-fluid row">
@Html.Raw(Model.Description)
</div>
}

View File

@@ -32,21 +32,27 @@
ViewData["Title"] = "Computers";
}
@model IEnumerable<ComputerMini>
@model IEnumerable<MachineMini>
<p>Search results:</p>
<p align="center">
<p align=center>
@if(ViewBag.Letter != '\0')
{
<b>@ViewBag.Letter</b><br/>
<b>@ViewBag.Letter</b>
<br />
}
@if(Model.Any())
{
<p>@Model.Count() computers found in the database.<br />
@foreach(ComputerMini computer in @Model)
<p>
@Model.Count() computers found in the database.<br />
@foreach(MachineMini computer in Model)
{
<a asp-controller="Computer" asp-action="View" asp-route-id="@computer.Id">@computer.Company.Name @computer.Model</a><br/>
<a asp-controller="Machine"
asp-action="View"
asp-route-id="@computer.Id">
@computer.Company.Name @computer.Model</a>
<br />
}
</p>
}

View File

@@ -32,7 +32,7 @@
ViewData["Title"] = "Computers";
}
@model IEnumerable<ComputerMini>
@model IEnumerable<MachineMini>
<p>Search results:</p>
<p align=center>
@@ -42,9 +42,9 @@
{
<p>
@Model.Count() computers found in the database.<br />
@foreach(ComputerMini computer in Model)
@foreach(MachineMini computer in Model)
{
<a asp-controller="Computer"
<a asp-controller="Machine"
asp-action="View"
asp-route-id="@computer.Id">
@computer.Company.Name @computer.Model</a>

View File

@@ -32,7 +32,7 @@
ViewData["Title"] = "Consoles";
}
@model IEnumerable<ConsoleMini>
@model IEnumerable<MachineMini>
<p>Search results:</p>
<p align=center>
@@ -46,9 +46,9 @@
{
<p>
@Model.Count() computers found in the database.<br />
@foreach(ConsoleMini console in Model)
@foreach(MachineMini console in Model)
{
<a asp-controller="Console"
<a asp-controller="Machine"
asp-action="View"
asp-route-id="@console.Id">
@console.Company.Name @console.Model</a>

View File

@@ -32,7 +32,7 @@
ViewData["Title"] = "Computers";
}
@model IEnumerable<ConsoleMini>
@model IEnumerable<MachineMini>
<p>Search results:</p>
<p align=center>
@@ -42,9 +42,9 @@
{
<p>
@Model.Count() videoconsoles found in the database.<br />
@foreach(ConsoleMini console in Model)
@foreach(MachineMini console in Model)
{
<a asp-controller="Console"
<a asp-controller="Machine"
asp-action="View"
asp-route-id="@console.Id">
@console.Company.Name @console.Model</a>

View File

@@ -1,938 +0,0 @@
@{
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Index.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Index page (and news)
//
// --[ 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
*******************************************************************************/
ViewData["Title"] = "Videoconsoles";
}
@using System.IO
@model cicm_web.Models.Console
<p align=center>
@if(Model.Company.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Company.LastLogo.Guid + ".svg")))
{
<picture>
<source type="image/svg+xml"
srcset="/assets/logos/@(Model.Company.LastLogo.Guid).svg">
<source type="image/webp"
srcset="/assets/logos/webp/1x/@(Model.Company.LastLogo.Guid).webp,
/assets/logos/webp/1x/@(Model.Company.LastLogo.Guid).webp 2x,
/assets/logos/webp/1x/@(Model.Company.LastLogo.Guid).webp 3x">
<img srcset="/assets/logos/png/1x/@(Model.Company.LastLogo.Guid).png,
/assets/logos/png/1x/@(Model.Company.LastLogo.Guid).png 2x,
/assets/logos/png/1x/@(Model.Company.LastLogo.Guid).webp 3x"
src="/assets/logos/png/1x@(Model.Company.LastLogo.Guid).png")
alt=""
height="auto"
width="auto"
style="max-height: 256px; max-width: 256px" />
</picture>
}
</p>
@if(Model.Year == 1000)
{
<b>
<div style="text-align: center;">PROTOTYPE</div>
</b>
}
<b>@Model.Company.Name @Model.Model</b>
<table width=100%>
@if(Model.Year != 1000)
{
<tr>
<th scope=row
width="37%">
<div align=right>
Year
</div>
</th>
<td width="63%">
@Model.Year
</td>
</tr>
}
<tr>
<th scope=row>
<div align=right>
Primary processor
</div>
</th>
@if(Model.Cpu1 != null)
{
<td>
@if(Model.Mhz1 > 0) { @(Model.Cpu1.GprSize > 0 ? $"{Model.Cpu1.Name} @ {Model.Mhz1}Mhz ({Model.Cpu1.GprSize} bits)" : $"{Model.Cpu1.Name} @ {Model.Mhz1}Mhz") }
else
{ @($"{Model.Cpu1.Name}") }
<a aria-controls="cpuInfo"
aria-expanded="false"
class="btn btn-link"
data-toggle="collapse"
href="#cpuInfo">
+info
</a>
<div class="collapse"
id="cpuInfo">
<div class="card card-body">
<table>
@if(Model.Cpu1.ModelCode != null && Model.Cpu1.ModelCode != Model.Cpu1.Name)
{
<tr>
<td>Model</td>
<td>@Model.Cpu1.ModelCode</td>
</tr>
}
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company
asp-action=View
asp-route-id=@Model.Cpu1.Company.Id>
@Model.Cpu1.Company.Name</a>
</td>
</tr>
@if(Model.Cpu1.Introduced != DateTime.MinValue)
{
<tr>
<td>Introduction date</td>
<td>@($"{Model.Cpu1.Introduced:yyyy}")</td>
</tr>
}
@if(Model.Cpu1.InstructionSet != null)
{
<tr>
<td>Instruction set</td>
<td>@Model.Cpu1.InstructionSet.Name</td>
</tr>
}
@if(Model.Cpu1.Speed > 0)
{
<tr>
<td>Nominal speed</td>
<td>@Model.Cpu1.Speed MHz</td>
</tr>
}
@if(Model.Cpu1.Gpr > 0 || Model.Cpu1.Fpr > 0 || Model.Cpu1.Simd > 0)
{
<tr>
<td>Registers</td>
<td>
<table>
@if(Model.Cpu1.Gpr > 0)
{
<tr>
<td>
@Model.Cpu1.Gpr general purpose registers of @Model.Cpu1.GprSize bits
@if(Model.Cpu1.FprSize > 0 && Model.Cpu1.Fpr == 0) { @($", that can be used as floating point registers of {Model.Cpu1.FprSize}") }
@if(Model.Cpu1.SimdSize > 0 && Model.Cpu1.Simd == 0) { @($", that can be used as SIMD registers of {Model.Cpu1.FprSize}") }
</td>
</tr>
}
@if(Model.Cpu1.Fpr > 0)
{
<tr>
<td>
@Model.Cpu1.Fpr floating-point registers of @Model.Cpu1.FprSize bits
@if(Model.Cpu1.SimdSize > 0 && Model.Cpu1.Simd == 0) { @($", that can be used as SIMD registers of {Model.Cpu1.FprSize}") }
</td>
</tr>
}
@if(Model.Cpu1.Simd > 0)
{
<tr>
<td>
@Model.Cpu1.Simd <abbr title="Single instruction, multiple data">SIMD</abbr>registers of @Model.Cpu1.SimdSize bits
</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.Cpu1.Cores > 1)
{
<tr>
<td>Multi-core</td>
<td>@Model.Cpu1.Cores cores</td>
</tr>
}
@if(Model.Cpu1.Cores > 1)
{
<tr>
<td>
<abbr title="Simultanoeus multithreading">SMT</abbr>
</td>
<td>
@Model.Cpu1.ThreadsPerCore threads
@if(Model.Cpu1.Cores > 1) { @(" per core") }
</td>
</tr>
}
@if(Model.Cpu1.DataBus > 0 || Model.Cpu1.AddressBus > 0)
{
<tr>
<td>Bus</td>
<td>
<table>
@if(Model.Cpu1.DataBus > 0)
{
<tr>
<td>
@Model.Cpu1.DataBus-bit data
</td>
</tr>
}
@if(Model.Cpu1.AddressBus > 0)
{
<tr>
<td>
@Model.Cpu1.AddressBus-bit address
</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.Cpu1.L1Instruction > 0 || Model.Cpu1.L1Data > 0 || Model.Cpu1.L2 > 0 || Model.Cpu1.L2 > 0)
{
<tr>
<td>Cache</td>
<td>
<table>
@if(Model.Cpu1.L1Instruction > 0)
{
<tr>
<td>
@(Model.Cpu1.L1Data < 0 ? $"{Model.Cpu1.L1Instruction}KiB combined instruction-data L1" : $"{Model.Cpu1.L1Instruction}KiB instruction L1")
</td>
</tr>
}
@if(Model.Cpu1.L1Data > 0)
{
<tr>
<td>
@($"{Model.Cpu1.L1Data}KiB data L1")
</td>
</tr>
}
@if(Model.Cpu1.L2 > 0)
{
<tr>
<td>
@($"{Model.Cpu1.L2}KiB L2")
</td>
</tr>
}
@if(Model.Cpu1.L3 > 0)
{
<tr>
<td>
@($"{Model.Cpu1.L3}KiB L3")
</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.Cpu1.Package != null)
{
<tr>
<td>Package</td>
<td>@Model.Cpu1.Package</td>
</tr>
}
@if(Model.Cpu1.Process != null || Model.Cpu1.ProcessNm > 0)
{
<tr>
<td>Manufacturing process</td>
<td>
@if(Model.Cpu1.Process != null && Model.Cpu1.ProcessNm > 0)
{
@Model.Cpu1.Process
@("@")
@(Model.Cpu1.ProcessNm > 100 ? $"{Model.Cpu1.ProcessNm / 100}µm" : $"{Model.Cpu1.ProcessNm}nm")
}
else if(Model.Cpu1.ProcessNm > 0) { @(Model.Cpu1.ProcessNm > 100 ? $"{Model.Cpu1.ProcessNm / 100}µm" : $"{Model.Cpu1.ProcessNm}nm") }
else
{ @Model.Cpu1.Process }
</td>
</tr>
}
@if(Model.Cpu1.DieSize > 0)
{
<tr>
<td>Die size</td>
<td>@Model.Cpu1.DieSize mm&sup2;</td>
</tr>
}
@if(Model.Cpu1.Transistors > 0)
{
<tr>
<td>Transistors</td>
<td>@Model.Cpu1.Transistors</td>
</tr>
}
</table>
</div>
</div>
</td>
}
else
{
<td>Unknown data</td>
}
</tr>
@if(Model.Cpu2 != null)
{
<tr>
<th scope=row>
<div align=right>
Secondary processor
</div>
</th>
<td>
@if(Model.Mhz1 > 0) { @(Model.Cpu2.GprSize > 0 ? $"{Model.Cpu2.Name} @ {Model.Mhz1}Mhz ({Model.Cpu2.GprSize} bits)" : $"{Model.Cpu2.Name} @ {Model.Mhz1}Mhz") }
else
{ @($"{Model.Cpu2.Name}") }
<a aria-controls="cpuInfo"
aria-expanded="false"
class="btn btn-link"
data-toggle="collapse"
href="#cpu2Info">
+info
</a>
<div class="collapse"
id="cpu2Info">
<div class="card card-body">
<table>
@if(Model.Cpu2.ModelCode != null && Model.Cpu2.ModelCode != Model.Cpu2.Name)
{
<tr>
<td>Model</td>
<td>@Model.Cpu2.ModelCode</td>
</tr>
}
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company
asp-action=View
asp-route-id=@Model.Cpu2.Company.Id>
@Model.Cpu2.Company.Name</a>
</td>
</tr>
@if(Model.Cpu2.Introduced != DateTime.MinValue)
{
<tr>
<td>Introduction date</td>
<td>@($"{Model.Cpu2.Introduced:yyyy}")</td>
</tr>
}
@if(Model.Cpu2.InstructionSet != null)
{
<tr>
<td>Instruction set</td>
<td>@Model.Cpu2.InstructionSet.Name</td>
</tr>
}
@if(Model.Cpu2.Speed > 0)
{
<tr>
<td>Nominal speed</td>
<td>@Model.Cpu2.Speed MHz</td>
</tr>
}
@if(Model.Cpu2.Gpr > 0 || Model.Cpu2.Fpr > 0 || Model.Cpu2.Simd > 0)
{
<tr>
<td>Registers</td>
<td>
<table>
@if(Model.Cpu2.Gpr > 0)
{
<tr>
<td>
@Model.Cpu2.Gpr general purpose registers of @Model.Cpu2.GprSize bits
@if(Model.Cpu2.FprSize > 0 && Model.Cpu2.Fpr == 0) { @($", that can be used as floating point registers of {Model.Cpu2.FprSize}") }
@if(Model.Cpu2.SimdSize > 0 && Model.Cpu2.Simd == 0) { @($", that can be used as SIMD registers of {Model.Cpu2.FprSize}") }
</td>
</tr>
}
@if(Model.Cpu2.Fpr > 0)
{
<tr>
<td>
@Model.Cpu2.Fpr floating-point registers of @Model.Cpu2.FprSize bits
@if(Model.Cpu2.SimdSize > 0 && Model.Cpu2.Simd == 0) { @($", that can be used as SIMD registers of {Model.Cpu2.FprSize}") }
</td>
</tr>
}
@if(Model.Cpu2.Simd > 0)
{
<tr>
<td>
@Model.Cpu2.Simd <abbr title="Single instruction, multiple data">SIMD</abbr>registers of @Model.Cpu2.SimdSize bits
</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.Cpu2.Cores > 1)
{
<tr>
<td>Multi-core</td>
<td>@Model.Cpu2.Cores cores</td>
</tr>
}
@if(Model.Cpu2.Cores > 1)
{
<tr>
<td>
<abbr title="Simultanoeus multithreading">SMT</abbr>
</td>
<td>
@Model.Cpu2.ThreadsPerCore threads
@if(Model.Cpu2.Cores > 1) { @(" per core") }
</td>
</tr>
}
@if(Model.Cpu2.DataBus > 0 || Model.Cpu2.AddressBus > 0)
{
<tr>
<td>Bus</td>
<td>
<table>
@if(Model.Cpu2.DataBus > 0)
{
<tr>
<td>
@Model.Cpu2.DataBus-bit data
</td>
</tr>
}
@if(Model.Cpu2.AddressBus > 0)
{
<tr>
<td>
@Model.Cpu2.AddressBus-bit address
</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.Cpu2.L1Instruction > 0 || Model.Cpu2.L1Data > 0 || Model.Cpu2.L2 > 0 || Model.Cpu2.L2 > 0)
{
<tr>
<td>Cache</td>
<td>
<table>
@if(Model.Cpu2.L1Instruction > 0)
{
<tr>
<td>
@(Model.Cpu2.L1Data < 0 ? $"{Model.Cpu2.L1Instruction}KiB combined instruction-data L1" : $"{Model.Cpu2.L1Instruction}KiB instruction L1")
</td>
</tr>
}
@if(Model.Cpu2.L1Data > 0)
{
<tr>
<td>
@($"{Model.Cpu2.L1Data}KiB data L1")
</td>
</tr>
}
@if(Model.Cpu2.L2 > 0)
{
<tr>
<td>
@($"{Model.Cpu2.L2}KiB L2")
</td>
</tr>
}
@if(Model.Cpu2.L3 > 0)
{
<tr>
<td>
@($"{Model.Cpu2.L3}KiB L3")
</td>
</tr>
}
</table>
</td>
</tr>
}
@if(Model.Cpu2.Package != null)
{
<tr>
<td>Package</td>
<td>@Model.Cpu2.Package</td>
</tr>
}
@if(Model.Cpu2.Process != null || Model.Cpu2.ProcessNm > 0)
{
<tr>
<td>Manufacturing process</td>
<td>
@if(Model.Cpu2.Process != null && Model.Cpu2.ProcessNm > 0)
{
@Model.Cpu2.Process
@("@")
@(Model.Cpu2.ProcessNm > 100 ? $"{Model.Cpu2.ProcessNm / 100}µm" : $"{Model.Cpu2.ProcessNm}nm")
}
else if(Model.Cpu2.ProcessNm > 0) { @(Model.Cpu2.ProcessNm > 100 ? $"{Model.Cpu2.ProcessNm / 100}µm" : $"{Model.Cpu2.ProcessNm}nm") }
else
{ @Model.Cpu2.Process }
</td>
</tr>
}
@if(Model.Cpu2.DieSize > 0)
{
<tr>
<td>Die size</td>
<td>@Model.Cpu2.DieSize mm&sup2;</td>
</tr>
}
@if(Model.Cpu2.Transistors > 0)
{
<tr>
<td>Transistors</td>
<td>@Model.Cpu2.Transistors</td>
</tr>
}
</table>
</div>
</div>
</td>
</tr>
}
<tr>
<th scope=row>
<div align=right>
RAM
</div>
</th>
@if(Model.Ram > 1024)
{
if(Model.Ram > 1048576)
{
<td>@($"{Model.Ram / 1048576}") Gbytes</td>
}
else
{
<td>@($"{Model.Ram / 1024}") Mbytes</td>
}
}
else
{
if(Model.Ram == 0)
{
<td>Unknown data</td>
}
else
{
<td>@Model.Ram Kbytes</td>
}
}
</tr>
<tr>
<th scope=row>
<div align=right>
ROM
</div>
</th>
@if(Model.Rom > 1024)
{
if(Model.Rom > 1048576)
{
<td>@($"{Model.Rom / 1048576}") Gbytes</td>
}
else
{
<td>@($"{Model.Rom / 1024}") Mbytes</td>
}
}
else
{
if(Model.Rom == 0)
{
<td>Unknown data</td>
}
else
{
<td>@Model.Rom Kbytes</td>
}
}
</tr>
@if(Model.Gpu == null || Model.Gpu != null && Model.Gpu.Id != -1)
{
<tr>
<th scope=row>
<div align=right>
Graphics processor
</div>
</th>
@if(Model.Gpu != null)
{
if(Model.Gpu.Id == -2)
{
<td>
Framebuffer
<a aria-controls="gpuInfo"
aria-expanded="false"
class="btn btn-link"
data-toggle="collapse"
href="#gpuInfo">
+info
</a>
<div class="collapse"
id="gpuInfo">
<div class="card card-body">
This videoconsole directly draws pixels from software to a memory region that's converted to video output by a <abbr title="Digital to Analog Converter">DAC</abbr> or similar without using any specific graphics processing unit.
</div>
</div>
</td>
}
else
{
<td>
@($"{Model.Gpu.Name}")
<a aria-controls="gpuInfo"
aria-expanded="false"
class="btn btn-link"
data-toggle="collapse"
href="#gpuInfo">
+info
</a>
<div class="collapse"
id="gpuInfo">
<div class="card card-body">
<table>
@if(Model.Gpu.ModelCode != null && Model.Gpu.ModelCode != Model.Gpu.Name)
{
<tr>
<td>Model</td>
<td>@Model.Gpu.ModelCode</td>
</tr>
}
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company
asp-action=View
asp-route-id=@Model.Gpu.Company.Id>
@Model.Gpu.Company.Name</a>
</td>
</tr>
@if(Model.Gpu.Introduced != DateTime.MinValue)
{
<tr>
<td>Introduction date</td>
<td>@($"{Model.Gpu.Introduced:yyyy}")</td>
</tr>
}
@if(Model.Gpu.Package != null)
{
<tr>
<td>Package</td>
<td>@Model.Gpu.Package</td>
</tr>
}
@if(Model.Gpu.Process != null || Model.Gpu.ProcessNm > 0)
{
<tr>
<td>Manufacturing process</td>
<td>
@if(Model.Gpu.Process != null && Model.Gpu.ProcessNm > 0)
{
@Model.Gpu.Process
@("@")
@(Model.Gpu.ProcessNm > 100 ? $"{Model.Gpu.ProcessNm / 100}µm" : $"{Model.Gpu.ProcessNm}nm")
}
else if(Model.Gpu.ProcessNm > 0) { @(Model.Gpu.ProcessNm > 100 ? $"{Model.Gpu.ProcessNm / 100}µm" : $"{Model.Gpu.ProcessNm}nm") }
else
{ @Model.Gpu.Process }
</td>
</tr>
}
@if(Model.Gpu.DieSize > 0)
{
<tr>
<td>Die size</td>
<td>@Model.Gpu.DieSize mm&sup2;</td>
</tr>
}
@if(Model.Gpu.Transistors > 0)
{
<tr>
<td>Transistors</td>
<td>@Model.Gpu.Transistors</td>
</tr>
}
</table>
</div>
</div>
</td>
}
}
else
{
<td>Unknown data</td>
}
</tr>
}
<tr>
<th scope=row>
<div align=right>
Video memory
</div>
</th>
@if(Model.Vram > 1024)
{
if(Model.Vram > 1048576)
{
<td>@($"{Model.Vram / 1048576}") Gbytes</td>
}
else
{
<td>@($"{Model.Vram / 1024}") Mbytes</td>
}
}
else
{
if(Model.Vram == 0)
{
<td>Unknown data</td>
}
else
{
<td>@Model.Vram Kbytes</td>
}
}
</tr>
<tr>
<th scope=row>
<div align=right>
Video resolution
</div>
</th>
@if(Model.Resolution != "???")
{
<td>@Model.Resolution</td>
}
else
{
<td>Unknown data</td>
}
</tr>
<tr>
<th scope=row>
<div align=right>
Colors
</div>
</th>
@if(Model.Colors > 0)
{
if(Model.Palette > 0)
{
<td>@Model.Colors from a palette of @Model.Palette</td>
}
else
{
<td>@Model.Colors</td>
}
}
else
{
<td>Unknown data</td>
}
</tr>
<tr>
<th scope=row>
<div align=right>
Sound processor
</div>
</th>
@if(Model.SoundSynth.Id > 1)
{
if(Model.SoundSynth.Id > 2)
{
if(Model.SoundChannels > 0)
{
<td>@Model.SoundSynth.Name (@Model.SoundChannels channels)</td>
}
else
{
<td>@Model.SoundSynth.Name</td>
}
}
else
{
<td>Unknown data</td>
}
}
else
{ <td>None</td> }
</tr>
<tr>
<th scope=row>
<div align=right>
Music synthetizer
</div>
</th>
@if(Model.MusicSynth.Id > 1)
{
if(Model.MusicSynth.Id > 2)
{
if(Model.MusicChannels > 0)
{
<td>@Model.MusicSynth.Name (@Model.MusicChannels channels)</td>
}
else
{
<td>@Model.MusicSynth.Name</td>
}
}
else
{
<td>Unknown data</td>
}
}
else
{ <td>None</td> }
</tr>
@if(Model.Format != null)
{
<tr>
<th scope=row>
<div align=right>
Primary disk
</div>
</th>
@if(Model.Format.Id != 30)
{
if(Model.Format.Id != 8)
{
if(Model.Format.Id != 6)
{
string cap1Bytes = Model.Cap > 1024 ? (Model.Cap > 1048576 ? $"{Model.Cap / 1048576} GBytes" : $"{Model.Cap / 1024} MBytes") : (Model.Cap > 0 ? $"{Model.Cap} Kbytes" : "Unknown capacity");
if(Model.Format.Id != 10)
{
if(Model.Format.Id != 15)
{
if(Model.Format.Id != 16)
{
if(Model.Format.Id != 36)
{
if(Model.Format.Id != 22)
{
if(Model.Format.Id != 23)
{
if(Model.Format.Id != 39)
{
if(Model.Format.Id != 31)
{
<td>@Model.Format.Description (@cap1Bytes)</td>
}
else
{
<td>Propietary (@cap1Bytes)</td>
}
}
else
{
<td>Digital tape (@cap1Bytes)</td>
}
}
else
{
<td>Punched card (@cap1Bytes)</td>
}
}
else
{
<td>Chip card (@cap1Bytes)</td>
}
}
else
{
<td>Magnetic card (@cap1Bytes)</td>
}
}
else
{
<td>Memory (@cap1Bytes)</td>
}
}
else
{
<td>Magneto-optical (@cap1Bytes)</td>
}
}
else
{
<td>Optical disk (@cap1Bytes)</td>
}
}
else
{
string cap1Bits = Model.Cap > 1000 ? (Model.Cap > 1000000 ? $"{Model.Cap / 1000000} GBits" : $"{Model.Cap / 1000} MBits") : (Model.Cap > 0 ? $"{Model.Cap} KBits" : "Unknown capacity");
<td>Cartridge (@cap1Bits)</td>
}
}
else
{
<td>Standard audio cassette (@Model.Cap bps)</td>
}
}
else
{ <td>None</td> }
</tr>
}
</table>
@if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/photos/consoles", Model.Id + ".jpg")))
{
<img src="@System.IO.Path.Combine("/assets/photos/consoles", Model.Id + ".jpg")"
alt="">
}

View File

@@ -32,7 +32,7 @@
ViewData["Title"] = "Computer";
}
@using System.IO
@model Computer
@model Machine
<p align=center>
@if(Model.Company.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Company.LastLogo.Guid + ".svg")))

View File

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