private void timer2_Tick(object sender, EventArgs e) { int x1 = Control.MousePosition.X; int y1 = Control.MousePosition.Y; if ((x == x1) && (y == y1) && ff) { start = DateTime.Now; ff = false; } if (x != x1 || y != y1) { x = x1; y = y1; start = DateTime.Now; ff = true; } TimeSpan ts = DateTime.Now.Subtract(start); if (ts.Minutes >= timeLogOut) { timer2.Stop(); StopTime = DateTime.Now.AddMinutes(-timeLogOut).ToString(); user.RestCount++; BinaryHelper.BinaryFileSave(fileName, user); ff = true; showWindow(); string msg = string.Format("您已休息{0}分钟,并记录到档案,请抓紧学习!\n点击确定后重新登录,培训时间重新计时!", timeLogOut); DialogResult result = MessageBox.Show(msg, "学习提醒", MessageBoxButtons.OK, MessageBoxIcon.Information); if (result == DialogResult.OK) { if (TimeUp != null) { TimeUp(this, new System.EventArgs()); } } } }
private void Form_FormClose(object sender, EventArgs e) { if (ff && !string.IsNullOrEmpty(StopTime)) { user.Logs[user.Logs.Count - 1].LogoffTime = StopTime; } else { user.Logs[user.Logs.Count - 1].LogoffTime = DateTime.Now.ToString(); } BinaryHelper.BinaryFileSave(fileName, user); if (File.Exists(lockFileName)) { if (fsLock != null) { fsLock.Close(); } File.Delete(lockFileName); } this.textBoxUser.Clear(); this.textBoxPwd.Clear(); this.Visible = true; }
private void timer1_Tick(object sender, EventArgs e) { user.Logs[user.Logs.Count - 1].LogoffTime = DateTime.Now.ToString(); BinaryHelper.BinaryFileSave(fileName, user); }