Example #1
0
        public int AddTimedEvent(TimedEvent timerEvent)
        {
            int result = 0;
            try
            {
                string sql = "INSERT INTO t_dingshi(Id,Frequency,Time,ExecEvents,FilePath)values(@Id,@Frequency,@Time,@ExecEvents,@FilePath)";

                SQLiteParameter[] parameters = new SQLiteParameter[]{
                                         new SQLiteParameter("@Id",timerEvent.Id),
                                         new SQLiteParameter("@Frequency",timerEvent.Frequency),
                                         new SQLiteParameter("@Time",timerEvent.Time.ToString("yyyy-MM-dd HH:mm:ss")),
                                         new SQLiteParameter("@ExecEvents",timerEvent.ExecEvents),
                                         new SQLiteParameter("@FilePath",timerEvent.FilePath)
                                         };
                SqlAction action = new SqlAction();
                result = action.IntQuery(sql, parameters);
            }
            catch
            {
            }
            return result;
        }
Example #2
0
 public iTimer(TimedEvent timerEvent)
 {
     InitializeComponent();
     _timerEvent = timerEvent;
     Init();
 }
Example #3
0
 private void ExecEvent(TimedEvent te)
 {
     try
     {
         switch (te.ExecEvents)
         {
             case "关机":
                 Process p = new Process();
                 p.StartInfo.FileName = "cmd.exe";
                 p.StartInfo.UseShellExecute = false;
                 p.StartInfo.RedirectStandardInput = true;
                 p.StartInfo.RedirectStandardOutput = true;
                 p.StartInfo.RedirectStandardError = true;
                 p.StartInfo.CreateNoWindow = true;
                 p.Start();
                 p.StandardInput.WriteLine("shutdown -s -f");
                 p.Close();
                 break;
             case "打开软件":
                 if (File.Exists(te.FilePath))
                     System.Diagnostics.Process.Start(te.FilePath);
                 if(list_TimedEvent.Contains(te)) list_TimedEvent.Remove(te);
                 break;
         }
     }
     catch (Exception ex)
     {
         log.WriteLog(ex.ToString());
     }
 }
Example #4
0
        private int DeleteTimedEvent(TimedEvent te)
        {
            int result = 0;
            try
            {
                result = _data.DeleteTimedEvent(te.Id);
                if (result == 0)
                {
                    MessageBox.Show("删除定时事件失败");
                    return result;
                }

                if (list_TimedEvent.Contains(te))
                {
                    list_TimedEvent.Remove(te);
                }
                panelTimedList.Controls.Clear();
                if (list_TimedEvent.Count > 0)
                {
                    foreach (TimedEvent item in list_TimedEvent)
                    {
                        iTimer itimer = new iTimer(item);
                        itimer.Dock = DockStyle.Top;
                        itimer.iTimerhandler += new iTimer.iTimerHandler(DeleteTimedEvent);
                        panelTimedList.Controls.Add(itimer);
                    }
                }
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.ToString());
            }
            return result;
        }
Example #5
0
        private void BtnAddTimedEvents_Click(object sender, EventArgs e)
        {
            try
            {
                if (labelFilepath.Visible && string.IsNullOrEmpty(labelFilepath.Text))
                {
                    MessageBox.Show("请选择需要打开的软件");
                    this.Visible = true;
                    tabControl.SelectedIndex = 2;
                    return;
                }
                newTimerEvent = new TimedEvent();
                for (int i = 0; i < 10000; i++)
                {
                    DataRow[] drs = table_TimedEvents.Select(string.Format("Id = {0}", i));
                    if (drs.Length == 0)
                    {
                        newTimerEvent.Id = i;
                        break;
                    }
                }
                newTimerEvent.Frequency = cbbFrequency.Text;
                newTimerEvent.Time = dateTimeEvent.Value;
                newTimerEvent.ExecEvents = cbbEvent.Text;
                newTimerEvent.FilePath = labelFilepath.Text;

                int result = _data.AddTimedEvent(newTimerEvent);
                if (result == 1)
                {
                    LoadTimedEvents();
                }
                else
                {
                    MessageBox.Show("添加失败");
                }
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.ToString());
            }
        }
Example #6
0
        private void LoadTimedEvents()
        {
            try
            {
                ResetTimedEventCondition();
                _data.DeleteTimedEvent(-1);//删除仅执行一次的过期定时事件
                table_TimedEvents = new DataTable();
                table_TimedEvents = _data.GetTimedEvents();
                panelTimedList.Controls.Clear();
                list_TimedEvent.Clear();
                if (table_TimedEvents != null && table_TimedEvents.Rows.Count > 0)
                {
                    foreach (DataRow dr in table_TimedEvents.Rows)
                    {
                        TimedEvent te = new TimedEvent();
                        te.Id = int.Parse(dr["Id"].ToString());
                        te.Frequency = dr["Frequency"].ToString();
                        te.Time = DateTime.Parse(dr["Time"].ToString());;
                        te.ExecEvents = dr["ExecEvents"].ToString();
                        te.FilePath = dr["FilePath"].ToString();

                        iTimer itimer = new iTimer(te);
                        itimer.Dock = DockStyle.Top;
                        itimer.iTimerhandler += new iTimer.iTimerHandler(DeleteTimedEvent);
                        panelTimedList.Controls.Add(itimer);
                        if (!list_TimedEvent.Contains(te)) list_TimedEvent.Add(te);
                    }
                }
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.ToString());
            }
        }
Example #7
0
 private bool IsTimeNow(DateTime time, TimedEvent te)
 {
     bool result = false;
     try
     {
         if (time.Hour == te.Time.Hour
             && time.Minute == te.Time.Minute)
             result = true;
     }
     catch (Exception ex)
     {
         log.WriteLog(ex.ToString());
     }
     return result;
 }