private void FillTreeview(Project prj) { treeView1.Nodes.Clear(); //加载根节点 treeView1.Nodes.Add(new TreeNode(prj.Name)); ImageList newImageList=new ImageList (); newImageList.Images.Add("project", Resources.project); newImageList.Images.Add("template", Resources.template); newImageList.Images.Add("folder",Resources.folder); newImageList.Images.Add("data",Resources.data); treeView1.ImageList = newImageList; treeView1.Nodes[0].ImageKey = "project"; treeView1.Nodes[0].SelectedImageKey = "project"; //加载模板节点 foreach(Template template in prj.TemplateList) { TreeNode node = treeView1.Nodes[0].Nodes.Add(template.Name, template.Name); node.ImageKey = "template"; node.SelectedImageKey = "template"; node.Tag = template; //加载数据节点 DirectoryInfo directoryInfo = new DirectoryInfo(prj.ConfigDataPath + "\\" + template.Name); foreach (FileSystemInfo fileSystemInfo in directoryInfo.GetFileSystemInfos()) { if (fileSystemInfo.GetType() == typeof(DirectoryInfo)) { TreeNode folderNode = node.Nodes.Add(fileSystemInfo.Name, fileSystemInfo.Name); folderNode.ImageKey = "folder"; folderNode.SelectedImageKey = "folder"; folderNode.Tag = template; DirectoryInfo directoryData = (DirectoryInfo)fileSystemInfo; foreach (FileInfo file in directoryData.GetFiles()) { ConfigData configFolderData = prj.GetConfigDataByName(file.Name.Replace(file.Extension, "")); TreeNode folderDataNode = folderNode.Nodes.Add(configFolderData.Code, configFolderData.Name); folderDataNode.ImageKey = "data"; folderDataNode.SelectedImageKey = "data"; folderDataNode.Tag = configFolderData; } } else if (fileSystemInfo.GetType() == typeof(FileInfo)) { ConfigData configdata = prj.GetConfigDataByName(fileSystemInfo.Name.Replace(fileSystemInfo.Extension,"")); TreeNode dataNode = node.Nodes.Add(configdata.Code, configdata.Name); dataNode.ImageKey = "data"; dataNode.SelectedImageKey = "data"; dataNode.Tag = configdata; } } } treeView1.ExpandAll(); }
private void ClearAll() { _project = null; CurrentProject.Instance = null; _projectFileName=""; _selecedTemplate=null; tabControl1.Tabs.Clear(); treeView1.Nodes.Clear(); CurrentProject.Instance = null; }
private void CreateProject() { frmCreateProject frm = new frmCreateProject(); DialogResult result = frm.ShowDialog(); if (frm.IsValidate) { ClearAll(); System.IO.Directory.CreateDirectory(frm.ProjectFolder); _project = new Project(); _project.Name = frm.ProjectName; _projectFileName = frm.ProjectFileName; _project.Save(_projectFileName); CurrentProject.Instance = _project; treeView1.Nodes.Clear(); treeView1.Nodes.Add(new TreeNode(CurrentProject.Instance.Name)); } }
private void OpenProject() { ClearAll(); openFileDialog1.Filter = "项目文件|*.prj"; DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { _projectFileName = openFileDialog1.FileName; _project = new Project(); _project.Load(_projectFileName); CurrentProject.Instance = _project; this.FillTreeview(CurrentProject.Instance); } }
public Template GetTemplate(Project prj) { if (prj.ID != this.ProjectId) throw new Exception("数据文件不在指定的项目中!"); var query = from template in prj.TemplateList where template.Code == this.TemplateCode select template; if (query.Count() == 0) throw new Exception("在指定项目中未找到模板!"); return query.First<Template>(); }
public frmTemplateManager(Project prj) { InitializeComponent(); _prj = prj; }