예제 #1
0
        public static void SendVSEPTXML(string hostStore, Customer cust, SelectedVehicle veh)
        {
            if (hostStore == null || hostStore.Trim() == "")
            {
                return;
            }                                                           //if unit is not found then store is unkno

            string postData = "";

            try
            {
                ASCIIEncoding encoding = new ASCIIEncoding();
                //here's the data we'll be sending
                StringBuilder postDataBuilder = new StringBuilder();
                postDataBuilder.Append("<?xml version=\"1.0\" ?><ProspectImport><Item><SourceProspectId>" + cust.Customer_ID + "</SourceProspectId><DealershipId>" + GetDealerID(hostStore) + "</DealershipId>");
                postDataBuilder.Append("<Email>" + cust.Email + "</Email>");
                postDataBuilder.Append("<Name>" + cust.FName + " " + cust.LName + "</Name>");
                postDataBuilder.Append("<Phone>" + cust.Phone + "</Phone>");
                postDataBuilder.Append("<SourceDate>" + System.DateTime.Now.ToString());
                postDataBuilder.Append("</SourceDate>");
                postDataBuilder.Append("<VehicleType>" + Utils.FindCDKVehicleType(veh.UnitClass) + "</VehicleType>");
                postDataBuilder.Append("<VehicleMake>" + veh.UnitMake + "</VehicleMake>");
                postDataBuilder.Append("<VehicleModel>" + veh.Model + "</VehicleModel>");
                postDataBuilder.Append("<VehicleYear>" + veh.ModelYear + "</VehicleYear>");
                postDataBuilder.Append("<Notes><![CDATA[" + BuildSB(cust) + "< ]]></Notes>");
                postDataBuilder.Append("</Item></ProspectImport>");
                postData = postDataBuilder.ToString();
                XmlDocument importDoc = new XmlDocument();
                importDoc.LoadXml(postData);
                ConsoleProject.VSEPTPCHService.Service1 sc = new ConsoleProject.VSEPTPCHService.Service1();
                string response = sc.AddProspect(importDoc.OuterXml, "Cycles128");
                sc.Dispose();
                //check for error
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

                doc.LoadXml(@"<?xml version=""1.0""?>" + response);
                XmlNode element = doc.SelectSingleNode("/AddProspectResults");

                if (element["Prospect"]["SourceProspectId"].InnerXml.Contains("error") || element["Prospect"].InnerXml == null)
                {
                    SendErrorEmail("XMLtoCEM-Error", element["Prospect"]["SourceProspectId"].InnerXml + " " + hostStore);
                }
                SendErrorEmail("XMLtoCEM-Good Response", element["Prospect"]["SourceProspectId"].InnerXml + " " + hostStore);
            }
            catch (Exception exc)
            {
                SendErrorEmail("CEM Send Error", "Error in sending xml file to CEM: " + "Exception: " + exc.Message);
            }
        }
예제 #2
0
 public void ProcessProspect(SelectedVehicle veh, Customer cust)
 {
     try
     {
         //send to store
         CustomerCommunications.SendCustomerInfoEmailToStore(veh.Store, cust);
         //if new customer, write to database
         cust.Customer_ID = DatabaseHandler.AddCustomer(cust);
         //send to CEM
         CustomerCommunications.SendVSEPTXML(veh.Store, cust, veh);
     }
     catch (Exception ex)
     {
         SendErrorEmail("error at process prospect", ex.Message);
     }
 }
예제 #3
0
        public void ParseProspect(string emailFileURI)
        {
            try
            {
                XDocument        xdoc     = XDocument.Load(emailFileURI);
                XElement         adf      = xdoc.Element("adf");
                XElement         prospect = adf.Element("prospect");
                CycleTraderEmail email    = new CycleTraderEmail();
                Customer         cust     = new Customer();
                email.requestDate = prospect.Element("requestdate").Value;
                foreach (XElement item in prospect.Element("customer").Element("contact").Elements("name"))
                {
                    foreach (var namepart in item.Attributes("part"))
                    {
                        if (namepart.Value.Equals("first"))
                        {
                            cust.FName = email.first = namepart.Parent.Value;
                        }
                        else if (namepart.Value.Equals("last"))
                        {
                            cust.LName = email.last = namepart.Parent.Value;
                        }
                    }
                }
                cust.Phone        = email.phone = prospect.Element("customer").Element("contact").Element("phone").Value;
                cust.Email        = email.email = prospect.Element("customer").Element("contact").Element("email").Value;
                email.year        = prospect.Element("vehicle").Element("year").Value;
                email.make        = prospect.Element("vehicle").Element("make").Value;
                email.model       = prospect.Element("vehicle").Element("model").Value;
                email.stock       = prospect.Element("vehicle").Element("stock").Value;
                email.price       = prospect.Element("vehicle").Element("price").Value; //tobedone: test
                email.requestDate = prospect.Element("requestdate").Value;
                cust.Comments     = email.comments = prospect.Element("customer").Element("comments").Value;

                SelectedVehicle veh = new SelectedVehicle();
                veh.Model = email.model;
                //strip leading zero
                email.stock     = email.stock.TrimStart('0');
                veh.StockNumber = email.stock;
                veh.Price       = email.price;
                veh.UnitMake    = email.make;
                SqlDataReader reader = DatabaseHandler.FindVehicle(email.stock, email.model);
                if (!reader.HasRows)
                {
                    throw new Exception("Vehicle data not found for " + email.stock + "; " + email.model);
                }
                while (reader.Read())
                {
                    veh.VIN       = reader["VIN"].ToString().TrimStart('0');
                    veh.Store     = reader["storeid"].ToString().ToUpper();
                    cust.VIN      = veh.VIN;
                    veh.Category  = Utils.FindCDKVehicleType(reader["unitclass"].ToString());
                    veh.UnitClass = reader["unitclass"].ToString();
                    veh.ModelYear = reader["modelyear"].ToString();
                }
                ProcessProspect(veh, cust);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }