//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        //public void DrawMiddleJackPanel(Entity PostEntity, System.Data.DataTable AllData)
        //{

        //    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
        //    bool conti = true;
        //    //Dictionary<Guid, List<Entity>> MyCells = new Dictionary<Guid, List<Entity>>();
        //    double MyScale = Atend.Base.Design.DProductProperties.AccessSelectBySoftwareCode((int)Atend.Control.Enum.ProductType.MiddleJackPanel).Scale;

        //    DrawMiddleJackPanelJig MidJ = new DrawMiddleJackPanelJig(PostContainerEntity, MyScale);
        //    MidJ.MiddleJackPanelProductCode = ProductCode;
        //    MidJ.MiddleJaclPanelParentCode = ParentCode;
        //    MidJ.Cells = JackpanelCells;
        //    PromptResult pr;
        //    while (conti)
        //    {
        //        pr = ed.Drag(MidJ);
        //        if (pr.Status == PromptStatus.OK)
        //        {
        //            conti = false;
        //            #region save data here
        //            ObjectIdCollection OIC = new ObjectIdCollection();
        //            List<Guid> CellsGuid = new List<Guid>();

        //            List<Entity> Entities = new List<Entity>();
        //            Entities = MidJ.GetEntities();
        //            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        //            #region Seprate different cells from each other
        //            foreach (Entity ent in Entities)
        //            {
        //                Atend.Global.Acad.AcadJigs.MyPolyLine poly = ent as Atend.Global.Acad.AcadJigs.MyPolyLine;
        //                object CellCode = null;
        //                if (poly != null)
        //                {
        //                    if (poly.AdditionalDictionary.ContainsKey("Code"))
        //                    {
        //                        poly.AdditionalDictionary.TryGetValue("Code", out CellCode);
        //                    }
        //                }
        //                else
        //                {
        //                    Atend.Global.Acad.AcadJigs.MyLine lin = ent as Atend.Global.Acad.AcadJigs.MyLine;
        //                    if (lin != null)
        //                    {
        //                        if (lin.AdditionalDictionary.ContainsKey("Code"))
        //                        {
        //                            lin.AdditionalDictionary.TryGetValue("Code", out CellCode);
        //                        }
        //                    }
        //                    else
        //                    {
        //                        Atend.Global.Acad.AcadJigs.MyCircle cir = ent as Atend.Global.Acad.AcadJigs.MyCircle;
        //                        if (cir != null)
        //                        {
        //                            if (cir.AdditionalDictionary.ContainsKey("Code"))
        //                            {
        //                                cir.AdditionalDictionary.TryGetValue("Code", out CellCode);
        //                            }
        //                        }
        //                    }
        //                }
        //                if (CellCode != null)
        //                {
        //                    if (!MyCells.ContainsKey(new Guid(CellCode.ToString())))
        //                    {
        //                        MyCells.Add(new Guid(CellCode.ToString()), new List<Entity>());
        //                        CellsGuid.Add(new Guid(CellCode.ToString()));
        //                        List<Entity> Entities1;
        //                        MyCells.TryGetValue(new Guid(CellCode.ToString()), out Entities1);
        //                        Entities1.Add(ent);

        //                    }
        //                    else
        //                    {
        //                        List<Entity> Entities1;
        //                        MyCells.TryGetValue(new Guid(CellCode.ToString()), out Entities1);
        //                        Entities1.Add(ent);
        //                    }

        //                }

        //            }
        //            #endregion

        //            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //            ObjectIdCollection BusOIs = new ObjectIdCollection();
        //            foreach (Guid _ExistGuid in MyCells.Keys)
        //            {

        //                try
        //                {
        //                    #region Draw different cells
        //                    List<Entity> MyList = null;
        //                    MyCells.TryGetValue(_ExistGuid, out MyList);
        //                    if (MyList != null)
        //                    {
        //                        ObjectIdCollection CurrentCellEntities = new ObjectIdCollection();
        //                        ObjectId CurrentCellObjectId = ObjectId.Null;
        //                        foreach (Entity ent in MyList)
        //                        {
        //                            object MyProductType = null;
        //                            object MYProductCode = null;
        //                            object myCodeGuid = null;
        //                            Atend.Global.Acad.AcadJigs.MyPolyLine poly = ent as Atend.Global.Acad.AcadJigs.MyPolyLine;
        //                            if (poly != null)
        //                            {
        //                                if (poly.AdditionalDictionary.ContainsKey("Code"))
        //                                {
        //                                    poly.AdditionalDictionary.TryGetValue("Code", out myCodeGuid);
        //                                }
        //                                if (poly.AdditionalDictionary.ContainsKey("ProductType"))
        //                                {
        //                                    poly.AdditionalDictionary.TryGetValue("ProductType", out MyProductType);
        //                                }
        //                                if (poly.AdditionalDictionary.ContainsKey("ProductCode"))
        //                                {
        //                                    poly.AdditionalDictionary.TryGetValue("ProductCode", out MYProductCode);
        //                                }


        //                            }
        //                            else
        //                            {
        //                                Atend.Global.Acad.AcadJigs.MyLine lin = ent as Atend.Global.Acad.AcadJigs.MyLine;
        //                                if (lin != null)
        //                                {
        //                                    if (lin.AdditionalDictionary.ContainsKey("Code"))
        //                                    {
        //                                        lin.AdditionalDictionary.TryGetValue("Code", out myCodeGuid);
        //                                    }
        //                                    if (lin.AdditionalDictionary.ContainsKey("ProductType"))
        //                                    {
        //                                        lin.AdditionalDictionary.TryGetValue("ProductType", out MyProductType);
        //                                    }
        //                                    if (lin.AdditionalDictionary.ContainsKey("ProductCode"))
        //                                    {
        //                                        lin.AdditionalDictionary.TryGetValue("ProductCode", out MYProductCode);
        //                                    }

        //                                }
        //                                else
        //                                {
        //                                    Atend.Global.Acad.AcadJigs.MyCircle cir = ent as Atend.Global.Acad.AcadJigs.MyCircle;
        //                                    if (cir != null)
        //                                    {
        //                                        if (cir.AdditionalDictionary.ContainsKey("Code"))
        //                                        {
        //                                            cir.AdditionalDictionary.TryGetValue("Code", out myCodeGuid);
        //                                        }
        //                                        if (cir.AdditionalDictionary.ContainsKey("ProductType"))
        //                                        {
        //                                            cir.AdditionalDictionary.TryGetValue("ProductType", out MyProductType);
        //                                        }
        //                                        if (cir.AdditionalDictionary.ContainsKey("ProductCode"))
        //                                        {
        //                                            cir.AdditionalDictionary.TryGetValue("ProductCode", out MYProductCode);
        //                                        }

        //                                    }
        //                                }
        //                            }

        //                            //------------------------
        //                            ObjectId NewCellEntities = Atend.Global.Acad.UAcad.DrawEntityOnScreen(ent, Atend.Control.Enum.AutoCadLayerName.MED_GROUND.ToString());
        //                            OIC.Add(NewCellEntities);
        //                            if (MyProductType != null)
        //                            {
        //                                if (Convert.ToInt32(MyProductType) == (int)Atend.Control.Enum.ProductType.Cell)
        //                                {
        //                                    CurrentCellObjectId = NewCellEntities;
        //                                }
        //                                else
        //                                {
        //                                    CurrentCellEntities.Add(NewCellEntities);
        //                                }
        //                            }
        //                            Atend.Base.Acad.AT_INFO CellSubInfo = new Atend.Base.Acad.AT_INFO(NewCellEntities);
        //                            if (myCodeGuid != null)
        //                            {
        //                                CellSubInfo.ParentCode = NodeCode.ToString();
        //                                CellSubInfo.NodeCode = myCodeGuid.ToString();
        //                            }
        //                            else
        //                            {
        //                                CellSubInfo.ParentCode = myCodeGuid.ToString();
        //                                CellSubInfo.NodeCode = "";
        //                            }

        //                            if (MYProductCode != null)
        //                            {
        //                                CellSubInfo.ProductCode = Convert.ToInt32(MYProductCode);
        //                            }
        //                            else
        //                            {
        //                                CellSubInfo.ProductCode = 0;
        //                            }

        //                            if (MyProductType != null)
        //                            {
        //                                CellSubInfo.NodeType = Convert.ToInt32(MyProductType);
        //                                if (Convert.ToInt32(MyProductType) == (int)Atend.Control.Enum.ProductType.Bus)
        //                                {
        //                                    CellSubInfo.ProductCode = Atend.Base.Equipment.EJAckPanel.AccessSelectByCode(ProductCode).MasterProductCode;
        //                                    BusOIs.Add(NewCellEntities);
        //                                    //ed.WriteMessage("Bus OI : {0}\n", NewCellEntities);
        //                                }
        //                            }
        //                            else
        //                            {
        //                                CellSubInfo.NodeType = 0;
        //                            }
        //                            CellSubInfo.Insert();


        //                        }

        //                        if (CurrentCellObjectId != null && CurrentCellEntities.Count != 0)
        //                        {
        //                            foreach (ObjectId oi in CurrentCellEntities)
        //                            {
        //                                Atend.Base.Acad.AT_SUB.AddToAT_SUB(oi, CurrentCellObjectId);
        //                            }
        //                        }
        //                    }
        //                    #endregion
        //                }
        //                catch (System.Exception ex)
        //                {
        //                    ed.WriteMessage("Error while drawing: {0} \n", ex.Message);
        //                    return;
        //                }
        //            }
        //            //ed.WriteMessage("Bus Count : {0} \n", BusOIs.Count);

        //            #region Join Buses to each other
        //            foreach (Guid _ExistGuid in MyCells.Keys)
        //            {
        //                try
        //                {

        //                }
        //                catch (System.Exception ex)
        //                {
        //                    ed.WriteMessage("Error while Connect bus to each other: {0} \n", ex.Message);
        //                    return;
        //                }
        //            }
        //            #endregion

        //            //if (BusOIs.Count > 0)
        //            //{
        //            //    for (int BC = 0; BC < BusOIs.Count - 1; BC++)
        //            //    {

        //            //        Atend.Global.Acad.DrawEquips.AcDrawTerminal _AcDrawTerminal = new AcDrawTerminal();
        //            //        _AcDrawTerminal.DrawTerminal(Atend.Global.Acad.UAcad.CenterOfEntity(Atend.Global.Acad.UAcad.GetEntityByObjectID(BusOIs[BC])), Atend.Global.Acad.UAcad.CenterOfEntity(Atend.Global.Acad.UAcad.GetEntityByObjectID(BusOIs[BC])));


        //            //        //Atend.Base.Acad.AT_INFO BusInfo=new Atend.Base.Acad.AT_INFO(



        //            //    }
        //            //}
        //            #region Group all cells of Middlejack panel

        //            if (NodeCode != Guid.Empty)
        //            {
        //                //ed.WriteMessage("Group all cells of Middlejack panel\n");
        //                ObjectId GroupOI = Atend.Global.Acad.Global.MakeGroup(NodeCode.ToString() + "-MJP", OIC);

        //                Atend.Base.Acad.AT_INFO MiddleGroupInfo = new Atend.Base.Acad.AT_INFO(GroupOI);
        //                MiddleGroupInfo.ParentCode = ParentCode.ToString();
        //                MiddleGroupInfo.NodeCode = NodeCode.ToString();
        //                MiddleGroupInfo.NodeType = (int)Atend.Control.Enum.ProductType.MiddleJackPanel;
        //                MiddleGroupInfo.ProductCode = ProductCode;
        //                MiddleGroupInfo.Insert();

        //                Atend.Base.Acad.AT_SUB.AddToAT_SUB(GroupOI, PostContainerEntity.ObjectId);
        //                Atend.Base.Acad.AT_SUB.AddToAT_SUB(PostContainerEntity.ObjectId, GroupOI);

        //            }
        //            #endregion

        //            #endregion
        //        }
        //        else
        //        {
        //            conti = false;
        //        }
        //    }
        //}


        public void DrawMiddleJackPanel(Entity PostContainerEntity, ref DataRow[] PostEquipInserted)
        {
            Editor ed          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            bool   conti       = true;
            Guid   NodeCode    = new Guid(PostEquipInserted[0]["NodeCode"].ToString());
            Guid   ParentCode  = new Guid(PostEquipInserted[0]["ParentCode"].ToString());
            int    ProductCode = Convert.ToInt32(PostEquipInserted[0]["ProductCode"]);

            Dictionary <Guid, List <Entity> > MyCells = new Dictionary <Guid, List <Entity> >();
            double MyScale = Atend.Base.Design.DProductProperties.AccessSelectBySoftwareCode((int)Atend.Control.Enum.ProductType.MiddleJackPanel).Scale;

            DrawMiddleJackPanelJig MidJ = new DrawMiddleJackPanelJig(PostContainerEntity, MyScale);

            MidJ.MiddleJackPanelProductCode = ProductCode;
            MidJ.MiddleJaclPanelParentCode  = ParentCode;
            MidJ.Cells = JackpanelCells;
            PromptResult pr;

            //ed.WriteMessage("------ START MJ {0} -------\n",NodeCode);
            while (conti)
            {
                pr = ed.Drag(MidJ);
                if (pr.Status == PromptStatus.OK)
                {
                    conti = false;
                    #region save data here
                    ObjectIdCollection OIC       = new ObjectIdCollection();
                    List <Guid>        CellsGuid = new List <Guid>();

                    List <Entity> Entities = new List <Entity>();
                    Entities = MidJ.GetEntities();
                    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                    #region Seprate different cells from each other
                    //ed.WriteMessage("Seprate different cells from each other\n");
                    foreach (Entity ent in Entities)
                    {
                        Atend.Global.Acad.AcadJigs.MyPolyLine poly = ent as Atend.Global.Acad.AcadJigs.MyPolyLine;
                        object CellCode = null;
                        if (poly != null)
                        {
                            //ed.WriteMessage("~~~Poly~~~:{0}\n", poly.AdditionalDictionary.ContainsKey("ProductCode"));
                            if (poly.AdditionalDictionary.ContainsKey("Code"))
                            {
                                poly.AdditionalDictionary.TryGetValue("Code", out CellCode);
                            }
                        }
                        else
                        {
                            Atend.Global.Acad.AcadJigs.MyLine lin = ent as Atend.Global.Acad.AcadJigs.MyLine;
                            if (lin != null)
                            {
                                if (lin.AdditionalDictionary.ContainsKey("Code"))
                                {
                                    lin.AdditionalDictionary.TryGetValue("Code", out CellCode);
                                }
                            }
                            else
                            {
                                Atend.Global.Acad.AcadJigs.MyCircle cir = ent as Atend.Global.Acad.AcadJigs.MyCircle;
                                if (cir != null)
                                {
                                    if (cir.AdditionalDictionary.ContainsKey("Code"))
                                    {
                                        cir.AdditionalDictionary.TryGetValue("Code", out CellCode);
                                    }
                                }
                            }
                        }
                        if (CellCode != null)
                        {
                            //ed.WriteMessage("Cellcode:{0}\n", CellCode);
                            if (!MyCells.ContainsKey(new Guid(CellCode.ToString())))
                            {
                                //ed.WriteMessage("\nCell Cuid Code:{0}\n", CellCode.ToString());
                                MyCells.Add(new Guid(CellCode.ToString()), new List <Entity>());
                                CellsGuid.Add(new Guid(CellCode.ToString()));

                                List <Entity> Entities1;
                                MyCells.TryGetValue(new Guid(CellCode.ToString()), out Entities1);
                                Entities1.Add(ent);
                            }
                            else
                            {
                                List <Entity> Entities1;
                                MyCells.TryGetValue(new Guid(CellCode.ToString()), out Entities1);
                                Entities1.Add(ent);
                            }
                        }
                    }
                    #endregion

                    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    foreach (Guid _ExistGuid in MyCells.Keys)
                    {
                        try
                        {
                            #region Draw different cells
                            //if (MyCells.ContainsKey(_ExistGuid))
                            //{
                            //ed.WriteMessage("Cell count : {0} \n", MyCells.Count);
                            List <Entity> MyList = null;
                            MyCells.TryGetValue(_ExistGuid, out MyList);
                            if (MyList != null)
                            {
                                //ed.WriteMessage("~~~~~ Entities found ~~~~~\n");
                                ObjectIdCollection CurrentCellEntities = new ObjectIdCollection();
                                ObjectId           CurrentCellObjectId = ObjectId.Null;
                                foreach (Entity ent in MyList)
                                {
                                    //-----------------------


                                    object MyProductType = null;
                                    object MYProductCode = null;
                                    object myCodeGuid    = null;
                                    Atend.Global.Acad.AcadJigs.MyPolyLine poly = ent as Atend.Global.Acad.AcadJigs.MyPolyLine;
                                    if (poly != null)
                                    {
                                        //ed.WriteMessage("~~~POLY~~~{0}\n", poly.AdditionalDictionary.ContainsKey("ProductCode"));
                                        if (poly.AdditionalDictionary.ContainsKey("Code"))
                                        {
                                            poly.AdditionalDictionary.TryGetValue("Code", out myCodeGuid);
                                        }
                                        if (poly.AdditionalDictionary.ContainsKey("ProductType"))
                                        {
                                            poly.AdditionalDictionary.TryGetValue("ProductType", out MyProductType);
                                        }
                                        if (poly.AdditionalDictionary.ContainsKey("ProductCode"))
                                        {
                                            poly.AdditionalDictionary.TryGetValue("ProductCode", out MYProductCode);
                                        }
                                    }
                                    else
                                    {
                                        Atend.Global.Acad.AcadJigs.MyLine lin = ent as Atend.Global.Acad.AcadJigs.MyLine;
                                        if (lin != null)
                                        {
                                            if (lin.AdditionalDictionary.ContainsKey("Code"))
                                            {
                                                lin.AdditionalDictionary.TryGetValue("Code", out myCodeGuid);
                                            }
                                            if (lin.AdditionalDictionary.ContainsKey("ProductType"))
                                            {
                                                lin.AdditionalDictionary.TryGetValue("ProductType", out MyProductType);
                                            }
                                            if (lin.AdditionalDictionary.ContainsKey("ProductCode"))
                                            {
                                                lin.AdditionalDictionary.TryGetValue("ProductCode", out MYProductCode);
                                            }
                                        }
                                        else
                                        {
                                            Atend.Global.Acad.AcadJigs.MyCircle cir = ent as Atend.Global.Acad.AcadJigs.MyCircle;
                                            if (cir != null)
                                            {
                                                if (cir.AdditionalDictionary.ContainsKey("Code"))
                                                {
                                                    cir.AdditionalDictionary.TryGetValue("Code", out myCodeGuid);
                                                }
                                                if (cir.AdditionalDictionary.ContainsKey("ProductType"))
                                                {
                                                    cir.AdditionalDictionary.TryGetValue("ProductType", out MyProductType);
                                                }
                                                if (cir.AdditionalDictionary.ContainsKey("ProductCode"))
                                                {
                                                    cir.AdditionalDictionary.TryGetValue("ProductCode", out MYProductCode);
                                                }
                                            }
                                        }
                                    }

                                    //------------------------
                                    //ed.WriteMessage("Entity Type:{0}\n", ProductType);
                                    ObjectId NewCellEntities = Atend.Global.Acad.UAcad.DrawEntityOnScreen(ent, Atend.Control.Enum.AutoCadLayerName.MED_GROUND.ToString());
                                    OIC.Add(NewCellEntities);
                                    //                                    CurrentCellEntities.Add(NewCellEntities);
                                    if (MyProductType != null)
                                    {
                                        if (Convert.ToInt32(MyProductType) == (int)Atend.Control.Enum.ProductType.Cell)
                                        {
                                            CurrentCellObjectId = NewCellEntities;
                                            //ed.WriteMessage("CurrentCellObjectId was found\n");
                                        }
                                        else
                                        {
                                            CurrentCellEntities.Add(NewCellEntities);
                                        }
                                    }
                                    //ed.WriteMessage("NodeCode : {0}\n", NodeCode);

                                    Atend.Base.Acad.AT_INFO CellSubInfo = new Atend.Base.Acad.AT_INFO(NewCellEntities);
                                    if (myCodeGuid != null)
                                    {
                                        //ed.WriteMessage("cell entity was found\n");
                                        CellSubInfo.ParentCode = NodeCode.ToString(); //CurrentMiddleJackPanelCodeGuid.ToString();
                                        CellSubInfo.NodeCode   = myCodeGuid.ToString();
                                    }
                                    else
                                    {
                                        CellSubInfo.ParentCode = myCodeGuid.ToString();
                                        CellSubInfo.NodeCode   = "";
                                    }
                                    //ed.WriteMessage("2\n");

                                    if (MYProductCode != null)
                                    {
                                        CellSubInfo.ProductCode = Convert.ToInt32(MYProductCode);
                                    }
                                    else
                                    {
                                        CellSubInfo.ProductCode = 0;
                                    }
                                    //ed.WriteMessage("3\n");

                                    if (MyProductType != null)
                                    {
                                        CellSubInfo.NodeType = Convert.ToInt32(MyProductType);
                                    }
                                    else
                                    {
                                        CellSubInfo.NodeType = 0;
                                    }
                                    //ed.WriteMessage("4\n");

                                    CellSubInfo.Insert();
                                }

                                //insert cell sub
                                //ed.WriteMessage("%%% CurrentCellObjectId %%% {0} : {1} \n", CurrentCellObjectId, CurrentCellEntities.Count);
                                if (CurrentCellObjectId != null && CurrentCellEntities.Count != 0)
                                {
                                    //ed.WriteMessage("5:1\n");
                                    //Atend.Base.Acad.AT_SUB cellsub = new Atend.Base.Acad.AT_SUB(CurrentCellObjectId);
                                    foreach (ObjectId oi in CurrentCellEntities)
                                    {
                                        //cellsub.SubIdCollection.Add(oi);
                                        Atend.Base.Acad.AT_SUB.AddToAT_SUB(oi, CurrentCellObjectId);
                                    }
                                    //cellsub.Insert();
                                    //ed.WriteMessage("5:2\n");
                                }
                            }
                            //}
                            // ed.WriteMessage("One Pack Was drawn \n");
                            //}
                            #endregion
                        }
                        catch (System.Exception ex)
                        {
                            ed.WriteMessage("Error while drawing: {0} \n", ex.Message);
                            return;
                        }
                    }

                    #region Group all cells of Middlejack panel

                    if (NodeCode != null)
                    {
                        //ed.WriteMessage("Group all cells of Middlejack panel\n");
                        ObjectId GroupOI = Atend.Global.Acad.Global.MakeGroup(NodeCode.ToString() + "-MJP", OIC);

                        Atend.Base.Acad.AT_INFO MiddleGroupInfo = new Atend.Base.Acad.AT_INFO(GroupOI);
                        MiddleGroupInfo.ParentCode  = ParentCode.ToString();
                        MiddleGroupInfo.NodeCode    = NodeCode.ToString();
                        MiddleGroupInfo.NodeType    = (int)Atend.Control.Enum.ProductType.MiddleJackPanel;
                        MiddleGroupInfo.ProductCode = ProductCode;
                        MiddleGroupInfo.Insert();


                        Atend.Base.Acad.AT_SUB.AddToAT_SUB(GroupOI, PostContainerEntity.ObjectId);
                    }
                    #endregion

                    #endregion
                }
                else
                {
                    conti = false;
                }
            }
        }