/// <summary> /// 启动项管理 /// </summary> private void StartupItem_Click(object sender, EventArgs e) { //状态 string state = string.Empty; try { System.Windows.Controls.MenuItem mi = (System.Windows.Controls.MenuItem)sender; state = mi.Tag.ToString(); } catch { System.Windows.Forms.MenuItem mi = (System.Windows.Forms.MenuItem)sender; state = mi.Tag.ToString(); } //开机启动 if (state == "SelfStarting") { Bll.BootUp(); if (Tips.Function == false) { Tips tp = new Tips("已经设置开机自启~"); tp.Show(); } } else { Bll.BootUp(false); if (Tips.Function == false) { Tips tp = new Tips("已经取消了开机自启~"); tp.Show(); } } }
/// <summary> /// 时钟事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer_Tick(object sender, EventArgs e) { if ((int)md.State == 1) { Count = 0; this.Visibility = Visibility.Collapsed; return; } if (md.Display != 0) { //非全屏显示,全屏下隐藏 if (!bll.FullScreen()) { this.Visibility = Visibility.Visible; } else { this.Visibility = Visibility.Collapsed; } } //正常模式 = 0, 智能计时 = 1, 加班模式 = 2, 游戏模式 = 3 switch ((int)md.TimerMode) { //正常模式 case 0: { Count++; break; } //重写智能计时 case 1: { //判断是否全屏 if (!bll.FullScreen()) //非全屏 { Count++; //判断系统是否处于空闲时间 if (Bll.GetLastInputTime() < 1000) { //检测到键盘鼠标活动就清空暂离累计时间 FreeCount = 0; } //如果电脑5分无人进行操作,那么就重新开始计时 else if (FreeCount >= 300) { //重新开始计时 Count = 0; } else { //判断是否处于暂离状态 FreeCount++; } } else { //全屏下 默认认为处于工作,清空空闲累计时间,并且累计工作时间。 Count++; FreeCount = 0; } break; } //加班模式 case 2: { Count++; break; } //游戏模式 case 3: { //如果不处于空闲时间 if (Bll.GetLastInputTime() < 1000) { //非全屏 if (!bll.FullScreen()) { Count++; } else { //判断工作时间是否已经到达,在游戏模式中,如果检测到全屏,会在即将锁屏的前一秒停止计时 if (md.Work * 60 > (Count + 1)) { Count++; } } //清空暂离状态 FreeCount = 0; } else { //判断是否处于暂离状态 FreeCount++; //如果电脑5分无人进行操作,那么就重新开始计时 if (FreeCount >= 300) { //重新开始计时 Count = 0; } } break; } } if (md.Work * 60 >= Count) { Time.Content = Bll.GetFormattingTime(Count.ToString()); md.AlreadyWorked = md.Work / 60; } //判断是否启用自动关机 if (md.Shutdown.Time != -1 && md.Shutdown.Branch != -1) { //分割时间 string[] time = DateTime.Now.ToLongTimeString().ToString().Split(new string[] { ":" }, StringSplitOptions.None); //关机前的提醒,如果是整点,也就是0,你需要做好这个判断 //是否为0分 if (md.Shutdown.Branch == 0) { //是否为0时 if (md.Shutdown.Time == 0) { if (Convert.ToInt32(time[0]) == 23 && Convert.ToInt32(time[1]) == 59 && Convert.ToInt32(time[2]) == 3) { if (Tips.Function == false) { Tips tp = new Tips("当前时间为:" + DateTime.Now.ToLongTimeString().ToString() + " 距离关机还有1分钟,请您注意保存好数据信息~"); tp.Show(); } } } else { if (Convert.ToInt32(time[0]) == (md.Shutdown.Time - 1) && Convert.ToInt32(time[1]) == 59 && Convert.ToInt32(time[2]) == 3) { if (Tips.Function == false) { Tips tp = new Tips("当前时间为:" + DateTime.Now.ToLongTimeString().ToString() + " 距离关机还有1分钟,请您注意保存好数据信息~"); tp.Show(); } } } } else { //到达关机时间 if (Convert.ToInt32(time[0]) == md.Shutdown.Time && Convert.ToInt32(time[1]) == (md.Shutdown.Branch - 1) && Convert.ToInt32(time[2]) == 3) { if (Tips.Function == false) { Tips tp = new Tips("当前时间为:" + DateTime.Now.ToLongTimeString().ToString() + " 距离关机还有1分钟,请您注意保存好数据信息~"); tp.Show(); } } } //到达关机时间 if (Convert.ToInt32(time[0]) == md.Shutdown.Time && Convert.ToInt32(time[1]) == md.Shutdown.Branch && Convert.ToInt32(time[2]) == 3) { timer.Stop(); Process.Start("shutdown", " -s -t 0"); } } //休息前的提醒 游戏模式下不进行提醒 if ((md.Work - 1) * 60 == Count && (int)md.TimerMode != 3) { if (Tips.Function == false) { Tips tp = new Tips("您已经工作了" + (Count / 60) + "分钟,1分钟后进入休息时间!"); tp.Show(); } } //到达休息时间 if (md.Work * 60 == Count) { md.State = (state)1; if (LockScreenⅡ.Function == false) { LockScreenⅡ ls = new LockScreenⅡ(md); try { //限制到第一个屏幕显示 Screen[] sc = Screen.AllScreens; ls.Location = new System.Drawing.Point(sc[0].Bounds.Left, sc[0].Bounds.Top); } catch { } ls.Show(); } } }
/// <summary> /// 时钟事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer_Tick(object sender, EventArgs e) { if ((int)md.State == 1) { Count = 0; return; } //正常模式 = 0, 智能计时 = 1, 加班模式 = 2, 游戏模式 = 3 switch ((int)md.TimerMode) { //正常模式 case 0: { Count++; break; } //智能计时 case 1: { //判断是否全屏 if (!bll.FullScreen()) //非全屏 { //判断系统是否处于空闲时间 if (Bll.GetLastInputTime() < 1000) { //如果不处于空闲时间 Count++; //清空暂离状态 FreeCount = 0; } else { //判断是否处于暂离状态 FreeCount++; //如果电脑5分无人进行操作,那么就重新开始计时 if (FreeCount >= 300) { //重新开始计时 Count = 0; } } } break; } //加班模式 case 2: { Count++; break; } //游戏模式 case 3: { //如果不处于空闲时间 if (Bll.GetLastInputTime() < 1000) { //非全屏 if (!bll.FullScreen()) { Count++; } else { //判断工作时间是否已经到达,在游戏模式中,如果检测到全屏,会在即将锁屏的前一秒停止计时 if (md.Work * 60 > (Count + 1)) { Count++; } } //清空暂离状态 FreeCount = 0; } else { //判断是否处于暂离状态 FreeCount++; //如果电脑5分无人进行操作,那么就重新开始计时 if (FreeCount >= 300) { //重新开始计时 Count = 0; } } break; } } if (md.Work * 60 >= Count) { Time.Content = Bll.GetFormattingTime(Count.ToString()); md.AlreadyWorked = md.Work / 60; } //判断是否启用自动关机 if (md.Shutdown.Time != -1 && md.Shutdown.Branch != -1) { //分割时间 string[] time = DateTime.Now.ToLongTimeString().ToString().Split(new string[] { ":" }, StringSplitOptions.None); //关机前的提醒,如果是整点,也就是0,你需要做好这个判断 //是否为0分 if (md.Shutdown.Branch == 0) { //是否为0时 if (md.Shutdown.Time == 0) { if (Convert.ToInt32(time[0]) == 23 && Convert.ToInt32(time[1]) == 59 && Convert.ToInt32(time[2]) == 3) { if (Tips.Function == false) { Tips tp = new Tips("当前时间为:" + DateTime.Now.ToLongTimeString().ToString() + " 距离关机还有1分钟,请您注意保存好数据信息~"); tp.Show(); } } } else { if (Convert.ToInt32(time[0]) == (md.Shutdown.Time - 1) && Convert.ToInt32(time[1]) == 59 && Convert.ToInt32(time[2]) == 3) { if (Tips.Function == false) { Tips tp = new Tips("当前时间为:" + DateTime.Now.ToLongTimeString().ToString() + " 距离关机还有1分钟,请您注意保存好数据信息~"); tp.Show(); } } } } else { //到达关机时间 if (Convert.ToInt32(time[0]) == md.Shutdown.Time && Convert.ToInt32(time[1]) == (md.Shutdown.Branch - 1) && Convert.ToInt32(time[2]) == 3) { if (Tips.Function == false) { Tips tp = new Tips("当前时间为:" + DateTime.Now.ToLongTimeString().ToString() + " 距离关机还有1分钟,请您注意保存好数据信息~"); tp.Show(); } } } //到达关机时间 if (Convert.ToInt32(time[0]) == md.Shutdown.Time && Convert.ToInt32(time[1]) == md.Shutdown.Branch && Convert.ToInt32(time[2]) == 3) { timer.Stop(); Process.Start("shutdown", " -s -t 0"); } } //休息前的提醒 游戏模式下不进行提醒 if ((md.Work - 1) * 60 == Count && (int)md.TimerMode != 3) { if (Tips.Function == false) { Tips tp = new Tips("您已经工作了" + (Count / 60) + "分钟,1分钟后进入休息时间!"); tp.Show(); } } //到达休息时间 if (md.Work * 60 == Count) { md.State = (state)1; if (LockScreen.Function == false) { LockScreen ls = new LockScreen(md); ls.Show(); } } }