/// <summary>
        /// Links the specified tree view to this tree view.  Whenever either treeview
        /// scrolls, the other will scroll too.
        /// </summary>
        /// <param name="treeView">The TreeView to link.</param>
        public void AddLinkedTreeView(MyTreeView treeView)
        {
            if (treeView == this)
            {
                throw new ArgumentException("Cannot link a TreeView to itself!", "treeView");
            }

            if (!linkedTreeViews.Contains(treeView))
            {
                //add the treeview to our list of linked treeviews
                linkedTreeViews.Add(treeView);
                //add this to the treeview's list of linked treeviews
                treeView.AddLinkedTreeView(this);

                //make sure the TreeView is linked to all of the other TreeViews that this TreeView is linked to
                for (int i = 0; i < linkedTreeViews.Count; i++)
                {
                    //get the linked treeview
                    var linkedTreeView = linkedTreeViews[i];
                    //link the treeviews together
                    if (linkedTreeView != treeView)
                    {
                        linkedTreeView.AddLinkedTreeView(treeView);
                    }
                }
            }
        }
        /// <summary>
        /// Sets the destination's scroll positions to that of the source.
        /// </summary>
        /// <param name="source">The source of the scroll positions.</param>
        /// <param name="dest">The destinations to set the scroll positions for.</param>
        private void SetScrollPositions(MyTreeView source, MyTreeView dest)
        {
            //get the scroll positions of the source
            int horizontal = User32.GetScrollPos(source.Handle, Orientation.Horizontal);
            int vertical   = User32.GetScrollPos(source.Handle, Orientation.Vertical);

            //set the scroll positions of the destination
            User32.SetScrollPos(dest.Handle, Orientation.Horizontal, horizontal, true);
            User32.SetScrollPos(dest.Handle, Orientation.Vertical, vertical, true);
        }
        private void compareTreeViewStrings(MyTreeView newTreeView, string newText, MyTreeView oldTreeView, string oldText)
        {
            ISideBySideDiffBuilder diffBuilder     = new SideBySideDiffBuilder(new Differ());
            SideBySideDiffModel    sideBySideModel = diffBuilder.BuildDiffModel(oldText, newText);

            newTreeView.Nodes.Clear();
            oldTreeView.Nodes.Clear();

            TreeNode newParentNode = newTreeView.Nodes.Add(sideBySideModel.NewText.Lines[0].Text);
            TreeNode oldParentNode = oldTreeView.Nodes.Add(sideBySideModel.OldText.Lines[0].Text);

            colorTreeView(newParentNode.FullPath, newParentNode, sideBySideModel.NewText.Lines, sideBySideModel.OldText.Lines, 1, true);
            colorTreeView(oldParentNode.FullPath, oldParentNode, sideBySideModel.OldText.Lines, sideBySideModel.NewText.Lines, 1, false);

            newTreeView.AddLinkedTreeView(oldTreeView);
        }
        private void buildRecordTreeNodes(commonClient commonClient, MyTreeView treeView, TreeNode parentNode, netsuiteRecord[] records)
        {
            for (int i = 0; i < records.Length; i++)
            {
                netsuiteRecord record = records[i];

                TreeNode recordNode              = commonClient.addNode(parentNode, record.recordName);
                TreeNode recordInternalIdNode    = commonClient.addNode(commonClient.addNode(recordNode, "internalId"), record.internalId);
                TreeNode recordRecordIdNode      = commonClient.addNode(commonClient.addNode(recordNode, "recordId"), record.recordId);
                TreeNode recordRecordsFieldsNode = commonClient.addNode(recordNode, "recordFields");

                string[] recordFields = records[i].recordFields;
                Array.Sort(recordFields);

                for (int j = 0; j < recordFields.Length; j++)
                {
                    commonClient.addNode(recordRecordsFieldsNode, recordFields[j]);
                }
            }
        }
        private void buildRecordTree(MyTreeView treeView, netsuiteRecord[] entityRecords, netsuiteRecord[] itemRecords, netsuiteRecord[] customRecords)
        {
            commonClient commonClient = new commonClient();

            treeView.Nodes.Clear();

            TreeNode recordsNode = treeView.Nodes.Add("records");

            TreeNode entityRecordsNode = commonClient.addNode(recordsNode, "entityRecords");

            buildRecordTreeNodes(commonClient, treeView, entityRecordsNode, entityRecords);

            TreeNode itemRecordsNode = commonClient.addNode(recordsNode, "itemRecords");

            buildRecordTreeNodes(commonClient, treeView, itemRecordsNode, itemRecords);

            TreeNode customRecordsNode = commonClient.addNode(recordsNode, "customRecords");

            buildRecordTreeNodes(commonClient, treeView, customRecordsNode, customRecords);
        }
        private void buildScriptTree(MyTreeView treeView, netsuiteCustomScript[] customScripts)
        {
            commonClient commonClient = new commonClient();

            treeView.Nodes.Clear();

            TreeNode customScriptsNode = treeView.Nodes.Add("customScripts");

            for (int i = 0; i < customScripts.Length; i++)
            {
                netsuiteCustomScript customScript = customScripts[i];

                TreeNode customScriptNode = commonClient.addNode(customScriptsNode, customScript.scriptName);
                commonClient.addNode(commonClient.addNode(customScriptNode, "internalId"), customScript.internalId);
                commonClient.addNode(commonClient.addNode(customScriptNode, "scriptId"), customScript.scriptId);
                commonClient.addNode(commonClient.addNode(customScriptNode, "scriptType"), customScript.scriptType);
                commonClient.addNode(commonClient.addNode(customScriptNode, "scriptAPIVersion"), customScript.scriptAPIVersion);

                TreeNode customScriptScriptFunctionsNode = commonClient.addNode(customScriptNode, "scriptFunctions");

                netsuiteCustomScriptFunction[] customScriptFunctions = customScript.scriptFunctions.ToArray();

                Array.Sort(customScriptFunctions, delegate(netsuiteCustomScriptFunction scriptFunction1, netsuiteCustomScriptFunction scriptFunction2)
                {
                    return(scriptFunction1.functionType.CompareTo(scriptFunction2.functionType));
                });

                for (int j = 0; j < customScriptFunctions.Length; j++)
                {
                    TreeNode customScriptScriptFunctionsFunctionTypeNode = commonClient.addNode(customScriptScriptFunctionsNode, customScriptFunctions[j].functionType);
                    commonClient.addNode(customScriptScriptFunctionsFunctionTypeNode, customScriptFunctions[j].function);
                }

                TreeNode customScriptScriptFileNode = commonClient.addNode(customScriptNode, "scriptFile");
                commonClient.addNode(commonClient.addNode(customScriptScriptFileNode, "internalId"), customScript.scriptFile.internalId);
                commonClient.addNode(commonClient.addNode(customScriptScriptFileNode, "name"), customScript.scriptFile.name);
                commonClient.addNode(commonClient.addNode(customScriptScriptFileNode, "folder"), customScript.scriptFile.folderId);
                commonClient.addNode(commonClient.addNode(customScriptScriptFileNode, "type"), customScript.scriptFile.fileType);
                commonClient.addNode(commonClient.addNode(customScriptScriptFileNode, "size"), customScript.scriptFile.size);
                commonClient.addNode(commonClient.addNode(customScriptScriptFileNode, "content"), customScript.scriptFile.content);

                TreeNode customScriptScriptLibrariesNode = commonClient.addNode(customScriptNode, "scriptLibraries");

                netsuiteFile[] customScriptLibraries = customScript.scriptLibraries.ToArray();

                Array.Sort(customScriptLibraries, delegate(netsuiteFile scriptLibrary1, netsuiteFile scriptLibrary2)
                {
                    return(scriptLibrary1.name.CompareTo(scriptLibrary2.name));
                });

                for (int j = 0; j < customScriptLibraries.Length; j++)
                {
                    TreeNode customScriptLibrariesScriptLibraryNode = commonClient.addNode(customScriptScriptLibrariesNode, customScriptLibraries[j].name);
                    commonClient.addNode(commonClient.addNode(customScriptLibrariesScriptLibraryNode, "internalId"), customScriptLibraries[j].internalId);
                    commonClient.addNode(commonClient.addNode(customScriptLibrariesScriptLibraryNode, "folder"), customScriptLibraries[j].folderId);
                    commonClient.addNode(commonClient.addNode(customScriptLibrariesScriptLibraryNode, "type"), customScriptLibraries[j].fileType);
                    commonClient.addNode(commonClient.addNode(customScriptLibrariesScriptLibraryNode, "size"), customScriptLibraries[j].size);
                    commonClient.addNode(commonClient.addNode(customScriptLibrariesScriptLibraryNode, "content"), customScriptLibraries[j].content);
                }

                TreeNode customScriptScriptDeploymentsNode = commonClient.addNode(customScriptNode, "scriptDeployments");

                netsuiteCustomScriptDeployment[] customScriptDeployments = customScript.scriptDeployments.ToArray();

                Array.Sort(customScriptDeployments, delegate(netsuiteCustomScriptDeployment scriptDeployment1, netsuiteCustomScriptDeployment scriptDeployment2)
                {
                    return(scriptDeployment1.scriptDeploymentId.CompareTo(scriptDeployment2.scriptDeploymentId));
                });

                for (int j = 0; j < customScriptDeployments.Length; j++)
                {
                    TreeNode customScriptScriptDeploymentsScriptDeploymentNode = commonClient.addNode(customScriptScriptDeploymentsNode, customScriptDeployments[j].scriptDeploymentId);
                    commonClient.addNode(commonClient.addNode(customScriptScriptDeploymentsScriptDeploymentNode, "internalId"), customScriptDeployments[j].internalId);
                    commonClient.addNode(commonClient.addNode(customScriptScriptDeploymentsScriptDeploymentNode, "isDeployed"), customScriptDeployments[j].isDeployed);
                    commonClient.addNode(commonClient.addNode(customScriptScriptDeploymentsScriptDeploymentNode, "recordType"), customScriptDeployments[j].recordType);
                    commonClient.addNode(commonClient.addNode(customScriptScriptDeploymentsScriptDeploymentNode, "status"), customScriptDeployments[j].status);
                }
            }
        }