public static System.Boolean GetDBVersion(out System.String APetraDBVersion) { TDBTransaction ReadTransaction = null; APetraDBVersion = "Cannot retrieve DB version"; TLogging.LogAtLevel(9, "TSysManServerLookups.GetDatabaseVersion called!"); SSystemDefaultsTable SystemDefaultsDT = new SSystemDefaultsTable(); DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction( IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { // Load data SystemDefaultsDT = SSystemDefaultsAccess.LoadByPrimaryKey("CurrentDatabaseVersion", ReadTransaction); }); if (SystemDefaultsDT.Rows.Count < 1) { throw new EOPAppException( "TSysManServerLookups.GetDBVersion: s_system_defaults DB Table is empty; this is unexpected and can lead to sever malfunction of OpenPetra. Contact your Support Team."); } SSystemDefaultsRow sysrow = SystemDefaultsDT.Rows[0] as SSystemDefaultsRow; if (sysrow == null) { throw new EOPAppException( "TSysManServerLookups.GetDBVersion: s_system_defaults DB Table is empty; this is unexpected and can lead to sever malfunction of OpenPetra. Contact your Support Team."); } APetraDBVersion = sysrow.DefaultValue; return(true); }
private void FPetraUtilsObject_DataSavingValidated(object Sender, System.ComponentModel.CancelEventArgs e) { // Capture any rows that are going to be saved that we are interested in SSystemDefaultsTable submitDT = FMainDS.SSystemDefaults.GetChangesTyped(); FIncludesLocalisedCountyLabel = (SSystemDefaultsRow)submitDT.Rows.Find(SharedConstants.SYSDEFAULT_LOCALISEDCOUNTYLABEL); FIncludesDonorZero = (SSystemDefaultsRow)submitDT.Rows.Find(SharedConstants.SYSDEFAULT_DONORZEROISVALID); FIncludesRecipientZero = (SSystemDefaultsRow)submitDT.Rows.Find(SharedConstants.SYSDEFAULT_RECIPIENTZEROISVALID); }
private void GetDetailDataFromControlsManual(SSystemDefaultsRow ARow) { if (FShowingSysAdminCodes) { ARow.DefaultValue = FPrevDefaultValue; } else { ARow.DefaultValue = FControlsDataTable.GetCurrentValue(); } }
public static String GetSystemDefault(String ASystemDefaultName) { String ReturnValue = SharedConstants.SYSDEFAULT_NOT_FOUND; SSystemDefaultsTable SystemDefaultsTable = GetSystemDefaults(); // Look up the System Default SSystemDefaultsRow FoundSystemDefaultsRow = (SSystemDefaultsRow)SystemDefaultsTable.Rows.Find(ASystemDefaultName); if (FoundSystemDefaultsRow != null) { ReturnValue = FoundSystemDefaultsRow.DefaultValue; } return(ReturnValue); }
private void ShowDetailsManual(SSystemDefaultsRow ARow) { if (ARow == null) { FPetraUtilsObject.ClearControls(pnlBottom); FControlsDataTable.RemoveAllControls(); pnlBottom.Enabled = false; return; } // Display the controls required for the system default code in this row pnlBottom.Enabled = true; FPrevDefaultValue = ARow.DefaultValue; FControlsDataTable.ShowControls(ARow.DefaultCode, pnlValues, ARow.DefaultValue, ARow.ReadOnly, ControlValidatedHandler); }
/// <summary> /// Updates the 'Last Reminder Date', that is the date when PartnerReminders last ran. /// <para> /// This is done by updating a certain SystemDefault. /// </para> /// </summary> /// <param name="ASystemDefaultsDR">SystemDefaults DataRow containing the date.</param> /// <param name="AReadWriteTransaction">Already instantiated DB Transaction.</param> private static void UpdateLastReminderDate(SSystemDefaultsRow ASystemDefaultsDR, TDBTransaction AReadWriteTransaction) { // Set SystemDefault value to today's date (mind the Format!) ASystemDefaultsDR.DefaultValue = String.Format("{0},{1},{2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); try { SSystemDefaultsAccess.SubmitChanges((SSystemDefaultsTable)ASystemDefaultsDR.Table, AReadWriteTransaction); } catch (Exception Exc) { TLogging.Log("TProcessPartnerReminders.UpdateLastReminderDate: An Exception occured:" + Environment.NewLine + Exc.ToString()); throw; } }
private void ValidateDataDetailsManual(SSystemDefaultsRow ARow) { if (FShowingSysAdminCodes) { return; } TVerificationResultCollection verificationResults = FPetraUtilsObject.VerificationResultCollection; DataColumn validationColumn = ARow.Table.Columns[SSystemDefaultsTable.ColumnDefaultValueId]; // First we need to validate that there were no errors setting up the controls for this row if (!FControlsDataTable.Validate(ARow.DefaultValue, validationColumn, this, verificationResults)) { // No point in carrying on with other validations because the controls are all messed up return; } // Individual rows can be validated to check that settings code values are ok. // This shows how to check SYSDEFAULT_LOCALISEDCOUNTYLABEL is not an empty string // We no longer check for this because Petra databases have empty string here and our main OP code takes care of empty string // by substituting our default County/State //TVerificationResult verificationResult = null; //if (string.Compare(ARow.DefaultCode, SharedConstants.SYSDEFAULT_LOCALISEDCOUNTYLABEL, true) == 0) //{ // Control[] validationControl = pnlValues.Controls.Find("cValue_0", true); // if (validationControl.Length > 0) // { // verificationResult = TStringChecks.StringMustNotBeEmpty(ARow.DefaultValue, "", // this, validationColumn, validationControl[0]); // if (verificationResult != null) // { // verificationResult.OverrideResultText(CommonResourcestrings.StrSettingCannotBeEmpty); // } // } // verificationResults.Auto_Add_Or_AddOrRemove(this, verificationResult, validationColumn); //} }
/// <summary> /// Returns the value of the specified System Default. /// <para> /// The caller doesn't need to know whether the Cache is already populated - if /// this should be necessary, this function will make a request to populate the /// cache. /// </para> /// </summary> /// <remarks>SystemDefault Names are not case sensitive.</remarks> /// <param name="ASystemDefaultName">The System Default for which the value should be returned.</param> /// <returns>The value of the System Default, or SharedConstants.SYSDEFAULT_NOT_FOUND if the /// specified System Default doesn't exist. /// </returns> public String GetSystemDefault(String ASystemDefaultName) { if (FSystemDefaultsDT == null) { LoadSystemDefaultsTable(); } // FSystemDefaultsDT is not case sensitive so Find will find the first case-insensitive match // The code to save a default handles ensuring that we never add a row with a 'similar' but non-identical primary key SSystemDefaultsRow FoundSystemDefaultsRow = (SSystemDefaultsRow)FSystemDefaultsDT.Rows.Find(ASystemDefaultName); if (FoundSystemDefaultsRow != null) { return(FoundSystemDefaultsRow.DefaultValue); } else { return(SharedConstants.SYSDEFAULT_NOT_FOUND); } }
/// <summary> /// Determines the 'Last Reminder Date', that is the date when PartnerReminders last ran. /// <para> /// This is done by reading a certain SystemDefault. If PartnerReminders was never run before, /// this SystemDefault is created. /// </para> /// </summary> /// <param name="ALastReminderDate">Date when PartnerReminders last ran. Will be January 1st, 1980 /// if PartnerReminders never ran before.</param> /// <param name="ASystemDefaultsDR">SystemDefaults DataRow containing the date. This is used later for updating /// the date.</param> /// <param name="AReadWriteTransaction">Already instantiated DB Transaction.</param> /// <returns>True if the 'Last Reminder Date' could be read/created. False if PartnerReminders was never run before /// AND creation of the new SystemDefault record failed for some reason.</returns> private static bool GetLastReminderDate(out DateTime ALastReminderDate, out SSystemDefaultsRow ASystemDefaultsDR, TDBTransaction AReadWriteTransaction) { const string UNDEFINED_SYSTEMDEFAULT_LAST_REMINDER_DATE = "1980,1,1"; // Double check order! SSystemDefaultsTable SystemDefaultsDT = new SSystemDefaultsTable(); string LastReminderDateStr; string[] DateParts; bool ReturnValue = true; ASystemDefaultsDR = null; // Check if there is already a SystemDefault for the Last Reminder Date (most likely there is!) if (SSystemDefaultsAccess.Exists(SYSTEMDEFAULT_LAST_REMINDER_DATE, AReadWriteTransaction)) { if (TLogging.DebugLevel >= 6) { TLogging.Log("GetLastReminderDate: System Default for the Last Reminder Date exists: use it."); } // There is already a SystemDefault for the Last Reminder Date: read its value SystemDefaultsDT = SSystemDefaultsAccess.LoadByPrimaryKey(SYSTEMDEFAULT_LAST_REMINDER_DATE, AReadWriteTransaction); // Used later to update the row ASystemDefaultsDR = SystemDefaultsDT[0]; } else { // System Default for the Last Reminder Date doesn't exist: add a new SystemDefault for future use if (TLogging.DebugLevel >= 6) { TLogging.Log("GetLastReminderDate: System Default for the Last Reminder Date doesn't exist yet: creating it."); } ASystemDefaultsDR = SystemDefaultsDT.NewRowTyped(); ASystemDefaultsDR.DefaultCode = SYSTEMDEFAULT_LAST_REMINDER_DATE; ASystemDefaultsDR.DefaultDescription = SYSTEMDEFAULT_LAST_REMINDER_DATE_DESC; ASystemDefaultsDR.DefaultValue = UNDEFINED_SYSTEMDEFAULT_LAST_REMINDER_DATE; try { SSystemDefaultsAccess.SubmitChanges(SystemDefaultsDT, AReadWriteTransaction); } catch (Exception Exc) { TLogging.Log("TProcessPartnerReminders.GetLastReminderDate: An Exception occured:" + Environment.NewLine + Exc.ToString()); throw; } } LastReminderDateStr = ASystemDefaultsDR.DefaultValue; // Last Reminder Date is stored as YEAR,MONTH,DAY DateParts = LastReminderDateStr.Split(','); ALastReminderDate = new DateTime( Convert.ToInt32(DateParts[0]), Convert.ToInt32(DateParts[1]), Convert.ToInt32(DateParts[2]), 0, 0, 1); // One second past midnight if (TLogging.DebugLevel >= 6) { TLogging.Log(String.Format("GetLastReminderDate: DB Field value: {0}; Parsed date: {1}", LastReminderDateStr, ALastReminderDate)); } return(ReturnValue); }
/// <summary> /// Determines the 'Last Reminder Date', that is the date when PartnerReminders last ran. /// <para> /// This is done by reading a certain SystemDefault. If PartnerReminders was never run before, /// this SystemDefault is created. /// </para> /// </summary> /// <param name="ALastReminderDate">Date when PartnerReminders last ran. Will be January 1st, 1980 /// if PartnerReminders never ran before.</param> /// <param name="ASystemDefaultsDR">SystemDefaults DataRow containing the date. This is used later for updating /// the date.</param> /// <param name="AReadWriteTransaction">Already instantiated DB Transaction.</param> /// <returns>True if the 'Last Reminder Date' could be read/created. False if PartnerReminders was never run before /// AND creation of the new SystemDefault record failed for some reason.</returns> private static bool GetLastReminderDate(out DateTime ALastReminderDate, out SSystemDefaultsRow ASystemDefaultsDR, TDBTransaction AReadWriteTransaction) { const string UNDEFINED_SYSTEMDEFAULT_LAST_REMINDER_DATE = "1980,1,1"; // Double check order! SSystemDefaultsTable SystemDefaultsDT = new SSystemDefaultsTable(); string LastReminderDateStr; string[] DateParts; bool ReturnValue = true; ASystemDefaultsDR = null; // Check if there is already a SystemDefault for the Last Reminder Date (most likely there is!) if (SSystemDefaultsAccess.Exists(SYSTEMDEFAULT_LAST_REMINDER_DATE, AReadWriteTransaction)) { if (TLogging.DebugLevel >= 6) { TLogging.Log("GetLastReminderDate: System Default for the Last Reminder Date exists: use it."); } // There is already a SystemDefault for the Last Reminder Date: read its value SystemDefaultsDT = SSystemDefaultsAccess.LoadByPrimaryKey(SYSTEMDEFAULT_LAST_REMINDER_DATE, AReadWriteTransaction); // Used later to update the row ASystemDefaultsDR = SystemDefaultsDT[0]; } else { // System Default for the Last Reminder Date doesn't exist: add a new SystemDefault for future use if (TLogging.DebugLevel >= 6) { TLogging.Log("GetLastReminderDate: System Default for the Last Reminder Date doesn't exist yet: creating it."); } ASystemDefaultsDR = SystemDefaultsDT.NewRowTyped(); ASystemDefaultsDR.DefaultCode = SYSTEMDEFAULT_LAST_REMINDER_DATE; ASystemDefaultsDR.DefaultDescription = SYSTEMDEFAULT_LAST_REMINDER_DATE_DESC; ASystemDefaultsDR.DefaultValue = UNDEFINED_SYSTEMDEFAULT_LAST_REMINDER_DATE; try { SSystemDefaultsAccess.SubmitChanges(SystemDefaultsDT, AReadWriteTransaction); } catch (Exception Exc) { TLogging.Log("TProcessPartnerReminders.GetLastReminderDate: An Exception occured:" + Environment.NewLine + Exc.ToString()); throw; } } LastReminderDateStr = ASystemDefaultsDR.DefaultValue; // Last Reminder Date is stored as YEAR,MONTH,DAY DateParts = LastReminderDateStr.Split(','); ALastReminderDate = new DateTime( Convert.ToInt32(DateParts[0]), Convert.ToInt32(DateParts[1]), Convert.ToInt32(DateParts[2]), 0, 0, 1); // One second past midnight if (TLogging.DebugLevel >= 6) { TLogging.Log(String.Format("GetLastReminderDate: DB Field value: {0}; Parsed date: {1}", LastReminderDateStr, ALastReminderDate)); } return ReturnValue; }
/// <summary> /// Stores a System Default in the DB. If it was already there it gets updated, if it wasn't there it gets added. /// </summary> /// <remarks>The change gets reflected in the System Defaults Cache the next time the System Defaults Cache /// gets accessed.</remarks> /// <param name="AKey">Name of the System Default.</param> /// <param name="AValue">Value of the System Default.</param> /// <param name="AAdded">True if the System Default got added, false if it already existed.</param> /// <remarks>SystemDefault Names are not case sensitive.</remarks> public void SetSystemDefault(String AKey, String AValue, out bool AAdded) { Boolean NewTransaction = false; Boolean ShouldCommit = false; SSystemDefaultsTable SystemDefaultsDT; try { TDBTransaction ReadWriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); SystemDefaultsDT = SSystemDefaultsAccess.LoadAll(ReadWriteTransaction); // This will find the row that matches a case-insensitive search of the table primary keys SystemDefaultsDT.CaseSensitive = false; // It is anyway SSystemDefaultsRow match = (SSystemDefaultsRow)SystemDefaultsDT.Rows.Find(AKey); if (match != null) { // I already have this System Default in the DB --> simply update the Value in the DB. // (This will often be the case!) match.DefaultValue = AValue; AAdded = false; } else { // The System Default isn't in the DB yet --> store it in the DB. var SystemDefaultsDR = SystemDefaultsDT.NewRowTyped(true); SystemDefaultsDR.DefaultCode = AKey; SystemDefaultsDR.DefaultDescription = "Created in OpenPetra"; SystemDefaultsDR.DefaultValue = AValue; SystemDefaultsDT.Rows.Add(SystemDefaultsDR); AAdded = true; } SSystemDefaultsAccess.SubmitChanges(SystemDefaultsDT, ReadWriteTransaction); ShouldCommit = true; } catch (Exception Exc) { TLogging.Log( "TSystemDefaultCache.SetSystemDefault: An Exception occured during the saving of the System Default '" + AKey + "'. Value to be saved: + '" + AValue + "'" + Environment.NewLine + Exc.ToString()); ShouldCommit = false; throw; } finally { if (NewTransaction) { if (ShouldCommit) { DBAccess.GDBAccessObj.CommitTransaction(); // We need to ensure that the next time the System Defaults Caches gets accessed it is refreshed from the DB!!! // Obtain thread-safe access to the FTableCached Field to prevent two (or more) Threads from getting a different // FTableCached value! lock (FTableCachedLockCookie) { FTableCached = false; } } else { DBAccess.GDBAccessObj.RollbackTransaction(); } } } }
/// <summary> /// Stores a System Default in the DB. If it was already there it gets updated, if it wasn't there it gets added. /// </summary> /// <remarks>The change gets reflected in the System Defaults Cache the next time the System Defaults Cache /// gets accessed.</remarks> /// <param name="AKey">Name of the System Default.</param> /// <param name="AValue">Value of the System Default.</param> /// <param name="AAdded">True if the System Default got added, false if it already existed.</param> /// <remarks>SystemDefault Names are not case sensitive.</remarks> public void SetSystemDefault(String AKey, String AValue, out bool AAdded) { TDataBase DBConnectionObj = null; TDBTransaction WriteTransaction = null; Boolean SubmissionOK = false; SSystemDefaultsTable SystemDefaultsDT; Boolean Added = false; try { // Open a separate DB Connection... DBConnectionObj = DBAccess.SimpleEstablishDBConnection("SetSystemDefault"); // ...and start a DB Transaction on that separate DB Connection DBConnectionObj.BeginAutoTransaction(IsolationLevel.ReadCommitted, ref WriteTransaction, ref SubmissionOK, "SetSystemDefault", delegate { SystemDefaultsDT = SSystemDefaultsAccess.LoadAll(WriteTransaction); // This will find the row that matches a case-insensitive search of the table primary keys SystemDefaultsDT.CaseSensitive = false; // It is anyway SSystemDefaultsRow match = (SSystemDefaultsRow)SystemDefaultsDT.Rows.Find(AKey); if (match != null) { // I already have this System Default in the DB --> simply update the Value in the DB. // (This will often be the case!) match.DefaultValue = AValue; Added = false; } else { // The System Default isn't in the DB yet --> store it in the DB. var SystemDefaultsDR = SystemDefaultsDT.NewRowTyped(true); SystemDefaultsDR.DefaultCode = AKey; SystemDefaultsDR.DefaultDescription = "Created in OpenPetra"; SystemDefaultsDR.DefaultValue = AValue; SystemDefaultsDT.Rows.Add(SystemDefaultsDR); Added = true; } SSystemDefaultsAccess.SubmitChanges(SystemDefaultsDT, WriteTransaction); SubmissionOK = true; }); AAdded = Added; } catch (Exception Exc) { TLogging.Log( "TSystemDefaultCache.SetSystemDefault: An Exception occured during the saving of the System Default '" + AKey + "'. Value to be saved: + '" + AValue + "'" + Environment.NewLine + Exc.ToString()); throw; } finally { if (SubmissionOK) { // We need to ensure that the next time the System Defaults Caches gets accessed it is refreshed from the DB!!! // Obtain thread-safe access to the FTableCached Field to prevent two (or more) Threads from getting a different // FTableCached value! lock (FTableCachedLockCookie) { FTableCached = false; } } if (DBConnectionObj != null) { DBConnectionObj.CloseDBConnection(); } } }
/// <summary> /// Stores a System Default in the DB. If it was already there it gets updated, if it wasn't there it gets added. /// </summary> /// <remarks>The change gets reflected in the System Defaults Cache the next time the System Defaults Cache /// gets accessed.</remarks> /// <param name="AKey">Name of the System Default.</param> /// <param name="AValue">Value of the System Default.</param> /// <param name="AAdded">True if the System Default got added, false if it already existed.</param> /// <param name="ADataBase"></param> /// <remarks>SystemDefault Names are not case sensitive.</remarks> public void SetSystemDefault(String AKey, String AValue, out bool AAdded, TDataBase ADataBase = null) { TDataBase DBConnectionObj = null; TDBTransaction WriteTransaction = new TDBTransaction(); bool SubmissionOK = false; SSystemDefaultsTable SystemDefaultsDT; Boolean Added = false; try { // Open a separate DB Connection... DBConnectionObj = DBAccess.Connect("SetSystemDefault", ADataBase); // ...and start a DB Transaction on that separate DB Connection DBConnectionObj.WriteTransaction(ref WriteTransaction, ref SubmissionOK, delegate { SystemDefaultsDT = SSystemDefaultsAccess.LoadAll(WriteTransaction); // This will find the row that matches a case-insensitive search of the table primary keys SystemDefaultsDT.CaseSensitive = false; // It is anyway SSystemDefaultsRow match = (SSystemDefaultsRow)SystemDefaultsDT.Rows.Find(AKey); if (match != null) { // I already have this System Default in the DB --> simply update the Value in the DB. // (This will often be the case!) match.DefaultValue = AValue; Added = false; } else { // The System Default isn't in the DB yet --> store it in the DB. var SystemDefaultsDR = SystemDefaultsDT.NewRowTyped(true); SystemDefaultsDR.DefaultCode = AKey; SystemDefaultsDR.DefaultDescription = "Created in OpenPetra"; SystemDefaultsDR.DefaultValue = AValue; SystemDefaultsDT.Rows.Add(SystemDefaultsDR); Added = true; } SSystemDefaultsAccess.SubmitChanges(SystemDefaultsDT, WriteTransaction); SubmissionOK = true; }); AAdded = Added; } catch (Exception Exc) { TLogging.Log( "TSystemDefaultCache.SetSystemDefault: An Exception occured during the saving of the System Default '" + AKey + "'. Value to be saved: + '" + AValue + "'" + Environment.NewLine + Exc.ToString()); throw; } finally { if (ADataBase == null) { DBConnectionObj.CloseDBConnection(); } if (SubmissionOK && (FSystemDefaultsDT != null)) { // We need to ensure that the next time the System Defaults Caches gets accessed it is refreshed from the DB!!! FSystemDefaultsDT.Clear(); FSystemDefaultsDT = null; } } }