private void LoadOrderAddressInfo() { if (int.TryParse(Request.QueryString["orderAddressId"], out _intOrderAddressID)) { // The value was successfulll retrieved from the Query String... so load the worflow payment record string strLastError = String.Empty; // Execute the query against CDW and load the results into the list of address records to be processed _objOrderAddress = new DAL.OrderAddress().Get(_intOrderAddressID, out strLastError); if (_objOrderAddress == null) { lblErrorMessage.Text = String.Concat("There was an ERROR while trying to retrieve the order address record from the DB. Error Message = [", strLastError, "]"); } else { LoadOrderAddressDetailInfo(); LoadCurrentStatusDetails(); LoadOrderAddressLogItems(); LoadOrderAddressStateEvaluator(); HideShowLinks(); SetAPIHistoryLink(); } } else { // The value could NOT be retrieved from the Query String and/or it could not be parsed to an integer _intOrderAddressID = 0; } }
public void Check_Why_SL_Not_Created() { int intOrderAddressID = 2; // Instantiate a GLM Call Manager, to be used to invoke the GLM Web Service APIs RAL.GLMCallManager objGLMCallManager = new RAL.GLMCallManager(_strBaseUrl, _strAuthorizationHeaderUsername_Authorization, _strAuthorizationHeaderApplicationID_XGLMAPIAuthorization, intOrderAddressID); bool blnServiceLocationExists; bool blnCallSucceeded; string strSLNumber; string strErrorMessage; DAL.OrderAddress _objOrderAddress = new DAL.OrderAddress().Get(intOrderAddressID, out strErrorMessage); // Invoke the GLM API, to search for the full set of data for the SITE LOCATION... including ALL of its SERVICE LOCATIONs List <Model.LocationService.SiteLocationV2> lstSiteLocationV2 = objGLMCallManager.GetSiteLocationFromGLMByPLOrClII("PL0001336837"); // Check to see if the call succeeded if (lstSiteLocationV2 != null) { // Declare an analzer class that will parse through the very cryptic GLM response to determine if the Site Location Exists BLL.SiteLocationAnalyzer objSiteLocationAnalyzer = new BLL.SiteLocationAnalyzer(); // Load the analyser if (objSiteLocationAnalyzer.Load(lstSiteLocationV2)) { // Search for the SERVICE LOCATION using its Floor, Room, and Suite blnServiceLocationExists = objSiteLocationAnalyzer.FindServiceLocation_SLNumber(_objOrderAddress.CDWFloor, _objOrderAddress.CDWRoom, _objOrderAddress.CDWSuite, out strSLNumber); // NOTE: The strSLNumber variable now holds the SL Number for the SERVICE LOCATION retrieved from GLM blnCallSucceeded = true; } else { // The call result cannot be loaded, which is the same end result as a failed call blnCallSucceeded = false; strSLNumber = String.Empty; } } else { // The call failed. blnCallSucceeded = false; strSLNumber = String.Empty; } }
private void InsertAsNewOrderAddress(DAL.CDWOrderAddressRecord objCDWOrderAddressRecord, Model.OrderSystemOfRecords enmOrderSystemOfRecord, string strCDWCustomerOrderNumber, string strCDWAddressOne, string strCDWCity, string strCDWState, string strCDWPostalCode, string strCDWCountry, string strCDWFloor, string strCDWRoom, string strCDWSuite) { // Instantiate a new object DAL.OrderAddress objOrderAddress = new DAL.OrderAddress(); // Declare a common date value to use DateTime dteNow = DateTime.Now; // Analyze the floor, room, and suite to determine if this address should be considerd a SITE or a SERVICE LOCATION objOrderAddress.OrderAddressTypeID = (int)CDWOrderAddressRecordUtil.TranslateRawAddressFieldsToOrderAddressType(strCDWFloor, strCDWRoom, strCDWSuite); // Set the default system status for new records objOrderAddress.MigrationStatusID = (int)MigrationStatuses.STAGED_for_Processing; // Set the SOR already translated/provided by the caller objOrderAddress.OrderSystemOfRecordID = (int)enmOrderSystemOfRecord; // Set the address field values, using the strings that were already cleaned by the caller as part of the existence check // The null overrride to empty string is important, since SQL SQL Syntax and the way the SELECT queries are written see a difference between EmptyString and NULL. i.e. - NULL values received from the CDW are translated to empty string objOrderAddress.CDWCustomerOrderNumber = strCDWCustomerOrderNumber ?? String.Empty; objOrderAddress.CDWAddressOne = strCDWAddressOne ?? String.Empty; objOrderAddress.CDWCity = strCDWCity ?? String.Empty; objOrderAddress.CDWState = strCDWState ?? String.Empty; objOrderAddress.CDWPostalCode = strCDWPostalCode ?? String.Empty; objOrderAddress.CDWCountry = strCDWCountry ?? String.Empty; objOrderAddress.CDWFloor = strCDWFloor ?? String.Empty; objOrderAddress.CDWRoom = strCDWRoom ?? String.Empty; objOrderAddress.CDWSuite = strCDWSuite ?? String.Empty; objOrderAddress.CDWCLII = objCDWOrderAddressRecord.CLIICode; // Validate the CLII provided objOrderAddress.ValidCLII = CLIIUtility.IsValidCLII(objCDWOrderAddressRecord.CLIICode); // Set all appropriate defaults for values that we don't yet have objOrderAddress.NumberOfFailedGLMSiteCalls = 0; objOrderAddress.ExistsInGLMAsSite = false; objOrderAddress.GLMPLNumber = String.Empty; objOrderAddress.NumberOfFailedGLMSiteCodeExistenceCalls = 0; objOrderAddress.NumberOfFailedGLMSiteCodeCreationCalls = 0; objOrderAddress.GLMSiteCode = String.Empty; objOrderAddress.HasGLMSiteCode = false; objOrderAddress.NumberOfFailedSAPSiteAddressSearchCalls = 0; objOrderAddress.NumberOfFailedSAPSiteAddressImportCalls = 0; objOrderAddress.ExistsInSAPAsSiteAddress = false; objOrderAddress.NumberOfRecordsInSAPWithPL = 0; objOrderAddress.NumberOfFailedGLMServiceLocationSearchCalls = 0; objOrderAddress.NumberOfFailedGLMServiceLocationCreationCalls = 0; objOrderAddress.GLMSLNumber = String.Empty; objOrderAddress.ExistsInGLMAsServiceLocation = false; objOrderAddress.NumberOfFailedGLMSCodeExistenceCalls = 0; objOrderAddress.NumberOfFailedGLMSCodeCreationCalls = 0; objOrderAddress.GLMSCode = String.Empty; objOrderAddress.HasGLMSCode = false; objOrderAddress.NumberOfFailedSAPServiceLocationAddressSearchCalls = 0; objOrderAddress.NumberOfFailedSAPServiceLocationAddressImportCalls = 0; objOrderAddress.ExistsInSAPAsServiceLocationAddress = false; objOrderAddress.NumberOfRecordsInSAPWithSL = 0; objOrderAddress.DateTimeOfLastMigrationStatusUpdate = dteNow; //objOrderAddress.DateTimeOfLastDupDetection = leave null objOrderAddress.DateCreated = dteNow; objOrderAddress.DateUpdated = dteNow; objOrderAddress.ServiceOrderNumber = objCDWOrderAddressRecord.ServiceOrderNumber; objOrderAddress.FIRST_ORDER_CREATE_DT = objCDWOrderAddressRecord.FIRST_ORDER_CREATE_DT; objOrderAddress.OPE_LAST_MODIFY_DATE = objCDWOrderAddressRecord.OPE_LAST_MODIFY_DATE; objOrderAddress.PL_LAST_MODIFY_DATE = objCDWOrderAddressRecord.PL_LAST_MODIFY_DATE; objOrderAddress.PS_LAST_MODIFY_DATE = objCDWOrderAddressRecord.PS_LAST_MODIFY_DATE; string strLastError = String.Empty; if (objOrderAddress.Insert(out strLastError)) { // The insert worked // Add a log item with the log message DAL.OrderAddressLogItem objOrderAddressLogItem = new DAL.OrderAddressLogItem(); objOrderAddressLogItem.OrderAddressID = objOrderAddress.OrderAddressID; objOrderAddressLogItem.MigrationStatusID = objOrderAddress.MigrationStatusID; objOrderAddressLogItem.LogMessage = "The order address was just pulled from the CDW and is now staged for further processing downstream into GLM and SAP."; objOrderAddressLogItem.DateCreated = dteNow; objOrderAddressLogItem.DateUpdated = dteNow; strLastError = String.Empty; if (objOrderAddressLogItem.Insert(out strLastError) == false) { throw new Exception(String.Format("There was an error while tyring to insert the log message detailing the order address record update. Error Message = [{0}]", strLastError)); } } else { throw new Exception(String.Format("There was an error while trying to insert the record retrieved from the CDW into the customer Order Address table in SQL Server (tblOrderAddress). Error Message = [{0}]", strLastError)); } }
/// <summary> /// Iterates over the list populated via the load method, and stages a record in the customer SQL server database if it does not yet already exist /// </summary> /// <returns></returns> public bool Process() { try { // Ensure that the load method was called and succeeded EnforceLoadSuccess(); // Instantiate a stopwatch to write runtimes to a log file Stopwatch objStopWatch = new Stopwatch(); objStopWatch.Start(); int intAlreadyExisted = 0; int intNewRecords = 0; // Iterate over the order addresses that require processing for (int i = 0; i < _lstCDWOrderAddressRecords_ToProcess.Count; i++) { // Declare a base logging string string strBaseLoggingString = CDWOrderAddressRecordUtil.CalcUniqueRecordIdentifierLoggingString(_lstCDWOrderAddressRecords_ToProcess[i]); try { // Translate the string valye from CDW for the Order Sytem Code to the corresponding ENUM Model.OrderSystemOfRecords enmOrderSystemOfRecord = TranslateDW_SOURCE_SYSTEM_CDToOrderSystemOfRecord.Translate(_lstCDWOrderAddressRecords_ToProcess[i].DataWarehouseSourceSystemCode); // Declare some variables to send in to the cleanup method // Initialize the return fields string strCDWCustomerOrderNumber = String.Empty; string strCDWAddressOne = String.Empty; string strCDWCity = String.Empty; string strCDWState = String.Empty; string strCDWPostalCode = String.Empty; string strCDWCountry = String.Empty; string strCDWFloor = String.Empty; string strCDWRoom = String.Empty; string strCDWSuite = String.Empty; // Trim and set the values that will get inserted/compared with out custom record store. If there is an issue or exception, an error will be added to the error list and the current record will be skipped. if (CDWOrderAddressRecordUtil.CleanupRawAddressFields(_lstCDWOrderAddressRecords_ToProcess[i], out strCDWCustomerOrderNumber, out strCDWAddressOne, out strCDWCity, out strCDWState, out strCDWPostalCode, out strCDWCountry, out strCDWFloor, out strCDWRoom, out strCDWSuite) == false) { throw new Exception(String.Format("There was an error while trying to cleanse the order address record pulled from CDW. {0}", strBaseLoggingString)); } string strLastError = String.Empty; // Check to see if the record exist... by trying to load it from the custom sql server table DAL.OrderAddress objOrderAddress = new DAL.OrderAddress().Get((int)enmOrderSystemOfRecord, strCDWCustomerOrderNumber, strCDWAddressOne, strCDWCity, strCDWState, strCDWPostalCode, strCDWCountry, strCDWFloor, strCDWRoom, strCDWSuite, out strLastError); if (objOrderAddress != null) { intAlreadyExisted++; // The record already exists so check its status if ((objOrderAddress.MigrationStatusID == (int)MigrationStatuses.STAGED_for_Processing) || (objOrderAddress.MigrationStatusID == (int)MigrationStatuses.IGNORED_indefinitely)) { // Leave this record as is, and don't bother with a log message } else { // Add a log item to reflect that this record has been detected again... after it began its trip through the workflow } } else { intNewRecords++; // The record does NOT yet exist, so add it and then set the local member InsertAsNewOrderAddress(_lstCDWOrderAddressRecords_ToProcess[i], enmOrderSystemOfRecord, strCDWCustomerOrderNumber, strCDWAddressOne, strCDWCity, strCDWState, strCDWPostalCode, strCDWCountry, strCDWFloor, strCDWRoom, strCDWSuite); } } catch (Exception ex) { string strErrorMessage = String.Format("There was an error while processing one of the order address records pulled from the CDW. This error is contained to a single CDW record, which will now be skipped. Other records contained in the result set will continue to process. Error Message = [{0}]. {1}", ex.Message, strBaseLoggingString); // Log a warning to the log file _objLogger.Warn(strErrorMessage); // Continue to the next record, so that one bad record cannot hault the processing of subsequent records that are next in the list continue; } } // Log the time to retrieve the date string strTimeElapsed = StopwatchUtil.GetHumanReadableTimeElapsedString(objStopWatch); string strLogMessage = String.Concat("Time elapsed while processing the Order Address records received from CDW to insert them into the custom database tables and queue them for further was [", strTimeElapsed, "]. --> Number of Errors = [", _lstErrorMessages.Count.ToString(), "], Number of Total Results Processed = [", _lstCDWOrderAddressRecords_ToProcess.Count, "] records. Number of Records that ALREADY existed = [", intAlreadyExisted.ToString(), "], Number of NEW records added to the DB = [", intNewRecords.ToString(), "]"); _objLogger.Info(strLogMessage); string strNote = String.Concat("The newest changeset of new or changed address records from the CDW has been processed. ", strLogMessage); SystemLogItemUtil.InsertLogItem(strNote, "CDW Sync"); } catch (Exception ex) { // Create the error message string strErrorMessage = String.Format("An error was caught while trying to iterate over the raw records retrieved from CDW. The nature of this issue will cause the system to dump the rest of the records that have yet to be processed, as the problem cannot be skipped over. Error Message = [{0}]", ex.Message); // Log a warning to the log file _objLogger.Warn(strErrorMessage); // Add the error message to the error list so that the caller can access it _lstErrorMessages.Add(strErrorMessage); } return(_lstErrorMessages.Count == 0); }
public static string CalcUniqueRecordIdentifierLoggingString(DAL.OrderAddress objOrderAddressRecord) { return(String.Format("Order Address -> OrderAddressID = [{0}], System of Record = [{1}], OrderAddressType = [{2}], CustomerOrderNumber = [{3}], Line1Address = [{4}], CityName = [{5}], StateCode = [{6}], PostalCode = [{7}], CountryName = [{8}], Floor = [{9}], Room = [{8}], Suite = [{10}]", objOrderAddressRecord.OrderAddressID.ToString(), (Model.OrderSystemOfRecords)objOrderAddressRecord.OrderSystemOfRecordID, (Model.OrderAddressTypes)objOrderAddressRecord.OrderAddressTypeID, objOrderAddressRecord.CDWCustomerOrderNumber, objOrderAddressRecord.CDWAddressOne, objOrderAddressRecord.CDWCity, objOrderAddressRecord.CDWState, objOrderAddressRecord.CDWPostalCode, objOrderAddressRecord.CDWCountry, objOrderAddressRecord.CDWFloor, objOrderAddressRecord.CDWRoom, objOrderAddressRecord.CDWSuite)); }