Пример #1
0
        private Document GetDocument(DataSets.Order.CalculatedOrdersRow row,
            DataSets.Order.CalculatedOrderDetailsDataTable detailDataTable,
            DataSets.Order.DeletedOrderDetailsDataTable deletedOrderDetailsDataTable,
            Token lastToken, NorthwindConfig config)
        {
            #region Declarations
            OrderDocument doc;
            string id;
            LogState logState = LogState.Updated;
            Document lineItemDoc;
            CountryCodes countryCodes = new CountryCodes();
            #endregion

            id = row.OrderID.ToString();

            if (lastToken.InitRequest)
                logState = LogState.Created;

            else if (row.IsCreateIDNull() || row.IsModifyIDNull()
                || row.IsCreateUserNull() || row.IsModifyUserNull())
                logState = LogState.Created;

            else if ((row.CreateID > lastToken.SequenceNumber)
                   && (row.CreateUser != config.CrmUser))
                logState = LogState.Created;

            else if ((row.CreateID == lastToken.SequenceNumber)
                && (row.CreateUser != config.CrmUser)
                && (id.CompareTo(lastToken.Id.Id) > 0))
                logState = LogState.Created;

            else if ((row.ModifyID >= lastToken.SequenceNumber) && (row.ModifyUser != config.CrmUser))
                logState = LogState.Updated;

            doc = new OrderDocument();
            doc.Id = id;
            doc.LogState = logState;

            doc.currency.Value = config.CurrencyCode;
            doc.pricinglistid.Value = Constants.DefaultValues.PriceList.ID;
            doc.reference.Value = id;

            if (row.IsCustomerIDNull())
                doc.accountid.Value = null;
            else
                doc.accountid.Value = Constants.CustomerIdPrefix + row.CustomerID;

            if (row.IsOrderDateNull())
                doc.opened.Value = null;
            else
                doc.opened.Value = row.OrderDate;

            if (row.IsShippedDateNull())
                doc.status.Value = Constants.OrderStatus.Active;
            else
                doc.status.Value = Constants.OrderStatus.Completed;

            //doc.DiscountPercentage.Value = new decimal(0);

            //doc.grossamt.Value = row.IsTotalQuotedPriceNull() ? new decimal(0) : Convert.ToDecimal(row.TotalQuotedPrice);
            doc.discountamt.Value = new decimal(0);
            doc.lineitemdisc.Value = row.IsDiscountAmountNull() ? new decimal(0) : Convert.ToDecimal(row.DiscountAmount);
            doc.nettamt.Value = row.IsTotalNetPriceNull() ? new decimal(0) : Convert.ToDecimal(row.TotalNetPrice);
            doc.freight.Value = row.IsFreightNull() ? new decimal(0) : row.Freight;

            doc.tax.Value = new decimal(0);
            doc.grossamt.Value = doc.nettamt.Value;

            if (row.IsRequiredDateNull())
                doc.deliverydate.Value = null;
            else
                doc.deliverydate.Value = row.RequiredDate;
            if (row.IsEmployeeIDNull())
                doc.salesrepr.Value = null;
            else
                doc.salesrepr.Value = Convert.ToString(row.EmployeeID);

            if (row.IsShipViaNull())
                doc.shippedvia.Value = null;
            else
                doc.shippedvia.Value = row.ShipVia;

            OrderAddress orderAddress = new OrderAddress();
            orderAddress.SetNorthwindAddress(row.IsShipAddressNull() ? "" : row.ShipAddress,
                row.IsShipCityNull() ? "" : row.ShipCity,
                row.IsShipPostalCodeNull() ? "" : row.ShipPostalCode,
                row.IsShipCountryNull() ? "" : row.ShipCountry);

            doc.shipaddress.Value = orderAddress.CrmOrderAddress;

            foreach (DataSets.Order.CalculatedOrderDetailsRow detailRow in detailDataTable.Rows)
            {
                lineItemDoc = GetDocumentLineItem(detailRow, lastToken, config);
                if ((doc.LogState != LogState.Created) && (lineItemDoc.HasNoLogStatus))
                    continue;

                doc.orderitems.Add(lineItemDoc);
            }

            foreach (DataSets.Order.DeletedOrderDetailsRow deletedRow in deletedOrderDetailsDataTable.Rows)
            {
                lineItemDoc = new LineItemDocument();
                lineItemDoc.Id = deletedRow[0].ToString();
                lineItemDoc.LogState = LogState.Deleted;
                doc.orderitems.Add(lineItemDoc);
            }

            return doc;
        }
Пример #2
0
        private AccountDocument GetDocument(AccountDataset.AccountsRow row, Token lastToken, NorthwindConfig config)
        {
            #region Declarations
            CountryCodes countryCodes = new CountryCodes();
            AccountDocument accDoc;
            PersonDocument persDoc;
            PhoneDocument phoneDoc;
            AddressDocument addrDoc;
            Address address;
            Phone phone;
            string identity;
            ContactName contactName;
            #endregion

            identity = row.ID;

            // create Account Doc
            accDoc = new AccountDocument();

            // set the account id
            accDoc.Id = identity;

            // change the the log state regarding the timestamps stored in the northwind database.

            // for an init request the logstate is always created
            if (lastToken.InitRequest)
                accDoc.LogState = LogState.Created;

            // if something wrong, than it is created
            else if (row.IsCreateIDNull() || row.IsModifyIDNull()
                || row.IsCreateUserNull() || row.IsModifyUserNull())
                accDoc.LogState = LogState.Created;

            // the log state is created if the create id is greater
            // than the sequence number of the last token and it was not created by the crm user
            else if ((row.CreateID > lastToken.SequenceNumber)
                && (row.CreateUser != config.CrmUser))
                accDoc.LogState = LogState.Created;

            else if ((row.CreateID == lastToken.SequenceNumber)
                && (row.CreateUser != config.CrmUser)
                && (identity.CompareTo(lastToken.Id.Id) > 0))
                accDoc.LogState = LogState.Created;

            // the log state is modified if the modify id is greater
            // than the sequence number of the last token and it was not created by the crm user
            else if ((row.ModifyID >= lastToken.SequenceNumber) && (row.ModifyUser != config.CrmUser))
                accDoc.LogState = LogState.Updated;

            // set the account type
            //accDoc.type.Value = GetAccountType(identity);

            // set the account name
            accDoc.name.Value = row.IsCompanyNameNull() ? null : row.CompanyName;

            // set the customerSupplierFlag
            accDoc.customerSupplierFlag.Value = row.IsCustomerSupplierFlagNull() ? null : row.CustomerSupplierFlag;

            // set default values if it is no update
            if (accDoc.LogState != LogState.Updated)
            {
                accDoc.onhold.Value = !accDoc.Id.StartsWith(Constants.CustomerIdPrefix);
                accDoc.currencyid.Value = config.CurrencyCode;
            }

            // create person Doc
            persDoc = new PersonDocument();

            // since there is only one person in Northwind, the Identity of the person is the same as
            // the account id
            persDoc.Id = identity;

            // set the log state if the account also has a logstate
            if (!accDoc.HasNoLogStatus)
                persDoc.LogState = accDoc.LogState;

            // set the transaction status for the person doc.
            persDoc.SetTransactionStatus(TransactionStatus.Success);

            // set the first and lst name to null if the contact in northwind is null
            if (row.IsContactNameNull() || string.IsNullOrEmpty(row.ContactName))
            {
                persDoc.firstname.Value = null;
                persDoc.lastname.Value = null;
                persDoc.fullname.Value = null;
            }
            else
            {
                persDoc.fullname.Value = row.ContactName;

                // create an object to splitt the contact name
                contactName = new ContactName();

                // initiate the object with the northwind contact name
                contactName.NorthwindContacName = row.ContactName;

                // get the splitted values
                persDoc.salutation.Value = contactName.CrmSalutation;
                persDoc.firstname.Value = contactName.CrmFirstName;
                persDoc.middlename.Value = contactName.CrmMiddleName;
                persDoc.lastname.Value = contactName.CrmLastName;
                persDoc.suffix.Value = contactName.CrmSuffix;

            }

            if (row.IsContactTitleNull())
                persDoc.title.Value = null;
            else
                persDoc.title.Value = row.ContactTitle;

            // set the person type to billing
            persDoc.primaryperson.Value = "True";

            // add the person to the people collection of the account document
            accDoc.people.Add(persDoc);

            // create Phone Doc
            phoneDoc = new PhoneDocument();

            // since there are exact 2 phone numbers stored in northwind
            // the id for the phone number ist the account id plus a postfix
            phoneDoc.Id = identity + Constants.PhoneIdPostfix;

            // set the log state if the account also has a logstate
            if (!accDoc.HasNoLogStatus)
                phoneDoc.LogState = accDoc.LogState;

            // set the person type to business
            phoneDoc.type.Value = CRMSelections.Link_PersPhon_Business;

            phoneDoc.SetTransactionStatus(TransactionStatus.Success);

            if (!row.IsPhoneNull())
            {
                phoneDoc.fullnumber.Value = row.Phone;

                phone = new Phone();
                phone.NorthwindPhone = row.Phone;
                phoneDoc.countrycode.Value = phone.CrmCountryCode;
                phoneDoc.areacode.Value = phone.CrmAreaCode;
                phoneDoc.number.Value = phone.CrmPhone;
                accDoc.phones.Add(phoneDoc);
            }

            // create Fax Doc
            phoneDoc = new PhoneDocument();
            phoneDoc.Id = identity + Constants.FaxIdPostfix;
            if (!accDoc.HasNoLogStatus)
                phoneDoc.LogState = accDoc.LogState;
            phoneDoc.type.Value = CRMSelections.Link_PersPhon_Fax;
            phoneDoc.SetTransactionStatus(TransactionStatus.Success);
            if (!row.IsFaxNull())
            {
                phoneDoc.fullnumber.Value = row.Fax;
                phone = new Phone();
                phone.NorthwindPhone = row.Fax;
                phoneDoc.countrycode.Value = phone.CrmCountryCode;
                phoneDoc.areacode.Value = phone.CrmAreaCode;
                phoneDoc.number.Value = phone.CrmPhone;
                accDoc.phones.Add(phoneDoc);
            }

            // create Address Doc
            addrDoc = new AddressDocument();
            addrDoc.Id = identity;
            if (!accDoc.HasNoLogStatus)
                addrDoc.LogState = accDoc.LogState;
            //addrDoc.AddressType.Value = CRMSelections.Link_CompAddr_Billing;
            addrDoc.primaryaddress.Value = "True";
            addrDoc.SetTransactionStatus(TransactionStatus.Success);

            if (row.IsAddressNull())
            {
                addrDoc.address1.Value = null;
                addrDoc.address2.Value = null;
                addrDoc.address3.Value = null;
                addrDoc.address4.Value = null;
            }
            else
            {
                address = new Address();
                address.NorthwindAddress = row.Address;
                addrDoc.address1.Value = address.CrmAddressLine1;
                addrDoc.address2.Value = address.CrmAddressLine2;
                addrDoc.address3.Value = address.CrmAddressLine3;
                addrDoc.address4.Value = address.CrmAddressLine4;
            }

            addrDoc.City.Value = row.IsCityNull() ? null : row.City;

            addrDoc.state.Value = row.IsRegionNull() ? null : row.Region;
            if (row.IsCountryNull())
                addrDoc.country.Value = null;
            else
                addrDoc.country.Value = countryCodes.GetCountryCode(row.Country);

            addrDoc.postcode.Value = row.IsPostalCodeNull() ? null : row.PostalCode;

            if (accDoc.Id.StartsWith(Constants.CustomerIdPrefix))
                accDoc.emails = GetEmailsCollectionFromCustomer(accDoc.Id.Substring(Constants.CustomerIdPrefix.Length), lastToken, config);

            accDoc.addresses.Add(addrDoc);

            return accDoc;
        }
        private SalesOrderFeedEntry GetPayload(Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.CalculatedOrdersRow row,
            Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.CalculatedOrderDetailsDataTable detailDataTable,
            NorthwindConfig config)
        {
            #region Declarations
            SalesOrderFeedEntry payload;
            string id;
            CountryCodes countryCodes = new CountryCodes();
            #endregion

            id = row.OrderID.ToString();

            payload = new SalesOrderFeedEntry();
            payload.UUID = GetUuid(id, "", SupportedResourceKinds.salesOrders);
            payload.active = true;

            payload.currency = config.CurrencyCode;

            payload.pricelist = new PriceListFeedEntry();
            payload.pricelist.UUID = GetUuid(id, "", SupportedResourceKinds.priceLists);

            if (!row.IsCustomerIDNull())
            {
                /*payload.tradingAccount = new TradingAccountFeedEntry();
                payload.tradingAccount.Key = Sage.Integration.Northwind.Application.API.Constants.CustomerIdPrefix + row.CustomerID;
                payload.tradingAccount.UUID = GetUuid(payload.tradingAccount.Key, "", SupportedResourceKinds.tradingAccounts);
                payload.tradingAccount.Id = GetSDataId(payload.tradingAccount.Key, SupportedResourceKinds.tradingAccounts);
                payload.tradingAccount.Uri = payload.tradingAccount.Id;*/

                payload.tradingAccount = (TradingAccountFeedEntry)_tradingAccountsFeedEntryWrapper.GetFeedEntry(Sage.Integration.Northwind.Application.API.Constants.CustomerIdPrefix + row.CustomerID);

            }

            if (!row.IsOrderDateNull())
            {
                payload.date = row.OrderDate;
            }

            //payload.lineCount = detailDataTable.Rows.Count;

            payload.discountTotal = row.IsDiscountAmountNull() ? new decimal(0) : Convert.ToDecimal(row.DiscountAmount);

            payload.netTotal = row.IsTotalNetPriceNull() ? new decimal(0) : Convert.ToDecimal(row.TotalNetPrice);

            payload.carrierTotalPrice = row.IsFreightNull() ? new decimal(0) : row.Freight;

            payload.grossTotal = payload.netTotal;

            if (!row.IsRequiredDateNull())
            {
                payload.dueDate = row.RequiredDate;
            }

            if (!row.IsShipViaNull())
            {
                payload.deliveryMethod = row.ShipVia.ToString(); ;
            }

            PostalAddressFeedEntry address = new PostalAddressFeedEntry();
            address.active = true;
            address.address1 = row.IsShipAddressNull() ? null : row.ShipAddress;
            address.country = row.IsShipCountryNull() ? null : row.ShipCountry;
            address.townCity = row.IsShipCityNull() ? null : row.ShipCity;
            address.zipPostCode = row.IsShipPostalCodeNull() ? null : row.ShipPostalCode;
            address.type = postalAddressTypeenum.Shipping;

            payload.postalAddresses = new PostalAddressFeed();
            //TODO: check if valid Address?
            payload.postalAddresses.Entries.Add(address);

            payload.salesOrderLines = new SalesOrderLineFeed();
            foreach (Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.CalculatedOrderDetailsRow detailRow in detailDataTable.Rows)
            {
                SalesOrderLineFeedEntry soPayload = GetLineItem(detailRow, config);
                payload.salesOrderLines.Entries.Add(soPayload);
            }

            return payload;
        }
Пример #4
0
        private SalesOrderPayload GetPayload(DataSets.Order.CalculatedOrdersRow row,
            DataSets.Order.CalculatedOrderDetailsDataTable detailDataTable,
            //DataSets.Order.DeletedOrderDetailsDataTable deletedOrderDetailsDataTable,
            NorthwindConfig config)
        {
            #region Declarations
            SalesOrderPayload payload;
            string id;
            CountryCodes countryCodes = new CountryCodes();
            #endregion

            id = row.OrderID.ToString();

            payload = new SalesOrderPayload();
            payload.LocalID = id;
            payload.SyncUuid = GetUuid(id, "", SupportedResourceKinds.salesOrders);
            payload.SalesOrdertype.active = true;
            payload.SalesOrdertype.applicationID = id;

            payload.SalesOrdertype.currency = config.CurrencyCode;

            payload.ForeignIds.Add("pricelist", Sage.Integration.Northwind.Application.API.Constants.DefaultValues.PriceList.ID);

            if (!row.IsCustomerIDNull())
                payload.ForeignIds.Add("tradingAccount", Sage.Integration.Northwind.Application.API.Constants.CustomerIdPrefix + row.CustomerID);

            if (!row.IsOrderDateNull())
            {
                payload.SalesOrdertype.date = row.OrderDate;
                payload.SalesOrdertype.dateSpecified = true;
            }

            payload.SalesOrdertype.lineCountSpecified = true;
            payload.SalesOrdertype.lineCount = detailDataTable.Rows.Count;

            payload.SalesOrdertype.discountTotalSpecified = true;
            payload.SalesOrdertype.discountTotal = row.IsDiscountAmountNull() ? new decimal(0) : Convert.ToDecimal(row.DiscountAmount);

            payload.SalesOrdertype.netTotalSpecified = true;
            payload.SalesOrdertype.netTotal = row.IsTotalNetPriceNull() ? new decimal(0) : Convert.ToDecimal(row.TotalNetPrice);

            payload.SalesOrdertype.carrierTotalPriceSpecified = true;
            payload.SalesOrdertype.carrierTotalPrice = row.IsFreightNull() ? new decimal(0) : row.Freight;

            payload.SalesOrdertype.grossTotalSpecified = true;
            payload.SalesOrdertype.grossTotal = payload.SalesOrdertype.netTotal;

            if (!row.IsRequiredDateNull())
            {
                payload.SalesOrdertype.dueDateSpecified = true;
                payload.SalesOrdertype.dueDate = row.RequiredDate;
            }

            if (!row.IsShipViaNull())
            {
                payload.SalesOrdertype.deliveryMethod = row.ShipVia.ToString(); ;
            }

            postalAddresstype address = new postalAddresstype();
            address.active = true;
            address.activeSpecified = true;
            address.address1 = row.IsShipAddressNull() ? "" : row.ShipAddress;
            address.applicationID = id;
            address.country = row.IsShipCountryNull() ? "" : row.ShipCountry;
            address.townCity = row.IsShipCityNull() ? "" : row.ShipCity;
            address.zipPostCode = row.IsShipPostalCodeNull() ? "" : row.ShipPostalCode;
            address.type = postalAddressTypeenum.Shipping;

            payload.SalesOrdertype.postalAddresses = new postalAddresstype[1];
            payload.SalesOrdertype.postalAddresses[0] = address;

            payload.SalesOrdertype.salesOrderLines = new salesOrderLinetype[detailDataTable.Rows.Count];
            int index = 0;
            foreach (DataSets.Order.CalculatedOrderDetailsRow detailRow in detailDataTable.Rows)
            {
                SalesOrderLinePayload soPayload = GetLineItem(detailRow, config);
                payload.ForeignIds.Add(
                            String.Format("salesOrderLines[{0}]",
                            index.ToString()),
                            soPayload.LocalID);
                foreach (string key in soPayload.ForeignIds.Keys)//  (int foreignIdIndex = 0; foreignIdIndex <= soPayload.ForeignIds.Count; foreignIdIndex++)
                {
                    string value;
                    if (soPayload.ForeignIds.TryGetValue(key, out value))
                    {
                        payload.ForeignIds.Add(
                            String.Format("salesOrderLines[{0}]/{1}",
                            index.ToString(),
                            key),
                            value);
                    }
                }
                payload.SalesOrdertype.salesOrderLines[index] = soPayload.SalesOrderLinetype;
                index++;
            }

            //foreach (DataSets.Order.DeletedOrderDetailsRow deletedRow in deletedOrderDetailsDataTable.Rows)
            //{
            //    lineItemDoc = new LineItemDocument();
            //    lineItemDoc.Id = deletedRow[0].ToString();
            //    lineItemDoc.LogState = LogState.Deleted;
            //    doc.orderitems.Add(lineItemDoc);
            //}

            return payload;
        }
 public OrderAddress()
 {
     //init the default northwind maxLength
     this.countryCodes = new CountryCodes();
 }