/// <summary> /// Build Standard Material Object /// </summary> /// <param name="pDBRecord"></param> /// <returns></returns> internal static standardMaterial BuildStandardMaterialObject(DBRecordInfo pDBRecord, WincashWSAdapterConfig pWincashWSAdapterConfig) { standardMaterial material = null; try { if (pDBRecord == null || pDBRecord.Row == null) { return(null); } material = new standardMaterial() { materialNumber = pDBRecord.GetFieldValue <String>(QueryFields.materialNumber) }; DateTime modificationStamp = WincashWSAdapterUtilities.ParseModificationStamp( pDBRecord.GetFieldValue <String>(QueryFields.modificationStamp)); if (modificationStamp != DateTime.MinValue) { material.modificationStamp = modificationStamp; material.modificationStampSpecified = true; } if (!material.materialNumber.IsValidString()) { return(null); } #region Master Data Settings material.masterDataSettings = new masterDataSettings() { status = pDBRecord.GetFieldValue <String>(QueryFields.status).ToStatus(), statusSpecified = true }; #endregion #region Inheritance Settings material.inheritanceSettings = new inheritanceSettings() { Item = pDBRecord.GetFieldValue <String>(QueryFields.treeID), // [shopName or treeID] ItemElementName = ItemChoiceType.treeID }; #endregion #region General Settings // Material Name Translations List <translation> _materialNameTranslations = new List <translation>(); _materialNameTranslations.Add(new translation() { translatedLanguage = "EN", translatedText = pDBRecord.GetFieldValue <String>(QueryFields.materialName) }); List <translation> _materialName2Translations = new List <translation>(); _materialName2Translations.Add(new translation() { translatedLanguage = "EN", translatedText = pDBRecord.GetFieldValue <String>(QueryFields.materialName2) }); material.generalSettings = new generalSettings() { materialName = pDBRecord.GetFieldValue <String>(QueryFields.materialName), materialNameTranslations = _materialNameTranslations.ToArray(), materialName2 = pDBRecord.GetFieldValue <String>(QueryFields.materialName2), materialName2Translations = _materialName2Translations.ToArray(), Item = pDBRecord.GetFieldValue <String>(QueryFields.goodsGroupName), ItemElementName = ItemChoiceType3.goodsGroupName, Item1 = pDBRecord.GetFieldValue <String>(QueryFields.materialGroupName), Item1ElementName = Item1ChoiceType2.materialGroupName, Item2 = pDBRecord.GetFieldValue <String>(QueryFields.unitName), Item2ElementName = Item2ChoiceType.unitName, supplierMaterialNumber = pDBRecord.GetFieldValue <String>(QueryFields.supplierMaterialNumber) }; #endregion #region Price Settings material.priceSettings = new priceSettings() { price = pDBRecord.BuildNonFractionNumber(QueryFields.price, QueryFields.priceMultiplier), Item = pDBRecord.GetFieldValue <String>(QueryFields.currencyName), // [currencyID or currencyName] ItemElementName = ItemChoiceType4.currencyName, Item1 = pDBRecord.GetFieldValue <String>(QueryFields.taxNumber), // [taxID or taxNumber] Item1ElementName = Item1ChoiceType9.taxNumber, denyPriceOverwriting = pDBRecord.GetFieldValue <String>(QueryFields.denyPriceOverwriting).ToFlag(), denyPriceOverwritingSpecified = true, denyReduction = pDBRecord.GetFieldValue <String>(QueryFields.denyReduction).ToFlag(), denyReductionSpecified = true, allowNegativeReducedPrice = pDBRecord.GetFieldValue <String>(QueryFields.allowNegativeReducedPrice).ToFlag(), allowNegativeReducedPriceSpecified = true, maximumPrice = pDBRecord.BuildNonFractionNumber(QueryFields.maximumPriceValue, QueryFields.maximumPriceMultiplier), minimumPrice = pDBRecord.BuildNonFractionNumber(QueryFields.minimumPriceValue, QueryFields.minimumPriceMultiplier), turnoverRelevancy = pDBRecord.BuildNonFractionNumber(QueryFields.turnoverRelevancyValue, QueryFields.turnoverRelevancyMultiplier), priceListsAvailable = pDBRecord.GetFieldValue <String>(QueryFields.priceListsAvailable).ToFlag(), priceListsAvailableSpecified = true }; #endregion #region Serial Settings List <serialNumberDefinition> _serialNumberDefinitions = new List <serialNumberDefinition>(); _serialNumberDefinitions.Add(new serialNumberDefinition() { serialLength = pDBRecord.GetFieldValue <String>(QueryFields.serialLength), serialType = pDBRecord.GetFieldValue <String>(QueryFields.serialType).ToSerialType(), serialTypeSpecified = true }); material.serialSettings = new serialSettings() { forceSerial = pDBRecord.GetFieldValue <String>(QueryFields.forceSerial).ToFlag(), forceSerialSpecified = true, serialPoolTracked = pDBRecord.GetFieldValue <String>(QueryFields.serialPoolTracked).ToFlag(), serialPoolTrackedSpecified = true, serialNumberDefinitions = _serialNumberDefinitions.ToArray() }; #endregion #region Inventory Handling material.inventoryHandling = new inventoryHandling() { inventoryAssignments = WincashWSAdapterUtilities.BuildMaterialToStockMappingList(pDBRecord, pWincashWSAdapterConfig), supplierAssignments = WincashWSAdapterUtilities.BuildMaterialToSupplierList(pDBRecord, pWincashWSAdapterConfig), valuationPrice = pDBRecord.BuildNonFractionNumber(QueryFields.valuationPriceValue, QueryFields.valuationPriceMultiplier), // Flags stockControl = pDBRecord.GetFieldValue <String>(QueryFields.stockControl).ToFlag(), stockControlSpecified = true, denyAutomaticOrder = pDBRecord.GetFieldValue <String>(QueryFields.denyAutomaticOrder).ToFlag(), denyAutomaticOrderSpecified = true, denyNegativeStockQuantity = pDBRecord.GetFieldValue <String>(QueryFields.denyNegativeStockQuantity).ToFlag(), denyNegativeStockQuantitySpecified = true }; #endregion #region Extended Settings List <translation> _materialDescriptionTranslations = new List <translation>(); _materialDescriptionTranslations.Add(new translation() { translatedLanguage = "EN", translatedText = pDBRecord.GetFieldValue <String>(QueryFields.materialDescription) }); material.extendedSettings = new extendedSettings() { usageSettings = new usageSettings() { allowQuantityOverwriting = pDBRecord.GetFieldValue <String>(QueryFields.allowQuantityOverwriting).ToFlag(), allowQuantityOverwritingSpecified = true, rejectionReason = pDBRecord.GetFieldValue <String>(QueryFields.rejectionReason).ToFlag(), rejectionReasonSpecified = true, isUseUserItemRestriction = pDBRecord.GetFieldValue <String>(QueryFields.isUseUserItemRestriction).ToFlag(), isUseUserItemRestrictionSpecified = true }, extendedMaterialDescription = new extendedMaterialDescription() { materialDescription = pDBRecord.GetFieldValue <String>(QueryFields.materialDescription), materialDescriptionTranslations = _materialDescriptionTranslations.ToArray(), hyperlink = pDBRecord.GetFieldValue <String>(QueryFields.hyperlink), materialPicture = pDBRecord.GetFieldValue <String>(QueryFields.materialPicture) }, leaseSettings = new leaseSettings() { denyLeaseExchange = pDBRecord.GetFieldValue <String>(QueryFields.denyLeaseExchange).ToFlag(), denyLeaseExchangeSpecified = true }, reservationSettings = new reservationSettings() { denyReservation = pDBRecord.GetFieldValue <String>(QueryFields.denyReservation).ToFlag(), denyReservationSpecified = true } }; #endregion } catch (Exception ex) { LogManager.LogException(ex); } return(material); }
/// <summary> /// Invoke Application Web Service Request - POST /// pPushToDestinationRequest.AdapterCacheResults >> Read the post cache records and fire the web service request to post them /// </summary> /// <param name="pApplicationWebServiceRequest"></param> /// <param name="pPushToDestinationRequest"></param> /// <returns></returns> public override WSDestinationAdapterResponse InvokeApplicationWebServiceRequest_POST(ApplicationWebServiceRequest pApplicationWebServiceRequest, PushToDestinationRequest pPushToDestinationRequest) { WSDestinationAdapterResponse response = null; try { response = new WSDestinationAdapterResponse(base.AdapterMetadata, pApplicationWebServiceRequest); #region Request Header fullMaterialRequestData request = new fullMaterialRequestData(); // Build the request header as configured in the NTSwincash management console requestHeader _requestHeader = new requestHeader() { securityToken = new securityToken() { userName = this.AdapterConfigurations.SecurityTokenUserName, password = this.AdapterConfigurations.SecurityTokenPassword, }, interfaceVersion = this.AdapterConfigurations.InterfaceVersion, buildNumber = this.AdapterConfigurations.BuildNumber, senderID = this.AdapterConfigurations.SenderID, //request uniqueID, can be used by the NTSwincash interface to identify if a request was sent more than one time uniqueID = WincashWSAdapterUtilities.BuildUniqueID(), numberOfRecords = pPushToDestinationRequest.AdapterCacheResults.Count.SafeToString() }; request.requestHeader = _requestHeader; #endregion #region Request Builders List <standardMaterial> _standardMaterials = new List <standardMaterial>(); List <DBRecordInfo> dbRecords = new List <DBRecordInfo>(); foreach (AdapterCacheResult adapterCacheResult in pPushToDestinationRequest.AdapterCacheResults) { standardMaterial material = WincashWSAdapterUtilities.BuildStandardMaterialObject(adapterCacheResult.DBRecord, this.AdapterConfigurations); if (material != null) { dbRecords.Add(adapterCacheResult.DBRecord); _standardMaterials.Add(material); } } standardMaterialList _standardMaterialList = new standardMaterialList() { transferMode = dataTransferMode.DELTA, transferModeSpecified = true, material = _standardMaterials.ToArray() }; fullMaterialType _fullMaterialType = new fullMaterialType() { materials = _standardMaterialList }; request.interfaceData = _fullMaterialType; //Goods Group List goodsGroupList _goodsGroupList = WincashWSAdapterUtilities.BuildGoodsGroupList(dbRecords); //Material Group List materialGroupList _materialGroupList = WincashWSAdapterUtilities.BuildMaterialGroupList(dbRecords); LogManager.LogMessage(string.Format("Data to be pushed to Wincash Material Web Service:{0}\tMaterials: {1}{0}\tGoods Group:{2}{0}\tMaterial Group:{3}", Environment.NewLine, (request.interfaceData.materials.material != null ? request.interfaceData.materials.material.Length.SafeToString() : "0"), _goodsGroupList != null ? _goodsGroupList.goodsGroup.Length.SafeToString() : "0", _materialGroupList != null ? _materialGroupList.materialGroup.Length.SafeToString() : "0" )); #endregion if (request.interfaceData.materials.material != null && request.interfaceData.materials.material.Length > 0) { using (MaterialImportServiceV16 client = new MaterialImportServiceV16(pApplicationWebServiceRequest.ApplicationWebService.ApplicationWebServiceURL)) { #region Import Goods Groups { try { if (_goodsGroupList != null && _goodsGroupList.goodsGroup != null && _goodsGroupList.goodsGroup.Length > 0) { string _goodsGroupTobeImported = string.Format("List of Goods Groups to be imported:{0}", Environment.NewLine); foreach (goodsGroup _goodsGroup in _goodsGroupList.goodsGroup) { _goodsGroupTobeImported += string.Format("\t{1}{0}", Environment.NewLine, _goodsGroup.goodsGroupName); } LogManager.LogMessage(_goodsGroupTobeImported); goodsGroupRequestData goodsGroupRequestData = new goodsGroupRequestData() { goodsGroups = _goodsGroupList, requestHeader = _requestHeader }; genericImportResponse goodsGroupResponse = client.importGoodsGroups(goodsGroupRequestData); string _goodsGroupLogMessage = string.Format("Wincash Import Goods Groups Response{0}{0}Result: {1}{0}Return Code: {2}{0}Interface Specific Response: {3}{0}", Environment.NewLine, goodsGroupResponse.result, goodsGroupResponse.returnCode, goodsGroupResponse.interfaceSpecificResponse); LogManager.LogMessage(_goodsGroupLogMessage, goodsGroupResponse.returnCode.SafeIntegerParse() == 0 ? OperationStatus.Succeeded : OperationStatus.Failed); } else { LogManager.LogMessage("Wincash Import Goods Groups > No Goods Group to be imported"); } } catch (Exception ex) { LogManager.LogException(ex, "Wincash Import Goods Groups Response"); } } #endregion #region Import Material Groups { try { if (_materialGroupList != null && _materialGroupList.materialGroup != null && _materialGroupList.materialGroup.Length > 0) { string _materialGroupTobeImported = string.Format("List of Material Groups to be imported:", Environment.NewLine); foreach (materialGroup _materialGroup in _materialGroupList.materialGroup) { _materialGroupTobeImported += string.Format("{0}\t{1}", Environment.NewLine, _materialGroup.materialGroupName); } LogManager.LogMessage(_materialGroupTobeImported); materialGroupRequestData materialGroupRequestData = new materialGroupRequestData() { materialGroups = _materialGroupList, requestHeader = _requestHeader }; materialGroupRequestData.requestHeader.uniqueID = WincashWSAdapterUtilities.BuildUniqueID(); genericImportResponse materialGroupResponse = client.importMaterialGroups(materialGroupRequestData); string _materialGroupLogMessage = string.Format("Wincash Import Material Groups Response{0}{0}Result: {1}{0}Return Code: {2}{0}Interface Specific Response: {3}{0}", Environment.NewLine, materialGroupResponse.result, materialGroupResponse.returnCode, materialGroupResponse.interfaceSpecificResponse); LogManager.LogMessage(_materialGroupLogMessage, materialGroupResponse.returnCode.SafeIntegerParse() == 0 ? OperationStatus.Succeeded : OperationStatus.Failed); } else { LogManager.LogMessage("Wincash Import Material Groups > No Material Groups to be imported"); } } catch (Exception ex) { LogManager.LogException(ex, "Wincash Import Material Groups Response"); } } #endregion #region Import Material Data genericImportResponse materialImportResponse = null; try { request.requestHeader.uniqueID = WincashWSAdapterUtilities.BuildUniqueID(); materialImportResponse = client.importFullMaterialData(request); } catch (Exception ex) { LogManager.LogException(ex); } try { if (materialImportResponse != null) { #region Logging string _logMessage = string.Format("Wincash Import Material Data Response{0}\tResult: {1}{0}\tReturn Code: {2}{0}\tInterface Specific Response: {3}{0}", Environment.NewLine, materialImportResponse.result, materialImportResponse.returnCode, materialImportResponse.interfaceSpecificResponse.IsValidString() ? materialImportResponse.interfaceSpecificResponse : "Nothing"); if (materialImportResponse.responseParameters != null && materialImportResponse.responseParameters.Length > 0) { _logMessage += string.Format("{0}Response Parameters:{0}", Environment.NewLine); foreach (var resParam in materialImportResponse.responseParameters) { _logMessage += string.Format("\tKey: {1}\t\t Value: {2}{0}", Environment.NewLine, resParam.key, resParam.value); } } _logMessage += string.Format("{0}Processed Jobs:{0}", Environment.NewLine); foreach (processedJob _job in materialImportResponse.jobs) { foreach (failedRecord _failedRecord in _job.failedRecords.Where(c => c.keyValues.Length > 0)) { string failedMaterialNumber = string.Format("{0}\tFailed Keys:{0}", Environment.NewLine); foreach (keyValue failedKeyValue in _failedRecord.keyValues) { failedMaterialNumber += string.Format("\t\tKey Name: {1}\t\tKey Value: {2}{0}", Environment.NewLine, failedKeyValue.keyName, failedKeyValue.Value); } _logMessage += string.Format("\t\tFailed Material Number: {1}{0}\t\tError Code: {2}{0}\t\tError Message: {3}{0}{0}", Environment.NewLine, failedMaterialNumber, _failedRecord.errorCode, _failedRecord.errorMessage); } _logMessage += string.Format("\tCommitted Records: {1}{0}\tFailed Records: {2}{0}\tSkipped Records: {3}{0}\tTotal Records: {4}{0}", Environment.NewLine, _job.committedRecords != null ? _job.committedRecords.Length.SafeToString("0") : "Null", _job.failedRecords != null ? _job.failedRecords.Length.SafeToString("0") : "Null", _job.skippedRecords != null ? _job.skippedRecords.Length.SafeToString("0") : "Null", _job.totalRecords); } LogManager.LogMessage(_logMessage); #endregion #region Response Discovery response.BooleanResult = materialImportResponse.returnCode.SafeIntegerParse() == 0; response.Status = response.BooleanResult ? OperationStatus.Succeeded : OperationStatus.Failed; IList <string> _failedMaterialList = WincashWSAdapterUtilities.BuildFailedMaterialList(materialImportResponse); foreach (AdapterCacheResult cacheResult in pPushToDestinationRequest.AdapterCacheResults) { try { string _materialNumber = cacheResult.DBRecord.GetFieldValue <String>(QueryFields.materialNumber); if (_materialNumber.IsValidString()) { if (!_failedMaterialList.Contains(_materialNumber)) { cacheResult.DBRecord.RecordTransactionStatus = RecordTransactionStatus.Succeeded; cacheResult.DBRecordCache.CacheStatus = RecordCacheStatus.Succeeded.GetValue <Byte>(); } else { cacheResult.DBRecord.RecordTransactionStatus = RecordTransactionStatus.Failed; cacheResult.DBRecordCache.CacheStatus = RecordCacheStatus.Failed.GetValue <Byte>(); } base.AppRuntime.DataService.ApplyEntityChanges(cacheResult.DBRecordCache); response.Results.Add(cacheResult.DBRecord); } } catch (Exception ex) { LogManager.LogException(ex, string.Format("Cache Primary Keys : {0}", cacheResult.DBRecordCache.CachePrimaryKeys)); } } #endregion } else { #region No Response LogManager.LogMessage(string.Format("The web service method [importFullMaterialData] has returned no response"), OperationStatus.Failed); response.BooleanResult = false; response.Status = OperationStatus.Failed; foreach (AdapterCacheResult cacheResult in pPushToDestinationRequest.AdapterCacheResults) { cacheResult.DBRecord.RecordTransactionStatus = RecordTransactionStatus.Failed; cacheResult.DBRecordCache.CacheStatus = RecordCacheStatus.Failed.GetValue <Byte>(); base.AppRuntime.DataService.ApplyEntityChanges(cacheResult.DBRecordCache); response.Results.Add(cacheResult.DBRecord); } #endregion } } catch (Exception ex) { LogManager.LogException(ex); } #endregion } } } catch (Exception ex) { throw ex; } return(response); }