mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add operations for database version 2.
This commit is contained in:
19
Cicm.Database/IDbCore.cs
Normal file
19
Cicm.Database/IDbCore.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public interface IDbCore
|
||||||
|
{
|
||||||
|
Operations Operations { get; }
|
||||||
|
|
||||||
|
long LastInsertRowId { get; }
|
||||||
|
|
||||||
|
bool OpenDb(string server, string user, string database, string password, ushort port);
|
||||||
|
|
||||||
|
void CloseDb();
|
||||||
|
|
||||||
|
bool CreateDb(string database, string server, string user, string password, ushort port);
|
||||||
|
|
||||||
|
IDbDataAdapter GetNewDataAdapter();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
using MySql.Data.MySqlClient;
|
using System;
|
||||||
|
using System.Data;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace Cicm.Database
|
namespace Cicm.Database
|
||||||
{
|
{
|
||||||
public class Mysql
|
public class Mysql : IDbCore
|
||||||
{
|
{
|
||||||
MySqlConnection connection;
|
MySqlConnection connection;
|
||||||
|
|
||||||
@@ -10,13 +12,101 @@ namespace Cicm.Database
|
|||||||
{
|
{
|
||||||
string connectionString =
|
string connectionString =
|
||||||
$"server={server};user={user};database={database};port={port};password={password}";
|
$"server={server};user={user};database={database};port={port};password={password}";
|
||||||
|
|
||||||
connection = new MySqlConnection(connectionString);
|
connection = new MySqlConnection(connectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Operations Operations { get; private set; }
|
||||||
|
public long LastInsertRowId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
MySqlCommand command = connection.CreateCommand();
|
||||||
|
command.CommandText = "SELECT LAST_INSERT_ID()";
|
||||||
|
IDataReader reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
if(reader == null || !reader.Read()) return 0;
|
||||||
|
|
||||||
|
long id = reader.GetInt64(0);
|
||||||
|
reader.Close();
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OpenDb(string server, string user, string database, string password, ushort port = 3306)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string connectionString =
|
||||||
|
$"server={server};user={user};database={database};port={port};password={password}";
|
||||||
|
|
||||||
|
connection = new MySqlConnection(connectionString);
|
||||||
|
|
||||||
|
Operations = new Operations(connection, this);
|
||||||
|
|
||||||
|
bool res = Operations.UpdateDatabase();
|
||||||
|
|
||||||
|
if(res) return true;
|
||||||
|
|
||||||
|
connection = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch(MySqlException ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error opening database.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
connection = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CloseDb()
|
||||||
|
{
|
||||||
|
connection?.Close();
|
||||||
|
connection = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDbDataAdapter GetNewDataAdapter()
|
||||||
|
{
|
||||||
|
return new MySqlDataAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
~Mysql()
|
~Mysql()
|
||||||
{
|
{
|
||||||
connection?.Close();
|
CloseDb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
224
Cicm.Database/Operations/Admin.cs
Normal file
224
Cicm.Database/Operations/Admin.cs
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetAdmins(out List<Admin> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all admins...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from admin";
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 admin 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Admin GetAdmin(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting admin with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from admin 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountAdmins()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting admins...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM admin";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddAdmin(Admin entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding admin `{0}`...", entry.user);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandAdmin(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL = "INSERT INTO admin (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateAdmin(Admin entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating admin `{0}`...", entry.user);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandAdmin(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = "UPDATE admin SET user = @user, password = @password " + $"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 admin 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.user;
|
||||||
|
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.Parse(dataRow["id"].ToString()),
|
||||||
|
user = dataRow["user"].ToString(),
|
||||||
|
password = dataRow["password"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
313
Cicm.Database/Operations/BrowserTest.cs
Normal file
313
Cicm.Database/Operations/BrowserTest.cs
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddBrowserTest(BrowserTest entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding browser test `{0}`...", entry.idstring);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandBrowserTest(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL =
|
||||||
|
"INSERT INTO browser_test (idstring, browser, version, os, platform, gif87, gif89, jpeg, png, pngt, agif, table, colors, js, frames, flash)" +
|
||||||
|
" VALUES (@idstring, @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateBrowserTest(BrowserTest entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating browser test `{0}`...", entry.idstring);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandBrowserTest(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql =
|
||||||
|
"UPDATE browser_test SET idstring = @idstring, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "@idstring";
|
||||||
|
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.idstring;
|
||||||
|
param2.Value = entry.browser;
|
||||||
|
param3.Value = entry.version;
|
||||||
|
param4.Value = entry.os;
|
||||||
|
param5.Value = entry.platform;
|
||||||
|
param6.Value = entry.gif87;
|
||||||
|
param7.Value = entry.gif89;
|
||||||
|
param8.Value = entry.jpeg;
|
||||||
|
param9.Value = entry.png;
|
||||||
|
param10.Value = entry.pngt;
|
||||||
|
param11.Value = entry.agif;
|
||||||
|
param12.Value = entry.table;
|
||||||
|
param13.Value = entry.colors;
|
||||||
|
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.Parse(dataRow["id"].ToString()),
|
||||||
|
idstring = dataRow["idstring"].ToString(),
|
||||||
|
browser = dataRow["browser"].ToString(),
|
||||||
|
version = dataRow["version"].ToString(),
|
||||||
|
os = dataRow["os"].ToString(),
|
||||||
|
platform = dataRow["platform"].ToString(),
|
||||||
|
gif87 = bool.Parse(dataRow["gif87"].ToString()),
|
||||||
|
gif89 = bool.Parse(dataRow["gif89"].ToString()),
|
||||||
|
jpeg = bool.Parse(dataRow["jpeg"].ToString()),
|
||||||
|
png = bool.Parse(dataRow["png"].ToString()),
|
||||||
|
pngt = bool.Parse(dataRow["pngt"].ToString()),
|
||||||
|
agif = bool.Parse(dataRow["agif"].ToString()),
|
||||||
|
table = bool.Parse(dataRow["table"].ToString()),
|
||||||
|
colors = bool.Parse(dataRow["colors"].ToString()),
|
||||||
|
js = bool.Parse(dataRow["js"].ToString()),
|
||||||
|
frames = bool.Parse(dataRow["frames"].ToString()),
|
||||||
|
flash = bool.Parse(dataRow["flash"].ToString())
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
218
Cicm.Database/Operations/Company.cs
Normal file
218
Cicm.Database/Operations/Company.cs
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetCompanies(out List<Company> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all companies...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from Companias";
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 Companias 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Company GetCompany(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting company with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from Companias 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountCompanies()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting companies...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM Companias";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddCompany(Company entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding company `{0}`...", entry.Compania);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandCompany(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL = "INSERT INTO Companias (Compania)" + " VALUES (@Compania)";
|
||||||
|
|
||||||
|
dbcmd.CommandText = SQL;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
id = dbCore.LastInsertRowId;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine(" id {0}", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateCompany(Company entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating company `{0}`...", entry.Compania);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandCompany(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = "UPDATE Companias SET Compania = @Compania " + $"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 Companias 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();
|
||||||
|
|
||||||
|
param1.ParameterName = "@Compania";
|
||||||
|
|
||||||
|
param1.DbType = DbType.String;
|
||||||
|
|
||||||
|
param1.Value = entry.Compania;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Company> CompaniesFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<Company> entries = new List<Company>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
Company entry = new Company
|
||||||
|
{
|
||||||
|
id = int.Parse(dataRow["id"].ToString()),
|
||||||
|
Compania = dataRow["Compania"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
374
Cicm.Database/Operations/Computer.cs
Normal file
374
Cicm.Database/Operations/Computer.cs
Normal file
@@ -0,0 +1,374 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetComputers(out List<Computer> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all computers...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from computers";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = SQL;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = ComputersFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting computers.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetComputers(out List<Computer> entries, ulong start, ulong count)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting {0} computers from {1}...", count, start);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM 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 = ComputersFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting computers.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Computer GetComputer(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting computer with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from computers WHERE id = '{id}'";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = sql;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
List<Computer> entries = ComputersFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting computer.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountComputers()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting computers...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM computers";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddComputer(Computer entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding computer `{0}`...", entry.model);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandComputer(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL =
|
||||||
|
"INSERT INTO computers (company, year, model, cpu1, mhz1, cpu2, mhz2, bits, ram, rom, gpu, vram, colors, res, spu, mpu, sound_channels, music_channels, hdd1, hdd2, hdd3, disk1, cap1, disk2, cap2, comment)" +
|
||||||
|
" VALUES (@company, @year, @model, @cpu1, @mhz1, @cpu2, @mhz2, @bits, @ram, @rom, @gpu, @vram, @colors, @res, @spu, @mpu, @sound_channels, @music_channels, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, @cap2, @comment)";
|
||||||
|
|
||||||
|
dbcmd.CommandText = SQL;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
id = dbCore.LastInsertRowId;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine(" id {0}", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateComputer(Computer entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating computer `{0}`...", entry.model);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandComputer(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql =
|
||||||
|
"UPDATE computers SET company = @company, year = @year, model = @model, cpu1 = @cpu1, mhz1 = @mhz1, cpu2 = @cpu2, " +
|
||||||
|
"mhz2 = @mhz2, bits = @bits, ram = @ram, rom = @rom, gpu = @gpu, vram = @vram, colors = @colors, res = @res, spu = @spu, mpu = @mpu " +
|
||||||
|
"sound_channels = @sound_channels, music_channels = @music_channels, hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, cap1 = @cap1, disk2 = @disk2, cap2 = @cap2, comment = @comment " +
|
||||||
|
$"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RemoveComputer(long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Removing computer widh id `{0}`...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = $"DELETE FROM computers WHERE id = '{id}';";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbCommand GetCommandComputer(Computer entry)
|
||||||
|
{
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
|
||||||
|
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param4 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param5 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param6 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param7 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param8 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param9 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param10 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param11 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param12 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param13 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param14 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param15 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param16 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param17 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param18 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param19 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param20 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param21 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param22 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param23 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param24 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param25 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param26 = dbcmd.CreateParameter();
|
||||||
|
|
||||||
|
param1.ParameterName = "@company";
|
||||||
|
param2.ParameterName = "@year";
|
||||||
|
param3.ParameterName = "@model";
|
||||||
|
param4.ParameterName = "@cpu1";
|
||||||
|
param5.ParameterName = "@mhz1";
|
||||||
|
param6.ParameterName = "@cpu2";
|
||||||
|
param7.ParameterName = "@mhz2";
|
||||||
|
param8.ParameterName = "@bits";
|
||||||
|
param9.ParameterName = "@ram";
|
||||||
|
param10.ParameterName = "@rom";
|
||||||
|
param11.ParameterName = "@gpu";
|
||||||
|
param12.ParameterName = "@vram";
|
||||||
|
param13.ParameterName = "@colors";
|
||||||
|
param14.ParameterName = "@res";
|
||||||
|
param15.ParameterName = "@spu";
|
||||||
|
param16.ParameterName = "@mpu";
|
||||||
|
param17.ParameterName = "@sound_channels";
|
||||||
|
param18.ParameterName = "@music_channels";
|
||||||
|
param19.ParameterName = "@hdd1";
|
||||||
|
param20.ParameterName = "@hdd2";
|
||||||
|
param21.ParameterName = "@hdd3";
|
||||||
|
param22.ParameterName = "@disk1";
|
||||||
|
param23.ParameterName = "@cap1";
|
||||||
|
param24.ParameterName = "@disk2";
|
||||||
|
param25.ParameterName = "@cap2";
|
||||||
|
param26.ParameterName = "@comment";
|
||||||
|
|
||||||
|
param1.DbType = DbType.Int32;
|
||||||
|
param2.DbType = DbType.Int32;
|
||||||
|
param3.DbType = DbType.String;
|
||||||
|
param4.DbType = DbType.Int32;
|
||||||
|
param5.DbType = DbType.Double;
|
||||||
|
param6.DbType = DbType.Int32;
|
||||||
|
param7.DbType = DbType.Double;
|
||||||
|
param8.DbType = DbType.Int32;
|
||||||
|
param9.DbType = DbType.Int32;
|
||||||
|
param10.DbType = DbType.Int32;
|
||||||
|
param11.DbType = DbType.Int32;
|
||||||
|
param12.DbType = DbType.Int32;
|
||||||
|
param13.DbType = DbType.Int32;
|
||||||
|
param14.DbType = DbType.String;
|
||||||
|
param15.DbType = DbType.Int32;
|
||||||
|
param16.DbType = DbType.Int32;
|
||||||
|
param17.DbType = DbType.Int32;
|
||||||
|
param18.DbType = DbType.Int32;
|
||||||
|
param19.DbType = DbType.Int32;
|
||||||
|
param20.DbType = DbType.Int32;
|
||||||
|
param21.DbType = DbType.Int32;
|
||||||
|
param22.DbType = DbType.Int32;
|
||||||
|
param23.DbType = DbType.String;
|
||||||
|
param24.DbType = DbType.Int32;
|
||||||
|
param25.DbType = DbType.String;
|
||||||
|
param26.DbType = DbType.String;
|
||||||
|
|
||||||
|
param1.Value = entry.company;
|
||||||
|
param2.Value = entry.year;
|
||||||
|
param3.Value = entry.model;
|
||||||
|
param4.Value = entry.cpu1;
|
||||||
|
param5.Value = entry.mhz1;
|
||||||
|
param6.Value = entry.cpu2;
|
||||||
|
param7.Value = entry.mhz2;
|
||||||
|
param8.Value = entry.bits;
|
||||||
|
param9.Value = entry.ram;
|
||||||
|
param10.Value = entry.rom;
|
||||||
|
param11.Value = entry.gpu;
|
||||||
|
param12.Value = entry.vram;
|
||||||
|
param13.Value = entry.colors;
|
||||||
|
param14.Value = entry.res;
|
||||||
|
param15.Value = entry.spu;
|
||||||
|
param16.Value = entry.mpu;
|
||||||
|
param17.Value = entry.sound_channels;
|
||||||
|
param18.Value = entry.music_channels;
|
||||||
|
param19.Value = entry.hdd1;
|
||||||
|
param20.Value = entry.hdd2;
|
||||||
|
param21.Value = entry.hdd3;
|
||||||
|
param22.Value = entry.disk1;
|
||||||
|
param23.Value = entry.cap1;
|
||||||
|
param24.Value = entry.disk2;
|
||||||
|
param25.Value = entry.cap2;
|
||||||
|
param26.Value = entry.comment;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
dbcmd.Parameters.Add(param2);
|
||||||
|
dbcmd.Parameters.Add(param3);
|
||||||
|
dbcmd.Parameters.Add(param4);
|
||||||
|
dbcmd.Parameters.Add(param5);
|
||||||
|
dbcmd.Parameters.Add(param6);
|
||||||
|
dbcmd.Parameters.Add(param7);
|
||||||
|
dbcmd.Parameters.Add(param8);
|
||||||
|
dbcmd.Parameters.Add(param9);
|
||||||
|
dbcmd.Parameters.Add(param10);
|
||||||
|
dbcmd.Parameters.Add(param11);
|
||||||
|
dbcmd.Parameters.Add(param12);
|
||||||
|
dbcmd.Parameters.Add(param13);
|
||||||
|
dbcmd.Parameters.Add(param14);
|
||||||
|
dbcmd.Parameters.Add(param15);
|
||||||
|
dbcmd.Parameters.Add(param16);
|
||||||
|
dbcmd.Parameters.Add(param17);
|
||||||
|
dbcmd.Parameters.Add(param18);
|
||||||
|
dbcmd.Parameters.Add(param19);
|
||||||
|
dbcmd.Parameters.Add(param20);
|
||||||
|
dbcmd.Parameters.Add(param21);
|
||||||
|
dbcmd.Parameters.Add(param22);
|
||||||
|
dbcmd.Parameters.Add(param23);
|
||||||
|
dbcmd.Parameters.Add(param24);
|
||||||
|
dbcmd.Parameters.Add(param25);
|
||||||
|
dbcmd.Parameters.Add(param26);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Computer> ComputersFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<Computer> entries = new List<Computer>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
Computer entry = new Computer
|
||||||
|
{
|
||||||
|
id = int.Parse(dataRow["id"].ToString()),
|
||||||
|
company = int.Parse(dataRow["company"].ToString()),
|
||||||
|
year = int.Parse(dataRow["year"].ToString()),
|
||||||
|
model = dataRow["model"].ToString(),
|
||||||
|
cpu1 = int.Parse(dataRow["cpu1"].ToString()),
|
||||||
|
mhz1 = float.Parse(dataRow["mhz1"].ToString()),
|
||||||
|
cpu2 = int.Parse(dataRow["cpu2"].ToString()),
|
||||||
|
mhz2 = float.Parse(dataRow["mhz2"].ToString()),
|
||||||
|
bits = int.Parse(dataRow["bits"].ToString()),
|
||||||
|
ram = int.Parse(dataRow["ram"].ToString()),
|
||||||
|
rom = int.Parse(dataRow["rom"].ToString()),
|
||||||
|
gpu = int.Parse(dataRow["gpu"].ToString()),
|
||||||
|
vram = int.Parse(dataRow["vram"].ToString()),
|
||||||
|
colors = int.Parse(dataRow["colors"].ToString()),
|
||||||
|
res = dataRow["res"].ToString(),
|
||||||
|
spu = int.Parse(dataRow["spu"].ToString()),
|
||||||
|
mpu = int.Parse(dataRow["mpu"].ToString()),
|
||||||
|
sound_channels = int.Parse(dataRow["sound_channels"].ToString()),
|
||||||
|
music_channels = int.Parse(dataRow["music_channels"].ToString()),
|
||||||
|
hdd1 = int.Parse(dataRow["hdd1"].ToString()),
|
||||||
|
hdd2 = int.Parse(dataRow["hdd2"].ToString()),
|
||||||
|
hdd3 = int.Parse(dataRow["hdd3"].ToString()),
|
||||||
|
disk1 = int.Parse(dataRow["disk1"].ToString()),
|
||||||
|
cap1 = dataRow["cap1"].ToString(),
|
||||||
|
disk2 = int.Parse(dataRow["disk2"].ToString()),
|
||||||
|
cap2 = dataRow["cap2"].ToString(),
|
||||||
|
comment = dataRow["comment"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
349
Cicm.Database/Operations/Console.cs
Normal file
349
Cicm.Database/Operations/Console.cs
Normal file
@@ -0,0 +1,349 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Console = Cicm.Database.Schemas.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetConsoles(out List<Console> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine("Getting all consoles...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from consoles";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = SQL;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = ConsolesFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
System.Console.WriteLine("Error getting consoles.");
|
||||||
|
System.Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetConsoles(out List<Console> entries, ulong start, ulong count)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine("Getting {0} consoles from {1}...", count, start);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM 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 = ConsolesFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
System.Console.WriteLine("Error getting consoles.");
|
||||||
|
System.Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Console GetConsole(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine("Getting console with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from consoles WHERE id = '{id}'";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = sql;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
List<Console> entries = ConsolesFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
System.Console.WriteLine("Error getting console.");
|
||||||
|
System.Console.WriteLine(ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountConsoles()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine("Counting consoles...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM consoles";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddConsole(Console entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.Write("Adding console `{0}`...", entry.name);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandConsole(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL =
|
||||||
|
"INSERT INTO consoles (company, year, name, cpu1, mhz1, cpu2, mhz2, bits, ram, rom, gpu, vram, colors, res, spu, mpu, schannels, mchannels, palette, format, cap, comments)" +
|
||||||
|
" VALUES (@company, @year, @name, @cpu1, @mhz1, @cpu2, @mhz2, @bits, @ram, @rom, @gpu, @vram, @colors, @res, @spu, @mpu, @schannels, @mchannels, @palette, @format, @cap, @comments)";
|
||||||
|
|
||||||
|
dbcmd.CommandText = SQL;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
id = dbCore.LastInsertRowId;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine(" id {0}", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateConsole(Console entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine("Updating console `{0}`...", entry.name);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandConsole(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql =
|
||||||
|
"UPDATE consoles SET company = @company, year = @year, name = @name, cpu1 = @cpu1, mhz1 = @mhz1, cpu2 = @cpu2, " +
|
||||||
|
"mhz2 = @mhz2, bits = @bits, ram = @ram, rom = @rom, gpu = @gpu, vram = @vram, colors = @colors, res = @res, spu = @spu, mpu = @mpu " +
|
||||||
|
"schannels = @schannels, mchannels = @mchannels, palette = @palette, format = @format, cap = @cap, comments = @comments " +
|
||||||
|
$"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RemoveConsole(long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine("Removing console widh id `{0}`...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = $"DELETE FROM consoles WHERE id = '{id}';";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbCommand GetCommandConsole(Console entry)
|
||||||
|
{
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
|
||||||
|
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param4 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param5 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param6 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param7 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param8 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param9 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param10 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param11 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param12 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param13 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param14 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param15 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param16 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param17 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param18 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param19 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param20 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param21 = dbcmd.CreateParameter();
|
||||||
|
IDbDataParameter param22 = dbcmd.CreateParameter();
|
||||||
|
|
||||||
|
param1.ParameterName = "@company";
|
||||||
|
param2.ParameterName = "@year";
|
||||||
|
param3.ParameterName = "@name";
|
||||||
|
param4.ParameterName = "@cpu1";
|
||||||
|
param5.ParameterName = "@mhz1";
|
||||||
|
param6.ParameterName = "@cpu2";
|
||||||
|
param7.ParameterName = "@mhz2";
|
||||||
|
param8.ParameterName = "@bits";
|
||||||
|
param9.ParameterName = "@ram";
|
||||||
|
param10.ParameterName = "@rom";
|
||||||
|
param11.ParameterName = "@gpu";
|
||||||
|
param12.ParameterName = "@vram";
|
||||||
|
param13.ParameterName = "@colors";
|
||||||
|
param14.ParameterName = "@res";
|
||||||
|
param15.ParameterName = "@spu";
|
||||||
|
param16.ParameterName = "@mpu";
|
||||||
|
param17.ParameterName = "@schannels";
|
||||||
|
param18.ParameterName = "@mchannels";
|
||||||
|
param19.ParameterName = "@palette";
|
||||||
|
param20.ParameterName = "@format";
|
||||||
|
param21.ParameterName = "@cap";
|
||||||
|
param22.ParameterName = "@comments";
|
||||||
|
|
||||||
|
param1.DbType = DbType.Int32;
|
||||||
|
param2.DbType = DbType.Int32;
|
||||||
|
param3.DbType = DbType.String;
|
||||||
|
param4.DbType = DbType.Int32;
|
||||||
|
param5.DbType = DbType.Double;
|
||||||
|
param6.DbType = DbType.Int32;
|
||||||
|
param7.DbType = DbType.Double;
|
||||||
|
param8.DbType = DbType.Int32;
|
||||||
|
param9.DbType = DbType.Int32;
|
||||||
|
param10.DbType = DbType.Int32;
|
||||||
|
param11.DbType = DbType.Int32;
|
||||||
|
param12.DbType = DbType.Int32;
|
||||||
|
param13.DbType = DbType.Int32;
|
||||||
|
param14.DbType = DbType.String;
|
||||||
|
param15.DbType = DbType.Int32;
|
||||||
|
param16.DbType = DbType.Int32;
|
||||||
|
param17.DbType = DbType.Int32;
|
||||||
|
param18.DbType = DbType.Int32;
|
||||||
|
param19.DbType = DbType.Int32;
|
||||||
|
param20.DbType = DbType.Int32;
|
||||||
|
param21.DbType = DbType.Int32;
|
||||||
|
param22.DbType = DbType.String;
|
||||||
|
|
||||||
|
param1.Value = entry.company;
|
||||||
|
param2.Value = entry.year;
|
||||||
|
param3.Value = entry.name;
|
||||||
|
param4.Value = entry.cpu1;
|
||||||
|
param5.Value = entry.mhz1;
|
||||||
|
param6.Value = entry.cpu2;
|
||||||
|
param7.Value = entry.mhz2;
|
||||||
|
param8.Value = entry.bits;
|
||||||
|
param9.Value = entry.ram;
|
||||||
|
param10.Value = entry.rom;
|
||||||
|
param11.Value = entry.gpu;
|
||||||
|
param12.Value = entry.vram;
|
||||||
|
param13.Value = entry.colors;
|
||||||
|
param14.Value = entry.res;
|
||||||
|
param15.Value = entry.spu;
|
||||||
|
param16.Value = entry.mpu;
|
||||||
|
param17.Value = entry.schannels;
|
||||||
|
param18.Value = entry.mchannels;
|
||||||
|
param19.Value = entry.palette;
|
||||||
|
param20.Value = entry.format;
|
||||||
|
param21.Value = entry.cap;
|
||||||
|
param22.Value = entry.comments;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
dbcmd.Parameters.Add(param2);
|
||||||
|
dbcmd.Parameters.Add(param3);
|
||||||
|
dbcmd.Parameters.Add(param4);
|
||||||
|
dbcmd.Parameters.Add(param5);
|
||||||
|
dbcmd.Parameters.Add(param6);
|
||||||
|
dbcmd.Parameters.Add(param7);
|
||||||
|
dbcmd.Parameters.Add(param8);
|
||||||
|
dbcmd.Parameters.Add(param9);
|
||||||
|
dbcmd.Parameters.Add(param10);
|
||||||
|
dbcmd.Parameters.Add(param11);
|
||||||
|
dbcmd.Parameters.Add(param12);
|
||||||
|
dbcmd.Parameters.Add(param13);
|
||||||
|
dbcmd.Parameters.Add(param14);
|
||||||
|
dbcmd.Parameters.Add(param15);
|
||||||
|
dbcmd.Parameters.Add(param16);
|
||||||
|
dbcmd.Parameters.Add(param17);
|
||||||
|
dbcmd.Parameters.Add(param18);
|
||||||
|
dbcmd.Parameters.Add(param19);
|
||||||
|
dbcmd.Parameters.Add(param20);
|
||||||
|
dbcmd.Parameters.Add(param21);
|
||||||
|
dbcmd.Parameters.Add(param22);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Console> ConsolesFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<Console> entries = new List<Console>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
Console entry = new Console
|
||||||
|
{
|
||||||
|
id = int.Parse(dataRow["id"].ToString()),
|
||||||
|
company = int.Parse(dataRow["company"].ToString()),
|
||||||
|
year = int.Parse(dataRow["year"].ToString()),
|
||||||
|
name = dataRow["name"].ToString(),
|
||||||
|
cpu1 = int.Parse(dataRow["cpu1"].ToString()),
|
||||||
|
mhz1 = float.Parse(dataRow["mhz1"].ToString()),
|
||||||
|
cpu2 = int.Parse(dataRow["cpu2"].ToString()),
|
||||||
|
mhz2 = float.Parse(dataRow["mhz2"].ToString()),
|
||||||
|
bits = int.Parse(dataRow["bits"].ToString()),
|
||||||
|
ram = int.Parse(dataRow["ram"].ToString()),
|
||||||
|
rom = int.Parse(dataRow["rom"].ToString()),
|
||||||
|
gpu = int.Parse(dataRow["gpu"].ToString()),
|
||||||
|
vram = int.Parse(dataRow["vram"].ToString()),
|
||||||
|
colors = int.Parse(dataRow["colors"].ToString()),
|
||||||
|
res = dataRow["res"].ToString(),
|
||||||
|
spu = int.Parse(dataRow["spu"].ToString()),
|
||||||
|
mpu = int.Parse(dataRow["mpu"].ToString()),
|
||||||
|
schannels = int.Parse(dataRow["schannels"].ToString()),
|
||||||
|
mchannels = int.Parse(dataRow["mchannels"].ToString()),
|
||||||
|
palette = int.Parse(dataRow["palette"].ToString()),
|
||||||
|
format = int.Parse(dataRow["format"].ToString()),
|
||||||
|
cap = int.Parse(dataRow["cap"].ToString()),
|
||||||
|
comments = dataRow["comments"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
218
Cicm.Database/Operations/ConsoleCompany.cs
Normal file
218
Cicm.Database/Operations/ConsoleCompany.cs
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetConsoleCompanies(out List<ConsoleCompany> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all console companies...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from console_company";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = SQL;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = ConsoleCompaniesFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting console companies.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetConsoleCompanies(out List<ConsoleCompany> entries, ulong start, ulong count)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting {0} console companies from {1}...", count, start);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM console_company 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 = ConsoleCompaniesFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting console companies.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConsoleCompany GetConsoleCompany(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting console company with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from console_company 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<ConsoleCompany> entries = ConsoleCompaniesFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting console company.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountConsoleCompanies()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting console companies...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM console_company";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddConsoleCompany(ConsoleCompany entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding console company `{0}`...", entry.company);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandConsoleCompany(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL = "INSERT INTO console_company (company)" + " VALUES (@company)";
|
||||||
|
|
||||||
|
dbcmd.CommandText = SQL;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
id = dbCore.LastInsertRowId;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine(" id {0}", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateConsoleCompany(ConsoleCompany entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating console company `{0}`...", entry.company);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandConsoleCompany(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = "UPDATE console_company SET company = @company " + $"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RemoveConsoleCompany(long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Removing console company widh id `{0}`...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = $"DELETE FROM console_company WHERE id = '{id}';";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbCommand GetCommandConsoleCompany(ConsoleCompany entry)
|
||||||
|
{
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
|
||||||
|
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||||
|
|
||||||
|
param1.ParameterName = "@company";
|
||||||
|
|
||||||
|
param1.DbType = DbType.String;
|
||||||
|
|
||||||
|
param1.Value = entry.company;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<ConsoleCompany> ConsoleCompaniesFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<ConsoleCompany> entries = new List<ConsoleCompany>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
ConsoleCompany entry = new ConsoleCompany
|
||||||
|
{
|
||||||
|
id = int.Parse(dataRow["id"].ToString()),
|
||||||
|
company = dataRow["company"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
214
Cicm.Database/Operations/Cpu.cs
Normal file
214
Cicm.Database/Operations/Cpu.cs
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetCpus(out List<Cpu> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all CPUs...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from cpu";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = SQL;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = CpusFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting CPUs.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetCpus(out List<Cpu> entries, ulong start, ulong count)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting {0} CPUs from {1}...", count, start);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM cpu 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 = CpusFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting CPUs.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cpu GetCpu(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting CPU with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from cpu 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<Cpu> entries = CpusFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting CPU.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountCpus()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting CPUs...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM cpu";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddCpu(Cpu entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding CPU `{0}`...", entry.cpu);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandCpu(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL = "INSERT INTO cpu (cpu)" + " VALUES (@cpu)";
|
||||||
|
|
||||||
|
dbcmd.CommandText = SQL;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
id = dbCore.LastInsertRowId;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine(" id {0}", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateCpu(Cpu entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating CPU `{0}`...", entry.cpu);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandCpu(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = "UPDATE cpu SET cpu = @cpu " + $"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RemoveCpu(long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Removing CPU widh id `{0}`...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = $"DELETE FROM cpu WHERE id = '{id}';";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbCommand GetCommandCpu(Cpu entry)
|
||||||
|
{
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
|
||||||
|
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||||
|
|
||||||
|
param1.ParameterName = "@cpu";
|
||||||
|
|
||||||
|
param1.DbType = DbType.String;
|
||||||
|
|
||||||
|
param1.Value = entry.cpu;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Cpu> CpusFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<Cpu> entries = new List<Cpu>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
Cpu entry = new Cpu {id = int.Parse(dataRow["id"].ToString()), cpu = dataRow["cpu"].ToString()};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
218
Cicm.Database/Operations/DiskFormat.cs
Normal file
218
Cicm.Database/Operations/DiskFormat.cs
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetDiskFormats(out List<DiskFormat> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all disk formats...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from Formatos_de_disco";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = SQL;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = DiskFormatsFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting disk formats.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetDiskFormats(out List<DiskFormat> entries, ulong start, ulong count)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting {0} disk formats from {1}...", count, start);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM Formatos_de_disco LIMIT {start}, {count}";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = sql;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = DiskFormatsFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting disk formats.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiskFormat GetDiskFormat(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting disk format with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from Formatos_de_disco 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<DiskFormat> entries = DiskFormatsFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting disk format.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountDiskFormats()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting disk formats...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM Formatos_de_disco";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddDiskFormat(DiskFormat entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding disk format `{0}`...", entry.Format);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandDiskFormat(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL = "INSERT INTO Formatos_de_disco (Format)" + " VALUES (@Format)";
|
||||||
|
|
||||||
|
dbcmd.CommandText = SQL;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
id = dbCore.LastInsertRowId;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine(" id {0}", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateDiskFormat(DiskFormat entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating disk format `{0}`...", entry.Format);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandDiskFormat(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = "UPDATE Formatos_de_disco SET Format = @Format " + $"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RemoveDiskFormat(long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Removing disk format widh id `{0}`...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = $"DELETE FROM Formatos_de_disco WHERE id = '{id}';";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbCommand GetCommandDiskFormat(DiskFormat entry)
|
||||||
|
{
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
|
||||||
|
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||||
|
|
||||||
|
param1.ParameterName = "@Format";
|
||||||
|
|
||||||
|
param1.DbType = DbType.String;
|
||||||
|
|
||||||
|
param1.Value = entry.Format;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<DiskFormat> DiskFormatsFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<DiskFormat> entries = new List<DiskFormat>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
DiskFormat entry = new DiskFormat
|
||||||
|
{
|
||||||
|
id = int.Parse(dataRow["id"].ToString()),
|
||||||
|
Format = dataRow["Format"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
214
Cicm.Database/Operations/Dsp.cs
Normal file
214
Cicm.Database/Operations/Dsp.cs
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetDsps(out List<Dsp> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all DSPs...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from DSPs";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = SQL;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = DspsFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting DSPs.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetDsps(out List<Dsp> entries, ulong start, ulong count)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting {0} DSPs from {1}...", count, start);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM DSPs 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 = DspsFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting DSPs.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dsp GetDsp(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting DSP with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from DSPs 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<Dsp> entries = DspsFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting DSP.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountDsps()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting DSPs...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM DSPs";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddDsp(Dsp entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding DSP `{0}`...", entry.DSP);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandDsp(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL = "INSERT INTO DSPs (DSP)" + " VALUES (@DSP)";
|
||||||
|
|
||||||
|
dbcmd.CommandText = SQL;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
id = dbCore.LastInsertRowId;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine(" id {0}", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateDsp(Dsp entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating DSP `{0}`...", entry.DSP);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandDsp(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = "UPDATE DSPs SET DSP = @DSP " + $"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RemoveDsp(long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Removing DSP widh id `{0}`...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = $"DELETE FROM DSPs WHERE id = '{id}';";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbCommand GetCommandDsp(Dsp entry)
|
||||||
|
{
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
|
||||||
|
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||||
|
|
||||||
|
param1.ParameterName = "@DSP";
|
||||||
|
|
||||||
|
param1.DbType = DbType.String;
|
||||||
|
|
||||||
|
param1.Value = entry.DSP;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Dsp> DspsFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<Dsp> entries = new List<Dsp>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
Dsp entry = new Dsp {id = int.Parse(dataRow["id"].ToString()), DSP = dataRow["DSP"].ToString()};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
238
Cicm.Database/Operations/Forbidden.cs
Normal file
238
Cicm.Database/Operations/Forbidden.cs
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddForbidden(Forbidden entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding forbidden `{0}`...", entry.browser);
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateForbidden(Forbidden entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating forbidden `{0}`...", entry.browser);
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.browser;
|
||||||
|
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.Parse(dataRow["id"].ToString()),
|
||||||
|
browser = dataRow["browser"].ToString(),
|
||||||
|
date = dataRow["date"].ToString(),
|
||||||
|
ip = dataRow["ip"].ToString(),
|
||||||
|
referer = dataRow["referer"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
214
Cicm.Database/Operations/Gpu.cs
Normal file
214
Cicm.Database/Operations/Gpu.cs
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddGpu(Gpu entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding GPU `{0}`...", entry.gpu);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandGpu(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL = "INSERT INTO gpus (GPU)" + " VALUES (@GPU)";
|
||||||
|
|
||||||
|
dbcmd.CommandText = SQL;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
id = dbCore.LastInsertRowId;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine(" id {0}", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateGpu(Gpu entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating GPU `{0}`...", entry.gpu);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandGpu(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = "UPDATE gpus SET GPU = @GPU " + $"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
param1.ParameterName = "@GPU";
|
||||||
|
|
||||||
|
param1.DbType = DbType.String;
|
||||||
|
|
||||||
|
param1.Value = entry.gpu;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Gpu> GpusFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<Gpu> entries = new List<Gpu>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
Gpu entry = new Gpu {id = int.Parse(dataRow["id"].ToString()), gpu = dataRow["GPU"].ToString()};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
103
Cicm.Database/Operations/Init.cs
Normal file
103
Cicm.Database/Operations/Init.cs
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
using System;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas.Sql;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool InitializeNewDatabase()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Creating new database version {0}", DB_VERSION);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `admins`");
|
||||||
|
dbCmd.CommandText = V2.Admins;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `browser_test`");
|
||||||
|
dbCmd.CommandText = V2.BrowserTests;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `Companias`");
|
||||||
|
dbCmd.CommandText = V2.Companies;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `computers`");
|
||||||
|
dbCmd.CommandText = V2.Computers;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `consoles`");
|
||||||
|
dbCmd.CommandText = V2.Consoles;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `console_company`");
|
||||||
|
dbCmd.CommandText = V2.ConsoleCompanies;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `cpu`");
|
||||||
|
dbCmd.CommandText = V2.Cpus;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `admins`");
|
||||||
|
dbCmd.CommandText = V2.Admins;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `DSPs`");
|
||||||
|
dbCmd.CommandText = V2.Dsps;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `forbidden`");
|
||||||
|
dbCmd.CommandText = V2.Forbidden;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `Formatos_de_disco`");
|
||||||
|
dbCmd.CommandText = V2.DiskFormats;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `gpus`");
|
||||||
|
dbCmd.CommandText = V2.Gpus;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `log`");
|
||||||
|
dbCmd.CommandText = V2.Logs;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `money_donation`");
|
||||||
|
dbCmd.CommandText = V2.MoneyDonations;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `mpus`");
|
||||||
|
dbCmd.CommandText = V2.Mpus;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `news`");
|
||||||
|
dbCmd.CommandText = V2.News;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `own_computer`");
|
||||||
|
dbCmd.CommandText = V2.OwnComputers;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `own_consoles`");
|
||||||
|
dbCmd.CommandText = V2.OwnConsoles;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("Creating table `procesadores_principales`");
|
||||||
|
dbCmd.CommandText = V2.ProcesadoresPrincipales;
|
||||||
|
dbCmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error creating database.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
238
Cicm.Database/Operations/Log.cs
Normal file
238
Cicm.Database/Operations/Log.cs
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddLog(Log entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding log `{0}`...", entry.browser);
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateLog(Log entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating log `{0}`...", entry.browser);
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.browser;
|
||||||
|
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.Parse(dataRow["id"].ToString()),
|
||||||
|
browser = dataRow["browser"].ToString(),
|
||||||
|
date = dataRow["date"].ToString(),
|
||||||
|
ip = dataRow["ip"].ToString(),
|
||||||
|
referer = dataRow["referer"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
225
Cicm.Database/Operations/MoneyDonation.cs
Normal file
225
Cicm.Database/Operations/MoneyDonation.cs
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetMoneyDonations(out List<MoneyDonation> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all money donations...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from money_donation";
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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_donation 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MoneyDonation GetMoneyDonation(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting money_donation with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from money_donation 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountMoneyDonations()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting money donations...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM money_donation";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
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_donation (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_donation SET donator = @donator, quantity = @quantity " +
|
||||||
|
$"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_donation 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.Parse(dataRow["id"].ToString()),
|
||||||
|
donator = dataRow["browser"].ToString(),
|
||||||
|
quantity = float.Parse(dataRow["date"].ToString())
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
214
Cicm.Database/Operations/Mpu.cs
Normal file
214
Cicm.Database/Operations/Mpu.cs
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetMpus(out List<Mpu> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all MPUs...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from mpus";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = SQL;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = MpusFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting MPUs.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetMpus(out List<Mpu> entries, ulong start, ulong count)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting {0} MPUs from {1}...", count, start);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM mpus 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 = MpusFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting MPUs.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mpu GetMpu(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting MPU with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from mpus 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<Mpu> entries = MpusFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting MPU.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountMpus()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting mpus...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM mpus";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddMpu(Mpu entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding MPU `{0}`...", entry.mpu);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandMpu(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL = "INSERT INTO mpus (MPU)" + " VALUES (@MPU)";
|
||||||
|
|
||||||
|
dbcmd.CommandText = SQL;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
id = dbCore.LastInsertRowId;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine(" id {0}", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateMpu(Mpu entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating MPU `{0}`...", entry.mpu);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandMpu(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = "UPDATE mpus SET MPU = @MPU " + $"WHERE id = {entry.id}";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RemoveMpu(long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Removing MPU widh id `{0}`...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql = $"DELETE FROM mpus WHERE id = '{id}';";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbCommand GetCommandMpu(Mpu entry)
|
||||||
|
{
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
|
||||||
|
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||||
|
|
||||||
|
param1.ParameterName = "@MPU";
|
||||||
|
|
||||||
|
param1.DbType = DbType.String;
|
||||||
|
|
||||||
|
param1.Value = entry.mpu;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Mpu> MpusFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<Mpu> entries = new List<Mpu>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
Mpu entry = new Mpu {id = int.Parse(dataRow["id"].ToString()), mpu = dataRow["MPU"].ToString()};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
230
Cicm.Database/Operations/News.cs
Normal file
230
Cicm.Database/Operations/News.cs
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.added_id;
|
||||||
|
|
||||||
|
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.Parse(dataRow["id"].ToString()),
|
||||||
|
date = dataRow["date"].ToString(),
|
||||||
|
type = int.Parse(dataRow["type"].ToString()),
|
||||||
|
added_id = int.Parse(dataRow["added_id"].ToString())
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Cicm.Database/Operations/Operations.cs
Normal file
18
Cicm.Database/Operations/Operations.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
const int DB_VERSION = 2;
|
||||||
|
|
||||||
|
readonly IDbConnection dbCon;
|
||||||
|
readonly IDbCore dbCore;
|
||||||
|
|
||||||
|
public Operations(IDbConnection connection, IDbCore core)
|
||||||
|
{
|
||||||
|
dbCon = connection;
|
||||||
|
dbCore = core;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
319
Cicm.Database/Operations/OwnComputer.cs
Normal file
319
Cicm.Database/Operations/OwnComputer.cs
Normal file
@@ -0,0 +1,319 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetOwnOwnComputers(out List<OwnComputer> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all owned computers...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from own_computer";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = SQL;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = OwnOwnComputersFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting owned computers.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetOwnOwnComputers(out List<OwnComputer> entries, ulong start, ulong count)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting {0} owned computers from {1}...", count, start);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM own_computer 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 = OwnOwnComputersFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting owned computers.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public OwnComputer GetOwnComputer(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting owned computer with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from own_computer 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<OwnComputer> entries = OwnOwnComputersFromDataTable(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountOwnOwnComputers()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting owned computers...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM own_computer";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddOwnComputer(OwnComputer entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding owned computer `{0}`...", entry.db_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandOwnComputer(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL =
|
||||||
|
"INSERT INTO own_computer (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateOwnComputer(OwnComputer entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating computer `{0}`...", entry.db_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandOwnComputer(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql =
|
||||||
|
"UPDATE own_computer 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RemoveOwnComputer(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 own_computer WHERE id = '{id}';";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbCommand GetCommandOwnComputer(OwnComputer 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();
|
||||||
|
|
||||||
|
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";
|
||||||
|
param14.ParameterName = "@disk1";
|
||||||
|
param15.ParameterName = "@cap1";
|
||||||
|
param16.ParameterName = "@disk2";
|
||||||
|
param17.ParameterName = "@cap2";
|
||||||
|
|
||||||
|
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;
|
||||||
|
param14.DbType = DbType.Int32;
|
||||||
|
param15.DbType = DbType.Int32;
|
||||||
|
param16.DbType = DbType.Int32;
|
||||||
|
param17.DbType = DbType.Int32;
|
||||||
|
|
||||||
|
param1.Value = entry.db_id;
|
||||||
|
param2.Value = entry.date;
|
||||||
|
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;
|
||||||
|
param14.Value = entry.disk1;
|
||||||
|
param15.Value = entry.cap1;
|
||||||
|
param16.Value = entry.disk2;
|
||||||
|
param17.Value = entry.cap2;
|
||||||
|
|
||||||
|
dbcmd.Parameters.Add(param1);
|
||||||
|
dbcmd.Parameters.Add(param2);
|
||||||
|
dbcmd.Parameters.Add(param3);
|
||||||
|
dbcmd.Parameters.Add(param4);
|
||||||
|
dbcmd.Parameters.Add(param5);
|
||||||
|
dbcmd.Parameters.Add(param6);
|
||||||
|
dbcmd.Parameters.Add(param7);
|
||||||
|
dbcmd.Parameters.Add(param8);
|
||||||
|
dbcmd.Parameters.Add(param9);
|
||||||
|
dbcmd.Parameters.Add(param10);
|
||||||
|
dbcmd.Parameters.Add(param11);
|
||||||
|
dbcmd.Parameters.Add(param12);
|
||||||
|
dbcmd.Parameters.Add(param13);
|
||||||
|
dbcmd.Parameters.Add(param14);
|
||||||
|
dbcmd.Parameters.Add(param15);
|
||||||
|
dbcmd.Parameters.Add(param16);
|
||||||
|
dbcmd.Parameters.Add(param17);
|
||||||
|
|
||||||
|
return dbcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<OwnComputer> OwnOwnComputersFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<OwnComputer> entries = new List<OwnComputer>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
OwnComputer entry = new OwnComputer
|
||||||
|
{
|
||||||
|
id = int.Parse(dataRow["id"].ToString()),
|
||||||
|
db_id = int.Parse(dataRow["db_id"].ToString()),
|
||||||
|
date = dataRow["date"].ToString(),
|
||||||
|
status = int.Parse(dataRow["status"].ToString()),
|
||||||
|
trade = bool.Parse(dataRow["trade"].ToString()),
|
||||||
|
boxed = bool.Parse(dataRow["boxed"].ToString()),
|
||||||
|
manuals = bool.Parse(dataRow["manuals"].ToString()),
|
||||||
|
cpu1 = int.Parse(dataRow["cpu1"].ToString()),
|
||||||
|
mhz1 = float.Parse(dataRow["mhz1"].ToString()),
|
||||||
|
cpu2 = int.Parse(dataRow["cpu1"].ToString()),
|
||||||
|
mhz2 = float.Parse(dataRow["mhz2"].ToString()),
|
||||||
|
ram = int.Parse(dataRow["ram"].ToString()),
|
||||||
|
vram = int.Parse(dataRow["vram"].ToString()),
|
||||||
|
rigid = dataRow["rigid"].ToString(),
|
||||||
|
disk1 = int.Parse(dataRow["disk1"].ToString()),
|
||||||
|
cap1 = int.Parse(dataRow["cap1"].ToString()),
|
||||||
|
disk2 = int.Parse(dataRow["disk2"].ToString()),
|
||||||
|
cap2 = int.Parse(dataRow["cap2"].ToString())
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
251
Cicm.Database/Operations/OwnConsole.cs
Normal file
251
Cicm.Database/Operations/OwnConsole.cs
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
using Console = System.Console;
|
||||||
|
|
||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool GetOwnOwnConsoles(out List<OwnConsole> entries)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting all owned consoles...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string SQL = "SELECT * from own_consoles";
|
||||||
|
|
||||||
|
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||||
|
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||||
|
dbCmd.CommandText = SQL;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
dataAdapter.SelectCommand = dbCmd;
|
||||||
|
dataAdapter.Fill(dataSet);
|
||||||
|
|
||||||
|
entries = OwnOwnConsolesFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting owned consoles.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetOwnOwnConsoles(out List<OwnConsole> entries, ulong start, ulong count)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting {0} owned consoles from {1}...", count, start);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM own_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 = OwnOwnConsolesFromDataTable(dataSet.Tables[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting owned consoles.");
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
entries = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public OwnConsole GetOwnConsole(int id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Getting owned console with id {0}...", id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * from own_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<OwnConsole> entries = OwnOwnConsolesFromDataTable(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CountOwnOwnConsoles()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Counting owned consoles...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||||
|
dbcmd.CommandText = "SELECT COUNT(*) FROM own_consoles";
|
||||||
|
object count = dbcmd.ExecuteScalar();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
try { return Convert.ToInt64(count); }
|
||||||
|
catch { return 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddOwnConsole(OwnConsole entry, out long id)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Write("Adding owned console `{0}`...", entry.db_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandOwnConsole(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
const string SQL = "INSERT INTO own_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateOwnConsole(OwnConsole entry)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Updating console `{0}`...", entry.db_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDbCommand dbcmd = GetCommandOwnConsole(entry);
|
||||||
|
IDbTransaction trans = dbCon.BeginTransaction();
|
||||||
|
dbcmd.Transaction = trans;
|
||||||
|
|
||||||
|
string sql =
|
||||||
|
"UPDATE own_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RemoveOwnConsole(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 own_consoles WHERE id = '{id}';";
|
||||||
|
|
||||||
|
dbcmd.CommandText = sql;
|
||||||
|
|
||||||
|
dbcmd.ExecuteNonQuery();
|
||||||
|
trans.Commit();
|
||||||
|
dbcmd.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbCommand GetCommandOwnConsole(OwnConsole 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.db_id;
|
||||||
|
param2.Value = entry.date;
|
||||||
|
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<OwnConsole> OwnOwnConsolesFromDataTable(DataTable dataTable)
|
||||||
|
{
|
||||||
|
List<OwnConsole> entries = new List<OwnConsole>();
|
||||||
|
|
||||||
|
foreach(DataRow dataRow in dataTable.Rows)
|
||||||
|
{
|
||||||
|
OwnConsole entry = new OwnConsole
|
||||||
|
{
|
||||||
|
id = int.Parse(dataRow["id"].ToString()),
|
||||||
|
db_id = int.Parse(dataRow["db_id"].ToString()),
|
||||||
|
date = dataRow["date"].ToString(),
|
||||||
|
status = int.Parse(dataRow["status"].ToString()),
|
||||||
|
trade = bool.Parse(dataRow["trade"].ToString()),
|
||||||
|
boxed = bool.Parse(dataRow["boxed"].ToString()),
|
||||||
|
manuals = bool.Parse(dataRow["manuals"].ToString())
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Cicm.Database/Operations/Update.cs
Normal file
11
Cicm.Database/Operations/Update.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Cicm.Database
|
||||||
|
{
|
||||||
|
public partial class Operations
|
||||||
|
{
|
||||||
|
public bool UpdateDatabase()
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Cicm.Database.Schemas
|
namespace Cicm.Database.Schemas
|
||||||
{
|
{
|
||||||
public class DiskFormats
|
public class DiskFormat
|
||||||
{
|
{
|
||||||
public int id;
|
public int id;
|
||||||
public string Format;
|
public string Format;
|
||||||
@@ -2,204 +2,205 @@
|
|||||||
{
|
{
|
||||||
public static class V2
|
public static class V2
|
||||||
{
|
{
|
||||||
static readonly string Admins = @"CREATE TABLE IF NOT EXISTS `admin` (
|
public static readonly string Admins = @"CREATE TABLE IF NOT EXISTS `admin` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`user` char(50) NOT NULL DEFAULT '',
|
`user` char(50) NOT NULL DEFAULT '',
|
||||||
`password` char(50) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',
|
`password` char(50) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string BrowserTests = @"CREATE TABLE IF NOT EXISTS `browser_test` (
|
|
||||||
`id` smallint(5) unsigned zerofill NOT NULL AUTO_INCREMENT,
|
|
||||||
`idstring` varchar(128) NOT NULL DEFAULT '',
|
|
||||||
`browser` varchar(64) NOT NULL DEFAULT '',
|
|
||||||
`version` varchar(16) NOT NULL DEFAULT '',
|
|
||||||
`os` varchar(32) NOT NULL DEFAULT '',
|
|
||||||
`platform` varchar(8) NOT NULL DEFAULT '',
|
|
||||||
`gif87` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`gif89` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`jpeg` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`png` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`pngt` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`agif` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`table` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`colors` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`js` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`frames` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
`flash` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
);";
|
||||||
|
|
||||||
static readonly string Companies = @"CREATE TABLE IF NOT EXISTS `Companias` (
|
public static readonly string BrowserTests = @"CREATE TABLE IF NOT EXISTS `browser_test` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` smallint(5) unsigned zerofill NOT NULL AUTO_INCREMENT,
|
||||||
`Compania` char(128) NOT NULL DEFAULT '',
|
`idstring` varchar(128) NOT NULL DEFAULT '',
|
||||||
PRIMARY KEY (`id`)
|
`browser` varchar(64) NOT NULL DEFAULT '',
|
||||||
);";
|
`version` varchar(16) NOT NULL DEFAULT '',
|
||||||
|
`os` varchar(32) NOT NULL DEFAULT '',
|
||||||
|
`platform` varchar(8) NOT NULL DEFAULT '',
|
||||||
|
`gif87` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`gif89` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`jpeg` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`png` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`pngt` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`agif` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`table` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`colors` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`js` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`frames` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
`flash` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
static readonly string Computers = @"CREATE TABLE IF NOT EXISTS `computers` (
|
public static readonly string Companies = @"CREATE TABLE IF NOT EXISTS `Companias` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`company` int(11) NOT NULL DEFAULT '0',
|
`Compania` char(128) NOT NULL DEFAULT '',
|
||||||
`year` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`model` char(50) NOT NULL DEFAULT '',
|
|
||||||
`cpu1` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`mhz1` decimal(11,2) NOT NULL DEFAULT '0.00',
|
|
||||||
`cpu2` int(11) DEFAULT NULL,
|
|
||||||
`mhz2` decimal(11,2) DEFAULT NULL,
|
|
||||||
`bits` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`ram` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`rom` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`gpu` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`vram` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`colors` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`res` char(10) NOT NULL DEFAULT '',
|
|
||||||
`spu` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`mpu` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`sound_channels` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`music_channels` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`hdd1` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`hdd2` int(11) DEFAULT NULL,
|
|
||||||
`hdd3` int(11) DEFAULT NULL,
|
|
||||||
`disk1` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`cap1` char(25) NOT NULL DEFAULT '0',
|
|
||||||
`disk2` int(11) DEFAULT NULL,
|
|
||||||
`cap2` char(25) DEFAULT NULL,
|
|
||||||
`comment` char(255) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string Consoles = @"CREATE TABLE IF NOT EXISTS `consoles` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`company` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`name` char(50) NOT NULL DEFAULT '',
|
|
||||||
`year` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`cpu1` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`mhz1` decimal(11,2) NOT NULL DEFAULT '0.00',
|
|
||||||
`cpu2` int(11) DEFAULT NULL,
|
|
||||||
`mhz2` decimal(11,2) DEFAULT NULL,
|
|
||||||
`bits` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`ram` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`rom` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`gpu` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`vram` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`res` char(11) NOT NULL DEFAULT '',
|
|
||||||
`colors` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`palette` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`spu` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`schannels` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`mpu` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`mchannels` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`format` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`cap` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`comments` char(255) NOT NULL DEFAULT '',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string ConsoleCompanies = @"CREATE TABLE IF NOT EXISTS `console_company` (
|
|
||||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
|
||||||
`company` char(128) NOT NULL DEFAULT '',
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);";
|
);";
|
||||||
|
|
||||||
static readonly string Cpus = @"CREATE TABLE IF NOT EXISTS `cpu` (
|
public static readonly string Computers = @"CREATE TABLE IF NOT EXISTS `computers` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`cpu` char(50) NOT NULL DEFAULT '',
|
`company` int(11) NOT NULL DEFAULT '0',
|
||||||
KEY `id` (`id`)
|
`year` int(11) NOT NULL DEFAULT '0',
|
||||||
);";
|
`model` char(50) NOT NULL DEFAULT '',
|
||||||
|
`cpu1` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`mhz1` decimal(11,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`cpu2` int(11) DEFAULT NULL,
|
||||||
|
`mhz2` decimal(11,2) DEFAULT NULL,
|
||||||
|
`bits` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`ram` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`rom` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`gpu` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`vram` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`colors` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`res` char(10) NOT NULL DEFAULT '',
|
||||||
|
`spu` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`mpu` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`sound_channels` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`music_channels` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`hdd1` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`hdd2` int(11) DEFAULT NULL,
|
||||||
|
`hdd3` int(11) DEFAULT NULL,
|
||||||
|
`disk1` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`cap1` char(25) NOT NULL DEFAULT '0',
|
||||||
|
`disk2` int(11) DEFAULT NULL,
|
||||||
|
`cap2` char(25) DEFAULT NULL,
|
||||||
|
`comment` char(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
static readonly string Dsps = @"CREATE TABLE IF NOT EXISTS `DSPs` (
|
public static readonly string Consoles = @"CREATE TABLE IF NOT EXISTS `consoles` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`DSP` char(50) NOT NULL DEFAULT '',
|
`company` int(11) NOT NULL DEFAULT '0',
|
||||||
PRIMARY KEY (`id`)
|
`name` char(50) NOT NULL DEFAULT '',
|
||||||
);";
|
`year` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`cpu1` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`mhz1` decimal(11,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`cpu2` int(11) DEFAULT NULL,
|
||||||
|
`mhz2` decimal(11,2) DEFAULT NULL,
|
||||||
|
`bits` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`ram` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`rom` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`gpu` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`vram` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`res` char(11) NOT NULL DEFAULT '',
|
||||||
|
`colors` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`palette` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`spu` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`schannels` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`mpu` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`mchannels` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`format` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`cap` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`comments` char(255) NOT NULL DEFAULT '',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
static readonly string Forbidden = @"CREATE TABLE IF NOT EXISTS `forbidden` (
|
public static readonly string ConsoleCompanies = @"CREATE TABLE IF NOT EXISTS `console_company` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`browser` char(128) NOT NULL DEFAULT '',
|
`company` char(128) NOT NULL DEFAULT '',
|
||||||
`date` char(20) NOT NULL DEFAULT '',
|
|
||||||
`ip` char(16) NOT NULL DEFAULT '',
|
|
||||||
`referer` char(255) NOT NULL DEFAULT '',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string DiskFormats = @"CREATE TABLE IF NOT EXISTS `Formatos_de_disco` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`Format` char(50) NOT NULL DEFAULT '',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string Gpus = @"CREATE TABLE IF NOT EXISTS `gpus` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`gpu` char(128) NOT NULL DEFAULT '',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string Logs = @"CREATE TABLE IF NOT EXISTS `log` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`browser` char(128) NOT NULL DEFAULT '',
|
|
||||||
`ip` char(16) NOT NULL DEFAULT '',
|
|
||||||
`date` char(20) NOT NULL DEFAULT '',
|
|
||||||
`referer` char(255) NOT NULL DEFAULT '',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string MoneyDonations = @"CREATE TABLE IF NOT EXISTS `money_donation` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`donator` char(128) NOT NULL DEFAULT '',
|
|
||||||
`quantity` decimal(11,2) NOT NULL DEFAULT '0.00',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string Mpus = @"CREATE TABLE IF NOT EXISTS `mpus` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`mpu` char(50) NOT NULL DEFAULT '',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string News = @"CREATE TABLE IF NOT EXISTS `news` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`date` char(20) NOT NULL DEFAULT '',
|
|
||||||
`type` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`added_id` int(11) NOT NULL DEFAULT '0',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string OwnComputers = @"CREATE TABLE IF NOT EXISTS `own_computer` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`db_id` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`date` varchar(20) NOT NULL DEFAULT '',
|
|
||||||
`status` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`trade` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`boxed` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`manuals` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`cpu1` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`mhz1` decimal(10,0) NOT NULL DEFAULT '0',
|
|
||||||
`cpu2` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`mhz2` decimal(10,0) NOT NULL DEFAULT '0',
|
|
||||||
`ram` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`vram` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`rigid` varchar(64) NOT NULL DEFAULT '',
|
|
||||||
`disk1` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`cap1` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`disk2` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`cap2` int(11) NOT NULL DEFAULT '0',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string OwnConsoles = @"CREATE TABLE IF NOT EXISTS `own_consoles` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`db_id` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`date` char(20) NOT NULL DEFAULT '',
|
|
||||||
`status` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`trade` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`boxed` int(11) NOT NULL DEFAULT '0',
|
|
||||||
`manuals` int(11) NOT NULL DEFAULT '0',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);";
|
|
||||||
|
|
||||||
static readonly string ProcesadoresPrincipales = @"CREATE TABLE IF NOT EXISTS `procesadores_principales` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`CPU` char(50) NOT NULL DEFAULT '',
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);";
|
);";
|
||||||
|
|
||||||
|
public static readonly string Cpus = @"CREATE TABLE IF NOT EXISTS `cpu` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`cpu` char(50) NOT NULL DEFAULT '',
|
||||||
|
KEY `id` (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string Dsps = @"CREATE TABLE IF NOT EXISTS `DSPs` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`DSP` char(50) NOT NULL DEFAULT '',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string Forbidden = @"CREATE TABLE IF NOT EXISTS `forbidden` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`browser` char(128) NOT NULL DEFAULT '',
|
||||||
|
`date` char(20) NOT NULL DEFAULT '',
|
||||||
|
`ip` char(16) NOT NULL DEFAULT '',
|
||||||
|
`referer` char(255) NOT NULL DEFAULT '',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string DiskFormats = @"CREATE TABLE IF NOT EXISTS `Formatos_de_disco` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`Format` char(50) NOT NULL DEFAULT '',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string Gpus = @"CREATE TABLE IF NOT EXISTS `gpus` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`gpu` char(128) NOT NULL DEFAULT '',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string Logs = @"CREATE TABLE IF NOT EXISTS `log` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`browser` char(128) NOT NULL DEFAULT '',
|
||||||
|
`ip` char(16) NOT NULL DEFAULT '',
|
||||||
|
`date` char(20) NOT NULL DEFAULT '',
|
||||||
|
`referer` char(255) NOT NULL DEFAULT '',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string MoneyDonations = @"CREATE TABLE IF NOT EXISTS `money_donation` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`donator` char(128) NOT NULL DEFAULT '',
|
||||||
|
`quantity` decimal(11,2) NOT NULL DEFAULT '0.00',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string Mpus = @"CREATE TABLE IF NOT EXISTS `mpus` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`mpu` char(50) NOT NULL DEFAULT '',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string News = @"CREATE TABLE IF NOT EXISTS `news` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`date` char(20) NOT NULL DEFAULT '',
|
||||||
|
`type` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`added_id` int(11) NOT NULL DEFAULT '0',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string OwnComputers = @"CREATE TABLE IF NOT EXISTS `own_computer` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`db_id` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`date` varchar(20) NOT NULL DEFAULT '',
|
||||||
|
`status` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`trade` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`boxed` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`manuals` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`cpu1` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`mhz1` decimal(10,0) NOT NULL DEFAULT '0',
|
||||||
|
`cpu2` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`mhz2` decimal(10,0) NOT NULL DEFAULT '0',
|
||||||
|
`ram` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`vram` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`rigid` varchar(64) NOT NULL DEFAULT '',
|
||||||
|
`disk1` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`cap1` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`disk2` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`cap2` int(11) NOT NULL DEFAULT '0',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string OwnConsoles = @"CREATE TABLE IF NOT EXISTS `own_consoles` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`db_id` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`date` char(20) NOT NULL DEFAULT '',
|
||||||
|
`status` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`trade` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`boxed` int(11) NOT NULL DEFAULT '0',
|
||||||
|
`manuals` int(11) NOT NULL DEFAULT '0',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
|
|
||||||
|
public static readonly string ProcesadoresPrincipales =
|
||||||
|
@"CREATE TABLE IF NOT EXISTS `procesadores_principales` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`CPU` char(50) NOT NULL DEFAULT '',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ namespace cicm_web
|
|||||||
{
|
{
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
static Cicm.Database.Mysql database;
|
static Cicm.Database.IDbCore database;
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user