今天呢!小编比较闲!回想一下自己开发过的程序!然后呢!为了便于加深记忆!小编便自己又写了一遍进销存程序!好吧废话不多说!进入主题啦!
这个关于Models部分我就不用讲了吧!学C#的应该都懂的!...略过...
DAL部分
public class UsersService
{
/// <summary>
/// 判断用户名和密码
/// </summary>
/// <param name="txtName"></param>
/// <param name="txtPassword"></param>
/// <returns></returns>
public static string IsLogin(string txtName,string txtPassword)
{
string str = null;
using (SqlConnection sc = new SqlConnection(CONN.GetConnectionString()))
{
using (SqlCommand scmd = new SqlCommand(" Select UserID,UserName,PasswordCode,IsUse From Users Where IsUse = 1 ",sc))
{
//打开数据管道
sc.Open();
using (SqlDataReader sdr = scmd.ExecuteReader())
{
while (sdr.Read())
{
//判断用户名是否正确正确的话!判断密码!否则的话返回一个字符串NAMEERROR
if (txtName == sdr["UserName"].ToString())
{
//如果用户名正确则判断密码是否正确 正确的话返回OK 否则返回PASSWORDERROR
if (txtPassword == sdr["PasswordCode"].ToString())
{
str = "OK";
}
else
{
str = "PASSWORDERROR";
}
}
else
{
str = "NAMEERROR";
}
}
}
}
}
return str;
}
}
UI部分
public partial class FormLogin : Form
{
public FormLogin()
{
InitializeComponent();
}
/// <summary>
/// 登录按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//接受返回的字符串
string txt = BLL.IsLoginManager.IsLogin(this.txtbName.Text, this.txtbPassword.Text);
//好的!开始判断
switch (txt)
{
case "NAMEERROR":
MessageBox.Show("用户名错误!请认真填写用户名...");
break;
case "PASSWORDERROR":
MessageBox.Show("密码错误!请认真填写密码...");
break;
case "OK":
MessageBox.Show("登录成功!");
this.DialogResult = DialogResult.OK;
break;
}
}
/// <summary>
/// 取消按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
---------------------
深圳网站建设 https://www.sz886.com