using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Welling_Motor_Debug_Tool { public partial class Login : Form { LocalInfo localInfo = new LocalInfo(); public Login() { InitializeComponent(); } public Dictionary UserAccount = new Dictionary(); private void Login_Load(object sender, EventArgs e) { UserAccount.Clear(); //读取账户信息 try { //检查配置文件 if (!Directory.Exists(localInfo.LocalPath)) Directory.CreateDirectory(localInfo.LocalPath); if (!File.Exists(localInfo.LocalPath+localInfo.UsrFileName)) { //设定账户密码 string info = ""; info += "USER=中置MG量产写入,PASSWD=1;"; info += "USER=中置MG量产检验,PASSWD=2;"; info += "USER=中置VP量产写入,PASSWD=1;"; info += "USER=中置VP量产检验,PASSWD=2;"; info += "USER=轮毂量产写入,PASSWD=3;"; info += "USER=轮毂量产检验,PASSWD=4;"; info += "USER=中置样机测试,PASSWD=5;"; info += "USER=轮毂样机测试,PASSWD=6;"; info += "USER=FCT治具测试,PASSWD=7;"; info += "USER=工程参数配置,PASSWD=123456;"; info += "USER=研发调试,PASSWD=123456;"; info += "USER=管理员,PASSWD=ttium.123"; //加密保存 aes.EncryptToFile(info, localInfo.LocalPath + localInfo.UsrFileName, "2D820F88F60A39D5", "3687C5216B19D16B"); } //解密 string decryptedText = aes.DecryptFromFile(localInfo.LocalPath + localInfo.UsrFileName, "2D820F88F60A39D5", "3687C5216B19D16B"); //获取账号 string[] userInfo = decryptedText.Split(';'); foreach (string info in userInfo) { if (info != null) { UserAccount.Add(info.Split(',')[0].Split('=')[1], info.Split(',')[1].Split('=')[1]); } } } catch (System.Exception) { MessageBox.Show("无账户信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); UserAccount.Add("未知用户", ""); } //账户名下拉列表更新 comboBox_User.Items.Clear(); foreach (string key in UserAccount.Keys) { comboBox_User.Items.Add(key); } //密码框清空 textBox_Passwd.Text = ""; } private void button_Login_Click(object sender, EventArgs e) { this.Close(); } private void button_keyboard_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("osk.exe"); } private void textBox_Passwd_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) this.Close(); } private void comboBox_User_SelectedIndexChanged(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } } }