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.fajihao.com/i/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);
parName.Value = https://www.fajihao.com/i/User;
cmd.Parameters.Add(parName);
cmd.ExecuteNonQuery();
conn.Close();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
int n;
n = ds.Tables[0].Rows.Count;
if(n > 0)
return true;
else
return false;
}
}
}
在Form2中我设计了一个label ,让它接受从Form1传过来的UserName,这样我们在以后的设计中好判断用户的权限的大小 。
Form2的代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace login
{
///
/// Form2 的摘要说明 。
/// public class Form2 : System.Windows.Forms.Form
{
private string UserName;
private
System.Windows.Forms.Label label1;
///
/// 必需的设计器变量 。
/// private
System.ComponentModel.Container components = null;
public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
Form1 myForm = new Form1();
myForm.ShowDialog(this);
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
/// 清理所有正在使用的资源 。
/// 【登录框设计怎么做,测试用例及步骤分享?】protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 – 不要使用代码编辑器修改
/// 此方法的内容 。
/// private void InitializeComponent()
- 淘宝主图怎么设置标题框 淘宝主图标签怎么弄
- 卡片设计怎么做,设计软件及模板详解?
- 室内设计有必要去培训班吗
- 机械设计制造及其自动化考研方向
- 钻展图设计思路,钻展图推广图片的设计技巧?
- 中南大学工业设计专业怎么样
- 404页面怎么制作网页设计404页面技巧和示例?
- 网站设计与SEO的关系,高手是从这4个维度分析的!?
- 双鱼送福的代表什么意思,在一些在婚庆设计上
- 有什么值得推荐的设计类书籍
