public void Rename(ImagePart part, string newName) { var index = part.Index; if (Folder.PartIndexs.Contains(index)) { if (Database.ImagePartTable[index.DictionaryName].Has(newName)) { MessageBox.Show( string.Format("无法重命名\"{0}\":与现有元件重名", newName), "重命名时出错"); } else { SymbolIndex oldid = part.Index; SymbolIndex newid = new SymbolIndex(newName, part.Standard, part.No); if (!index.Equals(newid)) { Database.ImagePartTable.Redirect(part, newid); Folder.Redirect(oldid, newid); } part.Rename(newName); } } }
/// <summary> /// 按给定的符号索引和名称重定位元件定义 /// </summary> /// <param name="part">元件定义</param> /// <param name="index">符号索引</param> /// <param name="name">名称</param> public void Redirect(ImagePart part, SymbolIndex index, string name) { var oldName = part.Name; var oldid = part.Index; var folders = Root .GetAllFolders() .Where(f => f.HasPartIndex(oldid)); ImagePartTable.Redirect(part, index); foreach (var folder in folders) { folder.Redirect(oldid, index); } if (oldName != name) { part.Rename(name); } }