diff options
Diffstat (limited to 'Aktywator/Setting.cs')
-rw-r--r-- | Aktywator/Setting.cs | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/Aktywator/Setting.cs b/Aktywator/Setting.cs new file mode 100644 index 0000000..45d6b58 --- /dev/null +++ b/Aktywator/Setting.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; +using System.Data.OleDb; + +namespace Aktywator +{ + class Setting + { + public string name; + public string type; + public string defaultStr; + public string table; + public CheckBox field; + private Bws bws; + + public Setting(string name, CheckBox field, Bws bws) + { + this.name = name; + this.field = field; + this.bws = bws; + } + + public void load() + { + StringBuilder str = new StringBuilder(); + str.Append("SELECT "); + str.Append(this.name); + str.Append(" FROM Settings"); + field.Checked = false; + string a = bws.sql.selectOne(str.ToString()); + field.Checked = a.ToUpper() == "TRUE" ? true : false; + } + + public static string load(string name, Bws bws, StringBuilder errors) + { + StringBuilder str = new StringBuilder(); + str.Append("SELECT "); + str.Append(name); + str.Append(" FROM Settings"); + try + { + return bws.sql.selectOne(str.ToString()); + } + catch (OleDbException) + { + if (errors.Length > 0) errors.Append(", "); + errors.Append(name); + return ""; + } + } + + public void save() + { + StringBuilder str = new StringBuilder(); + str.Append("UPDATE Settings SET "); + str.Append(this.name); + if (field.Checked) str.Append("=true"); + else str.Append("=false"); + bws.sql.query(str.ToString()); + } + + public static void save(string name, string value, Bws bws, StringBuilder errors) + { + StringBuilder str = new StringBuilder(); + str.Append("UPDATE Settings SET "); + str.Append(name); + str.Append("="); + str.Append(value); + try + { + bws.sql.query(str.ToString()); + } + catch (OleDbException) + { + if (errors.Length > 0) errors.Append(", "); + errors.Append(name); + } + } + + public Setting(string name, string type) + { + this.name = name; + this.type = type; + this.defaultStr = ""; + this.table = "Settings"; + } + + public Setting(string name, string type, string defaultStr) + { + this.name = name; + this.type = type; + this.defaultStr = defaultStr; + this.table = "Settings"; + } + + public Setting(string name, string type, string defaultStr, string table) + { + this.name = name; + this.type = type; + this.defaultStr = defaultStr; + this.table = table; + } + + public string getAddColumnSql() + { + StringBuilder str = new StringBuilder(); + str.Append("ALTER TABLE "); + str.Append(this.table); + str.Append(" ADD COLUMN "); + str.Append(this.name); + str.Append(" "); + str.Append(this.type); + str.Append(";"); + return str.ToString(); + } + + public string getSetDefaultSql() + { + StringBuilder str = new StringBuilder(); + if (defaultStr.Length > 0) + { + str.Append("UPDATE "); + str.Append(this.table); + str.Append(" SET "); + str.Append(this.name); + str.Append("="); + str.Append(this.defaultStr); + str.Append(";"); + } + return str.ToString(); + } + } +} |