用C#实现登陆界面

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 DBCL;
using System.Data.SqlClient;

namespace PurchaseSellSystem
{
public partial class Login : Form
{
DBCL.DataBase db = new DBCL.DataBase();
//函数*****************************************************************
//构造
public Login()
{
InitializeComponent();
}
//退出按钮事件
private void button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确认退出吗?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
Application.Exit();
}
}
//登录按钮事件
private void btnLogin_Click(object sender, EventArgs e)
{
string strUserName = "";
string strUserPwd = "";

strUserName = tbUserName.Text.Trim();
strUserPwd = tbUserPwd.Text.Trim();

if (strUserName == "")
{
MessageBox.Show("用户名不能为空!", "警告");
return;
}
if (strUserPwd == "")
{
MessageBox.Show("密码不能为空!", "警告");
return;
}

string strSql = "";
strSql = "select UserPwd from UserTable where UserName = '"+strUserName+"'";
SqlDataReader dr = db.DB_Red(strSql);
if(dr.Read())
{
if (strUserPwd.Equals(db.DB_C(strSql, 0)))
{
Form1 frm1 = new Form1();
frm1.Show();
this.Hide();
}
else
{
MessageBox.Show("密码错误!","警告");
return;
}
}
else
{
MessageBox.Show("用户名不存在!", "警告");
return;
}
}

private void Login_Load(object sender, EventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}
}
}

posted @   AsrielDream  阅读(195)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
点击右上角即可分享
微信分享提示