private void button1_Click(object sender, EventArgs e) { user = new User(); user.Name = textBoxUser.Text; //if (user.Name.Equals("admin", StringComparison.OrdinalIgnoreCase)) //{ // return; //} fileName = user.Name + ".bin"; lockFileName = fileName + ".lock"; if (File.Exists(fileName)) { if (File.Exists(lockFileName)) { MessageBox.Show("此用户已登录,请注销后再登录"); return; } user = BinaryHelper.FileToObject(fileName); if (user.Password.Equals(textBoxPwd.Text)) { LoginInfo info = new LoginInfo(); info.LoginTime = DateTime.Now.ToString(); info.LogoffTime = info.LoginTime; user.Logs.Add(info); fsLock = File.Create(lockFileName); } else { MessageBox.Show("密码输入错误,请重新输入密码"); return; } } else { //if (string.IsNullOrEmpty(textBoxPwd.Text)) //{ // MessageBox.Show("密码不能为空"); // return; //} user.Password = textBoxPwd.Text; LoginInfo info = new LoginInfo(); info.LoginTime = DateTime.Now.ToString(); info.LogoffTime = info.LoginTime; user.Logs.Add(info); BinaryHelper.BinaryFileSave(fileName, user); fsLock = File.Create(lockFileName); MessageBox.Show("已创建新学员:" + user.Name + ";请牢记密码:" + user.Password); } this.Visible = false; MainForm form = new MainForm(user, this); form.Show(); form.FormClose += Form_FormClose; this.timer2.Enabled = true; }
private List <User> getUsersByPath(string path) { List <User> users = new List <User>(); List <string> files = getFileNames(path, "*.bin"); foreach (var file in files) { User u = BinaryHelper.FileToObject(file); users.Add(u); } return(users); }