Esempio n. 1
0
        public void AddSelectedContactsAsLeadsToProject(String project_id, String source)
        {
            ArrayList added_lead_ids = SelectedValidContactIDs;

            String username = Util.GetUserFullNameFromUserId(hf_user_id.Value);

            // Iterate -selected- and -valid- contacts in Contact Manager and add as Leads
            for (int i = 0; i < added_lead_ids.Count; i++)
            {
                String ctc_id          = (String)added_lead_ids[i];
                String contact_history = "Added at " + DateTime.Now + " (GMT) by " + username;

                String iqry    = "INSERT INTO dbl_lead (ProjectID, ContactID, Source, LatestNoteID) VALUES (@ProjectID, @ContactID, @Source, (SELECT MAX(NoteID) FROM db_contact_note WHERE ContactID=@ContactID));";
                long   lead_id = SQL.Insert(iqry,
                                            new String[] { "@ProjectID", "@ContactID", "@Source" },
                                            new Object[] { project_id, ctc_id, source });

                // Add lead flag to contact types
                iqry = "INSERT IGNORE INTO db_contactintype (ContactID, ContactTypeID) VALUES (@ctc_id, (SELECT ContactTypeID FROM db_contacttype WHERE SystemName='Lead' AND ContactType='Lead'));";
                SQL.Insert(iqry, "@ctc_id", ctc_id);

                // Log
                LeadsUtil.AddLeadHistoryEntry(lead_id.ToString(), "Adding Lead to the " + LeadsUtil.GetProjectFullNameFromID(project_id) + " Project.");
            }
        }
Esempio n. 2
0
    protected void KillThisLead(object sender, EventArgs e)
    {
        if (dd_dont_contact_for.Items.Count > 0 && dd_dont_contact_reason.Items.Count > 0)
        {
            String action = "Lead killed";
            String dont_contact_for_expr = String.Empty;
            if (cb_dont_contact_for.Checked)
            {
                dont_contact_for_expr = ", dont_contact_until=DATE_ADD(NOW(), INTERVAL " + dd_dont_contact_for.SelectedItem.Value + " MONTH) ";
                action += ". Don't contact set for " + dd_dont_contact_for.SelectedItem.Text;
            }
            String dont_contact_reason = dd_dont_contact_reason.SelectedItem.Text;
            if (dd_dont_contact_reason.SelectedItem.Text == "Other" && tb_other_reason.Text.Trim() != String.Empty)
            {
                dont_contact_reason = tb_other_reason.Text;
            }

            action += ". Reason: " + dont_contact_reason + ".";

            String uqry = "UPDATE dbl_lead, db_contact SET dbl_lead.Active=0, DateUpdated=CURRENT_TIMESTAMP, dont_contact_reason=@dont_contact_reason," +
                          "dont_contact_added=CURRENT_TIMESTAMP, dont_contact_user_id=@user_id " + dont_contact_for_expr +
                          "WHERE dbl_lead.ContactID = db_contact.ctc_id AND LeadID=@LeadID";
            SQL.Update(uqry,
                       new String[] { "@LeadID", "@user_id", "@dont_contact_reason" },
                       new Object[] { hf_lead_id.Value, Util.GetUserId(), dont_contact_reason });

            // Log
            LeadsUtil.AddLeadHistoryEntry(hf_lead_id.Value, action);

            Util.CloseRadWindowFromUpdatePanel(this, String.Empty, false);
        }
    }
Esempio n. 3
0
    protected void EstimateEmailWithDataGeek(Contact c)
    {
        String UserID = Util.GetUserId();

        EstimatedEmail     = c.GetEstimatedEmailThroughDataGeek(UserID);
        IsDataGeekEstimate = true;

        if (EstimatedEmail.Contains("@"))
        {
            // Determine the ID of the entry to delete is the user cancels this estimation
            String qry            = "SELECT EmailHistoryID FROM db_contact_email_history WHERE EmailHistoryID=(SELECT MAX(EmailHistoryID) FROM db_contact_email_history WHERE ContactID=@ContactID AND DataGeekEstimate=1 AND Deleted=0 AND EstimatedByUserId=@EstimatedByUserId)";
            String EmailHistoryID = SQL.SelectString(qry, "EmailHistoryID", new String[] { "@ContactID", "@EstimatedByUserId" }, new Object[] { c.ContactID, UserID });
            if (!String.IsNullOrEmpty(EmailHistoryID))
            {
                String onok     = "var rb=$find('" + se.ClientID + "'); rb.click();";
                String oncancel = "var rb=$find('" + de.ClientID + "'); rb.click();";
                Util.PageMessagePrompt(this.Parent.Page, "Here's what DataGeek generated.. ", EstimatedEmail, onok, oncancel, "E-mail Address Generated");

                if (!String.IsNullOrEmpty(LeadID))
                {
                    LeadsUtil.AddLeadHistoryEntry(LeadID, "Estimated e-mail for this contact using DataGeek, generated e-mail: " + EstimatedEmail);
                }
            }
        }
        else
        {
            Util.PageMessageAlertify(this.Parent.Page, EstimatedEmail, "Estimation Results");
        }
    }
Esempio n. 4
0
    protected void MoveSelectedLeads(object sender, EventArgs e)
    {
        if (dd_buckets.Items.Count > 0)
        {
            String new_project_id = dd_buckets.SelectedItem.Value;
            hf_lead_ids.Value = hf_lead_ids.Value.Replace(",", " ").Trim();
            String[] ctc_ids     = hf_lead_ids.Value.Split(' ');
            String   ProjectName = LeadsUtil.GetProjectFullNameFromID(new_project_id);
            Util.SetRebindOnWindowClose(udp_move, true);
            String UserID = Util.GetUserId();

            if (hf_from_search.Value == "1")
            {
                String iqry = "INSERT INTO dbl_lead (ProjectID, ContactID, Source) VALUES (@ProjectID, @ContactID, 'RSA');";
                foreach (String ctc_id in ctc_ids)
                {
                    String lead_id = SQL.Insert(iqry,
                                                new String[] { "@ProjectID", "@ContactID" },
                                                new Object[] { new_project_id, ctc_id }).ToString();

                    // Log
                    LeadsUtil.AddLeadHistoryEntry(lead_id, "Lead added to the " + ProjectName + " Project.");
                }
            }
            else
            {
                String uqry = "UPDATE dbl_lead SET ProjectID=@NewProjectID WHERE LeadID=@LeadID;";
                String qry  = "SELECT LeadID FROM dbl_lead WHERE LeadID=@LeadID AND (ProjectID IN (SELECT ProjectID FROM dbl_project WHERE UserID=@UserID) OR ProjectID IN (SELECT ProjectID FROM dbl_project_share WHERE UserID=@UserID))";
                foreach (String lead_id in ctc_ids)
                {
                    // Verify Lead exists and ownership
                    if (SQL.SelectDataTable(qry, new String[] { "@LeadID", "@UserID" }, new Object[] { lead_id, UserID }).Rows.Count > 0)
                    {
                        SQL.Update(uqry,
                                   new String[] { "@NewProjectID", "@LeadID" },
                                   new Object[] { new_project_id, lead_id });

                        // Log
                        LeadsUtil.AddLeadHistoryEntry(lead_id, "Lead moved to the " + ProjectName + " Project.");
                    }
                }
            }

            Util.CloseRadWindowFromUpdatePanel(this, String.Empty, false);
        }
        else
        {
            Util.PageMessageAlertify(this, "You have no other Projects to move your Leads to.\\n\\nPlease close this window and add another Project first.", "Retry");
        }
    }
Esempio n. 5
0
    protected void AddLeadToProject(object sender, ImageClickEventArgs e)
    {
        ImageButton  imbtn_action = (ImageButton)sender;
        GridDataItem item         = (GridDataItem)imbtn_action.Parent.Parent;
        String       ctc_id       = item["ContactID"].Text;

        String[] pn = new String[] { "@ProjectID", "@ContactID" };
        Object[] pv = new Object[] { hf_project_id.Value, ctc_id };

        String iqry        = "INSERT INTO dbl_lead (ProjectID, ContactID, Source) VALUES (@ProjectID, @ContactID, 'OVA');";
        long   new_lead_id = SQL.Insert(iqry, pn, pv);

        // Log
        LeadsUtil.AddLeadHistoryEntry(new_lead_id.ToString(), "Adding Lead to the " + LeadsUtil.GetProjectFullNameFromID(hf_project_id.Value) + " Project.");

        BindOtherContacts(null, null);
    }
Esempio n. 6
0
    protected void MoveLead(object sender, EventArgs e)
    {
        if (dd_buckets.Items.Count > 0 && dd_buckets.SelectedItem != null)
        {
            String new_project_id = dd_buckets.SelectedItem.Value;
            String uqry           = "UPDATE dbl_lead SET ProjectID=@NewProjectID WHERE LeadID=@LeadID;";
            SQL.Update(uqry,
                       new String[] { "@NewProjectID", "@LeadID" },
                       new Object[] { new_project_id, hf_lead_id.Value });

            // Log
            LeadsUtil.AddLeadHistoryEntry(hf_lead_id.Value, "Lead moved to the " + LeadsUtil.GetProjectFullNameFromID(new_project_id) + " Project.");
        }
        else
        {
            Util.PageMessageAlertify(this, "You have no other Projects to move your Leads to.\\n\\nPlease add another Project first.", "Retry");
        }
    }
    public void ClearNextAction(object sender, EventArgs e)
    {
        String uqry = "UPDATE dbl_lead SET NextActionTypeID=0, NextActionDate=NULL WHERE LeadID=@LeadID";

        SQL.Update(uqry, "@LeadID", hf_lead_id.Value);
        rdp_next_action.SelectedDate = null;

        // Log
        LeadsUtil.AddLeadHistoryEntry(LeadID, "Next action cleared.");

        Util.PageMessageSuccess(this, "Next Action Cleared!", "top-right");

        if (InWindow) // resize
        {
            Util.ResizeRadWindow(this);
        }

        BindNotesAndNextAction();

        UpdateParentPage(true);
    }
Esempio n. 8
0
    protected void MakeSuspect(object sender, EventArgs e)
    {
        CompanyManager.UpdateCompany();

        if (CompanyManager.Turnover == null || CompanyManager.Industry == null || (CompanyManager.CompanySize == null && CompanyManager.CompanySizeBracket == null) || CompanyManager.Country == null || CompanyManager.Website == null)
        {
            Util.PageMessageAlertify(this, "You must have Country, Industry, Turnover, Company Size and Website specified " +
                                     "to push this Lead to Prospect.<br/><br/>Click the company edit pencil and specify the required data.", "Data Required");
        }
        else
        {
            String user_id = Util.GetUserId();

            // Find any Leads in this user's Projects which share this company so that they can be pushed to Suspect too
            String qry = "SELECT LeadID, dbl_project.ProjectID FROM dbl_lead, dbl_project, db_contact, db_company " +
                         "WHERE dbl_lead.ContactID=db_contact.ctc_id AND db_contact.new_cpy_id=db_company.cpy_id AND dbl_lead.ProjectID = dbl_project.ProjectID " +
                         "AND dbl_project.UserID=@user_id AND dbl_lead.Active=1 AND dbl_project.Active=1 AND db_company.cpy_id=@cpy_id";
            DataTable dt_leads = SQL.SelectDataTable(qry,
                                                     new String[] { "@user_id", "@cpy_id" },
                                                     new Object[] { user_id, hf_company_id.Value });

            for (int i = 0; i < dt_leads.Rows.Count; i++)
            {
                String this_lead_id    = dt_leads.Rows[i]["LeadID"].ToString();
                String this_project_id = LeadsUtil.GetProjectParentIDFromID(dt_leads.Rows[i]["ProjectID"].ToString());

                String uqry = "UPDATE dbl_lead SET Suspect=1, DateMadeSuspect=CURRENT_TIMESTAMP, " +
                              "ProjectID=(SELECT ProjectID FROM dbl_project WHERE name='Suspects' AND UserID=@user_id AND ParentProjectID=@project_id) WHERE LeadID=@lead_id";
                SQL.Update(uqry,
                           new String[] { "@lead_id", "@user_id", "@project_id" },
                           new Object[] { this_lead_id, user_id, this_project_id });

                // Leads Log
                LeadsUtil.AddLeadHistoryEntry(this_lead_id, "Pushed to Suspect.");
            }

            LeadsUtil.SetNoRebindOnWindowClose(udp_pts, false);
            Util.CloseRadWindowFromUpdatePanel(this, String.Empty, false);
        }
    }
    protected void DeleteAppointment(object sender, EventArgs e)
    {
        if (GmailAuthenticator.CheckAuthenticated(hf_uri.Value, hf_user_id.Value))
        {
            ImageButton  imbtn_del     = (ImageButton)sender;
            GridDataItem gdi           = (GridDataItem)imbtn_del.Parent.Parent;
            String       AppointmentID = gdi["AppointmentID"].Text;
            String       GoogleEventID = gdi["GoogleEventID"].Text;

            String dqry = "DELETE FROM dbl_appointments WHERE AppointmentID=@AppointmentID";
            SQL.Delete(dqry, "@AppointmentID", AppointmentID);

            RefreshNextAppointment();

            // Delete from Google calendar
            CalendarService service = LeadsUtil.GetCalendarService(hf_uri.Value, hf_user_id.Value);
            if (service != null)
            {
                try  // appears to be no way to do a check to see if calendar item exists by a given ID..
                {
                    service.Events.Delete(LeadsUtil.GoogleCalendarID, GoogleEventID).Execute();

                    // Log
                    LeadsUtil.AddLeadHistoryEntry(hf_lead_id.Value, "Deleting Google appointment.");
                }
                catch
                {
                    Util.PageMessageAlertify(this, "This appointment wasn't found in your Outlook calendar, probably because it was deleted from Outlook earlier.<br/><br/>Please try to add/remove all Leads appointments through DataGeek to avoid any discrepancies in the future.");
                }
            }
            else
            {
                Util.PageMessageAlertify(this, "Error getting calendar service from Google, please try again.");
            }

            Util.SetRebindOnWindowClose(this, true);
            Util.PageMessageSuccess(this, "Appointment deleted (also removed from your Outlook calendar)");
        }
        BindAppointments();
    }
Esempio n. 10
0
    protected void EstimateEmailEmailHunter(Contact c)
    {
        int    Score;
        String Sources;

        EstimatedEmail      = c.GetEstimatedEmailThroughEmailHunter(out Score, out Sources);
        EstimatedEmailScore = Score;
        IsDataGeekEstimate  = false;

        if (EstimatedEmail.Contains("@"))
        {
            String onok = "var rb=$find('" + se.ClientID + "'); rb.click();";
            Util.PageMessagePrompt(this.Parent.Page, "Here's what we found.. (with a score of " + Score + ")" + Sources, EstimatedEmail, onok, String.Empty, "E-mail Address Found");

            if (!String.IsNullOrEmpty(LeadID))
            {
                LeadsUtil.AddLeadHistoryEntry(LeadID, "E-mail Hunter request returned e-mail: " + EstimatedEmail + " (" + Score + ")");
            }
        }
        else
        {
            Util.PageMessageAlertify(this.Parent.Page, EstimatedEmail, "Estimation Results");
        }
    }
    protected void KillSelectedLeads(object sender, EventArgs e)
    {
        if (dd_dont_contact_for.Items.Count > 0 && dd_dont_contact_reason.Items.Count > 0)
        {
            String action = "Lead killed";
            String dont_contact_for_expr = String.Empty;
            String UserID = Util.GetUserId();
            if (cb_dont_contact_for.Checked)
            {
                dont_contact_for_expr = ", DontContactUntil=DATE_ADD(NOW(), INTERVAL " + dd_dont_contact_for.SelectedItem.Value + " MONTH) ";
                action += ". Don't contact set for " + dd_dont_contact_for.SelectedItem.Text;
            }
            String dont_contact_reason = dd_dont_contact_reason.SelectedItem.Text;
            if (dd_dont_contact_reason.SelectedItem.Text == "Other" && tb_other_reason.Text.Trim() != String.Empty)
            {
                dont_contact_reason = tb_other_reason.Text;
            }
            if (dont_contact_reason.Trim() == String.Empty)
            {
                dd_dont_contact_reason = null;
            }

            action += ". Reason: " + dont_contact_reason + ".";

            hf_lead_ids.Value = hf_lead_ids.Value.Replace(",", " ").Trim();
            String[]  lead_ids = hf_lead_ids.Value.Split(' ');
            ArrayList ctc_ids  = new ArrayList();

            String user_id = Util.GetUserId();
            bool   set_dnc = !dont_contact_reason.Contains("soft kill");

            String ctc_uqry = "UPDATE dbl_lead, db_contact SET db_contact.LastUpdated=CURRENT_TIMESTAMP, DontContactReason=@DontContactReason," +
                              "DontContactDateSet=CURRENT_TIMESTAMP, DontContactSetByUserID=@user_id " + dont_contact_for_expr +
                              "WHERE dbl_lead.ContactID = db_contact.ContactID AND LeadID=@LeadID";
            String lead_uqry      = "UPDATE dbl_lead SET Active=0, DateUpdated=CURRENT_TIMESTAMP WHERE LeadID=@LeadID";
            String ownsership_qry = "SELECT LeadID FROM dbl_lead WHERE LeadID=@LeadID AND (ProjectID IN (SELECT ProjectID FROM dbl_project WHERE UserID=@UserID) OR ProjectID IN (SELECT ProjectID FROM dbl_project_share WHERE UserID=@UserID))";
            foreach (String lead_id in lead_ids)
            {
                // Verify Lead exists and ownership
                if (SQL.SelectDataTable(ownsership_qry, new String[] { "@LeadID", "@UserID" }, new Object[] { lead_id, UserID }).Rows.Count > 0)
                {
                    String qry = "SELECT ContactID FROM dbl_lead WHERE LeadID=@lead_id";

                    // Update lead
                    SQL.Update(lead_uqry, "@LeadID", lead_id);

                    // Update contact dnc (only add once for each same contact)
                    if (set_dnc)
                    {
                        String ctc_id = SQL.SelectString(qry, "ContactID", "@lead_id", lead_id);
                        if (!ctc_ids.Contains(ctc_id))
                        {
                            ctc_ids.Add(ctc_id);
                            SQL.Update(ctc_uqry,
                                       new String[] { "@LeadID", "@user_id", "@DontContactReason" },
                                       new Object[] { lead_id, user_id, dont_contact_reason });
                        }
                    }

                    // Log
                    LeadsUtil.AddLeadHistoryEntry(lead_id, action);
                }
            }
        }

        Util.SetRebindOnWindowClose(this, true);
        Util.CloseRadWindowFromUpdatePanel(this, hf_from_viewer.Value, false);
    }
    protected void CreateOrUpdateAppointment(object sender, EventArgs e)
    {
        if (GmailAuthenticator.CheckAuthenticated(hf_uri.Value, hf_user_id.Value))
        {
            RadButton btn = (RadButton)sender;
            bool      CreatingAppointment = btn.Text.Contains("Create");

            DateTime AppointmentStart = new DateTime();
            DateTime AppointmentEnd   = new DateTime();

            if (rdp_app_start.SelectedDate != null && rdp_app_end.SelectedDate != null &&
                DateTime.TryParse(rdp_app_start.SelectedDate.ToString(), out AppointmentStart) && DateTime.TryParse(rdp_app_end.SelectedDate.ToString(), out AppointmentEnd) &&
                AppointmentStart <= AppointmentEnd)
            {
                String tz = "America/Los_Angeles";
                if (Util.GetOfficeRegion(Util.GetUserTerritory()) == "UK")
                {
                    tz = "Europe/London";
                }

                // Craft appointment (event)
                Event Appointment = new Event();
                Appointment.Created = DateTime.Now;
                Appointment.Start   = new EventDateTime()
                {
                    DateTime = AppointmentStart, TimeZone = tz
                };
                Appointment.End = new EventDateTime()
                {
                    DateTime = AppointmentEnd, TimeZone = tz
                };
                Appointment.Status      = dd_app_status.SelectedItem.Value; // confirmed / tentative / cancelled
                Appointment.Location    = tb_app_location.Text.Trim();
                Appointment.Summary     = rcb_app_subject.Text.Trim();
                Appointment.Description = tb_app_body.Text.Trim();

                // Add Lead information to the appointment by default
                String    qry          = "SELECT * FROM dbl_lead, db_contact, db_company WHERE dbl_lead.ContactID=db_contact.ContactID AND db_contact.CompanyID = db_company.CompanyID AND LeadID=@LeadID";
                DataTable dt_lead_info = SQL.SelectDataTable(qry, "@LeadID", hf_lead_id.Value);
                if (dt_lead_info.Rows.Count > 0)
                {
                    String LeadAppend = String.Empty;

                    String CompanyName      = dt_lead_info.Rows[0]["CompanyName"].ToString().Trim();
                    String ContactName      = (dt_lead_info.Rows[0]["FirstName"] + " " + dt_lead_info.Rows[0]["LastName"]).Trim();
                    String Country          = dt_lead_info.Rows[0]["Country"].ToString().Trim();
                    String Industry         = dt_lead_info.Rows[0]["Industry"].ToString().Trim();
                    String CompanyPhone     = dt_lead_info.Rows[0]["Phone"].ToString().Trim();
                    String CompanyPhoneCode = dt_lead_info.Rows[0]["PhoneCode"].ToString().Trim();
                    String Website          = dt_lead_info.Rows[0]["Website"].ToString().Trim();
                    String JobTitle         = dt_lead_info.Rows[0]["JobTitle"].ToString().Trim();
                    String Email            = dt_lead_info.Rows[0]["Email"].ToString().Trim();
                    String PersonalEmail    = dt_lead_info.Rows[0]["PersonalEmail"].ToString().Trim();
                    String Phone            = dt_lead_info.Rows[0]["Phone"].ToString().Trim();
                    String Mobile           = dt_lead_info.Rows[0]["Mobile"].ToString().Trim();

                    String CpyPhone = CompanyPhone;
                    if (CompanyPhone != String.Empty)
                    {
                        CpyPhone = "(" + CompanyPhoneCode + ")" + CompanyPhone;
                    }

                    if (CompanyName == String.Empty)
                    {
                        CompanyName = "None";
                    }
                    if (ContactName == String.Empty)
                    {
                        ContactName = "None";
                    }
                    if (Country == String.Empty)
                    {
                        Country = "None";
                    }
                    if (Industry == String.Empty)
                    {
                        Industry = "None";
                    }
                    if (Website == String.Empty)
                    {
                        Website = "None";
                    }
                    if (JobTitle == String.Empty)
                    {
                        JobTitle = "None";
                    }
                    if (Email == String.Empty)
                    {
                        Email = "None";
                    }
                    if (PersonalEmail == String.Empty)
                    {
                        PersonalEmail = "None";
                    }
                    if (Phone == String.Empty)
                    {
                        Phone = "None";
                    }
                    if (Mobile == String.Empty)
                    {
                        Mobile = "None";
                    }
                    if (CpyPhone == String.Empty)
                    {
                        CpyPhone = "None";
                    }

                    String br = Environment.NewLine + Environment.NewLine;
                    if (Appointment.Description == String.Empty)
                    {
                        br = String.Empty;
                    }

                    LeadAppend = br +
                                 "Company: " + CompanyName + Environment.NewLine +
                                 "Country: " + Country + Environment.NewLine +
                                 "Industry: " + Industry + Environment.NewLine +
                                 "Company Phone: " + CpyPhone + Environment.NewLine +
                                 "Website: " + Website + Environment.NewLine +
                                 "Contact: " + ContactName + Environment.NewLine +
                                 "Job Title: " + JobTitle + Environment.NewLine +
                                 "E-mail: " + Email + Environment.NewLine +
                                 "Personal E-mail: " + PersonalEmail + Environment.NewLine +
                                 "Phone: " + Phone + Environment.NewLine +
                                 "Mobile: " + Mobile;
                    if (Appointment.Summary == String.Empty)
                    {
                        Appointment.Summary += "App. w/ " + ContactName;
                    }
                    else if (!Appointment.Summary.Contains(ContactName))
                    {
                        Appointment.Summary += " w/ " + ContactName;
                    }

                    // Attendees
                    if (btn_include_attendees.SelectedToggleState.Value == "True" && Util.IsValidEmail(tb_app_attendees.Text))
                    {
                        String[] AttendeesArray = tb_app_attendees.Text.Trim().Split(';');
                        Appointment.Attendees = new List <EventAttendee>();
                        foreach (String ae in AttendeesArray)
                        {
                            String AttendeeEmail = ae.Trim().Replace(";", String.Empty);
                            if (AttendeeEmail != String.Empty)
                            {
                                EventAttendee Attendee = new EventAttendee()
                                {
                                    Email = AttendeeEmail
                                };
                                Appointment.Attendees.Add(Attendee);
                            }
                        }
                    }
                    else
                    {
                        Appointment.Description += LeadAppend;
                    }
                }

                // Get Calendar service
                CalendarService service = LeadsUtil.GetCalendarService(hf_uri.Value, hf_user_id.Value);
                if (service != null)
                {
                    if (CreatingAppointment) // creating appointment
                    {
                        Appointment = service.Events.Insert(Appointment, LeadsUtil.GoogleCalendarID).Execute();
                        if (Appointment != null)
                        {
                            // insert into db
                            String iqry = "INSERT INTO dbl_appointments (LeadID, GoogleEventID, AppointmentStart, AppointmentEnd, Summary, Description, Location) VALUES (@LeadID, @GoogleEventID, @AppointmentStart, @AppointmentEnd, @Summary, @Description, @Location)";
                            SQL.Insert(iqry,
                                       new String[] { "@LeadID", "@GoogleEventID", "@AppointmentStart", "@AppointmentEnd", "@Summary", "@Description", "@Location" },
                                       new Object[] { hf_lead_id.Value, Appointment.Id, AppointmentStart, AppointmentEnd, Appointment.Summary, Appointment.Description, Appointment.Location });

                            // Log
                            LeadsUtil.AddLeadHistoryEntry(hf_lead_id.Value, "Adding Google appointment: " + Appointment.Summary);

                            RefreshNextAppointment();
                            Util.PageMessageSuccess(this, "Appointment Created!");
                        }
                        else
                        {
                            Util.PageMessageError(this, "Something went wrong!", "bottom-right");
                        }
                    }
                    else // updating existing appointment
                    {
                        String AppointmentID = hf_bound_appointment_id.Value;
                        String GoogleEventID = hf_bound_appointment_google_event_id.Value;

                        // Update
                        service.Events.Update(Appointment, LeadsUtil.GoogleCalendarID, GoogleEventID).Execute();

                        String uqry = "UPDATE dbl_appointments SET AppointmentStart=@AppointmentStart, AppointmentEnd=@AppointmentEnd, Summary=@Summary, Description=@Description, Location=@Location, DateUpdated=CURRENT_TIMESTAMP WHERE AppointmentID=@AppointmentID";
                        SQL.Update(uqry,
                                   new String[] { "@AppointmentID", "@AppointmentStart", "@AppointmentEnd", "@Summary", "@Description", "@Location" },
                                   new Object[] { AppointmentID, AppointmentStart, AppointmentEnd, Appointment.Summary, Appointment.Description, Appointment.Location });

                        // Log
                        LeadsUtil.AddLeadHistoryEntry(hf_lead_id.Value, "Updating Google appointment: " + Appointment.Summary);

                        RefreshNextAppointment();

                        Util.PageMessageSuccess(this, "Appointment Updated!");

                        CancelUpdateAppointment(null, null);
                    }
                    Util.SetRebindOnWindowClose(this, true);
                }
                else
                {
                    Util.PageMessageAlertify(this, "Error getting calendar service from Google, please try again.");
                }
            }
            else
            {
                Util.PageMessageAlertify(this, "Please pick a valid datespan!", "Dates Aren't Right");
            }
        }
        BindAppointments();
    }
Esempio n. 13
0
    protected void PushLeadToProspect(object sender, EventArgs e)
    {
        //String[] forced_selected = new String[] { hf_contact_id.Value };
        //ContactManager.BindContacts(hf_company_id.Value, forced_selected); // rebind incase a merge occured on company update

        ContactManager.UpdateContacts(CompanyManager.CompanyID);

        CompanyManager.UpdateCompany();

        // Get valid selected ctc ids
        ArrayList selected_ctc_ids = ContactManager.SelectedValidContactIDs;
        ArrayList contact_ids      = ContactManager.ContactIDs;

        // Make sure all company info is correct
        if (CompanyManager.Turnover == null || CompanyManager.BizClikIndustry == null || (CompanyManager.CompanySize == null && CompanyManager.CompanySizeBracket == null) || CompanyManager.Country == null || CompanyManager.Website == null)
        {
            Util.PageMessageAlertify(this, "You must have Country, Industry, Turnover, Company Size and Website specified " +
                                     "to push this Lead to Prospect.<br/><br/>Click the company edit pencil and specify the required data.", "Data Required");
        }
        else if (dd_rep.SelectedItem.Text.Trim() == String.Empty || CompanyManager.CompanyName == null)
        {
            Util.PageMessageAlertify(this, "You must enter a company name and a rep!", "Rep and Company Name Required");
        }
        else if (CompanyManager.CompanyName.Length > 150)
        {
            Util.PageMessageAlertify(this, "The company name must be no more than 150 characters!", "Company Name Too Long");
        }
        else
        {
            String prosDueDate   = null;
            String prosLHDueDate = null;
            String PLevel        = null;
            if (datepicker_NewProspectDue.SelectedDate != null) // List Due
            {
                prosDueDate = Convert.ToDateTime(datepicker_NewProspectDue.SelectedDate).ToString("yyyy/MM/dd");
            }
            if (datepicker_NewProspectLHDue.SelectedDate != null) // List Due
            {
                prosLHDueDate = Convert.ToDateTime(datepicker_NewProspectLHDue.SelectedDate).ToString("yyyy/MM/dd");
            }

            if (dd_p1p2.SelectedItem.Text != String.Empty)
            {
                PLevel = dd_p1p2.SelectedItem.Text;
            }

            tb_notes.Text = Util.DateStamp(tb_notes.Text);
            // add username if not already exist
            if (tb_notes.Text.Trim() != String.Empty && !tb_notes.Text.EndsWith(")"))
            {
                tb_notes.Text += " (" + HttpContext.Current.User.Identity.Name + ")";
            }

            int  grade  = -1;
            bool insert = true;
            if (!Int32.TryParse(dd_grade.SelectedItem.Text, out grade))
            {
                insert = false;
                Util.PageMessage(this, "Please select a grade from 1-10!");
            }

            if (insert)
            {
                Util.SetRebindOnWindowClose(udp_ptp, true);

                if (dd_destination.Items.Count > 0 && dd_destination.SelectedItem != null)
                {
                    hf_team_id.Value = dd_destination.SelectedItem.Value;
                }

                // Ensure UTF8 encoding
                String notes = tb_notes.Text.Trim();
                if (!String.IsNullOrEmpty(notes))
                {
                    byte[] bytes = System.Text.Encoding.Default.GetBytes(notes);
                    notes = System.Text.Encoding.UTF8.GetString(bytes);
                }
                else
                {
                    notes = null;
                }

                String lha = tb_lha.Text.Trim();
                if (!String.IsNullOrEmpty(lha))
                {
                    byte[] bytes = System.Text.Encoding.Default.GetBytes(lha);
                    lha = System.Text.Encoding.UTF8.GetString(bytes);
                }
                else
                {
                    lha = null;
                }

                String benchmark_data = tb_benchmark_data.Text.Trim();
                if (!String.IsNullOrEmpty(benchmark_data))
                {
                    byte[] bytes = System.Text.Encoding.Default.GetBytes(benchmark_data);
                    benchmark_data = System.Text.Encoding.UTF8.GetString(bytes);
                }
                else
                {
                    benchmark_data = null;
                }

                String emails = null;
                if (dd_emails.SelectedItem.Value != String.Empty)
                {
                    emails = dd_emails.SelectedItem.Value;
                }

                String iqry = "INSERT INTO db_prospectreport " +
                              "(CompanyID,TeamID,CompanyName,Industry,SubIndustry,PLevel,Turnover,Employees,ListGeneratorFriendlyname,DateListDue,Emails," +
                              "Grade,OriginalGrade,Notes,IsHot,DateLetterHeadDue,LeadHookAngle,BenchmarkNotes) " +
                              "VALUES(@cpy_id, @team_id, @company, @industry, @sub_industry, @p1p2, @turnover, @employees, @rep, @list_due, @emails, @grade, @grade," +
                              "@notes,@hot,@lhduedate,@lha,@benchmark_data)";
                String[] pn = new String[] {
                    "@cpy_id",
                    "@team_id",
                    "@company",
                    "@industry",
                    "@sub_industry",
                    "@p1p2",
                    "@turnover",
                    "@employees",
                    "@rep",
                    "@list_due",
                    "@emails",
                    "@grade",
                    "@notes",
                    "@hot",
                    "@lhduedate",
                    "@lha",
                    "@benchmark_data"
                };
                Object[] pv = new Object[] {
                    CompanyManager.CompanyID,
                    hf_team_id.Value,
                    CompanyManager.CompanyName,
                    CompanyManager.BizClikIndustry,
                    CompanyManager.BizClikSubIndustry,
                    PLevel,
                    CompanyManager.Turnover + " " + CompanyManager.TurnoverDenomination,
                    CompanyManager.CompanySize,
                    dd_rep.SelectedItem.Text.Trim(),
                    prosDueDate,
                    emails,
                    grade,
                    notes,
                    cb_hot.Checked,
                    prosLHDueDate,
                    lha,
                    benchmark_data
                };

                try
                {
                    // Insert the Propsect first
                    long pros_id = SQL.Insert(iqry, pn, pv);

                    // Iterate ALL contacts and remove them from the Leads system
                    for (int i = 0; i < contact_ids.Count; i++)
                    {
                        String ctc_id = (String)contact_ids[i];

                        String[] ctc_pn = new String[] { "@ctc_id", "@user_id" };
                        Object[] ctc_pv = new Object[] { ctc_id, hf_user_id.Value };

                        // Remove Lead from Lead system [all projects for this user] (but ONLY for this user, people may share contacts in their Leads sheet)
                        String uqry = "UPDATE dbl_lead JOIN dbl_project ON dbl_lead.ProjectID = dbl_project.ProjectID SET dbl_lead.Active=0 WHERE ContactID=@ctc_id AND UserID=@user_id;";
                        SQL.Update(uqry, ctc_pn, ctc_pv);
                    }

                    // Iterate only SELECTED contacts and log them as Pushed To Prospect
                    String qry       = "SELECT LeadID FROM dbl_lead JOIN dbl_project ON dbl_lead.ProjectID = dbl_project.ProjectID WHERE ContactID=@ctc_id AND UserID=@user_id";
                    String pros_uqry = "UPDATE dbl_lead SET Prospect=1, DateMadeProspect=CURRENT_TIMESTAMP WHERE LeadID=@lead_id";
                    for (int i = 0; i < selected_ctc_ids.Count; i++)
                    {
                        String ctc_id = (String)selected_ctc_ids[i];

                        String[] ctc_pn = new String[] { "@ctc_id", "@user_id", "@prospect_id" };
                        Object[] ctc_pv = new Object[] { ctc_id, hf_user_id.Value, pros_id.ToString() };

                        // LOG: Get id of leads for this user whose contact id is selected as push to prospect
                        DataTable dt_leads = SQL.SelectDataTable(qry, ctc_pn, ctc_pv);
                        for (int j = 0; j < dt_leads.Rows.Count; j++)
                        {
                            String this_lead_id = dt_leads.Rows[j]["LeadID"].ToString();
                            SQL.Update(pros_uqry, "@lead_id", this_lead_id);
                            LeadsUtil.AddLeadHistoryEntry(this_lead_id, "Pushed to Prospect.");
                        }

                        // Add to contact context table
                        iqry = "INSERT INTO db_contact_system_context (ContactID, TargetSystemID, TargetSystem) VALUES (@ctc_id, @prospect_id, 'Prospect')";
                        SQL.Insert(iqry, ctc_pn, ctc_pv);
                    }

                    // Dashboard Log
                    Util.WriteLogWithDetails("New prospect (" + CompanyManager.CompanyName + ") added in " + hf_office.Value + " - " + hf_team_name.Value + ".", "prospectreports_log");

                    if (cb_view_writeup.Checked)
                    {
                        System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "OpenWindow", "window.open('/dashboard/prospectreports/prospectwriteup.aspx?id=" + pros_id + "','_newtab');", true);
                    }

                    Util.CloseRadWindowFromUpdatePanel(this, CompanyManager.CompanyName, false);
                }
                catch (Exception r)
                {
                    if (Util.IsTruncateError(this, r))
                    {
                    }
                    else
                    {
                        Util.PageMessage(this, "An error occured, please try again.");
                        Util.WriteLogWithDetails("Error adding prospect " + r.Message + " " + r.StackTrace, "prospectreports_log");
                    }
                }
            }
        }
    }
    public void SaveChanges(object sender, EventArgs e)
    {
        // insert new notes
        String username = Util.GetUserName();
        String new_note = tb_add_note.Text.Trim();

        tb_add_note.Text = String.Empty;
        int is_next_action = 0;

        bool IsCommonNote = ((Button)sender).ID == "btn_add_common_note" && dd_common_notes.Items.Count > 0 && dd_common_notes.SelectedItem != null;

        String msg = String.Empty;
        String uqry;

        if (LeadID != String.Empty && !IsCommonNote)
        {
            // Determine whether an action is changing or is new, then add special note if new/changed
            DateTime nad = new DateTime();
            bool     next_action_changing = false;
            if (rdp_next_action.SelectedDate != null && DateTime.TryParse(rdp_next_action.SelectedDate.ToString(), out nad) &&
                dd_next_action_type.Items.Count > 0 && dd_next_action_type.SelectedItem != null)
            {
                if (dd_next_action_type.SelectedItem.Text != String.Empty)
                {
                    next_action_changing = (hf_nat.Value != dd_next_action_type.SelectedItem.Value || hf_nad.Value != nad.ToString());
                    if (next_action_changing)
                    {
                        is_next_action = 1;

                        if (dd_next_action_type.SelectedItem.Text == "Other" && new_note != String.Empty)
                        {
                            new_note += " (" + nad.ToString("d MMMM yy, h tt") + ")";
                        }
                        else if (new_note != String.Empty)                                                                                         // removed 06/01/16
                        {
                            new_note = new_note + " -- " + dd_next_action_type.SelectedItem.Text + " at " + nad.ToString("d MMMM yy, h tt") + "."; //Environment.NewLine + Environment.NewLine +
                        }
                        if (new_note == String.Empty)
                        {
                            new_note = dd_next_action_type.SelectedItem.Text + " at " + nad.ToString("d MMMM yy, h tt") + ".";
                        }

                        msg = "Next Action Set!";
                    }
                }

                uqry = "UPDATE dbl_lead SET NextActionTypeID=@nat, NextActionDate=@nad WHERE LeadID=@LeadID";
                SQL.Update(uqry,
                           new String[] { "@nat", "@nad", "@LeadID" },
                           new Object[] { dd_next_action_type.SelectedItem.Value, nad, LeadID });
            }

            uqry = "UPDATE dbl_lead SET DateUpdated=CURRENT_TIMESTAMP WHERE LeadID=@LeadID";
            SQL.Update(uqry, "@LeadID", LeadID);
        }

        if (IsCommonNote)
        {
            String br = String.Empty;
            if (new_note != String.Empty)
            {
                br = Environment.NewLine + Environment.NewLine;
            }
            new_note = dd_common_notes.SelectedItem.Text + br + new_note;
        }

        if (ContactID != String.Empty && new_note != String.Empty)
        {
            // Ensure we have the latest version of this contact (it may have been merged)
            Contact c = new Contact(ContactID);
            ContactID = c.ContactID;

            new_note = Util.ConvertStringToUTF8(new_note);

            String iqry    = "INSERT INTO db_contact_note (ContactID, Note, AddedBy, IsNextAction) VALUES (@ContactID, @Note, @AddedBy, @IsNextAction);";
            long   note_id = SQL.Insert(iqry,
                                        new String[] { "@ContactID", "@Note", "@AddedBy", "@IsNextAction" },
                                        new Object[] { hf_ctc_id.Value, new_note, Util.GetUserId(), is_next_action });

            uqry = "UPDATE dbl_lead SET LatestNoteID=@lnid WHERE ContactID=@ContactID";
            SQL.Update(uqry,
                       new String[] { "@lnid", "@ContactID" },
                       new Object[] { note_id, hf_ctc_id.Value });

            // Log
            LeadsUtil.AddLeadHistoryEntry(LeadID, "Adding note/next action: " + new_note);

            if (msg == String.Empty)
            {
                msg = "Saved!";
            }

            Util.PageMessageSuccess(this, msg, "top-right");

            if (InWindow) // resize
            {
                Util.ResizeRadWindow(this);
            }
        }

        BindNotesAndNextAction();

        UpdateParentPage();
    }