Exemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LeadsUtil.SetNoRebindOnWindowClose(this, true);
            if (Request.QueryString["lead_id"] != null && !String.IsNullOrEmpty(Request.QueryString["lead_id"]))
            {
                hf_lead_id.Value = Request.QueryString["lead_id"];

                String qry        = "SELECT Suspect FROM dbl_lead WHERE LeadID=@lead_id";
                bool   is_suspect = SQL.SelectString(qry, "Suspect", "@lead_id", hf_lead_id.Value) == "1";

                if (is_suspect) // make push to prospect
                {
                    btn_push_to.OnClientClick = "var rw = GetRadWindow(); var rwm = rw.get_windowManager(); rwm.open('/dashboard/leads/pushtoprospect.aspx?lead_id=" + Server.UrlEncode(hf_lead_id.Value) + "', 'rw_push_to_prospect'); rw.Close();";
                    btn_push_to.Text          = "Push to Prospect";
                }
                else // make push to suspect
                {
                    btn_push_to.OnClientClick = "var rw = GetRadWindow(); var rwm = rw.get_windowManager(); rwm.open('/dashboard/leads/pushtosuspect.aspx?lead_id=" + Server.UrlEncode(hf_lead_id.Value) + "', 'rw_push_to_suspect'); rw.Close();";
                    btn_push_to.Text          = "Push to Suspect";
                }

                BindTemplate();
            }
            else
            {
                Util.PageMessageAlertify(this, LeadsUtil.LeadsGenericError, "Error");
            }
        }
        else
        {
            LeadsUtil.SetNoRebindOnWindowClose(this, false); // assume any partial postback is an update of some kind (some exceptions)
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LeadsUtil.SetNoRebindOnWindowClose(this, true);
            Security.BindPageValidatorExpressions(this);

            if (Request.QueryString["lead_id"] != null && !String.IsNullOrEmpty(Request.QueryString["lead_id"]))
            {
                hf_lead_id.Value = Request.QueryString["lead_id"];
                String qry = "SELECT team_name, team_id, db_userpreferences.userid, db_userpreferences.office, ctc_id, db_company.cpy_id " +
                             "FROM dbl_lead, dbl_project, db_userpreferences, db_ccateams, db_contact, db_company " +
                             "WHERE dbl_lead.ProjectID = dbl_project.ProjectID " +
                             "AND dbl_project.UserID = db_userpreferences.userid " +
                             "AND db_userpreferences.ccaTeam = db_ccateams.team_id " +
                             "AND dbl_lead.ContactID = db_contact.ctc_id " +
                             "AND db_contact.new_cpy_id = db_company.cpy_id " +
                             "AND LeadID=@lead_id";
                DataTable dt_user_info = SQL.SelectDataTable(qry, "@lead_id", hf_lead_id.Value);
                if (dt_user_info.Rows.Count > 0)
                {
                    hf_user_id.Value    = dt_user_info.Rows[0]["userid"].ToString();
                    hf_team_id.Value    = dt_user_info.Rows[0]["team_id"].ToString();
                    hf_office.Value     = dt_user_info.Rows[0]["office"].ToString();
                    hf_team_name.Value  = dt_user_info.Rows[0]["team_name"].ToString();
                    hf_company_id.Value = dt_user_info.Rows[0]["cpy_id"].ToString();
                    hf_contact_id.Value = dt_user_info.Rows[0]["ctc_id"].ToString();

                    String[] forced_selected = new String[] { hf_contact_id.Value };

                    CompanyManager.BindCompany(hf_company_id.Value);
                    ContactManager.BindContacts(hf_company_id.Value, forced_selected); // for multiple
                    //ContactManager.BindContact(hf_contact_id.Value, true);

                    // Bind Destination Prospect teams
                    BindDestinationTeams();

                    if (CompanyManager.Turnover == String.Empty)
                    {
                        Util.PageMessageAlertify(this, "Company turnover is not specified and is required to push this Lead to Prospect.<br/><br/>Click the company edit pencil and specify a turnover value. ", "Turnover Required");
                    }
                }

                BindRepDropDown();
            }
            else
            {
                Util.PageMessageAlertify(this, "There was an error getting the team information. Please close this window and retry.", "Error");
            }
        }
    }
Exemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LeadsUtil.SetNoRebindOnWindowClose(this, true);
            if (Request.QueryString["lead_id"] != null && !String.IsNullOrEmpty(Request.QueryString["lead_id"]))
            {
                hf_lead_id.Value = Request.QueryString["lead_id"];

                BindCompanyInfo();
            }
            else
            {
                Util.PageMessageAlertify(this, "There was an error getting the information. Please close this window and retry.", "Error");
            }
        }
    }
Exemplo n.º 4
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 (CheckAuthenticated())
        {
            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.");
            }

            LeadsUtil.SetNoRebindOnWindowClose(this, false);
            Util.PageMessageSuccess(this, "Appointment deleted (also removed from your Outlook calendar)");
        }
        BindAppointments();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LeadsUtil.SetNoRebindOnWindowClose(this, true);
            Security.BindPageValidatorExpressions(this);
            if (Request.QueryString["lead_id"] != null && !String.IsNullOrEmpty(Request.QueryString["lead_id"]))
            {
                hf_lead_id.Value = Request.QueryString["lead_id"];
                hf_user_id.Value = Util.GetUserId();
                hf_uri.Value     = Request.Url.ToString();

                ConfigureForm();
                BindAppointments();
                CheckAuthenticated();
            }
            else
            {
                Util.PageMessageAlertify(this, LeadsUtil.LeadsGenericError, "Error");
            }
        }
    }
Exemplo n.º 7
0
    protected void PushSuspectToProspect(object sender, EventArgs e)
    {
        CompanyManager.UpdateCompany();

        // Make sure all company info is correct
        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 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 P1P2          = String.Empty;
            int    waiting       = 1;
            if (datepicker_NewProspectDue.SelectedDate != null) // List Due
            {
                prosDueDate = Convert.ToDateTime(datepicker_NewProspectDue.SelectedDate).ToString("yyyy/MM/dd");
                waiting     = 0;
            }
            if (datepicker_NewProspectLHDue.SelectedDate != null) // List Due
            {
                prosLHDueDate = Convert.ToDateTime(datepicker_NewProspectLHDue.SelectedDate).ToString("yyyy/MM/dd");
            }

            if (dd_p1p2.SelectedItem.Text != String.Empty)
            {
                P1P2 = 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)
            {
                LeadsUtil.SetNoRebindOnWindowClose(udp_ptp, false);

                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();
                byte[] bytes = System.Text.Encoding.Default.GetBytes(notes);
                notes = System.Text.Encoding.UTF8.GetString(bytes);

                String benchmark_data = tb_benchmark_data.Text.Trim();
                bytes          = System.Text.Encoding.Default.GetBytes(benchmark_data);
                benchmark_data = System.Text.Encoding.UTF8.GetString(bytes);

                String iqry = "INSERT INTO db_prospectreport " +
                              "(`cpy_id`,`team_id`,`date`,`company`,`industry`,`sub_industry`,`p1p2`,`turnover`,`employees`,`rep`,`list_due`,`letter`," +
                              "`grade`,`buyin`,`notes`,`working`,`listin`,`blown`,`hot`,`dateblown`,`datein`,`lhduedate`,`lha`,`benchmark_data`) " +
                              "VALUES(@cpy_id, @team_id, " +
                              "CURRENT_TIMESTAMP, " +                           // date
                              "@company, @industry, @sub_industry, @p1p2, @turnover, @employees, @rep, @list_due, @letter, @grade, " +
                              "@buyin, @notes, @working, 0,0,@hot,null,null," + // listin, blown, hot, dateblown, datein
                              "@lhduedate,@lha,@benchmark_data)";
                String[] pn = new String[] {
                    "@cpy_id",
                    "@team_id",
                    "@company",
                    "@industry",
                    "@sub_industry",
                    "@p1p2",
                    "@turnover",
                    "@employees",
                    "@rep",
                    "@list_due",
                    "@letter",
                    "@grade",
                    "@buyin",
                    "@notes",
                    "@working",
                    "@hot",
                    "@lhduedate",
                    "@lha",
                    "@benchmark_data"
                };
                Object[] pv = new Object[] {
                    CompanyManager.CompanyID,
                    hf_team_id.Value,
                    CompanyManager.CompanyName,
                    CompanyManager.Industry,
                    CompanyManager.SubIndustry,
                    P1P2,
                    CompanyManager.Turnover + " " + CompanyManager.TurnoverDenomination,
                    CompanyManager.CompanySize,
                    dd_rep.SelectedItem.Text.Trim(),
                    prosDueDate,
                    dd_letter.SelectedItem.Text.Trim(),
                    grade,
                    null,
                    notes,
                    waiting,
                    cb_hot.Checked,
                    prosLHDueDate,
                    tb_lha.Text.Trim(),
                    benchmark_data
                };

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

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

                    // Update the contact details
                    ContactManager.UpdateContacts(CompanyManager.CompanyID);

                    // 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];
                        //Util.Debug("removing from lead system: " + ctc_id);

                        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" };
                        Object[] ctc_pv = new Object[] { ctc_id, hf_user_id.Value };

                        // 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.");
                        }
                    }

                    // 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");
                    }
                }
            }
        }
    }
    protected void CreateOrUpdateAppointment(object sender, EventArgs e)
    {
        if (CheckAuthenticated())
        {
            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.ctc_id AND db_contact.new_cpy_id = db_company.cpy_id 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]["company_name"].ToString().Trim();
                    String ContactName      = (dt_lead_info.Rows[0]["first_name"] + " " + dt_lead_info.Rows[0]["last_name"]).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]["phone_code"].ToString().Trim();
                    String Website          = dt_lead_info.Rows[0]["website"].ToString().Trim();
                    String JobTitle         = dt_lead_info.Rows[0]["job_title"].ToString().Trim();
                    String Email            = dt_lead_info.Rows[0]["email"].ToString().Trim();
                    String PersonalEmail    = dt_lead_info.Rows[0]["personal_email"].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);
                    }
                    LeadsUtil.SetNoRebindOnWindowClose(this, false);
                }
                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();
    }