コード例 #1
0
		/// <summary>
		/// The bt select connection_ click.
		/// </summary>
		/// <param name="sender">
		/// The sender.
		/// </param>
		/// <param name="e">
		/// The e.
		/// </param>
		private void BtSelectConnectionClick(object sender, EventArgs e)
		{
			DBType dbType           = null;
			string connectionString = null;
			string connectionName   = null;
			bool   isODBC           = false;
			bool   isDialogResultOk = false;

			if (cbDataBaseType.SelectedItem != null)
			{
				dbType = cbDataBaseType.SelectedItem as DBType;

				switch (dbType.Id)
				{
					case QuerySource.MSSQL:
						DataConnectionDialog dataConnectionDialog = GetDataConnectionDialog();

						if (DataConnectionDialog.Show(dataConnectionDialog) == DialogResult.OK)
						{
							isDialogResultOk = true;

							connectionString = dataConnectionDialog.ConnectionString;
							connectionName   = (dataConnectionDialog.ConnectionProperties["Dsn"] as string)
								?? (dataConnectionDialog.ConnectionProperties["Data Source"] as string);
							isODBC           = (dataConnectionDialog.SelectedDataSource == DataSource.OdbcDataSource);
						}
						break;

					case QuerySource.SQLite:
						InternalSqliteConnectionDialog sqliteConnectionDialog = CreateInternalSqliteConnectionDialog();

						if (sqliteConnectionDialog.ShowDialog() == DialogResult.OK)
						{
							isDialogResultOk = true;

							connectionString = sqliteConnectionDialog.ConnectionString;
							connectionName   = sqliteConnectionDialog.ConnectionString;
							isODBC = false;
						}
						break;

					case QuerySource.NetworkInformation:
						NetworkInformationConnectionDialog networkConnectionDialog = new NetworkInformationConnectionDialog();

						if (networkConnectionDialog.ShowDialog() == DialogResult.OK)
						{
							isDialogResultOk = true;

							connectionString = networkConnectionDialog.ConnectionString;
							connectionName   = networkConnectionDialog.ConnectionString;
							isODBC = false;
						}
						break;

					default:
						NonSqlDataConnectionDialog nonSqlDataConnectionDialog = new NonSqlDataConnectionDialog();

						if (nonSqlDataConnectionDialog.ShowDialog() == DialogResult.OK)
						{
							isDialogResultOk = true;

							connectionString = nonSqlDataConnectionDialog.ConnectionString;
							connectionName   = nonSqlDataConnectionDialog.ConnectionString;
							isODBC           = false;
						}
						break;
				}

				if (isDialogResultOk)
				{
					selectSqlConnection(
						connectionString,
						dbType,
						connectionName,
						isODBC
					);
				}
			}
		}
コード例 #2
0
        /// <summary>
        /// The bt select connection_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void BtSelectConnectionClick(object sender, EventArgs e)
        {
            DBType dbType           = null;
            string connectionString = null;
            string connectionName   = null;
            bool   isODBC           = false;
            bool   isDialogResultOk = false;

            if (cbDataBaseType.SelectedItem != null)
            {
                dbType = cbDataBaseType.SelectedItem as DBType;

                switch (dbType.Id)
                {
                case QuerySource.MSSQL:
                    DataConnectionDialog dataConnectionDialog = GetDataConnectionDialog();

                    if (DataConnectionDialog.Show(dataConnectionDialog) == DialogResult.OK)
                    {
                        isDialogResultOk = true;

                        connectionString = dataConnectionDialog.ConnectionString;
                        connectionName   = (dataConnectionDialog.ConnectionProperties["Dsn"] as string)
                                           ?? (dataConnectionDialog.ConnectionProperties["Data Source"] as string);
                        isODBC = (dataConnectionDialog.SelectedDataSource == DataSource.OdbcDataSource);
                    }
                    break;

                case QuerySource.SQLite:
                    InternalSqliteConnectionDialog sqliteConnectionDialog = CreateInternalSqliteConnectionDialog();

                    if (sqliteConnectionDialog.ShowDialog() == DialogResult.OK)
                    {
                        isDialogResultOk = true;

                        connectionString = sqliteConnectionDialog.ConnectionString;
                        connectionName   = sqliteConnectionDialog.ConnectionString;
                        isODBC           = false;
                    }
                    break;

                case QuerySource.NetworkInformation:
                    NetworkInformationConnectionDialog networkConnectionDialog = new NetworkInformationConnectionDialog();

                    if (networkConnectionDialog.ShowDialog() == DialogResult.OK)
                    {
                        isDialogResultOk = true;

                        connectionString = networkConnectionDialog.ConnectionString;
                        connectionName   = networkConnectionDialog.ConnectionString;
                        isODBC           = false;
                    }
                    break;

                default:
                    NonSqlDataConnectionDialog nonSqlDataConnectionDialog = new NonSqlDataConnectionDialog();

                    if (nonSqlDataConnectionDialog.ShowDialog() == DialogResult.OK)
                    {
                        isDialogResultOk = true;

                        connectionString = nonSqlDataConnectionDialog.ConnectionString;
                        connectionName   = nonSqlDataConnectionDialog.ConnectionString;
                        isODBC           = false;
                    }
                    break;
                }

                if (isDialogResultOk)
                {
                    selectSqlConnection(
                        connectionString,
                        dbType,
                        connectionName,
                        isODBC
                        );
                }
            }
        }