/// <summary> /// 设置文件卡自由变量的值(文件ID) /// </summary> /// <param name="_filePath">文件ID</param> /// <param name="_value">自由变量名称,变量值</param> /// <returns></returns> public static bool SetFileCardVariableValue(int _fileID, Dictionary <string, string> _value) { try { IEdmVault5 vault5 = new EdmVault5(); IEdmVault7 vault7 = (IEdmVault7)vault5; if (!vault5.IsLoggedIn) { vault5.Login(LogName, PWD, VaultName); } IEdmBatchUpdate2 update = default(IEdmBatchUpdate2); update = (IEdmBatchUpdate2)vault7.CreateUtility(EdmUtility.EdmUtil_BatchUpdate); IEdmVariableMgr5 variableMgr5 = (IEdmVariableMgr5)vault5; foreach (var key in _value.Keys) { //文件ID、变量ID、值、配置名称、 update.SetVar(_fileID, variableMgr5.GetVariable(key).ID, _value[key], "@", (int)EdmBatchFlags.EdmBatch_AllConfigs); } EdmBatchError2[] Errors = null; update.CommitUpdate(out Errors, null); return(true); } catch (Exception ex) { throw ex; } }
//获取用户列表 public static DataTable GetUserList() { DataTable dt = new DataTable(); if (dt.Columns.Count == 0) { dt.Columns.Add("UserName"); dt.Columns.Add("UserID"); dt.Columns.Add("IsLoggedIn"); dt.Columns.Add("Vault"); dt.Columns.Add("FullName"); dt.Columns.Add("UserData"); dt.Columns.Add("Initials"); dt.Columns.Add("ObjectType"); dt.Columns.Add("Email"); } DataRow dr = null; IEdmVault5 vault = new EdmVault5(); try { vault.Login(LogName, PWD, VaultName); } catch (Exception e) { MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } IEdmUserMgr5 UserMgr = default(IEdmUserMgr5); UserMgr = (IEdmUserMgr5)vault; IEdmPos5 UserPos = default(IEdmPos5); UserPos = UserMgr.GetFirstUserPosition(); while (!UserPos.IsNull) { dr = dt.NewRow(); IEdmUser5 user5 = UserMgr.GetNextUser(UserPos); IEdmUser6 user6 = (IEdmUser6)user5; IEdmUser7 user7 = (IEdmUser7)user5; IEdmUser8 user8 = (IEdmUser8)user5; IEdmUser9 user9 = (IEdmUser9)user5; IEdmUser10 user10 = (IEdmUser10)user5; dr["UserName"] = user5.Name; dr["UserID"] = user5.ID; dr["IsLoggedIn"] = user5.IsLoggedIn; dr["Vault"] = user5.Vault.Name; dr["FullName"] = user6.FullName; dr["UserData"] = user6.UserData; dr["Initials"] = user6.Initials; dr["ObjectType"] = user6.ObjectType; dr["Email"] = user10.Email; dt.Rows.Add(dr); } return(dt); }
/// <summary> /// 【5】为文件重命名 /// </summary> /// <param name="filepath">文件全名(包含路径)</param> /// <param name="newName">新名称</param> public static void ReName(string filepath, string newName) { IEdmVault5 vault1 = new EdmVault5(); vault1.Login(LogName, PWD, VaultName); IEdmVault7 vault2 = null; vault2 = (IEdmVault7)vault1; IEdmFile10 file = default(IEdmFile10); IEdmFolder5 ppoRetParentFolder; file = (IEdmFile11)vault2.GetFileFromPath(filepath, out ppoRetParentFolder); file.Rename(new Control().Handle.ToInt32(), newName); }
/// <summary> /// 【4.4】文件是否被检入,true为检出状态。false为检入状态 /// </summary> /// <param name="filepath">文件全名(包含路径)</param> /// <returns></returns> public static bool IsLock(string filepath) { IEdmVault5 vault1 = new EdmVault5(); vault1.Login(LogName, PWD, VaultName); IEdmVault7 vault2 = null; vault2 = (IEdmVault7)vault1; IEdmFile11 aFile = default(IEdmFile11); IEdmFolder5 ppoRetParentFolder; if (filepath.Length > 0) { aFile = (IEdmFile11)vault2.GetFileFromPath(filepath, out ppoRetParentFolder); } return(aFile.IsLocked); }
/// <summary> /// 【4.3】取消捡出指定文件 /// </summary> /// <param name="filepath">文件全名(包含路径)</param> public static void CancelCheckOut(string filepath) { IEdmVault5 vault1 = new EdmVault5(); vault1.Login(LogName, PWD, VaultName); IEdmVault7 vault2 = null; vault2 = (IEdmVault7)vault1; IEdmFile11 aFile = default(IEdmFile11); IEdmFolder5 ppoRetParentFolder; if (filepath.Length > 0) { aFile = (IEdmFile11)vault2.GetFileFromPath(filepath, out ppoRetParentFolder); aFile.UndoLockFile(new System.Windows.Forms.Control().Handle.ToInt32()); } }
/// <summary> /// 【2.1】根据路径获取ID /// </summary> /// <param name="filepath">文件路径(包含文件名)</param> /// <returns></returns> public static int GetFileID(string filepath) { IEdmVault5 vault1 = new EdmVault5(); vault1.Login(LogName, PWD, VaultName); IEdmVault7 vault2 = null; vault2 = (IEdmVault7)vault1; IEdmFile11 aFile = default(IEdmFile11); IEdmFolder5 ppoRetParentFolder; if (filepath.Length > 0) { aFile = (IEdmFile11)vault2.GetFileFromPath(filepath, out ppoRetParentFolder); //aFile.UnlockFile(new System.Windows.Forms.Control().Handle.ToInt32(), ""); } return(aFile.ID); }
/// <summary> /// 【6】pdm库内复制文件,返回pdm中文件全路径(包含文件名) /// </summary> /// <param name="oldFile">旧文件位置</param> /// <param name="newFolder">新文件夹位置</param> public static string CopyFile(string oldFile, string newFolder) { IEdmVault5 vault1 = new EdmVault5(); vault1.Login(LogName, PWD, VaultName); IEdmVault7 vault2 = null; vault2 = (IEdmVault7)vault1; IEdmFile10 file = default(IEdmFile10); IEdmFolder5 ppoRetParentFolder; file = (IEdmFile11)vault2.GetFileFromPath(oldFile, out ppoRetParentFolder); IEdmFolder5 destFolder1 = default(IEdmFolder5); destFolder1 = vault2.GetFolderFromPath(newFolder);//新文件夹位置 IEdmFolder8 destFolder = (IEdmFolder8)destFolder1; int FileID = 0; int copyFileStatus; FileID = destFolder.CopyFile2(file.ID, ppoRetParentFolder.ID, new Control().Handle.ToInt32(), out copyFileStatus, "", (int)EdmCopyFlag.EdmCpy_Simple); return(destFolder1.LocalPath + "\\" + file.Name.Substring(file.Name.LastIndexOf('\\') + 1)); }
private string getVaultRootPath() { string path = null; try { IEdmVault5 vault = new EdmVault5(); vault.Login(_UserName, _Password, _VaultName); path = vault.RootFolderPath; path = vault.RootFolderPath.ToLower(); if (path.LastIndexOf(Path.DirectorySeparatorChar) != path.Length - 1) { path += Path.DirectorySeparatorChar; } } catch (Exception ex) { MessageBox.Show("库登录失败!"); } return(path); }
private static LoginResult Login(string vaultName, string userName, string password, out IEdmVault5 vault) { LoginResult retCode = ResultCodes.LoginResult.OK; vault = null; try { vault = new EdmVault5(); vault.Login(userName, password, vaultName); } catch (System.Runtime.InteropServices.COMException ex) { switch (ex.ErrorCode) { case (int)EdmResultErrorCodes_e.E_EDM_LOGIN_FAILED: retCode = ResultCodes.LoginResult.LOGIN_FAILED; break; case (int)EdmResultErrorCodes_e.E_EDM_CANT_OPEN_DATABASE: retCode = ResultCodes.LoginResult.CANT_OPEN_DATABASE; break; case -2147221164: //没有注册类 retCode = ResultCodes.LoginResult.PDM_CLIENT_DOESNT_EXIST; break; default: retCode = ResultCodes.LoginResult.UNKNOWN_ERROR; break; } } catch (Exception ex) { retCode = ResultCodes.LoginResult.UNKNOWN_ERROR; } return(retCode); }
/// <summary> /// 【8】根据文件名称搜索路径,返回全部路径的集合,如果未搜索到返回null /// </summary> /// <param name="fileName">文件名称(不包含路径)</param> public static List <string> SearchPart(string fileName) { IEdmVault5 vault1 = new EdmVault5(); vault1.Login(LogName, PWD, VaultName); IEdmVault7 vault2 = null; vault2 = (IEdmVault7)vault1; IEdmSearch5 Search = (IEdmSearch5)vault2.CreateUtility(EdmUtility.EdmUtil_Search); Search.FileName = "%" + fileName + "%"; //模糊搜索 //Search.FileName = fileName;//命名搜索 IEdmSearchResult5 Result = Search.GetFirstResult(); //搜索第一个 List <string> lst = new List <string>(); //string filePath = string.Empty; while (Result != null) { lst.Add(Result.Path); Result = Search.GetNextResult();//搜索下一个 } return(lst); }
/// <summary> /// 【7】将文件复制到指定路径(硬盘)——导出 /// </summary> /// <param name="PathInVault">库文件夹根目录下相对路径</param> /// <param name="PathOutVault">本地具体路径</param> public static void CheckoutAndCopy(string PathInVault, string PathOutVault) { try { EdmVault5 vault = new EdmVault5(); vault.Login(LogName, PWD, VaultName); IEdmFile5 file = default(IEdmFile5); IEdmFolder5 folder = null; file = vault.GetFileFromPath(vault.RootFolderPath + PathInVault, out folder);//读取指定文件的位置,PathInVault库文件夹根目录下相对路径 file.LockFile(folder.ID, new System.Windows.Forms.Control().Handle.ToInt32()); file.UndoLockFile(new System.Windows.Forms.Control().Handle.ToInt32(), true); //Copy the file IEdmEnumeratorVersion5 verEnum = default(IEdmEnumeratorVersion5); verEnum = (IEdmEnumeratorVersion5)file; int Version = 0; Version = file.GetLocalVersionNo(folder.ID); IEdmVersion5 ver = default(IEdmVersion5); ver = verEnum.GetVersion(Version); ver.GetFileCopy(new System.Windows.Forms.Control().Handle.ToInt32(), PathOutVault);//PathOutVault本地具体路径 } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode.ToString() == "-2147220949") { MessageBox.Show("The selected file is not located in a file vault."); } else { MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 【3】将文件添加到库中指定位置——导入,并返回pdm中文件全路径(包含文件名) /// </summary> /// <param name="FullName">要复制库外文件路径和名称</param> /// <param name="path">库中根目录下具体位置,如“\\03标准规范\\05技术通知单”</param> /// <returns></returns> public static string AddFile(string FullName, string path) { IEdmVault5 vault1 = new EdmVault5(); IEdmVault7 vault2 = (IEdmVault7)vault1; vault1.Login(LogName, PWD, VaultName);//使用管理员登录每个用户不同 // Add selected file to the root folder of the vault IEdmFolder5 Folder = default(IEdmFolder8); Folder = (IEdmFolder8)vault2.RootFolder; Folder = vault2.GetFolderFromPath(Folder.LocalPath + path); string name = FullName.Substring(FullName.LastIndexOf("\\") + 1); if (File.Exists(Folder.LocalPath + "\\" + name)) { MessageBox.Show("文件已经存在,请更改文件名称!", "提示信息"); return(""); } else { Folder.AddFile(new System.Windows.Forms.Control().Handle.ToInt32(), FullName, "", 0); } return(Folder.LocalPath + "\\" + name); }