Exemple #1
0
        private void SelectEmployeeButton_Click(object sender, System.EventArgs e)
        {
            Database    db    = HostApplicationServices.WorkingDatabase;
            Editor      ed    = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Transaction trans = db.TransactionManager.StartTransaction();

            this.Hide();
            try
            {
                PromptEntityOptions prEnt    = new PromptEntityOptions("Select an Employee");
                PromptEntityResult  prEntRes = ed.GetEntity(prEnt);
                if (prEntRes.Status != PromptStatus.OK)
                {
                    this.Show();
                    return;
                }

                ArrayList saEmployeeList = new ArrayList();

                AsdkClass1.ListEmployee(prEntRes.ObjectId, saEmployeeList);
                if (saEmployeeList.Count == 4)
                {
                    tb_Name.Text     = saEmployeeList[0].ToString();
                    tb_Salary.Text   = saEmployeeList[1].ToString();
                    tb_Division.Text = saEmployeeList[2].ToString();
                }
            }
            finally
            {
                this.Show();
                trans.Dispose();
            }
        }
        override public void OnDrop(System.Windows.Forms.DragEventArgs e)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                Point3d pt = ed.PointToWorld(new Point(e.X, e.Y));

                using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    ModelessForm ctrl = (ModelessForm)e.Data.GetData(typeof(ModelessForm));
                    AsdkClass1.CreateDivision(ctrl.tb_Division.Text, AsdkClass1.sDivisionManager);
                    AsdkClass1.CreateEmployee(ctrl.tb_Name.Text, ctrl.tb_Division.Text, Convert.ToDouble(ctrl.tb_Salary.Text), pt);
                }
            }
            catch
            {
                ed.WriteMessage("Error handling OnDrop");
            }
        }
        override public void OnDrop(System.Windows.Forms.DragEventArgs e)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            //Get employee's coordinates in the drawing
            PromptPointOptions prPos = new PromptPointOptions("Enter Employee Position");

            prPos.AllowNone = false;

            PromptPointResult prPosRes = ed.GetPoint(prPos);

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

            DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
            ModelessForm ctrl    = (ModelessForm)e.Data.GetData(typeof(ModelessForm));

            AsdkClass1.CreateDivision(ctrl.tb_Division.Text, AsdkClass1.sDivisionManager);
            AsdkClass1.CreateEmployee(ctrl.tb_Name.Text, ctrl.tb_Division.Text, Convert.ToDouble(ctrl.tb_Salary.Text), prPosRes.Value);

            docLock.Dispose();
        }
        private void SelectEmployeeButton_Click(object sender, System.EventArgs e)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            this.Hide();
            try
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    PromptEntityOptions prEnt    = new PromptEntityOptions("Select an Employee");
                    PromptEntityResult  prEntRes = ed.GetEntity(prEnt);
                    if (prEntRes.Status != PromptStatus.OK)
                    {
                        throw new System.Exception("Error or User Cancelled");
                    }

                    ArrayList saEmployeeList = new ArrayList();

                    AsdkClass1.ListEmployee(prEntRes.ObjectId, saEmployeeList);
                    if (saEmployeeList.Count == 4)
                    {
                        tb_Name.Text     = saEmployeeList[0].ToString();
                        tb_Salary.Text   = saEmployeeList[1].ToString();
                        tb_Division.Text = saEmployeeList[2].ToString();
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error Creating Employee: " + ex.Message);
            }
            finally
            {
                this.Show();
            }
        }