public static void BindBuckets(RadDropDownList dd_Projects, RadDropDownList dd_Buckets, String BucketID, bool SelectCurrentlyViewed, bool ShowOnlyInactiveBuckets = false, bool OnlyCountContactsWithEmail = false) { if (dd_Projects.Items.Count > 0 && dd_Projects.SelectedItem != null) { String OnlyWithEmailExpr = String.Empty; if (OnlyCountContactsWithEmail) { OnlyWithEmailExpr = " AND (Email IS NOT NULL OR PersonalEmail IS NOT NULL)"; } String SumLeadsExpr = "SUM(CASE WHEN l.Active=1" + OnlyWithEmailExpr + " THEN 1 ELSE 0 END)"; if (ShowOnlyInactiveBuckets) { SumLeadsExpr = "SUM(CASE WHEN l.Active=0" + OnlyWithEmailExpr + " THEN 1 ELSE 0 END)"; } String qry = "SELECT p.ProjectID, CONCAT(Name,' (',IFNULL(" + SumLeadsExpr + ",0),CASE WHEN IFNULL(" + SumLeadsExpr + ",0)=1 THEN ' lead)' ELSE ' leads)' END) as 'Name' " + "FROM dbl_project p LEFT JOIN dbl_lead l ON p.ProjectID = l.ProjectID LEFT JOIN db_contact c ON c.ContactID = l.ContactID " + "WHERE p.Active=@active AND p.IsBucket=1 AND ParentProjectID=@project_id GROUP BY p.ProjectID ORDER BY Name"; DataTable dt_buckets = SQL.SelectDataTable(qry, new String[] { "@project_id", "@active" }, new Object[] { dd_Projects.SelectedItem.Value, !ShowOnlyInactiveBuckets }); dd_Buckets.DataSource = dt_buckets; dd_Buckets.DataTextField = "Name"; dd_Buckets.DataValueField = "ProjectID"; dd_Buckets.DataBind(); if (SelectCurrentlyViewed) { LeadsUtil.SelectCurrentlyViewedProject(dd_Buckets, BucketID); } } }
public static void BindProjects(RadDropDownList dd_Projects, RadDropDownList dd_Buckets, String ProjectID, String BucketID, bool SelectCurrentlyViewedParent, bool SelectCurrentlyViewedChild = true, bool ExcludeThisProject = false, bool OnlyCountContactsWithEmail = false) { String[] pn = new String[] { "@UserID", "@ThisProjectID" }; Object[] pv = new Object[] { Util.GetUserId(), ProjectID }; String exclude_expr = String.Empty; if (ExcludeThisProject) { exclude_expr = " AND dbl_project.ProjectID!=@ThisProjectID"; } // Bind projects and buckets for moving leads String qry = "SELECT p.ProjectID, CONCAT(Name,CASE WHEN s.UserID IS NOT NULL THEN ' [Shared]' ELSE '' END) as Name " + "FROM dbl_project p " + "LEFT JOIN dbl_project_share s ON p.ProjectID = s.ProjectID " + "LEFT JOIN dbl_lead l ON p.ProjectID = l.ProjectID " + "WHERE p.Active=1 AND p.IsBucket=0 AND (p.UserID=@UserId OR s.UserID=@UserId)" + exclude_expr + " " + "GROUP BY p.ProjectID ORDER BY Name"; DataTable dt_projects = SQL.SelectDataTable(qry, pn, pv); dd_Projects.DataSource = dt_projects; dd_Projects.DataTextField = "Name"; dd_Projects.DataValueField = "ProjectID"; dd_Projects.DataBind(); if (SelectCurrentlyViewedParent) { LeadsUtil.SelectCurrentlyViewedProject(dd_Projects, ProjectID); } if (dd_Buckets != null) { BindBuckets(dd_Projects, dd_Buckets, BucketID, SelectCurrentlyViewedChild, false, OnlyCountContactsWithEmail); } }