Login.cs 3.6 KB

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