Exemplo n.º 1
0
        /// <summary>
        /// 删除 指定任务的任务结束参数表
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="tpara"></param>
        /// <returns></returns>
        public DateTime GetTimePara(int taskId, TimePara tpara)
        {
            string sql = @"SELECT starttime FROM TaskPara 
WHERE tid=@tid 
  AND wd=@wd 
  AND shour=@shour 
  AND smin=@smin 
  AND runmin=@runmin";

            SQLiteParameter[] para = new[]
            {
                new SQLiteParameter("@tid", DbType.Int32)
                {
                    Value = taskId
                },
                new SQLiteParameter("@wd", DbType.Int32)
                {
                    Value = tpara.WeekOrDay
                },
                new SQLiteParameter("@shour", DbType.Int32)
                {
                    Value = tpara.StartHour
                },
                new SQLiteParameter("@smin", DbType.Int32)
                {
                    Value = tpara.StartMin
                },
                new SQLiteParameter("@runmin", DbType.Int32)
                {
                    Value = tpara.RunMinute
                },
            };
            object obj;

            lock (lockobj)
            {
                obj = SQLiteHelper.ExecuteScalar(Constr, sql, para);
            }
            if (obj == null || obj == DBNull.Value)
            {
                return(default(DateTime));
            }
            return(DateTime.Parse(obj.ToString()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 删除 指定任务的任务结束参数表
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="tpara"></param>
        /// <returns></returns>
        public bool DelTimePara(int taskId, TimePara tpara)
        {
            string sql = @"DELETE FROM TaskPara 
WHERE tid=@tid 
  AND wd=@wd 
  AND shour=@shour 
  AND smin=@smin 
  AND runmin=@runmin";

            SQLiteParameter[] para = new[]
            {
                new SQLiteParameter("@tid", DbType.Int32)
                {
                    Value = taskId
                },
                new SQLiteParameter("@wd", DbType.Int32)
                {
                    Value = tpara.WeekOrDay
                },
                new SQLiteParameter("@shour", DbType.Int32)
                {
                    Value = tpara.StartHour
                },
                new SQLiteParameter("@smin", DbType.Int32)
                {
                    Value = tpara.StartMin
                },
                new SQLiteParameter("@runmin", DbType.Int32)
                {
                    Value = tpara.RunMinute
                },
            };
            lock (lockobj)
            {
                return(SQLiteHelper.ExecuteNonQuery(Constr, sql, para) > 0);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加 指定任务的任务结束参数表
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="tpara"></param>
        /// <returns></returns>
        public bool AddTimePara(int taskId, TimePara tpara)
        {
            string sql = @"INSERT INTO TaskPara(tid, wd, shour, smin, runmin, starttime)
VALUES(@tid, @wd, @shour, @smin, @runmin, @starttime)";

            SQLiteParameter[] para = new[]
            {
                new SQLiteParameter("@tid", DbType.Int32)
                {
                    Value = taskId
                },
                new SQLiteParameter("@wd", DbType.Int32)
                {
                    Value = tpara.WeekOrDay
                },
                new SQLiteParameter("@shour", DbType.Int32)
                {
                    Value = tpara.StartHour
                },
                new SQLiteParameter("@smin", DbType.Int32)
                {
                    Value = tpara.StartMin
                },
                new SQLiteParameter("@runmin", DbType.Int32)
                {
                    Value = tpara.RunMinute
                },
                new SQLiteParameter("@starttime", DbType.String, 50)
                {
                    Value = tpara.StartTime.ToString("yyyy-MM-dd HH:mm:ss")
                },
            };
            lock (lockobj)
            {
                return(SQLiteHelper.ExecuteNonQuery(Constr, sql, para) > 0);
            }
        }
Exemplo n.º 4
0
        public static List <TimePara> GetPara(RunType runtype, string runtypepara)
        {
            var tmpret = new List <TimePara>();

            string tmppara = runtypepara;

            if (tmppara != null && (tmppara = tmppara.Trim()) != string.Empty)
            {
                //格式: 1-1:12,3:45|60;3-13:11,23:45
                string[] tmp = tmppara.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item1 in tmp)
                {
                    string item = item1;
                    // 每天运行时,加上1-,便于统一处理
                    if (runtype == RunType.PerDay)
                    {
                        item = "1-" + item;
                    }

                    string[] itemtmp = item.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                    if (itemtmp.Length != 2)
                    {
                        continue;
                    }

                    int weekOrDay;
                    // key必须是数字,即周几 或 每月几号
                    if (!int.TryParse(itemtmp[0], out weekOrDay))
                    {
                        continue;
                    }
                    // 每周运行,必须是周日到周六之间
                    if (runtype == RunType.PerWeek && (weekOrDay < 0 || weekOrDay > 6))
                    {
                        continue;
                    }
                    // 每月运行,必须是1到31号之间
                    if (runtype == RunType.PerMonth && (weekOrDay < 1 || weekOrDay > 31))
                    {
                        continue;
                    }

                    string[] valuetmp = itemtmp[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string valueitem in valuetmp)
                    {
                        //时间格式为 1:12 或 3:45|3600,没有竖线表示启动但不停止,竖线后面表示运行时长(分钟)
                        //如3:45|60表示,3点45启动,到4点45结束程序
                        string[] startEnd = valueitem.Split(new[] { '|' }, StringSplitOptions.None);

                        // 启动时间处理
                        string[] timetmp = startEnd[0].Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                        // 必须配置启动时间
                        if (timetmp.Length != 2)
                        {
                            continue;
                        }
                        uint hourStart, minStart;
                        if (!uint.TryParse(timetmp[0].Trim(), out hourStart) ||
                            !uint.TryParse(timetmp[1].Trim(), out minStart))
                        {
                            continue;
                        }

                        // 运行时长
                        int runtime;
                        if (startEnd.Length < 2 || !int.TryParse(startEnd[1], out runtime))
                        {
                            runtime = 0;
                        }

                        TimePara timepara = new TimePara
                        {
                            WeekOrDay = weekOrDay,
                            StartHour = (int)hourStart,
                            StartMin  = (int)minStart,
                            RunMinute = runtime,
                        };
                        tmpret.Add(timepara);
                    }
                }
            }
            return(tmpret);
        }