public int BindContact(String ctc_id, bool IncludeContactTypes = false, String TargetSystem = null, bool OnlyShowTargetSystemContactTypes = true, String UserId = "") { ContactID = ctc_id; String qry = "SELECT db_contact.*, fullname FROM db_contact LEFT JOIN db_userpreferences ON db_contact.DontContactSetByUserID=db_userpreferences.userid WHERE ContactID=@ContactID AND visible=1"; DataTable dt_contact = SQL.SelectDataTable(qry, "@ContactID", ctc_id); if (dt_contact.Rows.Count > 0) { FirstName = dt_contact.Rows[0]["FirstName"].ToString(); LastName = dt_contact.Rows[0]["LastName"].ToString(); NickName = dt_contact.Rows[0]["NickName"].ToString(); Title = dt_contact.Rows[0]["Title"].ToString(); Quals = dt_contact.Rows[0]["Quals"].ToString(); JobTitle = dt_contact.Rows[0]["JobTitle"].ToString(); Telephone = dt_contact.Rows[0]["Phone"].ToString(); Mobile = dt_contact.Rows[0]["Mobile"].ToString(); WorkEmail = dt_contact.Rows[0]["Email"].ToString(); PersonalEmail = dt_contact.Rows[0]["PersonalEmail"].ToString(); LinkedInAddress = dt_contact.Rows[0]["LinkedInUrl"].ToString(); Skype = dt_contact.Rows[0]["SkypeAddress"].ToString(); IsEmailVerified = dt_contact.Rows[0]["EmailVerified"].ToString() == "1"; IsEmailEstimated = dt_contact.Rows[0]["EmailEstimated"].ToString() == "1"; DontContactReason = dt_contact.Rows[0]["DontContactReason"].ToString(); DontContactUntil = dt_contact.Rows[0]["DontContactUntil"].ToString(); DontContactAdded = dt_contact.Rows[0]["DontContactDateSet"].ToString(); DontContactAddedBy = dt_contact.Rows[0]["fullname"].ToString(); int compl = 0; Int32.TryParse(dt_contact.Rows[0]["Completion"].ToString(), out compl); Completion = compl; // Set Validation Group rev_b_email.ValidationGroup = rev_p_email.ValidationGroup = rev_linkedin.ValidationGroup = "vg_" + ContactID; // Set previous notes qry = "SELECT * FROM db_contact_note WHERE ContactID=@ContactID ORDER BY DateAdded DESC"; DataTable dt_notes = SQL.SelectDataTable(qry, "@ContactID", ContactID); String notes = String.Empty; for (int i = 0; i < dt_notes.Rows.Count; i++) { notes += "[" + dt_notes.Rows[i]["DateAdded"] + " " + Util.GetUserFullNameFromUserId(dt_notes.Rows[i]["AddedBy"].ToString()) + "] " + dt_notes.Rows[i]["Note"] + Environment.NewLine; } PreviousNotes = notes; div_prev_notes.Visible = dt_notes.Rows.Count > 0; // Check and set Do Not Contact LeadsUtil.CheckAndSetDoNotContact(dt_contact.Rows[0], null, null, div_dont_contact, lbl_do_not_contact); // Check and set Existing Lead // Check to see if this contact is already a lead if (DuplicateLeadCheckingEnabled) { qry = "SELECT DISTINCT fullname, p.ProjectID, DateUpdated, p.UserId, s.UserID as 'Sid' FROM dbl_lead l LEFT JOIN dbl_project p ON l.ProjectID = p.ProjectId " + "LEFT JOIN db_userpreferences up ON p.UserID = up.userid LEFT JOIN dbl_project_share s ON s.ProjectID = l.ProjectID " + "WHERE l.Active=1 AND l.ContactID=@ContactID"; DataTable dt_existing_lead = SQL.SelectDataTable(qry, "@ContactID", ctc_id); if (dt_existing_lead.Rows.Count > 0) { for (int i = 0; i < dt_existing_lead.Rows.Count; i++) { String type = "Lead"; String project_fullname = LeadsUtil.GetProjectFullNameFromID(dt_existing_lead.Rows[i]["ProjectID"].ToString()); String ProjectUserId = dt_existing_lead.Rows[i]["UserId"].ToString(); String SharedProjectUserId = dt_existing_lead.Rows[i]["Sid"].ToString(); bool IsInUsersProject = ProjectUserId == UserId; bool IsSharedWithUser = SharedProjectUserId == UserId; if (IsInUsersProject || IsSharedWithUser) { lbl_already_in_my_project.ToolTip += "This contact is already an active " + type + " in your " + project_fullname + " Project, last modified " + dt_existing_lead.Rows[i]["DateUpdated"] + Environment.NewLine; if (!div_already_in_my_project.Visible) { div_already_in_my_project.Visible = true; lbl_already_in_my_project.Text = "NOTE: This contact is already a <b>Lead</b> in one or more of your <b>Project(s)</b>. Hover <b>here</b> for more details."; } } if (!IsInUsersProject || IsSharedWithUser) { // do not html encode here lbl_already_a_lead.ToolTip += "This contact is already an active " + type + " in " + dt_existing_lead.Rows[i]["fullname"].ToString() + "'s " + project_fullname + " Project, last modified " + dt_existing_lead.Rows[i]["DateUpdated"] + Environment.NewLine; if (!div_already_a_lead.Visible) { div_already_a_lead.Visible = true; lbl_already_a_lead.Text = "NOTE: This contact is already a <b>Lead</b> in someone else's <b>Project(s)</b>. Hover <b>here</b> for more details."; } } } } } // Build Contact types tr_contact_types.Visible = IncludeContactTypes; if (IncludeContactTypes) { String only_target_system_expr = String.Empty; if (OnlyShowTargetSystemContactTypes) { only_target_system_expr = " AND SystemName=@TargetSystem"; } qry = "SELECT ContactTypeID, SystemName FROM db_contacttype WHERE ContactType=SystemName" + only_target_system_expr + " ORDER BY SystemName"; DataTable dt_contact_systems = SQL.SelectDataTable(qry, "@TargetSystem", TargetSystem); qry = "SELECT ContactTypeID, ContactType, SystemName FROM db_contacttype WHERE ContactType!=SystemName ORDER BY SystemName, BindOrder"; DataTable dt_contact_types = SQL.SelectDataTable(qry, null, null); qry = "SELECT ContactTypeID FROM db_contactintype WHERE ContactID=@ctc_id"; DataTable dt_cca_types = SQL.SelectDataTable(qry, "@ctc_id", ContactID); for (int i = 0; i < dt_contact_systems.Rows.Count; i++) { String system_name = dt_contact_systems.Rows[i]["SystemName"].ToString(); String system_id = dt_contact_systems.Rows[i]["ContactTypeID"].ToString(); RadTreeNode node = new RadTreeNode() { Text = system_name, Value = system_id }; rtv_types.Nodes.Add(node); // always expand the system type we're adding into, unless contacts are being bound from different system if (system_name == TargetSystem) { node.Expanded = true; } for (int x = 0; x < dt_cca_types.Rows.Count; x++) // check parent system participation (such as Leads, Prospect, Profile Sales, etc); { if (system_id == dt_cca_types.Rows[x]["ContactTypeID"].ToString()) { node.Checked = true; break; } } for (int j = 0; j < dt_contact_types.Rows.Count; j++) // check child type participation { if (dt_contact_types.Rows[j]["SystemName"].ToString() == system_name) { String type_name = dt_contact_types.Rows[j]["ContactType"].ToString(); String type_id = dt_contact_types.Rows[j]["ContactTypeID"].ToString(); // Check main participation bool Checked = false; for (int x = 0; x < dt_cca_types.Rows.Count; x++) { if (type_id == dt_cca_types.Rows[x]["ContactTypeID"].ToString()) { Checked = true; break; } } RadTreeNode c_node = new RadTreeNode() { Text = type_name, Value = type_id, Checked = Checked }; node.Nodes.Add(c_node); dt_contact_types.Rows.RemoveAt(j); j--; } } } } } return(Completion); }