Login.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace Welling_Motor_Debug_Tool
  12. {
  13. public partial class Login : Form
  14. {
  15. LocalInfo localInfo = new LocalInfo();
  16. public Login()
  17. {
  18. InitializeComponent();
  19. }
  20. public Dictionary<string, string> UserAccount = new Dictionary<string, string>();
  21. private void Login_Load(object sender, EventArgs e)
  22. {
  23. UserAccount.Clear();
  24. //读取账户信息
  25. try
  26. {
  27. //检查配置文件
  28. if (!Directory.Exists(localInfo.LocalPath))
  29. Directory.CreateDirectory(localInfo.LocalPath);
  30. if (!File.Exists(localInfo.LocalPath+localInfo.UsrFileName))
  31. {
  32. //设定账户密码
  33. string info = "";
  34. info += "USER=中置MG量产写入,PASSWD=1;";
  35. info += "USER=中置MG量产检验,PASSWD=2;";
  36. info += "USER=中置VP量产写入,PASSWD=1;";
  37. info += "USER=中置VP量产检验,PASSWD=2;";
  38. info += "USER=轮毂量产写入,PASSWD=3;";
  39. info += "USER=轮毂量产检验,PASSWD=4;";
  40. info += "USER=中置样机测试,PASSWD=5;";
  41. info += "USER=轮毂样机测试,PASSWD=6;";
  42. info += "USER=FCT治具测试,PASSWD=7;";
  43. info += "USER=工程参数配置,PASSWD=123456;";
  44. info += "USER=研发调试,PASSWD=123456;";
  45. info += "USER=管理员,PASSWD=ttium.123";
  46. //加密保存
  47. aes.EncryptToFile(info, localInfo.LocalPath + localInfo.UsrFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  48. }
  49. //解密
  50. string decryptedText = aes.DecryptFromFile(localInfo.LocalPath + localInfo.UsrFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  51. //获取账号
  52. string[] userInfo = decryptedText.Split(';');
  53. foreach (string info in userInfo)
  54. {
  55. if (info != null)
  56. {
  57. UserAccount.Add(info.Split(',')[0].Split('=')[1], info.Split(',')[1].Split('=')[1]);
  58. }
  59. }
  60. }
  61. catch (System.Exception)
  62. {
  63. MessageBox.Show("无账户信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  64. UserAccount.Add("未知用户", "");
  65. }
  66. //账户名下拉列表更新
  67. comboBox_User.Items.Clear();
  68. foreach (string key in UserAccount.Keys)
  69. {
  70. comboBox_User.Items.Add(key);
  71. }
  72. //密码框清空
  73. textBox_Passwd.Text = "";
  74. }
  75. private void button_Login_Click(object sender, EventArgs e)
  76. {
  77. this.Close();
  78. }
  79. private void button_keyboard_Click(object sender, EventArgs e)
  80. {
  81. System.Diagnostics.Process.Start("osk.exe");
  82. }
  83. private void textBox_Passwd_KeyUp(object sender, KeyEventArgs e)
  84. {
  85. if (e.KeyCode == Keys.Enter)
  86. this.Close();
  87. }
  88. private void comboBox_User_SelectedIndexChanged(object sender, EventArgs e)
  89. {
  90. }
  91. private void label1_Click(object sender, EventArgs e)
  92. {
  93. }
  94. }
  95. }