• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            C++ Programmer's Cookbook

            {C++ 基礎(chǔ)} {C++ 高級} {C#界面,C++核心算法} {設(shè)計模式} {C#基礎(chǔ)}

            很好的arx學(xué)習(xí)代碼(.net版)

            using ?System?;
            using ?Autodesk.AutoCAD.Runtime?;
            using ?Autodesk.AutoCAD.ApplicationServices;
            using ?Autodesk.AutoCAD.DatabaseServices;
            using ?Autodesk.AutoCAD.Geometry;
            using ?Autodesk.AutoCAD.Colors;
            using ?Autodesk.AutoCAD.EditorInput;

            [assembly:?CommandClass(
            typeof (ClassLibrary.Class))]

            namespace ?ClassLibrary
            {
            ????
            /// ? <summary>
            ????
            /// ?Summary?description?for?Class.
            ????
            /// ? </summary>

            ???? public ? class ?Class
            ????
            {
            ????????
            public ?Class()
            ????????
            {
            ????????????
            //
            ????????????
            // ?TODO:?Add?constructor?logic?here
            ????????????
            //
            ????????}

            ????????
            // This?function?returns?the?ObjectId?for?the?BlockTableRecord?called?"EmployeeBlock",
            ????????
            // creating?it?if?necessary.??The?block?contains?three?entities?-?circle,?text?
            ????????
            // and?ellipse.
            ???????? public ?ObjectId?CreateEmployeeDefinition()?
            ????????
            {?
            ????????????ObjectId?newBtrId?
            = ? new ?ObjectId();? // The?return?value?for?this?function
            ????????????Database?db? = ?HostApplicationServices.WorkingDatabase;? // save?some?space
            ????????????Transaction?trans? = ?db.TransactionManager.StartTransaction();? // begin?the?transaction
            ????????????Editor?ed? = ?Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;?
            ????????????
            ????????????
            try ?
            ????????????
            {?
            ????????????????
            // Now,?drill?into?the?database?and?obtain?a?reference?to?the?BlockTable
            ????????????????BlockTable?bt? = ?(BlockTable)trans.GetObject(db.BlockTableId,?OpenMode.ForWrite);?
            ????????????????
            if ?((bt.Has( " EmployeeBlock " )))?
            ????????????????
            {?
            ????????????????????newBtrId?
            = bt[ " EmployeeBlock " ];
            ????????????????}
            ?
            ????????????????
            else ?
            ????????????????
            {?
            ????????????????????Point3d?center?
            = ? new ?Point3d( 10 ,? 10 ,? 0 );? // ?convenient?declaration
            ????????????????????
            // ??Declare?and?define?the?entities?we?want?to?add:
            ????????????????????
            // Circle:
            ????????????????????Circle?circle? = ? new ?Circle(center,?Vector3d.ZAxis,? 2 );?
            ????????????????????
            // Text:
            ????????????????????
            // MText?text?=?new?MText();?
            ????????????????????
            // text.Contents?=?"Earnest?Shackleton";?
            ????????????????????
            // text.Location?=?center;?
            ????????????????
            ????????????????????
            // Attribute?Definition
            ????????????????????AttributeDefinition?text? = ? new ?AttributeDefinition(center,? " NoName " ,? " Name: " ,? " Enter?Name " ,?db.Textstyle);
            ????????????????????text.ColorIndex?
            = ? 2 ;

            ????????????????????
            // Ellipse:
            ????????????????????Ellipse?ellipse? = ? new ?Ellipse(center,?Vector3d.ZAxis,? new ?Vector3d( 3 ,? 0 ,? 0 ),? 0.5 ,? 0 ,? 0 );?

            ????????????????????
            // Next,?create?a?layer?with?the?helper?function,?and?assign
            ????????????????????
            // the?layer?to?our?entities.
            ????????????????????ObjectId?empId? = ?CreateLayer();?
            ????????????????????text.LayerId?
            = ?empId;?
            ????????????????????circle.LayerId?
            = ?empId;?
            ????????????????????ellipse.LayerId?
            = ?empId;?
            ????????????????????
            // Set?the?color?for?each?entity?irrespective?of?the?layer's?color.
            ????????????????????text.ColorIndex? = ? 2 ;?
            ????????????????????circle.ColorIndex?
            = ? 1 ;?
            ????????????????????ellipse.ColorIndex?
            = ? 3 ;?

            ????????????????????
            // Create?a?new?block?definition?called?EmployeeBlock
            ????????????????????BlockTableRecord?newBtr? = ? new ?BlockTableRecord();?
            ????????????????????newBtr.Name?
            = ? " EmployeeBlock " ;?
            ????????????????????newBtrId?
            = ?bt.Add(newBtr);? // Add?the?block,?and?set?the?id?as?the?return?value?of?our?function
            ????????????????????trans.AddNewlyCreatedDBObject(newBtr,? true );? // Let?the?transaction?know?about?any?object/entity?you?add?to?the?database!
            ????????????????????
            ????????????????????newBtr.AppendEntity(circle);?
            // Append?our?entities
            ????????????????????newBtr.AppendEntity(text);?
            ????????????????????newBtr.AppendEntity(ellipse);?
            ????????????????????trans.AddNewlyCreatedDBObject(circle,?
            true );? // Again,?let?the?transaction?know?about?our?newly?added?entities.
            ????????????????????trans.AddNewlyCreatedDBObject(text,? true );?
            ????????????????????trans.AddNewlyCreatedDBObject(ellipse,?
            true );?
            ????????????????????????????????????????
            ????????????????}
            ?
            ????????????????trans.Commit();?
            // All?done,?no?errors???Go?ahead?and?commit!
            ????????????}
            ?
            ????????????
            catch ?
            ????????????
            {?????????????????
            ????????????????ed.WriteMessage(
            " Error?Creating?Employee?Block " );
            ????????????}
            ?
            ????????????
            finally ?
            ????????????
            {?
            ????????????????trans.Dispose();?
            ????????????}
            ?
            ????????????
            // CreateDivision();? // Create?the?Employee?Division?dictionaries.
            ???????????? return ?newBtrId;?
            ????????}

            ????????

            ????????
            // This?function?creates?a?new?BlockReference?to?the?"EmployeeBlock"?object,
            ????????
            // and?adds?it?to?ModelSpace.
            ???????? public ?ObjectId?CreateEmployee( string ?name,? string ?division,? double ?salary,?Point3d?pos)?
            ????????
            {?
            ????????????Database?db?
            = ?HostApplicationServices.WorkingDatabase;?
            ????????????Transaction?trans?
            = ?db.TransactionManager.StartTransaction();?
            ????????????
            try ?
            ????????????
            {?

            ????????????????BlockTable?bt?
            = ?(BlockTable)(trans.GetObject(db.BlockTableId,?OpenMode.ForWrite));?
            ????????????????BlockTableRecord?btr?
            = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],?OpenMode.ForWrite);
            ????????????????
            // Create?the?block?referenceuse?the?return?from?CreateEmployeeDefinition?directly!
            ????????????????BlockReference?br? = ? new ?BlockReference(pos,?CreateEmployeeDefinition());?
            ????????
            // ????????btr.AppendEntity(br);? // Add?the?reference?to?ModelSpace
            ????????
            // ????????trans.AddNewlyCreatedDBObject(br,?true);? // Let?the?transaction?know?about?it

            ????????????????AttributeReference?attRef?
            = ? new ?AttributeReference();?
            ????????????????
            // Iterate?the?employee?block?and?find?the?attribute?definition
            ????????????????BlockTableRecord?empBtr? = ?(BlockTableRecord)trans.GetObject(bt[ " EmployeeBlock " ],?OpenMode.ForRead);?
            ????????????????
            foreach ?(ObjectId?id? in ?empBtr)?
            ????????????????
            {?
            ????????????????????Entity?ent?
            = ?(Entity)trans.GetObject(id,?OpenMode.ForRead,? false );?
            ????????????????????
            // Use?it?to?open?the?current?object!?
            ???????????????????? if ?(ent? is ?AttributeDefinition)?? // We?use?.NET's?RTTI?to?establish?type.
            ???????????????????? {?
            ????????????????????????
            // Set?the?properties?from?the?attribute?definition?on?our?attribute?reference
            ????????????????????????AttributeDefinition?attDef? = ?((AttributeDefinition)(ent));?
            ????????????????????????attRef.SetPropertiesFrom(attDef);?
            ????????????????????????attRef.Position?
            = ? new ?Point3d(attDef.Position.X? + ?br.Position.X,?attDef.Position.Y? + ?br.Position.Y,?attDef.Position.Z? + ?br.Position.Z);?
            ????????????????????????attRef.Height?
            = ?attDef.Height;?
            ????????????????????????attRef.Rotation?
            = ?attDef.Rotation;?
            ????????????????????????attRef.Tag?
            = ?attDef.Tag;?
            ????????????????????????attRef.TextString?
            = ?name;?
            ????????????????????}
            ?
            ????????????????}
            ?
            ????????????????
            // Add?the?reference?to?ModelSpace
            ????????????????btr.AppendEntity(br);?
            ????????????????
            // Add?the?attribute?reference?to?the?block?reference
            ????????????????br.AttributeCollection.AppendAttribute(attRef);?
            ????????????????
            // let?the?transaction?know
            ????????????????trans.AddNewlyCreatedDBObject(attRef,? true );?
            ????????????????trans.AddNewlyCreatedDBObject(br,?
            true );

            ????????????????
            // Create?the?custom?per-employee?data
            ????????????????Xrecord?xRec? = ?? new ?Xrecord();
            ????????????????
            // We?want?to?add?'Name',?'Salary'?and?'Division'?information.??Here?is?how:
            ????????????????xRec.Data? = ? new ?ResultBuffer(?
            ????????????????????
            new ?TypedValue(( int )DxfCode.Text,?name),?
            ????????????????????
            new ?TypedValue(( int )DxfCode.Real,?salary),?
            ????????????????????
            new ?TypedValue(( int )DxfCode.Text,?division));

            ????????????????
            // Next,?we?need?to?add?this?data?to?the?'Extension?Dictionary'?of?the?employee.
            ????????????????br.CreateExtensionDictionary();
            ????????????????DBDictionary?brExtDict??
            = ?(DBDictionary)trans.GetObject(br.ExtensionDictionary,?OpenMode.ForWrite,? false );
            ????????????????brExtDict.SetAt(
            " EmployeeData " ,?xRec);? // Set?our?XRecord?in?the?dictionary?at?'EmployeeData'.
            ????????????????trans.AddNewlyCreatedDBObject(xRec,? true );

            ????????????????trans.Commit();?
            ????????????????
            return ?br.ObjectId;
            ????????????}
            ?
            ????????????
            finally ?
            ????????????
            {?
            ????????????????trans.Dispose();?
            ????????????}
            ?
            ????????}

            ?????????
            ????????
            // This?function?returns?the?objectId?for?the?"EmployeeLayer",?creating?it?if?necessary.
            ???????? public ?ObjectId?CreateLayer()?
            ????????
            {?
            ????????????ObjectId?layerId;?
            ????????????Database?db?
            = ?HostApplicationServices.WorkingDatabase;?
            ????????????Transaction?trans?
            = ?db.TransactionManager.StartTransaction();?
            ????????????
            // Get?the?layer?table?first
            ????????????LayerTable?lt? = ?(LayerTable)trans.GetObject(db.LayerTableId,?OpenMode.ForWrite);?
            ????????????
            // Check?if?EmployeeLayer?exists
            ????????????
            ????????????
            if ?(lt.Has( " EmployeeLayer " ))?
            ????????????
            {?
            ????????????????layerId?
            = ?lt[ " EmployeeLayer " ];
            ????????????}
            ?
            ????????????
            else ?
            ????????????
            {?
            ????????????????
            // If?not,?create?the?layer?here.
            ????????????????LayerTableRecord?ltr? = ? new ?LayerTableRecord();?
            ????????????????ltr.Name?
            = ? " EmployeeLayer " ;? // ?Set?the?layer?name
            ????????????????ltr.Color? = ?Color.FromColorIndex(ColorMethod.ByAci,? 2 );?
            ????????????????layerId?
            = ?lt.Add(ltr);?
            ????????????????trans.AddNewlyCreatedDBObject(ltr,?
            true );?
            ????????????}
            ?
            ????????????trans.Commit();?
            ????????????trans.Dispose();?
            ????????????
            return ?layerId;?
            ????????}


            ????????
            public ?ObjectId?CreateDivision( string ?division,? string ?manager)
            ????????
            {
            ????????????Database?db?
            = ?HostApplicationServices.WorkingDatabase;
            ????????????Transaction?trans?
            = ?db.TransactionManager.StartTransaction();?

            ????????????
            try
            ????????????
            {
            ????????????????
            // First,?get?the?NOD
            ????????????????DBDictionary?NOD? = ?(DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId,?OpenMode.ForWrite);
            ????????????????
            // Define?a?corporate?level?dictionary
            ????????????????DBDictionary?acmeDict;
            ????????????????
            try
            ????????????????
            {
            ????????????????????
            // Just?throw?if?it?doesn't?existdo?nothing?else
            ????????????????????acmeDict? = ?(DBDictionary)trans.GetObject(NOD.GetAt( " ACME_DIVISION " ),?OpenMode.ForRead);
            ????????????????}

            ????????????????
            catch
            ????????????????
            {
            ????????????????????
            // Doesn't?exist,?so?create?one,?and?set?it?in?the?NOD?
            ????????????????????acmeDict? = ? new ?DBDictionary();
            ????????????????????NOD.SetAt(
            " ACME_DIVISION " ,?acmeDict);
            ????????????????????trans.AddNewlyCreatedDBObject(acmeDict,?
            true );
            ????????????????}


            ????????????????
            // Now?get?the?division?we?want?from?acmeDict
            ????????????????DBDictionary?divDict;
            ????????????????
            try
            ????????????????
            {
            ????????????????????divDict?
            = ?(DBDictionary)trans.GetObject(acmeDict.GetAt(division),?OpenMode.ForWrite);
            ????????????????}

            ????????????????
            catch
            ????????????????
            {
            ????????????????????divDict?
            = ? new ?DBDictionary();
            ????????????????????
            // Division?doesn't?exist,?create?one
            ????????????????????acmeDict.UpgradeOpen();
            ????????????????????acmeDict.SetAt(division,?divDict);
            ????????????????????trans.AddNewlyCreatedDBObject(divDict,?
            true );
            ????????????????}


            ????????????????
            // Now?get?the?manager?info?from?the?division
            ????????????????
            // We?need?to?add?the?name?of?the?division?supervisor.??We'll?do?this?with?another?XRecord.
            ????????????????Xrecord?mgrXRec;
            ????????????????
            try
            ????????????????
            {
            ????????????????????mgrXRec?
            = ?(Xrecord)trans.GetObject(divDict.GetAt( " Department?Manager " ),?OpenMode.ForWrite);
            ????????????????}

            ????????????????
            catch
            ????????????????
            {
            ????????????????????mgrXRec?
            = ? new ?Xrecord();
            ????????????????????mgrXRec.Data?
            = ? new ?ResultBuffer( new ?TypedValue(( int )DxfCode.Text,?manager));
            ????????????????????divDict.SetAt(
            " Department?Manager " ,?mgrXRec);
            ????????????????????trans.AddNewlyCreatedDBObject(mgrXRec,?
            true );
            ????????????????}


            ????????????????trans.Commit();
            ????????????????
            // Return?the?department?manager?XRecord
            ???????????????? return ?mgrXRec.ObjectId;

            ????????????}

            ????????????
            finally
            ????????????
            {
            ????????????????trans.Dispose();
            ????????????}

            ????????}


            ????????[CommandMethod(
            " EMPLOYEECOUNT " )]
            ????????
            public ? void ?EmployeeCount()
            ????????
            {
            ????????????Database?db?
            = ?HostApplicationServices.WorkingDatabase;
            ????????????Transaction?trans?
            = ?db.TransactionManager.StartTransaction();?? // Start?the?transaction.
            ???????????? int ?nEmployeeCount?? = ? 0 ;
            ????????????
            try
            ????????????
            {
            ????????????????
            // First,?get?at?the?BlockTable,?and?the?ModelSpace?BlockTableRecord
            ????????????????BlockTable?bt? = ?(BlockTable)trans.GetObject(db.BlockTableId,?OpenMode.ForRead);
            ????????????????BlockTableRecord?btr?
            = ?(BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],?OpenMode.ForRead);
            ????????????????
            // Now,?we?need?to?be?able?to?print?to?the?commandline.??Here?is?an?object?which?will?help?us:
            ????????????????Editor?ed? = ?Application.DocumentManager.MdiActiveDocument.Editor;

            ????????????????
            // Now,?here?is?the?fun?part.??This?is?where?we?iterate?through?ModelSpace:
            ???????????????? foreach ?(ObjectId?id? in ?btr)
            ????????????????
            {
            ????????????????????Entity?ent?
            = ?(Entity)trans.GetObject(id,?OpenMode.ForRead,? false );?? // Use?it?to?open?the?current?object!
            ???????????????????? if ?(ent.GetType()? == ? typeof (BlockReference))? // We?use?.NET's?RTTI?to?establish?type.
            ???????????????????? {
            ????????????????????????nEmployeeCount?
            += ? 1 ;
            ????????????????????}

            ????????????????}


            ????????????????ed.WriteMessage(
            " Employees?Found:? " ? + ?nEmployeeCount.ToString());
            ????????????????trans.Commit();
            ????????????}

            ????????????
            finally
            ????????????
            {
            ????????????????trans.Dispose();
            ????????????}

            ????????}


            ????????
            // We?want?a?command?which?will?go?through?and?list?all?the?relevant?employee?data.
            ???????? public ? static ? void ?ListEmployee(ObjectId?employeeId,? ref ? string []?saEmployeeList)?
            ????????
            {?
            ????????????
            int ?nEmployeeDataCount? = ? 0 ;?
            ????????????Database?db?
            = ?HostApplicationServices.WorkingDatabase;?
            ????????????Transaction?trans?
            = ?db.TransactionManager.StartTransaction();? // Start?the?transaction
            ???????????? try ?
            ????????????
            {?
            ????????????????Entity?ent?
            = ?(Entity)trans.GetObject(employeeId,?OpenMode.ForRead,? false );? // Use?it?to?open?the?current?object!
            ???????????????? if ?(ent.GetType()? == ? typeof (BlockReference))? // We?use?.NET's?RTTI?to?establish?type.
            ???????????????? {?
            ????????????????????
            // Not?all?BlockReferences?will?have?our?employee?data,?so?we?must?make?sure?we?can?handle?failure
            ???????????????????? bool ?bHasOurDict? = ? true ;?
            ????????????????????Xrecord?EmployeeXRec?
            = ? null ;?
            ????????????????????
            try ?
            ????????????????????
            {?
            ????????????????????????BlockReference?br?
            = ?(BlockReference)ent;?
            ????????????????????????DBDictionary?extDict?
            = ?(DBDictionary)trans.GetObject(br.ExtensionDictionary,?OpenMode.ForRead,? false );?
            ????????????????????????EmployeeXRec?
            = ?(Xrecord)trans.GetObject(extDict.GetAt( " EmployeeData " ),?OpenMode.ForRead,? false );?
            ????????????????????}
            ?
            ????????????????????
            catch ?
            ????????????????????
            {?
            ????????????????????????bHasOurDict?
            = ? false ;? // Something?bad?happenedour?dictionary?and/or?XRecord?is?not?accessible
            ????????????????????}
            ?

            ????????????????????
            if ?(bHasOurDict)? // If?obtaining?the?Extension?Dictionary,?and?our?XRecord?is?successful
            ???????????????????? {?

            ????????????????????????
            // ?allocate?memory?for?the?list
            ????????????????????????saEmployeeList? = ? new ?String[ 4 ];

            ????????????????????????TypedValue?resBuf?
            = ?EmployeeXRec.Data.AsArray()[ 0 ];?
            ????????????????????????saEmployeeList.SetValue(
            string .Format( " {0}\n " ,?resBuf.Value),?nEmployeeDataCount);?
            ????????????????????????nEmployeeDataCount?
            += ? 1 ;?
            ????????????????????????resBuf?
            = ?EmployeeXRec.Data.AsArray()[ 1 ];?
            ????????????????????????saEmployeeList.SetValue(
            string .Format( " {0}\n " ,?resBuf.Value),?nEmployeeDataCount);?
            ????????????????????????nEmployeeDataCount?
            += ? 1 ;?
            ????????????????????????resBuf?
            = ?EmployeeXRec.Data.AsArray()[ 2 ];?
            ????????????????????????
            string ?str? = ?( string )resBuf.Value;?
            ????????????????????????saEmployeeList.SetValue(
            string .Format( " {0}\n " ,?resBuf.Value),?nEmployeeDataCount);?
            ????????????????????????nEmployeeDataCount?
            += ? 1 ;?
            ????????????????????????DBDictionary?NOD?
            = ?(DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId,?OpenMode.ForRead,? false );?
            ????????????????????????DBDictionary?acmeDict?
            = ?(DBDictionary)trans.GetObject(NOD.GetAt( " ACME_DIVISION " ),?OpenMode.ForRead);?
            ????????????????????????DBDictionary?salesDict?
            = ?(DBDictionary)trans.GetObject(acmeDict.GetAt(( string )EmployeeXRec.Data.AsArray()[ 2 ].Value),?OpenMode.ForRead);?
            ????????????????????????Xrecord?salesXRec?
            = ?(Xrecord)trans.GetObject(salesDict.GetAt( " Department?Manager " ),?OpenMode.ForRead);?
            ????????????????????????resBuf?
            = ?salesXRec.Data.AsArray()[ 0 ];?
            ????????????????????????saEmployeeList.SetValue(
            string .Format( " {0}\n " ,?resBuf.Value),?nEmployeeDataCount);?
            ????????????????????????nEmployeeDataCount?
            += ? 1 ;?
            ????????????????????}
            ?
            ????????????????}
            ?
            ????????????????trans.Commit();?
            ????????????}
            ?
            ????????????
            finally ?
            ????????????
            {?
            ????????????????trans.Dispose();?
            ????????????}
            ?
            ????????}
            ?

            ????
            ????????[CommandMethod(
            " PRINTOUTEMPLOYEE " )]?
            ????????
            public ? static ?? void ?PrintoutEmployee()?
            ????????
            {?
            ????????????Editor?ed?
            = ?Application.DocumentManager.MdiActiveDocument.Editor;?
            ????????????Database?db?
            = ?HostApplicationServices.WorkingDatabase;?
            ????????????Transaction?trans?
            = ?db.TransactionManager.StartTransaction();?
            ????????????
            try ?
            ????????????
            {?
            ????????????????BlockTable?bt?
            = ?(BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId,?OpenMode.ForRead);?
            ????????????????BlockTableRecord?btr?
            = ?(BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],?OpenMode.ForRead);?
            ????????????????
            foreach ?(ObjectId?id? in ?btr)?
            ????????????????
            {?
            ????????????????????Entity?ent?
            = ?(Entity)trans.GetObject(id,?OpenMode.ForRead,? false );?
            ????????????????????
            if ?(ent? is ?BlockReference)?
            ????????????????????
            {?
            ????????????????????????
            string []?saEmployeeList? = ? null ;
            ????????????????
            ????????????????????????ListEmployee(id,?
            ref ?saEmployeeList);?
            ????????????????????????
            if ?((saEmployeeList.Length? == ? 4 ))?
            ????????????????????????
            {?
            ????????????????????????????ed.WriteMessage(
            " Employee?Name:?{0} " ,?saEmployeeList[ 0 ]);?
            ????????????????????????????ed.WriteMessage(
            " Employee?Salary:?{0} " ,?saEmployeeList[ 1 ]);?
            ????????????????????????????ed.WriteMessage(
            " Employee?Division:?{0} " ,?saEmployeeList[ 2 ]);?
            ????????????????????????????ed.WriteMessage(
            " Division?Manager:?{0} " ,?saEmployeeList[ 3 ]);?
            ????????????????????????}
            ?
            ????????????????????}
            ?
            ????????????????}
            ?
            ????????????}
            ?
            ????????????
            finally ?
            ????????????
            {?
            ????????????}
            ?????
            ????????}


            ????????[CommandMethod(
            " CREATE " )]?
            ????????
            public ? void ?CreateEmployee()?
            ????????
            {?
            ????????????Database?db?
            = ?HostApplicationServices.WorkingDatabase;?
            ????????????Editor?ed?
            = ?Application.DocumentManager.MdiActiveDocument.Editor;?
            ????????????Transaction?trans?
            = ?db.TransactionManager.StartTransaction();?
            ????????????
            try ?
            ????????????
            {?
            ????????????????
            string ?empName? = ?? " Earnest?Shackleton " ;
            ????????????????
            string ?divName? = ?? " Sales " ;?
            ????????????????
            double ?salary? = ? new ? double ();?
            ????????????????salary?
            = ? 10000 ;?
            ????????????????Point3d?position?
            = ? new ?Point3d( 0 ,? 0 ,? 0 );?
            ????????????????
            bool ?gotPosition? = ? new ? bool ();?
            ????????????????
            // boolean?to?check?if?a?point?has?been?entered
            ????????????????gotPosition? = ? false ;

            ????????????????
            // Prompts?for?each?employee?detail
            ????????????????PromptStringOptions?prName? = ? new ?PromptStringOptions( " Enter?Employee?Name?< " ? + ?empName? + ? " > " );?
            ????????????????PromptStringOptions?prDiv?
            = ? new ?PromptStringOptions( " Enter?Employee?Division?< " ? + ?divName? + ? " > " );?
            ????????????????PromptDoubleOptions?prSal?
            = ? new ?PromptDoubleOptions( " Enter?Employee?Salary?< " ? + ?salary? + ? " > " );?
            ????????????????PromptPointOptions?prPos?
            = ? new ?PromptPointOptions( " Enter?Employee?Position?or " );

            ????????????????
            // Add?keywords?when?prompting?for?position
            ????????????????prPos.Keywords.Add( " Name " );?
            ????????????????prPos.Keywords.Add(
            " Division " );?
            ????????????????prPos.Keywords.Add(
            " Salary " );?
            ????????????????
            // Set?conditions?for?prompting
            ????????????????prPos.AllowNone? = ? false ;? // Do?not?allow?null?values

            ????????????????
            // prompt?results
            ????????????????PromptResult?prNameRes;?
            ????????????????PromptResult?prDivRes;?
            ????????????????PromptDoubleResult?prSalRes;?
            ????????????????PromptPointResult?prPosRes;

            ????????????????
            // Loop?to?get?employee?details.?Exit?the?loop?when?positon?is?entered
            ???????????????? while ?( ! gotPosition)?
            ????????????????
            {?
            ????????????????????
            // Prompt?for?position
            ????????????????????prPosRes? = ?ed.GetPoint(prPos);?
            ????????????????????
            // Got?a?point
            ???????????????????? if ?(prPosRes.Status? == ?PromptStatus.OK)?
            ????????????????????
            {?
            ????????????????????????gotPosition?
            = ? true ;?
            ????????????????????????position?
            = ?prPosRes.Value;?
            ????????????????????}
            ?
            ????????????????????
            else ? if ?(prPosRes.Status? == ?PromptStatus.Keyword)? // Got?a?keyword
            ???????????????????? {?
            ????????????????????????
            // Name?keyword?entered
            ???????????????????????? if ?(prPosRes.StringResult? == ? " Name " )?
            ????????????????????????
            {?
            ????????????????????????????
            // Get?employee?name
            ????????????????????????????prName.AllowSpaces? = ? true ;?
            ????????????????????????????prNameRes?
            = ?ed.GetString(prName);?
            ????????????????????????????
            if ?(prNameRes.Status? != ?PromptStatus.OK)?
            ????????????????????????????
            {?
            ????????????????????????????????
            return ;?
            ????????????????????????????}
            ?
            ????????????????????????????
            // we?got?the?employee?name?successfully
            ???????????????????????????? if ?(prNameRes.StringResult? != ? "" )?
            ????????????????????????????
            {?
            ????????????????????????????????empName?
            = ?prNameRes.StringResult;?
            ????????????????????????????}
            ?
            ????????????????????????}

            ?
            ????????????????????????
            // Division?keyword?entered
            ???????????????????????? if ?(prPosRes.StringResult? == ? " Division " )?
            ????????????????????????
            {?

            ????????????????????????????
            // Get?employee?division
            ????????????????????????????prDiv.AllowSpaces? = ? true ;?
            ????????????????????????????prDivRes?
            = ?ed.GetString(prDiv);?
            ????????????????????????????
            if ?(prDivRes.Status? != ?PromptStatus.OK)?
            ????????????????????????????
            {?
            ????????????????????????????????
            return ;?
            ????????????????????????????}
            ?
            ????????????????????????????
            if ?(prDivRes.StringResult? != ? "" )?
            ????????????????????????????
            {?
            ????????????????????????????????divName?
            = ?prDivRes.StringResult;?
            ????????????????????????????}
            ?
            ????????????????????????}
            ? // ?Division

            ????????????????????????
            // ?Salary?keyword?entered
            ???????????????????????? if ?(prPosRes.StringResult? == ? " Salary " )?
            ????????????????????????
            {?
            ????????????????????????????
            // Get?employee?salary
            ????????????????????????????prSal.AllowNegative? = ? false ;?
            ????????????????????????????prSal.AllowNone?
            = ? true ;?
            ????????????????????????????prSal.AllowZero?
            = ? false ;?
            ????????????????????????????prSalRes?
            = ?ed.GetDouble(prSal);?
            ????????????????????????????
            if ?(prSalRes.Status? != ?PromptStatus.OK? & ?prSalRes.Status? != ?PromptStatus.None)?
            ????????????????????????????
            {?
            ????????????????????????????????
            return ;?
            ????????????????????????????}
            ?
            ????????????????????????????
            if ?(prSalRes.Status? != ?PromptStatus.None)?
            ????????????????????????????
            {?
            ????????????????????????????????salary?
            = ?prSalRes.Value;?
            ????????????????????????????}
            ?
            ????????????????????????}
            ? // ?Salary
            ????????????????????}
            ?
            ????????????????????
            else ?
            ????????????????????
            {?
            ????????????????????????
            // ?Error?in?getting?a?point
            ????????????????????????ed.WriteMessage( " ***Error?in?getting?a?point,?exiting!!*** " ? + ? " \r\n " );?
            ????????????????????????
            return ;?
            ????????????????????}
            ?? // ?If?got?a?point
            ????????????????}


            ????????????????
            // Create?the?Employee
            ????????????????CreateEmployee(empName,?divName,?salary,?position);

            ????????????????
            string ?manager? = ? "" ;
            ????????????????
            // Now?create?the?division?
            ????????????????
            // Pass?an?empty?string?for?manager?to?check?if?it?already?exists
            ????????????????Xrecord?depMgrXRec;?
            ????????????????ObjectId?xRecId;?
            ????????????????xRecId?
            = ?CreateDivision(divName,?manager);?
            ????????????????
            // Open?the?department?manager?XRecord
            ????????????????depMgrXRec? = ?(Xrecord)trans.GetObject(xRecId,?OpenMode.ForRead);?
            ????????????????TypedValue[]?typedVal?
            = ?depMgrXRec.Data.AsArray();
            ????????????????
            foreach ?(TypedValue?val? in ?typedVal)?
            ????????????????
            {?
            ????????????????????
            string ?str;?
            ????????????????????str?
            = ?( string )val.Value;?
            ????????????????????
            if ?(str? == ? "" )?
            ????????????????????
            {?
            ????????????????????????
            // Manager?was?not?set,?now?set?it
            ????????????????????????
            // ?Prompt?for??manager?name?first
            ????????????????????????ed.WriteMessage( " \r\n " );?
            ????????????????????????PromptStringOptions?prManagerName?
            = ? new ?PromptStringOptions( " No?manager?set?for?the?division!?Enter?Manager?Name " );?
            ????????????????????????prManagerName.AllowSpaces?
            = ? true ;?
            ????????????????????????PromptResult?prManagerNameRes?
            = ?ed.GetString(prManagerName);?
            ????????????????????????
            if ?(prManagerNameRes.Status? != ?PromptStatus.OK)?
            ????????????????????????
            {?
            ????????????????????????????
            return ;?
            ????????????????????????}
            ?
            ????????????????????????
            // Set?a?manager?name
            ????????????????????????depMgrXRec.Data? = ? new ?ResultBuffer( new ?TypedValue(( int )DxfCode.Text,?prManagerNameRes.StringResult));?
            ????????????????????}
            ?
            ????????????????}


            ????????????????trans.Commit();?
            ????????????}
            ?
            ????????????
            finally ?
            ????????????
            {?
            ????????????????trans.Dispose();?
            ????????????}
            ?
            ????????}


            ????????[CommandMethod(
            " LISTEMPLOYEES " )]?
            ????????
            public ? void ?List()?
            ????????
            {?
            ????????????Editor?ed?
            = ?Application.DocumentManager.MdiActiveDocument.Editor;?
            ????????????
            try ?
            ????????????
            {?
            ????????????????PromptSelectionOptions?Opts?
            = ? new ?PromptSelectionOptions();?
            ????????????????TypedValue[]?filList?
            = ? new ?TypedValue[ 1 ];
            ?????????????????
            // Build?a?filter?list?so?that?only?block?references?are?selected
            ????????????????filList[ 0 ]? = ? new ?TypedValue(( int )DxfCode.Start,? " INSERT " );?
            ????????????????SelectionFilter?filter?
            = ? new ?SelectionFilter(filList);?
            ????????????????PromptSelectionResult?res?
            = ?ed.GetSelection(Opts,?filter);?
            ????????????????
            // Do?nothing?if?selection?is?unsuccessful
            ???????????????? if ?(res.Status? != ?PromptStatus.OK)?
            ????????????????????????
            return ;?
            ????????????????Autodesk.AutoCAD.EditorInput.SelectionSet?SS?
            = ?res.Value;?
            ????????????????ObjectId[]?idArray;
            ????????????????idArray?
            = ?SS.GetObjectIds();?
            ????????????????
            string []?saEmployeeList? = ? new ? string [ 4 ];?
            ????????????????
            // collect?all?employee?details?in?saEmployeeList?array
            ???????????????? foreach ?(ObjectId?employeeId? in ?idArray)?
            ????????????????
            {?
            ????????????????????ListEmployee(employeeId,?
            ref ?saEmployeeList);?
            ????????????????????
            // Print?employee?details?to?the?command?line
            ???????????????????? foreach ?( string ?employeeDetail? in ?saEmployeeList)?
            ????????????????????
            {?
            ????????????????????????ed.WriteMessage(employeeDetail);?
            ????????????????????}
            ?
            ????????????????????
            // separator
            ????????????????????ed.WriteMessage( " ---------------------- " ? + ? " \r\n " );?
            ????????????????}
            ?
            ????????????}
            ??
            ????????????
            finally ?
            ????????????
            {?
            ????????????}
            ?
            ????????}


            ????????[CommandMethod(
            " Test " )]
            ????????
            public ?? void ?Test()
            ????????
            {
            ????????????CreateDivision(
            " Sales " ,? " Randolph?P.?Brokwell " );
            ????????}

            ????}

            }

            posted on 2006-06-26 17:10 夢在天涯 閱讀(2128) 評論(1)  編輯 收藏 引用 所屬分類: ARX/DBX

            評論

            # re: 很好的arx學(xué)習(xí)代碼(.net版)[未登錄] 2009-06-24 01:51 kevin

            iamwlb@qq.com
            不知道為什么我的程序執(zhí)行到database db的時候就異常了,不知道是不是不能脫離autocad運行?  回復(fù)  更多評論   

            公告

            EMail:itech001#126.com

            導(dǎo)航

            統(tǒng)計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1804430
            • 排名 - 5

            最新評論

            閱讀排行榜

            久久婷婷五月综合成人D啪| 久久精品人人做人人爽电影| 国产99久久久国产精品~~牛| 精产国品久久一二三产区区别| 亚洲精品综合久久| 国内精品久久国产| 久久人人添人人爽添人人片牛牛| 婷婷久久综合| 久久天天躁狠狠躁夜夜avapp| 欧美精品九九99久久在观看| 伊人久久国产免费观看视频| 香蕉久久久久久狠狠色| 2021国内精品久久久久久影院| 欧美性猛交xxxx免费看久久久| 香蕉久久永久视频| 国产精品久久新婚兰兰| 亚洲国产精品久久久天堂| 人妻无码久久一区二区三区免费| 亚洲国产精品无码久久一区二区| 久久夜色精品国产欧美乱| 99国产欧美精品久久久蜜芽| 久久精品国产亚洲欧美| 91麻豆精品国产91久久久久久| 久久精品国产亚洲一区二区三区| 开心久久婷婷综合中文字幕| 久久天天躁狠狠躁夜夜躁2014| 欧美丰满熟妇BBB久久久| 国产精品久久久久AV福利动漫 | 亚洲精品久久久www| 青青草原综合久久大伊人| 日本久久久久亚洲中字幕| 日本免费一区二区久久人人澡| 久久精品国产99久久久香蕉| 久久亚洲精品无码aⅴ大香| 精品久久久久久无码中文字幕一区 | 93精91精品国产综合久久香蕉| 久久久久久极精品久久久| 久久久久久久久波多野高潮| 99久久国语露脸精品国产| 久久久久久国产精品免费免费| 精品伊人久久大线蕉色首页|