private async void BtnLogin_Click(object sender, EventArgs e) { var p = await db.Provinces.FindAsync(1); if (p == null) { string url = "https://api.jisuapi.com/area/province?appkey=1b5f267715e671b2"; var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; using (var http = new HttpClient(handler)) { var response = await http.GetAsync(url); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); string json = await response.Content.ReadAsStringAsync(); ProvinceDetails province = JsonConvert.DeserializeObject <ProvinceDetails>(json); for (int i = 0; i < province.result.Count; i++) { Province prs = new Province(); prs.id = province.result[i].id; prs.name = province.result[i].name; prs.parentid = province.result[i].parentid; prs.parentname = province.result[i].parentname; prs.areacode = province.result[i].areacode; prs.zipcode = province.result[i].zipcode; prs.depth = province.result[i].depth; if (prs != null) { db.Provinces.Add(prs); await db.SaveChangesAsync(); } } } } var c = await db.Provinces.FindAsync(499); if (c == null) { for (int w = 1; w < 10; w++) { string url = "https://api.jisuapi.com/area/city?parentid=" + w + "&appkey=1b5f267715e671b2"; var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; using (var http = new HttpClient(handler)) { var response = await http.GetAsync(url); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); string json = await response.Content.ReadAsStringAsync(); ProvinceDetails province = JsonConvert.DeserializeObject <ProvinceDetails>(json); for (int i = 0; i < province.result.Count; i++) { Province prs = new Province(); prs.id = province.result[i].id; prs.name = province.result[i].name; prs.parentid = province.result[i].parentid; prs.parentname = province.result[i].parentname; prs.areacode = province.result[i].areacode; prs.zipcode = province.result[i].zipcode; prs.depth = province.result[i].depth; if (prs != null) { db.Provinces.Add(prs); await db.SaveChangesAsync(); } } } } } string username = txtUserName.Text.Trim(); string pwd = txtPassWord.Text.Trim(); if (username == "") { MessageBox.Show("用户名不能为空"); return; } if (pwd == "") { MessageBox.Show("密码不能为空"); return; } var user = db.Users.Where(m => m.UserName == username).ToList(); if (user.Count >= 1) { User user1 = db.Users.SingleOrDefault(m => m.UserName == username && m.PassWord == pwd); if (user1 != null) { MessageBox.Show("登录成功!!!"); Personal ps = new Personal(user1.Id); this.Hide(); ps.Show(); } else { MessageBox.Show("用户名或密码不正确!"); } } else { MessageBox.Show("用户名不存在"); } }
public async Task <IActionResult> Index(User user) { var p = await _context.Provinces.FindAsync(1); if (p.id.ToString() == null) { string url = "https://api.jisuapi.com/area/province?appkey=1b5f267715e671b2"; var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; using (var http = new HttpClient(handler)) { var response = await http.GetAsync(url); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); string json = await response.Content.ReadAsStringAsync(); // string o=i.Replace("\"","\'"); // string p=o.Replace("'name':'','areacode':'010','zipcode':'100000','depth':1},{'id':2,'name':'安徽','parentid':0,'parentname':'','areacode':null,'zipcode':'','depth':1}";status':0,'msg':'ok','result':[{",""); // string a=p.Replace("]}",""); // string json = @"{'id':1,'name':'北京','parentid':0,'parent // ProvinceDetails pr = JsonConvert.DeserializeObject<ProvinceDetails>(json);//反序列化 // CityDetails city = JsonConvert.DeserializeObject<CityDetails>(json);//反序列化 ProvinceDetails province = JsonConvert.DeserializeObject <ProvinceDetails>(json); //反序列化 // Console.WriteLine(string.Format("反序列化: id={0},name={1},parentid={2},parentname={3},areacode={4},zipcode={5},depth={6}" // , descJsonStu.id, descJsonStu.name, descJsonStu.parentid, descJsonStu.parentname,descJsonStu.areacode,descJsonStu.zipcode,descJsonStu.depth)); Province prs = new Province(); for (int i = 0; i < province.result.Count; i++) { prs.id = province.result[i].id; prs.name = province.result[i].name; prs.parentid = province.result[i].parentid; prs.parentname = province.result[i].parentname; prs.areacode = province.result[i].areacode; prs.zipcode = province.result[i].zipcode; prs.depth = province.result[i].depth; if (prs != null) { _context.Provinces.Add(prs); await _context.SaveChangesAsync(); } } return(Json(prs)); } } var c = await _context.Provinces.FindAsync(499); if (c.id.ToString() == null) { for (int w = 1; w < 10; w++) { string url = "https://api.jisuapi.com/area/city?parentid=" + w + "&appkey=1b5f267715e671b2"; var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; using (var http = new HttpClient(handler)) { var response = await http.GetAsync(url); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); string json = await response.Content.ReadAsStringAsync(); ProvinceDetails province = JsonConvert.DeserializeObject <ProvinceDetails>(json); Province prs = new Province(); for (int i = 0; i < province.result.Count; i++) { prs.id = province.result[i].id; prs.name = province.result[i].name; prs.parentid = province.result[i].parentid; prs.parentname = province.result[i].parentname; prs.areacode = province.result[i].areacode; prs.zipcode = province.result[i].zipcode; prs.depth = province.result[i].depth; if (prs != null) { _context.Provinces.Add(prs); await _context.SaveChangesAsync(); } } } } } if (ModelState.IsValid) { var dbuser = _context.Users.FirstOrDefault(m => m.UserName.Equals(user.UserName) && m.PassWord.Equals(user.PassWord)); if (dbuser != null) { return(RedirectToAction("Edit", "Personal", new { id = dbuser.Id })); } else { return(View()); } } return(View(user)); }
public Province(ulong id, BufferedReader reader, Date ck3BookmarkDate) { // Load from a country file, if one exists. Otherwise rely on defaults. Id = id; details = new ProvinceDetails(reader, ck3BookmarkDate); }
public Province(ulong id, Province otherProvince) { Id = id; BaseProvinceId = otherProvince.Id; details = new ProvinceDetails(otherProvince.details); }
public async Task <IActionResult> Index([FromBody] User user) { var p = await _context.Provinces.FindAsync(1); if (p == null) { string shuju = ""; string path = "D:/省份.txt"; string url = "https://api.jisuapi.com/area/province?appkey=f48e75474d78a4d6"; FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write); var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; using (var http = new HttpClient(handler)) { var response = await http.GetAsync(url); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); string json = await response.Content.ReadAsStringAsync(); ProvinceDetails province = JsonConvert.DeserializeObject <ProvinceDetails>(json); for (int i = 0; i < province.result.Count; i++) { string sql = "insert into [Provinces] (name,parentid)values('" + province.result[i].name + "'," + province.result[i].parentid + ");"; shuju = shuju + sql; } byte[] bytes = Encoding.UTF8.GetBytes(shuju); fileStream.Write(bytes, 0, bytes.Length); fileStream.Close(); } } var c = await _context.Provinces.FindAsync(499); if (c == null) { string ooo = ""; string path = "D:/城市.txt"; FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write); for (int w = 1; w < 35; w++) { string url = "https://api.jisuapi.com/area/city?parentid=" + w + "&appkey=f48e75474d78a4d6"; var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; using (var http = new HttpClient(handler)) { var response = await http.GetAsync(url); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); string json = await response.Content.ReadAsStringAsync(); ProvinceDetails province = JsonConvert.DeserializeObject <ProvinceDetails>(json); string shuju = ""; for (int i = 0; i < province.result.Count; i++) { string sql = "insert into [Provinces] (name,parentid) select '" + province.result[i].name + "' , Id from[Provinces] where name='" + province.result[i].parentname + "';"; shuju = shuju + sql; } ooo = ooo + shuju; } } byte[] bytes = Encoding.UTF8.GetBytes(ooo); fileStream.Write(bytes, 0, bytes.Length); } if (!ModelState.IsValid) { var dbuser = _context.Users.FirstOrDefault(m => m.LoginName.Equals(user.UserName) && m.PassWord.Equals(user.PassWord)); if (dbuser != null) { HttpContext.Session.SetInt32("UserId", dbuser.Id); return(Json(dbuser)); } else { return(Json(dbuser)); } } return(View(user)); }