public async Task <IActionResult> WXUpdate(string datas) { WXProject myWXProject = JsonConvert.DeserializeObject <WXProject>(datas); //update //先查询要修改的原数据 WXProject customer = _context.WXProjects.Find(myWXProject.ID); //设置修改后的值 // customer.ID = myWXProject.ID; customer.SSLX = myWXProject.SSLX; customer.SBRY = myWXProject.SBRY; customer.WXZT = myWXProject.WXZT; customer.WZ = myWXProject.WZ; customer.SBRQ = myWXProject.SBRQ; customer.WXRQ = myWXProject.WXRQ; //customer.X = myWXProject.X; //customer.Y = myWXProject.Y; //customer.X84 = myWXProject.X84; //customer.Y84 = myWXProject.Y84; customer.BZ = myWXProject.BZ; //更新到数据库 _context.SaveChanges(); var wxProjects = await _context.WXProjects.ToListAsync(); string wxProject = Newtonsoft.Json.JsonConvert.SerializeObject(wxProjects); return(Json(wxProject)); }
public async Task <IActionResult> WXSave(string datas) { WXProject myWXProject = JsonConvert.DeserializeObject <WXProject>(datas); //坐标转换96-84 string URL = _configuration["URL:transformURL"]; //string towgsUrl = $"{URL}/transfer/XY2BL?fromCoord=qingdao96&toCoord=wgs84&x={myWXProject.X}&y={myWXProject.Y}&callback="; string towgsUrl = $"{URL}/Web.asmx/Qingdao96ToWGS84?x={myWXProject.X}&y={myWXProject.Y}"; Dictionary <string, string> xylocaiton = await HttpGetAsync(towgsUrl, System.Text.Encoding.GetEncoding("utf-8")); string x = xylocaiton["longitude"]; string y = xylocaiton["latitude"]; myWXProject.X84 = Convert.ToDouble(y); myWXProject.Y84 = Convert.ToDouble(x); _context.WXProjects.Add(myWXProject); _context.SaveChanges(); var wxProjects = await _context.WXProjects.ToListAsync(); string wxProject = Newtonsoft.Json.JsonConvert.SerializeObject(wxProjects); //return wxProject; return(Json(wxProject)); }
public async Task <IActionResult> WXDelete(string id) { try { //创建删除对象 WXProject project = _context.WXProjects.Find(id); _context.WXProjects.Remove(project); //更新到数据库 _context.SaveChanges(); var filepath = _environment.ContentRootPath + "/wwwroot/Report"; //维修上传根目录 var filepath1 = _environment.ContentRootPath + "/wwwroot/Report\\" + id; //维修上传子目录 for (int i = 0; i < Directory.GetDirectories(filepath).ToList().Count; i++) //删除对应的图像与视频文件 { var ff = Directory.GetDirectories(filepath).ToList(); if (Directory.GetDirectories(filepath)[i] == filepath1) { Directory.Delete(filepath1, true); } } } catch (Exception ex) { } var wxProjects = await _context.WXProjects.ToListAsync(); string wxProject = Newtonsoft.Json.JsonConvert.SerializeObject(wxProjects); return(Json(wxProject)); }
public async Task <IActionResult> Post() { string[] pictureFormatArray = { "png", "jpg", "jpeg", "bmp", "gif", "ico", "PNG", "JPG", "JPEG", "BMP", "GIF", "ICO" }; //对象标识 & string uploadTime = DateTime.Now.ToString("yyyy/MM/dd"); string uploadTime1 = DateTime.Now.ToString("yyyyMMdd"); var projects = await _context.WXProjects.ToListAsync(); int offset = 1; /*foreach(WXProject project in projects){--------------------20190621 * if(project.SBRQ == uploadTime){ * offset++; * } * }*/ int maxNum = 0; foreach (WXProject project in projects) { if (project.ID.Substring(0, 8) == uploadTime1) { //判断是否有中间数字文件被删除后导致计数与有ID发生冲突 string incomingData = project.ID.Substring(8, 4); int parsedResult; if (int.TryParse(incomingData, out parsedResult)) { if (maxNum <= parsedResult) { maxNum = parsedResult; } } offset++; } } ; maxNum = maxNum + 1; //string offsetString = Convert.ToString(offset); string offsetString = Convert.ToString(maxNum); string offsetString2 = "0000" + offsetString; offsetString2 = offsetString2.Substring(offsetString.Length); string ID = DateTime.Now.ToString("yyyyMMdd") + offsetString2; var uploadFile = Request.Form.Files; //上报人员 string user = Request.Form["uploadPerson"]; //设施类型 string type = Request.Form["type"]; //位置 string locationName = Request.Form["locationName"]; //X Y坐标 string latitude = Request.Form["CoordinateLatitude"]; double latitudeDouble = Convert.ToDouble(latitude); string longitude = Request.Form["CoordinateLongitude"]; double longitudeDouble = Convert.ToDouble(longitude); //上报日期 string uploadDate = DateTime.Now.ToString("yyyy/MM/dd"); //备注 string addition = Request.Form["addition"]; WXProject myWXProject = new WXProject(); myWXProject.ID = ID; myWXProject.SSLX = type; myWXProject.SBRY = user; myWXProject.SBRQ = uploadDate; myWXProject.WZ = locationName; myWXProject.X84 = latitudeDouble; myWXProject.Y84 = longitudeDouble; myWXProject.BZ = addition; /* **********修改************************************************************ */ string URL = _configuration["URL:transformURL"]; string toqdUrl = $"{URL}/Web.asmx/WGS84ToQingdao96?lon={longitude}&lat={latitude}"; //string toqdUrl = $"{APIURLManager.APIURLManager.transformURL}/transfer/BL2XY?fromCoord=wgs84&toCoord=qingdao96&lon={longitude}&lat={latitude}&callback="; //string xylocaiton =await HttpGetAsync(toqdUrl,System.Text.Encoding.GetEncoding("utf-8")); /*xylocaiton = xylocaiton.Substring(1,xylocaiton.Length - 2); * JObject xylocaitonJson = (JObject)JsonConvert.DeserializeObject(xylocaiton); * string x = xylocaitonJson["x"].ToString(); * string y = xylocaitonJson["y"].ToString();*/ Dictionary <string, string> xylocaiton = await HttpGetAsync(toqdUrl, System.Text.Encoding.GetEncoding("utf-8")); string x = xylocaiton["longitude"]; string y = xylocaiton["latitude"]; myWXProject.X = Convert.ToDouble(x); myWXProject.Y = Convert.ToDouble(y); /* **********修改************************************************************ */ myWXProject.WXZT = "待处理"; _context.WXProjects.Add(myWXProject); _context.SaveChanges(); //图片 视频 if (uploadFile.Count > 0) { string filePath = _environment.ContentRootPath + "\\wwwroot\\Report\\" + myWXProject.ID; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } foreach (var file in uploadFile) { var filename = DateTime.Now.ToString("yyyyMMdd") + "_" + ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.ToString().Trim('"'); string extension = filename.Split('.')[1]; string imagePath = filePath + "\\"; if (!pictureFormatArray.Contains(extension)) { imagePath = imagePath + "video"; } else { imagePath = imagePath + "pic"; } if (!Directory.Exists(imagePath)) { Directory.CreateDirectory(imagePath); } imagePath = imagePath + "\\" + filename; using (FileStream fs = System.IO.File.Create(imagePath)) { await file.CopyToAsync(fs); fs.Flush(); } } string message = $"{uploadFile.Count} file(s) uploaded successfully!"; return(Json(message)); } return(Json("上传成功(无视频或图片)")); }