📄 loginmain.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 Bank
{
public partial class LoginMain : Form
{
public LoginMain()
{
InitializeComponent();
}
private void btnLoginMainEnter_Click(object sender, EventArgs e)
{
/*
数据库连接
*/
string LoginIdMain = "";
string LoginPwdMain = "";
int LoginMoneyMain = 0;
string sql = "select * from users";
bool i = false;
try
{
SqlCommand command = new SqlCommand(sql, DBHelper.connection);
DBHelper.connection.Open();
SqlDataReader dataReader = command.ExecuteReader();
Mainform mainform = new Mainform();
/*
验证部分
*/
if (!dataReader.HasRows)
{
MessageBox.Show("对不起,没有任何用户,请先创建用户", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
}
while (dataReader.Read())
{
LoginIdMain = (string)dataReader["id"];
MaintxtIdSave.Text = LoginIdMain;
LoginPwdMain = (string)dataReader["pwd"];
MaintxtPwdSave.Text = LoginPwdMain;
LoginMoneyMain = (int)dataReader["money"];
MaintxtMoneySave.Text = LoginMoneyMain.ToString();
bool verdict = txtLoginMainID.Text == "admin" && txtLoginMainPwd.Text == "0000" && cboLoginMainClass.Text == "管理员";
bool login = txtLoginMainID.Text == MaintxtIdSave.Text && txtLoginMainPwd.Text == MaintxtPwdSave.Text;
if (login || verdict)
{
this.Hide();
i = false;
HelperSend.LoginID = txtLoginMainID.Text;
HelperSend.LoginPwd = txtLoginMainPwd.Text;
HelperSend.LoginMoney = MaintxtMoneySave.Text;//控件MaintxtMoneySave文本中的金额,用于窗体传参
HelperSend.state = cboLoginMainClass.Text;
mainform.ShowDialog();
}
else
{
i = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show("数据库出错了!\n\n"+ex,"提示",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation);
}
finally
{
DBHelper.connection.Close();
}
while (i)
{
MessageBox.Show("对不起,您输入的用户名或密码错误 !请重新输入..");
this.txtLoginMainPwd.Focus();
i = false;
}
}
private void LoginMain_Load(object sender, EventArgs e)
{
cboLoginMainClass.SelectedIndex = 0;
}
private void btnLoginMainExit_Click(object sender, EventArgs e)
{
DialogResult result =
MessageBox.Show("确定退出吗?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
if(result==DialogResult.Yes)
{
Application.Exit();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -