登录功能
Purchase and sale
LoginForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using BLL;
/**********************
* *
* 作者:** *
* 日期:2019/12/4 *
* *
**********************/
//=================================================================================================================
//
// 版本V1.00 修改时间 2019/12/3 修改内容 界面优化 代码优化
// 版本V1.01 修改时间 2019/12/4 修改内容 改写三次架构 界面优化 代码优化
//
//=================================================================================================================
//
namespace Purchase_and_sale
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}
BLogin b = new BLogin();
private void btndl_Click(object sender, EventArgs e)
{string accountNumber = txtAccountNumber.Text.Trim();
string passWord = txtPassWord.Text.Trim();
if (accountNumber == "")
{
MessageBox.Show("请输入账号");
return;
}if (passWord == "")
{
MessageBox.Show("请输入密码");
return;
}
if (cmbIdentity.Text == "")
{
MessageBox.Show("请选择你的身份");
return;
}
if (cmbIdentity.Text == "管理员")
{
if (b.UserAdministrator(accountNumber, passWord))
{
MessageBox.Show("管理员登录成功");
MainForm m = new MainForm();
m.aNumber = accountNumber;
m.aPassword = passWord;
this.Hide();
m.ShowDialog();
}
else
{
MessageBox.Show("账号或密码错误!");
}
}if (cmbIdentity.Text == "员工")
{
if (b.UserStaff(accountNumber, passWord))
{
MessageBox.Show("员工登录成功");
MainForm m = new MainForm();
m.employeeCompetence = true;
m.Jurisdiction = accountNumber;
m.eNumber= accountNumber;
m.ePassword= passWord;
this.Hide();
m.Show();
}
else
{
MessageBox.Show("账号或密码错误!");
}
}
}
private void LoginForm_Load(object sender, EventArgs e)
{
}private void timer1_Tick(object sender, EventArgs e)
{
}
}
}
BLL
LoginForm.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
namespace BLL
{
public class BLogin
{
DLogin d = new DLogin();
/// <summary>
/// 是否从管理员表里查到记录
/// </summary>
/// <param name="zh">账号</param>
/// <param name="pass">密码</param>
/// <returns>有记录返回true 否则,返回false</returns>
public bool UserAdministrator(string accountNumber, string passWord)
{
if(d.UserAdministrator(accountNumber, passWord).Tables[0].Rows.Count>0)
{
return true;
}
else
{
return false;
}}
/// <summary>
/// 是否从员工表里查到记录
/// </summary>
/// <param name="zh">账号</param>
/// <param name="pass">密码</param>
/// <returns>有记录返回true 否则,返回false</returns>
public bool UserStaff(string accountNumber, string passWord)
{
if (d.UserStaff(accountNumber, passWord).Tables[0].Rows.Count > 0)
{
return true;
}
else
{
return false;
}}
}
}
DAL
LoginForm.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DbUtility;
using System.Data;
using System.Data.SqlClient;namespace DAL
{
public class DLogin
{
/// <summary>
///
/// </summary>
/// <param name="accountNumber">管理员账号</param>
/// <param name="passWord">管理员密码</param>
/// <returns></returns>
public DataSet UserAdministrator(string accountNumber, string passWord)
{
string sql = " SELECT pass FROM Administrators WHERE account='" + accountNumber + "' AND pass='" + passWord + "'";
return SqlHelp.Query(sql);
}
/// <summary>
///
/// </summary>
/// <param name="accountNumber">员工账号</param>
/// <param name="passWord">员工密码</param>
/// <returns></returns>
public DataSet UserStaff(string accountNumber, string passWord)
{
string sql = " SELECT pass FROM Einformation WHERE account='" + accountNumber + "' AND pass='" + passWord + "'";
return SqlHelp.Query(sql);
}}
}
本文来自博客园,作者:hellowworld!,转载请注明原文链接:https://www.cnblogs.com/zhangsai/p/17636536.html
posted on 2023-08-16 23:58 hellowworld! 阅读(17) 评论(0) 编辑 收藏 举报