예제 #1
0
        protected void nextStep_Click(object sender, EventArgs e)
        {
            if (!validateForm())
                return;
            int amountToCharge = Convert.ToInt32(ViewState["originalamount"]);

            string firstName = billTo_firstName.Text;
            string lastName = billTo_lastName.Text;
            string city = billTo_city.Text;
            string country = billTo_country.Text;
            string address = billTo_street1.Text;
            string state = billTo_state.Text;
            string zip = billTo_postalCode.Text;
            string phone = billTo_phoneNumber.Text;
            string email = billTo_email.Text;
            string numstudents = "1"; // numberOfStudents.SelectedValue.ToString();
            string comments = billto_comments.Text;
            string couponcode = ""; // couponCode.Text;
            string registrationId = "0";
            string company = txtcompany.Text;
            string leadsource = (findUs.SelectedItem.Text + " " + sourceOther.Text);
            var conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["classDBF"].ConnectionString);
            conn.Open();
            try
            {
                string insertSql =
                    string.Format(
                        "Insert Into registration ( classId, amounttocharge, firstname, lastname, address, city , state, zipcode, country, phone, email, numstudents, couponcode, comments, DateCreated, company, leadsource ) " +
                        " values ({0},{1},'{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',{11},'{12}', '{13}', '" +
                        DateTime.Now + "','{14}', '{15}')",
                        classID.Text, amountToCharge, firstName, lastName, address, city, state, zip, country, phone, email,
                        numstudents, couponcode, comments, company, leadsource);

                var cmd = new OleDbCommand(insertSql, conn);
                cmd.ExecuteNonQuery();
                cmd = new OleDbCommand("select max(registrationid) from registration", conn);
                registrationId = cmd.ExecuteScalar().ToString();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                return;
            }
            finally
            {
                conn.Close();
            }

            if (ConfigurationManager.AppSettings["SendLeadsToSalesForce"] == "true")
            {
                try
                {
                    var sf = new SalesForceHelper();

                    var lead = new Lead();
                    lead.FirstName = firstName;
                    lead.LastName = lastName;
                    lead.Company = company;
                    lead.Email = email;
                    lead.Phone = phone;
                    if (leadsource.Length > 40)
                        leadsource = leadsource.Substring(0, 40);
                    lead.LeadSource = leadsource;
                    lead.Street = address;
                    lead.City = city;
                    lead.State = state;
                    lead.PostalCode = zip;
                    lead.Description = "Web Site Registration Initiated - " + locationLabel.Text + " " + ClassHeader1.ClassType + " " + classDate.Text + " Comments: " + billto_comments.Text;

                    var sr = sf.Binding.create(new sObject[] {lead});

                    foreach (var s in sr)
                    {
                        if (s.success)
                        {
                            Session["LeadId"] = s.id;
                            break;
                        }
                        throw new Exception(string.Format("Error creating Lead: {0}", s.errors[0].message));
                    }
                }
                catch (Exception ex)
                {
                    var objSendEmail = new SendMail();
                    objSendEmail.IsHTML = true;
                    objSendEmail.Subject = "Error on pinnacle3learning.com - SalesForce Integration";
                    string body = "<b>Message</b><br>" + ex.Message + "<br><br>";
                    body += "<b>Attempting to Create Lead</b><br>" + firstName + " " + lastName + "<br><br>";
                    body += "<b>Page</b><br>register.aspx<br><br>";
                    body += "<b>Inner Exception</b><br>" + ex.InnerException + "<br><br>";
                    body += "<b>Stack Trace</b><br>" + ex.StackTrace + "<br><br>";
                    body += "<b>TimeStamp</b><br>" + DateTime.Now.ToString() + "<br><br>";
                    objSendEmail.Body = body;
                    SendMail.Send(objSendEmail, true);
                }
            }
            nextStep.Visible = false;
            string url;
            // if the config setting allows it, go secure for the rest of the user's visit.
            if (ConfigurationManager.AppSettings["GoSecure"] == "true")
            {
                url = String.Format("https://{0}{1}",
                                           Request.ServerVariables["HTTP_HOST"],
                                           ResolveUrl("~/confirm.aspx?registrationid=" + registrationId));
            }
            else
            {
                url = "confirm.aspx?registrationid=" + registrationId;
            }
            var redirect = "window.location.href='" + url + "'";
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), redirect, true);
        }
예제 #2
0
        private void _doSalesForceWork(string opportunityName, string companyName, int amountToCharge, string targetLocation, DateTime targetDate)
        {
            try
            {
                if (Session["LeadId"] == null || string.IsNullOrEmpty(Session["LeadId"].ToString()))
                    return;
                // Retrieve the Lead record;
                string leadId = Session["LeadId"].ToString();
                string accountId = "";
                SalesForceHelper sf = new SalesForceHelper();

                QueryResult qr = null;

                sf.Binding.QueryOptionsValue = new QueryOptions();
                sf.Binding.QueryOptionsValue.batchSize = 250;
                sf.Binding.QueryOptionsValue.batchSizeSpecified = true;

                qr = sf.Binding.query("select Id, Name from Account where name = '" + companyName + "'");
                if (qr != null && qr.records != null)
                    foreach (sObject t in qr.records)
                    {
                        Account a = (Account) t;
                        accountId = a.Id;
                        break;
                    }

                string optyId = sf.ConvertLeadToOpportunity(leadId, accountId, opportunityName);
                sObject[] records = sf.Binding.retrieve("Id, Name, StageName", "Opportunity", new[] {optyId});

                if (records.Length == 1)
                {
                    Opportunity opty = (Opportunity) records[0];
                    opty.StageName = "Proposal/Price Quote";
                    opty.Description = "Web Site Registration Confirmed & Unpaid - " + lblClassLocation.Text + " " +
                                       lblClass.Text + " " + lblClassDate.Text + " " + lblClassDays.Text + " Comments: " +
                                       billto_comments.Text;
                    opty.Amount = amountToCharge;
                    opty.AmountSpecified = true;
                    opty.Target_Date__c = targetDate;
                    opty.Target_Date__cSpecified = true;
                    opty.Target_Location__c = targetLocation;
                    sf.Binding.update(new[] {opty});
                }

                sf.Binding.logout();
            }
            catch (Exception ex)
            {
                SendMail objSendEmail = new SendMail();
                objSendEmail.IsHTML = true;
                objSendEmail.Subject = "Error on pinnacle3learning.com - SalesForce Integration ";
                string body = "<b>Message</b><br>" + ex.Message + "<br><br>";
                body += "<b>Attempting to Convert Lead</b><br>" + opportunityName + "<br><br>";
                body += "<b>Page</b><br>confirmed-paid.aspx<br><br>";
                body += "<b>Inner Exception</b><br>" + ex.InnerException + "<br><br>";
                body += "<b>Stack Trace</b><br>" + ex.StackTrace + "<br><br>";
                body += "<b>TimeStamp</b><br>" + DateTime.Now.ToString() + "<br><br>";
                objSendEmail.Body = body;
                SendMail.Send(objSendEmail, true);
            }
        }