/// <summary> /// save new site /// </summary> /// <returns></returns> public OperationResult SaveSite() { var operationResult = new OperationResult(); logger.Debug("Site is being created..."); string sCustomerDocument; string sXsdSchema; string sConnectionString; using (eConnectMethods e = new eConnectMethods()) { try { // Create the site data file SerializeSiteObject("Site.xml"); // Use an XML document to create a string representation of the site XmlDocument xmldoc = new XmlDocument(); xmldoc.Load("Site.xml"); sCustomerDocument = xmldoc.OuterXml; // Specify the Microsoft Dynamics GP server and database in the connection string sConnectionString = @"data source=SLM-DYNAMICS;Database=STHLD;User Id=programmer;Password=programmer;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); operationResult.Success = true; operationResult.Message = "Successfully added a site."; } // 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 site: {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 site: {0} ", ex.ToString()); } finally { // Call the Dispose method to release the resources // of the eConnectMethds object e.Dispose(); } } // end of using statement //try //{ // var newSite = new IV40700_Site() // { // LOCNCODE = site.LOCNCODE, // LOCNDSCR = site.LOCNDSCR, // NOTEINDX = site.NOTEINDX, // ADDRESS1 = site.ADDRESS1, // ADDRESS2 = site.ADDRESS2, // ADDRESS3 = site.ADDRESS3, // CITY = site.CITY, // STATE = site.STATE, // ZIPCODE = site.ZIPCODE, // COUNTRY = site.COUNTRY, // PHONE1 = site.PHONE1, // PHONE2 = site.PHONE2, // PHONE3 = site.PHONE3, // FAXNUMBR = site.FAXNUMBR, // Location_Segment = site.Location_Segment, // STAXSCHD = site.STAXSCHD, // PCTAXSCH = site.PCTAXSCH, // INCLDDINPLNNNG = site.INCLDDINPLNNNG, // PORECEIPTBIN = site.PORECEIPTBIN, // PORETRNBIN = site.PORETRNBIN, // SOFULFILLMENTBIN = site.SOFULFILLMENTBIN, // SORETURNBIN = site.SORETURNBIN, // BOMRCPTBIN = site.BOMRCPTBIN, // MATERIALISSUEBIN = site.MATERIALISSUEBIN, // WMSINT = site.WMSINT, // PICKTICKETSITEOPT = site.PICKTICKETSITEOPT, // BINBREAK = site.BINBREAK, // CCode = site.CCode, // DECLID = site.DECLID, // INACTIVE = site.INACTIVE, // DEX_ROW_ID = site.DEX_ROW_ID // }; // _dynamicsContext.IV40700_Site.InsertOnSubmit(newSite); // _dynamicsContext.SubmitChanges(); // operationResult.Success = true; // operationResult.Message = "Success"; //} //catch (Exception ex) //{ // operationResult.Success = false; // operationResult.Message = "Error"; // logger.ErrorFormat("Error saving new site: {0} ", ex.ToString()); //} return(operationResult); }
/// <summary> /// save new receivable transaction /// </summary> /// <param name="receivable"></param> /// <returns></returns> public OperationResult SaveReceivableTransaction(RM20101 receivable) { var operationResult = new OperationResult(); logger.Debug("Receivable is being created..."); using (eConnectMethods e = new eConnectMethods()) { try { // Instantiate a taPMTransactionInsert XML node object taRMTransaction transaction = new taRMTransaction(); //Populate elements of the taUpdateCreateItemRcd XML node object transaction.RMDTYPAL = receivable.RMDTYPAL; transaction.DOCNUMBR = receivable.DOCNUMBR; transaction.DOCDATE = receivable.DOCDATE.ToShortDateString(); transaction.BACHNUMB = receivable.BACHNUMB; transaction.CUSTNMBR = receivable.CUSTNMBR; transaction.DOCAMNT = receivable.DOCAMNT; transaction.SLSAMNT = receivable.SLSAMNT; // Instantiate a PMTransactionType schema object RMTransactionType transactiontype = new RMTransactionType(); // Populate the PMTransactionType schema with the taPMTransactionInsert XML node transactiontype.taRMTransaction = transaction; RMTransactionType[] receivableTransaction = { transactiontype }; // 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 PMTransactionType schema object eConnect.RMTransactionType = receivableTransaction; // 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 payables transaction: {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 payables transaction: {0} ", ex.ToString()); } finally { // Call the Dispose method to release the resources // of the eConnectMethds object e.Dispose(); } } // end of using statement return(operationResult); }
public static bool ProcessMethod(dynamic queueData) { string econnectDocument; string sXsdSchema; string sConnectionString; try { dynamic zudelloObject = JsonConvert.DeserializeObject <ExpandoObject>(queueData.queue.Body); string order = queueData.map.ProcessOrder.ToString(); //Created at string obj = queueData.map.DocType.ToString(); string uuid = "";//zudelloObject.invoiceUUID.ToString(); string queueID = queueData.queue.Id.ToString(); //Generate the eConnectXml string xmlRendered = GpTools.RenderXml(queueData.map.Body, zudelloObject); using (eConnectMethods e = new eConnectMethods()) { try { XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xmlRendered); econnectDocument = xmldoc.OuterXml; //User ID=sa;Password=sa using (var db = new ZudelloContext()) { var Connection = db.Zconnections.Where(i => i.Id == 1).FirstOrDefault(); sConnectionString = String.Format(@"Data Source={0};Integrated Security = SSPI; Persist Security Info = false ; Initial Catalog ={1};", Connection.DataSource, Connection.InitialCatalog); db.Dispose(); } // sConnectionString = @"Data Source=LAPTOP-BUDQ9SBN\DYNAMICGP;Integrated Security = SSPI; Persist Security Info = false ; Initial Catalog = GP_DE;"; // 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. bool created = e.CreateEntity(sConnectionString, econnectDocument); if (created == true) { return(true); } else { return(false); } } // The eConnectException class will catch eConnect business logic errors. // display the error message on the console catch (eConnectException exc) { Console.Write(exc.ToString()); e.Dispose(); return(false); } // Catch any system error that might occurr. // display the error message on the console catch (System.Exception ex) { Console.Write(ex.ToString()); e.Dispose(); return(false); } } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }
/// <summary> /// update foundry /// </summary> /// <param name="foundry"></param> /// <returns></returns> public OperationResult UpdateFoundry(PM00200_Foundry foundry) { var operationResult = new OperationResult(); var existingFoundry = _dynamicsContext.PM00200_Foundry.FirstOrDefault(x => x.VENDORID.Replace(" ", string.Empty) == foundry.VENDORID); if (existingFoundry != null) { logger.Debug("Foundry is being updated."); string sCustomerDocument; string sXsdSchema; string sConnectionString; using (eConnectMethods e = new eConnectMethods()) { try { // Instantiate a taUpdateCreateCustomerRcd XML node object taUpdateCreateVendorRcd vendor = new taUpdateCreateVendorRcd(); //Populate elements of the taUpdateCreateVendorRcd XML node object vendor.VENDORID = foundry.VENDORID; vendor.VENDNAME = foundry.VENDNAME; vendor.VENDSHNM = foundry.VENDSHNM; vendor.UseVendorClass = 0; vendor.UpdateIfExists = 1; // Instantiate a PMVendorMasterType schema object PMVendorMasterType vendortype = new PMVendorMasterType(); // Populate the PMVendorMasterType schema with the taUpdateCreateVendorRcd XML node vendortype.taUpdateCreateVendorRcd = vendor; PMVendorMasterType[] vendorMaster = { vendortype }; // 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.PMVendorMasterType = vendorMaster; // 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.UpdateEntity(_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 while updating foundry: {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 while updating foundry: {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 = "Unable to find selected foundry."; } return(operationResult); }
/// <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); }
/// <summary> /// save new vendor order /// </summary> /// <param name="order"></param> /// <param name="orderLines"></param> /// <returns></returns> public OperationResult SaveVendorOrder(POP10100_PurchaseOrder_Work order, List <POP10110_PurchaseOrderLine_Work> orderLines) { var operationResult = new OperationResult(); logger.Debug("Vendor Order is being created..."); using (eConnectMethods e = new eConnectMethods()) { try { if (orderLines != null && orderLines.Count > 0) { taPoLine_ItemsTaPoLine[] lineItems = new taPoLine_ItemsTaPoLine[orderLines.Count]; var orderLineNumber = 16384; var lineNumber = 0; foreach (var orderLine in orderLines) { // Instantiate a taUpdateCreateItemRcd XML node object taPoLine_ItemsTaPoLine orderLineItem = new taPoLine_ItemsTaPoLine(); //Populate elements of the taUpdateCreateItemRcd XML node object orderLineItem.PONUMBER = orderLine.PONUMBER; orderLineItem.VENDORID = orderLine.VENDORID; orderLineItem.DOCDATE = orderLine.DOCDATE; orderLineItem.LOCNCODE = orderLine.LOCNCODE; orderLineItem.VNDITNUM = orderLine.VNDITNUM; orderLineItem.ITEMNMBR = orderLine.ITEMNMBR; orderLineItem.QUANTITY = orderLine.QUANTITY; //DUE DATE orderLineItem.PRMDATE = orderLine.PRMDATE; //SHIP DATE orderLineItem.PRMSHPDTE = orderLine.PRMSHPDTE; orderLineItem.UpdateIfExists = 0; lineItems[lineNumber] = orderLineItem; orderLineNumber = orderLineNumber * 2; lineNumber++; } // Instantiate a taUpdateCreateItemRcd XML node object taPoHdr orderHeader = new taPoHdr(); //Populate elements of the taUpdateCreateItemRcd XML node object orderHeader.POTYPE = order.POTYPE; orderHeader.PONUMBER = order.PONUMBER; orderHeader.VENDORID = order.VENDORID; orderHeader.SUBTOTAL = order.SUBTOTAL; orderHeader.UpdateIfExists = 0; // Instantiate a IVItemMasterType schema object POPTransactionType ordertype = new POPTransactionType(); // Populate the IVItemMasterType schema with the taUpdateCreateItemRcd XML node ordertype.taPoLine_Items = lineItems; ordertype.taPoHdr = orderHeader; POPTransactionType[] orderEntry = { ordertype }; // 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 IVItemMasterType schema object eConnect.POPTransactionType = orderEntry; /////////////////////////////////////////////////////////////////////////////// // 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(); ///////////////////////////////////////////////////////////////////////////////// //string xmldocument; //SerializeReceiptHeaderObject("C:\\receipt.xml", receipt, receiptLines); ////Use an XML document to create a string representation of the customer //XmlDocument xmldoc = new XmlDocument(); //xmldoc.Load("C:\\receipt.xml"); //xmldocument = xmldoc.OuterXml; ////Call eConnect to process the xmldocument. //e.CreateEntity(_dynamicsConnection, xmldocument); ////////////////////////////////////////////////////////////////////////////////// // Call eConnect to process the XmlDocument. e.CreateEntity(_dynamicsConnection, xmlDocument.OuterXml); operationResult.Success = true; operationResult.Message = "Success"; } else { operationResult.Success = false; operationResult.Message = "No items are attached to receive."; } } // 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 receipt: {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 receipt: {0} ", ex.ToString()); } finally { // Call the Dispose method to release the resources // of the eConnectMethds object e.Dispose(); } } // end of using statement return(operationResult); }
/// <summary> /// Integra nc de AR y aplica facturas /// </summary> /// <param name="worker"></param> /// <param name="e"></param> private void IntegraRMNotaCreditoYAplicaciones(BackgroundWorker worker, DoWorkEventArgs e) { string mensajeOk = ""; string mensajeError = ""; Model.RMFactura docGP = null; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); string nroLote = DateTime.Now.ToString("yyyyMMdd.HHmmss"); worker.ReportProgress(0, new string[] { "Credit memo batch " + nroLote, "Credit memo Batch " + nroLote }); cantidad = 0; foreach (var dato in _cobros.LBoletosBrasil) { mensajeOk = ""; mensajeError = ""; DateTime fechaCobro = dato.FechaTotalLiquidado.AddDays(parametrosCobrosXL.FechaTotalLiquidadoAddDays); using (eConnectMethods eConnectMethods = new eConnectMethods()) { eConnectMethods.RequireProxyService = true; List <RMTransactionType> masterRMTransactionType = new List <RMTransactionType>(); List <RMApplyType> masterRMApplyType = new List <RMApplyType>(); try { bool error = false; decimal valorBoleto = decimal.Round(dato.ValorBoleto, 2); decimal valorPago = decimal.Round(dato.ValorPago, 2); decimal juros = decimal.Round(dato.Juros, 2); //RMCashReceiptsType RMCashReceiptsTypeEntry = new RMCashReceiptsType(); RMTransactionType RMTransactionTypeEntry = new RMTransactionType(); taRMTransaction rmTransactionItem = new taRMTransaction(); //el número de la planilla puede venir así: B-10201, B-10201., B-10201 01, B-10201. 01 //string numFactura = dato.NumeroFactura.Trim().Length > 7 ? Model.Utiles.Izquierda(dato.NumeroFactura, 8) : Model.Utiles.Izquierda( dato.NumeroFactura, 7); docGP = this.getCustnmbrDocnumbr(dato.NumeroFactura.Trim(), dato.FechaVencimientoPago); rmTransactionItem.CUSTNMBR = docGP.Custnmbr; // custData["custnmbr"].ToString(); //_custnmbr; rmTransactionItem.DOCNUMBR = "CC" + dato.NumeroCobro; rmTransactionItem.DOCDATE = fechaCobro.ToString(parametrosCobrosXL.FormatoFecha); //System.Configuration.ConfigurationManager.AppSettings[_pre + "_FormatoFecha"]); rmTransactionItem.RMDTYPAL = 7; rmTransactionItem.DOCAMNT = juros; rmTransactionItem.SLSAMNT = juros; rmTransactionItem.BACHNUMB = nroLote; rmTransactionItem.DOCDESCR = dato.NumeroFacturaYCuota; rmTransactionItem.CSTPONBR = dato.NombrePagador; RMApplyType RMApplyTypeEntry = new RMApplyType(); taRMApply ApplyItem = new taRMApply(); ApplyItem.APTODCNM = docGP.Docnmbr; // custData["docnumbr"].ToString(); // _docnmbr.Trim(); ApplyItem.APFRDCNM = "CC" + dato.NumeroCobro; ApplyItem.APPTOAMT = juros - Convert.ToDecimal(docGP.Amount) > 0 ? Convert.ToDecimal(docGP.Amount) : juros; ApplyItem.APFRDCTY = 7; ApplyItem.APTODCTY = 1; ApplyItem.APPLYDATE = fechaCobro.ToString(parametrosCobrosXL.FormatoFecha); // System.Configuration.ConfigurationManager.AppSettings[_pre + "_FormatoFecha"]); ApplyItem.GLPOSTDT = fechaCobro.ToString(parametrosCobrosXL.FormatoFecha); // System.Configuration.ConfigurationManager.AppSettings[_pre + "_FormatoFecha"]); cantidad++; if (!error) { eConnectType eConnDoc = new eConnectType(); RMTransactionTypeEntry.taRMTransaction = rmTransactionItem; masterRMTransactionType.Add(RMTransactionTypeEntry); eConnDoc.RMTransactionType = masterRMTransactionType.ToArray(); RMApplyTypeEntry.taRMApply = ApplyItem; masterRMApplyType.Add(RMApplyTypeEntry); eConnDoc.RMApplyType = masterRMApplyType.ToArray(); XmlDocument xmlDoc = Serializa(eConnDoc); eConnectMethods.CreateEntity(parametrosCobrosXL.ConnStringTarget, xmlDoc.OuterXml); mensajeOk = dato.NumeroFactura + " - " + dato.NumeroCobro + ": Credit Memo OK" + Environment.NewLine; } else { mensajeError = dato.NumeroFactura + " - " + dato.NumeroCobro + ": Error" + Environment.NewLine; } System.Threading.Thread.Sleep(100); } catch (eConnectException ec) { mensajeError = dato.NumeroFactura + " - " + dato.NumeroCobro + " eConn: " + ec.Message + Environment.NewLine + ec.StackTrace; } catch (Exception ex) { mensajeError = dato.NumeroFactura + " - " + dato.NumeroCobro + ": " + ex.Message + Environment.NewLine + ex.StackTrace; } finally { eConnectMethods.Dispose(); worker.ReportProgress(0, new string[] { mensajeError, mensajeOk }); } } } worker.ReportProgress(0, new string[] { "Credit memo uploading finished.", "Credit memo uploading finished." }); }
/// <summary> /// save part vendor master /// </summary> /// <param name="part"></param> /// <returns></returns> public OperationResult SavePartVendorMaster(IV00103_Part_Vendor_Master part) { var operationResult = new OperationResult(); var existingPart = _dynamicsContext.IV00103_Part_Vendor_Master.FirstOrDefault(x => x.ITEMNMBR.Replace(" ", string.Empty).ToLower() == part.ITEMNMBR.Replace(" ", string.Empty).ToLower()); if (existingPart == null) { logger.Debug("Vendor Part is being created..."); using (eConnectMethods e = new eConnectMethods()) { try { // Instantiate a taCreateItemVendors_ItemsTaCreateItemVendors XML node object taCreateItemVendors_ItemsTaCreateItemVendors item = new taCreateItemVendors_ItemsTaCreateItemVendors(); //Populate elements of the taCreateItemVendors_ItemsTaCreateItemVendors XML node object item.ITEMNMBR = part.ITEMNMBR; item.VENDORID = part.VENDORID; item.VNDITNUM = part.VNDITNUM; item.UpdateIfExists = 0; // Instantiate a IVItemMasterType schema object IVItemMasterType itemtype = new IVItemMasterType(); // Populate the IVItemMasterType schema with the taCreateItemVendors_ItemsTaCreateItemVendors XML node itemtype.taCreateItemVendors_Items = new taCreateItemVendors_ItemsTaCreateItemVendors[1] { item }; IVItemMasterType[] vendorItem = { itemtype }; // 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 IVItemMasterType schema object eConnect.IVItemMasterType = vendorItem; // 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 part price header: {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 part price header: {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); }
/// <summary> /// save new salesperson /// </summary> /// <param name="salesperson"></param> /// <returns></returns> public OperationResult SaveSalesperson(RM00301_Salesperson salesperson) { var operationResult = new OperationResult(); var existingSalesperson = _dynamicsContext.RM00301_Salesperson.FirstOrDefault(x => x.SLPRSNID.Replace(" ", string.Empty) == salesperson.SLPRSNID); if (existingSalesperson == null) { logger.Debug("Salesperson is being created..."); string sCustomerDocument; string sXsdSchema; string sConnectionString; using (eConnectMethods e = new eConnectMethods()) { try { // Create the customer data file SerializeSalespersonObject("Customer.xml"); // Use an XML document to create a string representation of the customer XmlDocument xmldoc = new XmlDocument(); xmldoc.Load("Customer.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); 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 salesperson: {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 salesperson: {0} ", ex.ToString()); } finally { // Call the Dispose method to release the resources // of the eConnectMethds object e.Dispose(); } } // end of using statement //try //{ // var newSalesperson = new RM00301_Salesperson() // { // SLPRSNID = salesperson.SLPRSNID, // EMPLOYID = salesperson.EMPLOYID, // VENDORID = salesperson.VENDORID, // SLPRSNFN = salesperson.SLPRSNFN, // SPRSNSMN = salesperson.SPRSNSMN, // SPRSNSLN = salesperson.SPRSNSLN, // ADDRESS1 = salesperson.ADDRESS1, // ADDRESS2 = salesperson.ADDRESS2, // ADDRESS3 = salesperson.ADDRESS3, // CITY = salesperson.CITY, // STATE = salesperson.STATE, // ZIP = salesperson.ZIP, // COUNTRY = salesperson.COUNTRY, // PHONE1 = salesperson.PHONE1, // PHONE2 = salesperson.PHONE2, // PHONE3 = salesperson.PHONE3, // FAX = salesperson.FAX, // INACTIVE = salesperson.INACTIVE, // SALSTERR = salesperson.SALSTERR, // COMMCODE = salesperson.COMMCODE, // COMPRCNT = salesperson.COMPRCNT, // STDCPRCT = salesperson.STDCPRCT, // COMAPPTO = salesperson.COMAPPTO, // COSTTODT = salesperson.COSTTODT, // CSTLSTYR = salesperson.CSTLSTYR, // TTLCOMTD = salesperson.TTLCOMTD, // TTLCOMLY = salesperson.TTLCOMLY, // COMSLTDT = salesperson.COMSLTDT, // COMSLLYR = salesperson.COMSLLYR, // NCOMSLTD = salesperson.NCOMSLTD, // NCOMSLYR = salesperson.NCOMSLYR, // KPCALHST = salesperson.KPCALHST, // KPERHIST = salesperson.KPERHIST, // NOTEINDX = salesperson.NOTEINDX, // MODIFDT = salesperson.MODIFDT, // CREATDDT = salesperson.CREATDDT, // COMMDEST = salesperson.COMMDEST, // DEX_ROW_TS = salesperson.DEX_ROW_TS, // DEX_ROW_ID = salesperson.DEX_ROW_ID // }; // _dynamicsContext.RM00301_Salesperson.InsertOnSubmit(newSalesperson); // _dynamicsContext.SubmitChanges(); // operationResult.Success = true; // operationResult.Message = "Success"; //} //catch (Exception ex) //{ // operationResult.Success = false; // operationResult.Message = "Error"; // logger.ErrorFormat("Error saving new salesperson: {0} ", ex.ToString()); //} } else { operationResult.Success = false; operationResult.Message = "Duplicate Entry"; } return(operationResult); }