Exemple #1
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            Editor ed            = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Guid   StartPoleCode = Guid.Empty;

            Autodesk.AutoCAD.DatabaseServices.ObjectId _BranchOi = Autodesk.AutoCAD.DatabaseServices.ObjectId.Null;
            int _vol = 0;

            //gClamp.Visible = false;
            //gConsol.Visible = false;
            BranchesData.Clear();

            this.Hide();

            PromptSelectionOptions pso = new PromptSelectionOptions();

            pso.MessageForAdding = "Select Branches Please";

            //PromptEntityOptions PEO = new PromptEntityOptions(": \n");
            //PromptEntityResult PER = ed.GetEntity(PEO);
            PromptSelectionResult PSR = ed.GetSelection(pso);

            SelectdEntities.Clear();
            if (PSR.Status == PromptStatus.OK)
            {
                SelectionSet ss = PSR.Value;
                ////////if (ss.Count > 0)
                ////////{
                ////////    Atend.Base.Acad.AT_INFO SelectedBranchInfo = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(ss[0].ObjectId);
                ////////    if (SelectedBranchInfo.NodeType == (int)Atend.Control.Enum.ProductType.Conductor)
                ////////    {
                ////////        IsConductor = true;
                ////////    }
                ////////    else
                ////////    {
                ////////        IsConductor = false;
                ////////    }
                ////////}
                //MessageBox.Show("NUmber of selected entity : " + ss.Count.ToString());
                foreach (SelectedObject so in ss)
                {
                    ConsolsOIs.Clear();
                    ClampsOIs.Clear();
                    Atend.Base.Acad.AT_INFO BranchInfo = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(so.ObjectId);
                    if (BranchInfo.NodeType == (int)Atend.Control.Enum.ProductType.Conductor)
                    {
                        //MessageBox.Show("it was conductor");
                        //gConsol.Visible = true;
                        Atend.Base.Acad.AT_SUB BranchSub = Atend.Base.Acad.AT_SUB.SelectBySelectedObjectId(so.ObjectId);
                        foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId oi in BranchSub.SubIdCollection)
                        {
                            Atend.Base.Acad.AT_INFO ConsolInfo = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(oi);
                            if (ConsolInfo.NodeType == (int)Atend.Control.Enum.ProductType.Consol)
                            {
                                Atend.Base.Equipment.EConsol ConsolData = Atend.Base.Equipment.EConsol.AccessSelectByCode(ConsolInfo.ProductCode);
                                if (ConsolData.ConsolType == 0 || ConsolData.ConsolType == 1)
                                {
                                    ConsolsOIs.Add(oi);
                                    Autodesk.AutoCAD.DatabaseServices.Line BranchEntity = Atend.Global.Acad.UAcad.GetEntityByObjectID(so.ObjectId) as Autodesk.AutoCAD.DatabaseServices.Line;
                                    if (BranchEntity != null)
                                    {
                                        if (Atend.Global.Acad.UAcad.CenterOfEntity(Atend.Global.Acad.UAcad.GetEntityByObjectID(oi)) == BranchEntity.StartPoint)
                                        {
                                            StartPoleCode = new Guid(ConsolInfo.ParentCode);
                                            _BranchOi     = so.ObjectId;
                                            _vol          = ConsolData.VoltageLevel;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (BranchInfo.NodeType == (int)Atend.Control.Enum.ProductType.SelfKeeper)
                    {
                        //MessageBox.Show("it was self keeper");
                        //gClamp.Visible = true;
                        Atend.Base.Acad.AT_SUB BranchSub = Atend.Base.Acad.AT_SUB.SelectBySelectedObjectId(so.ObjectId);
                        foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId oi in BranchSub.SubIdCollection)
                        {
                            Atend.Base.Acad.AT_INFO ClampInfo = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(oi);
                            if (ClampInfo.NodeType == (int)Atend.Control.Enum.ProductType.Kalamp)
                            {
                                Atend.Base.Equipment.EClamp ClampData = Atend.Base.Equipment.EClamp.AccessSelectByCode(ClampInfo.ProductCode);
                                if (ClampData.Type != 5)
                                {
                                    ClampsOIs.Add(oi);
                                    Autodesk.AutoCAD.DatabaseServices.Line BranchEntity = Atend.Global.Acad.UAcad.GetEntityByObjectID(so.ObjectId) as Autodesk.AutoCAD.DatabaseServices.Line;
                                    if (BranchEntity != null)
                                    {
                                        if (Atend.Global.Acad.UAcad.CenterOfEntity(Atend.Global.Acad.UAcad.GetEntityByObjectID(oi)) == BranchEntity.StartPoint)
                                        {
                                            StartPoleCode = new Guid(ClampInfo.ParentCode);
                                            _BranchOi     = so.ObjectId;
                                            _vol          = ClampData.VoltageLevel;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (ConsolsOIs.Count == 2 || ClampsOIs.Count == 2)
                    {
                        //if (IsConductor)
                        //{
                        //    if (BranchInfo.NodeType == (int)Atend.Control.Enum.ProductType.Conductor)
                        //    {
                        SelectdEntities.Add(Atend.Global.Acad.UAcad.GetEntityByObjectID(so.ObjectId));


                        DataRow NewDataRow = BranchesData.NewRow();
                        NewDataRow["BranchCode"] = BranchInfo.NodeCode;
                        NewDataRow["BranchType"] = Convert.ToInt32(BranchInfo.NodeType);
                        NewDataRow["BranchOI"]   = _BranchOi.ToString().Substring(1, _BranchOi.ToString().Length - 2);
                        //NewDataRow["IsSelected"] = true;
                        NewDataRow["Type"]     = (Convert.ToInt32(BranchInfo.NodeType) == (int)Atend.Control.Enum.ProductType.Conductor ? "سیم" : "کابل خودنگهدار");
                        NewDataRow["Voltage"]  = _vol;
                        NewDataRow["PoleCode"] = StartPoleCode;
                        BranchesData.Rows.Add(NewDataRow);

                        //int NewRowIndex = gvBranches.Rows.Add();
                        //gvBranches.Rows[NewRowIndex].Cells["BranchCode"].Value = BranchInfo.ProductCode;
                        //gvBranches.Rows[NewRowIndex].Cells["BranchType"].Value = Convert.ToInt32(BranchInfo.NodeType);
                        //gvBranches.Rows[NewRowIndex].Cells["BranchOI"].Value = _BranchOi.ToString().Substring(1, _BranchOi.ToString().Length - 2);
                        //gvBranches.Rows[NewRowIndex].Cells["IsSelected"].Value = true;
                        //gvBranches.Rows[NewRowIndex].Cells["Type"].Value = (Convert.ToInt32(BranchInfo.NodeType) == (int)Atend.Control.Enum.ProductType.Conductor ? "سیم" : "کابل خودنگهدار");
                        //gvBranches.Rows[NewRowIndex].Cells["Voltage"].Value = _vol;


                        //    }
                        //    gConsol.Visible = true;
                        //    gClamp.Visible = false;
                        //}
                        //else
                        //{
                        //    if (BranchInfo.NodeType == (int)Atend.Control.Enum.ProductType.SelfKeeper)
                        //    {
                        //        SelectdEntities.Add(Atend.Global.Acad.UAcad.GetEntityByObjectID(so.ObjectId));
                        //    }
                        //    gConsol.Visible = false;
                        //    gClamp.Visible = true;
                        //}
                    }
                } //end for
            }     // end if (PSR.Status == PromptStatus.OK)
            this.Show();
            DataView dv = new DataView(BranchesData);

            dv.RowFilter          = "BranchType=" + (cboBranchType.SelectedIndex == 0 ? (int)Atend.Control.Enum.ProductType.Conductor : (int)Atend.Control.Enum.ProductType.SelfKeeper);
            gvBranches.DataSource = dv;
            //MessageBox.Show("count:" + SelectdEntities.Count.ToString());
        }