📄 frmmain.cs
字号:
obj.OnlyFileID = this.OnlyFileReader.GetNextID();
obj.BelongTo = newNode.FullPath;
obj.InputDate = DateTime.Today;
//存入数据库中
this.OnlyFileReader.SaveMeToDB(obj);
//将此对象放入树节点的Tag属性中
newNode.Tag = obj;
//将对象传给窗体
this.OnlyFileForm.OnlyFileObject = obj;
//显示面板
this.ShowOnlyFilePanel();
}
/// <summary>
/// 创建Folder对象,将其存入数据库,并放到树的Tag节点中,然后,显示相应的面板
/// </summary>
/// <param name="newNode"></param>
private void DoWithNewFolderNode(SuperTreeViewNode newNode)
{
Folder obj = new Folder();
obj.FolderID = this.FolderReader.GetNextID();
obj.BelongTo = newNode.FullPath;
obj.InputDate = DateTime.Today;
//存入数据库中
this.FolderReader.SaveMeToDB(obj);
//将此对象放入树节点的Tag属性中
newNode.Tag = obj;
//将对象传给窗体
this.FolderForm.FolderObject = obj;
//显示面板
this.ShowFolderPanel();
}
/// <summary>
/// 创建PicLib对象,将其存入数据库,并放到树的Tag节点中,然后,显示相应的面板
/// </summary>
/// <param name="newNode"></param>
private void DoWithNewPicLibNode(SuperTreeViewNode newNode)
{
PicLib obj = new PicLib();
obj.PicLibID = this.PicLibReader.GetNextID();
obj.BelongTo = newNode.FullPath;
obj.InputDate = DateTime.Today;
//存入数据库中
this.PicLibReader.SaveMeToDB(obj);
//将此对象放入树节点的Tag属性中
newNode.Tag = obj;
//将对象传给窗体
this.PicLibForm.PicLibObject = obj;
//显示面板
this.ShowPicLibPanel();
}
#endregion
/// <summary>
/// 删除节点时的处理
/// </summary>
private void OnDeleteNode()
{
bool bDeleted = false;
try
{
if(this.superTreeView1.SelectedNode == null)
return;
if(this.sysArgu.Debug)
{
MyTrace.WriteLine("", false);
MyTrace.WriteLine("Delete Node:" + this.superTreeView1.SelectedNode.Text, true);
}
if(this.superTreeView1.SelectedNode == this.superTreeView1.Nodes[0])
{
DialogResult ret = MessageBox.Show("删除根节点将导致清空所有数据,真的进行吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if(ret == DialogResult.Yes)
{
this.DeleteRootNode();
bDeleted = true;
}
}
else//非根节点,则需要完成递归删除工作
{
DialogResult ret = MessageBox.Show("删除此节点将导致其子节点同时被删除,真的进行吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(ret == DialogResult.Yes)
{
this.DeleteNode(this.superTreeView1.SelectedNode as SuperTreeViewNode);
bDeleted = true;
}
}
//保存树
this.SaveAllTree();
}
catch(Exception ex)
{
MessageBox.Show("在删除节点时发生错误,系统给出的信息为:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if(bDeleted)
{
this.superTreeView1.SelectedNode = null;
//隐藏所有的面板
this.HideAllPanel();
}
}
}
/// <summary>
/// 节点改名时的处理
/// </summary>
private void OnRenameNode()
{
if(this.superTreeView1.SelectedNode == null)
return;
this.superTreeView1.LabelEdit = true;
this.curOperationStatus = TreeOperationStatus.RenameNode;
this.superTreeView1.SelectedNode.BeginEdit();
}
private void SaveAllTree()
{
try
{
this.superTreeView1.SaveToXMLFile(Application.StartupPath + "\\" + MainTreeFile, null);
}
catch(Exception ex)
{
MessageBox.Show("保存树到文件:" + MainTreeFile + "时发生错误,下层组件返回的信息为:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 复制节点文本
/// </summary>
private void CopyNodeText()
{
if(this.superTreeView1.SelectedNode == null)
return;
Clipboard.SetDataObject(this.superTreeView1.SelectedNode.Text);
}
/// <summary>
/// 剪切节点
/// </summary>
private void OnCutNode()
{
//根节点不允许剪切
if(this.superTreeView1.SelectedNode.Parent == null)
return;
if(this.sysArgu.Debug)
{
MyTrace.WriteLine("", false);
MyTrace.WriteLine("CutNode:" + this.superTreeView1.SelectedNode.Text, true);
MyTrace.WriteLine("ParentNode:" + this.superTreeView1.SelectedNode.Text, false);
}
this.IsInNodeCut = true;
this.superTreeView1.CutNode();
this.DetailForm.DetailTextObject = null;
this.mnuCutNode.Enabled = false;
this.mnuPasteNode.Enabled = true;
//隐藏所有的面板
this.HideAllPanel();
}
/// <summary>
/// 粘贴节点
/// </summary>
private void OnPasteNode()
{
if(this.sysArgu.Debug)
{
MyTrace.WriteLine("", false);
MyTrace.WriteLine("PasteNode:ParentNode=" + this.superTreeView1.SelectedNode.Text, false);
}
this.superTreeView1.PasteNode();
this.mnuCutNode.Enabled = true;
this.mnuPasteNode.Enabled = false;
this.superTreeView1.SelectedNode.Expand();
this.IsInNodeCut = false;
}
/// <summary>
/// 查找数据
/// </summary>
private void FindNode()
{
this.FindDataForm.Show();
}
#region 处理树节点单击
/// <summary>
/// 当用户点击不同节点时的处理:显示不同的面板
/// </summary>
/// <param name="node"></param>
private void OnAfterSelectedNode(SuperTreeViewNode node)
{
if(node == null)
return;
switch(node.NodeType)
{
case "OnlyText" :
//隐藏所有的面板
this.HideAllPanel();
break;
case "DetailText" :
this.OnClickDetailTextNode(node);
break;
case "OnlyFile" :
this.OnClickOnlyFileNode(node);
break;
case "Folder" :
this.OnClickFolderNode(node);
break;
case "PicLib" :
this.OnClickPicLibNode(node);
break;
default ://不知名的节点类型
this.HideAllPanel();
break;
}
if(this.CanAddToHistory)
{
this.BackForwardObj.AddOpt(node);
this.btnBack.Enabled = true;
this.btnForward.Enabled = false;
this.CanAddToHistory = false;
}
}
/// <summary>
/// 单击文件夹节点
/// </summary>
/// <param name="node"></param>
private void OnClickFolderNode(SuperTreeViewNode node)
{
this.ShowFolderPanel();
Folder obj;
if(node.Tag == null)
{
//从数据库中创建对象,并装入Tag属性中
obj = this.FolderReader.GetObjectByPathStr(node.FullPath);
if(obj == null)//有可能为空,因为XML配置文件中的节点属性可以改变
{
obj = new Folder();
obj.FolderID = this.FolderReader.GetNextID();
obj.BelongTo = node.FullPath;
obj.InputDate = DateTime.Today;
this.FolderReader.SaveMeToDB(obj);
}
node.Tag = obj;
}
else
{
obj = node.Tag as Folder;
}
//显示相关信息
this.FolderForm.FolderObject = obj;
}
/// <summary>
/// 单击图像节点
/// </summary>
/// <param name="node"></param>
private void OnClickPicLibNode(SuperTreeViewNode node)
{
this.ShowPicLibPanel();
PicLib obj;
if(node.Tag == null)
{
//从数据库中创建对象,并装入Tag属性中
obj = this.PicLibReader.GetObjectByPathStr(node.FullPath);
if(obj == null)//有可能为空,因为XML配置文件中的节点属性可以改变
{
obj = new PicLib();
obj.PicLibID = this.PicLibReader.GetNextID();
obj.BelongTo = node.FullPath;
obj.InputDate = DateTime.Today;
this.PicLibReader.SaveMeToDB(obj);
}
node.Tag = obj;
}
else
{
obj = node.Tag as PicLib;
}
//显示相关信息
this.PicLibForm.PicLibObject = obj;
}
/// <summary>
/// 处理单击DetailText节点
/// </summary>
/// <param name="node"></param>
private void OnClickDetailTextNode(SuperTreeViewNode node)
{
this.ShowDetailTextPanel();
DetailText obj;
if(node.Tag == null)
{
//从数据库中创建对象,并装入Tag属性中
obj = this.DetailReader.GetObjectByPathStr(node.FullPath);
if(obj == null)//有可能为空,因为XML配置文件中的节点属性可以改变
{
obj = new DetailText();
obj.DetailTextID = this.DetailReader.GetNextID();
obj.BelongTo = node.FullPath;
obj.InputDate = DateTime.Today;
this.DetailReader.SaveMeToDB(obj);
}
node.Tag = obj;
}
else
{
obj = node.Tag as DetailText;
}
//显示相关信息
this.DetailForm.DetailTextObject = obj;
}
/// <summary>
/// 处理单击OnlyFile节点
/// </summary>
/// <param name="node"></param>
private void OnClickOnlyFileNode(SuperTreeViewNode node)
{
this.ShowOnlyFilePanel();
OnlyFile obj;
if(node.Tag == null)
{
//从数据库中创建对象,并装入Tag属性中
obj = this.OnlyFileReader.GetObjectByPathStr(node.FullPath);
if(obj == null)//有可能为空,因为XML配置文件中的节点属性可以改变
{
obj = new OnlyFile();
obj.OnlyFileID = this.OnlyFileReader.GetNextID();
obj.BelongTo = node.FullPath;
obj.InputDate = DateTime.Today;
this.OnlyFileReader.SaveMeToDB(obj);
}
node.Tag = obj;
}
else
{
obj = node.Tag as OnlyFile;
}
//显示相关信息
this.OnlyFileForm.OnlyFileObject = obj;
}
#endregion
#region 完成树节点的前进与后退功能
/// <summary>
/// 将一个树节点加入
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -