Ejemplo n.º 1
0
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            Document.MoveFirst(); // to avoid an error on the first 'Edit'
            int nDontCare = 0;    // don't care

            while (!Document.EOF)
            {
                Fields aFields = Document.Fields;
                Field  aField  = aFields[m_strFieldName];
                if (aField.Value != System.DBNull.Value)
                {
                    AccessRange aWordRange = new AccessRange(aField, this);

                    try
                    {
                        if (!aWordProcessor.Process(aWordRange, ref nDontCare))
                        {
                            return(false);
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        // this gets called whether we successfully process the word or not,
                        //  whether we're returning 'false' (in the try) or not, and whether we
                        //  have an exception or not... just exactly what we want, or MSAccess
                        //  process won't release when we exit.
                        OfficeApp.ReleaseComObject(aField);
                        OfficeApp.ReleaseComObject(aFields);
                    }
                }

                Document.MoveNext();
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void ConvertTableFieldDialog_Click(Office.IRibbonControl control)
        {
#if DEBUG
            MessageBox.Show("ConvertTableFieldDialog_Click");
#endif

            Database aDb = Application.CurrentDb();
            if (aDb == null)
            {
                return;
            }

            TableDefs aTableDefs = null;
            TableDef  aTableDef  = null;
            Recordset aRecordSet = null;
            try
            {
                aTableDefs = aDb.TableDefs;
                DbFieldSelect dlg = new DbFieldSelect(aTableDefs);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    aTableDef  = aTableDefs[dlg.TableName];
                    aRecordSet = aTableDef.OpenRecordset(RecordsetTypeEnum.dbOpenTable, 0);
                    // dao.RecordsetOptionEnum.);

                    if (!aRecordSet.Updatable)
                    {
                        throw new ApplicationException("Can't edit this table? Is it opened? If so, then close it and try again.");
                    }

                    string        strTitle = String.Format("Select the Converter for the {0}.{1} field", dlg.TableName, dlg.FieldName);
                    EncConverters aECs     = GetEncConverters;
                    if (aECs != null)
                    {
                        IEncConverter           aIEC            = aECs.AutoSelectWithTitle(ConvType.Unknown, strTitle);
                        FontConverter           aFC             = new FontConverter(new DirectableEncConverter(aIEC));
                        OfficeDocumentProcessor aTableProcessor = new OfficeDocumentProcessor(aFC, new SILConverterProcessorForm());
                        AccessDocument          rsDoc           = new AccessDocument(aRecordSet, dlg.FieldName);

                        // do a transaction just in case we throw an exception trying to update and the user
                        //  wants to rollback.
                        aDb.BeginTrans();
                        rsDoc.ProcessWordByWord(aTableProcessor);
                        aDb.CommitTrans((int)CommitTransOptionsEnum.dbForceOSFlush);
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
                if (ex.Message != cstrAbortMessage)
                {
                    if (MessageBox.Show("Would you like to rollback the transaction?", OfficeApp.cstrCaption, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        aDb.Rollback();
                    }
                    else
                    {
                        aDb.CommitTrans((int)CommitTransOptionsEnum.dbForceOSFlush);
                    }
                }
            }
            finally
            {
                if (aRecordSet != null)
                {
                    aRecordSet.Close();
                }
                ReleaseComObject(aRecordSet);
                ReleaseComObject(aTableDef);
                ReleaseComObject(aTableDefs);
                ReleaseComObject(aDb);
            }
        }