Example #1
0
        private void Button3_Click(object sender, EventArgs e)
        {
            Class36.SetFocus(Application.DocumentManager.MdiActiveDocument.Window.Handle);
            DocumentLock documentLock      = Application.DocumentManager.MdiActiveDocument.LockDocument();
            Document     mdiActiveDocument = Application.DocumentManager.MdiActiveDocument;

            mdiActiveDocument.SendStringToExecute("\u0003\u0003", false, false, false);
            Database database = mdiActiveDocument.Database;
            long     value    = 0L;

            this.ListBox1.Items.Clear();
            if (this.CheckBox1.Checked)
            {
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    BlockTable       blockTable       = (BlockTable)transaction.GetObject(database.BlockTableId, 1);
                    BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], 1);
                    try
                    {
                        foreach (ObjectId objectId in blockTable)
                        {
                            BlockTableRecord blockTableRecord2 = (BlockTableRecord)transaction.GetObject(objectId, 1);
                            try
                            {
                                foreach (ObjectId objectId2 in blockTableRecord2)
                                {
                                    if (Operators.CompareString(Class36.amIrsvPmtO(objectId2), "DBText", false) == 0)
                                    {
                                        DBText dbtext     = (DBText)transaction.GetObject(objectId2, 1);
                                        string textString = dbtext.TextString;
                                        string text       = textString.Replace(this.TextBox1.Text, this.TextBox2.Text);
                                        if (Operators.CompareString(textString, text, false) != 0)
                                        {
                                            dbtext.TextString = text;
                                            Interlocked.Increment(ref value);
                                            this.ListBox1.Items.Add(string.Concat(new string[]
                                            {
                                                Conversions.ToString(value),
                                                "    ",
                                                textString,
                                                "   ",
                                                text
                                            }));
                                        }
                                    }
                                }
                            }
                            finally
                            {
                                BlockTableRecordEnumerator enumerator2;
                                if (enumerator2 != null)
                                {
                                    enumerator2.Dispose();
                                }
                            }
                        }
                    }
                    finally
                    {
                        SymbolTableEnumerator enumerator;
                        if (enumerator != null)
                        {
                            enumerator.Dispose();
                        }
                    }
                    transaction.Commit();
                    goto IL_339;
                }
            }
            checked
            {
                using (Transaction transaction2 = database.TransactionManager.StartTransaction())
                {
                    long num  = 0L;
                    long num2 = this.long_0 - 1L;
                    this.long_1 = num;
                    for (;;)
                    {
                        long num3 = this.long_1;
                        long num4 = num2;
                        if (num3 > num4)
                        {
                            break;
                        }
                        DBText dbtext2     = (DBText)transaction2.GetObject(this.selectionSet_0[(int)this.long_1].ObjectId, 1);
                        string textString2 = dbtext2.TextString;
                        string text2       = textString2.Replace(this.TextBox1.Text, this.TextBox2.Text);
                        if (Operators.CompareString(textString2, text2, false) != 0)
                        {
                            dbtext2.TextString = text2;
                            Interlocked.Increment(ref value);
                            this.ListBox1.Items.Add(string.Concat(new string[]
                            {
                                Conversions.ToString(value),
                                "    ",
                                textString2,
                                "   ",
                                text2
                            }));
                        }
                        this.long_1 += 1L;
                    }
                    transaction2.Commit();
                }
IL_339:
                database.Regenmode = true;
                documentLock.Dispose();
                this.Label3.Text     = Conversions.ToString(value) + "个替换完毕";
                this.Button3.Enabled = false;
                this.Button2.Enabled = false;
            }
        }