代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace member
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(login));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(280, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 3;
this.button1.Text = "确 定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(368, 184);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 24);
this.button2.TabIndex = 4;
this.button2.Text = "取 消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox1.Location = new System.Drawing.Point(272, 104);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(160, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox2.Enabled = false;
this.textBox2.Location = new System.Drawing.Point(272, 128);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(160, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox3.Location = new System.Drawing.Point(272, 152);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(160, 21);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Location = new System.Drawing.Point(208, 109);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 5;
this.label1.Text = "用户代码:";
//
// label2
//
this.label2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label2.Location = new System.Drawing.Point(208, 133);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 16);
this.label2.TabIndex = 6;
this.label2.Text = "用户姓名:";
//
// label3
//
this.label3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label3.Location = new System.Drawing.Point(208, 157);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 16);
this.label3.TabIndex = 7;
this.label3.Text = "用户密码:";
//
// login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(448, 229);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox3,
this.textBox2,
this.textBox1,
this.button2,
this.button1,
this.label1,
this.label2,
this.label3});
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "login";
this.Text = "会员登录";
this.ResumeLayout(false); }
#endregion private void button1_Click(object sender, System.EventArgs e)
{
if (this.CheckUser(this.textBox1.Text.Trim(),this.textBox2.Text.Trim(),this.textBox3.Text.Trim())==true)
{
winmain winmain = new winmain();
classa.Code =textBox1.Text;
classa.User =textBox2.Text;
winmain.Show();
this.Hide();
}
else
{
MessageBox.Show("您输入的帐号或密码有误,请重新登录!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
} } private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit ();
}
private void textBox1_Enter(object sender, System.EventArgs e)
{
Application.Exit ();
}
private bool CheckUser(string Code,string UserName,string Password)
{
bool IsIn=false;
string source="server=localhost;"+
"uid=sa;pwd=ntdba;"+
"database=zyhx";
string select="select * from admin where code='" + Code.Trim() + "' and passwd='" + Password.Trim() + "'";
try
{
SqlConnection conn = new SqlConnection(source);
conn.Open();
SqlCommand cmd = new SqlCommand(select,conn);
SqlDataReader sql = cmd.ExecuteReader();
while (sql.Read())
{
textBox2.Text = sql["user"].ToString ();
IsIn=true;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
//conn.Close();
return IsIn;
}
[STAThread] static void Main()
{
login newmain=new login();
Application.Run(newmain);
}
}
}
我想实现,当textbox1输入完毕后,textbox2自动从数据库中读取数据并显示。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace member
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(login));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(280, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 3;
this.button1.Text = "确 定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(368, 184);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 24);
this.button2.TabIndex = 4;
this.button2.Text = "取 消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox1.Location = new System.Drawing.Point(272, 104);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(160, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox2.Enabled = false;
this.textBox2.Location = new System.Drawing.Point(272, 128);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(160, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox3.Location = new System.Drawing.Point(272, 152);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(160, 21);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Location = new System.Drawing.Point(208, 109);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 5;
this.label1.Text = "用户代码:";
//
// label2
//
this.label2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label2.Location = new System.Drawing.Point(208, 133);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 16);
this.label2.TabIndex = 6;
this.label2.Text = "用户姓名:";
//
// label3
//
this.label3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label3.Location = new System.Drawing.Point(208, 157);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 16);
this.label3.TabIndex = 7;
this.label3.Text = "用户密码:";
//
// login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(448, 229);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox3,
this.textBox2,
this.textBox1,
this.button2,
this.button1,
this.label1,
this.label2,
this.label3});
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "login";
this.Text = "会员登录";
this.ResumeLayout(false); }
#endregion private void button1_Click(object sender, System.EventArgs e)
{
if (this.CheckUser(this.textBox1.Text.Trim(),this.textBox2.Text.Trim(),this.textBox3.Text.Trim())==true)
{
winmain winmain = new winmain();
classa.Code =textBox1.Text;
classa.User =textBox2.Text;
winmain.Show();
this.Hide();
}
else
{
MessageBox.Show("您输入的帐号或密码有误,请重新登录!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
} } private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit ();
}
private void textBox1_Enter(object sender, System.EventArgs e)
{
Application.Exit ();
}
private bool CheckUser(string Code,string UserName,string Password)
{
bool IsIn=false;
string source="server=localhost;"+
"uid=sa;pwd=ntdba;"+
"database=zyhx";
string select="select * from admin where code='" + Code.Trim() + "' and passwd='" + Password.Trim() + "'";
try
{
SqlConnection conn = new SqlConnection(source);
conn.Open();
SqlCommand cmd = new SqlCommand(select,conn);
SqlDataReader sql = cmd.ExecuteReader();
while (sql.Read())
{
textBox2.Text = sql["user"].ToString ();
IsIn=true;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
//conn.Close();
return IsIn;
}
[STAThread] static void Main()
{
login newmain=new login();
Application.Run(newmain);
}
}
}
我想实现,当textbox1输入完毕后,textbox2自动从数据库中读取数据并显示。
解决方案 »
- 谢谢ttotcs3大哥帮我解决彩信下行的问题。
- VS3.5怎么才能转成VS2.0
- VS2005下面如何声明服务器控件和服务器事件?
- C# .net 2.0 的输入法bug ?
- 高手请进:.net中winForm应用程序的启动过程以及.net框架的加载过程是怎样的?(操作系统做了什么操作)
- TcpListener用到一半关了,再发数据时有原本连上的TcpClient的程序死了,有无办法发现TcpListener已关显示提示。
- 多线程环境,如何实现对一段代码的独占?
- 跪求高手,希望大家进来一起帮我看看,我都快愁死了,在线等
- 我想要实现这种效果在 textbox中 使用的c# 怎么实现 谢谢
- 用C#读写XML数据的问题!
- dataGrid显示后可以修改的问题(菜鸟的问题)
- 怎么WPF中字体总是那么模糊呀,有没有什么办法解决?
……
}
textBox2.Text = "aa";
}我加了怎么无效啊?
{
if(!this.ReadOnly)
{
textBox2.Text = "aa";
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace member
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(login));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(280, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 3;
this.button1.Text = "确 定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(368, 184);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 24);
this.button2.TabIndex = 4;
this.button2.Text = "取 消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox1.Location = new System.Drawing.Point(272, 104);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(160, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox2.Enabled = false;
this.textBox2.Location = new System.Drawing.Point(272, 128);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(160, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox3.Location = new System.Drawing.Point(272, 152);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(160, 21);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Location = new System.Drawing.Point(208, 109);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 5;
this.label1.Text = "用户代码:";
//
// label2
//
this.label2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label2.Location = new System.Drawing.Point(208, 133);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 16);
this.label2.TabIndex = 6;
this.label2.Text = "用户姓名:";
//
// label3
//
this.label3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label3.Location = new System.Drawing.Point(208, 157);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 16);
this.label3.TabIndex = 7;
this.label3.Text = "用户密码:";
//
// login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(448, 229);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox3,
this.textBox2,
this.textBox1,
this.button2,
this.button1,
this.label1,
this.label2,
this.label3});
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "login";
this.Text = "会员登录";
this.ResumeLayout(false); }
#endregion private void button1_Click(object sender, System.EventArgs e)
{
if (this.CheckUser(this.textBox1.Text.Trim(),this.textBox2.Text.Trim(),this.textBox3.Text.Trim())==true)
{
winmain winmain = new winmain();
classa.Code =textBox1.Text;
classa.User =textBox2.Text;
winmain.Show();
this.Hide();
}
else
{
MessageBox.Show("您输入的帐号或密码有误,请重新登录!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
} } private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit ();
}
private void textBox1_Enter(object sender, System.EventArgs e)
{
Application.Exit ();
}
private bool CheckUser(string Code,string UserName,string Password)
{
bool IsIn=false;
string source="server=localhost;"+
"uid=sa;pwd=ntdba;"+
"database=zyhx";
string select="select * from admin where code='" + Code.Trim() + "' and passwd='" + Password.Trim() + "'";
try
{
SqlConnection conn = new SqlConnection(source);
conn.Open();
SqlCommand cmd = new SqlCommand(select,conn);
SqlDataReader sql = cmd.ExecuteReader();
while (sql.Read())
{
textBox2.Text = sql["user"].ToString ();
IsIn=true;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
//conn.Close();
return IsIn;
}
[STAThread] private void textBox1_Leave(object sender, System.EventArgs e) {
textBox2.Text = "aa";
} static void Main()
{
login newmain=new login();
Application.Run(newmain);
}
}
}
---------------------------------------------------------------------
这个用"焦点"去判断,在winform是很难实现的,且也不稳定,一般的做法是"当textbox1输入完毕后,按回车键执行查询",你的需求如果改成这样就容易实现多了
在它里面加上this.textBox1.Click += new System.EventHandler(this.textBox1_Leave);
就行了
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace member
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;public login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(login));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(280, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 3;
this.button1.Text = "确 定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(368, 184);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 24);
this.button2.TabIndex = 4;
this.button2.Text = "取 消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox1.Location = new System.Drawing.Point(272, 104);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(160, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
//
// textBox2
//
this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox2.Enabled = false;
this.textBox2.Location = new System.Drawing.Point(272, 128);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(160, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox3.Location = new System.Drawing.Point(272, 152);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(160, 21);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Location = new System.Drawing.Point(208, 109);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 5;
this.label1.Text = "用户代码:";
//
// label2
//
this.label2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label2.Location = new System.Drawing.Point(208, 133);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 16);
this.label2.TabIndex = 6;
this.label2.Text = "用户姓名:";
//
// label3
//
this.label3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label3.Location = new System.Drawing.Point(208, 157);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 16);
this.label3.TabIndex = 7;
this.label3.Text = "用户密码:";
//
// login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(448, 229);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox3,
this.textBox2,
this.textBox1,
this.button2,
this.button1,
this.label1,
this.label2,
this.label3});
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "login";
this.Text = "会员登录";
this.ResumeLayout(false);}
#endregionprivate void button1_Click(object sender, System.EventArgs e)
{if (this.CheckUser(this.textBox1.Text.Trim(),this.textBox2.Text.Trim(),this.textBox3.Text.Trim())==true)
{
winmain winmain = new winmain();
classa.Code =textBox1.Text;
classa.User =textBox2.Text;
winmain.Show();
this.Hide();
}
else
{
MessageBox.Show("您输入的帐号或密码有误,请重新登录!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}}private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit ();
}
private void textBox1_Enter(object sender, System.EventArgs e)
{
Application.Exit ();
}
private bool CheckUser(string Code,string UserName,string Password)
{
bool IsIn=false;
string source="server=localhost;"+
"uid=sa;pwd=ntdba;"+
"database=zyhx";
string select="select * from admin where code='" + Code.Trim() + "' and passwd='" + Password.Trim() + "'";
try
{
SqlConnection conn = new SqlConnection(source);
conn.Open();
SqlCommand cmd = new SqlCommand(select,conn);
SqlDataReader sql = cmd.ExecuteReader();
while (sql.Read())
{
textBox2.Text = sql["user"].ToString ();
IsIn=true;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
//conn.Close();
return IsIn;
}
[STAThread]private void textBox1_Leave(object sender, System.EventArgs e){
textBox2.Text = "aa";
}static void Main()
{
login newmain=new login();
Application.Run(newmain);
}
}
}