예제 #1
0
        private void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            var fileDialog = new System.Windows.Forms.OpenFileDialog();
            var result     = fileDialog.ShowDialog();

            string fileName = null;

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                lblMessage.Text = string.Empty;

                fileName = fileDialog.FileName;

                if (fileName != string.Empty && fileName.Contains(".mdb"))
                {
                    F1Mdb.OpenConnection(fileName);

                    if (F1Mdb.IsConnected)
                    {
                        MainWindow mainWindow = new MainWindow();
                        mainWindow.exporter = new F1Mdb();
                        mainWindow.Show();
                        this.Close();
                    }
                    else
                    {
                        lblMessage.Text = $"Could not open the MDB database file. {F1Mdb.ErrorMessage}";
                    }
                }
                else
                {
                    lblMessage.Text = "Please choose a MDB database file.";
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Handles the Click event of the btnFileUpload control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnFileUpload_Click(object sender, RoutedEventArgs e)
        {
            var fileDialog = new System.Windows.Forms.OpenFileDialog();
            var result     = fileDialog.ShowDialog();

            string fileName = null;

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                lblMessage_MDB.Text = string.Empty;

                fileName = fileDialog.FileName;

                bool isValidFileName = fileName.ToLower().Contains(".mdb") ||
                                       (Environment.Is64BitProcess && fileName.ToLower().Contains(".accdb"));

                if (isValidFileName)
                {
                    F1Mdb.OpenConnection(fileName);

                    if (F1Mdb.IsConnected)
                    {
                        MainWindow mainWindow = new MainWindow();
                        mainWindow.exporter = new F1Mdb();
                        mainWindow.Show();
                        this.Close();
                    }
                    else
                    {
                        lblMessage_MDB.Text = $"Could not open the MDB database file. {F1Mdb.ErrorMessage}";
                    }
                }
                else
                {
                    lblMessage_MDB.Text = "Please choose an Access database (MDB) file.";
                    if (Environment.Is64BitProcess)
                    {
                        lblMessage_MDB.Text = "Please choose an Access database (MDB or ACCDB) file.";
                    }
                }
            }
        }