Exemplo n.º 1
0
        /*
         * /// <summary>
         * ///
         * /// </summary>
         * /// <param name="vendor"></param>
         * /// <returns></returns>
         * private string SerializeVendor(taUpdateCreateVendorRcd vendor)
         * {
         *  try
         *  {
         *      PMVendorMasterType VendorMasterType = new PMVendorMasterType();
         *      eConnectType eConnect = new eConnectType();
         *      VendorMasterType.taUpdateCreateVendorRcd = vendor;
         *      PMVendorMasterType[] VendorsMasterType = { VendorMasterType };
         *
         *      eConnect.PMVendorMasterType = VendorsMasterType;
         *
         *      //MemoryStream ms = new MemoryStream();
         *      FileStream FS = new FileStream(@"C:\DOCS\eConnectVendor.xml", FileMode.Create);
         *
         *      XmlTextWriter writer = new XmlTextWriter(FS, new UTF8Encoding());
         *
         *      XmlSerializer serializer = new XmlSerializer(eConnect.GetType());
         *      serializer.Serialize(writer, eConnect);
         *      writer.Close();
         *
         *      XmlDocument xmldoc = new XmlDocument();
         *
         *
         *      xmldoc.Load(@"C:\DOCS\eConnectVendor.xml");
         *
         *      string VendorEntity = xmldoc.OuterXml;
         *
         *      File.Delete(@"C:\DOCS\eConnectVendor.xml");
         *
         *      return VendorEntity;
         *
         *  }
         *  catch (XmlException)
         *  {
         *      throw;
         *  }
         *  catch (Exception)
         *  {
         *
         *      throw;
         *  }
         *
         *
         * }
         */


        /// <summary>
        ///
        /// </summary>
        /// <param name="vendor"></param>
        /// <returns></returns>
        private string SerializeVendor(taUpdateCreateVendorRcd vendor)
        {
            try
            {
                PMVendorMasterType VendorMasterType = new PMVendorMasterType();
                eConnectType       eConnect         = new eConnectType();
                VendorMasterType.taUpdateCreateVendorRcd = vendor;
                PMVendorMasterType[] VendorsMasterType = { VendorMasterType };

                eConnect.PMVendorMasterType = VendorsMasterType;

                MemoryStream ms = new MemoryStream();

                XmlSerializer serializer = new XmlSerializer(eConnect.GetType());
                serializer.Serialize(ms, eConnect);
                ms.Position = 0;
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(ms);
                string VendorEntity = xmldoc.OuterXml;
                return(VendorEntity);
            }
            catch (XmlException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// serialize vendor
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="foundry"></param>
        public static void SerializeVendorObject(string filename, PM00200_Foundry foundry)
        {
            try
            {
                // Instantiate an eConnectType schema object
                eConnectType eConnect = new eConnectType();

                // Instantiate a PMVendorMasterType schema object
                PMVendorMasterType vendortype = new PMVendorMasterType();

                // Instantiate a taUpdateCreateCustomerRcd XML node object
                taUpdateCreateVendorRcd vendor = new taUpdateCreateVendorRcd();

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

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

                // Populate the PMVendorMasterType schema with the taUpdateCreateVendorRcd XML node
                vendortype.taUpdateCreateVendorRcd = vendor;
                PMVendorMasterType[] vendorMaster = { vendortype };

                // Populate the eConnectType object with the PMVendorMasterType schema object
                eConnect.PMVendorMasterType = vendorMaster;

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

                // Serialize the eConnectType object to a file using the XmlTextWriter.
                serializer.Serialize(writer, eConnect);
                writer.Close();
            }
            // catch any errors that occur and display them to the console
            catch (System.Exception ex)
            {
                Console.Write(ex.ToString());
            }
        }
Exemplo n.º 3
0
        public void armaProveedorEconn(ExcelWorksheet hojaXl, int fila, Parametros param)
        {
            try
            {
                iError     = 0;
                Vendor     = new taUpdateCreateVendorRcd();
                VendorType = new PMVendorMasterType();

                Vendor.VENDORID       = hojaXl.Cells[fila, param.facturaPmVENDORID].Value.ToString().Trim();
                Vendor.VENDNAME       = hojaXl.Cells[fila, param.facturaPmVENDORNAME].Value.ToString().Trim();
                Vendor.VNDCLSID       = param.defaultVNDCLSID;
                Vendor.VADDCDPR       = "PRINCIPAL";
                Vendor.UpdateIfExists = 0;
                Vendor.UseVendorClass = 1;

                this.VendorType.taUpdateCreateVendorRcd = this.Vendor;
                this.arrVendorType = new PMVendorMasterType[] { this.VendorType };
            }
            catch (Exception errorGral)
            {
                sMensaje = "Excepción al armar el proveedor. " + errorGral.Message + " [armaProveedorEconn]";
                iError++;
            }
        }
Exemplo n.º 4
0
        public VendorResponseDto ImportGPVendor(taUpdateCreateVendorRcd vendor)
        {
            var response = new VendorResponseDto();

            //var sw = new Stopwatch();
            //sw.Start();
            //decimal elapsedTime = 0;

            try
            {
                string clearValue = "~~~";
                string cdataValue = "<![CDATA[ ]]>";

                //Replace null or empty string properties with the clear data value
                vendor = Fn.ReplaceNullOrEmptyStringProperties(vendor, clearValue);

                var PMVendor = new PMVendorMasterType();
                PMVendor.taUpdateCreateVendorRcd = vendor;

                PMVendorMasterType[] PMVendorType = { PMVendor };

                eConnectType eConnect = new eConnectType();
                eConnect.PMVendorMasterType = PMVendorType;

                MemoryStream  memStream  = new MemoryStream();
                XmlSerializer serializer = new XmlSerializer(eConnect.GetType());
                serializer.Serialize(memStream, eConnect);
                memStream.Position = 0;

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(memStream);
                memStream.Close();

                string finalXML = xmlDocument.OuterXml;
                //After serialization, replace clearValue with the eConnect CDATA value to clear field values that should now be empty
                finalXML = finalXML.Replace(clearValue, cdataValue);

                string responseMessage = string.Empty;
                string errorMessage    = string.Empty;

                string vendorID   = vendor.VENDORID;
                string vendorName = vendor.VENDNAME;

                bool success = eConn.CreateEntity(ref responseMessage, finalXML, _config.Value.GPCompanyDB);

                response.Success   = success;
                response.ErrorCode = 0;

                if (success)
                {
                    response.Message = "Vendor " + vendorID + " imported successfully";
                }
                else
                {
                    errorMessage       = "Failed to import vendor " + vendorID + " - " + vendorName + ": " + responseMessage;
                    response.Message   = errorMessage;
                    response.ErrorCode = LoggingEvents.INSERT_VENDOR_FAILED;
                }

                //sw.Stop();
                //elapsedTime = Convert.ToDecimal(sw.ElapsedMilliseconds);
                //response.Elapsed = elapsedTime.ToString();

                //_logger.LogInformation(LoggingEvents.INSERT_VENDOR_COMPLETE, $"ImportVendor {vendorID} complete: " + response.Elapsed);

                return(response);
            }
            catch (Exception ex)
            {
                //sw.Stop();
                //elapsedTime = Convert.ToDecimal(sw.ElapsedMilliseconds);
                //response.Elapsed = elapsedTime.ToString();

                response.Success   = false;
                response.ErrorCode = LoggingEvents.INSERT_VENDOR_EXCEPTION;
                response.Message   = "An unexpected error occured in ImportGPVendor: " + ex.Message;
                return(response);
            }
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        public static bool CheckeConnectVendor(string gpDatabase, string gpVendorID, ref int errorNumber, ref string errorMessage)
        {
            try
            {
                //Create / update test vendor to check eConnect status
                taUpdateCreateVendorRcd vendor = new taUpdateCreateVendorRcd();

                vendor.VENDORID          = gpVendorID;
                vendor.VENDNAME          = "eConnect Status TEST VENDOR";
                vendor.HOLD              = 1;
                vendor.HOLDSpecified     = true;
                vendor.VENDSTTS          = 2;
                vendor.VENDSTTSSpecified = true;
                vendor.VADDCDPR          = "TEST";
                vendor.VNDCNTCT          = "eConnect Status Test GP Web API";
                vendor.ADDRESS1          = "eConnect Status Test";
                vendor.ADDRESS2          = "eConnect Status Test";
                vendor.ADDRESS3          = "eConnect Status Test";
                vendor.COMMENT1          = "Updated " + DateTime.Now;

                vendor.UpdateIfExists = 1;

                PMVendorMasterType PMVendor = new PMVendorMasterType();
                PMVendor.taUpdateCreateVendorRcd = vendor;

                PMVendorMasterType[] PMVendorType = { PMVendor };

                eConnectType eConnect = new eConnectType();
                eConnect.PMVendorMasterType = PMVendorType;

                MemoryStream  memoryStream  = new MemoryStream();
                XmlSerializer xmlSerializer = new XmlSerializer(eConnect.GetType());
                xmlSerializer.Serialize(memoryStream, eConnect);
                memoryStream.Position = 0;

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(memoryStream);
                memoryStream.Close();

                string response = string.Empty;

                bool returnValue = CreateEntity(ref response, xmlDocument.OuterXml, gpDatabase);

                if (returnValue == true)
                {
                    errorNumber  = 0;
                    errorMessage = string.Empty;
                    return(true);
                }
                else
                {
                    gpVendorID   = string.Empty;
                    errorNumber  = 520;
                    errorMessage = "Failed to import eConnect test vendor: " + response;
                    return(false);
                }
            }
            catch (Exception ex)
            {
                gpVendorID   = string.Empty;
                errorNumber  = 529;
                errorMessage = "An unexpected error occurred in CheckeConnect: " + ex.Message;
                return(false);
            }
        }