Login.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. FileStream fs = File.Create(localInfo.LocalPath + localInfo.UsrFileName);
  33. fs.Close();
  34. StreamWriter file = new StreamWriter(localInfo.LocalPath + localInfo.UsrFileName);
  35. file.WriteLine("USER=中置量产写入,PASSWD=1");
  36. file.WriteLine("USER=中置量产检验,PASSWD=2");
  37. file.WriteLine("USER=轮毂量产写入,PASSWD=3");
  38. file.WriteLine("USER=轮毂量产检验,PASSWD=4");
  39. file.WriteLine("USER=中置样机测试,PASSWD=5");
  40. file.WriteLine("USER=轮毂样机测试,PASSWD=6");
  41. file.WriteLine("USER=工程参数配置,PASSWD=123456");
  42. file.WriteLine("USER=研发调试,PASSWD=123456");
  43. file.WriteLine("USER=管理员,PASSWD=ttium.123");
  44. file.Close();
  45. }
  46. //读取配置文件
  47. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.UsrFileName);
  48. string sLine = "";
  49. List<string> userInfo = new List<string>();
  50. while (sLine != null)
  51. {
  52. sLine = objReader.ReadLine();
  53. userInfo.Add(sLine);
  54. }
  55. objReader.Close();
  56. foreach (string info in userInfo)
  57. {
  58. if (info != null)
  59. {
  60. UserAccount.Add(info.Split(',')[0].Split('=')[1], info.Split(',')[1].Split('=')[1]);
  61. }
  62. }
  63. }
  64. catch (System.Exception)
  65. {
  66. MessageBox.Show("无账户信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  67. UserAccount.Add("未知用户", "");
  68. }
  69. //账户名下拉列表更新
  70. comboBox_User.Items.Clear();
  71. foreach (string key in UserAccount.Keys)
  72. {
  73. comboBox_User.Items.Add(key);
  74. }
  75. //密码框清空
  76. textBox_Passwd.Text = "";
  77. }
  78. private void button_Login_Click(object sender, EventArgs e)
  79. {
  80. this.Close();
  81. }
  82. private void button_keyboard_Click(object sender, EventArgs e)
  83. {
  84. System.Diagnostics.Process.Start("osk.exe");
  85. }
  86. private void textBox_Passwd_KeyUp(object sender, KeyEventArgs e)
  87. {
  88. if (e.KeyCode == Keys.Enter)
  89. this.Close();
  90. }
  91. }
  92. }