⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.cs

📁 个人信息的源代码
💻 CS
📖 第 1 页 / 共 5 页
字号:
		}
		/// <summary>
		/// 显示PicLib面板
		/// </summary>
		private void ShowPicLibPanel()
		{
			if(this.PicLibForm.pnlPicLib.Visible == false)
			{
				this.DetailForm.pnlDetailText.Visible = false;
				this.OnlyFileForm.pnlOnlyFile.Visible = false;
				this.FolderForm.pnlFolder.Visible = false;
				this.PicLibForm.pnlPicLib.Visible = true;
			}
		}

		#endregion

		#region 树操作区

		#region 删除节点

		/// <summary>
		/// 删除节点,包括其子树都被递归处理
		/// </summary>
		/// <param name="node"></param>
		private void DeleteNode(SuperTreeViewNode node)
		{
			if(node == null)
				return;

			try
			{
				//删除数据库记录
				DetailReader.DeleteDBRow(node.FullPath);
				OnlyFileReader.DeleteDBRow(node.FullPath);
				FolderReader.DeleteDBRow(node.FullPath);
				PicLibReader.DeleteDBRow(node.FullPath);
				//删除树中的节点
				this.superTreeView1.DeleteSelectedNode();
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
		/// <summary>
		/// 删除整棵树
		/// </summary>
		private void DeleteRootNode()
		{
			if(this.DetailReader == null)
				throw new Exception("DetailReader cann't be null");

			try
			{
				//清空所有表
				this.DetailReader.dbObj.ClearTable("DetailText");
				this.DetailReader.dbObj.ClearTable("Files");
				this.DetailReader.dbObj.ClearTable("Folder");
				this.DetailReader.dbObj.ClearTable("FolderFile");
				this.DetailReader.dbObj.ClearTable("OnlyFile");
				this.DetailReader.dbObj.ClearTable("PicLib");
				this.DetailReader.dbObj.ClearTable("PicLibFile");
				//清空树
				this.superTreeView1.Nodes.Clear();
			}
			catch(Exception ex)
			{
				MessageBox.Show("在清空数据库表时出错,系统给出的信息为:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}

		#endregion

		/// <summary>
		/// 展开选中节点的所有子树
		/// </summary>
		private void ExpandAllSubTree()
		{
			if(this.superTreeView1.SelectedNode == null)
				return;
			else
				this.superTreeView1.SelectedNode.ExpandAll();
		}
		/// <summary>
		/// 结束编辑时的处理
		/// </summary>
		/// <param name="e"></param>
		private void OnEndEdit(NodeLabelEditEventArgs e)
		{
			SuperTreeViewNode node = e.Node as SuperTreeViewNode;
			if(e.Label != null && e.Label.IndexOf("'") != -1)
			{
				MessageBox.Show("不能在树节点中使用半角的单引号。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
				e.CancelEdit = true;
				return;
			}
			if(e.Label != null && (e.Label.IndexOf("[") != -1 || e.Label.IndexOf("]") != -1))
			{
				MessageBox.Show("不能在树节点中使用中括号。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
				e.CancelEdit = true;
				return;
			}
			if(e.Label == null)
			{
				//以下条件所发生的情况
				//当改名时,发现重名,然后让其重改,但用户直接回车,未改,而e.Label为null
				//为保证数据一致,只能让其再改,不改好就不让走!
				if(this.IsTextExistInBrotherNodes(e.Node as SuperTreeViewNode, e.Node.Text))
				{
					MessageBox.Show("已存在同级的此名的节点,请重新换一个名字。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
					node.EndEdit(true);
					node.BeginEdit();
					return;
				}
				this.superTreeView1.LabelEdit = false;
				return;
			}
			else
			{
				//用户改了些文本
				if(this.IsTextExistInBrotherNodes(e.Node as SuperTreeViewNode, e.Label))
				{
					MessageBox.Show("已存在同级的此名的节点,请重新换一个名字。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
					node.EndEdit(true);
					node.BeginEdit();
					return;
				}
				else
				{
					node.EndEdit(false);
				}
			}

			switch(this.curOperationStatus)
			{
				case TreeOperationStatus.AddNode ://新加节点状态
					this.superTreeView1.LabelEdit = false;
					break;
				case TreeOperationStatus.RenameNode ://改名状态
					try
					{
						string oldPath, newPath;
						oldPath = node.FullPath;
						if(e.Label == node.Text)
						{//如果用户没有改过文本
							this.superTreeView1.LabelEdit = false;
							return;
						}
						else
						{
							newPath = oldPath.Substring(0, oldPath.Length - (node.Text + "\\").Length) + e.Label + "\\";
						}

						if(sysArgu.Debug)
						{
							MyTrace.WriteLine("", false);
							MyTrace.WriteLine("节点改名:", true);

							MyTrace.WriteLine("oldPath:" + oldPath, false);
							MyTrace.WriteLine("NewPath:" + newPath, false);
						}

						//更新记录
						try
						{
							this.DetailReader.RenameNodePath(oldPath, newPath);
						}
						catch(Exception ex)
						{
							MessageBox.Show("在更新数据库DetailText表中的BelongTo字段时出错,系统给出的信息为:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
						}

						try
						{
							this.OnlyFileReader.RenameNodePath(oldPath, newPath);
						}
						catch(Exception ex)
						{
							MessageBox.Show("在更新数据库OnlyFile表中的BelongTo字段时出错,系统给出的信息为:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
						}

						try
						{
							this.FolderReader.RenameNodePath(oldPath, newPath);
						}
						catch(Exception ex)
						{
							MessageBox.Show("在更新数据库Folder表中的BelongTo字段时出错,系统给出的信息为:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
						}

						try
						{
							this.PicLibReader.RenameNodePath(oldPath, newPath);
						}
						catch(Exception ex)
						{
							MessageBox.Show("在更新数据库PicLib表中的BelongTo字段时出错,系统给出的信息为:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
						}
						//更新当前面板中处理对象的路径信息
						switch(node.NodeType)
						{
							case "DetailText" :
								this.DetailForm.DetailTextObject.BelongTo = newPath;
								break;
							case "OnlyFile" :
								this.OnlyFileForm.OnlyFileObject.BelongTo = newPath;
								break;
							case "Folder" :
								this.FolderForm.FolderObject.BelongTo = newPath;
								break;
							case "PicLib" :
								this.PicLibForm.PicLibObject.BelongTo = newPath;
								break;
						}
					}
					catch(Exception ex)
					{
						MessageBox.Show(ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
					}
					finally
					{
						this.curOperationStatus = TreeOperationStatus.None;
						this.superTreeView1.LabelEdit = false;
					}
					break;
			}
		}
		/// <summary>
		/// 增加节点时的处理
		/// </summary>
		/// <param name="AddType"></param>
		/// <param name="NodeType"></param>
		/// <param name="NodeText"></param>
		private void OnAddNode(AddNodeType AddType, string NodeType, string NodeText)
		{
			SuperTreeViewNode tmpNode = null;
			//创建第一个根节点时例外处理
			if(this.superTreeView1.SelectedNode == null && AddType != AddNodeType.AddFirstLevel)
			{
				return;
			}

			if(AddType != AddNodeType.AddFirstLevel && this.superTreeView1.SelectedNode.IsEditing == true)
			{
				this.superTreeView1.SelectedNode.EndEdit(false);
			}
			
			//增加节点,并进入编辑状态
			switch(AddType)
			{
				case AddNodeType.AddFirstLevel :
					if(this.superTreeView1.GetNodeCount(false) == 0)
					{
						tmpNode = this.superTreeView1.AddFirstLevelNode(NodeText + SuperTreeViewNode.NodeCount.ToString());
					}
					else
					{
						MessageBox.Show("只能有一个根节点。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
						return;
					}
					break;
				case AddNodeType.AddChild :
					tmpNode = this.superTreeView1.AddSelectedNodeChild(NodeText + SuperTreeViewNode.NodeCount.ToString());
					break;
				case AddNodeType.AddBrother :
					if(this.superTreeView1.SelectedNode.Parent == null)
					{
						MessageBox.Show("只能有一个根节点,不能给根节点添加兄弟。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
						return;
					}
					tmpNode = this.superTreeView1.AddSelectedNodeBrother(NodeText + SuperTreeViewNode.NodeCount.ToString());
					break;
			}

			tmpNode.NodeType = NodeType;
			//设置图标
			switch(tmpNode.NodeType)
			{
				case "OnlyText" :
					tmpNode.ImageIndex = 2;
					tmpNode.SelectedImageIndex = 3;
					break;
				case "DetailText" :
					tmpNode.ImageIndex = 4;
					tmpNode.SelectedImageIndex = 5;
					break;
				case "OnlyFile" :
					tmpNode.ImageIndex = 6;
					tmpNode.SelectedImageIndex = 7;
					break;
				case "Folder" :
					tmpNode.ImageIndex = 8;
					tmpNode.SelectedImageIndex = 9;
					break;
				case "PicLib" :
					tmpNode.ImageIndex = 11;
					tmpNode.SelectedImageIndex = 10;
					break;
			}
			this.superTreeView1.SelectedNode = tmpNode;

			if(this.sysArgu.Debug)
			{
				MyTrace.WriteLine("", false);

				MyTrace.WriteLine("AddNode:" + tmpNode.NodeType, true);
				MyTrace.WriteLine("Text:" + tmpNode.Text, false);
			}

			//隐藏所有的面板
			this.HideAllPanel();

			switch(tmpNode.NodeType)
			{
				case "OnlyText" :
					break;
				case "DetailText" :
					//创建DetailText对象,将其存入数据库,并放到树的Tag节点中,然后,显示相应的面板
					this.DoWithNewDetailTextNode(tmpNode);
					break;
				case "Folder" :
					//创建Folder对象,将其存入数据库,并放到树的Tag节点中,然后,显示相应的面板
					this.DoWithNewFolderNode(tmpNode);
					break;
				case "OnlyFile" :
					//创建OnlyFile对象,将其存入数据库,并放到树的Tag节点中,然后,显示相应的面板
					this.DoWithNewOnlyFileNode(tmpNode);
					break;
				case "PicLib" :
					//创建PicLib对象,将其存入数据库,并放到树的Tag节点中,然后,显示相应的面板
					this.DoWithNewPicLibNode(tmpNode);
					break;
			}

			//加入到历史列表中
			this.AddTreeNodeToHistory(this.superTreeView1.SelectedNode as SuperTreeViewNode);

			//进入改名状态
			this.OnRenameNode();
		}

		#region 处理新加节点

		/// <summary>
		/// 创建DetailText对象,将其存入数据库,并放到树的Tag节点中,然后,显示相应的面板
		/// </summary>
		/// <param name="newNode"></param>
		private void DoWithNewDetailTextNode(SuperTreeViewNode newNode)
		{
			DetailText obj = new DetailText();
			obj.DetailTextID = DetailReader.GetNextID();
			obj.BelongTo = newNode.FullPath;
			obj.InputDate = DateTime.Today;

			//存入数据库中
			this.DetailReader.SaveMeToDB(obj);

			//将此对象放入树节点的Tag属性中
			newNode.Tag = obj;

			//将对象传给窗体
			DetailForm.DetailTextObject = obj;
			//显示面板
			this.ShowDetailTextPanel();
		}
		/// <summary>
		/// 创建OnlyFile对象,将其存入数据库,并放到树的Tag节点中,然后,显示相应的面板
		/// </summary>
		/// <param name="newNode"></param>
		private void DoWithNewOnlyFileNode(SuperTreeViewNode newNode)
		{
			OnlyFile obj = new OnlyFile();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -