public void addNodes(DataSets.dsModuleStructure3.dtStepCompositeRow row, TreeNode parentNode)
        {
            TreeNode treeNode = new StepCompositeNode(row);

            DataSets.dsModuleStructure3.dtModuleRow module = getSelectedModuleRow();

            if (row.dtModuleRow.fk_module_type == module.fk_module_type)
            {
                if (parentNode == null)
                {
                    tlvSteps.Nodes.Add(treeNode);
                }
                else
                {
                    parentNode.Nodes.Add(treeNode);
                }

                foreach (DataSets.dsModuleStructure3.dtStepCompositeRow childRows in row.GetdtStepCompositeRows())
                {
                    addNodes(childRows, treeNode);
                }

                foreach (DataSets.dsModuleStructure3.dtStepLeafRow stepLeafRow in row.GetdtStepLeafRows())
                {
                    TreeNode stepLeafNode = new StepLeafNode(stepLeafRow, _dsModuleStructure.dtActionValue);
                    treeNode.Nodes.Add(stepLeafNode);
                }
            }
        }
        public void SaveTree(TreeNode treeNode)
        {
            //using (Stream file = File.Open(filename, FileMode.Create))
            //{
            //    BinaryFormatter bf = new BinaryFormatter();
            //    bf.Serialize(file, tree.Nodes.Cast<TreeNode>().ToList());
            //}


            if (treeNode is TreeNode && !(treeNode is StepCompositeNode))
            {
                foreach (TreeNode childNodes in treeNode.Nodes)
                {
                    SaveTree(childNodes);
                }
            }

            if (treeNode is StepCompositeNode)
            {
                StepCompositeNode stepCompositeNode = treeNode as StepCompositeNode;

                DataSets.dsModuleStructure3.dtStepCompositeRow stepComposite = stepCompositeNode.getStepCompositeRow();

                DataSets.dsModuleStructure3.dtSavedProtocolRow row;
                //DataSets.dsModuleStructure3.dtSavedProtocolRow test;
                //row = dsModuleStructureGUI.dtSavedProtocol.NewdtSavedProtocolRow();
                row                   = dsModuleStructure.dtSavedProtocol.NewdtSavedProtocolRow();
                row.description       = stepCompositeNode.Parent.Text;
                row.fk_step_composite = stepComposite.pk_id;
                dsModuleStructure.dtSavedProtocol.AdddtSavedProtocolRow(row);
                updateRow(row);
            }
        }
        private void tlvProtocol_DragDrop(object sender, DragEventArgs e)
        {
            // Retrieve the client coordinates of the drop location.
            Point targetPoint = tlvProtocol.PointToClient(new Point(e.X, e.Y));

            // Retrieve the node at the drop location.
            TreeNode          targetNode            = tlvProtocol.GetNodeAt(targetPoint);
            TreeNode          dropNode              = new TreeNode();
            StepCompositeNode treeNodeStepComposite = (StepCompositeNode)e.Data.GetData(typeof(StepCompositeNode));
            StepLeafNode      treeNodeStepLeaf      = (StepLeafNode)e.Data.GetData(typeof(StepLeafNode));

            if (treeNodeStepComposite != null)
            {
                addNodes(treeNodeStepComposite.getStepCompositeRow(), targetNode);
            }
            else if (treeNodeStepLeaf != null)
            {
                targetNode.Nodes.Add(new StepLeafNode(treeNodeStepLeaf.getStepLeaf(), dsModuleStructure.dtActionValue));
            }
        }
        public void addNodes(DataSets.dsModuleStructure3.dtStepCompositeRow row, TreeNode parentNode)
        {
            TreeNode treeNode = new StepCompositeNode(row);

            if (parentNode == null)
            {
                tlvProtocol.Nodes.Add(treeNode);
            }
            else
            {
                parentNode.Nodes.Add(treeNode);
            }

            foreach (DataSets.dsModuleStructure3.dtStepCompositeRow childRows in row.GetdtStepCompositeRows())
            {
                addNodes(childRows, treeNode);
            }

            foreach (DataSets.dsModuleStructure3.dtStepLeafRow stepLeafRow in row.GetdtStepLeafRows())
            {
                TreeNode stepLeafNode = new StepLeafNode(stepLeafRow, dsModuleStructure.dtActionValue);
                treeNode.Nodes.Add(stepLeafNode);
            }
        }
        private void AutoFillToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String protocolType = ((ToolStripMenuItem)sender).Text;
            //dialog result for adding new node to treeview
            DialogResult   dialogResultAddNode = DialogResult.Cancel;
            frmNewProtocol frmProtocolAdd;
            frmNewStep     _frmNewStep;
            TreeNode       treeNode = new TreeNode();


            switch (protocolType)
            {
            case PROTOCOL_TYPE:

                frmProtocolAdd = new frmNewProtocol();

                dialogResultAddNode = frmProtocolAdd.ShowDialog();
                if (dialogResultAddNode == DialogResult.OK)
                {
                    //treeNodeText = frmProtocolAdd.getStepName();
                    DataSets.dsModuleStructure3.dtStepCompositeRow compositeRow = _dsModuleStructure.dtStepComposite.NewdtStepCompositeRow();
                    DataSets.dsModuleStructure3.dtModuleRow        module       = getSelectedModuleRow();
                    if (module == null)
                    {
                        return;
                    }

                    if (module.pk_id.Length == 0)
                    {
                        return;
                    }

                    compositeRow.fk_module_id = module.pk_id;
                    compositeRow.description  = frmProtocolAdd.getStepName();

                    if (tlvSteps.SelectedNode != null)
                    {
                        if (tlvSteps.SelectedNode is StepCompositeNode)
                        {
                            StepCompositeNode stepCompositeNode = tlvSteps.SelectedNode as StepCompositeNode;
                            compositeRow.fk_step_parent_id = stepCompositeNode.getStepCompositeRow().pk_id;
                        }
                    }

                    _dsModuleStructure.dtStepComposite.AdddtStepCompositeRow(compositeRow);

                    updateRow(compositeRow);

                    treeNode = new Steps.Parameter_controls.StepCompositeNode(compositeRow);
                }

                break;

            case STEP_TYPE:

                DataSets.dsModuleStructure3.dtModuleRow        moduleRow = getSelectedModuleRow();
                DataSets.dsModuleStructure3.dtStepCompositeRow c         = _dsModuleStructure.dtStepComposite.NewdtStepCompositeRow();


                if (moduleRow == null)
                {
                    break;
                }

                c.fk_module_id = moduleRow.pk_id;
                //c.fk

                String headerTitle = moduleRow.pk_id.ToString();

                _frmNewStep = new frmNewStep(_dsModuleStructure, moduleRow);

                dialogResultAddNode = _frmNewStep.ShowDialog();
                if (dialogResultAddNode.Equals(DialogResult.OK))
                {
                    if (tlvSteps.SelectedNode is StepCompositeNode)
                    {
                        StepCompositeNode stepCompositeNode = tlvSteps.SelectedNode as StepCompositeNode;
                        DataSets.dsModuleStructure3.dtStepLeafRow stepLeafRow = _dsModuleStructure.dtStepLeaf.NewdtStepLeafRow();
                        stepLeafRow.fk_step_composite = stepCompositeNode.getStepCompositeRow().pk_id;
                        stepLeafRow.description       = _frmNewStep.getStepDescription();

                        _dsModuleStructure.dtStepLeaf.AdddtStepLeafRow(stepLeafRow);

                        updateRow(stepLeafRow);

                        treeNode = new StepLeafNode(stepLeafRow, _dsModuleStructure.dtActionValue);

                        Dictionary <dsModuleStructure3.dtModuleTypeActionTypeRow, ctrlCommand> command = _frmNewStep.getActionValues();
                        foreach (KeyValuePair <dsModuleStructure3.dtModuleTypeActionTypeRow, ctrlCommand> kvp in command)
                        {
                            Dictionary <dsModuleStructure3.dtActionTypeRow, namedInputTextBox> actionTypeInputBoxDict = kvp.Value.getActionTypesValues();

                            foreach (KeyValuePair <dsModuleStructure3.dtActionTypeRow, namedInputTextBox> kvpActionType in actionTypeInputBoxDict)
                            {
                                if (kvpActionType.Value.getInputTextValue().Length != 0)
                                {
                                    DataSets.dsModuleStructure3.dtActionValueRow actionValue = _dsModuleStructure.dtActionValue.NewdtActionValueRow();
                                    actionValue.fk_action_type       = kvpActionType.Key.pk_id;
                                    actionValue.fk_action_value_type = kvp.Key.dtActionValueTypeRow.pk_id;
                                    actionValue.fk_step_leaf_id      = stepLeafRow.pk_id;
                                    actionValue.description          = kvpActionType.Value.getInputTextValue();
                                    _dsModuleStructure.dtActionValue.AdddtActionValueRow(actionValue);
                                    updateRow(actionValue);
                                }
                            }
                        }
                    }
                }

                break;

            default:
                break;
            }

            if (dialogResultAddNode.Equals(DialogResult.OK))
            {
                if (tlvSteps.SelectedNode != null)
                {
                    tlvSteps.SelectedNode.Nodes.Add(treeNode);
                }
                else
                {
                    tlvSteps.Nodes.Add(treeNode);
                }
            }
        }