private void StoreFormula() { string cacheName = (activeCode != null) ? activeCode : "NOTES"; UTF8Encoding enc = new UTF8Encoding(); try { lock (Core.SettingsProvider) { FormulaPoco poco = Core.SettingsProvider.Database.FirstOrDefault <FormulaPoco>(string.Format("select * from {0} where code=@0", Core.SettingsProvider.GetFullTableName("formulas")), cacheName); byte[] decoded = enc.GetBytes(tbFormula.Text); string encoded = Convert.ToBase64String(decoded); string fmt = "DELETE FROM {2} WHERE code='{0}'"; if (tbFormula.Text.Length > 0) { fmt = (poco != null) ? "UPDATE {2} SET formula='{1}' WHERE code='{0}'" : "INSERT INTO {2} (code, formula) VALUES('{0}', '{1}')"; } string cmd = string.Format(fmt, cacheName, encoded, Core.SettingsProvider.GetFullTableName("formulas")); Core.SettingsProvider.Database.Execute(cmd); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void LoadFormula() { string cacheName = (activeCode != null) ? activeCode : "NOTES"; try { lock (Core.SettingsProvider) { FormulaPoco poco = Core.SettingsProvider.Database.FirstOrDefault <FormulaPoco>(string.Format("select * from {0} where code=@0", Core.SettingsProvider.GetFullTableName("formulas")), cacheName); if (poco != null) { UTF8Encoding enc = new UTF8Encoding(); byte[] decoded = Convert.FromBase64String(poco.formula); string formula = enc.GetString(decoded); tbFormula.Text = formula; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }