private bool UsePBSServiceDataAndUpdateFlags(ProcessData processData) { bool result = false; try { string destinationName = null; string orderNumber = null; string destinationStreet = null; string destinationStreetSupplement1 = null; string destinationPostalCode = null; string destinationCity = null; string destinationRegionCoded = null; string scheduledShipmentDateInString = null; string scheduledDeliveryDateInString = null; string isScheduled = null; /* Expecting data to come in below sequence and updating the fields based on this only * * JobNo,Delivery Date,ShpDate,Scheduled,Order Date,Job Order,Job Category,Job Type,Customer, * Company Name,Contract Number,Order Number,Origin Location,Origin Name,Origin Address,Origin Address2, * Origin City,Origin State,Origin Zip,Origin Attention,Origin Phone,Origin Phone2,Origin Fax, * Origin Email,Destination Location,Destination Name,Destination Address,Destination Address2, * Destination City,Destination State,Destination Zip,Destination Attention,Destination Phone, * Destination Phone2,Destination Email,Destination Note,Service Type,Mode,Partner Name,Driver Number, * Driver,ApprDel,ShprNo * */ var pbsQueryResult = ProcessPBSQueryResult.Instance; var currentOrderDetails = new PBSData(); if (pbsQueryResult.AllPBSOrder.ContainsKey(processData.OrderNumber.Trim())) { currentOrderDetails = pbsQueryResult.AllPBSOrder[processData.OrderNumber.Trim()]; } destinationName = currentOrderDetails.DestinationName; orderNumber = currentOrderDetails.OrderNumber; destinationStreet = currentOrderDetails.DestinationStreet; destinationStreetSupplement1 = currentOrderDetails.DestinationStreetSupplyment1; destinationPostalCode = currentOrderDetails.DestinationPostalCode; destinationCity = currentOrderDetails.DestinationCity; destinationRegionCoded = currentOrderDetails.DestinationRegionCoded; scheduledShipmentDateInString = currentOrderDetails.ShipmentDate; scheduledDeliveryDateInString = currentOrderDetails.DeliveryDate; isScheduled = currentOrderDetails.IsScheduled; if (!string.IsNullOrWhiteSpace(scheduledShipmentDateInString) && !string.IsNullOrWhiteSpace(orderNumber) && (processData.ShippingSchedule.OrderNumber.Trim().Equals(orderNumber.Trim(), StringComparison.OrdinalIgnoreCase))) { #region XCBL Data var xcblRequestDate = DateTimeOffset.Parse(processData.ShippingSchedule.ScheduleIssuedDate).UtcDateTime; var xcblScheduledShipDate = DateTimeOffset.Parse(processData.ShippingSchedule.ScheduleIssuedDate).UtcDateTime; DateTime?xcblScheduledDeliveryDate = null; if (!string.IsNullOrWhiteSpace(processData.ShippingSchedule.EstimatedArrivalDate)) { xcblScheduledDeliveryDate = DateTimeOffset.Parse(processData.ShippingSchedule.EstimatedArrivalDate).UtcDateTime; } var xcblDeliveryName = processData.ShippingSchedule.Name1 ?? ""; var xcblStreet = processData.ShippingSchedule.Street ?? ""; var xcblStreetSupplement1 = processData.ShippingSchedule.StreetSupplement1 ?? ""; var xcblPostalCode = processData.ShippingSchedule.PostalCode ?? ""; var xcblCity = processData.ShippingSchedule.City ?? ""; var xcblRegionCoded = processData.ShippingSchedule.RegionCoded ?? ""; var xcblSameDay = processData.ShippingSchedule.Other_SameDay ?? ""; var xcblFirstStop = processData.ShippingSchedule.Other_FirstStop ?? ""; var xcblBefore7 = processData.ShippingSchedule.Other_Before7 ?? ""; var xcblBefore9 = processData.ShippingSchedule.Other_Before9 ?? ""; var xcblBefore12 = processData.ShippingSchedule.Other_Before12 ?? ""; var xcblOwnerOccupied = processData.ShippingSchedule.Other_OwnerOccupied ?? ""; #endregion XCBL Data #region PBS Data destinationName = destinationName ?? ""; destinationStreet = destinationStreet ?? ""; destinationStreetSupplement1 = destinationStreetSupplement1 ?? ""; destinationCity = destinationCity ?? ""; destinationPostalCode = processData.ShippingSchedule.PostalCode ?? ""; destinationRegionCoded = destinationRegionCoded ?? ""; isScheduled = isScheduled ?? ""; var scheduledShipmentDate = DateTimeOffset.Parse(scheduledShipmentDateInString).UtcDateTime; var scheduledShipmentDate10AM = new DateTime(scheduledShipmentDate.Year, scheduledShipmentDate.Month, scheduledShipmentDate.Day, 10, 0, 0); DateTime?scheduledDeliveryDate = null; DateTime?scheduledDeliveryDate10AM = null; if (!string.IsNullOrWhiteSpace(scheduledDeliveryDateInString)) { scheduledDeliveryDate = DateTimeOffset.Parse(scheduledDeliveryDateInString).UtcDateTime; } if (!string.IsNullOrWhiteSpace(scheduledDeliveryDateInString)) { scheduledDeliveryDate10AM = new DateTime(scheduledDeliveryDate.Value.Year, scheduledDeliveryDate.Value.Month, scheduledDeliveryDate.Value.Day, 10, 0, 0); } #endregion PBS Data var currentDateTime = DateTime.UtcNow; if (isScheduled.Trim().Equals(MeridianGlobalConstants.PBS_SCHEDULED_FALSE, StringComparison.OrdinalIgnoreCase)) { processData.ShippingSchedule.Approve05 = _meridianResult.Approve05 = MeridianGlobalConstants.XCBL_YES_FLAG; } else if ((scheduledShipmentDate >= currentDateTime) && (xcblRequestDate > scheduledShipmentDate10AM.AddDays(-2))) { processData.ShippingSchedule.Pending01 = _meridianResult.Pending01 = MeridianGlobalConstants.XCBL_YES_FLAG; } else if ((scheduledShipmentDate < currentDateTime) && scheduledDeliveryDate10AM.HasValue && (xcblRequestDate > scheduledDeliveryDate10AM.Value.AddDays(-2))) { processData.ShippingSchedule.Pending02 = _meridianResult.Pending02 = MeridianGlobalConstants.XCBL_YES_FLAG; } else if (xcblSameDay.Equals(MeridianGlobalConstants.XCBL_YES_FLAG, StringComparison.OrdinalIgnoreCase) || xcblFirstStop.Equals(MeridianGlobalConstants.XCBL_YES_FLAG, StringComparison.OrdinalIgnoreCase) || xcblBefore7.Equals(MeridianGlobalConstants.XCBL_YES_FLAG, StringComparison.OrdinalIgnoreCase) || xcblBefore9.Equals(MeridianGlobalConstants.XCBL_YES_FLAG, StringComparison.OrdinalIgnoreCase) || xcblBefore12.Equals(MeridianGlobalConstants.XCBL_YES_FLAG, StringComparison.OrdinalIgnoreCase) || xcblOwnerOccupied.Equals(MeridianGlobalConstants.XCBL_YES_FLAG, StringComparison.OrdinalIgnoreCase)) { processData.ShippingSchedule.Pending03 = _meridianResult.Pending03 = MeridianGlobalConstants.XCBL_YES_FLAG; } else if (!xcblStreet.Trim().Equals(destinationStreet.Trim(), StringComparison.OrdinalIgnoreCase) || !xcblStreetSupplement1.Trim().Equals(destinationStreetSupplement1.Trim(), StringComparison.OrdinalIgnoreCase) || !xcblPostalCode.Trim().Equals(destinationPostalCode.Trim(), StringComparison.OrdinalIgnoreCase) || !xcblCity.Trim().Equals(destinationCity.Trim(), StringComparison.OrdinalIgnoreCase) || !xcblRegionCoded.Trim().Equals(destinationRegionCoded.Trim(), StringComparison.OrdinalIgnoreCase)) { processData.ShippingSchedule.Pending04 = _meridianResult.Pending04 = MeridianGlobalConstants.XCBL_YES_FLAG; } else if ((processData.ShippingSchedule.OrderType != null) && (processData.ShippingSchedule.OrderType.Trim().Equals(MeridianGlobalConstants.XCBL_ORDER_TYPE_NPT, StringComparison.OrdinalIgnoreCase) || processData.ShippingSchedule.OrderType.Trim().Equals(MeridianGlobalConstants.XCBL_ORDER_TYPE_RRO, StringComparison.OrdinalIgnoreCase))) { processData.ShippingSchedule.Approve01 = _meridianResult.Approve01 = MeridianGlobalConstants.XCBL_YES_FLAG; } else if ((scheduledShipmentDate > currentDateTime) && (xcblRequestDate <= scheduledShipmentDate10AM.AddDays(-2))) { processData.ShippingSchedule.Approve02 = _meridianResult.Approve02 = MeridianGlobalConstants.XCBL_YES_FLAG; } else if ((scheduledShipmentDate < currentDateTime) && scheduledDeliveryDate10AM.HasValue && (xcblRequestDate <= scheduledDeliveryDate10AM.Value.AddDays(-2))) { processData.ShippingSchedule.Approve03 = _meridianResult.Approve03 = MeridianGlobalConstants.XCBL_YES_FLAG; } else if ((xcblScheduledShipDate == scheduledShipmentDate) && xcblScheduledDeliveryDate.HasValue && scheduledDeliveryDate.HasValue && (xcblScheduledDeliveryDate.Value == scheduledDeliveryDate.Value) && xcblSameDay.Equals(MeridianGlobalConstants.XCBL_NO_FLAG, StringComparison.OrdinalIgnoreCase) && xcblFirstStop.Equals(MeridianGlobalConstants.XCBL_NO_FLAG, StringComparison.OrdinalIgnoreCase) && xcblBefore7.Equals(MeridianGlobalConstants.XCBL_NO_FLAG, StringComparison.OrdinalIgnoreCase) && xcblBefore9.Equals(MeridianGlobalConstants.XCBL_NO_FLAG, StringComparison.OrdinalIgnoreCase) && xcblBefore12.Equals(MeridianGlobalConstants.XCBL_NO_FLAG, StringComparison.OrdinalIgnoreCase) && xcblOwnerOccupied.Equals(MeridianGlobalConstants.XCBL_NO_FLAG, StringComparison.OrdinalIgnoreCase)) { processData.ShippingSchedule.Approve04 = _meridianResult.Approve04 = MeridianGlobalConstants.XCBL_YES_FLAG; } else { processData.ShippingSchedule.Pending05 = _meridianResult.Pending05 = MeridianGlobalConstants.XCBL_YES_FLAG; } } else { processData.ShippingSchedule.Rejected01 = _meridianResult.Rejected01 = MeridianGlobalConstants.XCBL_YES_FLAG; processData.ShippingSchedule.Comments = _meridianResult.Comments = MeridianGlobalConstants.XCBL_COMMENT_ORDER_NOT_FOUND; MeridianSystemLibrary.LogTransaction(processData.WebUserName, processData.FtpUserName, "UsePBSServiceDataAndUpdateFlags", "02.24", "Warning - No Data from PBS WebService", string.Format("Warning - No data got for Order '{0}' from PBS WebService", processData.OrderNumber), processData.CsvFileName, processData.ScheduleID, processData.OrderNumber, null, "Warning 02.24"); } result = true; MeridianSystemLibrary.LogPBS( processData.ScheduleID, processData.OrderNumber, processData.ShippingSchedule.Approve01, processData.ShippingSchedule.Approve02, processData.ShippingSchedule.Approve03, processData.ShippingSchedule.Approve04, processData.ShippingSchedule.Approve05, processData.ShippingSchedule.Pending01, processData.ShippingSchedule.Pending02, processData.ShippingSchedule.Pending03, processData.ShippingSchedule.Pending04, processData.ShippingSchedule.Pending05, "ShippingSchedule", processData.ShippingSchedule.Rejected01, processData.ShippingSchedule.Comments); } catch (Exception ex) { MeridianSystemLibrary.LogTransaction(processData.WebUserName, processData.FtpUserName, "UsePBSServiceDataAndUpdateFlags", "03.13", "Error - Something went wrong", string.Format("Exception - {0}", ex.Message), processData.CsvFileName, processData.ScheduleID, processData.OrderNumber, null, "Error 03.13 - PBS Service Call"); } return(result); }
private void GetAllOrder() { IsProcessing = true; MeridianSystemLibrary.LogTransaction(null, null, "GetAllOrder", "01.10", "Success - inside GetAllOrder", "Success - inside GetAllOrder", null, null, null, null, "Success - inside GetAllOrder"); var allLatestPBSOrders = new Dictionary <string, PBSData>(); pbsFrequencyTimer.Stop(); pbsFrequencyTimer.Interval = TimeSpan.FromMinutes(MeridianGlobalConstants.PBS_QUERY_FREQUENCY).TotalMilliseconds; pbsFrequencyTimer.Start(); string fileNameFormat = DateTime.Now.ToString(MeridianGlobalConstants.XCBL_FILE_DATETIME_FORMAT); using (HttpClient client = new HttpClient()) { var sqlQuery = string.Format(MeridianGlobalConstants.PBS_WEB_SERVICE, MeridianGlobalConstants.PBS_WEB_SERVICE_QUERY, MeridianGlobalConstants.CONFIG_PBS_WEB_SERVICE_USER_NAME, MeridianGlobalConstants.CONFIG_PBS_WEB_SERVICE_PASSWORD); var res = client.GetAsync(sqlQuery).Result; var resultString = client.GetStringAsync(MeridianGlobalConstants.PBS_OUTPUT_FILE).Result; if (MeridianGlobalConstants.PBS_ENABLE_CACHE_LOG == MeridianGlobalConstants.XCBL_YES_FLAG) { CommonProcess.CreateLogFile(string.Format("{0}\\PBS{1}voc.txt", MeridianGlobalConstants.PBS_CACHE_LOG_LOCATION, fileNameFormat), resultString); } if (!string.IsNullOrWhiteSpace(resultString)) { var lines = resultString.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); if (lines.Count() > 1) { for (int i = 1; i < lines.Length; i++) { if (!string.IsNullOrWhiteSpace(lines[i])) { var values = lines[i].Split(','); if (values.Length > 29) { DateTimeOffset orderDate; if (DateTimeOffset.TryParse(values[4], out orderDate)) { PBSData pbsData = new PBSData(); pbsData.DeliveryDate = values[1]; pbsData.ShipmentDate = values[2]; pbsData.IsScheduled = values[3]; pbsData.OrderNumber = values[10].Trim(); pbsData.DestinationName = values[25]; pbsData.DestinationStreet = values[26]; pbsData.DestinationStreetSupplyment1 = values[27]; pbsData.DestinationCity = values[28]; pbsData.DestinationRegionCoded = string.Format(MeridianGlobalConstants.XCBL_US_CODE + values[29]); pbsData.DestinationPostalCode = values[30]; if (!allLatestPBSOrders.ContainsKey(pbsData.OrderNumber)) { allLatestPBSOrders.Add(pbsData.OrderNumber.Trim(), pbsData); } } } else { MeridianSystemLibrary.LogTransaction(null, null, "GetAllOrder", "02.25", "Warning - Values lenght less then 29", "Warning - Values lenght less then 29 from PBS WebService", null, null, null, null, "Warning 02.25 : Values lenght less then 29"); } } } } else { MeridianSystemLibrary.LogTransaction(null, null, "GetAllOrder", "02.26", "Warning - PBS File Lines Count < 2", "Warning - PBS File Lines Count < 2 from PBS WebService", null, null, null, null, "Warning 02.26 : PBS File Lines Count < 2"); } } else { MeridianSystemLibrary.LogTransaction(null, null, "GetAllOrder", "02.27", "Warning - Empty PBS text file", "Warning - Empty PBS text file from PBS WebService", null, null, null, null, "Warning 02.27 : Empty Text File"); } } if (MeridianGlobalConstants.PBS_ENABLE_CACHE_LOG == MeridianGlobalConstants.XCBL_YES_FLAG) { StringBuilder strBuilder = new StringBuilder(MeridianGlobalConstants.PBS_CSV_HEADERS); strBuilder.AppendLine(); foreach (var item in allLatestPBSOrders) { strBuilder.AppendLine(string.Format(MeridianGlobalConstants.PBS_CSV_HEADER_NAME_FORMAT, item.Value.DeliveryDate, item.Value.ShipmentDate, item.Value.IsScheduled, item.Value.OrderNumber, item.Value.DestinationName, item.Value.DestinationStreet, item.Value.DestinationStreetSupplyment1, item.Value.DestinationCity, item.Value.DestinationRegionCoded, item.Value.DestinationPostalCode)); } CommonProcess.CreateLogFile(string.Format("{0}\\XCBL{1}PBSCachedOrders.csv", MeridianGlobalConstants.PBS_CACHE_LOG_LOCATION, fileNameFormat), strBuilder.ToString()); } AllPBSOrder = allLatestPBSOrders; IsProcessing = false; }