Exemple #1
0
        public List <Org> SearchByGeo(string searchStr)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            searchStr = searchStr.Trim();

            if (string.IsNullOrEmpty(searchStr))
            {
                return((from c in db.Orgs
                        select c).ToList());
            }
            else
            {
                Geo g = GeoBLL.GetByFullname(searchStr);
                if (g == null)
                {
                    return(new List <Org>());
                }

                if (g.Level == 1)
                {
                    return(db.Orgs.Where(r => r.GeoID1 == g.ID).ToList());
                }
                if (g.Level == 2)
                {
                    return(db.Orgs.Where(r => r.GeoID2 == g.ID && r.GeoID1 == g.ParentGeo.ID).ToList());
                }
                if (g.Level == 3)
                {
                    return(db.Orgs.Where(r => r.GeoID3 == g.ID && r.GeoID2 == g.ParentGeo.ID && r.GeoID1 == g.ParentGeo.ParentGeo.ID).ToList());
                }
                return(new List <Org>());
            }
        }
Exemple #2
0
        public static void Set3LevelByFullname(string fullname, Func <Guid?, Guid?, Guid?, int> setGeoFunc)
        {
            if (string.IsNullOrEmpty(fullname) ||
                string.IsNullOrEmpty(fullname.Trim()))
            {
                throw new Exception("Nhập đơn vị hành chính.");
            }
            else
            {
                Geo g = GeoBLL.GetByFullname(fullname);
                if (g == null)
                {
                    throw new Exception("Nhập sai đơn vị hành chính.");
                }
                else
                {
                    Guid?geo1ID = null;
                    Guid?geo2ID = null;
                    Guid?geo3ID = null;

                    if (g.Level == 1)
                    {
                        geo1ID = g.ID;
                    }

                    if (g.Level == 2)
                    {
                        geo2ID = g.ID;
                        geo1ID = g.ParentGeo.ID;
                    }

                    if (g.Level == 3)
                    {
                        geo3ID = g.ID;
                        geo2ID = g.ParentGeo.ID;
                        geo1ID = g.ParentGeo.ParentGeo.ID;
                    }

                    setGeoFunc(geo1ID, geo2ID, geo3ID);
                }
            }
        }