|
请各位高手帮忙看看,如何进行C#单元测试?万分感谢~!
namespace 成绩管理系统
{
public partial class Form1 : Form
{
Boolean b = false;
string str1 = @"Data Source=.;Initial Catalog=StudentCj;Integrated Security=True"; //无密码建立连接SQL数据库对象
public Form1()
{
InitializeComponent();
this.skinEngine1.SkinFile = "MP10.ssk"; //皮肤
}
private void Form1_Load(object sender, EventArgs e) //窗体加载时清空文本中的值
{
textBox1.Text = "";
textBox2.Text = "";
}
private void select()
{
SqlConnection con = new SqlConnection(str1);
string sql = "select Name,passwd from Admin where Name='" + textBox1.Text + "' ";
SqlCommand com = new SqlCommand();
com.CommandText = sql;
com.Connection = con;
con.Open();
SqlDataReader ada = com.ExecuteReader();
if (ada.Read())
{
if (ada["passwd"].ToString().Trim() != textBox2.Text.Trim())
{
MessageBox.Show("密码不正确");
textBox2.Focus();
return;
}
else
{
con.Close();
b = true;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
select();
if (b)
{
Main lons1 = new Main();
lons1.Show();
this.Visible = false; //进入Main窗体时不显示Form1窗体
}
else
{
MessageBox.Show("用户名和密码不正确 ");
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close(); //关闭
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
} |
|