public static bool CreateEntity(ref string response, string transactionXML, string companyDB)
        {
            string connString = DataAccess.ConnectionStringWindows;

            bool returnValue;

            response = "";

            eConnectMethods eConnCall = new eConnectMethods();

            try
            {
                returnValue = eConnCall.CreateEntity(connString, transactionXML);
                return(true);
            }
            catch (eConnectException ex)
            {
                response = ex.Message;
                return(false);
            }
            catch (SqlException ex)
            {
                foreach (SqlError sqlErr in ex.Errors)
                {
                    response += sqlErr.Message + "\r\n";
                }
                return(false);
            }
            catch (Exception ex)
            {
                response = ex.Message;
                return(false);
            }
        }
        public static void GP()
        {
            string econnectDocument;
            string sXsdSchema;
            string sConnectionString;



            //Generate the eConnectXml
            string xmlRendered = @"PM_Transaction-Invoice.xml";

            using (eConnectMethods e = new eConnectMethods())
            {
                try
                {
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.Load(xmlRendered);
                    econnectDocument = xmldoc.OuterXml;

                    //User ID=sa;Password=sa
                    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 response = e.CreateEntity(sConnectionString, econnectDocument);
                    Console.WriteLine(response);
                    Console.ReadLine();
                }

                // 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();
                }
                // Catch any system error that might occurr.
                // display the error message on the console
                catch (System.Exception ex)
                {
                    Console.Write(ex.ToString());
                    e.Dispose();
                }
            }
        }
        public Response CreateGPMaster(string strCNX, string strXML)
        {
            var eConnCall = new eConnectMethods();
            var response  = new Response();

            try
            {
                response.SUCCESS = eConnCall.CreateEntity(strCNX, strXML);

                response.MESSAGE = "EXITO";
                return(response);
            }
            catch (eConnectException ex)
            {
                response.SUCCESS = false;
                response.MESSAGE = ex.Message;
                response.STACK   = ex.StackTrace;


                if (ex.InnerException != null)
                {
                    response.STACK += ex.InnerException.Message;
                }
                return(response);
            }
            catch (Exception ex)
            {
                response.SUCCESS = false;
                response.MESSAGE = ex.Message;
                response.STACK   = ex.StackTrace;


                if (ex.InnerException != null)
                {
                    response.STACK += ex.InnerException.Message;
                }
                return(response);
            }
            finally
            {
                eConnCall.Dispose();
            }
        }
        /// <summary>
        /// Integra un documento xml sDocXml a GP.
        /// </summary>
        public void integraEntityXml()
        {
            iError = 0;
            bool            eConnResult;
            eConnectMethods eConnObject = new eConnectMethods();

            try
            {
                //El método que integra eConnect_EntryPoint retorna True si fue exitoso
                //eConnResult = eConnObject.eConnect_EntryPoint(_DatosConexionDB.Elemento.ConnStr, EnumTypes.ConnectionStringType.SqlClient, _sDocXml, EnumTypes.SchemaValidationType.None);
                eConnResult = eConnObject.CreateEntity(_DatosConexionDB.Elemento.ConnStr, _sDocXml);

                if (eConnResult)
                {
                    sMensaje = "--> Integrado a GP";
                }
                else
                {
                    iError++;
                    sMensaje = "Error desconocido al crear la entidad eConnect.";
                }
            }
            catch (eConnectException eConnErr)
            {
                sMensaje = "Excepción eConnect: " + eConnErr.Message + "[IntegraComprasGP.integraEntityXml]";
                iError++;
            }
            catch (ApplicationException ex)
            {
                sMensaje = "Excepción de aplicación: " + ex.Message + "[IntegraComprasGP.integraEntityXml]";
                iError++;
            }
            catch (Exception errorGral)
            {
                sMensaje = "Excepción desconocida: " + errorGral.Message + "[IntegraComprasGP.integraEntityXml]";
                iError++;
            }
        }
        /// <summary>
        /// Crea el xml de una factura sop a partir de una fila de datos en una hoja excel.
        /// </summary>
        /// <param name="hojaXl">Hoja excel</param>
        /// <param name="filaXl">Fila de la hoja excel a procesar</param>
        public void IntegraFacturaSOP(ExcelWorksheet hojaXl, int filaXl, string sTimeStamp)
        {
            _iError  = 0;
            _mensaje = String.Empty;
            string            eConnResult    = String.Empty;
            eConnectType      docEConnectSOP = new eConnectType();
            eConnectType      entEconnect    = new eConnectType();
            FacturaDeVentaSOP documentoSOP   = new FacturaDeVentaSOP(_ParamExcel.ConnectionStringTargetEF);
            eConnectMethods   eConnObject    = new eConnectMethods();

            Cliente entidadCliente;

            try
            {
                _mensaje = " Número Doc: " + hojaXl.Cells[filaXl, _ParamExcel.FacturaSopnumbe].Value.ToString().Trim();

                entidadCliente = new Cliente(_ParamExcel.ConnectionStringTargetEF, _ParamExcel.FacturaSopTXRGNNUM.ToString(), _ParamExcel.FacturaSopCUSTNAME.ToString(), _ParamExcel.ClienteDefaultCUSTCLAS);
                if (entidadCliente.preparaClienteEconn(hojaXl, filaXl))
                {
                    entEconnect.RMCustomerMasterType = entidadCliente.ArrCustomerType;
                    serializa(entEconnect);
                    if (eConnObject.CreateEntity(_ParamExcel.ConnStringTarget, _sDocXml))
                    {
                        _mensaje += "--> Cliente Integrado a GP";
                    }
                }

                documentoSOP.preparaFacturaSOP(hojaXl, filaXl, sTimeStamp, _ParamExcel);
                docEConnectSOP.SOPTransactionType = new SOPTransactionType[] { documentoSOP.FacturaSop };
                serializa(docEConnectSOP);
                eConnResult  = eConnObject.CreateTransactionEntity(_ParamExcel.ConnStringTarget, _sDocXml);
                _sMensajeErr = "--> Integrado a GP";
            }
            catch (NullReferenceException nr)
            {
                string sInner = nr.InnerException == null ? String.Empty : nr.InnerException.Message;
                if (nr.InnerException != null)
                {
                    sInner += nr.InnerException.InnerException == null ? String.Empty : " " + nr.InnerException.InnerException.Message;
                }
                _sMensajeErr = "Excepción al validar datos de la factura SOP. " + nr.Message + " " + sInner + " [" + nr.TargetSite.ToString() + "]";
                _iError++;
            }
            catch (eConnectException eConnErr)
            {
                string sInner = eConnErr.InnerException == null ? String.Empty : eConnErr.InnerException.Message;
                _sMensajeErr = "Excepción eConnect al integrar factura SOP. " + eConnErr.Message + " " + sInner + " [" + eConnErr.TargetSite.ToString() + "]";
                _iError++;
            }
            catch (Exception errorGral)
            {
                string sInner = errorGral.InnerException == null ? String.Empty : errorGral.InnerException.Message;
                if (errorGral.InnerException != null)
                {
                    sInner += errorGral.InnerException.InnerException == null ? String.Empty : " " + errorGral.InnerException.InnerException.Message;
                }
                _sMensajeErr = "Excepción desconocida al integrar factura SOP. " + errorGral.Message + " " + sInner + " [" + errorGral.TargetSite.ToString() + "]";
                _iError++;
            }
            finally
            {
                _filaNuevaFactura = filaXl + 1;
                _mensaje          = "Fila: " + filaXl.ToString() + _mensaje;
            }
        }
Beispiel #6
0
        /// <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);
        }
Beispiel #7
0
        /// <summary>
        /// save new receipt
        /// </summary>
        /// <param name="receipt"></param>
        /// <param name="receiptLines"></param>
        /// <returns></returns>
        public OperationResult SaveReceipt(POP10300_Receipt_Work receipt, List <POP10310> receiptLines)
        {
            var operationResult = new OperationResult();

            logger.Debug("Receipt is being created...");

            using (eConnectMethods e = new eConnectMethods())
            {
                try
                {
                    if (receiptLines != null && receiptLines.Count > 0)
                    {
                        taPopRcptLotInsert_ItemsTaPopRcptLotInsert[] lotItems = new taPopRcptLotInsert_ItemsTaPopRcptLotInsert[receiptLines.Count];

                        taPopRcptLineInsert_ItemsTaPopRcptLineInsert[] lineItems = new taPopRcptLineInsert_ItemsTaPopRcptLineInsert[receiptLines.Count];

                        var receiptLineNumber = 16384;
                        var lineNumber        = 0;

                        foreach (var receiptLine in receiptLines)
                        {
                            // Instantiate a taUpdateCreateItemRcd XML node object
                            taPopRcptLotInsert_ItemsTaPopRcptLotInsert receiptLotLine = new taPopRcptLotInsert_ItemsTaPopRcptLotInsert();

                            receiptLotLine.POPRCTNM  = receiptLine.POPRCTNM;
                            receiptLotLine.RCPTLNNM  = receiptLineNumber;
                            receiptLotLine.ITEMNMBR  = receiptLine.ITEMNMBR;
                            receiptLotLine.SERLTNUM  = receiptLine.SERLTNUM;
                            receiptLotLine.SERLTQTY  = receiptLine.QTYSHPPD;
                            receiptLotLine.CREATEBIN = 0;

                            lotItems[lineNumber] = receiptLotLine;

                            // Instantiate a taUpdateCreateItemRcd XML node object
                            taPopRcptLineInsert_ItemsTaPopRcptLineInsert receiptLineItem = new taPopRcptLineInsert_ItemsTaPopRcptLineInsert();

                            //Populate elements of the taUpdateCreateItemRcd XML node object
                            receiptLineItem.POPTYPE  = receiptLine.POPTYPE;
                            receiptLineItem.POPRCTNM = receiptLine.POPRCTNM;
                            receiptLineItem.RCPTLNNM = receiptLineNumber;
                            receiptLineItem.ITEMNMBR = receiptLine.ITEMNMBR;
                            receiptLineItem.VENDORID = receiptLine.VENDORID;
                            receiptLineItem.PONUMBER = receiptLine.PONUMBER;
                            receiptLineItem.VNDITNUM = receiptLine.VNDITNUM;
                            receiptLineItem.QTYSHPPD = receiptLine.QTYSHPPD;
                            receiptLineItem.AUTOCOST = 1;

                            lineItems[lineNumber] = receiptLineItem;

                            receiptLineNumber = receiptLineNumber * 2;

                            lineNumber++;
                        }

                        // Instantiate a taUpdateCreateItemRcd XML node object
                        taPopRcptHdrInsert receiptHeader = new taPopRcptHdrInsert();

                        //Populate elements of the taUpdateCreateItemRcd XML node object
                        receiptHeader.POPRCTNM    = receipt.POPRCTNM;
                        receiptHeader.POPTYPE     = receipt.POPTYPE;
                        receiptHeader.receiptdate = receipt.receiptdate;
                        receiptHeader.BACHNUMB    = receipt.BACHNUMB;
                        receiptHeader.VENDORID    = receipt.VENDORID;

                        // Instantiate a IVItemMasterType schema object
                        POPReceivingsType receipttype = new POPReceivingsType();

                        // Populate the IVItemMasterType schema with the taUpdateCreateItemRcd XML node
                        receipttype.taPopRcptLotInsert_Items  = lotItems;
                        receipttype.taPopRcptLineInsert_Items = lineItems;
                        receipttype.taPopRcptHdrInsert        = receiptHeader;
                        POPReceivingsType[] receiptEntry = { receipttype };

                        // 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.POPReceivingsType = receiptEntry;

                        ///////////////////////////////////////////////////////////////////////////////

                        // 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);
        }
Beispiel #8
0
        /// <summary>
        /// save new inventory transaction
        /// </summary>
        /// <param name="transaction"></param>
        /// <param name="transactionLines"></param>
        /// <returns></returns>
        public OperationResult SaveInventoryTransaction(IV10000_IventoryTransaction_Work transaction, List <IV10000_IventoryTransaction_Work> transactionLines)
        {
            var operationResult = new OperationResult();

            logger.Debug("Receipt is being created...");

            using (eConnectMethods e = new eConnectMethods())
            {
                try
                {
                    if (transactionLines != null && transactionLines.Count > 0)
                    {
                        taIVTransactionLotInsert_ItemsTaIVTransactionLotInsert[] lotItems = new taIVTransactionLotInsert_ItemsTaIVTransactionLotInsert[transactionLines.Count];

                        taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert[] lineItems = new taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert[transactionLines.Count];

                        var transactionLineNumber = 16384;
                        var lineNumber            = 0;

                        foreach (var transactionLine in transactionLines)
                        {
                            //// Instantiate a taUpdateCreateItemRcd XML node object
                            taIVTransactionLotInsert_ItemsTaIVTransactionLotInsert transactionLotItem = new taIVTransactionLotInsert_ItemsTaIVTransactionLotInsert();

                            //Populate elements of the taUpdateCreateItemRcd XML node object
                            transactionLotItem.IVDOCNBR = transactionLine.IVDOCNBR;
                            transactionLotItem.IVDOCTYP = transactionLine.IVDOCTYP;
                            transactionLotItem.LOTNUMBR = transactionLine.LOTNUMBR;
                            transactionLotItem.ITEMNMBR = transactionLine.ITEMNMBR;
                            transactionLotItem.SERLTQTY = transactionLine.TRXQTY;
                            transactionLotItem.LOCNCODE = transactionLine.TRXLOCTN;
                            //transactionLotItem.EXPNDATE = transactionLine.EXPNDATE;
                            //transactionLotItem.DATERECD = transactionLine.DATERECD;

                            lotItems[lineNumber] = transactionLotItem;

                            // Instantiate a taUpdateCreateItemRcd XML node object
                            taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert transactionLineItem = new taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert();

                            //Populate elements of the taUpdateCreateItemRcd XML node object
                            transactionLineItem.IVDOCNBR = transactionLine.IVDOCNBR;
                            transactionLineItem.IVDOCTYP = transactionLine.IVDOCTYP;
                            //transactionLineItem.LNSEQNBR = transactionLine.LNSEQNBR;
                            transactionLineItem.ITEMNMBR = transactionLine.ITEMNMBR;
                            transactionLineItem.TRXLOCTN = transactionLine.TRXLOCTN;
                            transactionLineItem.TRXQTY   = transactionLine.TRXQTY;
                            //transactionLineItem.Reason_Code = transactionLine.Reason_Code;

                            lineItems[lineNumber] = transactionLineItem;

                            transactionLineNumber = transactionLineNumber * 2;

                            lineNumber++;
                        }

                        // Instantiate a taUpdateCreateItemRcd XML node object
                        taIVTransactionHeaderInsert transactionHeader = new taIVTransactionHeaderInsert();

                        //Populate elements of the taUpdateCreateItemRcd XML node object
                        transactionHeader.BACHNUMB = transaction.BACHNUMB;
                        transactionHeader.IVDOCNBR = transaction.IVDOCNBR;
                        transactionHeader.IVDOCTYP = transaction.IVDOCTYP;
                        transactionHeader.DOCDATE  = transaction.DOCDATE;

                        // Instantiate a IVItemMasterType schema object
                        IVInventoryTransactionType transactiontype = new IVInventoryTransactionType();

                        // Populate the IVItemMasterType schema with the taUpdateCreateItemRcd XML node
                        transactiontype.taIVTransactionLotInsert_Items  = lotItems;
                        transactiontype.taIVTransactionLineInsert_Items = lineItems;
                        transactiontype.taIVTransactionHeaderInsert     = transactionHeader;
                        IVInventoryTransactionType[] transactionEntry = { 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 IVItemMasterType schema object
                        eConnect.IVInventoryTransactionType = transactionEntry;

                        ///////////////////////////////////////////////////////////////////////////////

                        // 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);

                        /////////////////////////////////////////////////////////////////////////////////

                        //string xmldocument;

                        //SerializeTransactionObject("C:\\inventoryTransaction.xml", transaction, transactionLines);

                        ////Use an XML document to create a string representation of the customer
                        //XmlDocument xmldoc = new XmlDocument();
                        //xmldoc.Load("C:\\inventoryTransaction.xml");
                        //xmldocument = xmldoc.OuterXml;

                        ////Call eConnect to process the xmldocument.
                        //e.CreateEntity(_dynamicsConnection, xmldocument);

                        //////////////////////////////////////////////////////////////////////////////////

                        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)
                {
                    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)
                {
                    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);
        }
Beispiel #9
0
        /// <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);
        }
Beispiel #10
0
        /// <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);
        }
Beispiel #11
0
        /// <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);
        }
Beispiel #12
0
        /// <summary>
        /// save new foundry
        /// </summary>
        /// <param name="foundry"></param>
        /// <returns></returns>
        public OperationResult SaveFoundry(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 created...");

                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 = 1;
                        vendor.VNDCLSID       = "SUO";
                        vendor.UpdateIfExists = 0;

                        // 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.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 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 saving new 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 = "Duplicate Entry";
            }

            return(operationResult);
        }
Beispiel #13
0
        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);
            }
        }
Beispiel #14
0
        /// <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." });
        }
Beispiel #16
0
            public int InsertXml(string xmlString)
            {
                string sConnectionString = "";
                Log    errorLog          = new Log(@"C:\Sinex\errorLog.txt");
                int    errorCount        = 0;

                errorLog.Clear();
                try
                {
                    StringBuilder sb = new StringBuilder();
                    sb = new StringBuilder();
                    sb.Append("<eConnect xmlns:dt=\"urn: schemas - microsoft - com:datatypes\">");
                    // sb.Append("<RMCustomerMasterType>");
                    sb.Append("<eConnectProcessInfo>");
                    sb.Append("</eConnectProcessInfo>");
                    sb.Append("<taPMTransactionInsert>");
                    sb.Append("<BACHNUMB>1</BACHNUMB>");
                    sb.Append("<VCHNUMWK>99999</VCHNUMWK>");
                    sb.Append("<VENDORID>ACETRAVE0001</VENDORID>");
                    sb.Append("<DOCNUMBR>99999</DOCNUMBR>");
                    sb.Append("<DOCTYPE>1</DOCTYPE>");
                    sb.Append("<DOCAMNT>99.99</DOCAMNT>");
                    sb.Append("<DOCDATE>2020-01-01</DOCDATE>");
                    sb.Append("<MSCCHAMT>0.00</MSCCHAMT>");
                    sb.Append("<PRCHAMNT>99.99</PRCHAMNT>");
                    sb.Append("<TAXAMNT>0.00</TAXAMNT>");
                    sb.Append("<FRTAMNT>0.00</FRTAMNT>");
                    sb.Append("<TRDISAMT>0.00</TRDISAMT>");
                    sb.Append("<CHRGAMNT>99.99</CHRGAMNT>");
                    sb.Append("<CASHAMNT>0.00</CASHAMNT>");
                    sb.Append("<CHEKAMNT>0.00</CHEKAMNT>");
                    sb.Append("<CRCRDAMT>0.00</CRCRDAMT>");
                    sb.Append("<DISTKNAM>0.00</DISTKNAM>");
                    sb.Append("</taPMTransactionInsert>");
                    //sb.Append("</RMCustomerMasterType>");
                    sb.Append("</eConnect>");

                    sConnectionString = "server=LAPTOP-G581GE4V\\SQL2016_GP2018R2;database=TWO;Integrated Security=SSPI;persist security info=False";
                    eConnectMethods eConnectObject = new eConnectMethods();
                    XmlDocument     xmlDoc         = new XmlDocument();
                    XmlDocument     xmlDoc2        = new XmlDocument();
                    xmlString.Replace(" ", "");
                    xmlDoc.LoadXml(xmlString);

                    bool eConnectResult;
                    eConnectResult = eConnectObject.CreateEntity(sConnectionString, xmlDoc.OuterXml);
                    return(errorCount);
                }
                catch (Exception ex)
                {// If an error occurs, diplay the error information to the user
                    errorCount = errorCount + 1;
                    int    errorLocation       = ex.Message.IndexOf("Error Number =");
                    int    errorNumberLocation = errorLocation + 14;
                    string errorNumber         = ex.Message.Substring(errorNumberLocation, 6).Trim();
                    switch (errorNumber)
                    {
                    case "305":
                        errorLog.Write($"ERROR: Document Number {docnumbr} already exists");
                        break;

                    case "306":
                        errorLog.Write($"ERROR: Voucher Number {vchnumwk} already exists");
                        break;

                    default:
                        errorLog.Error("Pmtransaction.InsertXml", ex);
                        break;
                    }
                }
                return(errorCount);
            }
Beispiel #17
0
        public static string NextSopDocumentNumber(string salesDocID)
        {
            GetNextDocNumbers sopTransNumber        = new GetNextDocNumbers();
            string            nextTransactionNumber = string.Empty;
            string            sConnectionString     = "";

            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<eConnect xmlns:dt=\"urn: schemas - microsoft - com:datatypes\">");
                sb.Append("<RMCustomerMasterType>");
                sb.Append("<eConnectProcessInfo>");
                sb.Append("</eConnectProcessInfo>");
                sb.Append("<taUpdateCreateCustomerRcd>");
                sb.Append("<CUSTNMBR>JEFF0002</CUSTNMBR>");
                sb.Append("<CUSTNAME>JL Lawn Care Service</CUSTNAME>");
                sb.Append("<STMTNAME>JL Lawn Care Service </STMTNAME>");
                sb.Append("<SHRTNAME>JL Lawn Care</SHRTNAME>");
                sb.Append("<ADRSCODE>PRIMARY </ADRSCODE>");
                sb.Append("<ADDRESS1>123 Main Street</ADDRESS1>");
                sb.Append("<CITY>Valley City </CITY>");
                sb.Append("<STATE>ND </STATE>");
                sb.Append("<ZIPCODE>58072 </ZIPCODE>");
                sb.Append("<COUNTRY>USA </COUNTRY>");
                sb.Append("<PHNUMBR1>55532336790000 </PHNUMBR1>");
                sb.Append("<PHNUMBR2>55551161817181 </PHNUMBR2>");
                sb.Append("<FAX>55584881000000 </FAX>");
                sb.Append("<UPSZONE>red </UPSZONE>");
                sb.Append("<SHIPMTHD>PICKUP </SHIPMTHD>");
                sb.Append("<TAXSCHID>ILLINOIS</TAXSCHID>");
                sb.Append("<PRBTADCD>PRIMARY </PRBTADCD>");
                sb.Append("<PRSTADCD>PRIMARY </PRSTADCD>");
                sb.Append("<STADDRCD>PRIMARY </STADDRCD>");
                sb.Append("<SLPRSNID>GREG E.</SLPRSNID>");
                sb.Append("<SALSTERR>TERRITORY 6</SALSTERR>");
                sb.Append("<COMMENT1>comment1</COMMENT1>");
                sb.Append("<COMMENT2>comment2</COMMENT2>");
                sb.Append("<PYMTRMID>Net 30 </PYMTRMID>");
                sb.Append("<CHEKBKID>PAYROLL </CHEKBKID>");
                sb.Append("<KPCALHST>0 </KPCALHST>");
                //sb.Append("<RMCSHACTNUMST>000-1200-00 </RMCSHACTNUMST>");
                sb.Append("<UseCustomerClass>0</UseCustomerClass>");
                sb.Append("<UpdateIfExists>1</UpdateIfExists>");
                sb.Append("</taUpdateCreateCustomerRcd>");
                sb.Append("</RMCustomerMasterType>");
                sb.Append("</eConnect>");

                sb = new StringBuilder();
                sb.Append("<eConnect xmlns:dt=\"urn: schemas - microsoft - com:datatypes\">");
                sb.Append("<RMCustomerMasterType>");
                sb.Append("<eConnectProcessInfo>");
                sb.Append("</eConnectProcessInfo>");
                sb.Append("<taPMTransactionInsert>");
                sb.Append("<BACHNUMB>1</BACHNUMB>");
                sb.Append("<VCHNUMWK>99999</VCHNUMWK>");
                sb.Append("<VENDORID>ACETRAVE0001</VENDORID>");
                sb.Append("<DOCNUMBR>99999</DOCNUMBR>");
                sb.Append("<DOCTYPE>1</DOCTYPE>");
                sb.Append("<DOCAMNT>99.99</DOCAMNT>");
                sb.Append("<DOCDATE>2020-01-01</DOCDATE>");
                sb.Append("<MSCCHAMT>0.00</MSCCHAMT>");
                sb.Append("<PRCHAMNT>99.99</PRCHAMNT>");
                sb.Append("<TAXAMNT>0.00</TAXAMNT>");
                sb.Append("<FRTAMNT>0.00</FRTAMNT>");
                sb.Append("<TRDISAMT>0.00</TRDISAMT>");
                sb.Append("<CHRGAMNT>99.99</CHRGAMNT>");
                sb.Append("<CASHAMNT>0.00</CASHAMNT>");
                sb.Append("<CHEKAMNT>0.00</CHEKAMNT>");
                sb.Append("<CRCRDAMT>0.00</CRCRDAMT>");
                sb.Append("<DISTKNAM>0.00</DISTKNAM>");

                sb.Append("</taPMTransactionInsert>");
                sb.Append("</RMCustomerMasterType>");
                sb.Append("</eConnect>");

                sConnectionString = "server=LAPTOP-G581GE4V\\SQL2016_GP2018R2;database=TWO;Integrated Security=SSPI;persist security info=False";
                eConnectMethods eConnectObject = new eConnectMethods();
                XmlDocument     xmlDoc         = new XmlDocument();
                xmlDoc.LoadXml(sb.ToString());
                bool eConnectResult;
                eConnectResult = eConnectObject.CreateEntity(sConnectionString, xmlDoc.OuterXml);
                return(nextTransactionNumber);
            }
            catch (Exception ex)
            {// If an error occurs, diplay the error information to the user
                MessageBox.Show(ex.Message);
                throw ex;
            }
            finally
            {
                sopTransNumber.Dispose();
            }
        }
Beispiel #18
0
        /// <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);
        }