Fixed ROM count and platform display
* Fixed ROM count and platform display
This commit is contained in:
@@ -235,7 +235,8 @@ namespace gaseous_server.Classes
|
|||||||
{
|
{
|
||||||
case databaseType.MySql:
|
case databaseType.MySql:
|
||||||
MySQLServerConnector conn = new MySQLServerConnector(ConnectionString);
|
MySQLServerConnector conn = new MySQLServerConnector(ConnectionString);
|
||||||
return (int)conn.ExecNonQuery(Command, Parameters, Timeout);
|
int retVal = conn.ExecNonQuery(Command, Parameters, Timeout);
|
||||||
|
return retVal;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,8 @@ namespace gaseous_server.Classes
|
|||||||
|
|
||||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
string sql = "";
|
string sql = "";
|
||||||
|
string sqlCount = "";
|
||||||
|
string sqlPlatform = "";
|
||||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
||||||
dbDict.Add("id", GameId);
|
dbDict.Add("id", GameId);
|
||||||
|
|
||||||
@@ -31,21 +33,32 @@ namespace gaseous_server.Classes
|
|||||||
dbDict.Add("namesearch", '%' + NameSearch + '%');
|
dbDict.Add("namesearch", '%' + NameSearch + '%');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// platform query
|
||||||
|
sqlPlatform = "SELECT DISTINCT Games_Roms.PlatformId, Platform.`Name` FROM Games_Roms LEFT JOIN Platform ON Games_Roms.PlatformId = Platform.Id WHERE GameId = @id ORDER BY Platform.`Name`;";
|
||||||
|
|
||||||
if (PlatformId == -1) {
|
if (PlatformId == -1) {
|
||||||
|
// data query
|
||||||
sql = "SELECT Games_Roms.*, Platform.`Name` AS platformname FROM Games_Roms LEFT JOIN Platform ON Games_Roms.PlatformId = Platform.Id WHERE Games_Roms.GameId = @id" + NameSearchWhere + " ORDER BY Platform.`Name`, Games_Roms.`Name` LIMIT 1000;";
|
sql = "SELECT Games_Roms.*, Platform.`Name` AS platformname FROM Games_Roms LEFT JOIN Platform ON Games_Roms.PlatformId = Platform.Id WHERE Games_Roms.GameId = @id" + NameSearchWhere + " ORDER BY Platform.`Name`, Games_Roms.`Name` LIMIT 1000;";
|
||||||
|
|
||||||
|
// count query
|
||||||
|
sqlCount = "SELECT COUNT(Games_Roms.Id) AS RomCount FROM Games_Roms WHERE Games_Roms.GameId = @id" + NameSearchWhere + ";";
|
||||||
} else {
|
} else {
|
||||||
|
// data query
|
||||||
sql = "SELECT Games_Roms.*, Platform.`Name` AS platformname FROM Games_Roms LEFT JOIN Platform ON Games_Roms.PlatformId = Platform.Id WHERE Games_Roms.GameId = @id AND Games_Roms.PlatformId = @platformid" + NameSearchWhere + " ORDER BY Platform.`Name`, Games_Roms.`Name` LIMIT 1000;";
|
sql = "SELECT Games_Roms.*, Platform.`Name` AS platformname FROM Games_Roms LEFT JOIN Platform ON Games_Roms.PlatformId = Platform.Id WHERE Games_Roms.GameId = @id AND Games_Roms.PlatformId = @platformid" + NameSearchWhere + " ORDER BY Platform.`Name`, Games_Roms.`Name` LIMIT 1000;";
|
||||||
|
|
||||||
|
// count query
|
||||||
|
sqlCount = "SELECT COUNT(Games_Roms.Id) AS RomCount FROM Games_Roms WHERE Games_Roms.GameId = @id AND Games_Roms.PlatformId = @platformid" + NameSearchWhere + ";";
|
||||||
|
|
||||||
dbDict.Add("platformid", PlatformId);
|
dbDict.Add("platformid", PlatformId);
|
||||||
}
|
}
|
||||||
DataTable romDT = db.ExecuteCMD(sql, dbDict);
|
DataTable romDT = db.ExecuteCMD(sql, dbDict);
|
||||||
|
Dictionary<string, object> rowCount = db.ExecuteCMDDict(sqlCount, dbDict)[0];
|
||||||
|
DataTable platformDT = db.ExecuteCMD(sqlPlatform, dbDict);
|
||||||
|
|
||||||
if (romDT.Rows.Count > 0)
|
if (romDT.Rows.Count > 0)
|
||||||
{
|
{
|
||||||
// set count of roms
|
// set count of roms
|
||||||
GameRoms.Count = romDT.Rows.Count;
|
GameRoms.Count = int.Parse((string)rowCount["RomCount"]);
|
||||||
|
|
||||||
// setup platforms list
|
|
||||||
Dictionary<long, string> platformDict = new Dictionary<long, string>();
|
|
||||||
|
|
||||||
int pageOffset = pageSize * (pageNumber - 1);
|
int pageOffset = pageSize * (pageNumber - 1);
|
||||||
for (int i = 0; i < romDT.Rows.Count; i++)
|
for (int i = 0; i < romDT.Rows.Count; i++)
|
||||||
@@ -56,18 +69,18 @@ namespace gaseous_server.Classes
|
|||||||
{
|
{
|
||||||
GameRoms.GameRomItems.Add(gameRomItem);
|
GameRoms.GameRomItems.Add(gameRomItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!platformDict.ContainsKey(gameRomItem.PlatformId))
|
|
||||||
{
|
|
||||||
platformDict.Add(gameRomItem.PlatformId, gameRomItem.Platform);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get rom media groups
|
// get rom media groups
|
||||||
GameRoms.MediaGroups = Classes.RomMediaGroup.GetMediaGroupsFromGameId(GameId);
|
GameRoms.MediaGroups = Classes.RomMediaGroup.GetMediaGroupsFromGameId(GameId);
|
||||||
|
|
||||||
// sort the platforms
|
// sort the platforms
|
||||||
GameRoms.Platforms = platformDict.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value).ToList<KeyValuePair<long, string>>();
|
GameRoms.Platforms = new List<KeyValuePair<long, string>>();
|
||||||
|
foreach (DataRow platformRow in platformDT.Rows)
|
||||||
|
{
|
||||||
|
KeyValuePair<long, string> valuePair = new KeyValuePair<long, string>((long)platformRow["PlatformId"], (string)platformRow["Name"]);
|
||||||
|
GameRoms.Platforms.Add(valuePair);
|
||||||
|
}
|
||||||
|
|
||||||
return GameRoms;
|
return GameRoms;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user