|
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace DBLayer.DBLayer.UI
{
/// <summary>
/// Summary description for SelectDBctrl.
/// </summary>
public class SelectDBctrl : System.Windows.Forms.UserControl
{
private System.Windows.Forms.TextBox txtServerName;
private System.Windows.Forms.RadioButton radioWindow;
private System.Windows.Forms.RadioButton radioSqlServer;
private System.Windows.Forms.Panel pnlDB;
private System.Windows.Forms.ComboBox comboDatabases;
private System.Windows.Forms.Label lblDatabase;
private System.Windows.Forms.Panel pnlUserPass;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Label lblUserName;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.TextBox txtUserName;
private System.Windows.Forms.Label lblServerName;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public DBLayerEngine.ServerInfo _ServerInfo;
public string DBName;
public SelectDBctrl(DBLayerEngine.ServerInfo serverInfo)
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
_ServerInfo=serverInfo;
}
public SelectDBctrl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
_ServerInfo=new DBLayerEngine.ServerInfo(txtServerName.Text,true);
}
/// <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 Component 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.txtServerName = new System.Windows.Forms.TextBox();
this.radioWindow = new System.Windows.Forms.RadioButton();
this.radioSqlServer = new System.Windows.Forms.RadioButton();
this.pnlDB = new System.Windows.Forms.Panel();
this.comboDatabases = new System.Windows.Forms.ComboBox();
this.lblDatabase = new System.Windows.Forms.Label();
this.pnlUserPass = new System.Windows.Forms.Panel();
this.txtPassword = new System.Windows.Forms.TextBox();
this.lblUserName = new System.Windows.Forms.Label();
this.lblPassword = new System.Windows.Forms.Label();
this.txtUserName = new System.Windows.Forms.TextBox();
this.lblServerName = new System.Windows.Forms.Label();
this.pnlDB.SuspendLayout();
this.pnlUserPass.SuspendLayout();
this.SuspendLayout();
//
// txtServerName
//
this.txtServerName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtServerName.Location = new System.Drawing.Point(112, 16);
this.txtServerName.Name = "txtServerName";
this.txtServerName.Size = new System.Drawing.Size(272, 20);
this.txtServerName.TabIndex = 16;
this.txtServerName.Text = "(local)";
this.txtServerName.TextChanged += new System.EventHandler(this.Controls_TextChanged);
//
// radioWindow
//
this.radioWindow.Checked = true;
this.radioWindow.Location = new System.Drawing.Point(24, 56);
this.radioWindow.Name = "radioWindow";
this.radioWindow.Size = new System.Drawing.Size(176, 24);
this.radioWindow.TabIndex = 17;
this.radioWindow.TabStop = true;
this.radioWindow.Text = "Windows Authentication";
this.radioWindow.CheckedChanged += new System.EventHandler(this.Controls_TextChanged);
//
// radioSqlServer
//
this.radioSqlServer.Location = new System.Drawing.Point(24, 88);
this.radioSqlServer.Name = "radioSqlServer";
this.radioSqlServer.Size = new System.Drawing.Size(168, 24);
this.radioSqlServer.TabIndex = 18;
this.radioSqlServer.Text = "S&QL Server Authentication";
this.radioSqlServer.CheckedChanged += new System.EventHandler(this.Controls_TextChanged);
//
// pnlDB
//
this.pnlDB.Controls.Add(this.comboDatabases);
this.pnlDB.Controls.Add(this.lblDatabase);
this.pnlDB.Location = new System.Drawing.Point(8, 200);
this.pnlDB.Name = "pnlDB";
this.pnlDB.Size = new System.Drawing.Size(384, 32);
this.pnlDB.TabIndex = 20;
//
// comboDatabases
//
this.comboDatabases.Location = new System.Drawing.Point(96, 5);
this.comboDatabases.Name = "comboDatabases";
this.comboDatabases.Size = new System.Drawing.Size(280, 21);
this.comboDatabases.TabIndex = 12;
this.comboDatabases.DropDown += new System.EventHandler(this.comboDatabases_DropDown);
this.comboDatabases.SelectedIndexChanged += new System.EventHandler(this.comboDatabases_SelectedIndexChanged);
//
// lblDatabase
//
this.lblDatabase.Location = new System.Drawing.Point(8, 5);
this.lblDatabase.Name = "lblDatabase";
this.lblDatabase.Size = new System.Drawing.Size(64, 23);
this.lblDatabase.TabIndex = 8;
this.lblDatabase.Text = "Database :";
//
// pnlUserPass
//
this.pnlUserPass.Controls.Add(this.txtPassword);
this.pnlUserPass.Controls.Add(this.lblUserName);
this.pnlUserPass.Controls.Add(this.lblPassword);
this.pnlUserPass.Controls.Add(this.txtUserName);
this.pnlUserPass.Enabled = false;
this.pnlUserPass.Location = new System.Drawing.Point(56, 112);
this.pnlUserPass.Name = "pnlUserPass";
this.pnlUserPass.Size = new System.Drawing.Size(344, 80);
this.pnlUserPass.TabIndex = 19;
//
// txtPassword
//
this.txtPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtPassword.Location = new System.Drawing.Point(80, 48);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(248, 20);
this.txtPassword.TabIndex = 7;
this.txtPassword.Text = "";
this.txtPassword.TextChanged += new System.EventHandler(this.Controls_TextChanged);
//
// lblUserName
//
this.lblUserName.Location = new System.Drawing.Point(8, 8);
this.lblUserName.Name = "lblUserName";
this.lblUserName.Size = new System.Drawing.Size(72, 23);
this.lblUserName.TabIndex = 4;
this.lblUserName.Text = "User Name :";
//
// lblPassword
//
this.lblPassword.Location = new System.Drawing.Point(8, 48);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(64, 23);
this.lblPassword.TabIndex = 5;
this.lblPassword.Text = "Password :";
//
// txtUserName
//
this.txtUserName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtUserName.Location = new System.Drawing.Point(80, 8);
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(248, 20);
this.txtUserName.TabIndex = 6;
this.txtUserName.Text = "";
this.txtUserName.TextChanged += new System.EventHandler(this.Controls_TextChanged);
//
// lblServerName
//
this.lblServerName.Location = new System.Drawing.Point(16, 16);
this.lblServerName.Name = "lblServerName";
this.lblServerName.Size = new System.Drawing.Size(80, 23);
this.lblServerName.TabIndex = 15;
this.lblServerName.Text = "Server Name";
//
// SelectDBctrl
//
this.Controls.Add(this.txtServerName);
this.Controls.Add(this.radioWindow);
this.Controls.Add(this.radioSqlServer);
this.Controls.Add(this.pnlDB);
this.Controls.Add(this.pnlUserPass);
this.Controls.Add(this.lblServerName);
this.Name = "SelectDBctrl";
this.Size = new System.Drawing.Size(416, 264);
this.Load += new System.EventHandler(this.SelectDBctrl_Load);
this.pnlDB.ResumeLayout(false);
this.pnlUserPass.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void SelectDBctrl_Load(object sender, System.EventArgs e)
{
txtPassword.PasswordChar="\x25cf"[0];
}
private void FillComboDatabases()
{
try
{
SqlConnection connection=new SqlConnection(DBLayerEngine.Helper.GenerateConnectionString(_ServerInfo,"Master"));
SqlCommand command=new SqlCommand("select name from sysdatabases",connection);
DataTable table=new DataTable();
SqlDataAdapter adapter=new SqlDataAdapter(command);
adapter.Fill(table);
comboDatabases.DataSource=table;
comboDatabases.DisplayMember="name";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Controls_TextChanged(object sender, System.EventArgs e)
{
if(radioWindow.Checked)
{
pnlUserPass.Enabled=false;
_ServerInfo.WindowsAuthentication=true;
}
else
{
pnlUserPass.Enabled=true;
_ServerInfo.WindowsAuthentication=false;
}
if(txtServerName.Text.Length>0)
{
if(radioWindow.Checked)
{
pnlDB.Enabled=true;
return;
}
else if(radioSqlServer.Checked)
{
if(txtUserName.Text.Length>0 )
{
pnlDB.Enabled=true;
return;
}
}
}
pnlDB.Enabled=false;
}
private void comboDatabases_SelectedIndexChanged(object sender, System.EventArgs e)
{
DBName= ((DataRowView)comboDatabases.SelectedValue).Row["name"].ToString();
}
private void comboDatabases_DropDown(object sender, System.EventArgs e)
{
if(txtServerName.Text!=_ServerInfo.ServerName || txtPassword.Text!=_ServerInfo.Password || txtUserName.Text!=_ServerInfo.UserName)
{
_ServerInfo.ServerName=txtServerName.Text;
comboDatabases.DataSource=null;
comboDatabases.Items.Clear();
_ServerInfo.UserName=txtUserName.Text;
_ServerInfo.Password=txtPassword.Text;
FillComboDatabases();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
Egyption ,B.Sc in computer science Department from faculty of computer science and information system Egypt-Helwan Univeristy ,
my master in progress in intelligent systems in Vienna Technology university ,
Microsoft Certified Professional science 2003 experience with
Turbo Pascal ,C++,VC++,C#,VB.NET,J# ,asp,ASP.Net,COM+ & XML , sql server 2000,action script 2
I have B.Sc in Computer Science , Microsoft Certified Solution Developer and experienced with C/C++,MFC,C#,VB.NET,ASP.NET,XML,SQL Server 2000 & Crystal Reports.I like challenge and enjoy working with new technologies.