ZHJA_HJGL/HJGL_ZH/BLL/Common/UploadFileService.cs

202 lines
7.1 KiB
C#

using System.IO;
namespace BLL
{
/// <summary>
/// 上传附件相关
/// </summary>
public class UploadFileService
{
#region
/// <summary>
/// 附件上传
/// </summary>
/// <param name="fileUpload">上传控件</param>
/// <param name="fileUrl">上传路径</param>
/// <param name="constUrl">定义路径</param>
/// <returns></returns>
public static string UploadAttachment(string rootPath, FineUIPro.FileUpload fileUpload, string fileUrl, string constUrl)
{
if (!string.IsNullOrEmpty(fileUrl)) ////是否存在附件 存在则删除
{
string urlFullPath = rootPath + fileUrl;
if (File.Exists(urlFullPath))
{
File.Delete(urlFullPath);
}
}
string initFullPath = rootPath + constUrl;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
string filePath = fileUpload.PostedFile.FileName;
string fileName = Funs.GetNewFileName() + "~" + Path.GetFileName(filePath);
int count = fileUpload.PostedFile.ContentLength;
string savePath = constUrl + fileName;
string fullPath = initFullPath + fileName;
if (!File.Exists(fullPath))
{
byte[] buffer = new byte[count];
Stream stream = fileUpload.PostedFile.InputStream;
stream.Read(buffer, 0, count);
MemoryStream memoryStream = new MemoryStream(buffer);
FileStream fs = new FileStream(fullPath, FileMode.Create, FileAccess.Write);
memoryStream.WriteTo(fs);
memoryStream.Flush();
memoryStream.Close();
fs.Flush();
fs.Close();
memoryStream = null;
fs = null;
//if (!string.IsNullOrEmpty(fileUrl))
//{
// fileUrl += "," + savePath;
//}
//else
//{
// fileUrl += savePath;
//}
fileUrl = savePath;
}
else
{
fileUrl = string.Empty;
}
return fileUrl;
}
#endregion
#region
/// <summary>
/// 附件资源删除
/// </summary>
/// <param name="rootPath"></param>
/// <param name="fileUrl"></param>
public static void DeleteFile(string rootPath, string fileUrl)
{
if (!string.IsNullOrEmpty(fileUrl))
{
string[] strs = fileUrl.Trim().Split(',');
foreach (var item in strs)
{
string urlFullPath = rootPath + item;
if (File.Exists(urlFullPath))
{
File.Delete(urlFullPath);
}
}
}
}
#endregion
#region
/// <summary>
/// 安全组织体系
/// </summary>
public const string HSSEOrganizeFilePath = "FileUpload\\HSSEOrganize\\";
/// <summary>
/// 安全管理机构-附件路径
/// </summary>
public const string HSSEManageFilePath = "FileUpload\\HSSEManage\\";
/// <summary>
/// 标准规范-附件路径
/// </summary>
public static string HSSEStandardsListFilePath = "FileUpload\\HSSEStandardsList\\";
/// <summary>
///法律法规-附件路径
/// </summary>
public static string LawRegulationFilePath = "FileUpload\\LawRegulation\\";
/// <summary>
/// 管理规定-附件路径
/// </summary>
public static string ManageRuleFilePath = "FileUpload\\ManageRule\\";
/// <summary>
/// 生产管理规章制度-附件路径
/// </summary>
public static string RulesRegulationsFilePath = "FileUpload\\RulesRegulations\\";
/// <summary>
/// 培训教材库-附件路径
/// </summary>
public static string TrainingFilePath = "FileUpload\\Training\\";
/// <summary>
/// 事故案例库-附件路径
/// </summary>
public static string AccidentCaseFilePath = "FileUpload\\AccidentCase\\";
/// <summary>
/// HAZOP-附件路径
/// </summary>
public static string HAZOPFilePath = "FileUpload\\HAZOP\\";
/// <summary>
/// 安全试题库-附件路径
/// </summary>
public static string TrainTestDBFilePath = "FileUpload\\TrainTestDB\\";
/// <summary>
/// 安全专家-附件路径
/// </summary>
public static string ExpertFilePath = "FileUpload\\Expert\\";
/// <summary>
/// 应急预案-附件路径
/// </summary>
public const string EmergencyFilePath = "FileUpload\\Emergency\\";
/// <summary>
/// 专项方案-附件路径
/// </summary>
public const string SpecialSchemeFilePath = "FileUpload\\SpecialScheme\\";
/// <summary>
/// 安全监督检查报告-附件路径
/// </summary>
public static string SuperviseCheckReportFilePath = "FileUpload\\SuperviseCheckReport\\";
/// <summary>
/// 安全生产快报-附件路径
/// </summary>
public static string SafeProductionExpressFilePath = "FileUpload\\SafeProductionExpress\\";
/// <summary>
/// 安全交流-附件路径
/// </summary>
public static string ExchangeFilePath = "FileUpload\\Exchange\\";
/// <summary>
/// 安全生产数据季报-附件路径
/// </summary>
public static string SafetyQuarterlyReportFilePath = "FileUpload\\SafetyQuarterlyReport\\";
/// <summary>
/// 在线督查
/// </summary>
public const string OnLineSupervisionFilePath = "FileUpload\\OnLineSupervision\\";
/// <summary>
/// 项目评价
/// </summary>
public const string ProjectEvaluationFilePath = "FileUpload\\ProjectEvaluation\\";
/// <summary>
/// 事故快报
/// </summary>
public const string ProjectAccidentFilePath = "FileUpload\\ProjectAccident\\";
/// <summary>
/// 版本附件路径
/// </summary>
public const string SysVersionFilePath = "FileUpload\\SysVersion\\";
/// <summary>
/// 测温点布置示意图附件路径
/// </summary>
public const string CewendianshcFilePath = "FileUpload\\HotProcessCard1\\";
/// <summary>
/// 理论焊后热处理曲线
/// </summary>
public const string LilunhanhouFilePath = "FileUpload\\HotProcessCard2\\";
/// <summary>
/// 二维码上传路径
/// </summary>
public const string QRCodeImageFilePath = "FileUpload\\QRCodeFile\\";
#endregion
}
}