コード例 #1
0
        public override List <IObjecOptions> LoadObjectNames(string containerInvariantName)
        {
            Database = Application.CurrentDb();

            ContainerNames container = AllowedContainers.Find(containerInvariantName);

            if (container == null)
            {
                throw new ArgumentException(Properties.Resources.NotAllowedObjectTypeException, "objectType");
            }

            List <IObjecOptions> lst = new List <IObjecOptions>();

            if (containerInvariantName == ObjectType.General.ToString())
            {
                lst.Add(new ObjectOptions(Properties.Resources.DatabaseProperties, ObjectType.DatabaseDao));
                lst.Add(new ObjectOptions(Properties.Resources.References, ObjectType.References));
                lst.Add(new ObjectOptions(Properties.Resources.Relations, ObjectType.Relations));
            }
            else if (IsStandardContainerName(container.InvariantName))
            {
                dao.Container daoContainer = Database.Containers[container.InvariantName];
                foreach (dao.Document doc in daoContainer.Documents)
                {
                    lst.Add(new ObjectOptions(doc.Name, container.DefaultObjectType));
                }
            }
            else
            {
                lst.AddRange(GetDaoObjects(container.InvariantName));
            }
            return(lst);
        }
コード例 #2
0
        public override void LoadMenu()
        {
            dao.Database aDb = (dao.Database)Application.CurrentDb();
            if (aDb == null)
            {
                // Application.NewCurrentDatabase
            }
            else
            {
                base.LoadMenu();

                try
                {
                    SILConvertersPopup         = (Office.CommandBarPopup)NewMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, true);
                    SILConvertersPopup.Caption = "&SIL Converters";

                    AddMenu(ref ConvertFieldMenu, this.SILConvertersPopup, "&Convert a field in a table",
                            "Click this item to convert a field in a table with a converter from the system repository",
                            new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(ConvertTableFieldDialog_Click));
                }
                catch (Exception ex)
                {
                    DisplayException(ex);
                }
            }

            ReleaseComObject(aDb);
        }
コード例 #3
0
        public override void OpenDatabase()
        {
            //TODO: Check for password protected databases
            //TODO: Check for databases attached to workgroup database
            string fullFileName = System.IO.Path.GetFullPath(FileName);

            dao.Database db = Application.DBEngine.OpenDatabase(System.IO.Path.GetFullPath(fullFileName));
            try {
                if (double.Parse(db.Version, System.Globalization.CultureInfo.InvariantCulture) < 4.0)
                {
                    throw new Exception(Properties.ImportRes.InvalidFileFormat);
                }
                else
                {
                    string accVersion = db.Properties["AccessVersion"].Value.ToString();
                    accVersion = accVersion.Substring(0, accVersion.IndexOf('.'));
                    if (int.Parse(accVersion) < 9)
                    {
                        throw new Exception(Properties.ImportRes.InvalidFileFormat);
                    }
                }
            } finally {
                db.Close();
            }
            Application.OpenCurrentDatabase(fullFileName);
        }
コード例 #4
0
        public override void CreateDatabase(Dictionary <string, object> databaseProperties)
        {
            //Could call to Application.NewCurrentDatabase, but this method has no options
            //TODO: Add support for Access Version, ¿password, encryption?
            Locales databaseLocales = new Locales();
            string  collating       = databaseProperties["CollatingOrder"].ToString().Substring(2);

            dao.Database db = Application.DBEngine.CreateDatabase(FileName, databaseLocales[collating]);
            db.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(db);
            Application.OpenCurrentDatabase(FileName);
        }
コード例 #5
0
        public override void LoadMenu()
        {
            dao.Database aDb = (dao.Database)Application.CurrentDb();
            if (aDb == null)
            {
                // Application.NewCurrentDatabase
            }
            else
            {
                base.LoadMenu();

                try
                {
                    SILConvertersPopup         = (Office.CommandBarPopup)NewMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, true);
                    SILConvertersPopup.Caption = "&SIL Converters";

#if !UseDialogBoxToGetTableField
                    foreach (dao.TableDef aTable in aDb.TableDefs)
                    {
                        if (aTable.Attributes == 0)                         // don't want system tables
                        {
                            Office.CommandBarPopup aPopup = (Office.CommandBarPopup)SILConvertersPopup.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, true);
                            aPopup.Caption = aTable.Name;

                            List <Office.CommandBarButton> aListOfCommandButtons = new List <Microsoft.Office.Core.CommandBarButton>();
                            foreach (dao.Field aField in aTable.Fields)
                            {
                                Office.CommandBarButton aFieldButton = null;
                                AddMenu(ref aFieldButton, aPopup, aField.Name, aTable.Name,
                                        new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(ConvertTableField_Click));
                                aListOfCommandButtons.Add(aFieldButton);
                            }

                            m_listTablePopups.Add(aPopup, aListOfCommandButtons);
                        }
                    }
#else
                    AddMenu(ref ConvertFieldMenu, this.SILConvertersPopup, "&Convert a field in a table",
                            "Click this item to convert a field in a table with a converter from the system repository",
                            new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(ConvertTableFieldDialog_Click));
#endif
                }
                catch (Exception ex)
                {
                    DisplayException(ex);
                }
            }

            ReleaseComObject(aDb);
        }
コード例 #6
0
        void ConvertTableFieldDialog_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
#endif
        {
#if DEBUG
            MessageBox.Show("ConvertTableFieldDialog_Click");
#endif
            dao.Database aDb = Application.CurrentDb();
            if (aDb == null)
            {
                return;
            }

            dao.TableDefs aTableDefs = null;
            dao.TableDef  aTableDef  = null;
            dao.Recordset aRecordSet = null;
            try
            {
                aTableDefs = aDb.TableDefs;
                DbFieldSelect dlg = new DbFieldSelect(aTableDefs);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    aTableDef  = aTableDefs[dlg.TableName];
                    aRecordSet = aTableDef.OpenRecordset(dao.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)dao.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)dao.CommitTransOptionsEnum.dbForceOSFlush);
                    }
                }
            }
            finally
            {
                if (aRecordSet != null)
                {
                    aRecordSet.Close();
                }
                ReleaseComObject(aRecordSet);
                ReleaseComObject(aTableDef);
                ReleaseComObject(aTableDefs);
                ReleaseComObject(aDb);
            }
        }