private string SerializeCustomerChild(taUpdateCreateCustomerRcd rmcustomer, taParentIDChild_ItemsTaParentIDChild[] rmchildren) { try { RMCustomerMasterType customerMasterType = new RMCustomerMasterType(); eConnectType eConnect = new eConnectType(); customerMasterType.taUpdateCreateCustomerRcd = rmcustomer; //customerMasterType.taCreateParentID = rmparent; customerMasterType.taParentIDChild_Items = rmchildren; RMCustomerMasterType[] Customers = { customerMasterType }; eConnect.RMCustomerMasterType = Customers; MemoryStream ms = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(eConnect.GetType()); serializer.Serialize(ms, eConnect); ms.Position = 0; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(ms); string CustomerEntity = xmldoc.OuterXml; return(CustomerEntity); } catch (XmlException) { throw; } catch (Exception) { throw; } }
public void armaClienteEconn(ExcelWorksheet hojaXl, int fila) { try { _Customer = new taUpdateCreateCustomerRcd(); _CustomerType = new RMCustomerMasterType(); _Customer.CUSTNMBR = hojaXl.Cells[fila, _colIdImpuestoCliente].Value.ToString().Trim().Replace(".", String.Empty).Replace("-", String.Empty); _Customer.CUSTNAME = hojaXl.Cells[fila, _colCUSTNAME].Value.ToString().Trim(); _Customer.CUSTCLAS = _ClienteDefaultCUSTCLAS; _Customer.ADRSCODE = "MAIN"; if (_colIdImpuestoCliente > 0) { _Customer.TXRGNNUM = hojaXl.Cells[fila, _colIdImpuestoCliente].Value.ToString().Trim(); } _Customer.UpdateIfExists = 0; _Customer.UseCustomerClass = 1; _CustomerType.taUpdateCreateCustomerRcd = _Customer; _arrCustomerType = new RMCustomerMasterType[] { _CustomerType }; } catch (Exception) { throw; } }
private taUpdateCreateCustomerRcd SetCustomerValues(RMCustomer customer) { var pmCustomer = new taUpdateCreateCustomerRcd(); try { pmCustomer.CUSTNMBR = customer.CUSTNMBR; pmCustomer.HOLD = customer.HOLD.GetValueOrDefault(); pmCustomer.INACTIVE = customer.INACTIVE.GetValueOrDefault(); pmCustomer.CUSTNAME = customer.CUSTNAME; pmCustomer.SHRTNAME = customer.SHRTNAME; pmCustomer.STMTNAME = customer.STMTNAME; pmCustomer.CUSTCLAS = customer.CUSTCLASS; pmCustomer.ADRSCODE = customer.ADRSCODE; pmCustomer.CNTCPRSN = customer.CNTCPRSN; pmCustomer.ADDRESS1 = customer.ADDRESS1; pmCustomer.ADDRESS2 = customer.ADDRESS2; pmCustomer.ADDRESS3 = customer.ADDRESS3; pmCustomer.CITY = customer.CITY; pmCustomer.STATE = customer.STATE; pmCustomer.ZIPCODE = customer.ZIPCODE; pmCustomer.CCode = customer.CCode; pmCustomer.COUNTRY = customer.COUNTRY; pmCustomer.PHNUMBR1 = customer.PHNUMBR1; pmCustomer.PHNUMBR2 = customer.PHNUMBR2; pmCustomer.PHNUMBR3 = customer.PHNUMBR3; pmCustomer.FAX = customer.FAX; pmCustomer.TAXSCHID = customer.TAXSCHID; pmCustomer.SLPRSNID = customer.SLPRSNID; pmCustomer.SALSTERR = customer.SALESTERR; pmCustomer.USERDEF1 = customer.USERDEF1; pmCustomer.USERDEF2 = customer.USERDEF2; pmCustomer.CRLMTTYP = customer.CRLMTTYP.GetValueOrDefault(); pmCustomer.CRLMTPER = customer.CRLMTPER.GetValueOrDefault(); pmCustomer.CRLMTAMT = customer.CRLMTAMT.GetValueOrDefault(); pmCustomer.TXRGNNUM = customer.TXRGNNUM; pmCustomer.CURNCYID = customer.CURNCYID; pmCustomer.CHEKBKID = customer.CHEKBKID; pmCustomer.UseCustomerClass = customer.UseCustomerClass.GetValueOrDefault(); pmCustomer.CreateAddress = customer.CreateAddress.GetValueOrDefault(); pmCustomer.INTEGRATIONID = customer.INTEGRATIONID; pmCustomer.UpdateIfExists = customer.UpdateIfExists.GetValueOrDefault(); return(pmCustomer); } catch (Exception) { throw; } }
/// <summary> /// serialize customer /// </summary> /// <param name="filename"></param> private void SerializeCustomerObject(string filename) { try { // Instantiate an eConnectType schema object eConnectType eConnect = new eConnectType(); // Instantiate a RMCustomerMasterType schema object RMCustomerMasterType customerType = new RMCustomerMasterType(); // Instantiate a taUpdateCreateCustomerRcd XML node object taUpdateCreateCustomerRcd customer = new taUpdateCreateCustomerRcd(); // Create an XML serializer object XmlSerializer serializer = new XmlSerializer(eConnect.GetType()); // Populate elements of the taUpdateCreateCustomerRcd XML node object customer.CUSTNMBR = "Customer001"; customer.CUSTNAME = "Customer 1"; customer.ADDRESS1 = "2002 60th St SW"; customer.ADRSCODE = "Primary"; customer.CITY = "NewCity"; customer.ZIPCODE = "52302"; // Populate the RMCustomerMasterType schema with the taUpdateCreateCustomerRcd XML node customerType.taUpdateCreateCustomerRcd = customer; RMCustomerMasterType[] customerMaster = { customerType }; // Populate the eConnectType object with the RMCustomerMasterType schema object eConnect.RMCustomerMasterType = customerMaster; // 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()); } }
/// <summary> /// save new customer /// </summary> /// <param name="newCustomer"></param> /// <returns></returns> public OperationResult SaveCustomer(RM00101_Customer newCustomer) { var operationResult = new OperationResult(); var existingCustomer = _dynamicsContext.RM00101_Customer.FirstOrDefault(x => x.CUSTNMBR.Replace(" ", string.Empty) == newCustomer.CUSTNMBR); if (existingCustomer == null) { logger.Debug("Customer 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 taUpdateCreateCustomerRcd XML node object taUpdateCreateCustomerRcd customer = new taUpdateCreateCustomerRcd(); //Populate elements of the taUpdateCreateVendorRcd XML node object customer.CUSTNMBR = newCustomer.CUSTNMBR; customer.UseCustomerClass = 1; customer.CUSTCLAS = "blah"; customer.UpdateIfExists = 0; // Instantiate a RMCustomerMasterType schema object RMCustomerMasterType customertype = new RMCustomerMasterType(); // Populate the RMCustomerMasterType schema with the taUpdateCreateCustomerRcd XML node customertype.taUpdateCreateCustomerRcd = customer; RMCustomerMasterType[] customerMaster = { customertype }; // 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 PMVendorMasterType schema object eConnect.RMCustomerMasterType = customerMaster; // 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: {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: {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 static bool CheckeConnectCustomer(string gpDatabase, string gpCustomerID, ref int errorNumber, ref string errorMessage) { try { //Create / update test customer to check eConnect status taUpdateCreateCustomerRcd customer = new taUpdateCreateCustomerRcd(); customer.CUSTNMBR = gpCustomerID; customer.HOLD = 1; customer.HOLDSpecified = true; customer.INACTIVE = 1; customer.INACTIVESpecified = true; customer.CUSTNAME = "eConnect Status Test GP Web API"; customer.CNTCPRSN = "eConnect Status Test"; customer.ADRSCODE = "MAILING"; customer.ADDRESS1 = "eConnect Status Test"; customer.ADDRESS2 = "eConnect Status Test"; customer.ADDRESS3 = "eConnect Status Test"; customer.CITY = "eConnect Test"; customer.STATE = "TEST"; customer.ZIPCODE = "00000"; customer.COMMENT1 = "Updated " + DateTime.Now; customer.UpdateIfExists = 1; RMCustomerMasterType RMCust = new RMCustomerMasterType(); RMCust.taUpdateCreateCustomerRcd = customer; RMCustomerMasterType[] RMCustType = { RMCust }; eConnectType eConnect = new eConnectType(); eConnect.RMCustomerMasterType = RMCustType; MemoryStream memoryStream = new MemoryStream(); XmlSerializer xmlSerializer = new XmlSerializer(eConnect.GetType()); xmlSerializer.Serialize(memoryStream, eConnect); memoryStream.Position = 0; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(memoryStream); memoryStream.Close(); string response = string.Empty; bool returnValue = CreateEntity(ref response, xmlDocument.OuterXml, gpDatabase); if (returnValue == true) { errorNumber = 0; errorMessage = string.Empty; return(true); } else { gpCustomerID = string.Empty; errorNumber = 520; errorMessage = "Failed to import eConnect test customer: " + response; return(false); } } catch (Exception ex) { gpCustomerID = string.Empty; errorNumber = 529; errorMessage = "An unexpected error occurred in CheckeConnect: " + ex.Message; return(false); } }
public String CreateCustomer(Account customer) { try { // datos de la address taUpdateCreateCustomerRcd record = new taUpdateCreateCustomerRcd { CUSTNAME = customer.Name, CUSTNMBR = customer.AccountCode, //CNTCPRSN = customer.ContactPerson, //PHNUMBR1 = customer.Phone, USERDEF1 = customer.UserDefine1, USERDEF2 = customer.UserDefine2, USRDEFND3 = customer.UserDefine3, COMMENT1 = customer.UserDefine1, UpdateIfExists = 0 }; RMCustomerMasterType eType = new RMCustomerMasterType(); eType.taUpdateCreateCustomerRcd = record; RMCustomerMasterType[] arrCustTypes = { eType }; //Create an eConnect XML document object and populate eConnectType eConnect = new eConnectType(); eConnect.RMCustomerMasterType = arrCustTypes; //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()); if (customer.AccountAddresses != null) foreach (AccountAddress address in customer.AccountAddresses) CreateCustomerAddress(address); return customer.AccountCode; } catch (Exception ex) { ExceptionMngr.WriteEvent("CreateCustomer", ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection); throw; } }