Beispiel #1
0
        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;
        }
Beispiel #2
0
        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());
                    }
                }
            }
        }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     user.Logs[user.Logs.Count - 1].LogoffTime = DateTime.Now.ToString();
     BinaryHelper.BinaryFileSave(fileName, user);
 }