/// <summary> /// 通用操作方式 /// </summary> /// <param name="guid">唯一编码</param> void ShowOrDownLoad(string guid) { FM_FilePath lnqTemp = m_serverFileBasicInfo.GetFilePathInfo(new Guid(guid)); 操作方式 frm = new 操作方式(ProcessType.发布); frm.ShowDialog(); if (frm.OperatorFlag == CE_FileOperatorType.在线阅读) { FileOperationService.File_Look(new Guid(guid), GlobalObject.GeneralFunction.StringConvertToEnum <CE_CommunicationMode>(BasicInfo.BaseSwitchInfo[(int)GlobalObject.CE_SwitchName.文件传输方式])); } else if (frm.OperatorFlag == CE_FileOperatorType.载) { saveFileDialog1.Filter = "All files (*.*)|*.*"; saveFileDialog1.FileName = (txtFileName.Text + lnqTemp.FileType).Replace("/", "-"); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { m_serverFTP.Download(lnqTemp.FilePath, saveFileDialog1.FileName); if (GetError()) { MessageDialog.ShowPromptMessage("下载成功"); } } } }
void InsertFile(string path, string billNo) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; try { DirectoryInfo mydir = new DirectoryInfo(path); if (!mydir.Exists) { return; } FileInfo[] fileList = mydir.GetFiles(); foreach (FileInfo file in fileList) { string filePath = file.FullName; Guid guid = Guid.NewGuid(); string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1, filePath.LastIndexOf(".") - (filePath.LastIndexOf("\\") + 1)); string fileType = filePath.Substring(filePath.LastIndexOf(".")); string strFtpServerPath = "/" + ServerTime.Time.Year.ToString() + "/" + ServerTime.Time.Month.ToString() + "/"; m_serverFTP.Upload(filePath, strFtpServerPath + guid); if (GetError()) { FM_FilePath lnqTemp = new FM_FilePath(); lnqTemp.FileUnique = guid; lnqTemp.FileType = fileType.ToLower(); lnqTemp.FilePath = strFtpServerPath + guid; lnqTemp.OperationDate = ServerTime.Time; ctx.FM_FilePath.InsertOnSubmit(lnqTemp); ctx.SubmitChanges(); ZL_Database_FileStruct tempLnq = new ZL_Database_FileStruct(); tempLnq.BillNo = billNo; tempLnq.CreationTime = ServerTime.Time; tempLnq.FileUnique = guid; tempLnq.FileName = fileName; tempLnq.ID = Guid.NewGuid(); tempLnq.LastModifyTime = ServerTime.Time; tempLnq.ParentID = null; InsertFileStruct(tempLnq); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// 文件上传 /// </summary> /// <param name="guid">唯一编码</param> /// <param name="systemPath">系统路径</param> /// <param name="type">操作文件访问方式</param> public static void File_UpLoad(Guid guid, string systemPath, CE_CommunicationMode type) { try { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; var varData = from a in ctx.FM_FilePath where a.FileUnique == guid select a; if (varData.Count() == 0) { FM_FilePath fileInfo = new FM_FilePath(); fileInfo.FileUnique = guid; fileInfo.FilePath = "/" + ServerTime.Time.Year.ToString() + "/" + ServerTime.Time.Month.ToString() + "/" + fileInfo.FileUnique.ToString(); fileInfo.FileType = systemPath.Substring(systemPath.LastIndexOf(".")); fileInfo.OperationDate = ServerTime.Time; ctx.FM_FilePath.InsertOnSubmit(fileInfo); DateTime tempdateTime = ServerTime.Time; if (type == CE_CommunicationMode.Socket) { FileServiceSocket serverSocket = new FileServiceSocket(GlobalObject.GlobalParameter.FTPServerIP, GlobalObject.GlobalParameter.FTPServerAdvancedUser, GlobalObject.GlobalParameter.FTPServerAdvancedPassword); serverSocket.Upload(systemPath, fileInfo.FilePath); } else if (type == CE_CommunicationMode.FTP) { FileServiceFTP serverFTP = new FileServiceFTP(GlobalObject.GlobalParameter.FTPServerIP, GlobalObject.GlobalParameter.FTPServerAdvancedUser, GlobalObject.GlobalParameter.FTPServerAdvancedPassword); serverFTP.Upload(systemPath, fileInfo.FilePath); } TimeSpan span = ServerTime.Time - tempdateTime; ctx.SubmitChanges(); } else { throw new Exception("文件唯一编码重复"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// 添加文件 /// </summary> /// <param name="uniqueCode">文件唯一编码</param> /// <param name="path">文件路径</param> /// <param name="fileType">文件类型</param> public void AddFile(Guid uniqueCode, string path, string fileType) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; FM_FilePath lnqTemp = new FM_FilePath(); lnqTemp.FileUnique = uniqueCode; lnqTemp.FileType = fileType.ToLower(); lnqTemp.FilePath = path; lnqTemp.OperationDate = ServerTime.Time; ctx.FM_FilePath.InsertOnSubmit(lnqTemp); ctx.SubmitChanges(); }
/// <summary> /// 查看 /// </summary> /// <param name="guid"></param> /// <param name="type"></param> public static void File_Look(Guid guid, CE_CommunicationMode type) { try { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; var varData = from a in ctx.FM_FilePath where a.FileUnique == guid select a; if (varData.Count() == 1) { FM_FilePath tempPath = varData.Single(); string temp = System.Environment.GetEnvironmentVariable("TEMP"); DirectoryInfo info = new DirectoryInfo(temp); string guidFile = (Guid.NewGuid()).ToString() + "\\"; string filePath = info.FullName + "\\" + guidFile + tempPath.FileUnique + tempPath.FileType; if (type == CE_CommunicationMode.Socket) { FileServiceSocket serverSocket = new FileServiceSocket(GlobalObject.GlobalParameter.FTPServerIP, GlobalObject.GlobalParameter.FTPServerAdvancedUser, GlobalObject.GlobalParameter.FTPServerAdvancedPassword); serverSocket.Download(varData.Single().FilePath, filePath); } else if (type == CE_CommunicationMode.FTP) { FileServiceFTP serverFTP = new FileServiceFTP(GlobalObject.GlobalParameter.FTPServerIP, GlobalObject.GlobalParameter.FTPServerAdvancedUser, GlobalObject.GlobalParameter.FTPServerAdvancedPassword); serverFTP.Download(varData.Single().FilePath, filePath); } System.Diagnostics.Process.Start(filePath); } else { throw new Exception("文件唯一编码重复"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// 更新数据 /// </summary> /// <param name="uniqueCode">唯一编码</param> /// <param name="fileType">文件类型</param> public void UpdateFile(Guid uniqueCode, string fileType) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; var varData = from a in ctx.FM_FilePath where a.FileUnique == uniqueCode select a; if (varData.Count() == 1) { FM_FilePath lnqTemp = varData.Single(); lnqTemp.FileType = fileType.ToLower(); lnqTemp.OperationDate = ServerTime.Time; ctx.SubmitChanges(); } }
/// <summary> /// 通用操作方式 /// </summary> /// <param name="guid">唯一编码</param> void ShowOrDownLoad(string guid) { try { FM_FilePath lnqTemp = m_serverFileBasic.GetFilePathInfo(new Guid(guid)); 操作方式 frm = new 操作方式(ProcessType.发布); frm.ShowDialog(); if (frm.OperatorFlag == CE_FileOperatorType.在线阅读) { FileOperationService.File_Look(new Guid(guid), GlobalObject.GeneralFunction.StringConvertToEnum <CE_CommunicationMode>(BasicInfo.BaseSwitchInfo[(int)GlobalObject.CE_SwitchName.文件传输方式])); } else if (frm.OperatorFlag == CE_FileOperatorType.载) { saveFileDialog1.Filter = "All files (*.*)|*.*"; saveFileDialog1.FileName = (txtFileName.Text + lnqTemp.FileType).Replace("/", "-"); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { BackgroundWorker worker = BackgroundWorkerTools.GetWorker("下载文件"); worker.RunWorkerAsync(); m_serverFTP.Download(lnqTemp.FilePath, saveFileDialog1.FileName); worker.CancelAsync(); if (GetError()) { MessageDialog.ShowPromptMessage("下载成功"); } } } } catch (Exception ex) { MessageDialog.ShowErrorMessage(ex.Message); this.Cursor = System.Windows.Forms.Cursors.Arrow; return; } }
/// <summary> /// 通用操作方式 /// </summary> /// <param name="guid">唯一编码</param> void ShowOrDownLoad(string guid) { try { FM_FilePath lnqTemp = m_serverFileBasicInfo.GetFilePathInfo(new Guid(guid)); 操作方式 frm = new 操作方式(ProcessType.审查); frm.ShowDialog(); if (frm.OperatorFlag == CE_FileOperatorType.在线阅读) { FileOperationService.File_Look(new Guid(guid), GlobalObject.GeneralFunction.StringConvertToEnum <CE_CommunicationMode>(BasicInfo.BaseSwitchInfo[(int)GlobalObject.CE_SwitchName.文件传输方式])); } else if (frm.OperatorFlag == CE_FileOperatorType.载) { saveFileDialog1.Filter = "All files (*.*)|*.*"; saveFileDialog1.FileName = (txtFileName.Text + lnqTemp.FileType).Replace("/", "-"); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { BackgroundWorker worker = BackgroundWorkerTools.GetWorker("下载文件"); worker.RunWorkerAsync(); m_serverFTP.Download(lnqTemp.FilePath, saveFileDialog1.FileName); worker.CancelAsync(); if (GetError()) { MessageDialog.ShowPromptMessage("下载成功"); } } } else if (frm.OperatorFlag == CE_FileOperatorType.在线编辑) { string filePath = "C:\\temp" + lnqTemp.FileType; m_serverFTP.Download(lnqTemp.FilePath, filePath); System.Diagnostics.Process myProcess = new System.Diagnostics.Process(); //设置启动进程的初始目录 myProcess.StartInfo.WorkingDirectory = Application.StartupPath; //设置启动进程的应用程序或文档名 myProcess.StartInfo.FileName = filePath; //设置启动进程的参数 myProcess.StartInfo.Arguments = ""; myProcess.Start(); myProcess.WaitForExit(); bool flag = false; Guid guidTemp = new Guid(); string strFtpServerPath = "/" + ServerTime.Time.Year.ToString() + "/" + ServerTime.Time.Month.ToString() + "/"; if (!GlobalObject.FileTypeRecognition.IsWordDocument(filePath)) { throw new Exception("此文件非正常WORD文件,可能由于文件格式无法识别或者文件加密造成无法上传"); } if (btnAdd.Visible) { ConditionUpdateFile(llbProposerDownLoad, ref guidTemp, strFtpServerPath, lnqTemp.FileType, CE_OperatorMode.修改); flag = true; llbProposerUpLoad.Tag = guidTemp; llbProposerDownLoad.Tag = guidTemp; llbProposerDownLoad.Text = BasicInfo.LoginName + "的文件"; } else if (btnAudit.Visible) { ConditionUpdateFile(llbAuditorDownLoad, ref guidTemp, strFtpServerPath, lnqTemp.FileType, CE_OperatorMode.修改); flag = true; llbAuditorUpLoad.Tag = guidTemp; llbAuditorDownLoad.Tag = guidTemp; llbAuditorDownLoad.Text = BasicInfo.LoginName + "的文件"; } else if (btnPointAffirm.Visible) { ConditionUpdateFile(llbPointDownLoad, ref guidTemp, strFtpServerPath, lnqTemp.FileType, CE_OperatorMode.修改); flag = true; m_serverReviewProcess.PointUpLoadFile(guidTemp, m_strSDBNo); dataGridView1.DataSource = m_serverReviewProcess.GetListInfoTable(txtSDBNo.Text); PositioningRecord(BasicInfo.LoginID); } else if (btnJudge.Visible) { ConditionUpdateFile(llbJudgeDownLoad, ref guidTemp, strFtpServerPath, lnqTemp.FileType, CE_OperatorMode.修改); flag = true; llbJudgeUpLoad.Tag = guidTemp; llbJudgeDownLoad.Tag = guidTemp; llbJudgeDownLoad.Text = BasicInfo.LoginName + "的文件"; } if (flag) { CursorControl.SetWaitCursor(this); m_serverFileBasicInfo.FileUpLoad(filePath, strFtpServerPath, guidTemp.ToString(), lnqTemp.FileType); this.Cursor = System.Windows.Forms.Cursors.Arrow; } File.Delete(filePath); } } catch (Exception ex) { MessageDialog.ShowErrorMessage(ex.Message); this.Cursor = System.Windows.Forms.Cursors.Arrow; return; } }