public static List <Competition> LoadXML() { List <Competition> competitions = new List <Competition>(); try { XDocument xdoc = XDocument.Load("competitions.xml"); foreach (XElement el in xdoc.Element("competitions").Elements("competition")) { string name = el.Attribute("name").Value.ToString(); Subject subject = (Subject)Enum.Parse(typeof(Subject), el.Element("subject").Value.ToString()); string place = el.Element("place").Value.ToString(); DateTime date = DateTime.ParseExact(el.Element("date").Value.ToString(), "dd.MM.yyyy", CultureInfo.InvariantCulture); RegionLevel region = (RegionLevel)Enum.Parse(typeof(RegionLevel), el.Element("region").Value.ToString()); bool wasHold = Convert.ToBoolean(el.Element("hold").Value); competitions.Add(new Competition(name, subject, place, date, region, wasHold)); } } catch (Exception ex) { //MessageBox.Show(ex.Message); MessageBox.Show("File is corrupted"); } return(competitions); }
public async Task <IEnumerable <Regions> > GetListAsync(long parentId, RegionLevel currentLevel) { using (var con = await ReadConnectionAsync()) { return(await con.QueryAsync <Regions>("SELECT * FROM Regions Where RegionLevel=@RegionLevel AND ParentId=@ParentId", new { RegionLevel = (byte)currentLevel, ParentId = parentId })); } }
/// <summary> /// 根据枚举返回区域数据 /// 返回JSON /// </summary> public string GetRegionData(RegionLevel level) { var result = string.Empty; var fileDir = Environment.CurrentDirectory; if (level == RegionLevel.Province) { var cacheName = "region_province"; //判断缓存是否有值 ,如果有就直接读缓存 if (ObjectCache.TryGet(cacheName, out string val)) { result = val; } else { result = File.ReadAllText(fileDir + @"\wwwroot\static\js\region\province.js"); //无缓存,写入缓存 ObjectCache.Set(cacheName, result); } } if (level == RegionLevel.City) { var cacheName = "region_city"; //判断缓存是否有值 ,如果有就直接读缓存 if (ObjectCache.TryGet(cacheName, out string val)) { result = val; } else { //判断缓存是否有值 ,如果有就直接读缓存 result = File.ReadAllText(fileDir + @"\wwwroot\static\js\region\city.js"); //无缓存,写入缓存 ObjectCache.Set(cacheName, result); } } if (level == RegionLevel.County) { var cacheName = "region_area"; //判断缓存是否有值 ,如果有就直接读缓存 if (ObjectCache.TryGet(cacheName, out string val)) { result = val; } else { //判断缓存是否有值 ,如果有就直接读缓存 result = File.ReadAllText(fileDir + @"\wwwroot\static\js\region\area.js"); //无缓存,写入缓存 ObjectCache.Set(cacheName, result); } } return(result); }
/// <summary> /// Returns the a RegionLevel corresponding to the integer. /// </summary> /// <param name="regionLevelInt"></param> /// <returns></returns> public static RegionLevel GetRegionLevelFromNumber(int regionLevelInt) { RegionLevel regionLevel = new RegionLevel(); switch (regionLevelInt) { case 0: { regionLevel = RegionLevel.World; break; } case 1: { regionLevel = RegionLevel.Continent; break; } case 2: { regionLevel = RegionLevel.Country; break; } case 3: { regionLevel = RegionLevel.Province; break; } case 4: { regionLevel = RegionLevel.FirstAdmin; break; } case 5: { regionLevel = RegionLevel.SecondAdmin; break; } case 6: { regionLevel = RegionLevel.ThirdAdmin; break; } case 7: { regionLevel = RegionLevel.FourthAdmin; break; } } return(regionLevel); }
public Competition(string name, Subject subject, string place, DateTime date, RegionLevel regionLevel, bool wasHold = false) { Name = name; Subject = subject; Place = place; Date = date; RegionLevel = regionLevel; Participants = new List <IParticipant <Person> >(); Winners = new Dictionary <Tour, List <IParticipant <Person> > >(); WasHold = wasHold; }
public List <Regions> GetChildrenRegionPager(long parentId, int parentLevel, ref GridPager pager) { int totalPage = 0, totalNumber = 0; RegionLevel queryLevel = (RegionLevel)(parentLevel + 1); var data = FoundationDB.DB.Queryable <Regions>() .Where(t => t.RegionLevel == queryLevel && t.ParentId == parentId) .OrderBy(t => t.Sort) .ToPageList(pager.Page, pager.Size, ref totalNumber, ref totalPage); pager.TotalPage = totalPage; pager.Count = totalNumber; return(data); }
public new JSONObject jsonify() { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); json.AddField("name", Name); json.AddField("location", JSONTemplates.FromVector2Int(Location)); json.AddField("level", RegionLevel.ToString()); JSONObject qrts = new JSONObject(JSONObject.Type.ARRAY); foreach (TournamentProtocol.Level level in quarterlies.Keys) { JSONObject record = new JSONObject(JSONObject.Type.OBJECT); record.AddField("key", level.ToString()); record.AddField("value", quarterlies[level].jsonify()); } json.AddField("quarterlies", qrts); return(json); }
public virtual int Add(string regionId, int level, string parentId, AfxContext db) { int count = 0; if (string.IsNullOrEmpty(regionId)) { throw new ArgumentNullException(nameof(regionId)); } if (!string.IsNullOrEmpty(parentId)) { var list = this.GetList(parentId); var idqueue = new Queue <string>(this.GetIdentityList <RegionLevel>(list.Count)); foreach (var vm in list) { var pm = new RegionLevel { Id = idqueue.Dequeue(), RegionId = regionId, ParentId = vm.ParentId, ParentLevel = vm.ParentLevel }; db.RegionLevel.Add(pm); } } var m = new RegionLevel { Id = this.GetIdentity <RegionLevel>(), RegionId = regionId, ParentId = regionId, ParentLevel = level }; db.RegionLevel.Add(m); count = db.SaveChanges(); return(count); }
/// <summary> /// Saves the shapefiles related to the model to the destination folder. /// </summary> /// <param name="model"></param> /// <param name="destinationFolder"></param> public static void SaveAllShapefilesInModel(Model model, DirectoryInfo destinationFolder) { List <Region> regionList = new List <Region>(); List <string> shapeFileNameList = new List <string>(); Region firstRegion = RegionHelper.Get(model.IDRegion); regionList.Add(firstRegion); regionList.AddRange(RegionHelper.GetAllChilds(firstRegion.IDRegion)); foreach (Region region in regionList) { if (shapeFileNameList.Contains(region.ShapeFileName)) { continue; } shapeFileNameList.Add(region.ShapeFileName); } if (shapeFileNameList.Count == 0) { return; } if (!Directory.Exists(destinationFolder.FullName)) { Directory.CreateDirectory(destinationFolder.FullName); } foreach (string shapeFileName in shapeFileNameList) { if (!File.Exists(DirectoryAndFileHelper.ClientShapefilesFolder + shapeFileName)) { continue; } int regionLevelInt = -1; if (!int.TryParse(shapeFileName.Substring(0, 1), out regionLevelInt)) { continue; } RegionLevel regionLevel = RegionHelper.GetRegionLevelFromNumber(regionLevelInt); if (!Directory.Exists(destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel)) { Directory.CreateDirectory(destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel); } FileInfo auxFileInfo = new FileInfo(DirectoryAndFileHelper.ClientShapefilesFolder + shapeFileName); //shp if (File.Exists(auxFileInfo.FullName)) { File.Copy(auxFileInfo.FullName, destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel + "\\" + auxFileInfo.Name, true); } //shx string shxFileName = shapeFileName.ToLower().Replace(".shp", ".shx"); auxFileInfo = new FileInfo(DirectoryAndFileHelper.ClientShapefilesFolder + shxFileName); if (File.Exists(auxFileInfo.FullName)) { File.Copy(auxFileInfo.FullName, destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel + "\\" + auxFileInfo.Name, true); } //dbf string dbfFileName = shapeFileName.ToLower().Replace(".shp", ".dbf"); auxFileInfo = new FileInfo(DirectoryAndFileHelper.ClientShapefilesFolder + dbfFileName); if (File.Exists(auxFileInfo.FullName)) { File.Copy(auxFileInfo.FullName, destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel + "\\" + auxFileInfo.Name, true); } } }
public ApiResult GetRegionData(RegionLevel level) { var result = Resolve <IRegionService>().GetRegionData(level); return(ApiResult.Success(result)); }
public bool AddCompetition(string name, Subject subject, string place, DateTime date, RegionLevel regionLevel) { if (!Competitions.Select(n => n.Name).Contains(name)) { Competitions.Add(new Competition(name, subject, place, date, regionLevel)); return(true); } return(false); }
private List <Region> GetRegions(out List <RegionLevel> regionLevels) { List <Region> list = new List <Region>(); regionLevels = new List <RegionLevel>(); string path = PathUtils.GetFileFullPath("Config/region.txt"); if (!System.IO.File.Exists(path)) { throw new System.IO.FileNotFoundException("Config/region.txt"); } using (var fs = System.IO.File.OpenText(path)) { string s = null; while ((s = fs.ReadLine()) != null) { string[] arr = s.Trim().Split(' ', '\t'); if (arr.Length >= 2) { string code = arr[0].Trim(); string name = arr[1].Trim(); if (code.Length == 6) { Region parent = null; if (code.Substring(2, 2) == "00" && code.Substring(4) == "00") { } else if (code.Substring(2, 2) != "00" && code.Substring(4) == "00") { var parentid = code.Substring(0, 2) + "0000"; parent = list.Find(q => q.Id == parentid); } else { var parentid = code.Substring(0, 4) + "00"; parent = list.Find(q => q.Id == parentid); if (parent == null) { parentid = code.Substring(0, 2) + "0000"; } parent = list.Find(q => q.Id == parentid); } var m = new Region() { Id = code, ParentId = parent?.Id, Level = (parent?.Level ?? 0) + 1, Name = name, IsDelete = false, }; list.Add(m); if (parent != null) { var plist = regionLevels.FindAll(q => q.RegionId == parent.Id); foreach (var l in plist) { var pl = new RegionLevel() { Id = code + "-" + l.ParentLevel.ToString("d2"), ParentId = l.ParentId, ParentLevel = l.ParentLevel, RegionId = code }; regionLevels.Add(pl); } } var level = new RegionLevel() { Id = code + "-" + m.Level.ToString("d2"), ParentId = code, ParentLevel = m.Level, RegionId = code }; regionLevels.Add(level); } } } } return(list); }