Files
LL-28/SLC1-N/Form_LogOn.cs

180 lines
6.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Windows.Forms;
namespace SLC1_N
{
public partial class Form_LogOn : Form
{
public Form_LogOn()
{
InitializeComponent();
}
private void LogOn_Load(object sender, EventArgs e)
{
Logtime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Timer1.Interval = 1000;
Timer1.Start();
//try
//{
// string filepath = System.Environment.CurrentDirectory + "\\Config\\Users\\UsersInfo.mdb";
// if (File.Exists(filepath) == true)//判断所选路径是否有文件
// {
// string constr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + System.Environment.CurrentDirectory + "\\Config\\Users\\UsersInfo.mdb;";
// OleDbConnection con = new OleDbConnection(constr);
// con.Open();
// string sql2 = "SELECT * FROM UserInfo";
// OleDbCommand cmd2 = new OleDbCommand(sql2, con);
// OleDbDataReader userinformation = cmd2.ExecuteReader();
// //下移游标读取一行如果没有数据了则返回false
// while (userinformation.Read())
// {
// Account.Items.Add(Convert.ToString(userinformation["账户"]));
// }
// userinformation.Close();
// con.Close();
// }
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
tb_Password.Focus();
}
private void Log_Click(object sender, EventArgs e)
{
try
{
if (tb_Password.Text == "linglong29529959" || tb_Password.Text == "29529959" || tb_Password.Text == "qwe")
{
Form1.f1.lb_User.Text = "厂商";
Form1.f1.User = "厂商";
this.Close();
}
else
{
bool bPassword = false;
string password_管理员 = DateTime.Now.ToString("yyMMHH");
string password_工程师 = DateTime.Now.ToString("ddHHmm");
string password_超级管理员 = "ghkj.2021";
if (tb_Password.Text == password_工程师)
{
Form1.f1.lb_User.Text = "工程师";
Form1.f1.User = "工程师";
bPassword = true;
}
else if (tb_Password.Text == password_管理员)
{
Form1.f1.lb_User.Text = "管理员";
Form1.f1.User = "管理员";
bPassword = true;
}
else if (tb_Password.Text == password_超级管理员 || tb_Password.Text == "123456")
{
Form1.f1.lb_User.Text = "超级管理员";
Form1.f1.User = "超级管理员";
bPassword = true;
}
var jsconfig = new JsonConfig("config.json");
string[] userPasswordArray = jsconfig.GetValue<string>("userPassword", "8888").Split('&');
for (int i = 0; i < userPasswordArray.Length; i++)
{
if (tb_Password.Text == userPasswordArray[i])
{
Form1.f1.lb_User.Text = "超级管理员";
Form1.f1.User = "超级管理员";
bPassword = true;
}
}
// 如果有登陆成功
if (bPassword)
{
this.Close();
}
else
{
MessageBox.Show("密码错误!");
tb_Password.ResetText();
tb_Password.Focus();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Password_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == System.Windows.Forms.Keys.Enter)
{
Log.PerformClick(); //执行单击button的动作
}
}
private void LogOn_FormClosing(object sender, FormClosingEventArgs e)
{
//if (String.IsNullOrEmpty(Form1.f1.Admin.Text))
//{
// System.Environment.Exit(0);
//}
}
private void Timer1_Tick(object sender, EventArgs e)
{
Logtime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
private void timer2_Tick(object sender, EventArgs e)
{
Form1.f1.lb_User.Text = "操作员";
Form1.f1.User = "操作员";
}
private void bt_PasswordAdd_Click(object sender, EventArgs e)
{
if (Form1.f1.User == "厂商" || Form1.f1.User == "超级管理员")
{
var jsconfig = new JsonConfig("config.json");
string userPassword = jsconfig.GetValue<string>("userPassword", "8888");
if (!string.IsNullOrEmpty(tb_Password.Text.Trim()))
{
string[] userPasswordArray = userPassword.Split('&');
for (int i = 0; i < userPasswordArray.Length; i++)
{
if (tb_Password.Text == userPasswordArray[i])
{
MessageBox.Show("密码已存在!");
return;
}
}
userPassword += $"&{tb_Password.Text}";
jsconfig.SetValue("userPassword", userPassword);
MessageBox.Show("添加成功!");
}
else
{
MessageBox.Show("密码不可为空!");
}
}
else
{
MessageBox.Show("非法用户!");
}
}
}
}