📄 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 ShipManageSystem
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string name = textBox1.Text;
string pwd = null;
string right = null;
DBConnection db = new DBConnection();
SqlConnection conn = db.getConnection();
conn.Open();
String sql = "select 密码,权限 from 用户 where 用户名='" + name + "'";
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader dr = comm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
pwd = dr.GetValue(0).ToString();
right = dr.GetValue(1).ToString();
Console.WriteLine(right);
dr.Dispose();
dr.Close();
Console.WriteLine(pwd);
dr.Close();
conn.Close();
}
if (pwd.Equals(textBox2.Text) && right.Equals("管理员"))
{
mainFrame obj = new mainFrame("admin");
this.Hide();
obj.ShowDialog();
}
else if (pwd.Equals(textBox2.Text) && (right.Equals("") || right.Equals("普通用户")))
{
mainFrame obj = new mainFrame("normal");
this.Hide();
obj.ShowDialog();
}
else
{
textBox2.Text = null;
textBox1.Text = null;
this.textBox1.Focus();
MessageBox.Show("错误的用户名或密码");
}
}
catch (SqlException)
{
MessageBox.Show("与数据库连接失败!");
}
catch (Exception)
{
MessageBox.Show("请检查用户名及密码是否正确!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -