示例#1
0
 /// <summary>
 /// Liberar el objeto COM de acuerdo a buenas prácticas
 /// </summary>
 /// <returns>Bool, Indica el exito de la tarea de liberar la compañia</returns>
 public bool ReleaseCompany()
 {
     //System.Runtime.InteropServices.Marshal.ReleaseComObject(conexion.compania);
     Conn = null;
     SAPConnection.conn = null;
     return(true);
 }
 public SAPConnectionData(string dataBase, string licenceServer, string DatabaseServer, string user, string password, string userBd, string passwordBD, string serverType)
 {
     Conn = new SAPConnection(dataBase, licenceServer, DatabaseServer, user, password, userBd, passwordBD, serverType);
 }
 public SAPConnectionData()
 {
     Conn = SAPConnection.conn;
 }
 /// <summary>
 /// Liberar el objeto COM de acuerdo a buenas prácticas
 /// </summary>
 /// <returns>Bool, Indica el exito de la tarea de liberar la compañia</returns>
 public bool ReleaseCompany()
 {
     //System.Runtime.InteropServices.Marshal.ReleaseComObject(conexion.compania);
     Conn = null;
     SAPConnection.conn = null;
     return true;
 }
        public MarketingDocument Add(SapDocumentType mktgDocType, MarketingDocument document, SAPConnection sapConn)
        {
            Documents doc = null;

            #region Document definition
            switch (mktgDocType)
            {
                case SapDocumentType.SalesInvoice:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oInvoices);
                    break;
                case SapDocumentType.SalesCreditNote:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oCreditNotes);
                    break;
                case SapDocumentType.SalesDelivery:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oDeliveryNotes);
                    break;
                case SapDocumentType.SalesReturn:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oReturns);
                    break;
                case SapDocumentType.SalesOrder:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oOrders);
                    break;
                case SapDocumentType.PurchaseInvoice:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseInvoices);
                    break;
                case SapDocumentType.PurchaseCreditNote:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseCreditNotes);
                    break;
                case SapDocumentType.PurchaseDelivery:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseDeliveryNotes);
                    break;
                case SapDocumentType.PurchaseReturn:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseReturns);
                    break;
                case SapDocumentType.PurchaseOrder:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseOrders);
                    break;
                case SapDocumentType.Quotation:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oQuotations);
                    break;
                default:
                    break;
            }
            #endregion

            #region Document header
            doc.Series = document.serie;
            doc.CardCode = document.cardCode;
            doc.DocDate = document.docDate;
            doc.DocDueDate = document.docDueDate;
            doc.TaxDate = document.taxDate;

            if (!string.IsNullOrEmpty(document.numAtCard))
                doc.NumAtCard = document.numAtCard;

            if (!string.IsNullOrEmpty(document.shipToCode))
                doc.ShipToCode = document.shipToCode;

            if (!string.IsNullOrEmpty(document.payToCode))
                doc.PayToCode = document.payToCode;

            if (document.groupNum != null)
                doc.GroupNumber = (int)document.groupNum;

            if (!string.IsNullOrEmpty(document.comments))
                doc.Comments = document.comments;

            if (document.slpCode != null)
                doc.SalesPersonCode = (int)document.slpCode;

            #region UDF's
            foreach (UserDefinedField item in document.userDefinedFields)
            {
                if (!string.IsNullOrEmpty(item.value))
                    switch (item.type)
                    {
                        case UdfType.Alphanumeric:
                            doc.UserFields.Fields.Item(item.name).Value = item.value;
                            break;
                        case UdfType.Integer:
                            doc.UserFields.Fields.Item(item.name).Value = int.Parse(item.value);
                            break;
                        case UdfType.Double:
                            doc.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                            break;
                        case UdfType.Datetime:
                            doc.UserFields.Fields.Item(item.name).Value = DateTime.Parse(item.value);
                            break;
                        case UdfType.Price:
                            doc.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                            break;
                        case UdfType.Text:
                            doc.UserFields.Fields.Item(item.name).Value = item.value;
                            break;
                        default:
                            break;
                    }
            }
            #endregion

            #endregion

            #region Document lines
            foreach (MarketingDocumentLine line in document.lines)
            {
                if (line.baseType != 202)
                    doc.Lines.ItemCode = line.itemCode;

                doc.Lines.Quantity = line.quantity;
                doc.Lines.WarehouseCode = line.whsCode;
                if (line.price != 0)
                    doc.Lines.UnitPrice = line.price;

                if (!string.IsNullOrEmpty(line.unitMsr))
                    doc.Lines.MeasureUnit = line.unitMsr;

                if (!string.IsNullOrEmpty(line.taxCode))
                    doc.Lines.TaxCode = line.taxCode;

                if (!string.IsNullOrEmpty(line.ocrCode))
                    doc.Lines.CostingCode = line.ocrCode;

                if (line.numPerMsr != 0)
                    doc.Lines.UnitsOfMeasurment = line.numPerMsr;

                if (line.baseEntry != 0)
                {
                    doc.Lines.BaseEntry = line.baseEntry;
                    doc.Lines.BaseLine = line.baseLine;
                    doc.Lines.BaseType = line.baseType;
                }

                #region UDF's
                foreach (UserDefinedField item in line.userDefinedFields)
                {
                    if (!string.IsNullOrEmpty(item.value))
                        switch (item.type)
                        {
                            case UdfType.Alphanumeric:
                                doc.Lines.UserFields.Fields.Item(item.name).Value = item.value;
                                break;
                            case UdfType.Integer:
                                doc.UserFields.Fields.Item(item.name).Value = int.Parse(item.value);
                                break;
                            case UdfType.Double:
                                doc.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                                break;
                            case UdfType.Datetime:
                                doc.Lines.UserFields.Fields.Item(item.name).Value = DateTime.Parse(item.value);
                                break;
                            case UdfType.Price:
                                doc.Lines.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                                break;
                            case UdfType.Text:
                                doc.Lines.UserFields.Fields.Item(item.name).Value = item.value;
                                break;
                            default:
                                break;
                        }
                }
                #endregion

                #region Batchs
                if (line.batchNumbers != null)
                    foreach (BatchNumber batchNumber in line.batchNumbers)
                    {
                        doc.Lines.BatchNumbers.BatchNumber = batchNumber.DistNumber;
                        doc.Lines.BatchNumbers.Quantity = batchNumber.Quantity;
                        doc.Lines.BatchNumbers.ExpiryDate = batchNumber.ExpDate;
                        doc.Lines.BatchNumbers.Add();
                    }
                #endregion

                #region Series
                if (line.serialNumbers != null)
                    foreach (SerialNumber serie in line.serialNumbers)
                    {

                        doc.Lines.SerialNumbers.InternalSerialNumber = serie.DisNumber;
                        doc.Lines.SerialNumbers.Add();
                    }
                doc.Lines.Add();
                #endregion
            }
            #endregion

            if (doc.Add() != 0)
            {
                throw new SAPException(sapConn.company.GetLastErrorCode(), sapConn.company.GetLastErrorDescription());
            }
            document.docEntry = Convert.ToInt32(sapConn.company.GetNewObjectKey());
            return document;
        }
        public void Cancel(SapDocumentType mktgDocType, MarketingDocument document, SAPConnection sapConn)
        {
            Documents doc = null;

            #region Document definition
            switch (mktgDocType)
            {
                case SapDocumentType.SalesInvoice:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oInvoices);
                    break;
                case SapDocumentType.SalesCreditNote:
                    doc = doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oCreditNotes);
                    break;
                case SapDocumentType.SalesDelivery:
                    doc = doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oDeliveryNotes);
                    break;
                case SapDocumentType.SalesReturn:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oReturns);
                    break;
                case SapDocumentType.SalesOrder:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oOrders);
                    break;
                case SapDocumentType.PurchaseInvoice:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseInvoices);
                    break;
                case SapDocumentType.PurchaseCreditNote:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseCreditNotes);
                    break;
                case SapDocumentType.PurchaseDelivery:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseDeliveryNotes);
                    break;
                case SapDocumentType.PurchaseReturn:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseReturns);
                    break;
                case SapDocumentType.PurchaseOrder:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseOrders);
                    break;
                case SapDocumentType.Quotation:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oQuotations);
                    break;
                default:
                    break;
            }
            #endregion


            doc.GetByKey(document.docEntry);

            if (doc.DocumentStatus == BoStatus.bost_Close)
                throw new SAPException(-8900, "El pedido está cerrado");

            if (doc.Cancel() != 0)
                throw new SAPException(sapConn.company.GetLastErrorCode(), SAPConnection.conn.company.GetLastErrorDescription());
        }
示例#7
0
 public SAPConnectionData(string dataBase, string licenceServer, string DatabaseServer, string user, string password, string userBd, string passwordBD, string serverType)
 {
     Conn = new SAPConnection(dataBase, licenceServer, DatabaseServer, user, password, userBd, passwordBD, serverType);
 }
示例#8
0
 public SAPConnectionData()
 {
     Conn = SAPConnection.conn;
 }
        public void Add(BusinessPartner partner, SAPConnection sapConn)
        {
            BusinessPartners bp; //= new BusinessPartners();
            bp = (BusinessPartners)sapConn.company.GetBusinessObject(BoObjectTypes.oBusinessPartners);

            #region Basic Data
            bp.CardCode = partner.cardCode;

            switch (partner.cardType)
            {
                case CardType.Customer:
                    bp.CardType = BoCardTypes.cCustomer;
                    break;
                case CardType.Supplier:
                    bp.CardType = BoCardTypes.cSupplier;
                    break;
                case CardType.Lead:
                    bp.CardType = BoCardTypes.cLid;
                    break;
                default:
                    break;
            }

            bp.CardName = partner.cardName;

            if (!string.IsNullOrEmpty(partner.cardFName))
                bp.CardForeignName = partner.cardFName;

            bp.GroupCode = partner.groupCode;
            bp.FederalTaxID = partner.licTradNum;
            bp.Currency = partner.currency;
            #endregion

            #region General tab
            bp.Phone1 = partner.phone1;

            if (!string.IsNullOrEmpty(partner.phone2))
                bp.Phone2 = partner.phone2;
            if (!string.IsNullOrEmpty(partner.cellular))
                bp.Cellular = partner.cellular;
            if (!string.IsNullOrEmpty(partner.fax))
                bp.Fax = partner.fax;
            if (!string.IsNullOrEmpty(partner.e_Mail))
                bp.EmailAddress = partner.e_Mail;
            if (!string.IsNullOrEmpty(partner.password))
                bp.Password = partner.password;
            if (partner.slpCode != 0)
                bp.SalesPersonCode = partner.slpCode;
            if (partner.territory != null)
                bp.Territory = (int)partner.territory;

            /*
             * DI-Api not expose agent Code field
            if (!string.IsNullOrEmpty(partner.agentCode))
                bp.a = partner.phone2;
             * 
            */

            #endregion

            #region Payment temrs tab
            if (partner.groupNum != null)
                bp.PayTermsGrpCode = (int)partner.groupNum;
            if (partner.intrstRate != null)
                bp.IntrestRatePercent = (double)partner.intrstRate;
            if (partner.listNum != null)
                bp.PriceListNum = (int)partner.listNum;
            if (partner.discount != null)
                bp.DiscountPercent = (double)partner.discount;
            if (partner.creditLine != null)
                bp.CreditLimit = (double)partner.creditLine;
            if (partner.debitLine != null)
                bp.MaxCommitment = (double)partner.debitLine;
            if (!string.IsNullOrEmpty(partner.dunTerm))
                bp.DunningTerm = partner.dunTerm;
            #endregion

            #region Accounting tab
            #region general subtab
            if (!string.IsNullOrEmpty(partner.debPayAcct))
                bp.DebitorAccount = partner.debPayAcct;

            if (partner.blockDunn)
                bp.BlockDunning = BoYesNoEnum.tYES;
            else
                bp.BlockDunning = BoYesNoEnum.tNO;

            #endregion
            #region tax subtab
            if (partner.wtLiable)
            {
                bp.SubjectToWithholdingTax = BoYesNoEnum.tYES;
            }
            #endregion
            #endregion

            #region Propierties tab
            bp.set_Properties(1, partner.qryGroup1 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(2, partner.qryGroup2 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(3, partner.qryGroup3 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(4, partner.qryGroup4 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(5, partner.qryGroup5 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(6, partner.qryGroup6 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(7, partner.qryGroup7 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(8, partner.qryGroup8 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(9, partner.qryGroup9 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(10, partner.qryGroup10 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(11, partner.qryGroup11 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(12, partner.qryGroup12 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(13, partner.qryGroup13 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(14, partner.qryGroup14 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(15, partner.qryGroup15 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(16, partner.qryGroup16 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(17, partner.qryGroup17 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(18, partner.qryGroup18 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(19, partner.qryGroup19 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(20, partner.qryGroup20 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(21, partner.qryGroup21 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(22, partner.qryGroup22 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(23, partner.qryGroup23 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(24, partner.qryGroup24 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(25, partner.qryGroup25 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(26, partner.qryGroup26 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(27, partner.qryGroup27 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(28, partner.qryGroup28 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(29, partner.qryGroup29 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(30, partner.qryGroup30 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(31, partner.qryGroup31 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(32, partner.qryGroup32 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(33, partner.qryGroup33 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(34, partner.qryGroup34 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(35, partner.qryGroup35 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(36, partner.qryGroup36 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(37, partner.qryGroup37 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(38, partner.qryGroup38 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(39, partner.qryGroup39 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(40, partner.qryGroup40 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(41, partner.qryGroup41 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(42, partner.qryGroup42 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(43, partner.qryGroup43 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(44, partner.qryGroup44 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(45, partner.qryGroup45 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(46, partner.qryGroup46 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(47, partner.qryGroup47 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(48, partner.qryGroup48 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(49, partner.qryGroup49 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(50, partner.qryGroup50 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(51, partner.qryGroup51 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(52, partner.qryGroup52 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(53, partner.qryGroup53 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(54, partner.qryGroup54 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(55, partner.qryGroup55 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(56, partner.qryGroup56 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(57, partner.qryGroup57 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(58, partner.qryGroup58 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(59, partner.qryGroup59 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(60, partner.qryGroup60 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(61, partner.qryGroup61 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(62, partner.qryGroup62 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(63, partner.qryGroup63 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            bp.set_Properties(64, partner.qryGroup64 ? BoYesNoEnum.tYES : BoYesNoEnum.tNO);
            #endregion

            #region Remarks tab
            if (!string.IsNullOrEmpty(partner.freeText))
                bp.FreeText = partner.freeText;
            #endregion

            #region UDF's
            if (partner.userDefinedFields != null)
                foreach (UserDefinedField item in partner.userDefinedFields)
                {
                    if (!string.IsNullOrEmpty(item.value))
                        switch (item.type)
                        {
                            case UdfType.Alphanumeric:
                                bp.UserFields.Fields.Item(item.name).Value = item.value;
                                break;
                            case UdfType.Integer:
                                bp.UserFields.Fields.Item(item.name).Value = int.Parse(item.value);
                                break;
                            case UdfType.Double:
                                bp.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                                break;
                            case UdfType.Datetime:
                                bp.UserFields.Fields.Item(item.name).Value = DateTime.Parse(item.value);
                                break;
                            case UdfType.Price:
                                bp.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                                break;
                            case UdfType.Text:
                                bp.UserFields.Fields.Item(item.name).Value = item.value;
                                break;
                            default:
                                break;
                        }
                }
            #endregion

            if (bp.Add() != 0)
                throw new SAPException(sapConn.company.GetLastErrorCode(), sapConn.company.GetLastErrorDescription());
        }
        public void AddBusinessPartnerWithholdingTax(BusinessPartnerWithholdingTax withholdingTax, SAPConnection sapConn)
        {
            List<BusinessPartnerWithholdingTax> bpWithholdingTaxes = GetBusinessPartnerWithholdingTaxList(withholdingTax.cardCode);

            BusinessPartners bp; //= new BusinessPartners();
            bp = (BusinessPartners)sapConn.company.GetBusinessObject(BoObjectTypes.oBusinessPartners);

            bp.GetByKey(withholdingTax.cardCode);
            int wtQty = bpWithholdingTaxes.Count();

            bp.BPWithholdingTax.Add();
            bp.BPWithholdingTax.SetCurrentLine(wtQty);
            bp.BPWithholdingTax.WTCode = withholdingTax.wtCode;

            bp.Update();
        }
        public void AddContact(ContactEmployee contact, SAPConnection sapConn)
        {
            List<ContactEmployee> contacts = GetContactList(contact.cardCode);

            BusinessPartners bp; //= new BusinessPartners();
            bp = (BusinessPartners)sapConn.company.GetBusinessObject(BoObjectTypes.oBusinessPartners);

            bp.GetByKey(contact.cardCode);
            int contactQty = contacts.Count();

            bp.ContactEmployees.Add();
            bp.ContactEmployees.SetCurrentLine(contactQty);
            bp.ContactEmployees.Name = contact.name;

            if (!string.IsNullOrEmpty(contact.firstName))
                bp.ContactEmployees.FirstName = contact.firstName;

            if (!string.IsNullOrEmpty(contact.middleName))
                bp.ContactEmployees.MiddleName = contact.middleName;

            if (!string.IsNullOrEmpty(contact.lastName))
                bp.ContactEmployees.LastName = contact.lastName;

            if (!string.IsNullOrEmpty(contact.title))
                bp.ContactEmployees.Title = contact.title;

            if (!string.IsNullOrEmpty(contact.position))
                bp.ContactEmployees.Position = contact.position;

            if (!string.IsNullOrEmpty(contact.address))
                bp.ContactEmployees.Address = contact.address;

            if (!string.IsNullOrEmpty(contact.telephone1))
                bp.ContactEmployees.Phone1 = contact.telephone1;

            if (!string.IsNullOrEmpty(contact.telephone2))
                bp.ContactEmployees.Phone2 = contact.telephone2;

            if (!string.IsNullOrEmpty(contact.cellolar))
                bp.ContactEmployees.MobilePhone = contact.cellolar;

            if (!string.IsNullOrEmpty(contact.e_mail))
                bp.ContactEmployees.E_Mail = contact.e_mail;

            bp.Update();
        }
        public void AddAddress(BusinessPartnerAddress address, SAPConnection sapConn)
        {
            int addressQty = GetAddressList(address.cardCode, AddressType.BillTo).Count() + GetAddressList(address.cardCode, AddressType.ShipTo).Count();

            BusinessPartners bp; //= new BusinessPartners();
            bp = (BusinessPartners)sapConn.company.GetBusinessObject(BoObjectTypes.oBusinessPartners);
            bp.GetByKey(address.cardCode);

            bp.Addresses.Add();
            bp.Addresses.SetCurrentLine(addressQty);

            bp.Addresses.AddressType = address.addressType == AddressType.BillTo ? BoAddressType.bo_BillTo : BoAddressType.bo_ShipTo;
            bp.Addresses.AddressName = address.address;

            if (!string.IsNullOrEmpty(address.street))
                bp.Addresses.Street = address.street;

            if (!string.IsNullOrEmpty(address.block))
                bp.Addresses.Block = address.block;

            if (!string.IsNullOrEmpty(address.zipCode))
                bp.Addresses.ZipCode = address.zipCode;

            if (!string.IsNullOrEmpty(address.city))
                bp.Addresses.City = address.city;

            if (!string.IsNullOrEmpty(address.country))
                bp.Addresses.Country = address.country;

            if (!string.IsNullOrEmpty(address.county))
                bp.Addresses.County = address.county;

            if (!string.IsNullOrEmpty(address.taxCode))
                bp.Addresses.TaxCode = address.taxCode;

            if (!string.IsNullOrEmpty(address.streetNo))
                bp.Addresses.StreetNo = address.streetNo;

            if (!string.IsNullOrEmpty(address.state))
                bp.Addresses.State = address.state;

            #region UDF's
            if (address.UserDefinedFields != null)
                foreach (UserDefinedField item in address.UserDefinedFields)
                {
                    if (!string.IsNullOrEmpty(item.value))
                        switch (item.type)
                        {
                            case UdfType.Alphanumeric:
                                bp.UserFields.Fields.Item(item.name).Value = item.value;
                                break;
                            case UdfType.Integer:
                                bp.UserFields.Fields.Item(item.name).Value = int.Parse(item.value);
                                break;
                            case UdfType.Double:
                                bp.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                                break;
                            case UdfType.Datetime:
                                bp.UserFields.Fields.Item(item.name).Value = DateTime.Parse(item.value);
                                break;
                            case UdfType.Price:
                                bp.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                                break;
                            case UdfType.Text:
                                bp.UserFields.Fields.Item(item.name).Value = item.value;
                                break;
                            default:
                                break;
                        }
                }
            #endregion

            bp.Update();
        }