1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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<string, string> UserAccount = new Dictionary<string, string>();
- 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))
- {
- FileStream fs = File.Create(localInfo.LocalPath + localInfo.UsrFileName);
- fs.Close();
- StreamWriter file = new StreamWriter(localInfo.LocalPath + localInfo.UsrFileName);
- file.WriteLine("USER=工程Engineer,PASSWD=123456");
- file.WriteLine("USER=武汉Wuhan,PASSWD=1");
- file.WriteLine("USER=越南Vietnam,PASSWD=2");
- file.WriteLine("USER=研发RD,PASSWD=3");
- file.Close();
- }
- //读取配置文件
- StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.UsrFileName);
- string sLine = "";
- List<string> userInfo = new List<string>();
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- userInfo.Add(sLine);
- }
- objReader.Close();
- 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();
- }
- }
- }
|