/// <summary> /// 更新一条数据 /// </summary> public bool Update(FileOperationLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update fileoperationlog set "); strSql.Append("PROJECTID=@PROJECTID,"); strSql.Append("EMPLOYEEID=@EMPLOYEEID,"); strSql.Append("FILENAME=@FILENAME,"); strSql.Append("OPERATETYPE=@OPERATETYPE,"); strSql.Append("OPERATEDATE=@OPERATEDATE,"); strSql.Append("OPERATEUSER=@OPERATEUSER,"); strSql.Append("OPERATECONTENT=@OPERATECONTENT"); strSql.Append(" where ID=@ID "); MySqlParameter[] parameters = { new MySqlParameter("@PROJECTID", MySqlDbType.VarChar, 36), new MySqlParameter("@EMPLOYEEID", MySqlDbType.VarChar, 36), new MySqlParameter("@FILENAME", MySqlDbType.VarChar, 255), new MySqlParameter("@OPERATETYPE", MySqlDbType.Int32, 2), new MySqlParameter("@OPERATEDATE", MySqlDbType.DateTime), new MySqlParameter("@OPERATEUSER", MySqlDbType.VarChar, 36), new MySqlParameter("@OPERATECONTENT", MySqlDbType.VarChar, 300), new MySqlParameter("@ID", MySqlDbType.VarChar, 36) }; parameters[0].Value = model.PROJECTID; parameters[1].Value = model.EMPLOYEEID; parameters[2].Value = model.FILENAME; parameters[3].Value = model.OPERATETYPE; parameters[4].Value = model.OPERATEDATE; parameters[5].Value = model.OPERATEUSER; parameters[6].Value = model.OPERATECONTENT; parameters[7].Value = model.ID; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public FileOperationLog DataRowToModel(DataRow row) { FileOperationLog model = new FileOperationLog(); if (row != null) { if (row["ID"] != null) { model.ID = row["ID"].ToString(); } if (row["PROJECTID"] != null) { model.PROJECTID = row["PROJECTID"].ToString(); } if (row["EMPLOYEEID"] != null) { model.EMPLOYEEID = row["EMPLOYEEID"].ToString(); } if (row["FILENAME"] != null) { model.FILENAME = row["FILENAME"].ToString(); } if (row["OPERATETYPE"] != null && row["OPERATETYPE"].ToString() != "") { model.OPERATETYPE = int.Parse(row["OPERATETYPE"].ToString()); } if (row["OPERATEDATE"] != null && row["OPERATEDATE"].ToString() != "") { model.OPERATEDATE = DateTime.Parse(row["OPERATEDATE"].ToString()); } if (row["OPERATEUSER"] != null) { model.OPERATEUSER = row["OPERATEUSER"].ToString(); } if (row["OPERATECONTENT"] != null) { model.OPERATECONTENT = row["OPERATECONTENT"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(FileOperationLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into fileoperationlog("); strSql.Append("ID,PROJECTID,EMPLOYEEID,FILENAME,OPERATETYPE,OPERATEDATE,OPERATEUSER,OPERATECONTENT)"); strSql.Append(" values ("); strSql.Append("@ID,@PROJECTID,@EMPLOYEEID,@FILENAME,@OPERATETYPE,@OPERATEDATE,@OPERATEUSER,@OPERATECONTENT)"); MySqlParameter[] parameters = { new MySqlParameter("@ID", MySqlDbType.VarChar, 36), new MySqlParameter("@PROJECTID", MySqlDbType.VarChar, 36), new MySqlParameter("@EMPLOYEEID", MySqlDbType.VarChar, 36), new MySqlParameter("@FILENAME", MySqlDbType.VarChar, 255), new MySqlParameter("@OPERATETYPE", MySqlDbType.Int32, 2), new MySqlParameter("@OPERATEDATE", MySqlDbType.DateTime), new MySqlParameter("@OPERATEUSER", MySqlDbType.VarChar, 36), new MySqlParameter("@OPERATECONTENT", MySqlDbType.VarChar, 300) }; parameters[0].Value = model.ID; parameters[1].Value = model.PROJECTID; parameters[2].Value = model.EMPLOYEEID; parameters[3].Value = model.FILENAME; parameters[4].Value = model.OPERATETYPE; parameters[5].Value = model.OPERATEDATE; parameters[6].Value = model.OPERATEUSER; parameters[7].Value = model.OPERATECONTENT; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public FileOperationLog GetModel(string ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID,PROJECTID,EMPLOYEEID,FILENAME,OPERATETYPE,OPERATEDATE,OPERATEUSER,OPERATECONTENT from fileoperationlog "); strSql.Append(" where ID=@ID "); MySqlParameter[] parameters = { new MySqlParameter("@ID", MySqlDbType.VarChar, 36) }; parameters[0].Value = ID; FileOperationLog model = new FileOperationLog(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public void DownloadFile() { string returnMsg = string.Empty; int errorCode = 0; // 校验参数 string[] parametersRequired = { "fileHistoryId" }; if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg)) { JsonResult <string> resultPra = new JsonResult <string> { Code = errorCode, Message = returnMsg, Rows = 0, Result = null }; GenerateJson(resultPra); return; } string actPath = string.Empty; string taskRootFolder = string.Empty; string taskFolderWithoutEmpNo = string.Empty; string fileHistoryId = context.Request["fileHistoryId"]; // 根据 ID 获取到 fileHistory 对象 FileHistory fileHistory = new FileHistoryBLL().GetModel(fileHistoryId); DataTable dtPrjIdAndCategory = new FileCategoryBLL().GetProjectIdByFileHistoryId(fileHistoryId).Tables[0]; string projectId = Convert.ToString(dtPrjIdAndCategory.Rows[0]["PROJECTID"]); string category = Convert.ToString(dtPrjIdAndCategory.Rows[0]["category"]); string folderName = Convert.ToString(dtPrjIdAndCategory.Rows[0]["folderName"]); bool flag = new FileCategoryBLL().GetFilePathByProjectId(projectId, category, folderName, false, out actPath, out taskRootFolder, out taskFolderWithoutEmpNo, out errorCode); string physicalFileName = Path.Combine(actPath, fileHistory.FILENAME); if (File.Exists(physicalFileName)) { string userId = UserProfile.GetInstance()?.ID; string operateTypeName = "下载"; int operateTypeKey = new ConfigureBLL().GetConfig(ConfigTypeName.文件操作类型.ToString()).AsEnumerable().Where(item => item["configValue"].ToString() == operateTypeName).Select(item => Convert.ToInt32(item["configKey"])).FirstOrDefault(); FileOperationLog fileOperationLog = new FileOperationLog(); fileOperationLog.ID = Guid.NewGuid().ToString(); fileOperationLog.PROJECTID = projectId; fileOperationLog.EMPLOYEEID = userId; fileOperationLog.FILENAME = fileHistory.FILENAME; fileOperationLog.OPERATETYPE = operateTypeKey; fileOperationLog.OPERATEDATE = DateTime.Now; fileOperationLog.OPERATECONTENT = operateTypeName + fileHistory.FILENAME; fileOperationLog.OPERATEUSER = userId; new FileOperationLogBLL().Add(fileOperationLog); System.IO.Stream iStream = null; // Buffer to read 10K bytes in chunk: byte[] buffer = new Byte[10000]; // Length of the file: int length; // Total bytes to read. long dataToRead; // Identify the file to download including its path. string filepath = physicalFileName; // Identify the file name. string filename = System.IO.Path.GetFileName(filepath); try { // Open the file. iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); // Total bytes to read. dataToRead = iStream.Length; context.Response.Clear(); context.Response.ClearHeaders(); context.Response.ClearContent(); context.Response.ContentType = "text/plain"; // Set the file type context.Response.AddHeader("Content-Length", dataToRead.ToString()); context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ""); // Read the bytes. while (dataToRead > 0) { // Verify that the client is connected. if (context.Response.IsClientConnected) { // Read the data in buffer. length = iStream.Read(buffer, 0, 10000); // Write the data to the current output stream. context.Response.OutputStream.Write(buffer, 0, length); // Flush the data to the HTML output. context.Response.Flush(); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { // Prevent infinite loop if user disconnects dataToRead = -1; } } } catch (Exception ex) { // Trap the error, if any. context.Response.Write("Error : " + ex.Message); } finally { if (iStream != null) { //Close the file. iStream.Close(); } context.Response.End(); } } errorCode = 6001; returnMsg = ErrorCode.GetCodeMessage(errorCode); JsonResult <string> result = new JsonResult <string> { Code = errorCode, Message = returnMsg, Rows = 0, Result = null }; GenerateJson(result); return; }
public void DeleteFile() { string returnMsg = string.Empty; int errorCode = 0; // 校验参数 string[] parametersRequired = { "fileHistoryId" }; if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg)) { JsonResult <string> result = new JsonResult <string> { Code = errorCode, Message = returnMsg, Rows = 0, Result = null }; GenerateJson(result); return; } string fileHistoryId = context.Request["fileHistoryId"]; // 根据 ID 获取到 fileHistory 对象 FileHistory fileHistory = new FileHistoryBLL().GetModel(fileHistoryId); if (fileHistoryId != null) { fileHistory.ISDELETED = true; bool delFlag = new FileHistoryBLL().Update(fileHistory); // 逻辑删除成功 if (delFlag) { string actPath = string.Empty; string taskRootFolder = string.Empty; string deletedFolder = ConfigurationManager.AppSettings["fileDeletedFolder"].ToString(); string taskFolderWithoutEmpNo = string.Empty; DataTable dtPrjIdAndCategory = new FileCategoryBLL().GetProjectIdByFileHistoryId(fileHistoryId).Tables[0]; string projectId = Convert.ToString(dtPrjIdAndCategory.Rows[0]["PROJECTID"]); string category = Convert.ToString(dtPrjIdAndCategory.Rows[0]["category"]); string folderName = Convert.ToString(dtPrjIdAndCategory.Rows[0]["folderName"]); bool flag = new FileCategoryBLL().GetFilePathByProjectId(projectId, category, folderName, false, out actPath, out taskRootFolder, out taskFolderWithoutEmpNo, out errorCode); string physicalFileName = Path.Combine(actPath, fileHistory.FILENAME); string timeStr = DateTime.Now.ToString("yyyyMMddHHmmss"); string destFileName = Path.Combine(deletedFolder, timeStr + fileHistory.FILENAME); if (File.Exists(physicalFileName)) { try { // 如果目标位置文件已存在,则先将其删除 if (File.Exists(destFileName)) { File.Delete(destFileName); } // 移动文件到删除暂存目录 File.Move(physicalFileName, destFileName); } catch (IOException ioEx) { errorCode = 1; returnMsg = ioEx.Message; LogHelper.WriteLine("文件删除失败:" + ioEx.Message); } finally { if (File.Exists(physicalFileName)) { fileHistory.ISDELETED = false; new FileHistoryBLL().Update(fileHistory); errorCode = 1; } else { // 记录操作日志 string operateTypeName = "删除"; int operateTypeKey = new ConfigureBLL().GetConfig(ConfigTypeName.文件操作类型.ToString()).AsEnumerable().Where(item => item["configValue"].ToString() == operateTypeName).Select(item => Convert.ToInt32(item["configKey"])).FirstOrDefault(); FileOperationLog fileOperationLog = new FileOperationLog(); fileOperationLog.ID = Guid.NewGuid().ToString(); fileOperationLog.PROJECTID = projectId; fileOperationLog.EMPLOYEEID = UserProfile.GetInstance()?.ID; fileOperationLog.FILENAME = fileHistory.FILENAME; fileOperationLog.OPERATETYPE = operateTypeKey; fileOperationLog.OPERATEDATE = DateTime.Now; fileOperationLog.OPERATECONTENT = operateTypeName + fileHistory.FILENAME; fileOperationLog.OPERATEUSER = UserProfile.GetInstance()?.ID; new FileOperationLogBLL().Add(fileOperationLog); } } } } else { errorCode = 1; } JsonResult <string> result = new JsonResult <string> { Code = errorCode, Message = returnMsg, Rows = 0, Result = null }; GenerateJson(result); return; } JsonResult <string> resultFinal = new JsonResult <string> { Code = errorCode, Message = returnMsg, Rows = 0, Result = null }; GenerateJson(resultFinal); return; }
public void UploadSuccess() { string returnMsg = string.Empty; int errorCode = 0; string projectId = string.Empty; string category = string.Empty; string folder = string.Empty; string userId = string.Empty; string physicalFileName = string.Empty; // 校验参数 string[] parametersRequired = { "parentId", "description", "taskid", "filename" }; if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg)) { JsonResult <string> resultChkPar = new JsonResult <string> { Code = errorCode, Message = returnMsg, Rows = 0, Result = null }; GenerateJson(resultChkPar); return; } string taskid = context.Request["taskid"].ToString(); string filename = context.Request["filename"].ToString(); string parentId = Convert.ToString(context.Request["parentId"]); string description = Convert.ToString(context.Request["description"]); FileCategory fileCategory = new FileCategoryBLL().GetModel(parentId); if (fileCategory != null) { projectId = fileCategory.PROJECTID; folder = fileCategory.FOLDERNAME; category = fileCategory.CATEGORY; bool flag = MergeSplitFile(taskid, projectId, category, folder, filename, out physicalFileName, out errorCode); if (flag) { userId = UserProfile.GetInstance()?.ID; string fileNameRelativeToTaskFolder = Path.Combine(folder, filename); bool addFileHisFlag = new FileHistoryBLL().AddFileHistory(parentId, filename, fileNameRelativeToTaskFolder, description, userId); if (addFileHisFlag) { string operateTypeName = "上传"; int operateTypeKey = new ConfigureBLL().GetConfig(ConfigTypeName.文件操作类型.ToString()).AsEnumerable().Where(item => item["configValue"].ToString() == operateTypeName).Select(item => Convert.ToInt32(item["configKey"])).FirstOrDefault(); FileOperationLog fileOperationLog = new FileOperationLog(); fileOperationLog.ID = Guid.NewGuid().ToString(); fileOperationLog.PROJECTID = projectId; fileOperationLog.EMPLOYEEID = userId; fileOperationLog.FILENAME = filename; fileOperationLog.OPERATETYPE = operateTypeKey; fileOperationLog.OPERATEDATE = DateTime.Now; fileOperationLog.OPERATECONTENT = operateTypeName + filename; fileOperationLog.OPERATEUSER = userId; new FileOperationLogBLL().Add(fileOperationLog); JsonResult <string> resultOprLog = new JsonResult <string> { Code = errorCode, Message = returnMsg, Rows = 0, Result = null }; GenerateJson(resultOprLog); return; } // 添加失败时,需删除已上传的文件 else { if (File.Exists(physicalFileName)) { File.Delete(physicalFileName); } JsonResult <string> resultAddDb2 = new JsonResult <string> { Code = errorCode, Message = "数据库记录添加失败", Rows = 0, Result = null }; GenerateJson(resultAddDb2); return; } } returnMsg = ErrorCode.GetCodeMessage(errorCode); JsonResult <string> resultAddDb = new JsonResult <string> { Code = errorCode, Message = returnMsg, Rows = 0, Result = null }; GenerateJson(resultAddDb); return; } JsonResult <string> result = new JsonResult <string> { Code = errorCode, Message = "未找到 projectId 对应的记录", Rows = 0, Result = null }; GenerateJson(result); return; }
public bool Add(FileOperationLog log) { return(false); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(FileOperationLog model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(FileOperationLog model) { return(dal.Add(model)); }