Files
SabreTools/SabreToolsUI/Helper.cs
Matt Nadareski 0f0313d52b Major changes to structure and code
First is the inclusion of two new projects: SabreHelper and SingleGame. SabreHelper is a DLL that contains anything that might be in common between programs (converters, db tools, logging). SingleGame is an experimental program to minimize a DAT for server usage, requested by Kludge.

The new structure represents a cleaner approach to having helper functions in a DLL, making each individual executable smaller and more well-defined.
2016-04-06 00:01:54 -07:00

81 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SabreTools
{
class UIHelper
{
private static string _dbName = "DATabase.sqlite";
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
public static object[] GetAllSystems()
{
List<object> objs = new List<object>();
Process.Start("DATabase.exe", "--skip");
string query = @"
SELECT DISTINCT systems.id, systems.manufacturer, systems.system
FROM systems JOIN games ON systems.id=games.system
ORDER BY systems.manufacturer, systems.system";
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
{
dbc.Open();
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
{
using (SQLiteDataReader sldr = slc.ExecuteReader())
{
// If nothing is found, tell the user and exit
if (sldr.HasRows)
{
while (sldr.Read())
{
objs.Add(sldr.GetString(1) + " - " + sldr.GetString(2) + " (" + sldr.GetInt32(0) + ")");
}
}
}
}
}
return objs.ToArray();
}
public static object[] GetAllSources()
{
List<object> objs = new List<object>();
Process.Start("DATabase.exe", "--skip");
string query = @"
SELECT DISTINCT sources.id, sources.name
FROM sources JOIN games on sources.id=games.source
ORDER BY sources.name COLLATE NOCASE";
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
{
dbc.Open();
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
{
using (SQLiteDataReader sldr = slc.ExecuteReader())
{
// If nothing is found, tell the user and exit
if (sldr.HasRows)
{
while (sldr.Read())
{
objs.Add(sldr.GetString(1) + " (" + sldr.GetInt32(0) + ")");
}
}
}
}
}
return objs.ToArray();
}
}
}