登录框设计怎么做,测试用例及步骤分享?( 二 )

  
this.txtPasswd.Name = “txtPasswd”;  
this.txtPasswd.PasswordChar = ‘*’;  
this.txtPasswd.TabIndex = 3;  
this.txtPasswd.Text = “”;  
//  
// btnOK  
//  
this.btnOK.Location = new System.Drawing.Point(40, 120);  
this.btnOK.Name = “btnOK”;  
this.btnOK.Size = new System.Drawing.Size(72, 23);  
this.btnOK.TabIndex = 4;  
this.btnOK.Text = “OK”;  
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);  
//  
// btnCancel  
//  
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;  
this.btnCancel.Location = new System.Drawing.Point(176, 120);  
this.btnCancel.Name = “btnCancel”;  
this.btnCancel.TabIndex = 5;  
this.btnCancel.Text = “Cancel”;  
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);  
//  
// Form1  
//  
this.AcceptButton = this.btnOK;  
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);  
this.CancelButton = this.btnCancel;  
this.ClientSize = new System.Drawing.Size(298, 167);  
this.Controls.Add(this.btnCancel);  
this.Controls.Add(this.btnOK);  
this.Controls.Add(this.txtPasswd);  
this.Controls.Add(this.txtUser);  
this.Controls.Add(this.label2);  
this.Controls.Add(this.label1);  
this.FormBorderStyle =  
System.Windows.Forms.FormBorderStyle.FixedDialog;  
this.MaximizeBox = false;  
this.MaximumSize = new System.Drawing.Size(304, 192);  
this.MinimizeBox = false;  
this.MinimumSize = new System.Drawing.Size(304, 192);  
this.Name = “Form1”;  
this.ShowInTaskbar = false;  
this.Text = “Login”;  
this.Load += new System.EventHandler(this.Form1_Load);  
this.ResumeLayout(false);  
}  
#endregion  
///  
/// 应用程序的主入口点 。  
/// private void btnCancel_Click(object sender, System.EventArgs e)  
{  
Application.Exit();  
}  
private void Form1_Load(object sender, System.EventArgs e)  
{  
this.SetDesktopLocation(280,180);  
}  
private void btnOK_Click(object sender, System.EventArgs e)  
{  
Form2 theOwner = (Form2)this.Owner;  
if(this.txtUser.Text == “”)  
{  
MessageBox.Show(“用户名不能为空!”,”错误”);  
}  
else if(this.txtPasswd.Text == “”)  
{  
MessageBox.Show(“密码不能为空!”,”错误”);  
}  
else  
{  
if(IsUser(this.txtUser.Text))  
{  
if(this.txtPasswd.Text == LoginUser(this.txtUser.Text))  
{  
this.DialogResult = DialogResult.OK;  
theOwner.getUserName = this.txtUser.Text;  
}  
else  
{  
MessageBox.Show(“用户名或密码错误!”);  
}  
}  
else  
{  
MessageBox.Show(“用户名或密码错误!”);  
}  
}  
}  
private string LoginUser(string User)  
{  
SqlConnection conn = new SqlConnection(“XXXXXXXX”);  
SqlCommand cmd = new SqlCommand();  
cmd.CommandType =  
CommandType.StoredProcedure;  
cmd.CommandText = “Login”;  
cmd.Connection = conn;  
conn.Open();  
SqlParameter parName = new SqlParameter(“@Name”,SqlDbType.VarChar,50);  
parName.Value = https://www.scwdwl.com/n/User;  
cmd.Parameters.Add(parName);  
cmd.ExecuteNonQuery();  
conn.Close();  
SqlDataAdapter da = new SqlDataAdapter();  
da.SelectCommand = cmd;  
DataSet ds = new DataSet();  
da.Fill(ds);  
return ds.Tables[0].Rows[0][“UserPasswd”].ToString();  
}  
private bool IsUser(string User)  
{  
SqlConnection conn = new SqlConnection(“XXXXXXXX”);  
SqlCommand cmd = new SqlCommand();  
cmd.CommandType =  
CommandType.StoredProcedure;  
cmd.CommandText = “IsUser”;  
cmd.Connection = conn;  
conn.Open();  
SqlParameter parName = new SqlParameter(“@UserName”,SqlDbType.VarChar,50);


特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。