?? frmysjy.cs
字號(hào):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Win32;
namespace DataC
{
/// <summary>
/// Summary description for frmYSJY.
/// </summary>
public class frmYSJY : System.Windows.Forms.Form
{
public
string strConn=null;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox tbDBN;
private System.Windows.Forms.TextBox tbPW;
private System.Windows.Forms.TextBox tbUN;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox cbType;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button btOK;
private System.Windows.Forms.OpenFileDialog ofd;
private System.Windows.Forms.Label lbODBC;
private System.Windows.Forms.ComboBox cbODBC;
private System.Windows.Forms.Label lbSql;
private System.Windows.Forms.TextBox tbSql;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmYSJY()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.tbSql = new System.Windows.Forms.TextBox();
this.lbSql = new System.Windows.Forms.Label();
this.btOK = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.tbDBN = new System.Windows.Forms.TextBox();
this.tbPW = new System.Windows.Forms.TextBox();
this.tbUN = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.cbODBC = new System.Windows.Forms.ComboBox();
this.cbType = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.lbODBC = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.ofd = new System.Windows.Forms.OpenFileDialog();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.tbSql);
this.groupBox1.Controls.Add(this.lbSql);
this.groupBox1.Controls.Add(this.btOK);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.tbDBN);
this.groupBox1.Controls.Add(this.tbPW);
this.groupBox1.Controls.Add(this.tbUN);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.cbODBC);
this.groupBox1.Controls.Add(this.cbType);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.lbODBC);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(1, -5);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(263, 221);
this.groupBox1.TabIndex = 14;
this.groupBox1.TabStop = false;
//
// tbSql
//
this.tbSql.Location = new System.Drawing.Point(88, 56);
this.tbSql.Name = "tbSql";
this.tbSql.Size = new System.Drawing.Size(120, 21);
this.tbSql.TabIndex = 1;
this.tbSql.Text = "";
//
// lbSql
//
this.lbSql.AutoSize = true;
this.lbSql.Location = new System.Drawing.Point(11, 56);
this.lbSql.Name = "lbSql";
this.lbSql.Size = new System.Drawing.Size(72, 17);
this.lbSql.TabIndex = 25;
this.lbSql.Text = "Sql服務(wù)器名";
//
// btOK
//
this.btOK.Location = new System.Drawing.Point(152, 184);
this.btOK.Name = "btOK";
this.btOK.TabIndex = 24;
this.btOK.Text = "確定";
this.btOK.Click += new System.EventHandler(this.btOK_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(224, 88);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(32, 23);
this.button1.TabIndex = 23;
this.button1.Text = "...";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// tbDBN
//
this.tbDBN.Location = new System.Drawing.Point(88, 88);
this.tbDBN.Name = "tbDBN";
this.tbDBN.Size = new System.Drawing.Size(136, 21);
this.tbDBN.TabIndex = 2;
this.tbDBN.Text = "";
//
// tbPW
//
this.tbPW.Location = new System.Drawing.Point(88, 152);
this.tbPW.Name = "tbPW";
this.tbPW.PasswordChar = '#';
this.tbPW.Size = new System.Drawing.Size(120, 21);
this.tbPW.TabIndex = 4;
this.tbPW.Text = "";
//
// tbUN
//
this.tbUN.Location = new System.Drawing.Point(88, 120);
this.tbUN.Name = "tbUN";
this.tbUN.Size = new System.Drawing.Size(120, 21);
this.tbUN.TabIndex = 3;
this.tbUN.Text = "";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(29, 88);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(54, 17);
this.label5.TabIndex = 21;
this.label5.Text = "數(shù)據(jù)庫名";
//
// cbODBC
//
this.cbODBC.Location = new System.Drawing.Point(88, 56);
this.cbODBC.Name = "cbODBC";
this.cbODBC.Size = new System.Drawing.Size(121, 20);
this.cbODBC.TabIndex = 20;
//
// cbType
//
this.cbType.Items.AddRange(new object[] {
"Access數(shù)據(jù)庫",
"SQLserver數(shù)據(jù)庫",
"Oracle數(shù)據(jù)庫"});
this.cbType.Location = new System.Drawing.Point(88, 21);
this.cbType.Name = "cbType";
this.cbType.Size = new System.Drawing.Size(121, 20);
this.cbType.TabIndex = 0;
this.cbType.Text = "Access數(shù)據(jù)庫";
this.cbType.SelectedIndexChanged += new System.EventHandler(this.cbType_SelectedIndexChanged);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(51, 153);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(29, 17);
this.label4.TabIndex = 16;
this.label4.Text = "密碼";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(40, 123);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(42, 17);
this.label3.TabIndex = 15;
this.label3.Text = "用戶名";
//
// lbODBC
//
this.lbODBC.AutoSize = true;
this.lbODBC.Location = new System.Drawing.Point(8, 56);
this.lbODBC.Name = "lbODBC";
this.lbODBC.Size = new System.Drawing.Size(79, 17);
this.lbODBC.TabIndex = 14;
this.lbODBC.Text = "ODBC數(shù)據(jù)源名";
this.lbODBC.Visible = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(18, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 17);
this.label1.TabIndex = 13;
this.label1.Text = "數(shù)據(jù)庫類型";
//
// frmYSJY
//
this.AcceptButton = this.btOK;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(266, 216);
this.ControlBox = false;
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "frmYSJY";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "配置源數(shù)據(jù)源";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void cbType_SelectedIndexChanged(object sender, System.EventArgs e)
{
tbDBN.Enabled=true;
if(cbType.Text=="ODBC數(shù)據(jù)源")
{
tbDBN.Enabled=false;
cbODBC.Visible=true;
lbODBC.Visible=true;
lbSql.Visible=false;
tbSql.Visible=false;
GetSysODBC(cbODBC.Items);
return;
}
if(cbType.Text=="Access數(shù)據(jù)庫")
{
}
if(cbType.Text=="SQLserver數(shù)據(jù)庫")
{
lbSql.Visible=true;
tbSql.Visible=true;
lbODBC.Visible=false;
cbODBC.Visible=false;
}
if(cbType.Text=="Oracle數(shù)據(jù)庫")
{
tbSql.Enabled=false;
lbSql.Enabled=false;
cbODBC.Visible=false;
lbODBC.Visible=false;
}
}
private void GetSysODBC(System.Windows.Forms.ComboBox.ObjectCollection slODBC)
{
RegistryKey a=Registry.CurrentUser;
RegistryKey b=a.OpenSubKey("Software");
RegistryKey c=b.OpenSubKey("ODBC");
RegistryKey d=c.OpenSubKey("ODBC.INI");
foreach(string strODBC in d.GetSubKeyNames())
{
slODBC.Add(strODBC);
}
}
private void odbcConnection1_InfoMessage(object sender, System.Data.Odbc.OdbcInfoMessageEventArgs e)
{
}
private void btOK_Click(object sender, System.EventArgs e)
{
if(cbType.Text=="ODBC數(shù)據(jù)源")
{
if(cbODBC.Text=="")
{
MessageBox.Show("Error ****ODBC數(shù)據(jù)源不能為空!****");
return;
}
strConn="Provider=ODBCOLEDB;DSN="+cbODBC.Text+";"+"UID="+tbUN.Text+";"+"PWD="+tbPW.Text+";";
}
else
{
if(tbDBN.Text=="")
{
MessageBox.Show("Error ****數(shù)據(jù)庫名不能為空!****");
return;
}
if(cbType.Text=="SQLserver數(shù)據(jù)庫")
{
strConn="Provider=SQLOLEDB;Data Source="+tbSql.Text+";User ID="+tbUN.Text +";Password="+tbPW.Text+";Initial Catalog="+tbDBN.Text;
}
if(cbType.Text=="Access數(shù)據(jù)庫")
{
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ tbDBN.Text+ ";User ID="+tbUN.Text+";Password="+tbPW.Text;
//strConn="Data Source=\"" + tbDBN.Text+ "\";Provider=\"Microsoft.Jet.OLEDB.4.0\";User ID=Admin;Password=;Jet OLEDB:SFP=False;";
}
if(cbType.Text=="Oracle數(shù)據(jù)庫")
{
strConn="Provider=OraOLEDB.Oracle.1;User ID="+tbUN.Text+";Data Source="+tbDBN.Text+";Persist Security Info=True;Password="+tbPW.Text;
}
}
this.Close();
}
private void button1_Click(object sender, System.EventArgs e)
{
if(ofd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
tbDBN.Text=ofd.FileName;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -