예제 #1
0
        private void CbBlockSystemSleep_CheckedChanged(object sender, EventArgs e)
        {
            if (this.cbBlockSystemSleep.Checked)
            {
                SystemSleepManagement.PreventSleep(this.cbBlockScreenOff.Checked);
            }
            else
            {
                this.cbBlockScreenOff.CheckedChanged -=
                    new System.EventHandler(this.CbBlockScreenOff_CheckedChanged);
                this.cbBlockScreenOff.Checked         = false;
                this.cbBlockScreenOff.CheckedChanged +=
                    new System.EventHandler(this.CbBlockScreenOff_CheckedChanged);

                SystemSleepManagement.ResotreSleep();
            }
        }
예제 #2
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            // 通知栏右键退出
            if (exitFlag)
            {
                SaveConfig();
                if (stopDateTime == DateTime.MinValue)
                {
                    stopDateTime = DateTime.Now;
                }
                this.sqlite.UpdateStopTime(this.startStopTimeId, stopDateTime, !systemShutdown);
                SystemSleepManagement.ResotreSleep();
                RegisterAppBar(true);
            }
            else
            {
                switch (e.CloseReason)
                {
                case CloseReason.UserClosing:
                    e.Cancel                = true;
                    this.WindowState        = FormWindowState.Minimized;
                    this.ShowInTaskbar      = false;
                    this.notifyIcon.Visible = true;
                    break;

                default:
                    exitFlag = true;
                    SaveConfig();
                    if (stopDateTime == DateTime.MinValue)
                    {
                        stopDateTime = DateTime.Now;
                    }
                    this.sqlite.UpdateStopTime(this.startStopTimeId, stopDateTime, !systemShutdown);
                    SystemSleepManagement.ResotreSleep();
                    RegisterAppBar(true);
                    break;
                }
            }
        }
예제 #3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.Icon = Properties.Resources.Startup;

            this.dataGridView.AutoGenerateColumns   = false;
            this.dataGridView.AllowUserToResizeRows = false;
            this.dataGridView.ContextMenuStrip      = this.contextMenuStripForDataGridView;

            this.ColumnIndex.DataPropertyName    = "index";
            this.ColumnURL.DataPropertyName      = "url";
            this.ColumnDomain.DataPropertyName   = "domain";
            this.ColumnInterval.DataPropertyName = "interval";
            this.ColumnLast.DataPropertyName     = "last";
            this.ColumnNeed.DataPropertyName     = "need";

            this.notifyIcon.Visible          = false;
            this.notifyIcon.Icon             = Properties.Resources.Startup;
            this.notifyIcon.Text             = "MyStartup";
            this.notifyIcon.ContextMenuStrip = this.contextMenuStrip;

            this.cbStartWithSystem.Checked  = Config.GetInstance().settingData.StartWithSystem;
            this.cbBlockScreenOff.Checked   = Config.GetInstance().settingData.BlockScreenOff;
            this.cbBlockSystemSleep.Checked = Config.GetInstance().settingData.BlockSystemSleep;
            this.textBoxDelayHour.Text      = Config.GetInstance().settingData.DelayHours.ToString();

            string strTemp = Config.GetInstance().settingData.NotAutoVisitTime;

            if (!string.IsNullOrWhiteSpace(strTemp))
            {
                DateTime dateTime = DateTime.Now;
                if (DateTime.TryParse(strTemp, out dateTime) && dateTime > DateTime.Now)
                {
                    this.cbNotAutoVisit.Checked = true;
                    notAutoVisitTime            = dateTime;
                    this.labelInfo.Text         = string.Format(
                        "到 {0} 结束", dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                }
            }

            // 打开程序30分钟内不自动访问网址
            if (notAutoVisitTime == null || (notAutoVisitTime < DateTime.Now.AddHours(0.5)))
            {
                notAutoVisitTime            = DateTime.Now.AddHours(0.5);
                this.cbNotAutoVisit.Checked = true;
                this.textBoxDelayHour.Text  = "0.5";
                this.labelInfo.Text         = string.Format(
                    "到 {0} 结束", notAutoVisitTime?.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            this.textBoxDelayHour.Enabled       = !this.cbNotAutoVisit.Checked;
            this.cbNotAutoVisit.CheckedChanged +=
                new System.EventHandler(this.CbNotAutoVisit_CheckedChanged);

            if (!Debugger.IsAttached)
            {
                StartWithSystem.SetStartWithSystem(this.cbStartWithSystem.Checked);
            }

            if (this.cbBlockSystemSleep.Checked)
            {
                SystemSleepManagement.PreventSleep(this.cbBlockScreenOff.Checked);
            }

            this.cbBlockSystemSleep.CheckedChanged +=
                new System.EventHandler(this.CbBlockSystemSleep_CheckedChanged);
            this.cbBlockScreenOff.CheckedChanged +=
                new System.EventHandler(this.CbBlockScreenOff_CheckedChanged);
            this.cbStartWithSystem.CheckedChanged +=
                new System.EventHandler(this.CbStartWithSystem_CheckedChanged);

            //gridViewData = ChromeInfo.GetGridViewDataFromChromeBookMark(
            //    new List<string>() { "P1", "P2" });

            gridViewData = new DataTable();
            gridViewData.Columns.Add("index", typeof(int));
            gridViewData.Columns.Add("url", typeof(string));
            gridViewData.Columns.Add("domain", typeof(string));
            gridViewData.Columns.Add("interval", typeof(double));
            gridViewData.Columns.Add("last", typeof(string));
            gridViewData.Columns.Add("need", typeof(double));

            List <Config.URLTimedAccess> URLTimedAccessList =
                Config.GetInstance().settingData.URLTimedAccessList;
            int index = 1;

            foreach (Config.URLTimedAccess urlTimedAccess in URLTimedAccessList)
            {
                DataRow dr = gridViewData.NewRow();
                dr[0] = index++;
                dr[1] = urlTimedAccess.URL;
                dr[2] = urlTimedAccess.Domain;
                dr[3] = urlTimedAccess.Interval;
                dr[4] = urlTimedAccess.Last;
                dr[5] = 0;
                gridViewData.Rows.Add(dr);
            }

            lock (lockThreadObject)
            {
                UpdateByChromeHistory(false);
                UpdateNeededTime();
            }
            this.dataGridView.DataSource = gridViewData;

            Thread thread = new Thread(new ThreadStart(ThreadAction));

            thread.Start();

            RegisterAppBar(false);

            this.sqlite = new Sqlite(Sqlite.SqliteDefaultDateBasePath);
            this.sqlite.CreateStartStopTimeTable();

            //DateTime lastShutdownTime = Helper.GetSystemLastShutdownTime();
            //if (lastShutdownTime != DateTime.MinValue)
            //{
            //    DataTable dt = this.sqlite.GetLastRowData();
            //    if (dt != null && dt.Rows.Count == 1 &&
            //        Convert.ToBoolean(dt.Rows[0]["complete"]) &&
            //        (!Convert.ToBoolean(dt.Rows[0]["manual_exit"])))
            //    {
            //        this.sqlite.UpdateStopTime(Convert.ToInt32(dt.Rows[0]["id"]),
            //            lastShutdownTime, false);
            //    }
            //}

            this.startStopTimeId = sqlite.InsertStartTime(DateTime.Now);

            if (!Directory.Exists(MyStartupApplicationDataFolder))
            {
                Directory.CreateDirectory(MyStartupApplicationDataFolder);
            }

            this.WindowState = FormWindowState.Minimized;
        }