Beispiel #1
0
        /// <summary>
        /// serialize customer address
        /// </summary>
        /// <param name="filename"></param>
        public static void SerializeCustomerAddressObject(string filename)
        {
            try
            {
                // Instantiate an eConnectType schema object
                eConnectType eConnect = new eConnectType();

                // Instantiate a RMCustomerAddressType schema object
                RMCustomerAddressType addressType = new RMCustomerAddressType();

                // Instantiate a taCreateCustomerAddress_ItemsTaCreateCustomerAddress XML node object
                taCreateCustomerAddress_ItemsTaCreateCustomerAddress address = new taCreateCustomerAddress_ItemsTaCreateCustomerAddress();

                // Create an XML serializer object
                XmlSerializer serializer = new XmlSerializer(eConnect.GetType());

                // Populate elements of the taUpdateCreateCustomerRcd XML node object
                address.CUSTNMBR = "Customer001";
                //address.CUSTNAME = "Customer 1";
                //address.ADDRESS1 = "2002 60th St SW";
                //address.ADRSCODE = "Primary";
                //address.CITY = "NewCity";
                //address.ZIPCODE = "52302";

                // Populate the RMCustomerAddressType schema with the taCreateCustomerAddress_ItemsTaCreateCustomerAddress XML node
                addressType.taCreateCustomerAddress_Items = new taCreateCustomerAddress_ItemsTaCreateCustomerAddress[1] {
                    address
                };
                RMCustomerAddressType[] customerAddress = { addressType };

                // Populate the eConnectType object with the RMCustomerAddressType schema object
                eConnect.RMCustomerAddressType = customerAddress;

                // Create objects to create file and write the customer XML to the file
                FileStream    fs     = new FileStream(filename, FileMode.Create);
                XmlTextWriter writer = new XmlTextWriter(fs, new UTF8Encoding());

                // Serialize the eConnectType object to a file using the XmlTextWriter.
                serializer.Serialize(writer, eConnect);
                writer.Close();
            }
            // catch any errors that occur and display them to the console
            catch (System.Exception ex)
            {
                Console.Write(ex.ToString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// save customer address
        /// </summary>
        /// <param name="newAddress"></param>
        /// <returns></returns>
        public OperationResult SaveCustomerAddress(RM00102_CustomerAddress newAddress)
        {
            var operationResult = new OperationResult();

            var existingAddress = _dynamicsContext.RM00102_CustomerAddress.FirstOrDefault(x => x.ADDRESS1.ToLower() == newAddress.ADDRESS1.ToLower());

            if (existingAddress == null)
            {
                logger.Debug("Customer Address is being created...");

                string sCustomerDocument;
                string sXsdSchema;
                string sConnectionString;

                using (eConnectMethods e = new eConnectMethods())
                {
                    try
                    {
                        //// Create the vendor data file
                        //SerializeVendorObject("Vendor.xml", foundry);

                        //// Use an XML document to create a string representation of the customer
                        //XmlDocument xmldoc = new XmlDocument();
                        //xmldoc.Load("Vendor.xml");
                        //sCustomerDocument = xmldoc.OuterXml;

                        //// Specify the Microsoft Dynamics GP server and database in the connection string
                        //sConnectionString = @"data source=localhost;initial catalog=TWO;integrated security=SSPI;persist security info=False;packet size=4096";

                        //// Create an XML Document object for the schema
                        //XmlDocument XsdDoc = new XmlDocument();

                        //// Create a string representing the eConnect schema
                        //sXsdSchema = XsdDoc.OuterXml;

                        //// Pass in xsdSchema to validate against.
                        //e.CreateEntity(sConnectionString, sCustomerDocument);

                        // Instantiate a taCreateCustomerAddress_ItemsTaCreateCustomerAddress XML node object
                        taCreateCustomerAddress_ItemsTaCreateCustomerAddress address = new taCreateCustomerAddress_ItemsTaCreateCustomerAddress();

                        //Populate elements of the taCreateCustomerAddress_ItemsTaCreateCustomerAddress XML node object
                        address.ADRSCODE       = newAddress.ADRSCODE;
                        address.CUSTNMBR       = newAddress.CUSTNMBR;
                        address.UpdateIfExists = 0;

                        // Instantiate a RMCustomerAddressType schema object
                        RMCustomerAddressType addresstype = new RMCustomerAddressType();

                        // Populate the RMCustomerAddressType schema with the taCreateCustomerAddress_Items XML node
                        addresstype.taCreateCustomerAddress_Items = new taCreateCustomerAddress_ItemsTaCreateCustomerAddress[1] {
                            address
                        };
                        RMCustomerAddressType[] customerAddress = { addresstype };

                        // Instantiate an eConnectType schema object
                        eConnectType eConnect = new eConnectType();

                        // Instantiate a Memory Stream object
                        MemoryStream memoryStream = new MemoryStream();

                        // Create an XML serializer object
                        XmlSerializer serializer = new XmlSerializer(eConnect.GetType());

                        // Populate the eConnectType object with the RMCustomerAddressType schema object
                        eConnect.RMCustomerAddressType = customerAddress;

                        // Serialize the eConnectType.
                        serializer.Serialize(memoryStream, eConnect);

                        // Reset the position of the memory stream to the start.
                        memoryStream.Position = 0;

                        // Create an XmlDocument from the serialized eConnectType in memory.
                        XmlDocument xmlDocument = new XmlDocument();
                        xmlDocument.Load(memoryStream);
                        memoryStream.Close();

                        // Call eConnect to process the XmlDocument.
                        e.CreateEntity(_dynamicsConnection, xmlDocument.OuterXml);

                        operationResult.Success = true;
                        operationResult.Message = "Success";
                    }
                    // The eConnectException class will catch eConnect business logic errors.
                    // display the error message on the console
                    catch (eConnectException exc)
                    {
                        Console.Write(exc.ToString());
                        operationResult.Success = false;
                        operationResult.Message = "Error";
                        logger.ErrorFormat("Error saving new customer address: {0} ", exc.ToString());
                    }
                    // Catch any system error that might occurr.
                    // display the error message on the console
                    catch (System.Exception ex)
                    {
                        Console.Write(ex.ToString());
                        operationResult.Success = false;
                        operationResult.Message = "Error";
                        logger.ErrorFormat("Error saving new customer address: {0} ", ex.ToString());
                    }
                    finally
                    {
                        // Call the Dispose method to release the resources
                        // of the eConnectMethds object
                        e.Dispose();
                    }
                } // end of using statement
            }
            else
            {
                operationResult.Success = false;
                operationResult.Message = "Duplicate Entry";
            }

            return(operationResult);
        }
        public string CreateCustomerAddress(AccountAddress address)  // string path
        {
            try
            {
                // datos de la address
                taCreateCustomerAddress_ItemsTaCreateCustomerAddress add = new taCreateCustomerAddress_ItemsTaCreateCustomerAddress();
                
                add.CUSTNMBR = address.Account.AccountCode;
                add.ADRSCODE = address.ErpCode;
                add.ADDRESS1 = address.AddressLine1;
                add.ADDRESS2 = address.AddressLine2;
                add.ADDRESS3 = address.AddressLine3;
                add.CNTCPRSN = address.ContactPerson;
                add.PHNUMBR1 = address.Phone1;
                add.PHNUMBR2 = address.Phone2;
                add.PHNUMBR3 = address.Phone3;
                add.COUNTRY = address.Country;
                add.STATE = address.State;
                add.CITY = address.City;
                add.ZIPCODE = address.ZipCode;
                add.UpdateIfExists = 1;  //Update If Exists

                RMCustomerAddressType addType = new RMCustomerAddressType();
                addType.taCreateCustomerAddress_Items = new taCreateCustomerAddress_ItemsTaCreateCustomerAddress[] { add };

                RMCustomerAddressType[] arrAddTypes = { addType };

                //Create an eConnect XML document object and populate 
                eConnectType eConnect = new eConnectType();
                eConnect.RMCustomerAddressType = arrAddTypes;

                //Serialize the XML document to the file
                XmlSerializer serializer = new XmlSerializer(typeof(eConnectType));
                StringWriter writer = new StringWriter();
                serializer.Serialize(writer, eConnect);

                DynamicsGP_ec.SendData(writer.ToString()); 
                
                return address.Account.AccountCode;

            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("CreateCustomerAddress", ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                throw;
            }

            
        }