public InterfaceRet SavPic(string input) { input = HttpUtility.UrlDecode(input); _ret.Clear(); try { SitePic paramModel = Newtonsoft.Json.JsonConvert.DeserializeObject <SitePic>(input); DBSite db = new DBSite(); foreach (ImgInfo imginfo in paramModel.data) { if (string.IsNullOrEmpty(imginfo.GUID)) { TF.CommonUtility.LogClass.log("图片的GUID为空,跳过本次循环"); continue; } //相对路径 string logicPath = "/SiteImage/" + Convert.ToDateTime(imginfo.EventTime).ToString("yyyyMMdd") + "/"; //绝对路径 string phsycalPath = HttpContext.Current.Server.MapPath(logicPath); if (!Directory.Exists(phsycalPath)) { Directory.CreateDirectory(phsycalPath); } string fileName = phsycalPath + imginfo.GUID + ".jpg"; byte[] imageBytes = Convert.FromBase64String(imginfo.Pic); FileStream fs = File.Create(fileName); try { fs.Write(imageBytes, 0, imageBytes.Length); fs.Flush(); db.AddSite_Photo(imginfo.GUID, imginfo.EventTime); } finally { fs.Close(); } } _ret.result = 0; _ret.resultStr = "返回成功"; } catch (Exception ex) { TF.CommonUtility.LogClass.logex(ex, ""); _ret.result = 1; _ret.resultStr = "提交失败" + ex.InnerException.Message.ToString(); } return(_ret); }
public InterfaceRet TMLeave(string data) { _ret.Clear(); data = System.Web.HttpUtility.UrlDecode(data); InputTMLeave input = Newtonsoft.Json.JsonConvert.DeserializeObject <InputTMLeave>(data); //判断所传对象是否为空 if (input.OperationType == null) { _ret.resultStr = "所传类型为空,无法执行下一步操作"; _ret.result = 1; return(_ret); } try { DBSite db = new DBSite(); switch (input.OperationType) { case OperationType.Insert: db.AddTMLeave(input); break; case OperationType.Delete: db.DelTMLeave(input); break; case OperationType.Update: db.UpdateTMLeave(input); break; default: throw new Exception("操作类型有误,请核对"); } } catch (Exception ex) { _ret.resultStr = ex.Message; _ret.result = 1; } return(_ret); }