/// <summary> /// FTP文件添加操作 /// </summary> /// <param name="msFile">内存流中的文件</param> /// <param name="ftpRelativePath">ftp的相对目标路径</param> /// <param name="hostIp">ftp主机IP</param> /// <param name="userNo">ftp用户名</param> /// <param name="userPwd">ftp用户密码</param> /// <param name="viewModel">文件信息</param> /// <param name="fileInfo">附件信息(名称+拓展名)</param> /// <returns>操作结果</returns> public string FtpAdd(MemoryStream msFile, string ftpRelativePath, string hostIp, string userNo, string userPwd, ModelView.DmsFileView viewModel, string fileInfo) { if (string.IsNullOrEmpty(fileInfo)) { return("目标文件信息无法读取!"); } string fileExtension = System.IO.Path.GetExtension(fileInfo); string fileOperateName = fileInfo; //文件格式校验 List <string> exts = new List <string>(); exts.Add(".doc"); exts.Add(".docx"); exts.Add(".xls"); exts.Add(".xlsx"); exts.Add(".ppt"); exts.Add(".ppts"); if (!exts.Contains(fileExtension.ToLower())) { return("文件格式不正确!"); } //校验文件是否存在 if (Common.FTPStreamHelper.FtpExistFile(ftpRelativePath, fileOperateName, hostIp, userNo, userPwd)) { return("不能上传已存在的文件!"); } if (Common.FTPStreamHelper.UploadFile(msFile, fileOperateName, ftpRelativePath, hostIp, userNo, userPwd)) { viewModel.ralate_file_name = fileInfo; Ctrl.DmsFileCtrl dfc = new DmsFileCtrl(); if (dfc.Update(viewModel) > 0) { return("success"); } else { Common.FTPStreamHelper.DelFile(fileOperateName, ftpRelativePath, hostIp, userNo, userPwd); return("数据写入失败!"); } } else { return("Ftp文件上传失败!"); } }
/// <summary> /// 设定文件生效日期 /// </summary> /// <param name="fileView"></param> /// <param name="dateStr">生效起始日期字符串</param> /// <returns></returns> public string SetValidDate(ModelView.DmsFileView fileView, string dateStr) { if (fileView == null) { return("无法设定目标文件为空的文件生效日期"); } DmsFileCtrl dmsFileCtrl = new DmsFileCtrl(); List <ModelView.DmsFileView> list = dmsFileCtrl.GetList(fileView.file_no, fileView.eqm_no, fileView.file_type_no); DateTime dtTmp = DateTime.Now; DateTime dtStart = (DateTime.TryParse(dateStr, out dtTmp) ? dtTmp : DateTime.Now).Date; DateTime dtStop = dtStart - new TimeSpan(0, 0, 1); string validDateStart = dtStart.ToString("yyyy-MM-dd HH:mm:ss.fff"); string validDateEnd = dtStop.ToString("yyyy-MM-dd HH:mm:ss.fff"); List <ModelView.DmsFileView> list2Update = new List <ModelView.DmsFileView>(); foreach (ModelView.DmsFileView item in list) { item.valid_date_end = validDateEnd; list2Update.Add(item); } fileView.valid_date_start = validDateStart; list2Update.Add(fileView); return(dmsFileCtrl.Update(list2Update) > 0 ? "success" : "生效日期数据写入失败!"); }
/// <summary> /// 文件信息的审核通过的写入 /// </summary> /// <param name="dmsFileView">要更新的文件视图</param> /// <returns>更新的消息</returns> private string UpdateFile(ModelView.DmsFileView dmsFileView) { DmsFileCtrl dmsfileCtrl = new DmsFileCtrl(); return(dmsfileCtrl.Update(dmsFileView) > 0?"success":"文件信息写入失败!"); }