Ejemplo n.º 1
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContentForm_Load(object sender, EventArgs e)
        {
            Hxj.IDBO.IDbObject dbObject = null;
            if (ConnectionModel.DbType.Equals(Dos.ORM.DatabaseType.SqlServer.ToString()))
            {
                dbObject = new Hxj.DbObjects.SQL2000.DbObject(ConnectionModel.ConnectionString);
            }
            else if (ConnectionModel.DbType.Equals(Dos.ORM.DatabaseType.SqlServer9.ToString()))
            {
                dbObject = new Hxj.DbObjects.SQL2005.DbObject(ConnectionModel.ConnectionString);
            }
            else if (ConnectionModel.DbType.Equals(Dos.ORM.DatabaseType.MsAccess.ToString()))
            {
                dbObject = new Hxj.DbObjects.OleDb.DbObject(ConnectionModel.ConnectionString);
            }
            else if (ConnectionModel.DbType.Equals(Dos.ORM.DatabaseType.Oracle.ToString()))
            {
                dbObject = new Hxj.DbObjects.Oracle.DbObject(ConnectionModel.ConnectionString);
            }
            else if (ConnectionModel.DbType.Equals(Dos.ORM.DatabaseType.Sqlite3.ToString()))
            {
                dbObject = new Hxj.DbObjects.SQLite.DbObject(ConnectionModel.ConnectionString);
            }
            else if (ConnectionModel.DbType.Equals(Dos.ORM.DatabaseType.MySql.ToString()))
            {
                dbObject = new Hxj.DbObjects.MySQL.DbObject(ConnectionModel.ConnectionString);
            }
            else
            {
                MessageBox.Show("未知数据库类型!");
                return;
            }
            columnsdt = dbObject.GetColumnInfoList(DatabaseName, TableName);

            gridColumns.DataSource = columnsdt;

            DataTable primarykeydt = dbObject.GetKeyName(DatabaseName, TableName);

            cbPrimarykey.Items.Clear();

            if (null != primarykeydt && primarykeydt.Rows.Count > 0)
            {
                foreach (DataRow dr in primarykeydt.Rows)
                {
                    cbPrimarykey.Items.Add(dr["ColumnName"].ToString());
                }

                cbPrimarykey.SelectedIndex = 0;
            }

            txtClassName.Text = TableName.Trim().Replace(' ', '_');
            txtnamespace.Text = Utils.ReadNamespace();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 测试连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (chbConnectString.Checked)
            {
                if (string.IsNullOrEmpty(txtConnectString.Text))
                {
                    MessageBox.Show("请填写连接字符串!");
                    return;
                }

                dbObject = new Hxj.DbObjects.Oracle.DbObject(txtConnectString.Text);
            }
            else
            {
                if (string.IsNullOrEmpty(cbbServer.Text))
                {
                    MessageBox.Show("请填写服务!");
                    return;
                }

                if (string.IsNullOrEmpty(txtUserName.Text))
                {
                    MessageBox.Show("请填写用户名!");
                    return;
                }

                dbObject = new Hxj.DbObjects.Oracle.DbObject(false, cbbServer.Text, txtUserName.Text, txtPassword.Text);
            }

            try
            {


                using (OracleConnection connect = new OracleConnection(dbObject.DbConnectStr))
                {
                    connect.Open();
                }


                MessageBox.Show("连接成功!");
                isConnection = true;
            }
            catch (Exception ex)
            {

                MessageBox.Show("连接失败!\n\r" + ex.Message);
                isConnection = false;

            }

        }
Ejemplo n.º 3
0
        /// <summary>
        /// 测试连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (chbConnectString.Checked)
            {
                if (string.IsNullOrEmpty(txtConnectString.Text))
                {
                    MessageBox.Show("请填写连接字符串!");
                    return;
                }

                dbObject = new Hxj.DbObjects.Oracle.DbObject(txtConnectString.Text);
            }
            else
            {
                if (string.IsNullOrEmpty(cbbServer.Text))
                {
                    MessageBox.Show("请填写服务!");
                    return;
                }

                if (string.IsNullOrEmpty(txtUserName.Text))
                {
                    MessageBox.Show("请填写用户名!");
                    return;
                }

                dbObject = new Hxj.DbObjects.Oracle.DbObject(false, cbbServer.Text, txtUserName.Text, txtPassword.Text);
            }

            try
            {
                using (OracleConnection connect = new OracleConnection(dbObject.DbConnectStr))
                {
                    connect.Open();
                }


                MessageBox.Show("连接成功!");
                isConnection = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!\n\r" + ex.Message);
                isConnection = false;
            }
        }