拿位高手帮我详细解释一下这些C#代码的意思(1)

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da... using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace BasketBallTool
{
public partial class loginForm : Form
{
public loginForm()
{
InitializeComponent();
}

private void loginForm_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}

private void button2_Click(object sender, EventArgs e)
{
this.Hide();

registerForm regForm = new registerForm();
regForm.Show();
}

private void button1_Click(object sender, EventArgs e)
{
string userID = textBox1.Text.Trim();
string password = textBox2.Text.Trim();

string strConnection = @"Data Source=(LOCAL);Initial Catalog=r2;Integrated Security=True";
SqlConnection dbConnection = new SqlConnection(strConnection);

string strCommand = @"select 用户ID,密码 from aID where 用户ID='" + userID + "'";
SqlCommand dbCommand = new SqlCommand(strCommand, dbConnection);

dbConnection.Open();

SqlDataReader dbReader = dbCommand.ExecuteReader();
if (dbReader.Read())
{
if (dbReader.GetString(1).Trim() == password)
{
MessageBox.Show("登录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

MDIParent1 MDIForm = new MDIParent1();
MDIForm.Show();

this.Hide();
}
else
{
MessageBox.Show("密码不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox2.Text = "";
textBox2.Focus();
}
}
else
{
MessageBox.Show("帐号不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox1.Text = "";
textBox1.Focus();
}

dbConnection.Close();
dbConnection.Dispose();
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
textBox2.Focus();
}

}

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
button1.Focus();
}

}

private void loginForm_Load(object sender, EventArgs e)
{

}
}
}
展开
 我来答
到茧照
2008-06-15 · TA获得超过1901个赞
知道大有可为答主
回答量:1589
采纳率:0%
帮助的人:1997万
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
//以上是导入命名空间

namespace BasketBallTool
{
public partial class loginForm : Form
{
public loginForm()
{
InitializeComponent();
}

private void loginForm_FormClosed(object sender, FormClosedEventArgs e) //该窗体关闭的时候
{
Application.Exit(); //退出程序
}

private void button2_Click(object sender, EventArgs e) //点击button2的时候
{
this.Hide(); //该窗体隐藏

registerForm regForm = new registerForm();
regForm.Show(); //实例一个新的窗体 registerForm.并让其弹出
}

private void button1_Click(object sender, EventArgs e) //点击button1的时候
{
string userID = textBox1.Text.Trim(); //取出文本框textBox1的值 为用户ID
string password = textBox2.Text.Trim(); //取出文本框textBox2的值 为密码

string strConnection = @"Data Source=(LOCAL);Initial Catalog=r2;Integrated Security=True"; //指定数据库连接字符串
SqlConnection dbConnection = new SqlConnection(strConnection); //声明并实例一个数据库连接对象

string strCommand = @"select 用户ID,密码 from aID where 用户ID='" + userID + "'"; //声明一个SQL语句.用来查询用户名和密码是否匹配
SqlCommand dbCommand = new SqlCommand(strCommand, dbConnection); //声明并实例一个数据操作对象.执行SQL语句

dbConnection.Open(); //打开连接

SqlDataReader dbReader = dbCommand.ExecuteReader(); //声明一个datareader用来保存读出的数据
if (dbReader.Read()) //判断是否读出数据
{
if (dbReader.GetString(1).Trim() == password) //如果密码匹配
{
MessageBox.Show("登录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //弹出窗口提示登录成功

MDIParent1 MDIForm = new MDIParent1();
MDIForm.Show(); //让一个叫MDIParent1的窗体弹出

this.Hide(); //当前窗体隐藏
}
else //如果密码不匹配
{
MessageBox.Show("密码不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); //提示密码不正确
textBox2.Text = ""; //清空密码框
textBox2.Focus(); //让密码框得到焦点
}
}
else //没读出数据的时候
{
MessageBox.Show("帐号不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //提示帐号不存在
textBox1.Text = ""; //清空帐号
textBox1.Focus(); //帐号框得到焦点
}

dbConnection.Close(); //关闭连接
dbConnection.Dispose(); //清空连接
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e) //当用户名文本框有输入时
{
if (e.KeyChar == 13) //如果按的是回车
{
textBox2.Focus(); //让密码框得到焦点
}

}

private void textBox2_KeyPress(object sender, KeyPressEventArgs e) //当密码框有输入时
{
if (e.KeyChar == 13) //如果按的是回车
{
button1.Focus(); //让登录按扭得到焦点
}

}

private void loginForm_Load(object sender, EventArgs e)
{

}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式