Login.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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=工程Engineer,PASSWD=123456");
  36. file.WriteLine("USER=武汉Wuhan,PASSWD=1");
  37. file.WriteLine("USER=越南Vietnam,PASSWD=2");
  38. file.WriteLine("USER=研发RD,PASSWD=3");
  39. file.Close();
  40. }
  41. //读取配置文件
  42. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.UsrFileName);
  43. string sLine = "";
  44. List<string> userInfo = new List<string>();
  45. while (sLine != null)
  46. {
  47. sLine = objReader.ReadLine();
  48. userInfo.Add(sLine);
  49. }
  50. objReader.Close();
  51. foreach (string info in userInfo)
  52. {
  53. if (info != null)
  54. {
  55. UserAccount.Add(info.Split(',')[0].Split('=')[1], info.Split(',')[1].Split('=')[1]);
  56. }
  57. }
  58. }
  59. catch (System.Exception)
  60. {
  61. MessageBox.Show("无账户信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  62. UserAccount.Add("未知用户", "");
  63. }
  64. //账户名下拉列表更新
  65. comboBox_User.Items.Clear();
  66. foreach (string key in UserAccount.Keys)
  67. {
  68. comboBox_User.Items.Add(key);
  69. }
  70. //密码框清空
  71. textBox_Passwd.Text = "";
  72. }
  73. private void button_Login_Click(object sender, EventArgs e)
  74. {
  75. this.Close();
  76. }
  77. private void button_keyboard_Click(object sender, EventArgs e)
  78. {
  79. System.Diagnostics.Process.Start("osk.exe");
  80. }
  81. private void textBox_Passwd_KeyUp(object sender, KeyEventArgs e)
  82. {
  83. if (e.KeyCode == Keys.Enter)
  84. this.Close();
  85. }
  86. }
  87. }