mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Remove unneeded code that has been substituted by Entity Framework.
This commit is contained in:
@@ -57,17 +57,6 @@ namespace Cicm.Database
|
||||
/// </summary>
|
||||
void CloseDb();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new database
|
||||
/// </summary>
|
||||
/// <param name="server">Server</param>
|
||||
/// <param name="user">User</param>
|
||||
/// <param name="database">Database name</param>
|
||||
/// <param name="password">Password</param>
|
||||
/// <param name="port">Port</param>
|
||||
/// <returns><c>true</c> if database is created correctly, <c>false</c> otherwise</returns>
|
||||
bool CreateDb(string database, string server, string user, string password, ushort port);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a data adapter for the opened database
|
||||
/// </summary>
|
||||
|
||||
@@ -104,49 +104,6 @@ namespace Cicm.Database
|
||||
connection = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new database
|
||||
/// </summary>
|
||||
/// <param name="server">Server</param>
|
||||
/// <param name="user">User</param>
|
||||
/// <param name="database">Database name</param>
|
||||
/// <param name="password">Password</param>
|
||||
/// <param name="port">Port</param>
|
||||
/// <returns><c>true</c> if database is created correctly, <c>false</c> otherwise</returns>
|
||||
public bool CreateDb(string database, string server, string user, string password, ushort port = 3306)
|
||||
{
|
||||
try
|
||||
{
|
||||
string connectionString =
|
||||
$"server={server};user={user};database={database};port={port};password={password}";
|
||||
|
||||
connection = new MySqlConnection(connectionString);
|
||||
connection.Open();
|
||||
|
||||
IDbCommand command = connection.CreateCommand();
|
||||
command.CommandText = $"CREATE DATABASE `{database}`;";
|
||||
command.ExecuteNonQuery();
|
||||
command.CommandText = $"USE `{database}`;";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
Operations = new Operations(connection, this);
|
||||
|
||||
bool res = Operations.InitializeNewDatabase();
|
||||
|
||||
if(res) return true;
|
||||
|
||||
connection = null;
|
||||
return false;
|
||||
}
|
||||
catch(MySqlException ex)
|
||||
{
|
||||
Console.WriteLine("Error opening database.");
|
||||
Console.WriteLine(ex);
|
||||
connection = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a data adapter for the opened database
|
||||
/// </summary>
|
||||
|
||||
@@ -1,290 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Admin.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage site administrators.
|
||||
//
|
||||
// --[ 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 admins
|
||||
/// </summary>
|
||||
/// <param name="entries">All admins</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetAdmins(out List<Admin> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all admins...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from admins";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = AdminsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting admins.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of admins since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of admins</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 GetAdmins(out List<Admin> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} admins from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM admins 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 = AdminsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting admins.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets admin by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Admin with specified id, <c>null</c> if not found or error</returns>
|
||||
public Admin GetAdmin(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting admin with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from admins 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<Admin> entries = AdminsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting admin.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of administrators in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountAdmins()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting admins...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM admins";
|
||||
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 AddAdmin(Admin entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding admin `{0}`...", entry.Username);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandAdmin(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO admins (user, password)" + " VALUES (@user, @password)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine(" id {0}", id);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updated an administrator in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateAdmin(Admin entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating admin `{0}`...", entry.Username);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandAdmin(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE admins SET user = @user, password = @password " + $"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an administrator 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 RemoveAdmin(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing admin widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM admins WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandAdmin(Admin entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@user";
|
||||
param2.ParameterName = "@password";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.Username;
|
||||
param2.Value = entry.Password;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<Admin> AdminsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Admin> entries = new List<Admin>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Admin entry = new Admin
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Username = (string)dataRow["user"],
|
||||
Password = (string)dataRow["password"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,379 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : BrowserTest.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage browser tests.
|
||||
//
|
||||
// --[ 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 browser tests
|
||||
/// </summary>
|
||||
/// <param name="entries">All browser tests</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetBrowserTests(out List<BrowserTest> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all browser tests...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from browser_test";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = BrowserTestsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting browser tests.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of browser tests since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of browser tests</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 GetBrowserTests(out List<BrowserTest> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} browser tests from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM browser_test 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 = BrowserTestsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting browser tests.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets browser test by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Browser test with specified id, <c>null</c> if not found or error</returns>
|
||||
public BrowserTest GetBrowserTest(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting browser test with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from browser_test 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<BrowserTest> entries = BrowserTestsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting browser test.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of browser tests in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountBrowserTests()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting browser tests...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM browser_test";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new browser test 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 AddBrowserTest(BrowserTest entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding browser test `{0}`...", entry.UserAgent);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandBrowserTest(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO browser_test (user_agent, browser, version, os, platform, gif87, gif89, jpeg, png, pngt, agif, table, colors, js, frames, flash)" +
|
||||
" VALUES (@user_agent, @browser, @version, @os, @platform, @gif87, @gif89, @jpeg, @png, @pngt, @agif, @table, @colors, @js, @frames, @flash)";
|
||||
|
||||
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 browser test in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateBrowserTest(BrowserTest entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating browser test `{0}`...", entry.UserAgent);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandBrowserTest(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE browser_test SET user_agent = @user_agent, browser = @browser, version = @version, os = @os, platform = @platform, gif87 = @gif87, " +
|
||||
"gif89 = @gif89, jpeg = @jpeg, png = @png, pngt = @pngt, agif = @agif, table = @table, colors = @colors, js = @js, frames = @frames, flash = @flash " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a browser test 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 RemoveBrowserTest(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing browser test widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM browser_test WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandBrowserTest(BrowserTest 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();
|
||||
|
||||
param1.ParameterName = "@user_agent";
|
||||
param2.ParameterName = "@browser";
|
||||
param3.ParameterName = "@version";
|
||||
param4.ParameterName = "@os";
|
||||
param5.ParameterName = "@platform";
|
||||
param6.ParameterName = "@gif87";
|
||||
param7.ParameterName = "@gif89";
|
||||
param8.ParameterName = "@jpeg";
|
||||
param9.ParameterName = "@png";
|
||||
param10.ParameterName = "@pngt";
|
||||
param11.ParameterName = "@agif";
|
||||
param12.ParameterName = "@table";
|
||||
param13.ParameterName = "@colors";
|
||||
param14.ParameterName = "@js";
|
||||
param15.ParameterName = "@frames";
|
||||
param16.ParameterName = "@flash";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.String;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.String;
|
||||
param5.DbType = DbType.String;
|
||||
param6.DbType = DbType.Boolean;
|
||||
param7.DbType = DbType.Boolean;
|
||||
param8.DbType = DbType.Boolean;
|
||||
param9.DbType = DbType.Boolean;
|
||||
param10.DbType = DbType.Boolean;
|
||||
param11.DbType = DbType.Boolean;
|
||||
param12.DbType = DbType.Boolean;
|
||||
param13.DbType = DbType.Boolean;
|
||||
param14.DbType = DbType.Boolean;
|
||||
param15.DbType = DbType.Boolean;
|
||||
param16.DbType = DbType.Boolean;
|
||||
|
||||
param1.Value = entry.UserAgent;
|
||||
param2.Value = entry.Name;
|
||||
param3.Value = entry.Version;
|
||||
param4.Value = entry.OperatingSystem;
|
||||
param5.Value = entry.Architecture;
|
||||
param6.Value = entry.Gif87;
|
||||
param7.Value = entry.Gif89;
|
||||
param8.Value = entry.Jpeg;
|
||||
param9.Value = entry.Png;
|
||||
param10.Value = entry.AlphaPng;
|
||||
param11.Value = entry.AnimatedGif;
|
||||
param12.Value = entry.Tables;
|
||||
param13.Value = entry.Color;
|
||||
param14.Value = entry.Js;
|
||||
param15.Value = entry.Frames;
|
||||
param16.Value = entry.Flash;
|
||||
|
||||
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);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<BrowserTest> BrowserTestsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<BrowserTest> entries = new List<BrowserTest>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
BrowserTest entry = new BrowserTest
|
||||
{
|
||||
Id = (ushort)dataRow["id"],
|
||||
UserAgent = (string)dataRow["user_agent"],
|
||||
Name = (string)dataRow["browser"],
|
||||
Version = (string)dataRow["version"],
|
||||
OperatingSystem = (string)dataRow["os"],
|
||||
Architecture = (string)dataRow["platform"],
|
||||
Gif87 = (int)dataRow["gif87"] > 0,
|
||||
Gif89 = (int)dataRow["gif89"] > 0,
|
||||
Jpeg = (int)dataRow["jpeg"] > 0,
|
||||
Png = (int)dataRow["png"] > 0,
|
||||
AlphaPng = (int)dataRow["pngt"] > 0,
|
||||
AnimatedGif = (int)dataRow["agif"] > 0,
|
||||
Tables = (int)dataRow["table"] > 0,
|
||||
Color = (int)dataRow["colors"] > 0,
|
||||
Js = (int)dataRow["js"] > 0,
|
||||
Frames = (int)dataRow["frames"] > 0,
|
||||
Flash = (int)dataRow["flash"] > 0
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,472 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Company.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage companies.
|
||||
//
|
||||
// --[ 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 companies
|
||||
/// </summary>
|
||||
/// <param name="entries">All companies</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetCompanies(out List<Company> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all companies...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from companies";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = CompaniesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting companies.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of companies since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of companies</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 GetCompanies(out List<Company> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} companies from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM companies 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 = CompaniesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting companies.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all companies that start with the specified letter
|
||||
/// </summary>
|
||||
/// <param name="entries">All companies</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetCompanies(out List<Company> entries, char startingLetter)
|
||||
{
|
||||
if((startingLetter < 'a' || startingLetter > 'z') && (startingLetter < 'A' || startingLetter > 'Z'))
|
||||
return GetCompanies(out entries);
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all companies that start with {0}...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = $"SELECT * FROM companies WHERE name LIKE '{startingLetter}%'";
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = CompaniesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting companies.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all companies from the specified country
|
||||
/// </summary>
|
||||
/// <param name="entries">All companies</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetCompanies(out List<Company> entries, int countryCode)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all companies that start with {0}...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = $"SELECT * from companies WHERE country = '{countryCode}'";
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = CompaniesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting companies.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets company by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Company with specified id, <c>null</c> if not found or error</returns>
|
||||
public Company GetCompany(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting company with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from companies 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<Company> entries = CompaniesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting company.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of companies in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountCompanies()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting companies...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM companies";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new company 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 AddCompany(Company entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding company `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandCompany(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO companies (name, founded, website, twitter, facebook, sold, sold_to, " +
|
||||
"address, city, province, postal_code, country, status) VALUES (@name, @founded, @website, " +
|
||||
"@twitter, @facebook, @sold, @sold_to, @address, @city, @province, @postal_code, " +
|
||||
"@country, status)";
|
||||
|
||||
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 company in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateCompany(Company entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating company `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandCompany(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE companies SET name = @name, founded = @founded, website = @website, twitter = @twitter, " +
|
||||
"facebook = @facebook, sold = @sold, sold_to = @sold_to, address = @address, city = @city, " +
|
||||
"province = @province, postal_code = @postal_code, country = @country, status = @status " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a company 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 RemoveCompany(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing company widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM companies WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandCompany(Company 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();
|
||||
|
||||
param1.ParameterName = "@name";
|
||||
param2.ParameterName = "@founded";
|
||||
param3.ParameterName = "@website";
|
||||
param4.ParameterName = "@twitter";
|
||||
param5.ParameterName = "@facebook";
|
||||
param6.ParameterName = "@sold";
|
||||
param7.ParameterName = "@sold_to";
|
||||
param8.ParameterName = "@address";
|
||||
param9.ParameterName = "@city";
|
||||
param10.ParameterName = "@province";
|
||||
param11.ParameterName = "@postal_code";
|
||||
param12.ParameterName = "@country";
|
||||
param13.ParameterName = "@status";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.DateTime;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.String;
|
||||
param5.DbType = DbType.String;
|
||||
param6.DbType = DbType.DateTime;
|
||||
param7.DbType = DbType.UInt32;
|
||||
param8.DbType = DbType.String;
|
||||
param9.DbType = DbType.String;
|
||||
param10.DbType = DbType.String;
|
||||
param11.DbType = DbType.String;
|
||||
param12.DbType = DbType.UInt16;
|
||||
param13.DbType = DbType.UInt32;
|
||||
|
||||
param1.Value = entry.Name;
|
||||
param2.Value = entry.Founded;
|
||||
param3.Value = entry.Website;
|
||||
param4.Value = entry.Twitter;
|
||||
param5.Value = entry.Facebook;
|
||||
if(entry.SoldTo != null)
|
||||
{
|
||||
param6.Value = entry.Sold;
|
||||
param7.Value = entry.SoldTo.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
param6.Value = null;
|
||||
param7.Value = null;
|
||||
}
|
||||
|
||||
param8.Value = entry.Address;
|
||||
param9.Value = entry.City;
|
||||
param10.Value = entry.Province;
|
||||
param11.Value = entry.PostalCode;
|
||||
if(entry.Country != null) param12.Value = entry.Country.Id;
|
||||
else param12.Value = null;
|
||||
param13.Value = entry.Status;
|
||||
|
||||
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);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
List<Company> CompaniesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Company> entries = new List<Company>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Company entry = new Company
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Name = (string)dataRow["name"],
|
||||
Website = dataRow["website"] == DBNull.Value ? null : (string)dataRow["website"],
|
||||
Twitter = dataRow["twitter"] == DBNull.Value ? null : (string)dataRow["twitter"],
|
||||
Facebook = dataRow["facebook"] == DBNull.Value ? null : (string)dataRow["facebook"],
|
||||
Address = dataRow["address"] == DBNull.Value ? null : (string)dataRow["address"],
|
||||
City = dataRow["city"] == DBNull.Value ? null : (string)dataRow["city"],
|
||||
Province = dataRow["province"] == DBNull.Value ? null : (string)dataRow["province"],
|
||||
PostalCode = dataRow["postal_code"] == DBNull.Value ? null : (string)dataRow["postal_code"],
|
||||
Status = (CompanyStatus)dataRow["status"],
|
||||
Founded =
|
||||
dataRow["founded"] == DBNull.Value
|
||||
? DateTime.MinValue
|
||||
: Convert.ToDateTime(dataRow["founded"].ToString()),
|
||||
Sold =
|
||||
dataRow["sold"] == DBNull.Value
|
||||
? DateTime.MinValue
|
||||
: Convert.ToDateTime(dataRow["sold"].ToString()),
|
||||
SoldTo = dataRow["sold_to"] == DBNull.Value ? null : GetCompany((int)dataRow["sold_to"]),
|
||||
Country = dataRow["country"] == DBNull.Value ? null : GetIso3166((short)dataRow["country"])
|
||||
};
|
||||
|
||||
if(GetCompanyLogosByCompany(out List<CompanyLogo> logos, entry.Id))
|
||||
{
|
||||
entry.Logos = logos.ToArray();
|
||||
if(entry.Logos != null && entry.Logos.Length > 0)
|
||||
if(entry.Logos.Length > 1)
|
||||
{
|
||||
int currentYear = 0;
|
||||
foreach(CompanyLogo logo in entry.Logos)
|
||||
{
|
||||
if(logo.Year <= currentYear) continue;
|
||||
|
||||
entry.LastLogo = logo;
|
||||
currentYear = logo.Year;
|
||||
}
|
||||
}
|
||||
else
|
||||
entry.LastLogo = entry.Logos[0];
|
||||
}
|
||||
|
||||
if(GetCompanyDescriptionsByCompany(out List<CompanyDescription> descriptions, entry.Id))
|
||||
if(descriptions != null && descriptions.Count > 0)
|
||||
entry.Description = descriptions[0].Text;
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,327 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : CompanyDescription.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage company descriptions.
|
||||
//
|
||||
// --[ 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 company descriptions
|
||||
/// </summary>
|
||||
/// <param name="entries">All company descriptions</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetCompanyDescriptions(out List<CompanyDescription> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all company descriptions...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from company_descriptions";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = CompanyDescriptionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting company descriptions.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of company descriptions since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of company_descriptions</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 GetCompanyDescriptions(out List<CompanyDescription> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} company descriptions from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM company_descriptions 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 = CompanyDescriptionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting company descriptions.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets company description by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>CompanyDescription with specified id, <c>null</c> if not found or error</returns>
|
||||
public CompanyDescription GetCompanyDescription(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting company description with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from company_descriptions 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<CompanyDescription> entries = CompanyDescriptionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting company.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets company description by specified id
|
||||
/// </summary>
|
||||
/// <param name="entries">List of company_descriptions</param>
|
||||
/// <param name="company">Company id</param>
|
||||
/// <returns>CompanyDescription with specified id, <c>null</c> if not found or error</returns>
|
||||
public bool GetCompanyDescriptionsByCompany(out List<CompanyDescription> entries, int company)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting company descriptions for company {0}...", company);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM company_descriptions WHERE company_id = {company}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = CompanyDescriptionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting company descriptions.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of company descriptions in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountCompanyDescriptions()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting company descriptions...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM company_descriptions";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new company description 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 AddCompanyDescription(CompanyDescription entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding description for company id `{0}`...", entry.CompanyId);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandCompanyDescription(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO company_descriptions (company_id, text) VALUES (@company_id, @text)";
|
||||
|
||||
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 company description in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateCompanyDescription(CompanyDescription entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating company description id `{0}`...", entry.Id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandCompanyDescription(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE company_descriptions SET company_id = @company_id, text = @text " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a company description 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 RemoveCompanyDescription(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing company description with id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM company_descriptions WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandCompanyDescription(CompanyDescription entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@company_id";
|
||||
param2.ParameterName = "@text";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.CompanyId;
|
||||
param2.Value = entry.Text;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<CompanyDescription> CompanyDescriptionsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<CompanyDescription> entries = new List<CompanyDescription>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
CompanyDescription entry = new CompanyDescription
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
CompanyId = (int)dataRow["company_id"],
|
||||
Text = dataRow["text"] == DBNull.Value ? null : (string)dataRow["text"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,334 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : CompanyLogo.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage company logos.
|
||||
//
|
||||
// --[ 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 company logos
|
||||
/// </summary>
|
||||
/// <param name="entries">All company logos</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetCompanyLogos(out List<CompanyLogo> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all company logos...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from company_logos";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = CompanyLogosFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting company logos.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of company logos since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of company_logos</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 GetCompanyLogos(out List<CompanyLogo> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} company logos from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM company_logos 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 = CompanyLogosFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting company logos.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets company logo by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>CompanyLogo with specified id, <c>null</c> if not found or error</returns>
|
||||
public CompanyLogo GetCompanyLogo(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting company logo with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from company_logos 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<CompanyLogo> entries = CompanyLogosFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting company.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets company logo by specified id
|
||||
/// </summary>
|
||||
/// <param name="entries">List of company_logos</param>
|
||||
/// <param name="company">Company id</param>
|
||||
/// <returns>CompanyLogo with specified id, <c>null</c> if not found or error</returns>
|
||||
public bool GetCompanyLogosByCompany(out List<CompanyLogo> entries, int company)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting company logos for company {0}...", company);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM company_logos WHERE company_id = {company}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = CompanyLogosFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting company logos.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of company logos in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountCompanyLogos()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting company logos...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM company_logos";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new company logo 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 AddCompanyLogo(CompanyLogo entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding logo for company id `{0}`...", entry.CompanyId);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandCompanyLogo(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO company_logos (company_id, year, logo_guid) VALUES (@company_id, @year, @logo_guid)";
|
||||
|
||||
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 company logo in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateCompanyLogo(CompanyLogo entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating company logo id `{0}`...", entry.Id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandCompanyLogo(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE company_logos SET company_id = @company_id, year = @year, logo_guid = @logo_guid " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a company logo 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 RemoveCompanyLogo(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing company logo with id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM company_logos WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandCompanyLogo(CompanyLogo entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@company_id";
|
||||
param2.ParameterName = "@year";
|
||||
param3.ParameterName = "@logo_guid";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.String;
|
||||
param3.DbType = DbType.Guid;
|
||||
|
||||
param1.Value = entry.CompanyId;
|
||||
param2.Value = entry.Year;
|
||||
param3.Value = entry.Guid;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<CompanyLogo> CompanyLogosFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<CompanyLogo> entries = new List<CompanyLogo>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
CompanyLogo entry = new CompanyLogo
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
CompanyId = (int)dataRow["company_id"],
|
||||
Year = dataRow["year"] == DBNull.Value ? 0 : (int)dataRow["year"],
|
||||
Guid = (Guid)dataRow["logo_guid"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Computer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage computers.
|
||||
//
|
||||
// --[ 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 computers
|
||||
/// </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<Machine> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all computers...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM machines WHERE type = '{(int)MachineType.Computer}'";
|
||||
|
||||
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 computers.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all computers from specified company
|
||||
/// </summary>
|
||||
/// <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<Machine> entries, int company)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all computers from company id {0}...", company);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql =
|
||||
$"SELECT * FROM machines WHERE company = '{company}' AND type = '{(int)MachineType.Computer}'";
|
||||
|
||||
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 computers.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of computers since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of computers</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 GetComputers(out List<Machine> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} computers from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql =
|
||||
$"SELECT * FROM machines LIMIT {start}, {count} WHERE type = '{(int)MachineType.Computer}'";
|
||||
|
||||
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 computers.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets computer by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Computer with specified id, <c>null</c> if not found or error</returns>
|
||||
public Machine GetComputer(int id)
|
||||
{
|
||||
return GetMachine(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of computers in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountComputers()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting computers...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = $"SELECT COUNT(*) FROM computers WHERE type = '{(int)MachineType.Computer}'";
|
||||
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 AddComputer(Machine entry, out long id)
|
||||
{
|
||||
entry.Type = MachineType.Computer;
|
||||
return AddMachine(entry, out id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updated a computer in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateComputer(Machine entry)
|
||||
{
|
||||
return UpdateMachine(entry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a computer 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 RemoveComputer(long id)
|
||||
{
|
||||
return RemoveMachine(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Console.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage videogame consoles.
|
||||
//
|
||||
// --[ 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 consoles
|
||||
/// </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<Machine> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all consoles...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM machines WHERE type = '{(int)MachineType.Console}'";
|
||||
|
||||
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 consoles.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all consoles from specified company
|
||||
/// </summary>
|
||||
/// <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<Machine> entries, int company)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all consoles from company id {0}...", company);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql =
|
||||
$"SELECT * FROM machines WHERE company = '{company}' AND type = '{(int)MachineType.Console}'";
|
||||
|
||||
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 consoles.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of videogame consoles since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of videogame consoles</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 GetConsoles(out List<Machine> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} consoles from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM machines WHERE type = '{(int)MachineType.Console}' 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 consoles.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets videogame console by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Videogame console with specified id, <c>null</c> if not found or error</returns>
|
||||
public Machine GetConsole(int id)
|
||||
{
|
||||
return GetMachine(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of videogame consoles in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountConsoles()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting consoles...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = $"SELECT COUNT(*) FROM consoles WHERE type = '{(int)MachineType.Console}'";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new videogame console 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 AddConsole(Machine entry, out long id)
|
||||
{
|
||||
entry.Type = MachineType.Console;
|
||||
return AddMachine(entry, out id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updated an videogame console in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateConsole(Machine entry)
|
||||
{
|
||||
return UpdateMachine(entry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a videogame console 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 RemoveConsole(long id)
|
||||
{
|
||||
return RemoveMachine(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,304 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Forbidden.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage forbidden accesses.
|
||||
//
|
||||
// --[ 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 forbidden accesses
|
||||
/// </summary>
|
||||
/// <param name="entries">All forbidden accesses</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetForbiddens(out List<Forbidden> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all forbiddens...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from forbidden";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ForbiddensFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting forbiddens.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of forbidden accesses since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of forbidden accesses</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 GetForbiddens(out List<Forbidden> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} forbiddens from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM forbidden 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 = ForbiddensFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting forbiddens.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets forbidden entry by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Forbidden entry with specified id, <c>null</c> if not found or error</returns>
|
||||
public Forbidden GetForbidden(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting forbidden with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from forbidden 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<Forbidden> entries = ForbiddensFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting forbidden.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of Forbidden accesses in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountForbiddens()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting forbiddens...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM forbidden";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new forbidden 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 AddForbidden(Forbidden entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding forbidden `{0}`...", entry.UserAgent);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandForbidden(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO forbidden (browser, date, ip, referer)" +
|
||||
" VALUES (@browser, @date, @ip, @referer)";
|
||||
|
||||
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 forbidden access in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateForbidden(Forbidden entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating forbidden `{0}`...", entry.UserAgent);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandForbidden(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE forbidden SET browser = @browser, date = @date, ip = @ip, referer = @referer " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a forbidden access 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 RemoveForbidden(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing forbidden widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM forbidden WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandForbidden(Forbidden entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param4 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@browser";
|
||||
param2.ParameterName = "@date";
|
||||
param3.ParameterName = "@ip";
|
||||
param4.ParameterName = "@referer";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.String;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.UserAgent;
|
||||
param2.Value = entry.Date;
|
||||
param3.Value = entry.Ip;
|
||||
param4.Value = entry.Referer;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<Forbidden> ForbiddensFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Forbidden> entries = new List<Forbidden>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Forbidden entry = new Forbidden
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
UserAgent = (string)dataRow["browser"],
|
||||
Date = (string)dataRow["date"],
|
||||
Ip = (string)dataRow["ip"],
|
||||
Referer = (string)dataRow["referer"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,342 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Gpu.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage GPUs.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <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 GPUs
|
||||
/// </summary>
|
||||
/// <param name="entries">All GPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetGpus(out List<Gpu> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all GPUs...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from gpus";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = GpusFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting GPUs.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of GPUs since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of GPUs</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 GetGpus(out List<Gpu> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} GPUs from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM gpus 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 = GpusFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting GPUs.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets GPU by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>GPU with specified id, <c>null</c> if not found or error</returns>
|
||||
public Gpu GetGpu(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting GPU with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from gpus 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<Gpu> entries = GpusFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting GPU.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of GPUs in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountGpus()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting gpus...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM gpus";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new GPU 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 AddGpu(Gpu entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding GPU `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandGpu(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO gpus (name, company, model_code, introduced, package, process, process_nm, " +
|
||||
"die_size, transistors)" +
|
||||
" VALUES (@name, @company, @model_code, @introduced, @package, " +
|
||||
"@process, @process_nm, @die_size, @transistors)";
|
||||
|
||||
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 GPU in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateGpu(Gpu entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating GPU `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandGpu(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE gpus SET name = @name, company = @company, model_code = @model_code, " +
|
||||
"introduced = @introduced, package = @package, process = @process, process_nm = @process_nm, " +
|
||||
"die_size = @die_size, transistors = @transistors " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a GPU 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 RemoveGpu(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing GPU widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM gpus WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandGpu(Gpu 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();
|
||||
|
||||
param1.ParameterName = "@name";
|
||||
param2.ParameterName = "@company";
|
||||
param3.ParameterName = "@model_code";
|
||||
param4.ParameterName = "@introduced";
|
||||
param5.ParameterName = "@package";
|
||||
param6.ParameterName = "@process";
|
||||
param7.ParameterName = "@process_nm";
|
||||
param8.ParameterName = "@die_size";
|
||||
param9.ParameterName = "@transistors";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.DateTime;
|
||||
param5.DbType = DbType.String;
|
||||
param6.DbType = DbType.String;
|
||||
param7.DbType = DbType.Double;
|
||||
param8.DbType = DbType.Double;
|
||||
param9.DbType = DbType.UInt64;
|
||||
|
||||
param1.Value = entry.Name;
|
||||
param2.Value = entry.Company == null ? null : (object)entry.Company.Id;
|
||||
param3.Value = entry.ModelCode;
|
||||
param4.Value = entry.Introduced == DateTime.MinValue ? null : (object)entry.Introduced;
|
||||
param5.Value = entry.Package;
|
||||
param6.Value = entry.Process;
|
||||
param7.Value = entry.ProcessNm;
|
||||
param8.Value = entry.DieSize;
|
||||
param9.Value = entry.Transistors;
|
||||
|
||||
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);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
List<Gpu> GpusFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Gpu> entries = new List<Gpu>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Gpu entry = new Gpu
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Name = (string)dataRow["name"],
|
||||
ModelCode = dataRow["model_code"] == DBNull.Value ? null : (string)dataRow["model_code"],
|
||||
Package = dataRow["package"] == DBNull.Value ? null : (string)dataRow["package"],
|
||||
Process = dataRow["process"] == DBNull.Value ? null : (string)dataRow["process"],
|
||||
ProcessNm = dataRow["process_nm"] == DBNull.Value ? 0 : (float)dataRow["process_nm"],
|
||||
DieSize = dataRow["die_size"] == DBNull.Value ? 0 : (float)dataRow["die_size"],
|
||||
Transistors = dataRow["transistors"] == DBNull.Value ? 0 : (long)dataRow["transistors"],
|
||||
Company = dataRow["company"] == DBNull.Value ? null : GetCompany((int)dataRow["company"]),
|
||||
Introduced = dataRow["introduced"] == DBNull.Value
|
||||
? DateTime.MinValue
|
||||
: Convert.ToDateTime(dataRow["introduced"])
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : GpuByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage gpus.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <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 gpus in machine
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetGpusByMachines(out List<GpuByMachine> entries, int machineId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all gpus for machine {0}...", machineId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM gpus_by_machine WHERE machine = {machineId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = GpuByMachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting gpus by machine.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all machines with specified gpu
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMachinesByGpu(out List<GpuByMachine> entries, int gpuId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all machines with gpu {0}...", gpuId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM gpus_by_machine WHERE gpu = {gpuId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = GpuByMachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machines by gpu.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
IDbCommand GetCommandGpuByMachine(GpuByMachine entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@gpu";
|
||||
param2.ParameterName = "@machine";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
|
||||
param1.Value = entry.Gpu;
|
||||
param2.Value = entry.Machine;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<GpuByMachine> GpuByMachinesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<GpuByMachine> entries = new List<GpuByMachine>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
GpuByMachine entry = new GpuByMachine {Machine = (int)dataRow["machine"], Gpu = (int)dataRow["gpu"]};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Init.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operation to initialize a new database.
|
||||
//
|
||||
// --[ 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.Data;
|
||||
using Cicm.Database.Schemas.Sql;
|
||||
|
||||
namespace Cicm.Database
|
||||
{
|
||||
public partial class Operations
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes tables in the database
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if initialized correctly, <c>false</c> otherwise</returns>
|
||||
public bool InitializeNewDatabase()
|
||||
{
|
||||
Console.WriteLine("Creating new database version {0}", DB_VERSION);
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
|
||||
Console.WriteLine("Creating table `admins`");
|
||||
dbCmd.CommandText = V22.Admins;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `browser_tests`");
|
||||
dbCmd.CommandText = V22.BrowserTests;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `cicm_db`");
|
||||
dbCmd.CommandText = V22.CicmDb;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `companies`");
|
||||
dbCmd.CommandText = V22.Companies;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `machine_families`");
|
||||
dbCmd.CommandText = V22.MachineFamilies;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `machines`");
|
||||
dbCmd.CommandText = V22.Machines;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `forbidden`");
|
||||
dbCmd.CommandText = V22.Forbidden;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `gpus`");
|
||||
dbCmd.CommandText = V22.Gpus;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `log`");
|
||||
dbCmd.CommandText = V22.Logs;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `money_donations`");
|
||||
dbCmd.CommandText = V22.MoneyDonations;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `news`");
|
||||
dbCmd.CommandText = V22.News;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `owned_computers`");
|
||||
dbCmd.CommandText = V22.OwnedComputers;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `owned_consoles`");
|
||||
dbCmd.CommandText = V22.OwnedConsoles;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `instruction_sets`");
|
||||
dbCmd.CommandText = V22.InstructionSets;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `instruction_set_extensions`");
|
||||
dbCmd.CommandText = V22.InstructionSetExtensions;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `processors`");
|
||||
dbCmd.CommandText = V22.Processors;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `instruction_set_extensions_by_processor`");
|
||||
dbCmd.CommandText = V22.InstructionSetExtensionsByProcessor;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `sound_synths`");
|
||||
dbCmd.CommandText = V22.SoundSynths;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `iso3166_1_numeric`");
|
||||
dbCmd.CommandText = V22.Iso3166Numeric;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Filling table `iso3166_1_numeric`");
|
||||
dbCmd.CommandText = V22.Iso3166NumericValues;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating foreign keys for table `companies`");
|
||||
dbCmd.CommandText = V22.CompaniesForeignKeys;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating foreign keys for table `machines`");
|
||||
dbCmd.CommandText = V22.MachinesForeignKeys;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `company_logos`");
|
||||
dbCmd.CommandText = V22.CompanyLogos;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `company_descriptions`");
|
||||
dbCmd.CommandText = V22.CompanyDescriptions;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `processors_by_machine`");
|
||||
dbCmd.CommandText = V22.ProcessorsByMachine;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `gpus_by_machine`");
|
||||
dbCmd.CommandText = V22.GpusByMachine;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `sound_by_machine`");
|
||||
dbCmd.CommandText = V22.SoundByMachine;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `memory_by_machine`");
|
||||
dbCmd.CommandText = V22.MemoryByMachine;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `resolutions`");
|
||||
dbCmd.CommandText = V22.Resolutions;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `resolutions_by_gpu`");
|
||||
dbCmd.CommandText = V22.ResolutionsByGpu;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `storage_by_machine`");
|
||||
dbCmd.CommandText = V22.StorageByMachine;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error creating database.");
|
||||
Console.WriteLine(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,281 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : InstructionSet.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage instruction_sets.
|
||||
//
|
||||
// --[ 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 instruction sets
|
||||
/// </summary>
|
||||
/// <param name="entries">All instruction sets</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetInstructionSets(out List<InstructionSet> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all instruction sets...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from instruction_sets";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = InstructionSetsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting instruction sets.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of instruction sets since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of instruction sets</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 GetInstructionSets(out List<InstructionSet> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} instruction sets from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM instruction_sets 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 = InstructionSetsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting instruction sets.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets instruction set by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>InstructionSet with specified id, <c>null</c> if not found or error</returns>
|
||||
public InstructionSet GetInstructionSet(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting instruction set with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from instruction_sets 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<InstructionSet> entries = InstructionSetsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting instruction set.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of instruction sets in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountInstructionSets()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting instruction_sets...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM instruction_sets";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new instruction set 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 AddInstructionSet(InstructionSet entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding instruction set `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandInstructionSet(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO instruction_sets (instruction_set) VALUES (@instruction_set)";
|
||||
|
||||
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 instruction set in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateInstructionSet(InstructionSet entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating instruction set `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandInstructionSet(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE instruction_sets SET instruction_set = @instruction_set " + $"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a instruction set 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 RemoveInstructionSet(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing instruction set widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM instruction_sets WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandInstructionSet(InstructionSet entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@instruction_set";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.Name;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<InstructionSet> InstructionSetsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<InstructionSet> entries = new List<InstructionSet>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
InstructionSet entry =
|
||||
new InstructionSet {Id = (int)dataRow["id"], Name = (string)dataRow["instruction_set"]};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : InstructionSet.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage instruction_set_extensions.
|
||||
//
|
||||
// --[ 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 instruction set extensions
|
||||
/// </summary>
|
||||
/// <param name="entries">All instruction set extensions</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetInstructionSetExtensions(out List<InstructionSetExtension> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all instruction set extensions...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from instruction_set_extensions";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = InstructionSetExtensionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting instruction set extensions.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of instruction set extensions since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of instruction set extensions</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 GetInstructionSetExtensions(out List<InstructionSetExtension> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} instruction set extensions from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM instruction_set_extensions 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 = InstructionSetExtensionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting instruction set extensions.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets instruction set extension by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>InstructionSet with specified id, <c>null</c> if not found or error</returns>
|
||||
public InstructionSetExtension GetInstructionSetExtension(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting instruction set extension with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from instruction_set_extensions 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<InstructionSetExtension> entries = InstructionSetExtensionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting instruction set extension.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<InstructionSetExtension> GetInstructionSetExtensions(int processor)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting instruction set extension for processor id {0}...", processor);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql =
|
||||
$"SELECT * from instruction_set_extensions_by_processor WHERE processor_id = '{processor}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
if(dataSet.Tables[0].Rows.Count == 0) return null;
|
||||
|
||||
List<InstructionSetExtension> entries = new List<InstructionSetExtension>();
|
||||
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
|
||||
{
|
||||
if(!int.TryParse(dataRow["extension_id"].ToString(), out int extensionId)) continue;
|
||||
if(extensionId == 0) continue;
|
||||
|
||||
entries.Add(GetInstructionSetExtension(extensionId));
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting instruction set extension.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of instruction set extensions in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountInstructionSetExtensions()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting instruction_set_extensions...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM instruction_set_extensions";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new instruction set extension 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 AddInstructionSetExtension(InstructionSetExtension entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding instruction set extension `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandInstructionSetExtension(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO instruction_set_extensions (extension) VALUES (@extension)";
|
||||
|
||||
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 instruction set extension in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateInstructionSetExtension(InstructionSetExtension entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating instruction set extension `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandInstructionSetExtension(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE instruction_set_extensions SET extension = @extension " + $"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a instruction set extension 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 RemoveInstructionSetExtension(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing instruction set extension widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM instruction_set_extensions WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandInstructionSetExtension(InstructionSetExtension entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@extension";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.Name;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<InstructionSetExtension> InstructionSetExtensionsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<InstructionSetExtension> entries = new List<InstructionSetExtension>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
InstructionSetExtension entry =
|
||||
new InstructionSetExtension {Id = (int)dataRow["id"], Name = (string)dataRow["extension"]};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,280 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Iso3166.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage iso3166_1_numeric.
|
||||
//
|
||||
// --[ 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 ISO 3166-1 codes
|
||||
/// </summary>
|
||||
/// <param name="entries">All ISO 3166-1 codes</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetIso3166(out List<Iso3166> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all ISO 3166-1 codes...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from iso3166_1_numeric";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = Iso3166FromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting ISO 3166-1 codes.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of ISO 3166-1 codes since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of ISO 3166-1 codes</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 GetIso3166(out List<Iso3166> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} ISO 3166-1 codes from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM iso3166_1_numeric 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 = Iso3166FromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting ISO 3166-1 codes.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets ISO 3166-1 code by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>ISO 3166-1 code with specified id, <c>null</c> if not found or error</returns>
|
||||
public Iso3166 GetIso3166(short id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting ISO 3166-1 code with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from iso3166_1_numeric 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<Iso3166> entries = Iso3166FromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting ISO 3166-1 code.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of ISO 3166-1 codes in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountIso3166()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting ISO 3166-1 codes...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM iso3166_1_numeric";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new ISO 3166-1 code 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 AddIso3166(Iso3166 entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding ISO 3166-1 code `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandIso3166(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO iso3166_1_numeric (name)" + " VALUES (@name)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine(" id {0}", id);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an ISO 3166-1 code in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateIso3166(Iso3166 entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating ISO 3166-1 code `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandIso3166(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE iso3166_1_numeric SET name = @name " + $"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an ISO 3166-1 code 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 RemoveIso3166(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing ISO 3166-1 code `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM iso3166_1_numeric WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandIso3166(Iso3166 entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@name";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.Name;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<Iso3166> Iso3166FromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Iso3166> entries = new List<Iso3166>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Iso3166 entry = new Iso3166 {Id = (short)dataRow["id"], Name = (string)dataRow["name"]};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,304 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Log.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage log entries.
|
||||
//
|
||||
// --[ 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 log entries
|
||||
/// </summary>
|
||||
/// <param name="entries">All log entries</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetLogs(out List<Log> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all logs...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from log";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = LogsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting logs.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of log entries since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of log entries</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 GetLogs(out List<Log> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} logs from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM log 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 = LogsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting logs.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets log entry by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Log entry with specified id, <c>null</c> if not found or error</returns>
|
||||
public Log GetLog(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting log with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from log 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<Log> entries = LogsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting log.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of log entries in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountLogs()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting logs...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM log";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new access log entry 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 AddLog(Log entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding log `{0}`...", entry.UserAgent);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandLog(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO log (browser, date, ip, referer)" +
|
||||
" VALUES (@browser, @date, @ip, @referer)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine(" id {0}", id);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updated an access log in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateLog(Log entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating log `{0}`...", entry.UserAgent);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandLog(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE log SET browser = @browser, date = @date, ip = @ip, referer = @referer " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an access log entry 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 RemoveLog(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing log widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM log WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandLog(Log entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param4 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@browser";
|
||||
param2.ParameterName = "@date";
|
||||
param3.ParameterName = "@ip";
|
||||
param4.ParameterName = "@referer";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.String;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.UserAgent;
|
||||
param2.Value = entry.Date;
|
||||
param3.Value = entry.Ip;
|
||||
param4.Value = entry.Referer;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<Log> LogsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Log> entries = new List<Log>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Log entry = new Log
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
UserAgent = (string)dataRow["browser"],
|
||||
Date = (string)dataRow["date"],
|
||||
Ip = (string)dataRow["ip"],
|
||||
Referer = (string)dataRow["referer"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,354 +0,0 @@
|
||||
/******************************************************************************
|
||||
// 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
|
||||
{
|
||||
string sql = $"SELECT * from machines WHERE company = '{company}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = 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.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandMachine(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO machines (company, introduced, name, type, model, family) VALUES (@company, @introduced, @name, @type, @model, @family)";
|
||||
|
||||
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.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandMachine(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE machines SET company = @company, introduced = @introduced, name = @name, type = @type, model = @model, family = @family " +
|
||||
$"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();
|
||||
|
||||
param1.ParameterName = "@company";
|
||||
param2.ParameterName = "@introduced";
|
||||
param3.ParameterName = "@name";
|
||||
param4.ParameterName = "@type";
|
||||
param5.ParameterName = "@model";
|
||||
param6.ParameterName = "@family";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.DateTime;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.Int32;
|
||||
param5.DbType = DbType.String;
|
||||
param6.DbType = DbType.Int32;
|
||||
|
||||
param1.Value = entry.Company;
|
||||
param2.Value = entry.Introduced;
|
||||
param3.Value = entry.Name;
|
||||
param4.Value = entry.Type;
|
||||
param5.Value = entry.Model;
|
||||
param6.Value = entry.Family == 0 ? (object)null : entry.Family;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
dbcmd.Parameters.Add(param5);
|
||||
dbcmd.Parameters.Add(param6);
|
||||
|
||||
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"],
|
||||
Introduced =
|
||||
dataRow["introduced"] == DBNull.Value ? DateTime.MinValue : (DateTime)dataRow["introduced"],
|
||||
Name = (string)dataRow["name"],
|
||||
Type = (MachineType)dataRow["type"],
|
||||
Model = dataRow["model"] == DBNull.Value ? null : (string)dataRow["model"],
|
||||
Family = dataRow["family"] == DBNull.Value ? 0 : (int)dataRow["family"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,326 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : MachineFamily.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage machine_families.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using Cicm.Database.Schemas;
|
||||
|
||||
namespace Cicm.Database
|
||||
{
|
||||
public partial class Operations
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all machine_families
|
||||
/// </summary>
|
||||
/// <param name="entries">All machine_families</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMachineFamilies(out List<MachineFamily> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all machine_families...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from machine_families";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machine_families.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all machine_families from specified company
|
||||
/// </summary>
|
||||
/// <param name="entries">All machine_families</param>
|
||||
/// <param name="company">Company id</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMachineFamilies(out List<MachineFamily> entries, int company)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all machine_families from company id {0}...", company);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from machine_families WHERE company = '{company}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machine_families.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of machine_families since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of machine_families</param>
|
||||
/// <param name="start">Start of query</param>
|
||||
/// <param name="count">How many entries to retrieve</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMachineFamilies(out List<MachineFamily> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} machine_families from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM machine_families LIMIT {start}, {count}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machine_families.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets machine_families by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>MachineFamily with specified id, <c>null</c> if not found or error</returns>
|
||||
public MachineFamily GetMachineFamily(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting machine_families with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from machine_families WHERE id = '{id}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
List<MachineFamily> entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machine_families.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of machine_families in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountMachineFamilies()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting machine_families...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM machine_families";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new administrator to the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Entry to add</param>
|
||||
/// <param name="id">ID of added entry</param>
|
||||
/// <returns><c>true</c> if added correctly, <c>false</c> otherwise</returns>
|
||||
public bool AddMachineFamily(MachineFamily entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding machine_families `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandMachineFamily(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO machine_families (company, name) VALUES (@company, @name)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine(" id {0}", id);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updated a machine_families in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateMachineFamily(MachineFamily entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating machine_families `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandMachineFamily(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE machine_families SET company = @company, name = @name " + $"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a machine_families from the database
|
||||
/// </summary>
|
||||
/// <param name="id">ID of entry to remove</param>
|
||||
/// <returns><c>true</c> if removed correctly, <c>false</c> otherwise</returns>
|
||||
public bool RemoveMachineFamily(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing machine_families widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM machine_families WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandMachineFamily(MachineFamily entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@company";
|
||||
param2.ParameterName = "@name";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.Company;
|
||||
param2.Value = entry.Name;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<MachineFamily> MachineFamiliesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<MachineFamily> entries = new List<MachineFamily>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
MachineFamily entry = new MachineFamily
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Company = (int)dataRow["company"],
|
||||
Name = (string)dataRow["name"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : MemoryByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage memory.
|
||||
//
|
||||
// --[ 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 memory in machine
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMemoryByMachine(out List<MemoryByMachine> entries, int machineId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all memory synths for machine {0}...", machineId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM memory_by_machine WHERE machine = {machineId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = MemoryByMachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting memory by machine.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all machines with specified gpu
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMachinesByMemory(out List<MemoryByMachine> entries, int gpuId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all machines with memory synth {0}...", gpuId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM memory_by_machine WHERE gpu = {gpuId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = MemoryByMachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machines by memory synth.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
IDbCommand GetCommandMemoryByMachine(MemoryByMachine 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();
|
||||
|
||||
param1.ParameterName = "@machine";
|
||||
param2.ParameterName = "@type";
|
||||
param3.ParameterName = "@usage";
|
||||
param4.ParameterName = "@size";
|
||||
param5.ParameterName = "@speed";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.Int32;
|
||||
param4.DbType = DbType.Int64;
|
||||
param5.DbType = DbType.Double;
|
||||
|
||||
param1.Value = entry.Machine;
|
||||
param2.Value = entry.Type;
|
||||
param3.Value = entry.Usage;
|
||||
param4.Value = entry.Size == 0 ? (object)null : entry.Size;
|
||||
param5.Value = entry.Speed <= 0 ? (object)null : entry.Speed;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
dbcmd.Parameters.Add(param5);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<MemoryByMachine> MemoryByMachinesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<MemoryByMachine> entries = new List<MemoryByMachine>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
MemoryByMachine entry = new MemoryByMachine
|
||||
{
|
||||
Machine = (int)dataRow["machine"],
|
||||
Type = (MemoryType)dataRow["type"],
|
||||
Usage = (MemoryUsage)dataRow["usage"],
|
||||
Size = dataRow["size"] == DBNull.Value ? 0 : (long)dataRow["size"],
|
||||
Speed = dataRow["speed"] == DBNull.Value ? 0 : (double)dataRow["speed"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,291 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Money Donation.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage money donations.
|
||||
//
|
||||
// --[ 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 money donations
|
||||
/// </summary>
|
||||
/// <param name="entries">All money donations</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMoneyDonations(out List<MoneyDonation> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all money donations...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from money_donations";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = MoneyDonationsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting money donations.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of money donations since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of money donations</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 GetMoneyDonations(out List<MoneyDonation> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} money donations from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM money_donations 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 = MoneyDonationsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting money donations.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets money donation by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Money donation with specified id, <c>null</c> if not found or error</returns>
|
||||
public MoneyDonation GetMoneyDonation(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting money_donation with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from money_donations 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<MoneyDonation> entries = MoneyDonationsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting money_donation.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of money donations in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountMoneyDonations()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting money donations...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM money_donations";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new money donation 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 AddMoneyDonation(MoneyDonation entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding money_donation `{0}` for `{1}`...", entry.Donator, entry.Quantity);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandMoneyDonation(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO money_donations (donator, quantity)" + " VALUES (@donator, @quantity)";
|
||||
|
||||
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 money donation in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateMoneyDonation(MoneyDonation entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating money_donation `{0}`...", entry.Donator);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandMoneyDonation(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE money_donations SET donator = @donator, quantity = @quantity " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a money donation 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 RemoveMoneyDonation(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing money donation widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM money_donations WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandMoneyDonation(MoneyDonation entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@donator";
|
||||
param2.ParameterName = "@quantity";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.Double;
|
||||
|
||||
param1.Value = entry.Donator;
|
||||
param2.Value = entry.Quantity;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<MoneyDonation> MoneyDonationsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<MoneyDonation> entries = new List<MoneyDonation>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
MoneyDonation entry = new MoneyDonation
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Donator = (string)dataRow["browser"],
|
||||
Quantity = (float)dataRow["date"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : News.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage site 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
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using Cicm.Database.Schemas;
|
||||
|
||||
namespace Cicm.Database
|
||||
{
|
||||
public partial class Operations
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all site news
|
||||
/// </summary>
|
||||
/// <param name="entries">All site news</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetNews(out List<News> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all news...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from news";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = NewsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting news.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of site news since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of site news</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 GetNews(out List<News> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} news from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM news 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 = NewsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting news.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets site news by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Site news with specified id, <c>null</c> if not found or error</returns>
|
||||
public News GetNews(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting news with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from news 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<News> entries = NewsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting news.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of site news in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountNews()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting news...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM news";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new site news 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 AddNews(News entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding news `{0}`...", entry.Date);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandNews(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO news (date, type, added_id)" + " VALUES (@date, @type, @added_id)";
|
||||
|
||||
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 site news in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateNews(News entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating news `{0}`...", entry.Date);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandNews(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE news SET date = @date, type = @type, added_id = @added_id " + $"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a site news entry 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 RemoveNews(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing news widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM news WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandNews(News entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@date";
|
||||
param2.ParameterName = "@type";
|
||||
param3.ParameterName = "@added_id";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.Int32;
|
||||
|
||||
param1.Value = entry.Date;
|
||||
param2.Value = entry.Type;
|
||||
param3.Value = entry.AffectedId;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<News> NewsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<News> entries = new List<News>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
News entry = new News
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Date = (string)dataRow["date"],
|
||||
Type = (NewsType)dataRow["type"],
|
||||
AffectedId = (int)dataRow["added_id"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,361 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : OwnedConsole.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage owned computers.
|
||||
//
|
||||
// --[ 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 owned computers
|
||||
/// </summary>
|
||||
/// <param name="entries">All owned computers</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetOwnedComputers(out List<OwnedComputer> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all owned computers...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from owned_computers";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = OwnedComputersFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting owned computers.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of owned computers since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of owned computers</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 GetOwnedComputers(out List<OwnedComputer> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} owned computers from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM owned_computers 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 = OwnedComputersFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting owned computers.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets owned computer by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Owned computer with specified id, <c>null</c> if not found or error</returns>
|
||||
public OwnedComputer GetOwnedComputer(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting owned computer with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from owned_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<OwnedComputer> entries = OwnedComputersFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting owned computer.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of owned computers in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountOwnedComputers()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting owned computers...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM owned_computers";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new owned computer 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 AddOwnedComputer(OwnedComputer entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding owned computer `{0}`...", entry.ComputerId);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandOwnedComputer(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO owned_computers (db_id, date, status, trade, boxed, manuals, cpu1, mhz1, cpu2, mhz2, ram, vram, rigid, disk1, cap1, disk2, cap2)" +
|
||||
" VALUES (@db_id, @date, @status, @trade, @boxed, @manuals, @cpu1, @mhz1, @cpu2, @mhz2, @ram, @vram, @rigid, @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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updated an owned computer in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateOwnedComputer(OwnedComputer entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating computer `{0}`...", entry.ComputerId);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandOwnedComputer(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE owned_computers SET db_id = @db_id, date = @date, status = @status, trade = @trade, boxed = @boxed, manuals = @manuals, cpu1 = @cpu1" +
|
||||
"mhz1 = @mhz1, cpu2 = @cpu2, mhz2 = @mhz2, ram = @ram, vram = @vram, rigid = @rigid, disk1 = @disk1, cap1 = @cap1, disk2 = @disk2, cap2 = @cap2 " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an owned computer 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 RemoveOwnedComputer(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing owned computer widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM owned_computers WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandOwnedComputer(OwnedComputer 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();
|
||||
|
||||
param1.ParameterName = "@db_id";
|
||||
param2.ParameterName = "@date";
|
||||
param3.ParameterName = "@status";
|
||||
param4.ParameterName = "@trade";
|
||||
param5.ParameterName = "@boxed";
|
||||
param6.ParameterName = "@manuals";
|
||||
param7.ParameterName = "@cpu1";
|
||||
param8.ParameterName = "@mhz1";
|
||||
param9.ParameterName = "@cpu2";
|
||||
param10.ParameterName = "@mhz2";
|
||||
param11.ParameterName = "@ram";
|
||||
param12.ParameterName = "@vram";
|
||||
param13.ParameterName = "@rigid";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.String;
|
||||
param3.DbType = DbType.Int32;
|
||||
param4.DbType = DbType.Boolean;
|
||||
param5.DbType = DbType.Boolean;
|
||||
param6.DbType = DbType.Boolean;
|
||||
param7.DbType = DbType.Int32;
|
||||
param8.DbType = DbType.Double;
|
||||
param9.DbType = DbType.Int32;
|
||||
param10.DbType = DbType.Double;
|
||||
param11.DbType = DbType.Int32;
|
||||
param12.DbType = DbType.Int32;
|
||||
param13.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.ComputerId;
|
||||
param2.Value = entry.Acquired;
|
||||
param3.Value = entry.Status;
|
||||
param4.Value = entry.Trade;
|
||||
param5.Value = entry.Boxed;
|
||||
param6.Value = entry.Manuals;
|
||||
param7.Value = entry.Cpu1;
|
||||
param8.Value = entry.Mhz1;
|
||||
param9.Value = entry.Cpu2;
|
||||
param10.Value = entry.Mhz2;
|
||||
param11.Value = entry.Ram;
|
||||
param12.Value = entry.Vram;
|
||||
param13.Value = entry.Rigid;
|
||||
|
||||
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);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<OwnedComputer> OwnedComputersFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<OwnedComputer> entries = new List<OwnedComputer>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
OwnedComputer entry = new OwnedComputer
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
ComputerId = (int)dataRow["db_id"],
|
||||
Acquired = dataRow["date"].ToString(),
|
||||
Status = (StatusType)dataRow["status"],
|
||||
Trade = (int)dataRow["trade"] > 0,
|
||||
Boxed = (int)dataRow["boxed"] > 0,
|
||||
Manuals = (int)dataRow["manuals"] > 0,
|
||||
Cpu1 = (int)dataRow["cpu1"],
|
||||
Mhz1 = (float)dataRow["mhz1"],
|
||||
Cpu2 = (int)dataRow["cpu1"],
|
||||
Mhz2 = (float)dataRow["mhz2"],
|
||||
Ram = (int)dataRow["ram"],
|
||||
Vram = (int)dataRow["vram"],
|
||||
Rigid = (string)dataRow["rigid"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : OwnConsole.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage owned consoles.
|
||||
//
|
||||
// --[ 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 owned consoles
|
||||
/// </summary>
|
||||
/// <param name="entries">All owned consoles</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetOwnedConsoles(out List<OwnedConsole> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all owned consoles...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from owned_consoles";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = OwnedConsolesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting owned consoles.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of owned consoles since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of owned consoles</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 GetOwnedConsoles(out List<OwnedConsole> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} owned consoles from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM owned_consoles 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 = OwnedConsolesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting owned consoles.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets owned console by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Owned console with specified id, <c>null</c> if not found or error</returns>
|
||||
public OwnedConsole GetOwnedConsole(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting owned console with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from owned_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<OwnedConsole> entries = OwnedConsolesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting owned console.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of owned consoles in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountOwnedConsoles()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting owned consoles...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM owned_consoles";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new owned console 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 AddOwnedConsole(OwnedConsole entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding owned console `{0}`...", entry.ConsoleId);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandOwnedConsole(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO owned_consoles (db_id, date, status, trade, boxed, manuals)" +
|
||||
" VALUES (@db_id, @date, @status, @trade, @boxed, @manuals)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine(" id {0}", id);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updated an owned console in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateOwnedConsole(OwnedConsole entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating owned console `{0}`...", entry.ConsoleId);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandOwnedConsole(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE owned_consoles SET db_id = @db_id, date = @date, status = @status, trade = @trade, boxed = @boxed, manuals = @manuals " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an owned console 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 RemoveOwnedConsole(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing owned console widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM owned_consoles WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandOwnedConsole(OwnedConsole 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();
|
||||
|
||||
param1.ParameterName = "@db_id";
|
||||
param2.ParameterName = "@date";
|
||||
param3.ParameterName = "@status";
|
||||
param4.ParameterName = "@trade";
|
||||
param5.ParameterName = "@boxed";
|
||||
param6.ParameterName = "@manuals";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.String;
|
||||
param3.DbType = DbType.Int32;
|
||||
param4.DbType = DbType.Boolean;
|
||||
param5.DbType = DbType.Boolean;
|
||||
param6.DbType = DbType.Boolean;
|
||||
|
||||
param1.Value = entry.ConsoleId;
|
||||
param2.Value = entry.Acquired;
|
||||
param3.Value = entry.Status;
|
||||
param4.Value = entry.Trade;
|
||||
param5.Value = entry.Boxed;
|
||||
param6.Value = entry.Manuals;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
dbcmd.Parameters.Add(param5);
|
||||
dbcmd.Parameters.Add(param6);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<OwnedConsole> OwnedConsolesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<OwnedConsole> entries = new List<OwnedConsole>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
OwnedConsole entry = new OwnedConsole
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
ConsoleId = (int)dataRow["db_id"],
|
||||
Acquired = dataRow["date"].ToString(),
|
||||
Status = (StatusType)dataRow["status"],
|
||||
Trade = (int)dataRow["trade"] > 0,
|
||||
Boxed = (int)dataRow["boxed"] > 0,
|
||||
Manuals = (int)dataRow["manuals"] > 0
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,419 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Processor.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage processors.
|
||||
//
|
||||
// --[ 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 processors
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetProcessors(out List<Processor> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all processors...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from processors";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ProcessorsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting processors.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of processors since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of processors</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 GetProcessors(out List<Processor> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} processors from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM processors 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 = ProcessorsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting processors.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets processor by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Processor with specified id, <c>null</c> if not found or error</returns>
|
||||
public Processor GetProcessor(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting processor with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from processors 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<Processor> entries = ProcessorsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting processor.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of processors in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountProcessors()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting processors...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM processors";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new processor 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 AddProcessor(Processor entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding processor `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandProcessor(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO processors (name)" + " VALUES (@name)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine(" id {0}", id);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updated a processor in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateProcessor(Processor entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating processor `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandProcessor(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE processors SET name = @name, company = @company, model_code = @model_code," +
|
||||
"introduced = @introduced, instruction_set = @instruction_set, speed = @speed, " +
|
||||
"package = @package, GPRs = @GPRs, GPR_size = @GPR_size, FPRs = @FPRs, FPR_size = @FPR_size," +
|
||||
"cores = @cores, threads_per_core = @threads_per_core, process = @process," +
|
||||
"process_nm = @process_nm, die_size = @die_size, transistors = @transistors," +
|
||||
"data_bus = @data_bus, addr_bus = @addr_bus, SIMD_registers = @SIMD_registers," +
|
||||
"SIMD_size = @SIMD_size, L1_instruction = @L1_instruction, L1_data = @L1_data, L2 = @L2," +
|
||||
"L3 = @L3 " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a processor 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 RemoveProcessor(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing processor widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM processors WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandProcessor(Processor 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 = "@name";
|
||||
param2.ParameterName = "@company";
|
||||
param3.ParameterName = "@model_code";
|
||||
param4.ParameterName = "@introduced";
|
||||
param5.ParameterName = "@instruction_set";
|
||||
param6.ParameterName = "@speed";
|
||||
param7.ParameterName = "@package";
|
||||
param8.ParameterName = "@GPRs";
|
||||
param9.ParameterName = "@GPR_size";
|
||||
param10.ParameterName = "@FPRs";
|
||||
param11.ParameterName = "@FPR_size";
|
||||
param12.ParameterName = "@cores";
|
||||
param13.ParameterName = "@threads_per_core";
|
||||
param14.ParameterName = "@process";
|
||||
param15.ParameterName = "@process_nm";
|
||||
param16.ParameterName = "@die_size";
|
||||
param17.ParameterName = "@transistors";
|
||||
param18.ParameterName = "@addr_bus";
|
||||
param19.ParameterName = "@data_bus";
|
||||
param20.ParameterName = "@SIMD_registers";
|
||||
param21.ParameterName = "@SIMD_size";
|
||||
param22.ParameterName = "@L1_instruction";
|
||||
param23.ParameterName = "@L1_data";
|
||||
param24.ParameterName = "@L2";
|
||||
param25.ParameterName = "@L3";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.DateTime;
|
||||
param5.DbType = DbType.Int32;
|
||||
param6.DbType = DbType.Double;
|
||||
param7.DbType = DbType.String;
|
||||
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.Double;
|
||||
param16.DbType = DbType.Double;
|
||||
param17.DbType = DbType.UInt64;
|
||||
param18.DbType = DbType.Int32;
|
||||
param19.DbType = DbType.Int32;
|
||||
param20.DbType = DbType.Int32;
|
||||
param21.DbType = DbType.Int32;
|
||||
param22.DbType = DbType.Double;
|
||||
param23.DbType = DbType.Double;
|
||||
param24.DbType = DbType.Double;
|
||||
param25.DbType = DbType.Double;
|
||||
|
||||
param1.Value = entry.Name;
|
||||
param2.Value = entry.Company == null ? null : (object)entry.Company.Id;
|
||||
param3.Value = entry.ModelCode;
|
||||
param4.Value = entry.Introduced == DateTime.MinValue ? null : (object)entry.Introduced;
|
||||
param5.Value = entry.InstructionSet?.Name;
|
||||
param6.Value = entry.Speed;
|
||||
param7.Value = entry.Package;
|
||||
param8.Value = entry.Gpr;
|
||||
param9.Value = entry.GprSize;
|
||||
param10.Value = entry.Fpr;
|
||||
param11.Value = entry.FprSize;
|
||||
param12.Value = entry.Cores;
|
||||
param13.Value = entry.ThreadsPerCore;
|
||||
param14.Value = entry.Process;
|
||||
param15.Value = entry.ProcessNm;
|
||||
param16.Value = entry.DieSize;
|
||||
param17.Value = entry.Transistors;
|
||||
param18.Value = entry.AddressBus;
|
||||
param19.Value = entry.DataBus;
|
||||
param20.Value = entry.Simd;
|
||||
param21.Value = entry.SimdSize;
|
||||
param22.Value = entry.L1Instruction;
|
||||
param23.Value = entry.L1Data;
|
||||
param24.Value = entry.L2;
|
||||
param25.Value = entry.L3;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
List<Processor> ProcessorsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Processor> entries = new List<Processor>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Processor entry = new Processor
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Name = (string)dataRow["name"],
|
||||
ModelCode = dataRow["model_code"] == DBNull.Value ? null : (string)dataRow["model_code"],
|
||||
Speed = dataRow["speed"] == DBNull.Value ? 0 : (double)dataRow["speed"],
|
||||
Package = dataRow["package"] == DBNull.Value ? null : (string)dataRow["package"],
|
||||
Gpr = dataRow["GPRs"] == DBNull.Value ? 0 : (int)dataRow["GPRs"],
|
||||
GprSize = dataRow["GPR_size"] == DBNull.Value ? 0 : (int)dataRow["GPR_size"],
|
||||
Fpr = dataRow["FPRs"] == DBNull.Value ? 0 : (int)dataRow["FPRs"],
|
||||
FprSize = dataRow["FPR_size"] == DBNull.Value ? 0 : (int)dataRow["FPR_size"],
|
||||
Cores = dataRow["cores"] == DBNull.Value ? 0 : (int)dataRow["cores"],
|
||||
ThreadsPerCore = dataRow["threads_per_core"] == DBNull.Value ? 0 : (int)dataRow["threads_per_core"],
|
||||
Process = dataRow["process"] == DBNull.Value ? null : (string)dataRow["process"],
|
||||
ProcessNm = dataRow["process_nm"] == DBNull.Value ? 0 : (float)dataRow["process_nm"],
|
||||
DieSize = dataRow["die_size"] == DBNull.Value ? 0 : (float)dataRow["die_size"],
|
||||
Transistors = dataRow["transistors"] == DBNull.Value ? 0 : (long)dataRow["transistors"],
|
||||
AddressBus = dataRow["addr_bus"] == DBNull.Value ? 0 : (int)dataRow["addr_bus"],
|
||||
DataBus = dataRow["data_bus"] == DBNull.Value ? 0 : (int)dataRow["data_bus"],
|
||||
Simd = dataRow["SIMD_registers"] == DBNull.Value ? 0 : (int)dataRow["SIMD_registers"],
|
||||
SimdSize = dataRow["SIMD_size"] == DBNull.Value ? 0 : (int)dataRow["SIMD_size"],
|
||||
L1Instruction = dataRow["L1_instruction"] == DBNull.Value ? 0 : (float)dataRow["L1_instruction"],
|
||||
L1Data = dataRow["L1_data"] == DBNull.Value ? 0 : (float)dataRow["L1_data"],
|
||||
L2 = dataRow["L2"] == DBNull.Value ? 0 : (float)dataRow["L2"],
|
||||
L3 = dataRow["L3"] == DBNull.Value ? 0 : (float)dataRow["L3"],
|
||||
Company = dataRow["company"] == DBNull.Value
|
||||
? null
|
||||
: GetCompany((int)dataRow["company"]),
|
||||
Introduced =
|
||||
dataRow["introduced"] == DBNull.Value
|
||||
? DateTime.MinValue
|
||||
: Convert.ToDateTime(dataRow["introduced"]),
|
||||
InstructionSet = dataRow["instruction_set"] == DBNull.Value
|
||||
? null
|
||||
: GetInstructionSet((int)dataRow["instruction_set"])
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : ProcessorByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage processors.
|
||||
//
|
||||
// --[ 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 processors in machine
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetProcessorsByMachines(out List<ProcessorByMachine> entries, int machineId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all processors for machine {0}...", machineId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM processors_by_machine WHERE machine = {machineId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ProcessorByMachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting processors by machine.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all machines with specified processor
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMachinesByProcessor(out List<ProcessorByMachine> entries, int processorId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all machines with processor {0}...", processorId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM processors_by_machine WHERE processor = {processorId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ProcessorByMachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machines by processor.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
IDbCommand GetCommandProcessorByMachine(ProcessorByMachine entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@processor";
|
||||
param2.ParameterName = "@machine";
|
||||
param3.ParameterName = "@speed";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.Single;
|
||||
|
||||
param1.Value = entry.Processor;
|
||||
param2.Value = entry.Machine;
|
||||
param3.Value = entry.Speed <= 0 ? (object)null : entry.Speed;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<ProcessorByMachine> ProcessorByMachinesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<ProcessorByMachine> entries = new List<ProcessorByMachine>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
ProcessorByMachine entry = new ProcessorByMachine
|
||||
{
|
||||
Machine = (int)dataRow["machine"],
|
||||
Processor = (int)dataRow["processor"],
|
||||
Speed = dataRow["speed"] == DBNull.Value ? 0 : (float)dataRow["speed"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,418 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Resolution.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage Resolutions.
|
||||
//
|
||||
// --[ 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 Resolutions
|
||||
/// </summary>
|
||||
/// <param name="entries">All Resolutions</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetResolutions(out List<Resolution> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all Resolutions...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from resolutions";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ResolutionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting Resolutions.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of Resolutions since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of Resolutions</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 GetResolutions(out List<Resolution> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} Resolutions from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM resolutions 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 = ResolutionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting Resolutions.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets Resolution by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Resolution with specified id, <c>null</c> if not found or error</returns>
|
||||
public Resolution GetResolution(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting Resolution with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from resolutions 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<Resolution> entries = ResolutionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting Resolution.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets Resolution by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Resolution with specified id, <c>null</c> if not found or error</returns>
|
||||
public Resolution GetResolution(int width, int height)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting first resolution of {0}x{1}...", width, height);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from resolutions WHERE width = {width} AND height = {height}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
List<Resolution> entries = ResolutionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting Resolution.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets Resolution by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Resolution with specified id, <c>null</c> if not found or error</returns>
|
||||
public Resolution GetResolution(int width, int height, long colors)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting first resolution of {0}x{1} with {2} colors...", width, height, colors);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql =
|
||||
$"SELECT * from resolutions WHERE width = {width} AND height = {height} AND colors = {colors}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
List<Resolution> entries = ResolutionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting Resolution.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets Resolution by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Resolution with specified id, <c>null</c> if not found or error</returns>
|
||||
public Resolution GetResolution(int width, int height, long colors, long palette)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting first resolution of {0}x{1} with {2} colors from a palette of {3} colors...",
|
||||
width, height, colors, palette);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql =
|
||||
$"SELECT * from resolutions WHERE width = {width} AND height = {height} AND colors = {colors} AND palette = {palette}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
List<Resolution> entries = ResolutionsFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting Resolution.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of Resolutions in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountResolutions()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting resolutions...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM resolutions";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new Resolution 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 AddResolution(Resolution entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding Resolution...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandResolution(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO resolutions (width, height, colors, palette, chars) VALUES (@width, @height, @colors, " +
|
||||
"@palette, @chars)";
|
||||
|
||||
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 Resolution in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateResolution(Resolution entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating Resolution `{0}`...", entry.Id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandResolution(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE resolutions SET width = @width, height = @height, colors = @colors, palette = @palette, " +
|
||||
"chars = @chars " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a Resolution 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 RemoveResolution(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing Resolution widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM resolutions WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandResolution(Resolution 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();
|
||||
|
||||
param1.ParameterName = "@width";
|
||||
param2.ParameterName = "@height";
|
||||
param3.ParameterName = "@colors";
|
||||
param4.ParameterName = "@palette";
|
||||
param5.ParameterName = "@chars";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.Int64;
|
||||
param4.DbType = DbType.Int64;
|
||||
param5.DbType = DbType.Boolean;
|
||||
|
||||
param1.Value = entry.Width;
|
||||
param2.Value = entry.Height;
|
||||
param3.Value = entry.Colors == 0 ? (object)null : entry.Colors;
|
||||
param4.Value = entry.Palette == 0 ? (object)null : entry.Palette;
|
||||
param5.Value = entry.Chars;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
dbcmd.Parameters.Add(param5);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<Resolution> ResolutionsFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Resolution> entries = new List<Resolution>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Resolution entry = new Resolution
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Width = (int)dataRow["width"],
|
||||
Height = (int)dataRow["height"],
|
||||
Colors = dataRow["colors"] == DBNull.Value ? 0 : (long)dataRow["colors"],
|
||||
Palette = dataRow["palette"] == DBNull.Value ? 0 : (long)dataRow["palette"],
|
||||
Chars = (bool)dataRow["chars"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Resolution.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage Resolutions.
|
||||
//
|
||||
// --[ 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 Resolutions
|
||||
/// </summary>
|
||||
/// <param name="entries">All Resolutions</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetResolutions(out List<Resolution> entries, int gpuId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all resolutions for GPU {0}...", gpuId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM resolutions_by_gpu WHERE gpu = {gpuId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = new List<Resolution>();
|
||||
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
|
||||
entries.Add(GetResolution((int)dataRow["resolution"]));
|
||||
|
||||
if(entries.Count != 0) return true;
|
||||
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting Resolutions.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : SoundByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage sound.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <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 sound in machine
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetSoundsByMachines(out List<SoundByMachine> entries, int machineId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all sound synths for machine {0}...", machineId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM sound_by_machine WHERE machine = {machineId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = SoundByMachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting sound by machine.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all machines with specified gpu
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMachinesBySound(out List<SoundByMachine> entries, int gpuId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all machines with sound synth {0}...", gpuId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM sound_by_machine WHERE gpu = {gpuId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = SoundByMachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machines by sound synth.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
IDbCommand GetCommandSoundByMachine(SoundByMachine entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@sound_synth";
|
||||
param2.ParameterName = "@machine";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
|
||||
param1.Value = entry.SoundSynth;
|
||||
param2.Value = entry.Machine;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<SoundByMachine> SoundByMachinesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<SoundByMachine> entries = new List<SoundByMachine>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
SoundByMachine entry = new SoundByMachine
|
||||
{
|
||||
Machine = (int)dataRow["machine"],
|
||||
SoundSynth = (int)dataRow["sound_synth"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,345 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : SoundSynth.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage sound synthetizers.
|
||||
//
|
||||
// --[ 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 sound synthetizers
|
||||
/// </summary>
|
||||
/// <param name="entries">All sound synthetizers</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetSoundSynths(out List<SoundSynth> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all sound synthetizers...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from sound_synths";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = SoundSynthFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting sound synthetizers.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of sound synthetizers since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of sound synthetizers</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 GetSoundSynths(out List<SoundSynth> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} sound synthetizers from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM sound_synths 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 = SoundSynthFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting sound synthetizers.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets sound synthetizer by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Sound synthetizer with specified id, <c>null</c> if not found or error</returns>
|
||||
public SoundSynth GetSoundSynth(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting sound synthetizer with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from sound_synths 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<SoundSynth> entries = SoundSynthFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting sound synthetizer.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of sound synthetizers in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountSoundSynths()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting sound synthetizers...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM sound_synths";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new sound synthetizer 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 AddSoundSynth(SoundSynth entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding sound synthetizer `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandSoundSynth(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL = "INSERT INTO sound_synths (name, company, model_code, introduced, voices, frequency, " +
|
||||
"depth, square_wave, white_noise, type) VALUES (@name, @company, @model_code, " +
|
||||
"@introduced, @voices, @frequency, @depth, @square_wave, @white_noise, @type)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine(" id {0}", id);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updated a sound synthetizer in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateSoundSynth(SoundSynth entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating sound synthetizer `{0}`...", entry.Name);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandSoundSynth(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = "UPDATE sound_synths SET name = @name, company = @company, model_code = @model_code, " +
|
||||
"introduced = @introduced, voices = @voices, frequency = @frequency, depth = @depth, " +
|
||||
"square_wave = @square_wave, white_noise = @white_noise, type = @type, " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a sound synthetizer 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 RemoveSoundSynth(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing sound synthetizer widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM sound_synths WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandSoundSynth(SoundSynth 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();
|
||||
|
||||
param1.ParameterName = "@name";
|
||||
param2.ParameterName = "@company";
|
||||
param3.ParameterName = "@model_code";
|
||||
param4.ParameterName = "@introduced";
|
||||
param5.ParameterName = "@voices";
|
||||
param6.ParameterName = "@frequency";
|
||||
param7.ParameterName = "@depth";
|
||||
param8.ParameterName = "@square_wave";
|
||||
param9.ParameterName = "@white_noise";
|
||||
param10.ParameterName = "@type";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.DateTime;
|
||||
param5.DbType = DbType.Int32;
|
||||
param6.DbType = DbType.Double;
|
||||
param7.DbType = DbType.Int32;
|
||||
param8.DbType = DbType.Int32;
|
||||
param9.DbType = DbType.Int32;
|
||||
param10.DbType = DbType.Int32;
|
||||
|
||||
param1.Value = entry.Name;
|
||||
param2.Value = entry.Company?.Id;
|
||||
param3.Value = entry.ModelCode;
|
||||
param4.Value = entry.Introduced == DateTime.MinValue ? (object)null : entry.Introduced;
|
||||
param5.Value = entry.Voices == 0 ? (object)null : entry.Voices;
|
||||
param6.Value = entry.Frequency <= 0 ? (object)null : entry.Frequency;
|
||||
param7.Value = entry.Depth == 0 ? (object)null : entry.Depth;
|
||||
param8.Value = entry.SquareWave == 0 ? (object)null : entry.SquareWave;
|
||||
param9.Value = entry.WhiteNoise == 0 ? (object)null : entry.WhiteNoise;
|
||||
param10.Value = entry.Type == 0 ? (object)null : entry.Type;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
dbcmd.Parameters.Add(param5);
|
||||
dbcmd.Parameters.Add(param6);
|
||||
dbcmd.Parameters.Add(param7);
|
||||
dbcmd.Parameters.Add(param8);
|
||||
dbcmd.Parameters.Add(param9);
|
||||
dbcmd.Parameters.Add(param10);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
List<SoundSynth> SoundSynthFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<SoundSynth> entries = new List<SoundSynth>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
SoundSynth entry = new SoundSynth
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Name = (string)dataRow["name"],
|
||||
ModelCode = dataRow["model_code"] == DBNull.Value ? null : (string)dataRow["model_code"],
|
||||
Voices = dataRow["voices"] == DBNull.Value ? 0 : (int)dataRow["voices"],
|
||||
Frequency = dataRow["frequency"] == DBNull.Value ? 0 : (double)dataRow["frequency"],
|
||||
Depth = dataRow["depth"] == DBNull.Value ? 0 : (int)dataRow["depth"],
|
||||
SquareWave = dataRow["square_wave"] == DBNull.Value ? 0 : (int)dataRow["square_wave"],
|
||||
WhiteNoise = dataRow["white_noise"] == DBNull.Value ? 0 : (int)dataRow["white_noise"],
|
||||
Type = dataRow["type"] == DBNull.Value ? 0 : (int)dataRow["type"],
|
||||
Company = dataRow["company"] == DBNull.Value ? null : GetCompany((int)dataRow["company"]),
|
||||
Introduced = dataRow["introduced"] == DBNull.Value
|
||||
? DateTime.MinValue
|
||||
: Convert.ToDateTime(dataRow["introduced"])
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : StorageByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage storage.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <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 storage in machine
|
||||
/// </summary>
|
||||
/// <param name="entries">All CPUs</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetStorageByMachines(out List<StorageByMachine> entries, int machineId)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all storage for machine {0}...", machineId);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM storage_by_machine WHERE machine = {machineId}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = StorageByMachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting storage by machine.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
IDbCommand GetCommandStorageByMachine(StorageByMachine entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param4 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@machine";
|
||||
param2.ParameterName = "@type";
|
||||
param3.ParameterName = "@interface";
|
||||
param4.ParameterName = "@capacity";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.Int32;
|
||||
param4.DbType = DbType.Int64;
|
||||
|
||||
param1.Value = entry.Machine;
|
||||
param2.Value = entry.Type;
|
||||
param3.Value = entry.Interface;
|
||||
param4.Value = entry.Capacity == 0 ? (object)null : entry.Capacity;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<StorageByMachine> StorageByMachinesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<StorageByMachine> entries = new List<StorageByMachine>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
StorageByMachine entry = new StorageByMachine
|
||||
{
|
||||
Machine = (int)dataRow["machine"],
|
||||
Type = (StorageType)dataRow["type"],
|
||||
Interface = (StorageInterface)dataRow["interface"],
|
||||
Capacity = dataRow["capacity"] == DBNull.Value ? 0 : (long)dataRow["capacity"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Admin.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a site administrator.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Site administrator</summary>
|
||||
public class Admin
|
||||
{
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Hashed password</summary>
|
||||
public string Password;
|
||||
/// <summary>Username</summary>
|
||||
public string Username;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : BrowserTest.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a browser test.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Browser test</summary>
|
||||
public class BrowserTest
|
||||
{
|
||||
/// <summary>Supports PNG with alpha channel</summary>
|
||||
public bool AlphaPng;
|
||||
/// <summary>Supports animated GIF</summary>
|
||||
public bool AnimatedGif;
|
||||
/// <summary>Browser architecture</summary>
|
||||
public string Architecture;
|
||||
/// <summary>Supports colors</summary>
|
||||
public bool Color;
|
||||
/// <summary>Supports Adobe Flash</summary>
|
||||
public bool Flash;
|
||||
/// <summary>Supports IFRAMEs</summary>
|
||||
public bool Frames;
|
||||
/// <summary>Supports GIF87</summary>
|
||||
public bool Gif87;
|
||||
/// <summary>Supports GIF with transparency (GIF89)</summary>
|
||||
public bool Gif89;
|
||||
/// <summary>ID</summary>
|
||||
public ushort Id;
|
||||
/// <summary>Supports JPEG</summary>
|
||||
public bool Jpeg;
|
||||
/// <summary>Supports JavaScript</summary>
|
||||
public bool Js;
|
||||
/// <summary>Browser name</summary>
|
||||
public string Name;
|
||||
/// <summary>Browser operating system</summary>
|
||||
public string OperatingSystem;
|
||||
/// <summary>Supports PNG</summary>
|
||||
public bool Png;
|
||||
/// <summary>Supports HTML tables</summary>
|
||||
public bool Tables;
|
||||
/// <summary>User agent string</summary>
|
||||
public string UserAgent;
|
||||
/// <summary>Browser version</summary>
|
||||
public string Version;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Company.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a company.
|
||||
//
|
||||
// --[ 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;
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Company</summary>
|
||||
public class Company
|
||||
{
|
||||
/// <summary>Address</summary>
|
||||
public string Address;
|
||||
/// <summary>City</summary>
|
||||
public string City;
|
||||
/// <summary>Country</summary>
|
||||
public Iso3166 Country;
|
||||
/// <summary>Description</summary>
|
||||
public string Description;
|
||||
/// <summary>Facebook account</summary>
|
||||
public string Facebook;
|
||||
/// <summary>Founding date</summary>
|
||||
public DateTime Founded;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Last logo</summary>
|
||||
public CompanyLogo LastLogo;
|
||||
/// <summary>Logos</summary>
|
||||
public CompanyLogo[] Logos;
|
||||
/// <summary>Name</summary>
|
||||
public string Name;
|
||||
/// <summary>Postal code</summary>
|
||||
public string PostalCode;
|
||||
/// <summary>Province</summary>
|
||||
public string Province;
|
||||
/// <summary>Sold date</summary>
|
||||
public DateTime Sold;
|
||||
/// <summary>Company it was sold to</summary>
|
||||
public Company SoldTo;
|
||||
/// <summary>Company status</summary>
|
||||
public CompanyStatus Status;
|
||||
/// <summary>Twitter account</summary>
|
||||
public string Twitter;
|
||||
/// <summary>Website</summary>
|
||||
public string Website;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Company.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a company.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Company description</summary>
|
||||
public class CompanyDescription
|
||||
{
|
||||
/// <summary>Company ID</summary>
|
||||
public int CompanyId;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Description</summary>
|
||||
public string Text;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Company.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a company.
|
||||
//
|
||||
// --[ 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;
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Company logo</summary>
|
||||
public class CompanyLogo
|
||||
{
|
||||
/// <summary>Company ID</summary>
|
||||
public int CompanyId;
|
||||
/// <summary>Logo GUID</summary>
|
||||
public Guid Guid;
|
||||
/// <summary>Logo ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Year when the company started using this logo, null for unknown</summary>
|
||||
public int Year;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Forbidden.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representaiton of a forbidden access.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Accesses forbidden with HTTP STATUS 403</summary>
|
||||
public class Forbidden
|
||||
{
|
||||
/// <summary>Date of access</summary>
|
||||
public string Date;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Access IP</summary>
|
||||
public string Ip;
|
||||
/// <summary>Referer</summary>
|
||||
public string Referer;
|
||||
/// <summary>User agent</summary>
|
||||
public string UserAgent;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Gpu.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a GPU (Graphics Processing Unit).
|
||||
//
|
||||
// --[ 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;
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Graphics Processing Unit</summary>
|
||||
public class Gpu
|
||||
{
|
||||
/// <summary>Company</summary>
|
||||
public Company Company;
|
||||
/// <summary>Size of die in square milimeters</summary>
|
||||
public float DieSize;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Datetime of introduction</summary>
|
||||
public DateTime Introduced;
|
||||
/// <summary>Model/SKU code</summary>
|
||||
public string ModelCode;
|
||||
/// <summary>Name</summary>
|
||||
public string Name;
|
||||
/// <summary>Package</summary>
|
||||
public string Package;
|
||||
/// <summary>Name of litography process</summary>
|
||||
public string Process;
|
||||
/// <summary>Nanometers of litography process</summary>
|
||||
public float ProcessNm;
|
||||
/// <summary>How many transistors in package</summary>
|
||||
public long Transistors;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Computer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a computer.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Computer</summary>
|
||||
public class GpuByMachine
|
||||
{
|
||||
/// <summary>GPU ID</summary>
|
||||
public int Gpu;
|
||||
/// <summary>Machine ID</summary>
|
||||
public int Machine;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : InstructionSet.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of an instruction set.
|
||||
//
|
||||
// --[ 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 InstructionSet
|
||||
{
|
||||
/// <summary>Instruction Set ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Name of the instruction set</summary>
|
||||
public string Name;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : InstructionSet.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of an instruction set.
|
||||
//
|
||||
// --[ 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 InstructionSetExtension
|
||||
{
|
||||
/// <summary>Instruction set extension ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Instruction set extension name</summary>
|
||||
public string Name;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Iso3166.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a ISO 3166-1 Numeric.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Country code from ISO 3166-1 Numeric</summary>
|
||||
public class Iso3166
|
||||
{
|
||||
/// <summary>ISO assigned ID</summary>
|
||||
public short Id;
|
||||
/// <summary>English name</summary>
|
||||
public string Name;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Log.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of an access log entry.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>
|
||||
/// Access log
|
||||
/// </summary>
|
||||
public class Log
|
||||
{
|
||||
/// <summary>Access date</summary>
|
||||
public string Date;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Access IP</summary>
|
||||
public string Ip;
|
||||
/// <summary>Referer</summary>
|
||||
public string Referer;
|
||||
/// <summary>User agent string</summary>
|
||||
public string UserAgent;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Computer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a computer.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Computer</summary>
|
||||
public class Machine
|
||||
{
|
||||
/// <summary>Manufacturer's company ID</summary>
|
||||
public int Company;
|
||||
/// <summary>Machine family</summary>
|
||||
public int Family;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Introduction date, null if unknown, 1000 if prototype</summary>
|
||||
public DateTime Introduced;
|
||||
/// <summary>Machine model/SKU</summary>
|
||||
public string Model;
|
||||
/// <summary>Model name</summary>
|
||||
public string Name;
|
||||
/// <summary>Machine type</summary>
|
||||
public MachineType Type;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Computer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a computer.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Computer</summary>
|
||||
public class MachineFamily
|
||||
{
|
||||
/// <summary>Manufacturer's company ID</summary>
|
||||
public int Company;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Model name</summary>
|
||||
public string Name;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : MemoryByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a computer.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Computer</summary>
|
||||
public class MemoryByMachine
|
||||
{
|
||||
/// <summary>Machine ID</summary>
|
||||
public int Machine;
|
||||
/// <summary>Memory size in bytes</summary>
|
||||
public long Size;
|
||||
/// <summary>Memory speed in Hz</summary>
|
||||
public double Speed;
|
||||
/// <summary>Memory type</summary>
|
||||
public MemoryType Type;
|
||||
/// <summary>Memory usage</summary>
|
||||
public MemoryUsage Usage;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : MoneyDonation.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a money donation.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Money donations</summary>
|
||||
public class MoneyDonation
|
||||
{
|
||||
/// <summary>Donator</summary>
|
||||
public string Donator;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Donation quantity in euros</summary>
|
||||
public float Quantity;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : MusicSynth.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a music synthetizer.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Music synthetizer</summary>
|
||||
public class MusicSynth
|
||||
{
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Name</summary>
|
||||
public string Name;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : News.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of site 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
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Site news</summary>
|
||||
public class News
|
||||
{
|
||||
/// <summary>Affected ID</summary>
|
||||
public int AffectedId;
|
||||
/// <summary>Date</summary>
|
||||
public string Date;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>News type</summary>
|
||||
public NewsType Type;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : OwnComputer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of an owned computer.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Owned computer</summary>
|
||||
public class OwnedComputer
|
||||
{
|
||||
/// <summary>Acquired date</summary>
|
||||
public string Acquired;
|
||||
/// <summary>Box present in collection</summary>
|
||||
public bool Boxed;
|
||||
/// <summary>Computer's ID</summary>
|
||||
public int ComputerId;
|
||||
/// <summary>Primary CPU</summary>
|
||||
public int Cpu1;
|
||||
/// <summary>Secondary CPU</summary>
|
||||
public int Cpu2;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Original manuals present in collection</summary>
|
||||
public bool Manuals;
|
||||
/// <summary>Frequency in MHz of primary CPU</summary>
|
||||
public float Mhz1;
|
||||
/// <summary>Frequency in MHz of secondary CPU</summary>
|
||||
public float Mhz2;
|
||||
/// <summary>Size in kibibytes of program RAM</summary>
|
||||
public int Ram;
|
||||
/// <summary>Rigid disk</summary>
|
||||
public string Rigid;
|
||||
/// <summary>Status</summary>
|
||||
public StatusType Status;
|
||||
/// <summary>Available for trade</summary>
|
||||
public bool Trade;
|
||||
/// <summary>Size in kibibytes for video RAM</summary>
|
||||
public int Vram;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : OwnConsole.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of an owned 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
|
||||
{
|
||||
/// <summary>Owned videogame console</summary>
|
||||
public class OwnedConsole
|
||||
{
|
||||
/// <summary>Acquired date</summary>
|
||||
public string Acquired;
|
||||
/// <summary>Box present in collection</summary>
|
||||
public bool Boxed;
|
||||
/// <summary>Videogame console's ID</summary>
|
||||
public int ConsoleId;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Original manuals present in collection</summary>
|
||||
public bool Manuals;
|
||||
/// <summary>Status</summary>
|
||||
public StatusType Status;
|
||||
/// <summary>Available for trade</summary>
|
||||
public bool Trade;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Processor.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a processor .
|
||||
//
|
||||
// --[ 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;
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Processor</summary>
|
||||
public class Processor
|
||||
{
|
||||
/// <summary>Size in bits of address bus with host (not interprocessor)</summary>
|
||||
public int AddressBus;
|
||||
/// <summary>Company</summary>
|
||||
public Company Company;
|
||||
/// <summary>How many processor cores per processor package</summary>
|
||||
public int Cores;
|
||||
/// <summary>Size in bits of data bus with host (not interprocessor)</summary>
|
||||
public int DataBus;
|
||||
/// <summary>Size of die in square milimeters</summary>
|
||||
public float DieSize;
|
||||
/// <summary>Number of available Floating Point Registers</summary>
|
||||
public int Fpr;
|
||||
/// <summary>Size in bits of FPRs</summary>
|
||||
public int FprSize;
|
||||
/// <summary>Number of available General Purpose Registers</summary>
|
||||
public int Gpr;
|
||||
/// <summary>Size in bits of GPRs</summary>
|
||||
public int GprSize;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Instruction set</summary>
|
||||
public InstructionSet InstructionSet;
|
||||
/// <summary>Extensions to the instruction set that are implemented in this processor</summary>
|
||||
public InstructionSetExtension[] InstructionSetExtensions;
|
||||
/// <summary>Datetime of introduction</summary>
|
||||
public DateTime Introduced;
|
||||
/// <summary>Size in kibibytes of L1 data cache. If -1, <see cref="L1Instruction" /> is size of L1 unified cache</summary>
|
||||
public float L1Data;
|
||||
/// <summary>Size in kibibytes of L1 instruction cache. If <see cref="L1Data" /> is -1, this is size of L1 unified cache</summary>
|
||||
public float L1Instruction;
|
||||
/// <summary>
|
||||
/// Size in kibibytes of L2 cache. It includes cache that's in same physical package but not in same chip die
|
||||
/// (e.g. Pentium II)
|
||||
/// </summary>
|
||||
public float L2;
|
||||
/// <summary>Size in kibibytes of L3 cache</summary>
|
||||
public float L3;
|
||||
/// <summary>Model/SKU code</summary>
|
||||
public string ModelCode;
|
||||
/// <summary>Name</summary>
|
||||
public string Name;
|
||||
/// <summary>Package</summary>
|
||||
public string Package;
|
||||
/// <summary>Name of litography process</summary>
|
||||
public string Process;
|
||||
/// <summary>Nanometers of litography process</summary>
|
||||
public float ProcessNm;
|
||||
/// <summary>Number of available SIMD registers</summary>
|
||||
public int Simd;
|
||||
/// <summary>Size in bits of SIMD registers</summary>
|
||||
public int SimdSize;
|
||||
/// <summary>Nominal speed, in MHz</summary>
|
||||
public double Speed;
|
||||
/// <summary>How many simultaneos threads can run on each processor core</summary>
|
||||
public int ThreadsPerCore;
|
||||
/// <summary>How many transistors in package</summary>
|
||||
public long Transistors;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Computer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a computer.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Computer</summary>
|
||||
public class ProcessorByMachine
|
||||
{
|
||||
/// <summary>Machine ID</summary>
|
||||
public int Machine;
|
||||
/// <summary>Processor ID</summary>
|
||||
public int Processor;
|
||||
/// <summary>Processor speed in MHz</summary>
|
||||
public float Speed;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Processor.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a processor .
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Processor</summary>
|
||||
public class Resolution
|
||||
{
|
||||
/// <summary>If <c>true</c> width and height indicate characters, else they indicate pixels</summary>
|
||||
public bool Chars;
|
||||
/// <summary>Colors</summary>
|
||||
public long Colors;
|
||||
/// <summary>Height</summary>
|
||||
public int Height;
|
||||
/// <summary>Resolution ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Palette, 0 if same as <see cref="Colors" /></summary>
|
||||
public long Palette;
|
||||
/// <summary>Width</summary>
|
||||
public int Width;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Computer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a computer.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Computer</summary>
|
||||
public class SoundByMachine
|
||||
{
|
||||
/// <summary>Machine ID</summary>
|
||||
public int Machine;
|
||||
/// <summary>Sound synth ID</summary>
|
||||
public int SoundSynth;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : SoundSynth.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a sound synthetizer.
|
||||
//
|
||||
// --[ 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;
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Sound synthetizer</summary>
|
||||
public class SoundSynth
|
||||
{
|
||||
/// <summary>Company</summary>
|
||||
public Company Company;
|
||||
/// <summary>Sample rate in bits of the generate sound</summary>
|
||||
public int Depth;
|
||||
/// <summary>Frequency in Hz of the generated sound</summary>
|
||||
public double Frequency;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Datetime of introduction</summary>
|
||||
public DateTime Introduced;
|
||||
/// <summary>Model/SKU code</summary>
|
||||
public string ModelCode;
|
||||
/// <summary>Name</summary>
|
||||
public string Name;
|
||||
/// <summary>Simultaneous square wave generators</summary>
|
||||
public int SquareWave;
|
||||
/// <summary>Type of sound synthetizer</summary>
|
||||
public int Type;
|
||||
/// <summary>Simultaneous voices that can be generated</summary>
|
||||
public int Voices;
|
||||
/// <summary>Simultaneous white noise generators</summary>
|
||||
public int WhiteNoise;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Computer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a computer.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Computer</summary>
|
||||
public class StorageByMachine
|
||||
{
|
||||
/// <summary>Capacity in bytes</summary>
|
||||
public long Capacity;
|
||||
/// <summary>Storage interface</summary>
|
||||
public StorageInterface Interface;
|
||||
/// <summary>Machine ID</summary>
|
||||
public int Machine;
|
||||
/// <summary>Storage type</summary>
|
||||
public StorageType Type;
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Company.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Company 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;
|
||||
using Cicm.Database.Schemas;
|
||||
using Markdig;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class CompanyWithItems
|
||||
{
|
||||
public string Address;
|
||||
public string City;
|
||||
public MachineMini[] Computers;
|
||||
public MachineMini[] Consoles;
|
||||
public Iso3166 Country;
|
||||
public string Description;
|
||||
public string Facebook;
|
||||
public DateTime Founded;
|
||||
public int Id;
|
||||
public CompanyLogo LastLogo;
|
||||
public CompanyLogo[] Logos;
|
||||
public string Name;
|
||||
public string PostalCode;
|
||||
public string Province;
|
||||
public DateTime Sold;
|
||||
public Cicm.Database.Schemas.Company SoldTo;
|
||||
public CompanyStatus Status;
|
||||
public string Twitter;
|
||||
public string Website;
|
||||
|
||||
public static CompanyWithItems GetItem(int id)
|
||||
{
|
||||
Cicm.Database.Schemas.Company dbItem = Program.Database?.Operations.GetCompany(id);
|
||||
MarkdownPipeline pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
|
||||
|
||||
return dbItem == null
|
||||
? null
|
||||
: new CompanyWithItems
|
||||
{
|
||||
Name = dbItem.Name,
|
||||
Id = dbItem.Id,
|
||||
Computers = ComputerMini.GetItemsWithCompany(id, dbItem.Name),
|
||||
Consoles = ConsoleMini.GetItemsWithCompany(id, dbItem.Name),
|
||||
Address = dbItem.Address,
|
||||
City = dbItem.City,
|
||||
Country = dbItem.Country,
|
||||
Facebook = dbItem.Facebook,
|
||||
Founded = dbItem.Founded,
|
||||
PostalCode = dbItem.PostalCode,
|
||||
Province = dbItem.Province,
|
||||
Sold = dbItem.Sold,
|
||||
SoldTo = dbItem.SoldTo,
|
||||
Status = dbItem.Status,
|
||||
Twitter = dbItem.Twitter,
|
||||
Website = dbItem.Website,
|
||||
Logos = dbItem.Logos,
|
||||
LastLogo = dbItem.LastLogo,
|
||||
Description =
|
||||
dbItem.Description == null ? null : Markdown.ToHtml(dbItem.Description, pipeline)
|
||||
};
|
||||
}
|
||||
|
||||
public static CompanyWithItems[] GetAllItems()
|
||||
{
|
||||
List<Cicm.Database.Schemas.Company> dbItems = null;
|
||||
bool? result = Program.Database?.Operations.GetCompanies(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
MarkdownPipeline pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
|
||||
|
||||
return dbItems.Select(t => new CompanyWithItems
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
Computers = ComputerMini.GetItemsWithCompany(t.Id, t.Name),
|
||||
Consoles = ConsoleMini.GetItemsWithCompany(t.Id, t.Name),
|
||||
Address = t.Address,
|
||||
City = t.City,
|
||||
Country = t.Country,
|
||||
Facebook = t.Facebook,
|
||||
Founded = t.Founded,
|
||||
PostalCode = t.PostalCode,
|
||||
Province = t.Province,
|
||||
Sold = t.Sold,
|
||||
SoldTo = t.SoldTo,
|
||||
Status = t.Status,
|
||||
Twitter = t.Twitter,
|
||||
Website = t.Website,
|
||||
Logos = t.Logos,
|
||||
LastLogo = t.LastLogo,
|
||||
Description = t.Description == null ? null : Markdown.ToHtml(t.Description, pipeline)
|
||||
}).OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static CompanyWithItems[] GetItemsStartingWithLetter(char letter)
|
||||
{
|
||||
List<Cicm.Database.Schemas.Company> dbItems = null;
|
||||
bool? result = Program.Database?.Operations.GetCompanies(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
MarkdownPipeline pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
|
||||
|
||||
return dbItems
|
||||
.Where(t => t.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
|
||||
.Select(t => new CompanyWithItems
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
Computers = ComputerMini.GetItemsWithCompany(t.Id, t.Name),
|
||||
Consoles = ConsoleMini.GetItemsWithCompany(t.Id, t.Name),
|
||||
Address = t.Address,
|
||||
City = t.City,
|
||||
Country = t.Country,
|
||||
Facebook = t.Facebook,
|
||||
Founded = t.Founded,
|
||||
PostalCode = t.PostalCode,
|
||||
Province = t.Province,
|
||||
Sold = t.Sold,
|
||||
SoldTo = t.SoldTo,
|
||||
Status = t.Status,
|
||||
Twitter = t.Twitter,
|
||||
Website = t.Website,
|
||||
Logos = t.Logos,
|
||||
LastLogo = t.LastLogo,
|
||||
Description = t.Description == null ? null : Markdown.ToHtml(t.Description, pipeline)
|
||||
}).OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public class Company
|
||||
{
|
||||
public int Id;
|
||||
public CompanyLogo LastLogo;
|
||||
public string Name;
|
||||
|
||||
public static Company GetItem(int id)
|
||||
{
|
||||
Cicm.Database.Schemas.Company dbItem = Program.Database?.Operations.GetCompany(id);
|
||||
|
||||
return dbItem == null ? null : new Company {Name = dbItem.Name, Id = dbItem.Id, LastLogo = dbItem.LastLogo};
|
||||
}
|
||||
|
||||
public static Company[] GetAllItems()
|
||||
{
|
||||
List<Cicm.Database.Schemas.Company> dbItems = null;
|
||||
bool? result = Program.Database?.Operations.GetCompanies(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
return dbItems.Select(t => new Company {Id = t.Id, Name = t.Name, LastLogo = t.LastLogo})
|
||||
.OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static Company[] GetItemsStartingWithLetter(char letter)
|
||||
{
|
||||
List<Cicm.Database.Schemas.Company> dbItems = null;
|
||||
bool? result =
|
||||
Program.Database?.Operations.GetCompanies(out dbItems, letter);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
return dbItems.Select(t => new Company {Id = t.Id, Name = t.Name, LastLogo = t.LastLogo})
|
||||
.OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static Company[] GetItemsByCountry(int countryCode)
|
||||
{
|
||||
List<Cicm.Database.Schemas.Company> dbItems = null;
|
||||
bool? result =
|
||||
Program.Database?.Operations.GetCompanies(out dbItems, countryCode);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
return dbItems.Select(t => new Company {Id = t.Id, Name = t.Name, LastLogo = t.LastLogo})
|
||||
.OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Computer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Videogame console 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;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public static class Computer
|
||||
{
|
||||
public static Machine[] GetAllItems()
|
||||
{
|
||||
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<Machine> items = new List<Machine>();
|
||||
|
||||
return dbItems.Select(Machine.TransformItem).OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static Machine[] GetItemsFromCompany(int id)
|
||||
{
|
||||
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(Machine.TransformItem).OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static Machine GetItem(int id)
|
||||
{
|
||||
Cicm.Database.Schemas.Machine dbItem = Program.Database?.Operations.GetComputer(id);
|
||||
return dbItem == null ? null : Machine.TransformItem(dbItem);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ComputerMini
|
||||
{
|
||||
public static MachineMini[] GetAllItems()
|
||||
{
|
||||
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<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.Name).ToArray();
|
||||
}
|
||||
|
||||
public static MachineMini[] GetItemsStartingWithLetter(char letter)
|
||||
{
|
||||
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<MachineMini> items = new List<MachineMini>();
|
||||
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
|
||||
if(dbItem.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
|
||||
items.Add(MachineMini.TransformItem(dbItem));
|
||||
|
||||
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static MachineMini[] GetItemsFromYear(int year)
|
||||
{
|
||||
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<MachineMini> items = new List<MachineMini>();
|
||||
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
|
||||
if(dbItem.Introduced.Year == year)
|
||||
items.Add(MachineMini.TransformItem(dbItem));
|
||||
|
||||
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static MachineMini[] GetItemsWithCompany(int id, string companyName)
|
||||
{
|
||||
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 MachineMini
|
||||
{
|
||||
Company = new Company {Id = id, Name = companyName},
|
||||
Id = t.Id,
|
||||
Name = t.Name
|
||||
}).OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static MachineMini[] GetItemsFromCompany(int id)
|
||||
{
|
||||
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(MachineMini.TransformItem).OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Console.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Videogame console 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;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public static class Console
|
||||
{
|
||||
public static Machine[] GetAllItems()
|
||||
{
|
||||
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(Machine.TransformItem) as Machine[];
|
||||
}
|
||||
|
||||
public static Machine[] GetItemsFromCompany(int id)
|
||||
{
|
||||
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(Machine.TransformItem).OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static Machine GetItem(int id)
|
||||
{
|
||||
Cicm.Database.Schemas.Machine dbItem = Program.Database?.Operations.GetConsole(id);
|
||||
return dbItem == null ? null : Machine.TransformItem(dbItem);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConsoleMini
|
||||
{
|
||||
public static MachineMini[] GetAllItems()
|
||||
{
|
||||
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<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.Name).ToArray();
|
||||
}
|
||||
|
||||
public static MachineMini[] GetItemsStartingWithLetter(char letter)
|
||||
{
|
||||
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<MachineMini> items = new List<MachineMini>();
|
||||
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
|
||||
if(dbItem.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
|
||||
items.Add(MachineMini.TransformItem(dbItem));
|
||||
|
||||
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static MachineMini[] GetItemsFromYear(int year)
|
||||
{
|
||||
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<MachineMini> items = new List<MachineMini>();
|
||||
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
|
||||
if(dbItem.Introduced.Year == year)
|
||||
items.Add(MachineMini.TransformItem(dbItem));
|
||||
|
||||
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static MachineMini[] GetItemsWithCompany(int id, string companyName)
|
||||
{
|
||||
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 MachineMini
|
||||
{
|
||||
Company = new Company {Id = id, Name = companyName},
|
||||
Id = t.Id,
|
||||
Name = t.Name
|
||||
}).OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
|
||||
public static MachineMini[] GetItemsFromCompany(int id)
|
||||
{
|
||||
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(MachineMini.TransformItem).OrderBy(t => t.Name).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Gpu.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Graphics Processing Unit 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;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class Gpu
|
||||
{
|
||||
public Company Company;
|
||||
public float DieSize;
|
||||
public int Id;
|
||||
public DateTime Introduced;
|
||||
public string ModelCode;
|
||||
public string Name;
|
||||
public string Package;
|
||||
public string Process;
|
||||
public float ProcessNm;
|
||||
public long Transistors;
|
||||
|
||||
public static Gpu GetItem(int id)
|
||||
{
|
||||
Cicm.Database.Schemas.Gpu dbItem = Program.Database?.Operations.GetGpu(id);
|
||||
return dbItem == null
|
||||
? null
|
||||
: new Gpu
|
||||
{
|
||||
Name = dbItem.Name,
|
||||
Company = dbItem.Company == null ? null : Company.GetItem(dbItem.Company.Id),
|
||||
DieSize = dbItem.DieSize,
|
||||
Introduced = dbItem.Introduced,
|
||||
ModelCode = dbItem.ModelCode,
|
||||
Package = dbItem.Package,
|
||||
Process = dbItem.Process,
|
||||
ProcessNm = dbItem.ProcessNm,
|
||||
Transistors = dbItem.Transistors,
|
||||
Id = dbItem.Id
|
||||
};
|
||||
}
|
||||
|
||||
public static Gpu[] GetAllItems()
|
||||
{
|
||||
List<Cicm.Database.Schemas.Gpu> dbItems = null;
|
||||
bool? result = Program.Database?.Operations.GetGpus(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
List<Gpu> items = new List<Gpu>();
|
||||
|
||||
foreach(Cicm.Database.Schemas.Gpu dbItem in dbItems)
|
||||
items.Add(new Gpu
|
||||
{
|
||||
Name = dbItem.Name,
|
||||
Company = dbItem.Company == null ? null : Company.GetItem(dbItem.Company.Id),
|
||||
DieSize = dbItem.DieSize,
|
||||
Introduced = dbItem.Introduced,
|
||||
ModelCode = dbItem.ModelCode,
|
||||
Package = dbItem.Package,
|
||||
Process = dbItem.Process,
|
||||
ProcessNm = dbItem.ProcessNm,
|
||||
Transistors = dbItem.Transistors,
|
||||
Id = dbItem.Id
|
||||
});
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : GpuByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Gpu by machine model
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class GpuByMachine
|
||||
{
|
||||
public Gpu Gpu;
|
||||
|
||||
public static GpuByMachine[] GetAllItems(int machineId)
|
||||
{
|
||||
List<Cicm.Database.Schemas.GpuByMachine> dbItems = null;
|
||||
bool? result =
|
||||
Program.Database?.Operations.GetGpusByMachines(out dbItems, machineId);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
List<GpuByMachine> items = new List<GpuByMachine>();
|
||||
|
||||
foreach(Cicm.Database.Schemas.GpuByMachine dbItem in dbItems)
|
||||
items.Add(new GpuByMachine
|
||||
{
|
||||
Gpu = Gpu.GetItem(dbItem.Gpu)
|
||||
});
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
/******************************************************************************
|
||||
// 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;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class Machine
|
||||
{
|
||||
public Company Company;
|
||||
public MachineFamily Family;
|
||||
public GpuByMachine[] Gpus;
|
||||
public int Id;
|
||||
public DateTime Introduced;
|
||||
public MemoryByMachine[] Memories;
|
||||
public string Model;
|
||||
public string Name;
|
||||
public ProcessorByMachine[] Processors;
|
||||
public SoundByMachine[] SoundSynths;
|
||||
public StorageByMachine[] Storage;
|
||||
public MachineType Type;
|
||||
|
||||
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.Name).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.Name).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)
|
||||
{
|
||||
return new Machine
|
||||
{
|
||||
Company = Company.GetItem(dbItem.Company),
|
||||
Gpus = GpuByMachine.GetAllItems(dbItem.Id),
|
||||
Id = dbItem.Id,
|
||||
Name = dbItem.Name,
|
||||
Introduced = dbItem.Introduced,
|
||||
Type = dbItem.Type,
|
||||
Processors = ProcessorByMachine.GetAllItems(dbItem.Id),
|
||||
SoundSynths = SoundByMachine.GetAllItems(dbItem.Id),
|
||||
Memories = MemoryByMachine.GetAllItems(dbItem.Id),
|
||||
Storage = StorageByMachine.GetAllItems(dbItem.Id),
|
||||
Family = MachineFamily.GetItem(dbItem.Family),
|
||||
Model = dbItem.Model
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class MachineMini
|
||||
{
|
||||
public Company Company;
|
||||
public int Id;
|
||||
public string Name;
|
||||
|
||||
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.Name).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.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
|
||||
items.Add(TransformItem(dbItem));
|
||||
|
||||
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).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.Introduced.Year == year)
|
||||
items.Add(TransformItem(dbItem));
|
||||
|
||||
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).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,
|
||||
Name = t.Name
|
||||
}).OrderBy(t => t.Name).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.Name).ToArray();
|
||||
}
|
||||
|
||||
internal static MachineMini TransformItem(Cicm.Database.Schemas.Machine dbItem)
|
||||
{
|
||||
return new MachineMini {Company = Company.GetItem(dbItem.Company), Id = dbItem.Id, Name = dbItem.Name};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : GpuByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Gpu by machine model
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class MachineFamily
|
||||
{
|
||||
public int Id;
|
||||
public string Name;
|
||||
|
||||
public static MachineFamily GetItem(int familyId)
|
||||
{
|
||||
Cicm.Database.Schemas.MachineFamily result = Program.Database?.Operations.GetMachineFamily(familyId);
|
||||
|
||||
if(result == null || result.Id != familyId) return null;
|
||||
|
||||
return new MachineFamily {Name = result.Name, Id = familyId};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : GpuByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Gpu by machine model
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Cicm.Database;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class MemoryByMachine
|
||||
{
|
||||
public long Size;
|
||||
public double Speed;
|
||||
public MemoryType Type;
|
||||
public MemoryUsage Usage;
|
||||
|
||||
public static MemoryByMachine[] GetAllItems(int machineId)
|
||||
{
|
||||
List<Cicm.Database.Schemas.MemoryByMachine> dbItems = null;
|
||||
bool? result =
|
||||
Program.Database?.Operations.GetMemoryByMachine(out dbItems, machineId);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
List<MemoryByMachine> items = new List<MemoryByMachine>();
|
||||
|
||||
foreach(Cicm.Database.Schemas.MemoryByMachine dbItem in dbItems)
|
||||
items.Add(new MemoryByMachine
|
||||
{
|
||||
Type = dbItem.Type,
|
||||
Usage = dbItem.Usage,
|
||||
Size = dbItem.Size,
|
||||
Speed = dbItem.Speed
|
||||
});
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : News.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Website news 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.Globalization;
|
||||
using System.Linq;
|
||||
using Cicm.Database;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class News
|
||||
{
|
||||
/// <summary>Affected ID</summary>
|
||||
public int AffectedId;
|
||||
/// <summary>Date</summary>
|
||||
public DateTime Date;
|
||||
/// <summary>URL of image</summary>
|
||||
public string Image;
|
||||
/// <summary>Subtext</summary>
|
||||
public string SubText;
|
||||
/// <summary>URL of target view, if applicable</summary>
|
||||
public string TargetView;
|
||||
/// <summary>Text</summary>
|
||||
public string Text;
|
||||
|
||||
public static News[] GetAllItems()
|
||||
{
|
||||
List<Cicm.Database.Schemas.News> dbItems = null;
|
||||
bool? result = Program.Database?.Operations.GetNews(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
return dbItems.OrderByDescending(i => i.Id).Select(TransformItem) as News[];
|
||||
}
|
||||
|
||||
public static News[] GetLastItems(int count = 10)
|
||||
{
|
||||
List<Cicm.Database.Schemas.News> dbItems = null;
|
||||
bool? result = Program.Database?.Operations.GetNews(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
return dbItems.OrderByDescending(i => i.Id).Take(count).Select(TransformItem).ToArray();
|
||||
}
|
||||
|
||||
static News TransformItem(Cicm.Database.Schemas.News dbItem)
|
||||
{
|
||||
string imageUrl;
|
||||
string text;
|
||||
string targetView;
|
||||
string subtext;
|
||||
Machine computer;
|
||||
OwnedComputer owncomputer;
|
||||
Machine console;
|
||||
OwnedConsole ownconsole;
|
||||
|
||||
switch(dbItem.Type)
|
||||
{
|
||||
case NewsType.NewComputerInDb:
|
||||
text = "New computer added to the database.";
|
||||
imageUrl = "assets/photos/computers/";
|
||||
targetView = "Computer";
|
||||
computer = Computer.GetItem(dbItem.AffectedId);
|
||||
subtext = $"{computer.Company.Name} - {computer.Name}";
|
||||
break;
|
||||
case NewsType.NewConsoleInDb:
|
||||
text = "New videoconsole added to the database.";
|
||||
imageUrl = "assets/photos/consoles/";
|
||||
targetView = "Console";
|
||||
console = Console.GetItem(dbItem.AffectedId);
|
||||
subtext = $"{console.Company.Name} - {console.Name}";
|
||||
break;
|
||||
case NewsType.NewComputerInCollection:
|
||||
text = "New computer added to the museum's collection.";
|
||||
imageUrl = "assets/photos/computers/";
|
||||
targetView = "CollectionComputer";
|
||||
owncomputer = OwnedComputer.GetItem(dbItem.AffectedId);
|
||||
subtext = $"{owncomputer.Computer.Company.Name} - {owncomputer.Computer.Name}";
|
||||
break;
|
||||
case NewsType.NewConsoleInCollection:
|
||||
text = "New videoconsole added to the museum's collection.";
|
||||
imageUrl = "assets/photos/consoles/";
|
||||
targetView = "CollectionConsole";
|
||||
ownconsole = OwnedConsole.GetItem(dbItem.AffectedId);
|
||||
subtext = $"{ownconsole.Console.Company.Name} - {ownconsole.Console.Name}";
|
||||
break;
|
||||
case NewsType.UpdatedComputerInDb:
|
||||
text = "Updated computer from the database.";
|
||||
imageUrl = "assets/photos/computers/";
|
||||
targetView = "Computer";
|
||||
computer = Computer.GetItem(dbItem.AffectedId);
|
||||
subtext = $"{computer.Company.Name} - {computer.Name}";
|
||||
break;
|
||||
case NewsType.UpdatedConsoleInDb:
|
||||
text = "Updated videoconsole from the database.";
|
||||
imageUrl = "assets/photos/consoles/";
|
||||
targetView = "Console";
|
||||
console = Console.GetItem(dbItem.AffectedId);
|
||||
subtext = $"{console.Company.Name} - {console.Name}";
|
||||
break;
|
||||
case NewsType.UpdatedComputerInCollection:
|
||||
text = "Updated computer from museum's collection.";
|
||||
imageUrl = "assets/photos/computers/";
|
||||
targetView = "CollectionComputer";
|
||||
owncomputer = OwnedComputer.GetItem(dbItem.AffectedId);
|
||||
subtext = $"{owncomputer.Computer.Company.Name} - {owncomputer.Computer.Name}";
|
||||
break;
|
||||
case NewsType.UpdatedConsoleInCollection:
|
||||
text = "Updated videoconsole from museum's collection.";
|
||||
imageUrl = "assets/photos/consoles/";
|
||||
targetView = "CollectionConsole";
|
||||
ownconsole = OwnedConsole.GetItem(dbItem.AffectedId);
|
||||
subtext = $"{ownconsole.Console.Company.Name} - {ownconsole.Console.Name}";
|
||||
break;
|
||||
case NewsType.NewMoneyDonation:
|
||||
text = "New money donation.";
|
||||
imageUrl = null;
|
||||
targetView = null;
|
||||
subtext = null;
|
||||
break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return new News
|
||||
{
|
||||
AffectedId = dbItem.AffectedId,
|
||||
Date = DateTime.ParseExact(dbItem.Date, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
Image = imageUrl == null ? null : imageUrl + $"{dbItem.AffectedId}",
|
||||
Text = text,
|
||||
TargetView = targetView,
|
||||
SubText = subtext
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : OwnedComputer.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Videogame console 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.Globalization;
|
||||
using System.Linq;
|
||||
using Cicm.Database;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class OwnedComputer
|
||||
{
|
||||
public DateTime Acquired;
|
||||
public bool Boxed;
|
||||
public Machine Computer;
|
||||
public Processor Cpu1;
|
||||
public Processor Cpu2;
|
||||
public int Id;
|
||||
public bool Manuals;
|
||||
public float Mhz1;
|
||||
public float Mhz2;
|
||||
public int Ram;
|
||||
public string Rigid;
|
||||
public StatusType Status;
|
||||
public bool Trade;
|
||||
public int Vram;
|
||||
|
||||
public static OwnedComputer[] GetAllItems()
|
||||
{
|
||||
List<Cicm.Database.Schemas.OwnedComputer> dbItems = null;
|
||||
bool? result =
|
||||
Program.Database?.Operations.GetOwnedComputers(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
return dbItems.OrderByDescending(i => i.Id).Select(TransformItem) as OwnedComputer[];
|
||||
}
|
||||
|
||||
public static OwnedComputer GetItem(int id)
|
||||
{
|
||||
Cicm.Database.Schemas.OwnedComputer dbItem = Program.Database?.Operations.GetOwnedComputer(id);
|
||||
return dbItem == null ? null : TransformItem(dbItem);
|
||||
}
|
||||
|
||||
static OwnedComputer TransformItem(Cicm.Database.Schemas.OwnedComputer dbItem)
|
||||
{
|
||||
Machine computer = Machine.GetItem(dbItem.ComputerId);
|
||||
|
||||
OwnedComputer item = new OwnedComputer
|
||||
{
|
||||
Acquired = DateTime.ParseExact(dbItem.Acquired, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
Boxed = dbItem.Boxed,
|
||||
Computer = computer,
|
||||
Id = dbItem.Id,
|
||||
Manuals = dbItem.Manuals,
|
||||
Ram = dbItem.Ram,
|
||||
Rigid = dbItem.Rigid,
|
||||
Status = dbItem.Status,
|
||||
Trade = dbItem.Trade,
|
||||
Vram = dbItem.Vram
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return computer == null ? null : item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : OwnedConsole.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Videogame console 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.Globalization;
|
||||
using System.Linq;
|
||||
using Cicm.Database;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class OwnedConsole
|
||||
{
|
||||
public DateTime Acquired;
|
||||
public bool Boxed;
|
||||
public Machine Console;
|
||||
public int Id;
|
||||
public bool Manuals;
|
||||
public StatusType Status;
|
||||
public bool Trade;
|
||||
|
||||
public static OwnedConsole[] GetAllItems()
|
||||
{
|
||||
List<Cicm.Database.Schemas.OwnedConsole> dbItems = null;
|
||||
bool? result =
|
||||
Program.Database?.Operations.GetOwnedConsoles(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
return dbItems.OrderByDescending(i => i.Id).Select(TransformItem) as OwnedConsole[];
|
||||
}
|
||||
|
||||
public static OwnedConsole GetItem(int id)
|
||||
{
|
||||
Cicm.Database.Schemas.OwnedConsole dbItem = Program.Database?.Operations.GetOwnedConsole(id);
|
||||
return dbItem == null ? null : TransformItem(dbItem);
|
||||
}
|
||||
|
||||
static OwnedConsole TransformItem(Cicm.Database.Schemas.OwnedConsole dbItem)
|
||||
{
|
||||
Machine console = Machine.GetItem(dbItem.ConsoleId);
|
||||
|
||||
return console == null
|
||||
? null
|
||||
: new OwnedConsole
|
||||
{
|
||||
Acquired =
|
||||
DateTime.ParseExact(dbItem.Acquired, "yyyy/MM/dd HH:mm:ss",
|
||||
CultureInfo.InvariantCulture),
|
||||
Boxed = dbItem.Boxed,
|
||||
Console = console,
|
||||
Id = dbItem.Id,
|
||||
Manuals = dbItem.Manuals,
|
||||
Status = dbItem.Status,
|
||||
Trade = dbItem.Trade
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Processor.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Processor 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 Cicm.Database.Schemas;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class Processor
|
||||
{
|
||||
public int AddressBus;
|
||||
public Company Company;
|
||||
public int Cores;
|
||||
public int DataBus;
|
||||
public float DieSize;
|
||||
public int Fpr;
|
||||
public int FprSize;
|
||||
public int Gpr;
|
||||
public int GprSize;
|
||||
public int Id;
|
||||
public InstructionSet InstructionSet;
|
||||
public InstructionSetExtension[] InstructionSetExtensions;
|
||||
public DateTime Introduced;
|
||||
public float L1Data;
|
||||
public float L1Instruction;
|
||||
public float L2;
|
||||
public float L3;
|
||||
public string ModelCode;
|
||||
public string Name;
|
||||
public string Package;
|
||||
public string Process;
|
||||
public float ProcessNm;
|
||||
public int Simd;
|
||||
public int SimdSize;
|
||||
public double Speed;
|
||||
public int ThreadsPerCore;
|
||||
public long Transistors;
|
||||
|
||||
public static Processor GetItem(int id)
|
||||
{
|
||||
Cicm.Database.Schemas.Processor dbItem = Program.Database?.Operations.GetProcessor(id);
|
||||
|
||||
return dbItem == null
|
||||
? null
|
||||
: new Processor
|
||||
{
|
||||
AddressBus = dbItem.AddressBus,
|
||||
Name = dbItem.Name,
|
||||
Company = Company.GetItem(dbItem.Company.Id),
|
||||
Cores = dbItem.Cores,
|
||||
DataBus = dbItem.DataBus,
|
||||
DieSize = dbItem.DieSize,
|
||||
Fpr = dbItem.Fpr,
|
||||
FprSize = dbItem.FprSize,
|
||||
Gpr = dbItem.Gpr,
|
||||
GprSize = dbItem.GprSize,
|
||||
InstructionSet = dbItem.InstructionSet,
|
||||
InstructionSetExtensions = dbItem.InstructionSetExtensions,
|
||||
Introduced = dbItem.Introduced,
|
||||
L1Data = dbItem.L1Data,
|
||||
L1Instruction = dbItem.L1Instruction,
|
||||
L2 = dbItem.L2,
|
||||
L3 = dbItem.L3,
|
||||
ModelCode = dbItem.ModelCode,
|
||||
Package = dbItem.Package,
|
||||
Process = dbItem.Process,
|
||||
ProcessNm = dbItem.ProcessNm,
|
||||
Simd = dbItem.Simd,
|
||||
SimdSize = dbItem.SimdSize,
|
||||
Speed = dbItem.Speed,
|
||||
ThreadsPerCore = dbItem.ThreadsPerCore,
|
||||
Transistors = dbItem.Transistors,
|
||||
Id = dbItem.Id
|
||||
};
|
||||
}
|
||||
|
||||
public static Processor[] GetAllItems()
|
||||
{
|
||||
List<Cicm.Database.Schemas.Processor> dbItems = null;
|
||||
bool? result = Program.Database?.Operations.GetProcessors(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
List<Processor> items = new List<Processor>();
|
||||
|
||||
foreach(Cicm.Database.Schemas.Processor dbItem in dbItems)
|
||||
items.Add(new Processor
|
||||
{
|
||||
AddressBus = dbItem.AddressBus,
|
||||
Name = dbItem.Name,
|
||||
Company = Company.GetItem(dbItem.Company.Id),
|
||||
Cores = dbItem.Cores,
|
||||
DataBus = dbItem.DataBus,
|
||||
DieSize = dbItem.DieSize,
|
||||
Fpr = dbItem.Fpr,
|
||||
FprSize = dbItem.FprSize,
|
||||
Gpr = dbItem.Gpr,
|
||||
GprSize = dbItem.GprSize,
|
||||
InstructionSet = dbItem.InstructionSet,
|
||||
InstructionSetExtensions = dbItem.InstructionSetExtensions,
|
||||
Introduced = dbItem.Introduced,
|
||||
L1Data = dbItem.L1Data,
|
||||
L1Instruction = dbItem.L1Instruction,
|
||||
L2 = dbItem.L2,
|
||||
L3 = dbItem.L3,
|
||||
ModelCode = dbItem.ModelCode,
|
||||
Package = dbItem.Package,
|
||||
Process = dbItem.Process,
|
||||
ProcessNm = dbItem.ProcessNm,
|
||||
Simd = dbItem.Simd,
|
||||
SimdSize = dbItem.SimdSize,
|
||||
Speed = dbItem.Speed,
|
||||
ThreadsPerCore = dbItem.ThreadsPerCore,
|
||||
Transistors = dbItem.Transistors,
|
||||
Id = dbItem.Id
|
||||
});
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : ProcessorByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Processor by machine model
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class ProcessorByMachine
|
||||
{
|
||||
public Processor Processor;
|
||||
public float Speed;
|
||||
|
||||
public static ProcessorByMachine[] GetAllItems(int machineId)
|
||||
{
|
||||
List<Cicm.Database.Schemas.ProcessorByMachine> dbItems = null;
|
||||
bool? result =
|
||||
Program.Database?.Operations.GetProcessorsByMachines(out dbItems, machineId);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
List<ProcessorByMachine> items = new List<ProcessorByMachine>();
|
||||
|
||||
foreach(Cicm.Database.Schemas.ProcessorByMachine dbItem in dbItems)
|
||||
items.Add(new ProcessorByMachine
|
||||
{
|
||||
Processor = Processor.GetItem(dbItem.Processor),
|
||||
Speed = dbItem.Speed
|
||||
});
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : GpuByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Gpu by machine model
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class SoundByMachine
|
||||
{
|
||||
public SoundSynth SoundSynth;
|
||||
|
||||
public static SoundByMachine[] GetAllItems(int machineId)
|
||||
{
|
||||
List<Cicm.Database.Schemas.SoundByMachine> dbItems = null;
|
||||
bool? result =
|
||||
Program.Database?.Operations.GetSoundsByMachines(out dbItems, machineId);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
List<SoundByMachine> items = new List<SoundByMachine>();
|
||||
|
||||
foreach(Cicm.Database.Schemas.SoundByMachine dbItem in dbItems)
|
||||
items.Add(new SoundByMachine {SoundSynth = SoundSynth.GetItem(dbItem.SoundSynth)});
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : SoundSynth.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Digital Sound Synthetizer 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;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class SoundSynth
|
||||
{
|
||||
public Company Company;
|
||||
public int Depth;
|
||||
public double Frequency;
|
||||
public int Id;
|
||||
public DateTime Introduced;
|
||||
public string ModelCode;
|
||||
public string Name;
|
||||
public int SquareWave;
|
||||
public int Type;
|
||||
public int Voices;
|
||||
public int WhiteNoise;
|
||||
|
||||
public static SoundSynth GetItem(int id)
|
||||
{
|
||||
Cicm.Database.Schemas.SoundSynth dbItem = Program.Database?.Operations.GetSoundSynth(id);
|
||||
return dbItem == null
|
||||
? null
|
||||
: new SoundSynth
|
||||
{
|
||||
Name = dbItem.Name,
|
||||
Id = dbItem.Id,
|
||||
Company = dbItem.Company == null ? null : Company.GetItem(dbItem.Company.Id),
|
||||
ModelCode = dbItem.ModelCode,
|
||||
Introduced = dbItem.Introduced,
|
||||
Voices = dbItem.Voices,
|
||||
Frequency = dbItem.Frequency,
|
||||
Depth = dbItem.Depth,
|
||||
SquareWave = dbItem.SquareWave,
|
||||
WhiteNoise = dbItem.WhiteNoise,
|
||||
Type = dbItem.Type
|
||||
};
|
||||
}
|
||||
|
||||
public static SoundSynth[] GetAllItems()
|
||||
{
|
||||
List<Cicm.Database.Schemas.SoundSynth> dbItems = null;
|
||||
bool? result = Program.Database?.Operations.GetSoundSynths(out dbItems);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
List<SoundSynth> items = new List<SoundSynth>();
|
||||
|
||||
foreach(Cicm.Database.Schemas.SoundSynth dbItem in dbItems)
|
||||
items.Add(new SoundSynth
|
||||
{
|
||||
Name = dbItem.Name,
|
||||
Id = dbItem.Id,
|
||||
Company = dbItem.Company == null ? null : Company.GetItem(dbItem.Company.Id),
|
||||
ModelCode = dbItem.ModelCode,
|
||||
Introduced = dbItem.Introduced,
|
||||
Voices = dbItem.Voices,
|
||||
Frequency = dbItem.Frequency,
|
||||
Depth = dbItem.Depth,
|
||||
SquareWave = dbItem.SquareWave,
|
||||
WhiteNoise = dbItem.WhiteNoise,
|
||||
Type = dbItem.Type
|
||||
});
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : StorageByMachine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Storage by machine model
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Cicm.Database;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class StorageByMachine
|
||||
{
|
||||
/// <summary>Capacity in bytes</summary>
|
||||
public long Capacity;
|
||||
/// <summary>Storage interface</summary>
|
||||
public StorageInterface Interface;
|
||||
/// <summary>Storage type</summary>
|
||||
public StorageType Type;
|
||||
|
||||
public static StorageByMachine[] GetAllItems(int machineId)
|
||||
{
|
||||
List<Cicm.Database.Schemas.StorageByMachine> dbItems = null;
|
||||
bool? result =
|
||||
Program.Database?.Operations.GetStorageByMachines(out dbItems, machineId);
|
||||
if(result == null || result.Value == false || dbItems == null) return null;
|
||||
|
||||
List<StorageByMachine> items = new List<StorageByMachine>();
|
||||
|
||||
foreach(Cicm.Database.Schemas.StorageByMachine dbItem in dbItems)
|
||||
items.Add(new StorageByMachine
|
||||
{
|
||||
Type = dbItem.Type,
|
||||
Interface = dbItem.Interface,
|
||||
Capacity = dbItem.Capacity
|
||||
});
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<Version>3.0.99.301</Version>
|
||||
<Version>3.0.99.302</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
|
||||
Reference in New Issue
Block a user