101 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			101 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using System.Threading.Tasks;
 | |
| 
 | |
| namespace BLL
 | |
| {    
 | |
|    public static class FileService
 | |
|     {
 | |
|         /// <summary>
 | |
|         /// 根据主键返回一个文件信息
 | |
|         /// </summary>
 | |
|         /// <param name="cnProfessionalCode">文件编号</param>
 | |
|         /// <returns></returns>
 | |
|         public static Model.DataBase_File GetFileById(string fileId)
 | |
|         {
 | |
|             return Funs.DB.DataBase_File.FirstOrDefault(x => x.FileId == fileId);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据子分部Id返回所有文件信息
 | |
|         /// </summary>
 | |
|         /// <param name="cnProfessionalCode">文件编号</param>
 | |
|         /// <returns></returns>
 | |
|         public static List<Model.DataBase_File> GetFilesByDataTypeProjectId(string dataTypeProjectId)
 | |
|         {
 | |
|             return (from x in Funs.DB.DataBase_File where x.DataTypeProjectId == dataTypeProjectId select x).ToList();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 添加文件
 | |
|         /// </summary>
 | |
|         /// <param name="Installation"></param>
 | |
|         public static void AddFile(Model.DataBase_File file)
 | |
|         {
 | |
|             Model.DataBase_File newFile = new Model.DataBase_File();
 | |
| 
 | |
|             newFile.FileId = file.FileId;
 | |
|             newFile.ProjectId = file.ProjectId;
 | |
|             newFile.DataTypeProjectId = file.DataTypeProjectId;
 | |
|             newFile.FileCode = file.FileCode;
 | |
|             newFile.FileName = file.FileName;
 | |
|             newFile.Pages = file.Pages;
 | |
|             newFile.Remark = file.Remark;
 | |
|             newFile.CompileDate = file.CompileDate;
 | |
|             newFile.CompileMan = file.CompileMan;
 | |
|             newFile.AttachUrl = file.AttachUrl;
 | |
|             newFile.UnitWorkId = file.UnitWorkId;
 | |
|             newFile.DivisionProjectId = file.DivisionProjectId;
 | |
|             newFile.UnitId = file.UnitId;
 | |
|             newFile.FileType = file.FileType;
 | |
| 
 | |
|             Funs.DB.DataBase_File.InsertOnSubmit(newFile);
 | |
|             Funs.DB.SubmitChanges();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 修改文件
 | |
|         /// </summary>
 | |
|         /// <param name="file"></param>
 | |
|         public static void UpdateFile(Model.DataBase_File file)
 | |
|         {
 | |
|             Model.DataBase_File newFile = Funs.DB.DataBase_File.FirstOrDefault(e => e.FileId == file.FileId);
 | |
|             if (newFile != null)
 | |
|             {
 | |
|                 //newFile.DataTypeProjectId = file.DataTypeProjectId;
 | |
|                 newFile.FileCode = file.FileCode;
 | |
|                 newFile.FileName = file.FileName;
 | |
|                 newFile.Pages = file.Pages;
 | |
|                 newFile.Remark = file.Remark;
 | |
|                 //newFile.CompileDate = file.CompileDate;
 | |
|                 //newFile.CompileMan = file.CompileMan;
 | |
|                 newFile.AttachUrl = file.AttachUrl;
 | |
|                 //newFile.UnitWorkId = file.UnitWorkId;
 | |
|                 //newFile.DivisionProjectId = file.DivisionProjectId;
 | |
| 
 | |
|                 Funs.DB.SubmitChanges();
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据主键删除一个文件信息
 | |
|         /// </summary>
 | |
|         /// <param name="breakdownCode"></param>
 | |
|         public static void DeleteFileById(string fileId)
 | |
|         {
 | |
|             Model.DataBase_File file = Funs.DB.DataBase_File.FirstOrDefault(e => e.FileId == fileId);
 | |
|             if (file != null)
 | |
|             {
 | |
|                 if (!string.IsNullOrEmpty(file.AttachUrl))
 | |
|                 {
 | |
|                     BLL.UploadAttachmentService.DeleteFile(Funs.RootPath, file.AttachUrl);//删除附件
 | |
|                 }
 | |
|                 Funs.DB.DataBase_File.DeleteOnSubmit(file);
 | |
|                 Funs.DB.SubmitChanges();
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |