}//END GetParameters class // ===================================================================================== /// <summary> /// This class sets the query parameter values. /// </summary> /// <param name="parms">SqlParameter: Database parameters</param> /// <param name="Item">EvDataChange: Change data object</param> /// <remarks> /// This method consists of the following steps: /// /// 1. Set Guid and Record Guid if they are not set /// /// 2. Load the SQL query parameter from the datachange object. /// </remarks> // ------------------------------------------------------------------------------------- private void setParameters(SqlParameter [] parms, EvDataChange Item) { // // Set the Guid if it is not set. // if (Item.Guid == Guid.Empty) { Item.Guid = Guid.NewGuid( ); } // // Set the RecordGuid if it is not set. // if (Item.RecordGuid == Guid.Empty) { Item.RecordGuid = Guid.NewGuid( ); } // // Load the Sql Parameters // parms [0].Value = Item.Guid; parms [1].Value = Item.RecordGuid; parms [2].Value = 0; parms [2].Value = Item.RecordUid; parms [3].Value = Item.TableName.ToString( ); parms [4].Value = this.encryptData(Item); parms [5].Value = Item.UserId; parms [6].Value = Item.DateStamp; }//END setUpdateChangeParameters.
}//END setUpdateChangeParameters. // +++++++++++++++++++++++++ END QUERY PARAMETERS SECTION ++++++++++++++++++++++++++++++ #endregion #region data change reader // ===================================================================================== /// <summary> /// This class reads the content of the data reader object into Change business object. /// </summary> /// <param name="Row">DataRow: a data row object</param> /// <returns>EvDataChange: a data change object</returns> /// <remarks> /// This method consists of the following steps: /// /// 1. Extract the data row values to the data change object. /// /// 2. Encrypt the data change if it is not encrypted. /// /// 3. Return the data change object. /// </remarks> // ------------------------------------------------------------------------------------- private EvDataChange getRowData(DataRow Row) { // // Initialise the data change object // EvDataChange dataChange = new EvDataChange( ); // // Extract the data row values to the data change object. // dataChange.Guid = EvSqlMethods.getGuid(Row, "DC_Guid"); dataChange.RecordGuid = EvSqlMethods.getGuid(Row, "DC_RecordGuid"); dataChange.Uid = EvSqlMethods.getLong(Row, "DC_Uid"); dataChange.RecordUid = EvSqlMethods.getLong(Row, "DC_RecordUid"); dataChange.TableName = Evado.Model.EvStatics.parseEnumValue <EvDataChange.DataChangeTableNames> ( EvSqlMethods.getString(Row, "DC_TableName")); string encrypted = EvSqlMethods.getString(Row, "DC_DataChange"); dataChange.UserId = EvSqlMethods.getString(Row, "DC_UserId"); dataChange.DateStamp = EvSqlMethods.getDateTime(Row, "DC_DateStamp"); // // Check that the encrypted string exists. // if (encrypted != String.Empty) { dataChange = this.decryptData(encrypted, dataChange.Guid); // // Check that items exist. // if (dataChange != null) { // // If the data change items exist process them. // if (dataChange.Items.Count > 0) { // // Iterate through the data change items updating the html coding // for (int count = 0; count < dataChange.Items.Count; count++) { dataChange.Items [count].InitialValue = dataChange.Items [count].InitialValue.Replace("&gt;", "&gt; "); dataChange.Items [count].NewValue = dataChange.Items [count].NewValue.Replace("&gt;", "&gt; "); } //END iterate through the item values correcting html coding. } //END data change items exist. } //END items exit } //END encrypted date exists // // Return the newField . // return(dataChange); }//END getRowData method.
}//END getItemById method. #endregion #region AdapterConfig Update queries // ===================================================================================== /// <summary> /// This method updates items to the SiteProfile data table. /// </summary> /// <param name="AdapterParameters">EvSiteProfile: A site Profile data object.</param> /// <returns>EvEventCodes: an event code for updating items.</returns> /// <remarks> /// This method consists of following steps. /// /// 1. Add items to datachange object if they do not exist in Old SiteProfile object. /// /// 2. Define the sql query parameters and execute the storeprocedure for updating items /// /// 3. Exit, if the storeprocedure runs fail. /// /// 4. Add datachange object's values to the backup datachanges object. /// /// 5. Else, return an event code for updating items. /// </remarks> // ------------------------------------------------------------------------------------ public EvEventCodes updateItem(Evado.Digital.Model.EdAdapterSettings AdapterParameters) { this.LogMethod("updateItem method "); // // Create the data change object. // EvDataChanges dataChanges = new EvDataChanges( ); EvDataChange dataChange = this.createDataChange(AdapterParameters); /* * foreach ( EvObjectParameter prm in ApplicationSettings.Parameters ) * { * this.LogDebug ( "Name: {0}, Value: {1}", prm.Name, prm.Value ); * } */ // // Define the SQL query parameters and load the query values. // SqlParameter [] cmdParms = GetParameters( ); SetParameters(cmdParms, AdapterParameters); try { // // Execute the update command. // if (EvSqlMethods.StoreProcUpdate(SQL_PROCEDURE_UPDATE, cmdParms) == 0) { return(EvEventCodes.Database_Record_Update_Error); } // // Add the data change object if items have changed. // if (dataChange.Items.Count > 0) { dataChanges.AddItem(dataChange); } } catch (Exception ex) { this.LogValue(Evado.Digital.Model.EvcStatics.getException(ex)); } // // Save the application parameters. // this.UpdateObjectParameters(AdapterParameters.Parameters, AdapterParameters.Guid); // // Return an enumerated value EventCode status. // this.LogMethodEnd("updateItem"); return(EvEventCodes.Ok); } //END updateItem method.
}//END AddItem class. #endregion #region Data encryption methods // ===================================================================================== /// <summary> /// This method serialises and encrypts the data change object. /// </summary> /// <param name="DataChange">EvDataChange: data change object</param> /// <returns>string: an Encrypted string</returns> /// <remarks> /// This method consists of the following steps: /// /// 1. Serialize the datachange object to xml datachange string. /// /// 2. Check whether the Guid of datachange object exists. /// /// 3. Initialize the encrypt object and encrypt xml datachange string to the encrypted /// datachange string. /// /// 4. Return the encrypted datachange string. /// </remarks> // ------------------------------------------------------------------------------------- public string encryptData(EvDataChange DataChange) { // // Initialise the method status, an xml data change string and an encrypted data chagne string. // this.LogMethod("encryptData method. "); this.LogDebug("SiteGuid: " + EvDataChanges._SiteGuid); this.LogDebug("DataChange.Guid: " + DataChange.Guid); string xmlDataChange = String.Empty; string encryptedDataChange = String.Empty; // // serialise the datachange object. // xmlDataChange = Evado.Digital.Model.EvcStatics.SerialiseObject <EvDataChange> (DataChange); // // Check whether the Guid exists. // if (EvDataChanges._SiteGuid == Guid.Empty || DataChange.Guid == Guid.Empty) { return(xmlDataChange); } xmlDataChange = xmlDataChange.Replace("\r\n", string.Empty); xmlDataChange = xmlDataChange.Replace("> ", ">"); xmlDataChange = xmlDataChange.Replace("> ", ">"); xmlDataChange = xmlDataChange.Replace("> ", ">"); xmlDataChange = xmlDataChange.Replace("> ", ">"); xmlDataChange = xmlDataChange.Replace(" <", "<"); xmlDataChange = xmlDataChange.Replace(" <", "<"); xmlDataChange = xmlDataChange.Replace(" <", "<"); xmlDataChange = xmlDataChange.Replace(" <", "<"); //this.LogDebug( "xmlDataChange: {{" + xmlDataChange + "}}" ); //return xmlDataChange; // // Initialise the encryption object. // EvEncrypt encrypt = new EvEncrypt(EvDataChanges._SiteGuid, DataChange.Guid); // // Encrypt the data change xml object. // encryptedDataChange = encrypt.encryptString(xmlDataChange); this.LogClass(encrypt.Log); // // Return the encrypted string. // return(encryptedDataChange); }//END encrypt Data method.
} //END addItem method. // ===================================================================================== /// <summary> /// This method updates items to Subject Record data table. /// </summary> /// <param name="AncillaryRecord">EvAncillaryRecord: An ancillary record object object.</param> /// <returns>EvEventCodes: An event code for updating items</returns> /// <remarks> /// This method consists of following steps: /// /// 1. Exit, if the VisitId or SubjectId is empty. /// /// 2. Add items to datachange object, if they do not exist on the old milestone record object. /// /// 3. Define the sql query parameters and execute the storeprocedure for updating items. /// /// 4. Exit, if the storeprocedure runs fail. /// /// 5. Add the datachange object's values to the backup datachanges object. /// /// 6. Return an event code for updating items. /// </remarks> // ---------------------------------------------------------------------------------- public EvEventCodes updateItem(EvAncillaryRecord AncillaryRecord) { this.LogMethod("updateItem."); this.LogValue("RecordId: " + AncillaryRecord.RecordId); this.LogValue("ProjectId: " + AncillaryRecord.ProjectId); this.LogValue("SubjectId: " + AncillaryRecord.SubjectId); this.LogValue("State: " + AncillaryRecord.State); // // Initialise the methods variables and objects. // EvDataChanges dataChanges = new EvDataChanges( ); // // Get an existing object to verify the record exists. // EvAncillaryRecord oldItem = getRecord(AncillaryRecord.Guid); if (oldItem.Guid == Guid.Empty) { return(EvEventCodes.Data_InvalidId_Error); } // // Compare the objects. // EvDataChange dataChange = SetDataChange(AncillaryRecord); // // Define the SQL query parameters and load the query values. // SqlParameter [] _cmdParms = GetParameters( ); SetParameters(_cmdParms, AncillaryRecord); // // Execute the update command. // if (EvSqlMethods.StoreProcUpdate(_STORED_PROCEDURE_UpdateItem, _cmdParms) == 0) { return(EvEventCodes.Database_Record_Update_Error); } // // Add the data change to the database. // dataChanges.AddItem(dataChange); // // Return an enumerated value EventCode status. // return(EvEventCodes.Ok); }//END updateItem method.
} // Close GetView method. // ++++++++++++++++++++++++++++++ END VIEW QUERY SECTION +++++++++++++++++++++++++++++++ #endregion #region DataChange Update queries // ===================================================================================== /// <summary> /// This class adds a data change object to the database. /// </summary> /// <param name="DataChange">EvDataChange: a datachange object</param> /// <returns>EvEventCodes: an event code for adding items to data change table.</returns> /// <remarks> /// This method consists of the following steps: /// /// 1. Loop through the datachange object items and validate whether the items are not empty /// /// 2. Define the sql query parameters /// /// 3. Execute the storeprocedure for adding new items to datachange table. /// /// 4. Return the event code for adding items. /// </remarks> // ------------------------------------------------------------------------------------- public EvEventCodes AddItem(EvDataChange DataChange) { // // Initialize the method status and a no-items variable // this.LogMethod("addItem method."); this.LogDebug("ProjectId: " + DataChange.TrialId); this.LogDebug("TypeId: " + DataChange.TableName); this.LogDebug("UserId: " + DataChange.UserId); this.LogDebug("DataChange.Items.Count count: " + DataChange.Items.Count); bool NoItems = true; // // Loop through the datachange object and validate whether the items are not empty. // foreach (EvDataChangeItem item in DataChange.Items) { if (item.ItemId != String.Empty) { NoItems = false; } }//END Foreach interation loop. // // IF not newField then exit without saving. // if (NoItems == true) { this.LogDebug(" No Items found."); return(EvEventCodes.Ok); } // // Define the SQL query parameters and load the query values. // SqlParameter [] _cmdParms = GetParameters( ); setParameters(_cmdParms, DataChange); // // Execute the update command. // if (EvSqlMethods.StoreProcUpdate(_STORED_PROCEDURE_AddItem, _cmdParms) == 0) { return(EvEventCodes.Database_Record_Update_Error); } return(EvEventCodes.Ok); }//END AddItem class.
}//END getRecord method #endregion #region Ancilliary Record Update queries // ===================================================================================== /// <summary> /// This method adds items to the Subject Record data table. /// </summary> /// <param name="AncillaryRecord">EvSubjectRecord: A Subject Record object</param> /// <returns>EvEventCodes: An event code for adding items</returns> /// <remarks> /// This method consists of follwoing steps: /// /// 1. Create new DB row Guid, if it is empty. /// /// 2. Define the sql query parameters and execute the storeprocedure for adding items. /// /// 3. Exit, if the storeprocedure runs fail. /// /// 4. Return an event code for adding items. /// </remarks> // ---------------------------------------------------------------------------------- public EvEventCodes addItem(EvAncillaryRecord AncillaryRecord) { this.LogMethod("addItem."); this.LogValue("RecordId: " + AncillaryRecord.RecordId); this.LogValue("ProjectId: " + AncillaryRecord.ProjectId); this.LogValue("SubjectId: " + AncillaryRecord.SubjectId); // // Initialise the methods variables and objects. // EvDataChanges dataChanges = new EvDataChanges( ); Guid newGuid = Guid.NewGuid( ); AncillaryRecord.RecordId = String.Empty; // // If the SubjectRecord Guid is empty then create a new Guid. // if (AncillaryRecord.Guid == Guid.Empty) { AncillaryRecord.Guid = newGuid; } // // Compare the objects. // EvDataChange dataChange = SetDataChange(AncillaryRecord); // // Define the SQL query parameters and load the query values. // SqlParameter [] _cmdParms = GetParameters( ); SetParameters(_cmdParms, AncillaryRecord); // // Execute the update command. // if (EvSqlMethods.StoreProcUpdate(_STORED_PROCEDURE_AddItem, _cmdParms) == 0) { return(EvEventCodes.Database_Record_Update_Error); } // // Return an enumerated value EventCode status. // return(EvEventCodes.Ok); } //END addItem method.
}//END GetFormFieldList class #endregion // ================================================ /// <summary> /// This class adds a data change object to the database. /// </summary> /// <param name="DataChange">EvDataChange: a datachange object</param> /// <returns>EvEventCodes: an event code for adding items to data change table.</returns> // ------------------------------------------------------------------------------------- public EvEventCodes AddItem(EvDataChange DataChange) { // // Initialize the method status and a no-items variable // this._DebugLog.AppendLine(Evado.Model.EvStatics.CONST_METHOD_START + " Evado.Digital.Dal.DataChanges.addItem method."); this._DebugLog.AppendLine("ProjectId: " + DataChange.TrialId); this._DebugLog.AppendLine("TypeId: " + DataChange.TableName); this._DebugLog.AppendLine("UserId: " + DataChange.UserId); this._DebugLog.AppendLine("DataChange.Items.Count count: " + DataChange.Items.Count); EvEventCodes result = EvEventCodes.Ok; result = this._dalChanges.AddItem(DataChange); this._DebugLog.AppendLine(this._dalChanges.Log); return(result); }
}//END EvFormFieldSelectionList method #endregion #region SelectionList Update queries // ===================================================================================== /// <summary> /// This class updates items on formfield selection list table. /// </summary> /// <param name="Item">EvFormFieldSelectionList: a formfield selection list object</param> /// <returns>EvEventCodes: an event code for updating items</returns> /// <remarks> /// This method consists of the following steps: /// /// 1. Exit, if the Old list's Guid is empty. /// /// 2. Add items to datachange object if they exist after comparing with the old list. /// /// 3. Define the sql parameters and execute the storeprocedure for updating items. /// /// 4. Add the datachange values to the backup datachanges object. /// /// 5. Return the event code for updating the items. /// </remarks> // ------------------------------------------------------------------------------------- public EvEventCodes updateItem(EdPageLayout Item) { this.LogMethod("updateItem"); // // Get the previous value // EdPageLayout oldItem = getItem(Item.Guid); if (oldItem.Guid == Guid.Empty) { return(EvEventCodes.Identifier_Global_Unique_Identifier_Error); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Compare the objects. // EvDataChanges dataChanges = new EvDataChanges( ); EvDataChange dataChange = new EvDataChange( ); dataChange.TableName = EvDataChange.DataChangeTableNames.EdPageLayouts; dataChange.TrialId = String.Empty; dataChange.RecordUid = -1; dataChange.RecordGuid = Item.Guid; dataChange.UserId = Item.UpdatedByUserId; dataChange.DateStamp = DateTime.Now; // // Add items to datachange object if they exist. // if (Item.PageId != oldItem.PageId) { dataChange.AddItem("ListId", oldItem.PageId, Item.PageId); } if (Item.Title != oldItem.Title) { dataChange.AddItem("Title", oldItem.Title, Item.Title); } if (Item.UserTypes != oldItem.UserTypes) { dataChange.AddItem("UserType", oldItem.UserTypes, Item.UserTypes); } if (Item.State != oldItem.State) { dataChange.AddItem("State", oldItem.State, Item.State); } if (Item.HeaderContent != oldItem.HeaderContent) { dataChange.AddItem("HeaderContent", Item.HeaderContent, Item.HeaderContent); } if (Item.HeaderComponentList != oldItem.HeaderComponentList) { dataChange.AddItem("HeaderGroupList", oldItem.HeaderComponentList, Item.HeaderComponentList); } if (Item.LeftColumnContent != oldItem.LeftColumnContent) { dataChange.AddItem("LeftColumnContent", oldItem.LeftColumnContent, Item.LeftColumnContent); } if (Item.LeftColumnComponentList != oldItem.LeftColumnComponentList) { dataChange.AddItem("LeftColumnGroupList", oldItem.LeftColumnComponentList, Item.LeftColumnComponentList); } if (Item.LeftColumnWidth != oldItem.LeftColumnWidth) { dataChange.AddItem("LeftColumnCommandList", oldItem.LeftColumnWidth, Item.LeftColumnWidth); } if (Item.CenterColumnContent != oldItem.CenterColumnContent) { dataChange.AddItem("CenterColumnContent", oldItem.CenterColumnContent, Item.CenterColumnContent); } if (Item.LeftColumnComponentList != oldItem.LeftColumnComponentList) { dataChange.AddItem("LeftColumnGroupList", oldItem.LeftColumnComponentList, Item.LeftColumnComponentList); } if (Item.RightColumnContent != oldItem.RightColumnContent) { dataChange.AddItem("RightColumnContent", oldItem.RightColumnContent, Item.RightColumnContent); } if (Item.RightColumnComponentList != oldItem.RightColumnComponentList) { dataChange.AddItem("RightColumnGroupList", oldItem.RightColumnComponentList, Item.RightColumnComponentList); } if (Item.RightColumnWidth != oldItem.RightColumnWidth) { dataChange.AddItem("RightColumnCommandList", oldItem.RightColumnWidth, Item.RightColumnWidth); } if (Item.Version != oldItem.Version) { dataChange.AddItem("Version", oldItem.Version, Item.Version); } if (Item.State != oldItem.State) { dataChange.AddItem("State", oldItem.State.ToString( ), Item.State.ToString( )); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Define the query parameters // SqlParameter [] commandParameters = GetParameters( ); SetParameters(commandParameters, Item); // // Execute the update command. // if (EvSqlMethods.StoreProcUpdate(_STORED_PROCEDURE_UpdateItem, commandParameters) == 0) { return(EvEventCodes.Database_Record_Update_Error); } // // update the parameter object values. // this.UpdateObjectParameters(Item.Parameters, Item.Guid); // // Add the change record // dataChanges.AddItem(dataChange); return(EvEventCodes.Ok); }//END updateItem class
} //END updateItem method. //=================================================================================== /// <summary> /// This method creates the data change object. /// /// </summary> /// <param name="ApplicationProperties">EvApplicationProfile Object.</param> /// <returns>EvDataChange</returns> //----------------------------------------------------------------------------------- private EvDataChange createDataChange(Evado.Digital.Model.EdAdapterSettings ApplicationProperties) { // // Initialise the methods variables and objects. // EvDataChange dataChange = new EvDataChange( ); // // Get an item to be updated. // Evado.Digital.Model.EdAdapterSettings oldItem = this.getItem(ApplicationProperties.ApplicationId); // // Compare the changes. // EvDataChanges dataChanges = new EvDataChanges( ); dataChange.TableName = EvDataChange.DataChangeTableNames.EdAdapterSettings; dataChange.RecordUid = 1; dataChange.RecordGuid = ApplicationProperties.Guid; dataChange.UserId = this.ClassParameters.UserProfile.UserId; dataChange.DateStamp = DateTime.Now; // // Add new items to datachanges if they do not exist in the Old Site Profile object. // if (ApplicationProperties.ApplicationId != oldItem.ApplicationId) { dataChange.AddItem("Id", oldItem.ApplicationId, ApplicationProperties.ApplicationId); } // // Add new items to datachanges if they do not exist in the Old Site Profile object. // dataChange.AddItem("MaximumSelectionListLength", oldItem.MaximumSelectionListLength, ApplicationProperties.MaximumSelectionListLength); dataChange.AddItem("SmtpServer", oldItem.SmtpServer, ApplicationProperties.SmtpServer); dataChange.AddItem("SmtpServerPort", oldItem.SmtpServerPort, ApplicationProperties.SmtpServerPort); dataChange.AddItem("SmtpUserId", oldItem.SmtpUserId, ApplicationProperties.SmtpUserId); dataChange.AddItem("EmailAlertTestAddress", oldItem.EmailAlertTestAddress, ApplicationProperties.EmailAlertTestAddress); // // Iterate through the parameters creating change object for each item. // for (int i = 0; i < ApplicationProperties.Parameters.Count; i++) { EvObjectParameter newParameter = ApplicationProperties.Parameters [i]; // // Skip the non selected forms // if (newParameter == null) { continue; } EvObjectParameter oldParameter = getParameter(oldItem.Parameters, newParameter.Name); if (oldParameter == null) { dataChange.AddItem("APP_" + newParameter.Name, String.Empty, newParameter.Value); } else { dataChange.AddItem("APP_" + newParameter.Name, oldParameter.Value, newParameter.Value); } }//END form list iteration loop. return(dataChange); }
}//END getItem method #endregion #region Update Organisation. // ===================================================================================== /// <summary> /// This class updates items to the organization data object. /// </summary> /// <param name="Organisation">EvOrganisation: an Organisation object</param> /// <returns>EvEventCodes: an event code for updating result</returns> /// <remarks> /// This method consists of the following steps: /// /// 1. Exit, if the Old Organization's Guid is empty or the New Organization's identfier is duplicated. /// /// 2. Create new orgnization's Guid if it is empty. /// /// 3. Add new items to datachange object if they do not exist. /// /// 4. Define the sql query parameters and execute the storeprocedure for updating /// /// 5. Add datachange object values to the backup datachanges object. /// /// 6. Return an event code for updating items. /// </remarks> // ------------------------------------------------------------------------------------- public EvEventCodes updateItem ( EdOrganisation Organisation ) { // // Initialize the method status and an old organization object // this.LogMethod ( "updateItem method." ); this.LogDebug ( "OrgId: " + Organisation.OrgId ); EdOrganisation oldOrg = getItem ( Organisation.Guid ); // // Validate whether the Old organization exists. // if ( oldOrg.Guid == Guid.Empty ) { this.LogDebug ( " Invalid Guid not object found." ); return EvEventCodes.Data_InvalidId_Error; } // // Validate whether the new Organization Identifier is unique. // if ( oldOrg.OrgId != Organisation.OrgId ) { EdOrganisation newOrg = getItem ( Organisation.OrgId ); if ( newOrg.Guid != Guid.Empty ) { this.LogDebug ( " DuplicateId error" ); return EvEventCodes.Data_Duplicate_Id_Error; } } // // If the guid is null create a new guid. // if ( Organisation.Guid == Guid.Empty ) { this.LogDebug ( " Creating a new GUID." ); Organisation.Guid = Guid.NewGuid ( ); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Compare the objects. // Initialize the datachange object and a backup datachanges object // EvDataChanges dataChanges = new EvDataChanges ( ); EvDataChange dataChange = new EvDataChange ( ); dataChange.TableName = EvDataChange.DataChangeTableNames.EvOrganisations; dataChange.RecordGuid = Organisation.Guid; dataChange.UserId = Organisation.UpdatedByUserId; dataChange.DateStamp = DateTime.Now; // // Add new items to the datachange object if they do not exist. // if ( Organisation.Name != oldOrg.Name ) { dataChange.AddItem ( "Name", oldOrg.Name, Organisation.Name ); } if ( Organisation.AddressStreet_1 != oldOrg.AddressStreet_1 ) { dataChange.AddItem ( "Address_1", oldOrg.AddressStreet_1, Organisation.AddressStreet_1 ); } if ( Organisation.AddressStreet_2 != oldOrg.AddressStreet_2 ) { dataChange.AddItem ( "AddressStreet_2", oldOrg.AddressStreet_2, Organisation.AddressStreet_2 ); } if ( Organisation.AddressCity != oldOrg.AddressCity ) { dataChange.AddItem ( "AddressCity", oldOrg.AddressCity, Organisation.AddressCity ); } if ( Organisation.AddressState != oldOrg.AddressState ) { dataChange.AddItem ( "AddressState", oldOrg.AddressState, Organisation.AddressState ); } if ( Organisation.AddressPostCode != oldOrg.AddressPostCode ) { dataChange.AddItem ( "AddressPostCode", oldOrg.AddressPostCode, Organisation.AddressPostCode ); } if ( Organisation.AddressCountry != oldOrg.AddressCountry ) { dataChange.AddItem ( "AddressCountry", oldOrg.AddressCountry, Organisation.AddressCountry ); } if ( Organisation.Telephone != oldOrg.Telephone ) { dataChange.AddItem ( "Telephone", oldOrg.Telephone, Organisation.Telephone ); } if ( Organisation.EmailAddress != oldOrg.EmailAddress ) { dataChange.AddItem ( "EmailAddress", oldOrg.EmailAddress, Organisation.EmailAddress ); } if ( Organisation.OrgType != oldOrg.OrgType ) { dataChange.AddItem ( "OrgType", oldOrg.OrgType.ToString ( ), Organisation.OrgType.ToString ( ) ); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Define the query parameters // this.LogDebug ( " Setting Parameters." ); SqlParameter [ ] cmdParms = GetParameters ( ); SetParameters ( cmdParms, Organisation ); // // Execute the update command. // if ( EvSqlMethods.StoreProcUpdate ( EdOrganisations.STORED_PROCEDURE_UPDATE_ITEM, cmdParms ) == 0 ) { return EvEventCodes.Database_Record_Update_Error; } // // Save the datachanges to the database. // dataChanges.AddItem ( dataChange ); this.LogDebug ( "DataChange: " + dataChanges.Log ); return EvEventCodes.Ok; }//END updateItem method
}//END updateItem method. // ===================================================================================== /// <summary> /// This method sets the data change values for the object and returns the data change /// object. /// </summary> /// <param name="AncillaryRecord">EvSubjectRecord: A Subject Record object.</param> /// <returns>EvDataChange: A DataChange object.</returns> /// <remarks> /// This method consists of following steps. /// /// 1. Add items to datachange object if they do not exist on the old Subject Record object. /// /// 2. Return the datachange object. /// </remarks> // ---------------------------------------------------------------------------------- private EvDataChange SetDataChange(EvAncillaryRecord AncillaryRecord) { // // Initialise the methods variables and objects. // EvDataChange dataChange = new EvDataChange( ); // // Retrieve the existing record object for comparision // EvAncillaryRecord oldRecord = this.getRecord(AncillaryRecord.Guid); // // Set the chanage objects values. // dataChange.TableName = EvDataChange.DataChangeTableNames.EvAncilliaryRecords; dataChange.RecordGuid = AncillaryRecord.Guid; dataChange.TrialId = AncillaryRecord.ProjectId; dataChange.SubjectId = AncillaryRecord.SubjectId; dataChange.RecordId = AncillaryRecord.RecordId; dataChange.UserId = AncillaryRecord.UpdatedByUserId; dataChange.DateStamp = DateTime.Now; dataChange.RecordGuid = AncillaryRecord.Guid; // // Add items to datachange object, if they do not exist on the old SubjectRecord object. // if (AncillaryRecord.ProjectId != oldRecord.ProjectId) { dataChange.AddItem("TrialId", oldRecord.ProjectId, AncillaryRecord.ProjectId); } if (AncillaryRecord.SubjectId != oldRecord.SubjectId) { dataChange.AddItem("SubjectId", oldRecord.SubjectId, AncillaryRecord.SubjectId); } if (AncillaryRecord.RecordId != oldRecord.RecordId) { dataChange.AddItem("RecordId", oldRecord.RecordId, AncillaryRecord.RecordId); } if (AncillaryRecord.Subject != oldRecord.Subject) { dataChange.AddItem("Subject", oldRecord.Subject, AncillaryRecord.Subject); } if (AncillaryRecord.Record != oldRecord.Record) { dataChange.AddItem("Record", oldRecord.Record, AncillaryRecord.Record); } if (AncillaryRecord.BinaryLength != oldRecord.BinaryLength) { dataChange.AddItem("BinaryLength", oldRecord.BinaryLength.ToString( ), AncillaryRecord.BinaryLength.ToString( )); } if (AncillaryRecord.BinaryType != oldRecord.BinaryType) { dataChange.AddItem("BinaryType", oldRecord.BinaryType, AncillaryRecord.BinaryType); } if (AncillaryRecord.Researcher != oldRecord.Researcher) { dataChange.AddItem("Researcher", oldRecord.Researcher, AncillaryRecord.Researcher); } if (AncillaryRecord.ResearcherUserId != oldRecord.ResearcherUserId) { dataChange.AddItem("ResearcherUserId", oldRecord.ResearcherUserId, AncillaryRecord.ResearcherUserId); } if (AncillaryRecord.ResearcherDate != oldRecord.ResearcherDate) { dataChange.AddItem("ResearcherDate", oldRecord.ResearcherDate.ToString("yyyy MMM dd HH:mm:ss"), AncillaryRecord.ResearcherDate.ToString("yyyy MMM dd HH:mm:ss")); } if (AncillaryRecord.Reviewer != oldRecord.Reviewer) { dataChange.AddItem("Reviewer", oldRecord.Reviewer, AncillaryRecord.Reviewer); } if (AncillaryRecord.ReviewerUserId != oldRecord.ReviewerUserId) { dataChange.AddItem("ReviewerUserId", oldRecord.ReviewerUserId, AncillaryRecord.ReviewerUserId); } if (AncillaryRecord.ReviewDate != oldRecord.ReviewDate) { dataChange.AddItem("ReviewDate", oldRecord.ReviewDate.ToString("yyyy MMM dd HH:mm:ss"), AncillaryRecord.ReviewDate.ToString("yyyy MMM dd HH:mm:ss")); } if (AncillaryRecord.Approver != oldRecord.Approver) { dataChange.AddItem("Approver", oldRecord.Approver, AncillaryRecord.Approver); } if (AncillaryRecord.ApproverUserId != oldRecord.ApproverUserId) { dataChange.AddItem("ApproverUserId", oldRecord.ApproverUserId, AncillaryRecord.ApproverUserId); } if (AncillaryRecord.ApprovalDate != oldRecord.ApprovalDate) { dataChange.AddItem("ApprovalDate", oldRecord.ApprovalDate.ToString("yyyy MMM dd HH:mm:ss"), AncillaryRecord.ApprovalDate.ToString("yyyy MMM dd HH:mm:ss")); } // // Return the data change object containing an EvDataChange object. // return(dataChange); }//END SetDataChange method
}//END encrypt Data method. // ===================================================================================== /// <summary> /// This method decrypts the data change object. /// </summary> /// <param name="encryptedData">string: The encrypted data string</param> /// <param name="ItemGuid">Guid: The item Guid</param> /// <returns>EvDataChange: a datachange object</returns> /// <remarks> /// This method consists of the following steps: /// /// 1. Try if encrypted data string exists, deserialize encrypted string to the return datachange object /// /// 2. if not, decrypt the encrypted string to xml datachange string. /// /// 3. Deserialize xml datachange string to the datachange object. /// /// 4. Return the datachange object. /// /// 5. catch - write error message to log and return new datachange object. /// /// </remarks> // ------------------------------------------------------------------------------------- private EvDataChange decryptData(string encryptedData, Guid ItemGuid) { // // Initialise the method status, a return datachange object and an xml datachange string. // this.LogMethod("decryptData method. "); this.LogDebug("encryptedData length: " + encryptedData.Length); this.LogDebug("SiteGuid: " + EvDataChanges._SiteGuid); this.LogDebug("ItemGuid: " + ItemGuid); EvDataChange dataChange = new EvDataChange( ); string xmlDataChange = String.Empty; try { // // Check that whether the change is encrypted. // if (encryptedData.Contains("<EvDataChange xmlns") == true) { this.LogDebug(" Unencrypted audit trail. "); // // deserialise the xml object. // dataChange = Evado.Digital.Model.EvcStatics.DeserialiseObject <EvDataChange> (encryptedData); // // if default reinitialise. // if (dataChange == default(EvDataChange)) { dataChange = new EvDataChange( ); } // // Return the encrypted string. // return(dataChange); } this.LogDebug(" Encrypted audit trail. "); // // Check that we have Guid keys. // if (EvDataChanges._SiteGuid != Guid.Empty && ItemGuid != Guid.Empty) { // // Initialise the encryption object. // EvEncrypt encrypt = new EvEncrypt(EvDataChanges._SiteGuid, ItemGuid); // // Encrypt the data change xml object. // xmlDataChange = encrypt.decryptString(encryptedData); this.LogClass(encrypt.Log); }//END decrypting the data change object. this.LogDebug(" xmlDataChange length: " + xmlDataChange.Length); // // Deserialise the datachange object. // dataChange = Evado.Digital.Model.EvcStatics.DeserialiseObject <EvDataChange> (xmlDataChange); // // if default reinitialise. // if (dataChange == default(EvDataChange)) { dataChange = new EvDataChange( ); } } catch (Exception Ex) { string eventMessage = "Decrypting Error. " + "\r\n Exception: \r\n" + Evado.Digital.Model.EvcStatics.getException(Ex); this.LogClass(eventMessage); Evado.Digital.Model.EvcStatics.WriteToEventLog(_eventLogSource, eventMessage, EventLogEntryType.Error); dataChange = new EvDataChange( ); } // // Return the encrypted string. // return(dataChange); }//END decryptData method.
}//END getRowData method. // +++++++++++++++++++++++++++ END RECORD READER SECTION ++++++++++++++++++++++++++++++ #endregion #region DataChange Queries // ===================================================================================== /// <summary> /// This method queries the data changes for a record. /// </summary> /// <param name="RecordGuid">Guid: (Mandatory) Record global Unique identifier.</param> /// <param name="TableName">EvDataChange.DataChangeTableNames: (Mandatory) table name.</param> /// <returns>List of EvDataChange: a list of data change items</returns> /// <remarks> /// This method consists of the following steps: /// /// 1. Defines the sql query parameters and the sql query string. /// /// 2. Execute the sql query string with parameters and store the results on datatable. /// /// 3. Loop through the table and extract data row to the data change object. /// /// 4. Add the object to the Datachanges list. /// /// 5. Return the Datachanges list. /// </remarks> // ------------------------------------------------------------------------------------- public List <EvDataChange> GetView( Guid RecordGuid, EvDataChange.DataChangeTableNames TableName) { // // Initialize the status and the return data change list // this.LogMethod("GetView method. "); this.LogDebug("SiteGuid: " + EvDataChanges._SiteGuid); this.LogDebug("RecordGuid: " + RecordGuid); this.LogDebug("Record Type: " + TableName); List <EvDataChange> View = new List <EvDataChange> ( ); // // If the site guid is empty exit. // if (EvDataChanges._SiteGuid == Guid.Empty) { return(new List <EvDataChange> ( )); } // // Define the SQL query parameters. // SqlParameter [] cmdParms = new SqlParameter [] { new SqlParameter(_parmRecordGuid, SqlDbType.UniqueIdentifier), new SqlParameter(_parmTableName, SqlDbType.NVarChar, 50) }; cmdParms [0].Value = RecordGuid; cmdParms [1].Value = TableName.ToString( ); // // Define the query string. // _sqlQueryString = _sqlQueryView + " WHERE (DC_RecordGuid = @RecordGuid) " + " AND (DC_TableName = @TableName) " + " ORDER BY DC_DateStamp;"; this.LogClass(_sqlQueryString); // // Execute the query against the database. // using (DataTable table = EvSqlMethods.RunQuery(_sqlQueryString, cmdParms)) { // // Iterate through the results extracting the role information. // for (int Count = 0; Count < table.Rows.Count; Count++) { // // Extract the table row // DataRow row = table.Rows [Count]; // // Read the row data. // EvDataChange Item = this.getRowData(row); // // Append the new Change object to the array. // View.Add(Item); } //END record iteration loop. } //END Using statement this.LogDebug("Record Count: " + View.Count); // // Pass back the result arrray. // return(View); } // Close GetView method.
}// END getItem method #endregion #region SelectionList Update queries // ===================================================================================== /// <summary> /// This class updates items on formfield selection list table. /// </summary> /// <param name="Item">EvFormFieldSelectionList: a formfield selection list object</param> /// <returns>EvEventCodes: an event code for updating items</returns> /// <remarks> /// This method consists of the following steps: /// /// 1. Exit, if the Old list's Guid is empty. /// /// 2. Add items to datachange object if they exist after comparing with the old list. /// /// 3. Define the sql parameters and execute the storeprocedure for updating items. /// /// 4. Add the datachange values to the backup datachanges object. /// /// 5. Return the event code for updating the items. /// </remarks> // ------------------------------------------------------------------------------------- public EvEventCodes updateItem(EvSelectionList Item) { this._Log = new System.Text.StringBuilder( ); this.LogMethod("updateItem"); // // Get the previous value // EvSelectionList oldItem = getItem(Item.Guid); if (oldItem.Guid == Guid.Empty) { return(EvEventCodes.Identifier_Global_Unique_Identifier_Error); } // // trime the item options. // this.trimItemOptions(Item); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Compare the objects. // EvDataChanges dataChanges = new EvDataChanges( ); EvDataChange dataChange = new EvDataChange( ); dataChange.TableName = EvDataChange.DataChangeTableNames.EdSelectionList; dataChange.TrialId = String.Empty; dataChange.RecordUid = -1; dataChange.RecordGuid = Item.Guid; dataChange.UserId = Item.UpdatedByUserId; dataChange.DateStamp = DateTime.Now; // // Add items to datachange object if they exist. // if (Item.ListId != oldItem.ListId) { dataChange.AddItem("ListId", oldItem.ListId, Item.ListId); } if (Item.Title != oldItem.Title) { dataChange.AddItem("Title", oldItem.Title, Item.Title); } if (Item.Description != oldItem.Description) { dataChange.AddItem("Description", oldItem.Description, Item.Description); } if (Item.Version != oldItem.Version) { dataChange.AddItem("Version", oldItem.Version, Item.Version); } if (Item.State != oldItem.State) { dataChange.AddItem("State", oldItem.State.ToString( ), Item.State.ToString( )); } string oldCodeItem = Evado.Digital.Model.EvcStatics.SerialiseObject <List <EvSelectionList.Item> > (Item.Items); string newCodeItem = Evado.Digital.Model.EvcStatics.SerialiseObject <List <EvSelectionList.Item> > (Item.Items); if (newCodeItem != oldCodeItem) { dataChange.AddItem("Items", oldCodeItem, newCodeItem); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Define the query parameters // SqlParameter [] commandParameters = GetParameters( ); SetParameters(commandParameters, Item); // // Execute the update command. // if (EvSqlMethods.StoreProcUpdate(_STORED_PROCEDURE_UpdateItem, commandParameters) == 0) { return(EvEventCodes.Database_Record_Update_Error); } // // Add the change record // dataChanges.AddItem(dataChange); // // Update the option list // this.updateOptions(Item); return(EvEventCodes.Ok); }//END updateItem class