Concise queries, reduce to functionality
- Remove DataStorage qualifier, add using statements - Remove unnecessary query variables and string.formatting statements - Remove duplicate code, reuse .RecordCount method
This commit is contained in:
parent
473655c2ce
commit
f8f70f46e6
16 changed files with 111 additions and 143 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using MatterHackers.MatterControl.SettingsManagement;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.MatterControl.SettingsManagement;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
|
|
@ -12,7 +13,7 @@ namespace MatterHackers.MatterControl
|
|||
public static string OpenDesignFileParams { get { return "STL, AMF, ZIP|*.stl;*.amf;*.zip"; } }
|
||||
|
||||
private static ApplicationSettings globalInstance = null;
|
||||
public Dictionary<string, DataStorage.SystemSetting> settingsDictionary;
|
||||
public Dictionary<string, SystemSetting> settingsDictionary;
|
||||
|
||||
public static ApplicationSettings Instance
|
||||
{
|
||||
|
|
@ -69,14 +70,14 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public void set(string key, string value)
|
||||
{
|
||||
DataStorage.SystemSetting setting;
|
||||
SystemSetting setting;
|
||||
if (settingsDictionary.ContainsKey(key))
|
||||
{
|
||||
setting = settingsDictionary[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
setting = new DataStorage.SystemSetting();
|
||||
setting = new SystemSetting();
|
||||
setting.Name = key;
|
||||
|
||||
settingsDictionary[key] = setting;
|
||||
|
|
@ -88,20 +89,17 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
private void LoadData()
|
||||
{
|
||||
IEnumerable<DataStorage.SystemSetting> settingsList = GetApplicationSettings();
|
||||
settingsDictionary = new Dictionary<string, DataStorage.SystemSetting>();
|
||||
foreach (DataStorage.SystemSetting s in settingsList)
|
||||
settingsDictionary = new Dictionary<string, SystemSetting>();
|
||||
foreach (SystemSetting s in GetApplicationSettings())
|
||||
{
|
||||
settingsDictionary[s.Name] = s;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<DataStorage.SystemSetting> GetApplicationSettings()
|
||||
private IEnumerable<SystemSetting> GetApplicationSettings()
|
||||
{
|
||||
//Retrieve a list of saved printers from the Datastore
|
||||
string query = string.Format("SELECT * FROM SystemSetting;");
|
||||
IEnumerable<DataStorage.SystemSetting> result = (IEnumerable<DataStorage.SystemSetting>)DataStorage.Datastore.Instance.dbSQLite.Query<DataStorage.SystemSetting>(query);
|
||||
return result;
|
||||
//Retrieve SystemSettings from the Datastore
|
||||
return Datastore.Instance.dbSQLite.Query<SystemSetting>("SELECT * FROM SystemSetting;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class PrinterSettings
|
||||
{
|
||||
private static PrinterSettings globalInstance = null;
|
||||
public Dictionary<string, DataStorage.PrinterSetting> settingsDictionary;
|
||||
public Dictionary<string, PrinterSetting> settingsDictionary;
|
||||
private int ActiveSettingsPrinterId = -1;
|
||||
|
||||
public static PrinterSettings Instance
|
||||
|
|
@ -60,14 +61,14 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
LoadDataIfNeeded();
|
||||
|
||||
DataStorage.PrinterSetting setting;
|
||||
PrinterSetting setting;
|
||||
if (settingsDictionary.ContainsKey(key))
|
||||
{
|
||||
setting = settingsDictionary[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
setting = new DataStorage.PrinterSetting();
|
||||
setting = new PrinterSetting();
|
||||
setting.Name = key;
|
||||
setting.PrinterId = ActivePrinterProfile.Instance.ActivePrinter.Id;
|
||||
|
||||
|
|
@ -83,9 +84,8 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
if (ActivePrinterProfile.Instance.ActivePrinter != null)
|
||||
{
|
||||
IEnumerable<DataStorage.PrinterSetting> settingsList = GetPrinterSettings();
|
||||
settingsDictionary = new Dictionary<string, DataStorage.PrinterSetting>();
|
||||
foreach (DataStorage.PrinterSetting s in settingsList)
|
||||
settingsDictionary = new Dictionary<string, PrinterSetting>();
|
||||
foreach (PrinterSetting s in GetPrinterSettings())
|
||||
{
|
||||
settingsDictionary[s.Name] = s;
|
||||
}
|
||||
|
|
@ -93,12 +93,11 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
private IEnumerable<DataStorage.PrinterSetting> GetPrinterSettings()
|
||||
private IEnumerable<PrinterSetting> GetPrinterSettings()
|
||||
{
|
||||
//Retrieve a list of settings from the Datastore
|
||||
string query = string.Format("SELECT * FROM PrinterSetting WHERE PrinterId = {0};", ActivePrinterProfile.Instance.ActivePrinter.Id);
|
||||
IEnumerable<DataStorage.PrinterSetting> result = (IEnumerable<DataStorage.PrinterSetting>)DataStorage.Datastore.Instance.dbSQLite.Query<DataStorage.PrinterSetting>(query);
|
||||
return result;
|
||||
return Datastore.Instance.dbSQLite.Query<PrinterSetting>(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue