/// <summary> /// 递归解密全部密码 /// </summary> /// <param name="dataManager"></param> /// <param name="parentNode"></param> private void DecryptPassword(RDSDataManager dataManager, RDSDataNode parentNode) { if (parentNode.Nodes == null && parentNode.Nodes.Count <= 0) { return; } // 恢复密码为明文 foreach (RDSDataNode node in parentNode.Nodes) { if (node.NodeType == RDSDataNodeType.Server) { var server = (RDSServer)node.RDSData; server.Password = EncryptUtils.DecryptServerPassword(server); dataManager.AddServer(server); } else { DecryptPassword(dataManager, node); } } }
private void button1_Click(object sender, EventArgs e) { Model.ServerID = Model.ServerID == Guid.Empty ? Guid.NewGuid() : Model.ServerID; Model.ServerName = txtServerName.Text.Trim(); Model.ServerAddress = txtServerAddress.Text.Trim(); Model.UserName = txtUserName.Text.Trim(); Model.Password = txtPassword.Text.Trim(); Model.OpType = rbtnWindows.Checked ? rbtnWindows.Text : rbtnLinux.Text; Model.LinkType = rbtnRD.Checked ? rbtnRD.Text : rbtnSSH.Text; int serverPort = 0; if (!int.TryParse(txtServerPort.Text.Trim(), out serverPort)) { MessageBox.Show("端口号应该是一个数字!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Model.ServerPort = serverPort; if (string.IsNullOrWhiteSpace(Model.ServerName) || string.IsNullOrWhiteSpace(Model.ServerAddress) || string.IsNullOrWhiteSpace(Model.UserName) || string.IsNullOrWhiteSpace(Model.Password) || string.IsNullOrWhiteSpace(Model.OpType) || string.IsNullOrWhiteSpace(Model.LinkType)) { MessageBox.Show("请首先填写所有项目!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } RDSDataManager dataManager = new RDSDataManager(); Model.Password = EncryptUtils.EncryptServerPassword(Model); dataManager.AddServer(Model); this.DialogResult = DialogResult.OK; }
/// <summary> /// 拖动释放 /// 参考:http://www.cnblogs.com/jiewei915/archive/2012/01/11/2318951.html /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void serverTree_DragDrop(object sender, DragEventArgs e) { // 得到拖放中的节点 var moveDataNode = (RDSDataNode)e.Data.GetData("RDManager.Model.RDSDataNode"); // 根据鼠标坐标确定要移动到的目标节点 TreeNode targetNode = new TreeNode(); Point pt = ((TreeView)(sender)).PointToClient(new Point(e.X, e.Y)); targetNode = this.serverTree.GetNodeAt(pt); var targetDataNode = (RDSDataNode)targetNode; // 如果目标为自己,返回 if (targetDataNode.Text == moveDataNode.Text) { return; } // 如果目标包含在自己的节点树中,返回 if (moveDataNode.Nodes.Contains(targetDataNode)) { return; } else if (targetDataNode.FullPath.Contains(moveDataNode.FullPath)) { return; } // 如果目标节点是Server,返回 if (targetDataNode.NodeType == RDSDataNodeType.Server) { return; } // 如果目标为子节点,返回 if (targetDataNode.Parent == moveDataNode) { return; } // 如果目标为父节点,返回 if (targetDataNode == moveDataNode.Parent) { return; } // 移除拖放的节点 RemoveServerTreeNode(moveDataNode, false); // 添加节点 var newMoveNode = (RDSDataNode)moveDataNode.Clone(); newMoveNode.RDSData = moveDataNode.RDSData; newMoveNode.NodeType = moveDataNode.NodeType; // 保存节点 if (newMoveNode.NodeType == RDSDataNodeType.Group) { var group = (RDSGroup)newMoveNode.RDSData; group.ParentGroupID = (Guid)targetDataNode.Tag; RDSDataManager dataManager = new RDSDataManager(); dataManager.AddGroup(group); } else { var server = (RDSServer)newMoveNode.RDSData; server.GroupID = (Guid)targetDataNode.Tag; RDSDataManager dataManager = new RDSDataManager(); dataManager.AddServer(server); } // 将节点插入到分组中 targetDataNode.Nodes.Insert(targetDataNode.Nodes.Count, newMoveNode); // 更新当前拖动的节点选择 serverTree.SelectedNode = newMoveNode; // 展开当前节点的父节点 targetDataNode.Expand(); }