public DocManagementEntity Get(int entityId) { DocManagementEntity entity = new DocManagementEntity(); string sql = "select * from DocManagements where ID=@ID and Isdeleted=0"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(sql)) { try { db.AddInParameter(dbCommand, "ID", DbType.Int32, entityId); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { entity = new DocManagementEntity(dataReader); } } } catch (Exception ex) { new log4netProvider().LogSQL(sql.ToString(), dbCommand.Parameters, ex); } } return(entity); }
public List <DocManagementEntity> GetList(int parentId) { List <DocManagementEntity> list = new List <DocManagementEntity>(); string sql = "select * from DocManagements where ParentID=@ParentID and Isdeleted=0 order by type,DisplayFileName"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(sql)) { try { db.AddInParameter(dbCommand, "ParentID", DbType.Int32, parentId); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { DocManagementEntity entity = new DocManagementEntity(dataReader); list.Add(entity); } } } catch (Exception ex) { new log4netProvider().LogSQL(sql.ToString(), dbCommand.Parameters, ex); } } return(list); }
/// <summary> /// 下载 文件夹 or 文件 /// </summary> /// <param name="dirId">文件夹或文件的ID</param> /// <param name="fileurl">文件存储目录(如:1/document/),对应DocManagements中的FileUrl字段</param> /// <param name="tempFolderName">压缩文件的名称</param> public bool Download(int projectId, int dirId, string fileurl, string tempFolderName = "My Document") { DocManagementEntity entity = Get(dirId); if (entity.Type == Entity.DocManagements.DocType.Folder || entity.ID == 0) //下载压缩文件夹 { List <DocManagementEntity> list = GetList(projectId, dirId); List <string> entrylist = new List <string>(); List <DocManagementEntity> files = GetFilePaths(list, out entrylist); string zipName = (entity.DisplayFileName == "" ? tempFolderName : entity.DisplayFileName) + ".zip"; return(CSharpCodeStringZipper.CreateZip(entrylist, from b in files select SF.Framework.SFConfig.FilePhysicalUrl + b.FileUrl, from c in files select c.DisplayFileName, zipName, SF.Framework.SFConfig.FilePhysicalUrl + fileurl)); } else if (entity.Type == Entity.DocManagements.DocType.File) //下载文件 { //1、添加编码规则Response.HeaderEncoding Response.ContentEncoding 为 utf-8 HttpContext.Current.Response.HeaderEncoding = Encoding.UTF8; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.ContentType = entity.FileContentType; //HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + NoHTML(entity.DisplayFileName));(老的方法) //2、头部分 Content-Disposition 的设置要按照 rfc231 要求, 应该按照如下格式设置: "Content-Disposition","attachment;filename*=utf-8'zh_cn'文件名.xx" // 关键是 filename的设置,*= 后面是 两个单引号,分成三部分(编码 语言 文件名) 如:*=utf-8'zh_cn'文件名.xx 或者 *=utf-8' '文件名.xx HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename*=utf-8''{0}", HttpUtility.UrlPathEncode(NoHTML(entity.DisplayFileName)))); string filename = SF.Framework.SFConfig.FilePhysicalUrl + entity.FileUrl; HttpContext.Current.Response.TransmitFile(filename); } return(true); }
public bool DownloadFiles(int projectId, string strId, string fileurl, string tempFolderName = "My Document") { string[] arrId = strId.Split('_'); List <DocManagementEntity> list = new List <DocManagementEntity>(); for (int i = 0; i < arrId.Length; i++) { DocManagementEntity entity = Get(Convert.ToInt32(arrId[i])); if (entity.Type == Entity.DocManagements.DocType.Folder) //下载压缩文件夹 { list.AddRange(GetList(projectId, Convert.ToInt32(arrId[i]))); } else if (entity.Type == Entity.DocManagements.DocType.File) //下载文件 { list.Add(entity); } } List <string> entrylist = new List <string>(); List <DocManagementEntity> files = GetFilePaths(list, out entrylist); string zipName = tempFolderName ?? "My Document" + ".zip"; return(CSharpCodeStringZipper.CreateZip(entrylist, from b in files select SF.Framework.SFConfig.FilePhysicalUrl + b.FileUrl, from c in files select c.DisplayFileName, zipName, SF.Framework.SFConfig.FilePhysicalUrl + fileurl)); }
public string GetFileInfo(int id) { DocManagementEntity entity = new DocManagementEntity(); entity = new DocManagementBusiness().Get(id); return(entity.FileUrl + "|" + entity.DisplayFileName); }
public bool AddDocManagement(string value) { var obj = (Newtonsoft.Json.Linq.JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(value); if (obj.Count > 0) { DocManagementEntity entity = new DocManagementEntity(); int projectId = 0; int.TryParse(obj[0]["ProjectId"].ToString(), out projectId); entity.ProjectID = projectId; int companyId = 0; int.TryParse(obj[0]["CompanyID"].ToString(), out companyId); entity.CompanyID = companyId; int createBy = 0; int.TryParse(obj[0]["CreatedBy"].ToString(), out createBy); entity.UserID = createBy; entity.ParentID = 0; entity.FileContentType = obj[0]["ContentType"].ToString(); entity.FileUrl = obj[0]["FilePath"].ToString(); entity.CreatedOn = DateTime.Now; entity.DisplayFileName = obj[0]["FileTitle"].ToString(); int filesize = 0; int.TryParse(obj[0]["FileSize"].ToString(), out filesize); entity.FileSize = filesize; entity.FileName = obj[0]["FilePath"].ToString().Substring(obj[0]["FilePath"].ToString().LastIndexOf("/") + 1); entity.Extenstions = obj[0]["FilePath"].ToString().Substring(obj[0]["FilePath"].ToString().LastIndexOf(".")); entity.Type = DocType.File; return(new DocManagementBusiness().Insert(entity) > 0); } return(false); }
/// <summary> /// Rename file name /// </summary> /// <param name="id">修改的文件ID</param> /// <param name="displayName">修改文件名字</param> /// <returns>修改是否成功</returns> public bool Modify(int id, string displayName) { DocManagementEntity entity = Get(id); entity.DisplayFileName = displayName; entity.UpdatedOn = DateTime.Now; return(Modify(entity)); }
public int AddFolder(int parentId, int projectId, string folderName) { DocManagementEntity entity = new DocManagementEntity(); entity.ProjectID = projectId; entity.UserID = UserID; entity.Type = FamilyBook.Entity.DocManagements.DocType.Folder; entity.ParentID = parentId; entity.FileName = folderName; entity.DisplayFileName = folderName; return(business.Insert(entity)); }
/// <summary> /// 获取目录 /// </summary> /// <param name="id"></param> /// <returns></returns> private string GetEntry(int id) { string entry = ""; DocManagementEntity entity = Get(id); if (entity.ParentID != 0) { entry += GetEntry(entity.ParentID) + "//"; } if (entity.Type == Entity.DocManagements.DocType.Folder) { entry += entity.DisplayFileName; } return(entry); }
/// <summary> /// 修改文件目录 /// </summary> /// <param name="id">修改节点ID</param> /// <param name="movetoId">移动到指定节点ID</param> /// <returns>是否成功</returns> public bool Modify(int projectId, int id, int movetoId) { DocManagementEntity entity = Get(id); List <DocManagementEntity> list = GetListAllChildByParentId(id, service.GetList(entity.ProjectID, "")); foreach (var item in list) { item.ProjectID = projectId; item.UpdatedOn = DateTime.Now; Modify(item); } entity.ProjectID = projectId; entity.ParentID = movetoId; entity.UpdatedOn = DateTime.Now; return(Modify(entity)); }
public bool Update(DocManagementEntity entity) { StringBuilder sb = new StringBuilder(); sb.Append("update DocManagements set "); sb.Append("ProjectID=@ProjectID,"); sb.Append("UserID=@UserID,"); sb.Append("ParentID=@ParentID,"); sb.Append("Type=@Type,"); sb.Append("FileName=@FileName,"); sb.Append("DisplayFileName=@DisplayFileName,"); sb.Append("FileContentType=@FileContentType,"); sb.Append("UpdatedOn=@UpdatedOn,"); sb.Append("CreatedOn=@CreatedOn,"); sb.Append("Extenstions=@Extenstions,"); sb.Append("FileSize=@FileSize,"); sb.Append("IsDeleted=@IsDeleted"); sb.Append(" where ID=@ID"); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(sb.ToString())) { try { db.AddInParameter(dbCommand, "ProjectID", DbType.Int32, entity.ProjectID); db.AddInParameter(dbCommand, "UserID", DbType.Int32, entity.UserID); db.AddInParameter(dbCommand, "ParentID", DbType.Int32, entity.ParentID); db.AddInParameter(dbCommand, "Type", DbType.Int16, (int)entity.Type); db.AddInParameter(dbCommand, "FileName", DbType.String, entity.FileName); db.AddInParameter(dbCommand, "DisplayFileName", DbType.String, entity.DisplayFileName); db.AddInParameter(dbCommand, "FileContentType", DbType.String, entity.FileContentType); db.AddInParameter(dbCommand, "FileUrl", DbType.String, entity.FileUrl); db.AddInParameter(dbCommand, "UpdatedOn", DbType.DateTime, entity.UpdatedOn); db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, entity.CreatedOn); db.AddInParameter(dbCommand, "Extenstions", DbType.String, entity.Extenstions); db.AddInParameter(dbCommand, "FileSize", DbType.Int32, entity.FileSize); db.AddInParameter(dbCommand, "IsDeleted", DbType.Boolean, entity.IsDeleted); db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID); return(db.ExecuteNonQuery(dbCommand) > 0); } catch (Exception ex) { new log4netProvider().LogSQL(sb.ToString(), dbCommand.Parameters, ex); return(false); } } }
public List <DocManagementEntity> GetList(string projectId, int parentid, int userId, string order = "", string sort = "") { List <DocManagementEntity> list = new List <DocManagementEntity>(); string sql = @"select *,p.Title as ProjectName,Users.FirstName, Users.LastName from DocManagements left join [dbo].[Projects] as p on DocManagements.ProjectID = p.ProjectID left join Users on DocManagements.UserID=Users.UserID where (DocManagements.ProjectID in(" + (string.IsNullOrEmpty(projectId.Trim()) ? "-1" : projectId) + @") or DocManagements.UserID=@UserID) and ParentID=@ParentID and Isdeleted=0 order by "; if (order != "" && sort != "") { sql += order + " " + sort; } else { sql += " p.Title,type,DisplayFileName"; } Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(sql)) { try { db.AddInParameter(dbCommand, "ParentID", DbType.Int32, parentid); db.AddInParameter(dbCommand, "UserID", DbType.Int32, userId); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { DocManagementEntity entity = new DocManagementEntity(dataReader); list.Add(entity); } } } catch (Exception ex) { new log4netProvider().LogSQL(sql.ToString(), dbCommand.Parameters, ex); } } return(list); }
public List <DocManagementEntity> GetList(string projectId, int userId, string filename) { List <DocManagementEntity> list = new List <DocManagementEntity>(); string sql = @"select *,p.Title as ProjectName,Users.FirstName, Users.LastName from DocManagements left join Users on DocManagements.UserID=Users.UserID left join [dbo].[Projects] as p on DocManagements.ProjectID = p.ProjectID where Isdeleted=0 and (DocManagements.projectId in (" + projectId + ") or (DocManagements.projectId=0 and DocManagements.UserID=@UserID))"; if (!string.IsNullOrEmpty(filename)) { sql += " and DisplayFileName like '%'+@DisplayFileName+'%' "; } sql += " order by type,DisplayFileName"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(sql)) { try { db.AddInParameter(dbCommand, "UserID", DbType.Int32, userId); if (!string.IsNullOrEmpty(filename)) { db.AddInParameter(dbCommand, "DisplayFileName", DbType.String, filename); } using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { DocManagementEntity entity = new DocManagementEntity(dataReader); list.Add(entity); } } } catch (Exception ex) { new log4netProvider().LogSQL(sql.ToString(), dbCommand.Parameters, ex); } } return(list); }
public bool Delete(int projectId, int id) { #if !DEBUG using (TransactionScope scope = new TransactionScope()) #endif { bool isSucess = true; try { int totaoFileSize = 0; List <DocManagementEntity> list = GetListAllChildByParentId(id, service.GetList(projectId, "")); foreach (var item in list) { totaoFileSize += item.FileSize; FileHelper.Delete(SF.Framework.SFConfig.FilePhysicalUrl + item.FileUrl); isSucess = service.Delete(projectId, item.ID); } DocManagementEntity docEntity = service.GetEntity(id); totaoFileSize += docEntity.FileSize; FileHelper.Delete(SF.Framework.SFConfig.FilePhysicalUrl + docEntity.FileUrl); if (isSucess) { isSucess = service.Delete(projectId, id); } } catch (Exception ex) { new log4netProvider().Log(ex); return(false); } #if !DEBUG scope.Complete(); #endif return(isSucess); } }
/// <summary> /// 上传多个文件 保存上传记录 /// </summary> /// <param name="listEntity"></param> /// <param name="parentId"></param> /// <returns></returns> public bool InsertList(int projectId, List <SF.Framework.File.FileEntity> listEntity, int parentId, int userId, int companyID) { #if !DEBUG using (TransactionScope scope = new TransactionScope()) #endif { try { foreach (var item in listEntity) { DocManagementEntity entity = new DocManagementEntity(); entity.ProjectID = projectId; entity.CompanyID = companyID; entity.UserID = userId; entity.Type = Entity.DocManagements.DocType.File; entity.ParentID = parentId; entity.FileUrl = item.FilePath; entity.FileContentType = item.ContentType; entity.FileSize = item.Size; entity.FileName = item.DbName; entity.DisplayFileName = item.DisplayName; entity.Extenstions = item.Extension; Insert(entity); } } catch (Exception ex) { new log4netProvider().Log(ex); return(false); } #if !DEBUG scope.Complete(); #endif return(true); } }
public int Insert(DocManagementEntity entity) { return(service.Insert(entity)); }
public bool Modify(DocManagementEntity entity) { return(service.Update(entity)); }
/// <summary> /// 添加Doc /// </summary> /// <param name="entity"></param> /// <returns>最新数据ID</returns> public int Insert(DocManagementEntity entity) { StringBuilder sb = new StringBuilder(); sb.Append("insert into DocManagements("); sb.Append("ProjectID,"); sb.Append("CompanyID,"); sb.Append("UserID,"); sb.Append("ParentID,"); sb.Append("Type,"); sb.Append("FileName,"); sb.Append("DisplayFileName,"); sb.Append("FileContentType,"); sb.Append("FileUrl,"); sb.Append("UpdatedOn,"); sb.Append("CreatedOn,"); sb.Append("Extenstions,"); sb.Append("FileSize,"); sb.Append("IsDeleted)"); sb.Append(" values("); sb.Append("@ProjectID,"); sb.Append("@CompanyID,"); sb.Append("@UserID,"); sb.Append("@ParentID,"); sb.Append("@Type,"); sb.Append("@FileName,"); sb.Append("@DisplayFileName,"); sb.Append("@FileContentType,"); sb.Append("@FileUrl,"); sb.Append("@UpdatedOn,"); sb.Append("@CreatedOn,"); sb.Append("@Extenstions,"); sb.Append("@FileSize,"); sb.Append("@IsDeleted);"); sb.Append(" SELECT @@IDENTITY as ID;"); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(sb.ToString())) { try { db.AddInParameter(dbCommand, "ProjectID", DbType.Int32, entity.ProjectID); db.AddInParameter(dbCommand, "CompanyID", DbType.Int32, entity.CompanyID); db.AddInParameter(dbCommand, "UserID", DbType.Int32, entity.UserID); db.AddInParameter(dbCommand, "ParentID", DbType.Int32, entity.ParentID); db.AddInParameter(dbCommand, "Type", DbType.Int16, (int)entity.Type); db.AddInParameter(dbCommand, "FileName", DbType.String, entity.FileName); db.AddInParameter(dbCommand, "DisplayFileName", DbType.String, entity.DisplayFileName); db.AddInParameter(dbCommand, "FileContentType", DbType.String, entity.FileContentType); db.AddInParameter(dbCommand, "FileUrl", DbType.String, entity.FileUrl); db.AddInParameter(dbCommand, "UpdatedOn", DbType.DateTime, entity.UpdatedOn); db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, entity.CreatedOn); db.AddInParameter(dbCommand, "Extenstions", DbType.String, entity.Extenstions); db.AddInParameter(dbCommand, "FileSize", DbType.Int32, entity.FileSize); db.AddInParameter(dbCommand, "IsDeleted", DbType.Boolean, entity.IsDeleted); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { int id = 0; if (dataReader.Read()) { id = Convert.ToInt32(dataReader["ID"]); } return(id); } } catch (Exception ex) { new log4netProvider().LogSQL(sb.ToString(), dbCommand.Parameters, ex); return(0); } } }
public int Insert(DocManagementEntity entity) { return(dao.Insert(entity)); }
public bool Update(DocManagementEntity entity) { return(dao.Update(entity)); }
public bool IsDuplicationReName(int id, int projectId, string filename) { DocManagementEntity entity = business.Get(id); return(business.GetListByParentID(UserID, entity.ParentID, projectId, filename).Where(e => e.ID != id).ToList().Count > 0); }