示例#1
0
        //DbConnectionStringBuilder cnnInfo;
        /// <summary>
        /// Obtains the meta data collection string of the project file path input by the user
        /// </summary>
        private void GetMetaConnectionString()
        {
            IDbDriverFactory metaDBFactory = GetSelectedCollectedDataDriver();
            DbDriverInfo     dbInfo        = new DbDriverInfo();

            dbInfo.DBCnnStringBuilder = metaDBFactory.RequestNewConnection(txtCollectedData.Text.Trim());
            this.MetaDBInfo           = dbInfo;
            if (this.metaDbInfo.DBCnnStringBuilder != null)
            {
                metadataConnectionString = this.metaDbInfo.DBCnnStringBuilder.ConnectionString;
            }
        }
        private void SetupOutputDataSource()
        {
            try
            {
                ComboBoxItem     selectedPlugIn = cmbDataFormats.SelectedItem as ComboBoxItem;
                IDbDriverFactory dbFactory      = null;

                string plugin = string.Empty;
                foreach (Epi.DataSets.Config.DataDriverRow row in dashboardHelper.Config.DataDrivers)
                {
                    string content = selectedPlugIn.Content.ToString();
                    if (content.Equals(row.DisplayName))
                    {
                        plugin = row.Type;
                    }
                }

                selectedDataProvider = plugin;
                bool isFlatFile = false;
                dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(plugin);
                if (dbFactory.ArePrerequisitesMet())
                {
                    DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder();
                    db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder);

                    IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb();
                    dialog.ShouldIgnoreNonExistance = true;

                    System.Windows.Forms.DialogResult result = ((System.Windows.Forms.Form)dialog).ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        //this.savedConnectionStringDescription = dialog.ConnectionStringDescription;
                        bool success = false;
                        db.ConnectionString = dialog.DbConnectionStringBuilder.ToString();
                        DbDriverInfo dbInfo = new DbDriverInfo();
                        dbInfo.DBCnnStringBuilder = dbFactory.RequestNewConnection(db.DataSource);

                        if (db.ConnectionDescription.ToLower().Contains("csv file:"))
                        {
                            isFlatFile = true;
                        }

                        if (!isFlatFile)
                        {
                            if (!db.CheckDatabaseExistance(db.ConnectionString, "", true))
                            {
                                dbFactory.CreatePhysicalDatabase(dbInfo);
                            }

                            try
                            {
                                success = db.TestConnection();
                            }
                            catch
                            {
                                success = false;
                                MessageBox.Show("Could not connect to selected data source.");
                            }
                        }
                        else
                        {
                            success = true;
                        }

                        if (success)
                        {
                            this.SelectedDataSource       = db;
                            controlNeedsRefresh           = true;
                            txtConnectionInformation.Text = db.ConnectionString;
                        }
                        else
                        {
                            this.SelectedDataSource = null;
                        }
                    }
                    else
                    {
                        this.SelectedDataSource = null;
                    }
                }
                else
                {
                    MessageBox.Show(dbFactory.PrerequisiteMessage, "Prerequisites not found");
                }

                if (selectedDataSource is IDbDriver)
                {
                    db = selectedDataSource as IDbDriver;
                    //this.txtDataSource.Text = db.ConnectionString;

                    if (!isFlatFile)
                    {
                        System.Collections.Generic.List <string> tableNames = db.GetTableNames();
                        foreach (string tableName in tableNames)
                        {
                            ComboBoxItem newItem = new ComboBoxItem();//tableName, tableName, tableName);
                            newItem.Content = tableName;
                            cmbDestinationTable.Items.Add(tableName);
                            //this.cmbDataTable.Items.Add(newItem);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SetErrorMessage(ex.Message);
            }
            finally
            {
                messagePanel.Visibility = System.Windows.Visibility.Hidden;
            }
        }