private void AddChildren(TreeNode ParentNode, ArrayList UnitNodes)
        {
            while (true)
            {
                UnitHierarchyNode Child = FindNodeWithThisParent(((UnitHierarchyNode)ParentNode.Tag).MyUnitKey, UnitNodes);

                if (Child == null)
                {
                    ParentNode.Expand();
                    return;
                }

                // Add the node to the specifed parent:
                TreeNode ChildNode = new TreeNode(Child.Description);
                ChildNode.Tag         = Child;
                ChildNode.ToolTipText = Child.TypeCode;

                InsertAlphabetically(ParentNode, ChildNode);
                ChildNode.Expand();

                // Remove this node from UnitNodes:
                UnitNodes.Remove(Child);
                // Add any children of this node:
                AddChildren(ChildNode, UnitNodes);
            }
        }
        private void RunOnceOnActivationManual()
        {
            // AlanP March 2013:  Use a try/catch block because nUnit testing on this screen does not support Drag/Drop in multi-threaded model
            // It is easier to do this than to configure all the different test execution methods to use STA
            try
            {
                trvUnits.AllowDrop = true;
                trvUnits.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(treeView_ItemDrag);
                trvUnits.DragOver += new System.Windows.Forms.DragEventHandler(treeView_DragOver);
                trvUnits.DragDrop += new System.Windows.Forms.DragEventHandler(treeView_DragDrop);
            }
            catch (InvalidOperationException)
            {
                // ex.Message is: DragDrop registration did not succeed.
                // Inner exception is: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.
            }

            trvUnits.Click           += new EventHandler(UnitsClick);
            trvUnits.ShowNodeToolTips = true;
            trvUnits.MouseWheel      += new MouseEventHandler(treeView_MouseWheel);
            trvUnits.Focus();

            txtChild.TextChanged  += new EventHandler(EvaluateParentChange);
            txtParent.TextChanged += new EventHandler(EvaluateParentChange);

            FPetraUtilsObject.UnhookControl(pnlDetails, true); // I don't want changes in these values to cause SetChangedFlag.
            FPetraUtilsObject.UnhookControl(txtStatus, false);

            ArrayList UnitNodes = TRemote.MPersonnel.WebConnectors.GetUnitHeirarchy();
            //
            // The list of nodes returned by the above call are ordered to the extent that:
            //  * The root node appears first,
            //  * a parent appears before its child.
            UnitHierarchyNode RootData = (UnitHierarchyNode)UnitNodes[0];
            TreeNode          RootNode = new TreeNode(RootData.Description);

            RootNode.Tag         = RootData;
            RootNode.ToolTipText = RootData.TypeCode;
            UnitNodes.RemoveAt(0);
            trvUnits.Nodes.Add(RootNode);
            AddChildren(RootNode, UnitNodes);
            Int64 MySiteKey = Convert.ToInt64(TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_SITEKEY, ""));

            ShowThisUnit(MySiteKey);
        }
Example #3
0
        public static ArrayList GetUnitHeirarchy()
        {
            const Int64 THE_ORGANISATION = 1000000;

            ArrayList Ret = new ArrayList();

            try
            {
                TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

                PUnitTable     UnitTbl     = PUnitAccess.LoadAll(Transaction);
                UUnitTypeTable UnitTypeTbl = UUnitTypeAccess.LoadAll(Transaction);
                UnitTypeTbl.DefaultView.Sort = UUnitTypeTable.GetUnitTypeCodeDBName();

                UmUnitStructureTable HierarchyTbl = UmUnitStructureAccess.LoadAll(Transaction);
                HierarchyTbl.DefaultView.Sort = UmUnitStructureTable.GetChildUnitKeyDBName();

                UnitTbl.DefaultView.Sort = PUnitTable.GetPartnerKeyDBName();
                UnitHierarchyNode RootNode = new UnitHierarchyNode();

                RootNode.MyUnitKey     = THE_ORGANISATION;
                RootNode.ParentUnitKey = THE_ORGANISATION;
                RootNode.Description   = "The Organisation";
                RootNode.TypeCode      = "Root";

                Int32 RootUnitIdx = UnitTbl.DefaultView.Find(THE_ORGANISATION);

                if (RootUnitIdx >= 0)
                {
                    RootNode.Description = ((PUnitRow)UnitTbl.DefaultView[RootUnitIdx].Row).UnitName;
                    UnitTbl.DefaultView.Delete(RootUnitIdx);
                }

                Ret.Add(RootNode);

                foreach (DataRowView rv in UnitTbl.DefaultView)
                {
                    PUnitRow          UnitRow = (PUnitRow)rv.Row;
                    UnitHierarchyNode Node    = new UnitHierarchyNode();
                    Node.Description = UnitRow.UnitName + " " + UnitRow.Description;

                    if (Node.Description == "")
                    {
                        Node.Description = "[" + UnitRow.PartnerKey.ToString("D10") + "]";
                    }

                    Node.MyUnitKey = UnitRow.PartnerKey;

                    //
                    // Retrieve parent..
                    Int32 HierarchyTblIdx = HierarchyTbl.DefaultView.Find(Node.MyUnitKey);

                    if (HierarchyTblIdx >= 0)
                    {
                        Node.ParentUnitKey = ((UmUnitStructureRow)HierarchyTbl.DefaultView[HierarchyTblIdx].Row).ParentUnitKey;
                    }
                    else
                    {
                        Node.ParentUnitKey = THE_ORGANISATION;
                    }

                    //
                    // Retrieve TypeCode..
                    Int32 TypeTblIndex = UnitTypeTbl.DefaultView.Find(UnitRow.UnitTypeCode);

                    if (TypeTblIndex >= 0)
                    {
                        Node.TypeCode = ((UUnitTypeRow)UnitTypeTbl.DefaultView[TypeTblIndex].Row).UnitTypeName;
                    }
                    else
                    {
                        Node.TypeCode = "Type: " + UnitRow.UnitTypeCode;
                    }

                    Ret.Add(Node);
                }
            }
            finally
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }
            return(Ret);
        }
Example #4
0
        public static ArrayList GetUnitHeirarchy()
        {
            const Int64 THE_ORGANISATION = 1000000;

            ArrayList Ret = new ArrayList();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction,
                                                           delegate
            {
                PPartnerTable PartnerTbl         = PPartnerAccess.LoadViaPPartnerClasses("UNIT", Transaction);
                PartnerTbl.DefaultView.RowFilter = "p_status_code_c <> 'MERGED'";
                PartnerTbl.DefaultView.Sort      = PPartnerTable.GetPartnerKeyDBName();

                PUnitTable UnitTbl           = PUnitAccess.LoadAll(Transaction);
                UUnitTypeTable UnitTypeTbl   = UUnitTypeAccess.LoadAll(Transaction);
                UnitTypeTbl.DefaultView.Sort = UUnitTypeTable.GetUnitTypeCodeDBName();

                UmUnitStructureTable HierarchyTbl = UmUnitStructureAccess.LoadAll(Transaction);
                HierarchyTbl.DefaultView.Sort     = UmUnitStructureTable.GetChildUnitKeyDBName();

                UnitTbl.DefaultView.Sort         = PUnitTable.GetPartnerKeyDBName();
                UnitHierarchyNode RootNode       = new UnitHierarchyNode();
                UnitHierarchyNode UnassignedNode = new UnitHierarchyNode();

                RootNode.MyUnitKey     = THE_ORGANISATION;
                RootNode.ParentUnitKey = THE_ORGANISATION;
                RootNode.Description   = "The Organisation";
                RootNode.TypeCode      = "Root";

                Int32 RootUnitIdx = UnitTbl.DefaultView.Find(THE_ORGANISATION);

                if (RootUnitIdx >= 0)
                {
                    RootNode.Description = ((PUnitRow)UnitTbl.DefaultView[RootUnitIdx].Row).UnitName;
                    UnitTbl.DefaultView.Delete(RootUnitIdx);
                }

                Ret.Add(RootNode);

                UnassignedNode.MyUnitKey     = 0;
                UnassignedNode.ParentUnitKey = 0;
                UnassignedNode.Description   = Catalog.GetString("Unassigned Units");
                Ret.Add(UnassignedNode);

                foreach (DataRowView rv in UnitTbl.DefaultView)
                {
                    PUnitRow UnitRow = (PUnitRow)rv.Row;

                    if (PartnerTbl.DefaultView.Find(UnitRow.PartnerKey) < 0)
                    {
                        // skip all merged units
                        continue;
                    }

                    UnitHierarchyNode Node = new UnitHierarchyNode();
                    Node.Description       = UnitRow.UnitName + " " + UnitRow.Description;

                    if (Node.Description == "")
                    {
                        Node.Description = "[" + UnitRow.PartnerKey.ToString("D10") + "]";
                    }

                    Node.MyUnitKey = UnitRow.PartnerKey;

                    //
                    // Retrieve parent..
                    Int32 HierarchyTblIdx = HierarchyTbl.DefaultView.Find(Node.MyUnitKey);

                    if (HierarchyTblIdx >= 0)
                    {
                        Node.ParentUnitKey = ((UmUnitStructureRow)HierarchyTbl.DefaultView[HierarchyTblIdx].Row).ParentUnitKey;
                    }
                    else
                    {
                        Node.ParentUnitKey = UnassignedNode.MyUnitKey;
                    }

                    //
                    // Retrieve TypeCode..
                    Int32 TypeTblIndex = UnitTypeTbl.DefaultView.Find(UnitRow.UnitTypeCode);

                    if (TypeTblIndex >= 0)
                    {
                        Node.TypeCode = ((UUnitTypeRow)UnitTypeTbl.DefaultView[TypeTblIndex].Row).UnitTypeName;
                    }
                    else
                    {
                        Node.TypeCode = "Type: " + UnitRow.UnitTypeCode;
                    }

                    Ret.Add(Node);
                }
            });

            return(Ret);
        }