/// <summary> /// 文件下载 /// </summary> /// <param name="docId"></param> /// <returns></returns> public FileStreamResult FileDownload(string docId) { FileStreamResult Ret = null; try { #region 判断是否为空 if (!string.IsNullOrEmpty(docId)) { using (TeamWorkDbContext et = new TeamWorkDbContext()) { KeyValModel kv = GetCurrentStoreDirectory(); T_XT_Doc_Entity _doc = et.T_XT_Doc_Entity.FirstOrDefault(d => d.IsDeleted == false && d.DocId == docId); if (kv != null && _doc != null) { string filePath = Server.MapPath(string.Format("~/DocLib/{0}/{1}", _doc.SubDirectory, _doc.InternalName));//路径 Ret = File(new FileStream(filePath, FileMode.Open), "text/plain", _doc.DocName); _doc.DownloadCount = _doc.DownloadCount ?? 0; _doc.DownloadCount++; et.SaveChanges(); } } } #endregion } catch (Exception ex) { } return(Ret); }
// Any customized logic needed after persist called can be added here. // InnerProcessor call related OnUpdated|Inseted|Deleted<EntitySet> methods public Task OnChangeSetItemProcessedAsync(SubmitContext context, ChangeSetItem item , CancellationToken cancellationToken) { var dataModificationItem = item as DataModificationItem; if (dataModificationItem != null) { object myEntity = dataModificationItem.Resource; string entitySetName = dataModificationItem.ResourceSetName; DataModificationItemAction operation = dataModificationItem.DataModificationItemAction; // In case of insert, the request URL has no key, and request body may not have key neither as the key may be generated by database var keyAttrbiutes = new Dictionary <string, object>(); var keyConvention = new Dictionary <string, object>(); //var entityTypeName = myEntity.GetType().Name; // PropertyInfo[] properties = myEntity.GetType().GetProperties(); var et = myEntity as IEntity; KeyValModel _user = null; var C_user = new BaseController().getCurUser(); if (C_user != null) { _user = new KeyValModel { Key = C_user.EmpCode, Val = C_user.EmpName }; } switch (operation) { case DataModificationItemAction.Insert: et.Create(_user); break; case DataModificationItemAction.Remove: et.Remove(_user); break; case DataModificationItemAction.Undefined: break; case DataModificationItemAction.Update: et.Modify(_user); break; default: break; } } return(InnerProcessor.OnChangeSetItemProcessedAsync(context, item, cancellationToken)); }
public virtual void Create(KeyValModel LoginInfo) { var entity = this as ICreationAudited; if (entity == null) { return; } if (LoginInfo != null) { entity.CreateByEmpCode = LoginInfo.Key; entity.CreateByEmpName = LoginInfo.Val; } entity.CreateTime = DateTime.Now; }
public void Modify(KeyValModel LoginInfo) { var entity = this as IModificationAudited; if (entity == null) { return; } if (LoginInfo != null) { entity.ModifyEmpCode = LoginInfo.Key; entity.ModifyEmpName = LoginInfo.Val; } entity.ModifyTime = DateTime.Now; }
public virtual void Remove(KeyValModel LoginInfo) { var entity = this as IDeleteAudited; if (entity == null) { return; } if (LoginInfo != null) { entity.ModifyEmpCode = LoginInfo.Key; entity.ModifyEmpName = LoginInfo.Val; } entity.ModifyTime = DateTime.Now; entity.IsDeleted = true; }
/// <summary> /// 获取文件储存地址 /// </summary> /// <returns></returns> protected KeyValModel GetCurrentStoreDirectory() { KeyValModel ret = null; try { using (TeamWorkDbContext et = new TeamWorkDbContext()) { T_XT_StoreDirectory_Entity st = et.T_XT_StoreDirectory_Entity.FirstOrDefault(k => k.IsDeleted == false); if (st != null) { ret = new KeyValModel { Key = st.StoreDirectoryId, Val = st.StoreDirectoryPath }; } } } catch (Exception) { } return(ret); }
public JsonResult FilesDelete(string[] docIds) { JsonRetModel ret = new JsonRetModel { Ret = false }; try { KeyValModel kv = GetCurrentStoreDirectory(); if (!docIds.Any()) { ret.Msg = "未检测到需要删除的文件!"; return(Json(ret)); } if (kv == null) { ret.Msg = "未能获取到文件储存目录!"; return(Json(ret)); } using (TeamWorkDbContext et = new TeamWorkDbContext()) { foreach (string _docId in docIds) { T_XT_Doc_Entity _doc = et.T_XT_Doc_Entity.FirstOrDefault(k => k.DocId == _docId); if (_doc != null) { #region 除文件 string path = string.Format("{0}\\{1}\\{2}", kv.Val, _doc.SubDirectory, _doc.InternalName); FileInfo info = new FileInfo(path); if (info.Exists) { info.Delete(); } #endregion #region 如果是图片类型的连带删除缩略图 if (CheckImageExt(_doc.DocType)) { string img_sp = string.Format("{0}\\{1}\\{2}_s{3}", kv.Val, _doc.SubDirectory, _doc.InternalName.Replace(_doc.DocType, ""), _doc.DocType); FileInfo img_s = new FileInfo(img_sp); if (img_s.Exists) { img_s.Delete(); } } #endregion #region 除表数据(伪删除) _doc.IsDeleted = true; et.SaveChanges(); #endregion } } ret.Msg = "操作成功"; ret.Ret = true; } } catch (Exception e) { ret.Msg = e.Message; ret.Ret = false; } return(Json(ret)); }
public JsonResult FileUpload() { JsonRetModel ret = new JsonRetModel(); try { Response.ContentType = "text/plain"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.Charset = "utf-8"; string _RelevanceId = Request["RelevanceId"], _FromModuleName = Request["FromModuleName"], _FromTableName = Request["FromTableName"], _ExpandOne = Request["ExpandOne"], _ExpandTwo = Request["ExpandTwo"], _ExpandThree = Request["ExpandThree"], _ExpandFour = Request["ExpandFour"], _ExpandFive = Request["ExpandFive"]; HttpPostedFileBase file = Request.Files["file"]; KeyValModel kv = GetCurrentStoreDirectory();//获取存储物理路径 if (kv != null) { using (TeamWorkDbContext et = new TeamWorkDbContext()) { string storeDirectoryId = kv.Key, storeDirectory = kv.Val, subDirectory = DateTime.Now.ToString("yyyyMM"), uploadPath = storeDirectory + @"\" + subDirectory + @"\"; bool IsImg = false; if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } string[] array = file.FileName.Split('.'); string suffix = "." + array[array.Length - 1], internalName = Guid.NewGuid().ToString("N"), realPath = uploadPath + internalName, fullPath = realPath + suffix; if (CheckImageExt(suffix)) { IsImg = true; MakeSmallImg(file.InputStream, realPath + "_s" + suffix, 100, 100); MakeSmallImg(file.InputStream, fullPath, 800, 800); } else { file.SaveAs(fullPath); } string fileName = file.FileName.Substring(file.FileName.LastIndexOf('/') + 1); T_XT_Doc_Entity _doc = new T_XT_Doc_Entity { DocId = Guid.NewGuid().ToString("N"), StoreDirectoryId = storeDirectoryId, DocName = fileName, DocType = suffix, DocSize = file.ContentLength, SubDirectory = subDirectory, InternalName = internalName + suffix, DownloadCount = 0, FromModuleName = _FromModuleName, FromTableName = _FromTableName, RelevanceId = _RelevanceId, ExpandOne = _ExpandOne, ExpandTwo = _ExpandTwo, ExpandThree = _ExpandThree, ExpandFour = _ExpandFour, ExpandFive = _ExpandFive, CreateTime = DateTime.Now, IsDeleted = false }; et.T_XT_Doc_Entity.Add(_doc); et.SaveChanges(); ret.Ret = true; ret.Msg = "上传成功"; ret.Data = new { DocId = _doc.DocId, DocName = _doc.DocName, Size = _doc.DocSize, CreateTime = _doc.CreateTime, Path = string.Format("DocLib/{0}/{1}", subDirectory, _doc.InternalName) //,Path_s = IsImg?string.Format("DocLib/{0}/{1}_s{2}", subDirectory, realPath, suffix):null }; } else { ret.Ret = false; ret.Msg = "未检测到文件"; } } } } catch (Exception ex) { ret.Ret = false; ret.Msg = ex.Message; } return(Json(ret)); }