Exemplo n.º 1
0
        //internal IDbConnection Connection
        //{
        //    get
        //    {
        //        return new NpgsqlConnection(connectionString);
        //    }
        //}

        public void Add(PartFamily item)
        {
            //using (IDbConnection dbConnection = Connection)
            //{
            //    dbConnection.Open();
            //    dbConnection.Execute("INSERT INTO customer (name,phone,email,address) VALUES(@Name,@Phone,@Email,@Address)", item);
            //}

            try
            {
                _context.PartFamily.Add(new PartFamily()
                {
                    PartFamilyID   = item.PartFamilyID,
                    PartFamilyName = item.PartFamilyName,
                    Description    = item.Description,
                    IsDeleted      = item.IsDeleted
                });
                _context.SaveChanges();

                var added = _context.PartFamily.FirstOrDefault(x => x.PartFamilyID == item.PartFamilyID);
                //  return new JsonResult(string.Format("Inserted part family: ID : {0} ;  Name: {1}", added.PartFamilyID, added.PartFamilyName));
            }
            catch (Exception ex)
            {
                //return new JsonResult(string.Format("Error: {0}\r\n {1}", ex.Message, ex.InnerException));
            }
        }
Exemplo n.º 2
0
        private Dictionary <ObjectId, SelectedPartTypeId> GetBlockStructureMapping()
        {
            blocksStructureMappingCompleteInput = true;
            Dictionary <ObjectId, SelectedPartTypeId> mapping
                = new Dictionary <ObjectId, SelectedPartTypeId>();

            foreach (BlockStructureMappingPairModel bsModel in BlocksStructuresMappingColl)
            {
                BlockTableRecord btr = bsModel.BlockVM.SelectedBlock;
                PartFamily       pf  = bsModel.StructureVM.SelectedPartFamily?.PartFamily;
                PartSize         ps  = bsModel.StructureVM.SelectedPartSize;

                if (btr != null && pf != null && ps != null) //проверка, что ввод в строку полный
                {
                    if (!mapping.ContainsKey(btr.Id))        //блоки могут повторяться!!!
                    {
                        mapping.Add(btr.Id, new SelectedPartTypeId(pf.Id, ps.Id));
                    }
                }
                else
                {
                    blocksStructureMappingCompleteInput = false;
                    //ввод неполный, то считать ввод не выполнен вообще
                    mapping.Clear();
                    break;
                }
            }
            return(mapping);
        }
Exemplo n.º 3
0
 public PartFamilyForm(PartFamily family)
 {
     InitializeComponent();
     m_family = family;
     Bind();
     WireEvents();
 }
Exemplo n.º 4
0
        private HashSet <ObjectId> GetSelectedBlocks()
        {
            blocksCompleteInput = true;
            HashSet <ObjectId> blocks = new HashSet <ObjectId>();

            foreach (BlockStructureMappingPairModel bsModel in BlocksStructuresMappingColl)
            {
                BlockTableRecord btr = bsModel.BlockVM.SelectedBlock;
                PartFamily       pf  = bsModel.StructureVM.SelectedPartFamily?.PartFamily;
                PartSize         ps  = bsModel.StructureVM.SelectedPartSize;

                if (btr != null)                  //проверка, что блок введен в строку
                {
                    if (!blocks.Contains(btr.Id)) //блоки могут повторяться!!!
                    {
                        blocks.Add(btr.Id);
                    }
                }
                else
                {
                    blocksCompleteInput = false;
                    //ввод неполный, то считать ввод не выполнен вообще
                    blocks.Clear();
                    break;
                }
            }
            return(blocks);
        }
 public IActionResult Create(PartFamily partFamily)
 {
     if (ModelState.IsValid)
     {
         partFamilyRepository.Add(partFamily);
         return(RedirectToAction("Index"));
     }
     return(View(partFamily));
 }
 public IActionResult Edit(PartFamily obj)
 {
     if (ModelState.IsValid)
     {
         partFamilyRepository.Update(obj);
         return(RedirectToAction("Index"));
     }
     return(View(obj));
 }
Exemplo n.º 7
0
        private bool PartServiceCommoditiesMatch(Part part, PartFamily family)
        {
            if (part.ServiceCommodity.Equals(family.ServiceCommodity))
            {
                return(true);
            }

            m_error = "This part number cannot be added because its service commodity doesnt match the families";
            return(false);
        }
Exemplo n.º 8
0
        private bool PartExistsInFamily(Part part, PartFamily family)
        {
            if (!family.ContainsPart(part))
            {
                return(false);
            }

            m_error = "This part already is a member of this family";
            return(false);
        }
Exemplo n.º 9
0
        public void Update(PartFamily item)
        {
            _context.PartFamily.Update(item);
            _context.SaveChanges();

            //using (IDbConnection dbConnection = Connection)
            //{
            //    dbConnection.Open();
            //    dbConnection.Query("UPDATE customer SET name = @Name,  phone  = @Phone, email= @Email, address= @Address WHERE id = @Id", item);
            //}
        }
Exemplo n.º 10
0
        private ObservableCollection <SelectPartFamilyModel> GetPartFams(Document doc, PartsList partsList,
                                                                         ObjectId defPartFamIfExists, ObjectId defPartSizeIfExists)
        {
            ObservableCollection <SelectPartFamilyModel> partfams = new ObservableCollection <SelectPartFamilyModel>();
            Database db = doc.Database;

            pfStartSelection = null;
            psStartSelection = null;


            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                for (int i = 0; i < partsList.PartFamilyCount; i++)
                {
                    ObjectId   plFamId = partsList[i];
                    PartFamily pf      = (PartFamily)tr.GetObject(plFamId, OpenMode.ForRead);



                    if (partType.HasFlag(pf.PartType))
                    {
                        ObservableCollection <PartSize> partSizes = new ObservableCollection <PartSize>();
                        PartSize startSelSizeCandidate            = null;
                        for (int j = 0; j < pf.PartSizeCount; j++)
                        {
                            ObjectId psId = pf[j];
                            PartSize ps   = (PartSize)psId.GetObject(OpenMode.ForRead);
                            if (defPartSizeIfExists.Equals(psId))
                            {
                                startSelSizeCandidate = ps;
                            }
                            partSizes.Add(ps);
                        }

                        SelectPartFamilyModel spfm = new SelectPartFamilyModel(pf, partSizes);
                        if (defPartFamIfExists.Equals(plFamId))
                        {
                            pfStartSelection = spfm;
                            if (startSelSizeCandidate != null)
                            {
                                psStartSelection = startSelSizeCandidate;
                            }
                        }
                        partfams.Add(spfm);
                    }
                }


                tr.Commit();
            }

            return(partfams);
        }
        // GET: /Customer/Edit/1
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            PartFamily obj = partFamilyRepository.FindByID(id.Value);

            if (obj == null)
            {
                return(NotFound());
            }
            return(View(obj));
        }
Exemplo n.º 12
0
        private bool ContainsTopLevel(Part part, PartFamily family)
        {
            if (!part.IsTopLevel)
            {
                return(false);
            }

            if (part.IsTopLevel && family.TopLevelPart == null)
            {
                return(false);
            }

            m_error = "You cannot add 2 toplevel part numbers to a part family.";
            return(true);
        }
Exemplo n.º 13
0
        public BsonDocument getNestedDevice(Measurement measurement)
        {
            BsonDocument bson   = new BsonDocument();
            Device       device = null;

            if (measurement != null && measurement.DeviceId.HasValue)
            {
                device = getDevice(measurement.DeviceId.Value, measurement.PartSpec.OutputPart);
            }
            if (device == null)
            {
                return(null);
            }

            if (device.SerialNumber == null)
            {
                return(null);
            }
            bson.Add("SerialNumber", device.SerialNumber);
            bson.Add("ContractManufacturer", contrManufs[device.Id]);

            if (measurement.PartSpec == null || measurement.PartSpec.OutputPart == null)
            {
                return(null);
            }

            Part part = getPart(measurement.PartSpec.OutputPart.Id);

            if (part == null)
            {
                Program.log("ERROR: No Part ID " + measurement.PartSpec.OutputPart.Id);
                return(null);
            }

            // Determine batch requests and initialize their proper count
            if (batchRequests.ContainsKey(device.Id))
            {
                int brcount = 0;
                foreach (var br in batchRequests[device.Id])
                {
                    brcount += 1;
                    if (measurement.StartDateTime >= br.date && brcount == 1)
                    {
                        bson.Set("brDate", br.date);
                        bson.Set("brName", br.name);
                    }
                }
                bson.Set("brCount", brcount);
            }

            // Add tosa rosas
            if (tosarosas.ContainsKey(device.Id))
            {
                foreach (var br in tosarosas[device.Id])
                {
                    bson.Add(br.Key, br.Value);
                }
            }

            // Initialize part numbers
            bson.Add("PartNumber", part.PartNumber);
            bson.Add("PartRevision", part.Revision);
            bson.Add("PartType", part.Type);

            if (outputParts.ContainsKey(device.PartId))
            {
                PartFamily partFamily = getPartFamily(outputParts[device.PartId].PartFamilyId.Value);
                if (partFamily == null)
                {
                    Program.log("ERROR: No Part Family ID " + outputParts[device.PartId].PartFamilyId.ToString());
                    return(null);
                }
                bson.Add("PartFamily", partFamily.Name);
            }

            return(bson);
        }
Exemplo n.º 14
0
        makePipeNetwork(ObjectId idAlign, string nameNetwork, string pipeType)
        {
            string pntDesc = fMNP.pntDesc;

            Point3d pnt3dPick = Pub.pnt3dO;

            if (idAlign == ObjectId.Null)
            {
                Autodesk.AutoCAD.DatabaseServices.Entity ent = Select.selectEntity(typeof(Alignment), "Select Alignment: ", "Selected object was not an alignment. Try again: ", out pnt3dPick);
                idAlign = ent.ObjectId;
            }

            Network            net   = null;
            ObjectIdCollection ids   = CivilApplication.ActiveDocument.GetPipeNetworkIds();
            ObjectId           idNet = ObjectId.Null;

            if (ids.Count == 0)
            {
                idNet = Network.Create(CivilApplication.ActiveDocument, ref nameNetwork);
            }
            else
            {
                for (int i = 0; i < ids.Count; i++)
                {
                    net = (Network)ids[i].getEnt();
                    //if (net.Name == nameNetwork){
                    //    string index = Align.getAlignIndex(nameNetwork);
                    //    nameNetwork = string.Format("{0}-{1}", nameNetwork, index);
                    //    break;
                    //}
                }
                idNet = Network.Create(CivilApplication.ActiveDocument, ref nameNetwork);
            }

            bool exists = false;

            Alignment align = (Alignment)idAlign.getEnt();
            AlignmentEntityCollection ents = align.Entities;
            TinSurface tinSurfDE           = Surf.getTinSurface("CPNT-ON", out exists);

            List <AlgnEntData> algnData = MNP_Align.sortAlignEnts(align);
            List <string>      hPipe    = new List <string>();
            List <ObjectId>    idsCgPnt = new List <ObjectId>();

            ObjectId idPipe, idPipeSize, idStruct, idStructSize;

            using (Transaction tr = BaseObjs.startTransactionDb())
            {
                net = (Network)tr.GetObject(idNet, OpenMode.ForWrite);
                net.ReferenceAlignmentId = idAlign;
                net.ReferenceSurfaceId   = Surf.getTinSurface("CPNT-ON", out exists).ObjectId;

                ObjectId  idPartsList = CivilApplication.ActiveDocument.Styles.PartsListSet["Standard"];
                PartsList partsList   = (PartsList)tr.GetObject(idPartsList, OpenMode.ForRead);

                idPipe = partsList["Concrete Pipe"];
                PartFamily partFamily = (PartFamily)tr.GetObject(idPipe, OpenMode.ForWrite);

                idPipeSize = partFamily[0];

                PartSize        partSize = (PartSize)tr.GetObject(idPipeSize, OpenMode.ForRead);
                PartDataRecord  pdr      = partSize.SizeDataRecord;
                PartDataField[] pdf      = pdr.GetAllDataFields();

                for (int i = 0; i < pdf.Length; i++)
                {
                    System.Diagnostics.Debug.Print(string.Format("{0}: {1}", pdf[i].Description, pdf[i].Value.ToString()));
                }

                idStruct     = partsList["Rectangular Structure Slab Top Rectangular Frame"];
                partFamily   = (PartFamily)tr.GetObject(idStruct, OpenMode.ForWrite);
                idStructSize = partFamily[0];

                double depth = -6, slope = 0, dZ = 0, top = 0;
                double diam = double.Parse(pdf[0].Value.ToString()) / 12;

                ObjectId idPipeNew = ObjectId.Null;

                AlignmentEntity ent    = null;
                Structure       sPrev  = null;
                uint            pntNum = 0;

                ObjectId     idCgPntBeg, idCgPntEnd, idCgPntPrev = ObjectId.Null;
                TypedValue[] tvs;

                for (int i = 0; i < algnData.Count; i++)
                {
                    if (algnData.Count == 1)
                    {
                        ent = ents[0];
                    }
                    else
                    {
                        ent = ents.EntityAtId(algnData[i].ID);
                    }

                    ObjectId  idStructNew = ObjectId.Null;
                    Structure s           = null;
                    Pipe      p           = null;

                    if (ent.EntityType == AlignmentEntityType.Line)
                    {
                        AlignmentLine line     = (AlignmentLine)ent;
                        Point2d       pnt2dBeg = line.StartPoint;
                        Point2d       pnt2dEnd = line.EndPoint;

                        try
                        {
                            top = tinSurfDE.FindElevationAtXY(pnt2dBeg.X, pnt2dBeg.Y) + depth;
                        }
                        catch (System.Exception)
                        {
                            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Pipe endpoint is beyond limit of design surface");
                            return;
                        }

                        Point3d pnt3dBeg = new Point3d(pnt2dBeg.X, pnt2dBeg.Y, top);

                        try
                        {
                            top = tinSurfDE.FindElevationAtXY(pnt2dEnd.X, pnt2dEnd.Y) + depth;
                        }
                        catch (System.Exception)
                        {
                            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Pipe endpoint is beyond limit of design surface");
                            return;
                        }

                        Point3d pnt3dEnd = new Point3d(pnt2dEnd.X, pnt2dEnd.Y, top);

                        LineSegment3d seg3d = new LineSegment3d(pnt3dBeg, pnt3dEnd);

                        net.AddLinePipe(idPipe, idPipeSize, seg3d, ref idPipeNew, true);

                        p = (Pipe)idPipeNew.getEnt();
                        p.AddToProfileView(fMNP.idProfileView);

                        ObjectId idPart = getProfileViewPart();

                        slope = pnt3dBeg.getSlope(pnt3dEnd);

                        dZ = diam / (2 * (System.Math.Cos(System.Math.Atan(System.Math.Abs(slope)))));

                        if (i == 0)
                        {
                            pnt3dBeg = new Point3d(pnt3dBeg.X, pnt3dBeg.Y, pnt3dBeg.Z - dZ);
                            pnt3dEnd = new Point3d(pnt3dEnd.X, pnt3dEnd.Y, pnt3dEnd.Z - dZ);

                            idCgPntBeg = pnt3dBeg.setPoint(out pntNum, pntDesc);
                            idsCgPnt.Add(idCgPntBeg);

                            idCgPntEnd = pnt3dEnd.setPoint(out pntNum, pntDesc);
                            idsCgPnt.Add(idCgPntEnd);

                            idCgPntPrev = idCgPntEnd;

                            tvs = new TypedValue[3];
                            tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0);
                            tvs.SetValue(new TypedValue(1005, idCgPntBeg.getHandle().ToString()), 1);
                            tvs.SetValue(new TypedValue(1005, idCgPntEnd.getHandle().ToString()), 2);

                            //idPart.setXData(rb, apps.lnkMNP);
                            idPipeNew.setXData(tvs, apps.lnkMNP);

                            net.AddStructure(idStruct, idStructSize, pnt3dBeg, 0, ref idStructNew, true);
                            s = (Structure)idStructNew.getEnt();
                            s.AddToProfileView(fMNP.idProfileView);
                            s.ConnectToPipe(idPipeNew, ConnectorPositionType.Start);

                            net.AddStructure(idStruct, idStructSize, pnt3dEnd, 0, ref idStructNew, true);
                            s = (Structure)idStructNew.getEnt();
                            s.AddToProfileView(fMNP.idProfileView);
                            s.ConnectToPipe(idPipeNew, ConnectorPositionType.End);

                            sPrev = s;
                            hPipe.Add(idPipeNew.getHandle().ToString());
                        }
                        else
                        {
                            pnt3dEnd   = new Point3d(pnt3dEnd.X, pnt3dEnd.Y, pnt3dEnd.Z - dZ);
                            idCgPntEnd = pnt3dEnd.setPoint(out pntNum, pntDesc);
                            idsCgPnt.Add(idCgPntEnd);

                            tvs = new TypedValue[3];
                            tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0);
                            tvs.SetValue(new TypedValue(1005, idCgPntPrev.getHandle().ToString()), 1);
                            tvs.SetValue(new TypedValue(1005, idCgPntEnd.getHandle().ToString()), 2);

                            //idPart.setXData(rb, apps.lnkMNP);
                            idPipeNew.setXData(tvs, apps.lnkMNP);

                            idCgPntPrev = idCgPntEnd;

                            net.AddStructure(idStruct, idStructSize, pnt3dEnd, 0, ref idStructNew, true);
                            s = (Structure)idStructNew.getEnt();
                            s.AddToProfileView(fMNP.idProfileView);
                            sPrev.ConnectToPipe(idPipeNew, ConnectorPositionType.Start);
                            s.ConnectToPipe(idPipeNew, ConnectorPositionType.End);

                            sPrev = s;
                            hPipe.Add(idPipeNew.getHandle().ToString());
                        }
                    }
                    else if (ent.EntityType == AlignmentEntityType.Arc)
                    {
                        AlignmentArc arc    = (AlignmentArc)ent;
                        double       radius = arc.Radius;

                        Point2d pnt2dBeg = arc.StartPoint;
                        Point2d pnt2dEnd = arc.EndPoint;

                        try
                        {
                            top = tinSurfDE.FindElevationAtXY(pnt2dBeg.X, pnt2dBeg.Y) + depth;
                        }
                        catch (System.Exception)
                        {
                            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Pipe endpoint is beyond limit of design surface");
                            return;
                        }
                        Point3d pnt3dBeg = new Point3d(pnt2dBeg.X, pnt2dBeg.Y, top);

                        try
                        {
                            top = tinSurfDE.FindElevationAtXY(pnt2dEnd.X, pnt2dEnd.Y) + depth;
                        }
                        catch (System.Exception)
                        {
                            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Pipe endpoint is beyond limit of design surface");
                            return;
                        }

                        IntPtr  iptr     = (IntPtr)0;
                        Point3d pnt3dEnd = new Point3d(pnt2dEnd.X, pnt2dEnd.Y, top);

                        Arc a = new Arc();
                        a.Radius     = arc.Radius;
                        a.StartPoint = new Point3d(pnt2dBeg.X, pnt2dBeg.Y, 0);
                        a.EndPoint   = new Point3d(pnt2dEnd.X, pnt2dEnd.Y, 0);
                        a.Center     = new Point3d(arc.CenterPoint.X, arc.CenterPoint.Y, 0);

                        Curve3d c = (Curve3d)a.GetGeCurve();

                        net.AddCurvePipe(idPipe, idPipeSize, c, arc.Clockwise, ref idPipeNew, true);

                        p = (Pipe)idPipeNew.getEnt();
                        p.AddToProfileView(fMNP.idProfileView);

                        ObjectId idPart = getProfileViewPart();
                        slope = (pnt3dEnd.Z - pnt3dBeg.Z) / arc.Length;

                        dZ = diam / (2 * (System.Math.Cos(System.Math.Atan(System.Math.Abs(slope)))));

                        if (i == 0)
                        {
                            pnt3dBeg = new Point3d(pnt3dBeg.X, pnt3dBeg.Y, pnt3dBeg.Z - dZ);
                            pnt3dEnd = new Point3d(pnt3dEnd.X, pnt3dEnd.Y, pnt3dEnd.Z - dZ);

                            idCgPntBeg = pnt3dBeg.setPoint(out pntNum, pntDesc);
                            idsCgPnt.Add(idCgPntBeg);

                            idCgPntEnd = pnt3dEnd.setPoint(out pntNum, pntDesc);
                            idsCgPnt.Add(idCgPntEnd);

                            tvs = new TypedValue[3];
                            tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0);
                            tvs.SetValue(new TypedValue(1005, idCgPntBeg.getHandle().ToString()), 1);
                            tvs.SetValue(new TypedValue(1005, idCgPntEnd.getHandle().ToString()), 2);

                            //idPart.setXData(rb, apps.lnkMNP);
                            idPipeNew.setXData(tvs, apps.lnkMNP);

                            net.AddStructure(idStruct, idStructSize, pnt3dBeg, 0, ref idStructNew, true);
                            s = (Structure)tr.GetObject(idStructNew, OpenMode.ForWrite);
                            s.AddToProfileView(fMNP.idProfileView);
                            s.ConnectToPipe(idPipeNew, ConnectorPositionType.Start);

                            net.AddStructure(idStruct, idStructSize, pnt3dBeg, 0, ref idStructNew, true);
                            s = (Structure)tr.GetObject(idStructNew, OpenMode.ForWrite);
                            s.AddToProfileView(fMNP.idProfileView);
                            s.ConnectToPipe(idPipeNew, ConnectorPositionType.End);
                            sPrev = s;
                            hPipe.Add(idPipeNew.getHandle().ToString());
                        }
                        else
                        {
                            pnt3dEnd = new Point3d(pnt3dEnd.X, pnt3dEnd.Y, pnt3dEnd.Z - dZ);

                            idCgPntEnd = pnt3dEnd.setPoint(out pntNum, pntDesc);
                            idsCgPnt.Add(idCgPntEnd);

                            tvs = new TypedValue[3];
                            tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0);
                            tvs.SetValue(new TypedValue(1005, idCgPntPrev.getHandle().ToString()), 1);
                            tvs.SetValue(new TypedValue(1005, idCgPntEnd.getHandle().ToString()), 2);

                            //idPart.setXData(rb, apps.lnkMNP);
                            idPipeNew.setXData(tvs, apps.lnkMNP);

                            idCgPntPrev = idCgPntEnd;

                            net.AddStructure(idStruct, idStructSize, pnt3dBeg, 0, ref idStructNew, true);
                            s = (Structure)tr.GetObject(idStructNew, OpenMode.ForWrite);
                            s.AddToProfileView(fMNP.idProfileView);
                            sPrev.ConnectToPipe(idPipeNew, ConnectorPositionType.Start);
                            s.ConnectToPipe(idPipeNew, ConnectorPositionType.End);
                            sPrev = s;
                            hPipe.Add(idPipeNew.getHandle().ToString());
                        }
                    }
                }
                tr.Commit();
            }

            hPipe.Insert(0, "-1");
            hPipe.Add("-1");

            for (int i = 0; i < idsCgPnt.Count; i++)
            {
                TypedValue[] tvs = new TypedValue[3];
                tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0);
                tvs.SetValue(new TypedValue(1005, hPipe[i]), 1);
                tvs.SetValue(new TypedValue(1005, hPipe[i + 1]), 2);
                idsCgPnt[i].setXData(tvs, apps.lnkMNP);
            }
        }
Exemplo n.º 15
0
        public void ExportToExcel()
        {
            Editor        ed  = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            CivilDocument doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;

            // Document AcadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            // Check that there's a pipe network to parse
            if (doc.GetPipeNetworkIds() == null)
            {
                ed.WriteMessage("There are no pipe networks to export.  Open a document that contains at least one pipe network");
                return;
            }

            // Interop code is adapted from the MSDN site:
            // http://msdn.microsoft.com/en-us/library/ms173186(VS.80).aspx
            xlApp = new Microsoft.Office.Interop.Excel.Application();

            if (xlApp == null)
            {
                Console.WriteLine(@"EXCEL could not be started. Check that your office installation 
                and project references are correct.");
                return;
            }
            xlApp.Visible       = true;
            xlWb                = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
            xlWsStructures      = ( Worksheet )xlWb.Worksheets[1];
            xlWsPipes           = ( Worksheet )xlWb.Worksheets.Add(xlWsStructures, System.Type.Missing, 1, System.Type.Missing);
            xlWsPipes.Name      = "Pipes";
            xlWsStructures.Name = "Structures";

            if (xlWsPipes == null)
            {
                Console.WriteLine(@"Worksheet could not be created. Check that your office installation 
                and project references are correct.");
            }

            // Iterate through each pipe network
            using (Transaction ts = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()) {
                int  row = 1;
                char col = 'B';
                Dictionary <string, char> dictPipe = new Dictionary <string, char>(); // track data parts column
                // set up header
                Range aRange = xlWsPipes.get_Range("A1", System.Type.Missing);
                aRange.Value2 = "Handle";
                aRange        = xlWsPipes.get_Range("B1", System.Type.Missing);
                aRange.Value2 = "Start";
                aRange        = xlWsPipes.get_Range("C1", System.Type.Missing);
                aRange.Value2 = "End";
                aRange        = xlWsPipes.get_Range("D1", System.Type.Missing);
                aRange.Value2 = "Slope";


                try {
                    ObjectId oNetworkId = doc.GetPipeNetworkIds()[0];
                    Network  oNetwork   = ts.GetObject(oNetworkId, OpenMode.ForWrite) as Network;

                    // Get pipes:
                    ObjectIdCollection oPipeIds = oNetwork.GetPipeIds();
                    int pipeCount = oPipeIds.Count;

                    // we can edit the slope, so make that column yellow
                    Range colRange = xlWsPipes.get_Range("D1", "D" + (pipeCount + 1));
                    colRange.Interior.ColorIndex        = 6;
                    colRange.Interior.Pattern           = XlPattern.xlPatternSolid;
                    colRange.Interior.PatternColorIndex = XlColorIndex.xlColorIndexAutomatic;

                    foreach (ObjectId oid in oPipeIds)
                    {
                        Pipe oPipe = ts.GetObject(oid, OpenMode.ForRead) as Pipe;
                        ed.WriteMessage("   " + oPipe.Name);
                        col = 'B';
                        row++;
                        aRange        = xlWsPipes.get_Range("A" + row, System.Type.Missing);
                        aRange.Value2 = oPipe.Handle.Value.ToString();
                        aRange        = xlWsPipes.get_Range("B" + row, System.Type.Missing);
                        aRange.Value2 = oPipe.StartPoint.X + "," + oPipe.StartPoint.Y + "," + oPipe.StartPoint.Z;
                        aRange        = xlWsPipes.get_Range("C" + row, System.Type.Missing);
                        aRange.Value2 = oPipe.EndPoint.X + "," + oPipe.EndPoint.Y + "," + oPipe.EndPoint.Z;

                        // This only gives the absolute value of the slope:
                        // aRange = xlWsPipes.get_Range("D" + row, System.Type.Missing);
                        // aRange.Value2 = oPipe.Slope;
                        // This gives a signed value:
                        aRange        = xlWsPipes.get_Range("D" + row, System.Type.Missing);
                        aRange.Value2 = (oPipe.EndPoint.Z - oPipe.StartPoint.Z) / oPipe.Length2DCenterToCenter;

                        // Get the catalog data to use later
                        ObjectId           partsListId             = doc.Styles.PartsListSet["Standard"];
                        PartsList          oPartsList              = ts.GetObject(partsListId, OpenMode.ForRead) as PartsList;
                        ObjectIdCollection oPipeFamilyIdCollection = oPartsList.GetPartFamilyIdsByDomain(DomainType.Pipe);

                        foreach (PartDataField oPartDataField in oPipe.PartData.GetAllDataFields())
                        {
                            // Make sure the data has a column in Excel, if not, add the column
                            if (!dictPipe.ContainsKey(oPartDataField.ContextString))
                            {
                                char nextCol = ( char )(( int )'E' + dictPipe.Count);
                                aRange        = xlWsPipes.get_Range("" + nextCol + "1", System.Type.Missing);
                                aRange.Value2 = oPartDataField.ContextString + "(" + oPartDataField.Name + ")";
                                dictPipe.Add(oPartDataField.ContextString, nextCol);

                                // We can edit inner diameter or width, so make those yellow
                                if ((oPartDataField.ContextString == "PipeInnerDiameter") || (oPartDataField.ContextString == "PipeInnerWidth"))
                                {
                                    colRange = xlWsPipes.get_Range("" + nextCol + "1", "" + nextCol + (pipeCount + 1));
                                    colRange.Interior.ColorIndex        = 6;
                                    colRange.Interior.Pattern           = XlPattern.xlPatternSolid;
                                    colRange.Interior.PatternColorIndex = XlColorIndex.xlColorIndexAutomatic;
                                }

                                // Check the part catalog data to see if this part data is user-modifiable
                                foreach (ObjectId oPipeFamliyId in oPipeFamilyIdCollection)
                                {
                                    PartFamily      oPartFamily      = ts.GetObject(oPipeFamliyId, OpenMode.ForRead) as PartFamily;
                                    SizeFilterField oSizeFilterField = null;

                                    try {
                                        oSizeFilterField = oPartFamily.PartSizeFilter[oPartDataField.Name];
                                    } catch (System.Exception e) { }

                                    /* You can also iterate through all defined size filter fields this way:
                                     * SizeFilterRecord oSizeFilterRecord = oPartFamily.PartSizeFilter;
                                     * for ( int i = 0; i < oSizeFilterRecord.ParamCount; i++ ) {
                                     *   oSizeFilterField = oSizeFilterRecord[i];
                                     * } */

                                    if (oSizeFilterField != null)
                                    {
                                        // Check whether it can be modified:
                                        if (oSizeFilterField.DataSource == PartDataSourceType.Optional)
                                        {
                                            colRange = xlWsPipes.get_Range("" + nextCol + "1", "" + nextCol + (pipeCount + 1));
                                            colRange.Interior.ColorIndex        = 4;
                                            colRange.Interior.Pattern           = XlPattern.xlPatternSolid;
                                            colRange.Interior.PatternColorIndex = XlColorIndex.xlColorIndexAutomatic;
                                        }

                                        break;
                                    }
                                }
                            }
                            char iColumnPipes = dictPipe[oPartDataField.ContextString];
                            aRange        = aRange = xlWsPipes.get_Range("" + iColumnPipes + row, System.Type.Missing);
                            aRange.Value2 = oPartDataField.Value;
                        }
                    }

                    // Now export the structures
                    row = 1;
                    col = 'B';
                    Dictionary <string, char> dictStructures = new Dictionary <string, char>(); // track data parts column
                    // Set up header
                    aRange        = xlWsStructures.get_Range("A1", System.Type.Missing);
                    aRange.Value2 = "Handle";
                    aRange        = xlWsStructures.get_Range("B1", System.Type.Missing);
                    aRange.Value2 = "Location";

                    // Get structures:
                    ObjectIdCollection oStructureIds = oNetwork.GetStructureIds();
                    foreach (ObjectId oid in oStructureIds)
                    {
                        Structure oStructure = ts.GetObject(oid, OpenMode.ForRead) as Structure;
                        col = 'B';
                        row++;
                        aRange        = xlWsStructures.get_Range("" + col + row, System.Type.Missing);
                        aRange.Value2 = oStructure.Handle.Value;
                        aRange        = xlWsStructures.get_Range("" + ++col + row, System.Type.Missing);
                        aRange.Value2 = oStructure.Position.X + "," + oStructure.Position.Y + "," + oStructure.Position.Z;

                        foreach (PartDataField oPartDataField in oStructure.PartData.GetAllDataFields())
                        {
                            // Make sure the data has a column in Excel, if not, add the column
                            if (!dictStructures.ContainsKey(oPartDataField.ContextString))
                            {
                                char nextCol = ( char )(( int )'D' + dictStructures.Count);
                                aRange        = xlWsStructures.get_Range("" + nextCol + "1", System.Type.Missing);
                                aRange.Value2 = oPartDataField.ContextString;
                                dictStructures.Add(oPartDataField.ContextString, nextCol);
                            }
                            char iColumnStructure = dictStructures[oPartDataField.ContextString];
                            aRange        = aRange = xlWsStructures.get_Range("" + iColumnStructure + row, System.Type.Missing);
                            aRange.Value2 = oPartDataField.Value;
                        }
                    }
                } catch (Autodesk.AutoCAD.Runtime.Exception ex) {
                    ed.WriteMessage("PipeSample: " + ex.Message);
                    return;
                }
            }
        }
Exemplo n.º 16
0
        public void ChangePipeType()
        {
            Document adoc = Application.DocumentManager.MdiActiveDocument;

            if (adoc == null)
            {
                return;
            }

            Database db = adoc.Database;

            Editor ed = adoc.Editor;

            try
            {
                //выбор элементов сети (TODO: или использовать текущий выбор объектов)
                //отобрать только трубы
                PromptSelectionOptions pso = new PromptSelectionOptions();
                pso.MessageForAdding = "\nВыберите трубы:";

                TypedValue[]    tv  = new TypedValue[] { new TypedValue(0, "AECC_PIPE") };
                SelectionFilter flt = new SelectionFilter(tv);

                PromptSelectionResult acSSPrompt = adoc.Editor.GetSelection(pso, flt);


                if (acSSPrompt.Status != PromptStatus.OK)
                {
                    return;
                }

                //определить каталог
                //трубы должны принадлежать к одному каталогу иначе отменить
                SelectionSet acSSet = acSSPrompt.Value;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    ObjectId    partsListId = ObjectId.Null;
                    List <Pipe> pipes       = new List <Pipe>();

                    ObjectId defPartFam  = ObjectId.Null;
                    ObjectId defPartSize = ObjectId.Null;

                    foreach (ObjectId id in acSSet.GetObjectIds())
                    {
                        Pipe pipe = null;
                        //using (Transaction tr = db.TransactionManager.StartTransaction())
                        //{
                        pipe = tr.GetObject(id, OpenMode.ForRead) as Pipe;
                        //    tr.Commit();
                        //}
                        if (pipe == null)
                        {
                            continue;
                        }


                        pipes.Add(pipe);

                        Network network = null;
                        //using (Transaction tr = db.TransactionManager.StartTransaction())
                        //{
                        network = tr.GetObject(pipe.NetworkId, OpenMode.ForRead) as Network;
                        //    tr.Commit();
                        //}
                        if (partsListId == ObjectId.Null)
                        {
                            partsListId = network.PartsListId;
                        }
                        else if (partsListId != network.PartsListId)
                        {
                            ed.WriteMessage("\nВыбранные трубы относятся к разным PartsList");
                            return;
                        }

                        //Нельзя узнать текущий PartFamily и PartSize???
                        //pipe.SwapPartFamilyAndSize
                    }

                    if (partsListId == ObjectId.Null)
                    {
                        return;
                    }

                    PartsList partsList = null;
                    //using (Transaction tr = db.TransactionManager.StartTransaction())
                    //{
                    partsList = tr.GetObject(partsListId, OpenMode.ForRead) as PartsList;
                    //    tr.Commit();
                    //}

                    //вывести окно с выбором нового типа трубы (если выбранные трубы имели одинаковый тип, то отобразить его)
                    SetPipeTypeViewModel viewModel = new SetPipeTypeViewModel(adoc, partsList);
                    SetPipeTypeView      view      = new SetPipeTypeView();
                    view.DataContext = viewModel;

                    Application.ShowModalWindow(view);

                    if (!view.DialogResult.HasValue || !view.DialogResult.Value)
                    {
                        return;
                    }

                    //задать выбранный тип трубы
                    PartFamily partFamily = viewModel.PipeVM.SelectedPartFamily.PartFamily;
                    PartSize   partSize   = viewModel.PipeVM.SelectedPartSize;


                    foreach (Pipe pipe in pipes)
                    {
                        pipe.SwapPartFamilyAndSize(partFamily.Id, partSize.Id);
                    }

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                CommonException(ex, "Ошибка при попытке изменить тип труб");
            }
        }
Exemplo n.º 17
0
 public SelectPartFamilyModel(PartFamily partFamily, ObservableCollection <PartSize> partSizes)
 {
     this.partFamily = partFamily;
     this.partSizes  = partSizes;
 }
Exemplo n.º 18
0
 public AddFamilyMemberValidator(PartFamily partFamily, Part part)
 {
     m_part       = part;
     m_partFamily = partFamily;
 }