📄 login.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 超市信息管理系统.MarketSystem
{
public partial class Login : Form
{
public static bool CanLogin = false; //记录能否检验通过
public static string strUser = ""; //记录用户名
public static string strUserRole = ""; //记录用户权限
//private string ConnString = "Persist security info=false;initial catalog=MarketSystem;data source=localhost;integrated security=sspi;";
//与数据库的连接
private SqlConnection myConnection;
private SqlDataAdapter da;
private DataSet ds = new DataSet();
private DataTable LogTable;
private DataRow LogRow;
private string StrSQL = "select * from SysUser";
public Login()
{
InitializeComponent();
}
private void Login_Load(object sender, EventArgs e)
{
try
{
myConnection = DataBaseConnection.connection();
this.da = new SqlDataAdapter(this.StrSQL, this.myConnection);
this.ds.Clear();
this.da.Fill(ds, "SyUser");
this.LogTable = ds.Tables[0];
}
catch (SqlException oe)
{
MessageBox.Show(oe.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < LogTable.Rows.Count; i++)
{
this.LogRow = LogTable.Rows[i];
//只有当输入的用户名和密码同时对应上数据库中记录时,才能通过校验
if (LogRow[0].ToString().Trim() == this.UserNameTxt.Text.ToString().Trim() && LogRow[1].ToString().Trim() == this.PwdTxt.Text.ToString().Trim())
{
// MessageBox.Show(LogRow[0].ToString() + LogRow[1].ToString().Trim());
CanLogin = true;
strUser = LogRow[0].ToString().Trim();//保存用户名
strUserRole = LogRow[2].ToString().Trim();//保存用户权限
this.Close();//关闭窗体
return;
}
}
MessageBox.Show("您输入的用户号或密码不正确!");
return;
}
catch (SqlException oe)
{
MessageBox.Show(oe.Message);
}
finally
{
myConnection.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("你确定要退出?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -