///<summary>Deletes everything from the SiteLink table. Does not truncate the table so that PKs are not reused on accident.</summary> public static void ClearSiteLinkTable() { string command = "DELETE FROM sitelink WHERE SiteLinkNum > 0"; DataCore.NonQ(command); SiteLinks.RefreshCache(); }
///<summary></summary> public static SiteLink CreateSiteLink(long siteNum, string octetStart = "", string connectionSettingsHQOverrides = "") { SiteLink siteLink = new SiteLink() { SiteNum = siteNum, OctetStart = octetStart, ConnectionSettingsHQOverrides = connectionSettingsHQOverrides }; siteLink.SiteLinkNum = SiteLinks.Insert(siteLink); SiteLinks.RefreshCache(); return(siteLink); }
///<summary>Attempts to connect and get connection settings from the database that is used by DataAction.RunCustomers(). ///Returns true and sets text boxes to the corresponding connectino setting values if a successful connection was made. ///Otherwise; displays an error message to the user and returns false. Assumes a connection to a 'customers' db has already been made.</summary> private bool TryDatabaseConnectionSettings() { //Assume that we have a guaranteed connection to HQ's 'customers' database. //Look and see what connection settings this computer should use via DataAction.RunCustomers(). _timerDatabase.Stop(); try { //Clear out the currently cached HQ database connections and refresh both the preference and site link caches. DataAction.ClearDictHqCentralConnections(); Prefs.RefreshCache(); SiteLinks.RefreshCache(); string serverName = ""; string databaseName = ""; string mySqlUser = ""; string mySqlPassword = ""; Action action = () => { serverName = DataConnection.GetServerName(); databaseName = DataConnection.GetDatabaseName(); mySqlUser = DataConnection.GetMysqlUser(); mySqlPassword = DataConnection.GetMysqlPass(); }; DataAction.RunCustomers(action, useConnectionStore: false); //Display the settings to the user so that we can easily tell what database this instance is pointing to. textServerName.Text = serverName; textDatabaseName.Text = databaseName; textMySQLUser.Text = mySqlUser; textMySQLPassword.Text = mySqlPassword; } catch (Exception ex) { labelError.Visible = true; MessageBox.Show(this, "There was an error making a connection to the database.\r\n" + "Please correct the database connection settings then click Reconnect.\r\n\r\n" + ex.Message); return(false); } _timerDatabase.Start(); return(true); }