📄 databaseobject_brows.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace TreeReportApp
{
/// <summary>
/// DatabaseObject_brows 的摘要说明。
/// </summary>
public class DatabaseObject_brows : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox_objectlist;
private System.Data.OleDb.OleDbConnection conn;
private System.Windows.Forms.Button button_ok;
private System.Windows.Forms.Button button_exit;
public string objectname="";
public string objecttype="";
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public DatabaseObject_brows()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.listBox_objectlist = new System.Windows.Forms.ListBox();
this.conn = new System.Data.OleDb.OleDbConnection();
this.button_ok = new System.Windows.Forms.Button();
this.button_exit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// listBox_objectlist
//
this.listBox_objectlist.ItemHeight = 12;
this.listBox_objectlist.Location = new System.Drawing.Point(0, 8);
this.listBox_objectlist.Name = "listBox_objectlist";
this.listBox_objectlist.Size = new System.Drawing.Size(192, 268);
this.listBox_objectlist.TabIndex = 0;
//
// button_ok
//
this.button_ok.Location = new System.Drawing.Point(16, 289);
this.button_ok.Name = "button_ok";
this.button_ok.Size = new System.Drawing.Size(64, 24);
this.button_ok.TabIndex = 1;
this.button_ok.Text = "选 取";
this.button_ok.Click += new System.EventHandler(this.button_ok_Click);
//
// button_exit
//
this.button_exit.Location = new System.Drawing.Point(109, 290);
this.button_exit.Name = "button_exit";
this.button_exit.Size = new System.Drawing.Size(64, 24);
this.button_exit.TabIndex = 1;
this.button_exit.Text = "退 出";
this.button_exit.Click += new System.EventHandler(this.button_exit_Click);
//
// DatabaseObject_brows
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(192, 323);
this.Controls.Add(this.button_ok);
this.Controls.Add(this.listBox_objectlist);
this.Controls.Add(this.button_exit);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(200, 350);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(200, 350);
this.Name = "DatabaseObject_brows";
this.Text = "数据库对象";
this.Load += new System.EventHandler(this.DatabaseObject_brows_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// DatabaseObject_brows_Load -查库中所有的用户数据表 ,供用户选择
/// 不同数据库,数据字典的管理方式,存放表都不同,访问方法也不同,
/// 例:Oracle用视图方法,SQLServer用存储过程,多种数据库化时,此函数要修改
/// </summary>
private void DatabaseObject_brows_Load(object sender, System.EventArgs e)
{
//连接据库,这段程序用一个公共连接类代替
conn.ConnectionString = TreeConnection.connstr;
//conn.ConnectionString = "Provider=SQLOLEDB.1;Password=20020830;Persist Security Info=True;User ID=liao;Data Source=LIAOHOME\\LIAOSQLSVR";
conn.Open();
//conn.ChangeDatabase("TreeDb");
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand();
System.Data.OleDb.OleDbDataReader rd;
cmd.Connection = conn;
cmd.CommandText = "select name+' ['+RTRIM(type)+']' from sysobjects where (type='U' or type='V') and name not in ('dtproperties','sysconstraints','syssegments')";
//cmd.CommandText = "sp_tables NULL, NULL, NULL, TABLE";
//cmd.CommandType = System.Data.CommandType.StoredProcedure;
rd = cmd.ExecuteReader();
while(rd.Read())
{
listBox_objectlist.Items.Add(rd.GetString(0));
}
rd.Close();
conn.Close();
}
/// <summary>
/// button_exit_Click - 取消退出
/// </summary>
private void button_exit_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Dispose();
}
/// <summary>
/// button_ok_Click - 选择并退出
/// </summary>
private void button_ok_Click(object sender, System.EventArgs e)
{
if(listBox_objectlist.SelectedIndex>=0)
{
objectname=listBox_objectlist.Text.Substring(0,listBox_objectlist.Text.Length-4);
if (listBox_objectlist.Text.IndexOf("[U]")>=0)
objecttype="table";
else
objecttype="view";
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -