/// <summary> /// Open the specified database file /// </summary> /// <param name="databaseFile">Database file name to open</param> /// <param name="password">Password of database file</param> public bool Open(string databaseFile, string password) { Close(); FileName = Path.GetFullPath(databaseFile); Password = password; bool ok = false; Version version = GetSdfVersion(FileName); if (version == null) { foreach (Version ver in AvailableVersions.Reverse <Version>()) { ok = OpenConnection(ver, databaseFile, password); if (ok || BadPassword) { break; } } } else { ok = OpenConnection(version, databaseFile, password); if (!ok && (!BadPassword || password != null)) { GlobalText.ShowError("UnableToOpen", LastError); } } return(ok); }
public object ExecuteSql(string sql, bool updatable, string method) { if (Connection == null) { return(null); } if (Connection.State == ConnectionState.Closed) { Connection.Open(); } LastError = ""; object command = assembly.CreateInstance("System.Data.SqlServerCe.SqlCeCommand", false, BindingFlags.CreateInstance, null, new object[] { null, Connection }, null, null); var enumType = assembly.GetType("System.Data.SqlServerCe.ResultSetOptions"); ResultSetOptions options = updatable ? ResultSetOptions.Scrollable | ResultSetOptions.Updatable : ResultSetOptions.Scrollable; object result = null; QueryCount = 0; for (Match m = regexSemicolon.Match(sql); m.Success; m = m.NextMatch()) { if (!string.IsNullOrEmpty(m.Value)) { QueryCount++; try { command.GetType().InvokeMember("CommandText", BindingFlags.SetProperty, null, command, new object[] { m.Value.Trim() }); object resultset = command.GetType().GetMethod(method, new System.Type[] { enumType }, null).Invoke(command, new object[] { options }); bool scrollable = (bool)resultset.GetType().InvokeMember("Scrollable", BindingFlags.GetProperty, null, resultset, null); if (scrollable) { result = resultset; } } catch (Exception e) { LastError = GlobalText.GetValue("Query") + " " + QueryCount + ": " + (e.InnerException == null ? e.Message : e.InnerException.Message); return(null); } } } return(result); }
public static void ShowWarning(string warningMsg) { MessageBox.Show(warningMsg, GlobalText.GetValue("Warning"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }
public static void ShowInfo(string key) { MessageBox.Show(GlobalText.GetValue(key), GlobalText.GetValue("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); }
public static void ShowError(string key, string additionalMsg) { string errorText = string.IsNullOrEmpty(additionalMsg) ? GlobalText.GetValue(key) : GlobalText.GetValue(key) + ":\r\n\r\n" + additionalMsg; MessageBox.Show(errorText, GlobalText.GetValue("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); }