private string SerializeSalesPerson(taCreateSalesperson salesperson)
        {
            try
            {
                RMSalespersonMasterType salespersonType = new RMSalespersonMasterType();
                eConnectType            eConnect        = new eConnectType();
                salespersonType.taCreateSalesperson = salesperson;

                RMSalespersonMasterType[] rmsalesperson = { salespersonType };

                eConnect.RMSalespersonMasterType = rmsalesperson;

                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 SalespersonEntity = xmldoc.OuterXml;
                return(SalespersonEntity);
            }
            catch (XmlException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// serialize sales person
        /// </summary>
        /// <param name="filename"></param>
        public static void SerializeSalespersonObject(string filename)
        {
            try
            {
                // Instantiate an eConnectType schema object
                eConnectType eConnect = new eConnectType();

                // Instantiate a RMSalespersonMasterType schema object
                RMSalespersonMasterType salespersonType = new RMSalespersonMasterType();

                // Instantiate a taCreateSalesperson XML node object
                taCreateSalesperson salesperson = new taCreateSalesperson();

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

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

                // Populate the RMSalespersonMasterType schema with the taCreateSalesperson XML node
                salespersonType.taCreateSalesperson = salesperson;
                RMSalespersonMasterType[] salespersonMaster = { salespersonType };

                // Populate the eConnectType object with the RMSalespersonMasterType schema object
                eConnect.RMSalespersonMasterType = salespersonMaster;

                // 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());
            }
        }
        private taCreateSalesperson SetSalesPersonValues(RMSalesPerson salesperson)
        {
            taCreateSalesperson rmsalespersoninsert = new taCreateSalesperson();

            try
            {
                rmsalespersoninsert.SLPRSNID = salesperson.SLPRSNID;
                rmsalespersoninsert.SALSTERR = salesperson.SALSTERR;
                rmsalespersoninsert.EMPLOYID = salesperson.EMPLOYID;
                rmsalespersoninsert.VENDORID = salesperson.VEDORID;
                rmsalespersoninsert.SLPRSNFN = salesperson.SLPRSNFN;
                rmsalespersoninsert.SPRSNSMN = salesperson.SPRSNSMN;
                rmsalespersoninsert.SPRSNSLN = salesperson.SPRSNSLN;
                rmsalespersoninsert.ADDRESS1 = salesperson.ADDRESS1;
                rmsalespersoninsert.ADDRESS2 = salesperson.ADDRESS2;
                rmsalespersoninsert.ADDRESS3 = salesperson.ADDRESS3;
                rmsalespersoninsert.CITY     = salesperson.CITY;
                rmsalespersoninsert.STATE    = salesperson.STATE;
                rmsalespersoninsert.ZIP      = salesperson.ZIP;
                rmsalespersoninsert.COUNTRY  = salesperson.COUNTRY;
                rmsalespersoninsert.PHONE1   = salesperson.PHONE1;
                rmsalespersoninsert.PHONE2   = salesperson.PHONE2;
                rmsalespersoninsert.PHONE3   = salesperson.PHONE3;
                rmsalespersoninsert.FAX      = salesperson.FAX;
                rmsalespersoninsert.INACTIVE = salesperson.INACTIVE.GetValueOrDefault();
                rmsalespersoninsert.COMMCODE = salesperson.COMMCODE;
                rmsalespersoninsert.COMPRCNT = salesperson.COMPRCNT.GetValueOrDefault();
                rmsalespersoninsert.STDCPRCT = salesperson.STDCPRCT.GetValueOrDefault();
                rmsalespersoninsert.COMAPPTO = salesperson.COMAPPTO.GetValueOrDefault();
                rmsalespersoninsert.COSTTODT = salesperson.COSTTODT.GetValueOrDefault();
                rmsalespersoninsert.CSTLSTYR = salesperson.CSTLSTYR.GetValueOrDefault();
                rmsalespersoninsert.TTLCOMTD = salesperson.TTLCOMTD.GetValueOrDefault();
                rmsalespersoninsert.TTLCOMLY = salesperson.TTLCOMLY.GetValueOrDefault();
                rmsalespersoninsert.COMSLTDT = salesperson.COMSLTDT.GetValueOrDefault();
                rmsalespersoninsert.COMSLLYR = salesperson.COMSLLYR.GetValueOrDefault();
                rmsalespersoninsert.NCOMSLTD = salesperson.NCOMSLTD.GetValueOrDefault();
                rmsalespersoninsert.NCOMSLYR = salesperson.NCOMSLYR.GetValueOrDefault();
                rmsalespersoninsert.KPCALHST = salesperson.KPCALHST.GetValueOrDefault();

                if (salesperson.MODIFDT != null)
                {
                    rmsalespersoninsert.MODIFDT = salesperson.MODIFDT.GetValueOrDefault().ToShortDateString();
                }

                if (salesperson.CREATDDT != null)
                {
                    rmsalespersoninsert.CREATDDT = salesperson.CREATDDT.GetValueOrDefault().ToShortDateString();
                }

                rmsalespersoninsert.COMMDEST       = salesperson.COMMDEST.GetValueOrDefault();
                rmsalespersoninsert.UpdateIfExists = salesperson.UpdateIfExists.GetValueOrDefault();
                rmsalespersoninsert.RequesterTrx   = salesperson.RequesterTrx.GetValueOrDefault();


                return(rmsalespersoninsert);
            }
            catch (Exception)
            {
                throw;
            }
        }