예제 #1
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, "Example01", 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);

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

            // show dialog for the user(you!)
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #2
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();
                }
            }
        }
예제 #3
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}\\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();
                }
            }
        }
예제 #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();
                }
            }
        }
예제 #5
0
        public void RunExample()
        {
            // start access
            Access.Application accessApplication = new Access.Application();

            // create database name
            string fileExtension = GetDefaultExtension(accessApplication);
            string documentFile  = string.Format("{0}\\Example01{1}", _hostApplication.RootDirectory, 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);

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

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #6
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, "Example01", 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);

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

            // show dialog for the user(you!)
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #7
0
        public void RunExample()
        {
            // start access
            Access.Application accessApplication = new Access.Application();

            // create a utils instance, no 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, "Example03", 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 < 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();

            // delete old file if exists
            string newDocumentFile = utils.File.Combine(HostApplication.RootDirectory, "Example03_Compacted", DocumentFormat.Normal);

            if (File.Exists(newDocumentFile))
            {
                File.Delete(newDocumentFile);
            }

            // now we do CompactDatabase
            accessApplication.DBEngine.CompactDatabase(documentFile, newDocumentFile);

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

            // show end dialog
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #8
0
        public TestResult DoTest()
        {
            Access.Application application = null;
            DateTime           startTime   = DateTime.Now;

            try
            {
                Bitmap iconBitmap = new Bitmap(System.Reflection.Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("AccessTestsCSharp.Test04.bmp"));
                application = COMObject.Create <Access.Application>(COMObjectCreateOptions.CreateNewCore);

                Office.CommandBarButton commandBarBtn;

                // create database name
                string fileExtension = GetDefaultExtension(application);
                string documentFile  = string.Format("{0}\\Test4{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);

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

                #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(iconBitmap);
                commandBarBtn.PasteFace();
                commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

                #endregion

                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();
                }
            }
        }
예제 #9
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}\\Test2{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 < 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();

                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();
                }
            }
        }
예제 #10
0
        public TestResult DoTest()
        {
            Access.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                Bitmap iconBitmap = new Bitmap(System.Reflection.Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("AccessTestsCSharp.Test04.bmp"));
                application = new Access.Application();

                Office.CommandBarButton commandBarBtn;

                // create database name 
                string fileExtension = GetDefaultExtension(application);
                string documentFile = string.Format("{0}\\Test4{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);

                // add a commandbar popup
                Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)application.CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarPopup.Caption = "commandBarPopup";
                  
                #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(iconBitmap);
                commandBarBtn.PasteFace();
                commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

                #endregion

                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();
                }
            }
        }
예제 #11
0
파일: Addin.cs 프로젝트: toroerp/NetOffice
 void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
     try
     {
         _accessApplication = COMObject.Create <Access.Application>(Application, COMObjectCreateOptions.CreateNewCore);
     }
     catch (Exception exception)
     {
         string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message);
         MessageBox.Show(message, _progId, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #12
0
 void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
     try
     {
         _accessApplication = new Access.Application(null, Application);
     }
     catch (Exception exception)
     {
         string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message);
         MessageBox.Show(message, _progId, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #13
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;
        }
예제 #14
0
        /// <summary>
        /// returns the valid file extension for the instance. for example ".mdb" or ".accdb"
        /// </summary>
        /// <param name="application">the instance</param>
        /// <returns>the extension</returns>
        private static string GetDefaultExtension(Access.Application application)
        {
            // Access 2000 doesnt have the Version property(unfortunately)
            // we check for support with the SupportEntity method, implemented by NetOffice
            if (!application.EntityIsAvailable("Version"))
                return ".mdb";

            double Version = Convert.ToDouble(application.Version);
            if (Version >= 120.00)
                return ".accdb";
            else
                return ".mdb";
        }
예제 #15
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, "Example03", 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 < 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();

            // delete old file if exists
            string newDocumentFile = string.Format("{0}\\CompactDatabase{1}", HostApplication, utils.File.FileExtension(Access.Tools.DocumentFormat.Normal));
            if (File.Exists(newDocumentFile))
                File.Delete(newDocumentFile);

            // now we do CompactDatabase            
            accessApplication.DBEngine.CompactDatabase(documentFile, newDocumentFile);

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

            // show dialog for the user(you!)
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #16
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; 
        }
예제 #17
0
        public void RunExample()
        {
            // start access
            Access.Application accessApplication = new Access.Application();

            // create database name
            string fileExtension = GetDefaultExtension(accessApplication);
            string documentFile  = string.Format("{0}\\Example02{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);
            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);
        }
예제 #18
0
        /// <summary>
        /// Creates an instance of the class
        /// </summary>
        /// <param name="application"></param>
        /// <exception cref="ArgumentNullException">given application is null</exception>
        /// <exception cref="ObjectDisposedException">given application is already disposed</exception>
        public FileUtils(Access.Application application)
        {
            if (null == application)
            {
                throw new ArgumentNullException("application");
            }
            if (application.IsDisposed)
            {
                throw new ObjectDisposedException("application");
            }

            double?version = NetOffice.OfficeApi.Tools.Contribution.CommonUtils.TryGetApplicationVersion(application);

            if (null != version && version >= 12.00)
            {
                _applicationIs2007OrHigher = true;
            }
        }
예제 #19
0
        public void RunExample()
        {
            // start access 
            Access.Application accessApplication = new Access.Application();

            // create database name 
            string fileExtension = GetDefaultExtension(accessApplication);
            string documentFile = string.Format("{0}\\Example02{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);
            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);
        }
예제 #20
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start access
            _accessApplication = new Access.Application();
            CommonUtils utils = new CommonUtils(_accessApplication);

            Office.CommandBarButton commandBarBtn = null;

            // add a commandbar popup
            Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)_accessApplication.CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, null, null, null, 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, null, null, null, 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;
        }
예제 #21
0
        public void RunExample()
        {
            // start access 
            Access.Application accessApplication = new Access.Application();
             
            // create database name 
            string fileExtension = GetDefaultExtension(accessApplication);
            string documentFile = string.Format("{0}\\Example01{1}", _hostApplication.RootDirectory, 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);

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

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #22
0
        private void CreateOfficeApplication()
        {
            switch (_officeApp)
            {
            case "Excel":
                _excelApplication = new Excel.Application("Excel.Application");
                break;

            case "Word":
                _wordApplication = new Word.Application("Word.Application");
                break;

            case "Outlook":
                _outlookApplication = new Outlook.Application("Outlook.Application");
                break;

            case "Power Point":
                _powerpointApplication = new PowerPoint.Application("PowerPoint.Application");
                break;

            case "Access":
                _accessApplication = new Access.Application("Access.Application");
                break;

            case "Project":
                _projectApplication = new Project.Application("MSProject.Application");
                break;

            case "Visio":
                _visioApplication = new Visio.Application("Visio.Application");
                break;

            default:
                throw new ArgumentOutOfRangeException("officeApp");
            }
        }
예제 #23
0
        private void ShowDatabaseInfo(string filePath)
        {
            // start access 
            Access.Application accessApplication = new 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);
        }
예제 #24
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);
            }
        }
예제 #25
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start access
            _accessApplication = new Access.Application();
            CommonUtils utils = new CommonUtils(_accessApplication);
            Office.CommandBarButton commandBarBtn = null;

            // add a commandbar popup
            Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)_accessApplication.CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, null, null, null, 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, null, null, null, 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;
        }
예제 #26
0
 private void CreateOfficeApplication()
 {
     switch (_officeApp)
     {
         case "Excel":
             _excelApplication = new Excel.Application("Excel.Application");
             break;
         case "Word":
             _wordApplication = new Word.Application("Word.Application");
             break;
         case "Outlook":
             _outlookApplication = new Outlook.Application("Outlook.Application");
             break;
         case "Power Point":
             _powerpointApplication = new PowerPoint.Application("PowerPoint.Application");
             break;
         case "Access":
             _accessApplication = new Access.Application("Access.Application");
             break;
         case "Project":
             _projectApplication = new Project.Application("MSProject.Application");
             break;
         case "Visio":
             _visioApplication = new Visio.Application("Visio.Application");
             break;
         default:
             throw new ArgumentOutOfRangeException("officeApp");
     }
 }