解决方案:https://download.csdn.net/download/qq_44840449/20106390
写的乱,希望多多体谅,有些功能还没实现,MySQL简单写个触发器,可以自行百度,非顶级窗口的传参这里没写,以后写,感谢
一:窗口的布局
(1)登录窗口- 这里有两个time控件,用于登录时候移动图片控件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
using System.Data.Common;
//using MySql.Data.MySqlClient;//添加mysql.dll MySQl数据库处理
namespace loge
{
public partial class Form1 : Form
{
Form2 f2 = new Form2();
maincs main = new maincs();
public Form1()
{
InitializeComponent();
// this.f2=f2;
pictureBox1.Hide();//图片默认隐藏
pictureBox2.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
//获取用户输入信息
string uname = textBox1.Text.Trim();//去除null
string upaw = textBox2.Text.Trim();
//判断输入是否为空
if(string.IsNullOrEmpty(uname)||string.IsNullOrEmpty(upaw))
{
MessageBox.Show("请检测账号或者密码输入格式是否正确","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
textBox1.Focus();//设置为焦点
return;
}
//与数据库通信,判断是否一致
{
sqlhelp cmd = new sqlhelp();
string sql = "select count(1) from home where name='" + uname + "' and psw='" + upaw + "'";
string connString = zfc.connn();
object o = cmd.ExecuteScalar(sql);//返回第一行第一列,例如我们在计算总条数的时候会使用到此方法
try//尝试,假如里面的语句出错就跳出
{
if (o==null || o==DBNull.Value || int.Parse(o.ToString())==0)
{
MessageBox.Show("请检测账号或者密码是否正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Focus();//设置为焦点
return;
}
else
{
//跳转到time,然后登录,设置两个time函数,一种超级用户,一种普通用户, time1为root
if (uname == "root" || uname=="a" || uname=="admin")
{
pictureBox1.Show();
timer1.Start();
}
else
{
pictureBox2.Show();
timer2.Start();
}
textBox1.Hide();
textBox2.Hide();
label1.Hide();
label2.Hide();
label3.Hide();
button1.Hide();
button2.Hide();
}
}
catch
{
MessageBox.Show("数据库判断尝试失败","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Hide();
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
}
private void label3_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.Show();
this.Hide();
label3.ForeColor = Color.Red;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("是否退出?", "提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (dr == DialogResult.OK) //如果单击“是”按钮
{
System.Environment.Exit(0); //退出全部线程
}
else if (dr == DialogResult.C