Esempio n. 1
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start access
            _accessApplication = new Access.Application();

            Office.CommandBarButton commandBarBtn = null;

            // create database name
            string fileExtension = GetDefaultExtension(_accessApplication);
            string documentFile  = string.Format("{0}\\Example05{1}", _hostApplication, fileExtension);

            // delete old database if exists
            if (System.IO.File.Exists(documentFile))
            {
                System.IO.File.Delete(documentFile);
            }

            // create database
            DAO.Database newDatabase = _accessApplication.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral);

            // add a commandbar popup
            Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)_accessApplication.CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarPopup.Caption = "commandBarPopup";

            #region few words, how to access the picture

            /*
             * you can see we use an own icon via .PasteFace()
             * is not possible from outside process boundaries to use the PictureProperty directly
             * the reason for is IPictureDisp: http://support.microsoft.com/kb/286460/de
             * its not important is early or late binding or managed or unmanaged, the behaviour is always the same
             * For example, a COMAddin running as InProcServer and can access the Picture Property
             */
            #endregion

            #region CommandBarButton

            // add a button to the popup
            commandBarBtn         = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarBtn.Style   = MsoButtonStyle.msoButtonIconAndCaption;
            commandBarBtn.Caption = "commandBarButton";
            Clipboard.SetDataObject(_hostApplication.DisplayIcon.ToBitmap());
            commandBarBtn.PasteFace();
            commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

            #endregion

            // make visible
            _accessApplication.Visible = true;
            buttonStartExample.Enabled = false;
            buttonQuitExample.Enabled  = true;
        }
Esempio n. 2
0
        public void RunExample()
        {
            // start access
            Access.Application accessApplication = new Access.Application();

            // create a utils instance, not need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(accessApplication);

            // create database file name
            string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example02", Access.Tools.DocumentFormat.Normal);

            // delete old database if exists
            if (System.IO.File.Exists(documentFile))
            {
                System.IO.File.Delete(documentFile);
            }

            // create database
            DAO.Database newDatabase = accessApplication.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral);
            accessApplication.DBEngine.Workspaces[0].Close();

            // setup database connection                         'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007
            OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile);

            oleConnection.Open();

            // create table
            OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection);

            oleCreateCommand.ExecuteReader().Close();

            // write some data with plain sql & close
            for (int i = 0; i < 1000; i++)
            {
                string       insertCommand    = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString());
                OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection);
                oleInsertCommand.ExecuteReader().Close();
            }
            oleConnection.Close();

            // close access and dispose reference
            accessApplication.Quit(AcQuitOption.acQuitSaveAll);
            accessApplication.Dispose();

            // show dialog for the user(you!)
            HostApplication.ShowFinishDialog(null, documentFile);
        }
Esempio n. 3
0
        private void InitPluginContext(IPluginContext2 pluginContext)
        {
            if (this._IsInit)
            {
                return;
            }

            this._PluginContext = pluginContext;

            this.db = (dao.Database)
                      NetOffice.Factory.CreateKnownObjectFromComProxy(
                null,
                this.PluginContext.Database.CurrentDb(),
                typeof(dao.Database));

            this.PopulateTableDropdown();

            this._IsInit = true;
        }
Esempio n. 4
0
        public TestResult DoTest()
        {
            Access.Application application = null;
            DateTime           startTime   = DateTime.Now;

            try
            {
                application = new Access.Application();

                // create database name
                string fileExtension = GetDefaultExtension(application);
                string documentFile  = string.Format("{0}\\Test01{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileExtension);

                // delete old database if exists
                if (System.IO.File.Exists(documentFile))
                {
                    System.IO.File.Delete(documentFile);
                }

                // create database
                DAO.Database newDatabase = application.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral);

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    // close access and dispose reference
                    application.Quit(AcQuitOption.acQuitSaveNone);
                    application.Dispose();
                }
            }
        }
Esempio n. 5
0
        private void ShowDatabaseInfo(string filePath)
        {
            // start access
            Access.Application accessApplication = COMObject.Create <Access.Application>();

            // open database
            DAO.Database database = accessApplication.DBEngine.Workspaces[0].OpenDatabase(filePath);

            TreeNode tnTableDefs = treeViewInfo.Nodes.Add("Tables");

            foreach (DAO.TableDef item in database.TableDefs)
            {
                tnTableDefs.Nodes.Add(item.Name);
            }

            TreeNode tnQueryDefs = treeViewInfo.Nodes.Add("Queries");

            foreach (DAO.QueryDef item in database.QueryDefs)
            {
                tnQueryDefs.Nodes.Add(item.Name);
            }

            TreeNode tnRelations = treeViewInfo.Nodes.Add("Relations");

            foreach (DAO.Relation item in database.Relations)
            {
                tnRelations.Nodes.Add(item.Name);
            }

            TreeNode tnContainers = treeViewInfo.Nodes.Add("Containers");

            foreach (DAO.Container item in database.Containers)
            {
                tnContainers.Nodes.Add(item.Name);
            }
        }
Esempio n. 6
0
        public TestResult DoTest()
        {
            Access.Application application = null;
            DateTime           startTime   = DateTime.Now;

            try
            {
                application = COMObject.Create <Access.Application>(COMObjectCreateOptions.CreateNewCore);

                // create database name
                string fileExtension = GetDefaultExtension(application);
                string documentFile  = string.Format("{0}\\Test3{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileExtension);

                // delete old database if exists
                if (System.IO.File.Exists(documentFile))
                {
                    System.IO.File.Delete(documentFile);
                }

                // create database
                DAO.Database newDatabase = application.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral);
                application.DBEngine.Workspaces[0].Close();

                // setup database connection                        'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007
                OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile);
                oleConnection.Open();

                // create table
                OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection);
                oleCreateCommand.ExecuteReader().Close();

                // write some data with plain sql & close
                for (int i = 0; i < 20000; i++)
                {
                    string       insertCommand    = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString());
                    OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection);
                    oleInsertCommand.ExecuteReader().Close();
                }
                oleConnection.Close();

                // now we do CompactDatabase
                string newDocumentFile = string.Format("{0}\\CompactDatabase{1}", Environment.CurrentDirectory, fileExtension);
                if (File.Exists(newDocumentFile))
                {
                    File.Delete(newDocumentFile);
                }

                application.DBEngine.CompactDatabase(documentFile, newDocumentFile);


                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    // close access and dispose reference
                    application.Quit(AcQuitOption.acQuitSaveNone);
                    application.Dispose();
                }
            }
        }
        private void InitPluginContext(IPluginContext2 pluginContext)
        {
            if (this._IsInit)
                return;

            this._PluginContext = pluginContext;

            this.db = (dao.Database)
                    NetOffice.Factory.CreateKnownObjectFromComProxy(
                        null,
                        this.PluginContext.Database.CurrentDb(),
                        typeof(dao.Database));

            this.PopulateTableDropdown();

            this._IsInit = true;
        }