📄 userform.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 Elysian
{
public partial class userForm : Form
{
private int count = 0;
public userForm()
{
InitializeComponent();
}
private string GetConnectionString()
{
return "data source=.;initial catalog=ElysianDB;integrated security=true;User ID=帐号;Password=密码;";
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
//验证数据库信息,从用户表读数据,如果验证成功,同时生成新窗口mainForm,如果3次验证不成功退出系统;
SqlConnection sqlconn = new SqlConnection(GetConnectionString());
try
{
sqlconn.Open();
}
catch (SqlException ex)
{
MessageBox.Show("连接SQL数据库发生错误:" + ex.Message, "错误!");
}
string sqlstr = string.Empty;
string name, password;
name = textBox1.Text;
password = textBox2.Text;
SqlCommand sqlcomm = new SqlCommand();
sqlcomm.CommandText = "select count(*) from 用户表 where 用户名称='" + name + "'and 密码='" + password + "'";
sqlcomm.Connection = sqlconn;
int n = Convert.ToInt32(sqlcomm.ExecuteScalar());
if (n > 0)
{
//MessageBox.Show("登陆成功");
mainForm mainform = new mainForm();
mainform.Show();
this.Hide();
}
else
{
count++;
if (count == 4)
{
MessageBox.Show("您的操作次数多于3次,请与管理员联系!", "提示");
this.DialogResult = DialogResult.Cancel;
this.Close();
}
else
{
MessageBox.Show("请正确填写用户名!", "提示");
textBox1.Focus();
textBox1.Text = "";
textBox2.Text = "";
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection sqlconn = new SqlConnection(GetConnectionString());
}
private void button3_Click(object sender, EventArgs e)
{
loginForm loginform = new loginForm();
loginform.Show();
this.Hide();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -