Exemplo n.º 1
0
        public SchedulePeriodQuery GetSchedulePeriod(SchedulePeriodQuery query)
        {
            try
            {
                return _secheduleServiceDao.GetSchedulePeriod(query);
            }
            catch (Exception ex)
            {

                throw new Exception("SecheduleServiceMgr-->GetSchedulePeriod-->" + ex.Message, ex);
            }
        }
Exemplo n.º 2
0
          public SchedulePeriodQuery GetSchedulePeriod(SchedulePeriodQuery query)
          {
              StringBuilder sql = new StringBuilder();
              try
              {
                  sql.AppendFormat(@"SELECT `rowid`, `schedule_code`, `period_type`, `period_nums`, `begin_datetime`, `current_nums`, `limit_nums`, `create_user`, `create_time`, `change_user`, `change_time` 
 FROM `schedule_period` WHERE rowid = '{0}';", query.rowid);
                  return _access.getSinggleObj<SchedulePeriodQuery>(sql.ToString());
              }
              catch (Exception ex)
              {

                  throw new Exception("ScheduleServiceDao-->GetSchedulePeriod-->" + ex.Message, ex);
              }
          }
        //添加排程執行日誌
        private void ScheduleAddLog(string schedule_code)
        {
            ScheduleLogQuery query_log = new ScheduleLogQuery();
            query_log.schedule_code = schedule_code;

            try
            {
                //如果通過瀏覽器登陸;
                query_log.create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
            }
            catch (Exception)
            {
                //根據schedule_code獲取相應period的change_user
                ScheduleMasterQuery query_master = new ScheduleMasterQuery();
                query_master.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                ScheduleMasterQuery master = _secheduleServiceMgr.GetScheduleMaster(query_master);
                if (master.schedule_period_id != 0)
                {
                    SchedulePeriodQuery query_period = new SchedulePeriodQuery();
                    query_period.rowid = master.schedule_period_id;
                    query_period = _secheduleServiceMgr.GetSchedulePeriod(query_period);
                    query_log.create_user = query_period.change_user;
                }

            }

            query_log.ipfrom = BLL.gigade.Common.CommonFunction.GetIP4Address(Request.UserHostAddress.ToString());
            _secheduleServiceMgr.AddScheduleLog(query_log);
        }
        //可以多行刪除數據_period
        public HttpResponseBase SchedulePeriodDelete()
        {
            string json = string.Empty;
            SchedulePeriodQuery period = new SchedulePeriodQuery();
            _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
            try
            {
                string id = Request.Params["id"];
                id = id.Substring(0, id.Length - 1).ToString();
                string[] ids = id.Split(',');
                if (ids.Length>0)
                {

                    period.rowid = int.Parse(ids[0].ToString());
                    period = _secheduleServiceMgr.GetSchedulePeriod(period);

                    ScheduleMasterQuery query_master = new ScheduleMasterQuery();
                    query_master.schedule_code = period.schedule_code;
                    
                    //刪除
                    int result = _secheduleServiceMgr.SchedulePeriodDelete(id);
                    if (result > 0)
                    {
                         ScheduleMasterQuery item = _secheduleServiceMgr.GetScheduleMaster(query_master);
                        //更新ScheduleMaster表的previous_execute_time、next_execute_time、state;

                        //獲取next_execute_time和schedule_period_id
                        int schedule_period_id = 0;
                        int next_execute_time = _secheduleServiceMgr.GetNext_Execute_Time(item.schedule_code, out schedule_period_id);
                        //if (item.next_execute_time > next_execute_time || (item.next_execute_time == 0 && item.next_execute_time < next_execute_time))
                        {
                            item.next_execute_time = next_execute_time;
                            if (item.next_execute_time == 0)
                            {
                                item.schedule_state = 0;
                            }
                            item.schedule_period_id = schedule_period_id;
                            //修改ScheduleMaster
                            _secheduleServiceMgr.UpdateScheduleMaster(item);
                        }
                    }

                }
                json = "{success:true}";
            }
            #region 只刪除一行數據時的代碼段
            //if (!string.IsNullOrEmpty(Request.Params["id"]))
            //{
            //    query.id = Convert.ToUInt32(Request.Params["id"]);
            //}

            //  int _dt = informationMgr.PersonInfromationDelete(query);

            //if (_dt > 0)
            //{
            //    json = "{success:true}";
            //}
            //else
            //{
            //    json = "{success:false}";
            //}  
            #endregion
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        //保存排程_period信息 
        public HttpResponseBase SaveSchedulePeriodInfo()
        {
            string json = string.Empty;
            try
            {
                SchedulePeriodQuery query = new SchedulePeriodQuery();
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);

                if (!string.IsNullOrEmpty(Request.Params["rowid"]))
                {
                    query.rowid = Convert.ToInt32(Request.Params["rowid"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["schedule_code"]))
                {
                    query.schedule_code = Request.Params["schedule_code"];
                }
                if (!string.IsNullOrEmpty(Request.Params["period_type"]))
                {
                    query.period_type = Convert.ToUInt32(Request.Params["period_type"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["period_nums"]))
                {
                    query.period_nums = Convert.ToUInt32(Request.Params["period_nums"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["current_nums"]))
                {
                    query.current_nums = Convert.ToUInt32(Request.Params["current_nums"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["limit_nums"]))
                {
                    query.limit_nums = Convert.ToUInt32(Request.Params["limit_nums"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["begin_datetime"]))
                {
                    query.begin_datetime = (int)CommonFunction.GetPHPTime(Request.Params["begin_datetime"]);
                }
                query.create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                query.change_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                int _dt = _secheduleServiceMgr.SaveSchedulePeriodInfo(query);

                if (_dt > 0)
                {
                    json = "{success:true}";
                    //根據schedule_code獲取相應的ScheduleMaster信息
                    ScheduleMasterQuery query_master = new ScheduleMasterQuery();
                    query_master.schedule_code = query.schedule_code;
                    ScheduleMasterQuery item = _secheduleServiceMgr.GetScheduleMaster(query_master);
                    //更新ScheduleMaster表的previous_execute_time、next_execute_time、state;
                    
                    //獲取next_execute_time和schedule_period_id
                    int schedule_period_id = 0;
                    int next_execute_time = _secheduleServiceMgr.GetNext_Execute_Time(item.schedule_code, out schedule_period_id);
                    if (item.next_execute_time > next_execute_time || (item.next_execute_time == 0 && item.next_execute_time < next_execute_time))
                    {
                        item.next_execute_time = next_execute_time; ;
                        item.schedule_period_id = schedule_period_id;
                        _secheduleServiceMgr.UpdateScheduleMaster(item);
                    }
                    
                }
                else
                {
                    json = "{success:false}";
                }

                
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,totalCount:0,data:[]}";

            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return Response;

        }
        /// <summary>
        /// 獲取需要執行的排程列表并逐個執行,添加日誌和更新排程;
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase GetExeScheduleServiceList()
        {
            //獲取需要執行的排程

            List<ScheduleMasterQuery> store = new List<ScheduleMasterQuery>();
            _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);

            try
            {
                ScheduleMasterQuery query = new ScheduleMasterQuery();
                query.schedule_state = 1;
                store = _secheduleServiceMgr.GetExeScheduleMasterList(query);
                foreach (ScheduleMasterQuery item in store)
                {
                    try
                    {
                            //執行排程
                            bool result = ExeScheduleService(item.schedule_api,item.schedule_code);
                            
                            //更新SchedulePeriod表的current_nums;ScheduleMaster表的previous_execute_time、next_execute_time、state;
                            //更新current_nums欄位;
                            SchedulePeriodQuery query_period = new SchedulePeriodQuery();
                            query_period.rowid = item.schedule_period_id;
                            query_period = _secheduleServiceMgr.GetSchedulePeriod(query_period);
                            if (query_period != null)
                            {
                                query_period.current_nums += 1;
                                _secheduleServiceMgr.UpdateSchedulePeriod(query_period);
                            }

                            //更新ScheduleMaster表的previous_execute_time、next_execute_time、state;
                            item.previous_execute_time = (int)CommonFunction.GetPHPTime();
                            //獲取next_execute_time和schedule_period_id
                            int schedule_period_id = 0;
                            item.next_execute_time = _secheduleServiceMgr.GetNext_Execute_Time(item.schedule_code, out schedule_period_id);
                            item.schedule_period_id = schedule_period_id;
                            if (item.next_execute_time == 0)
                            {
                                item.schedule_state = 0;
                            }
                            _secheduleServiceMgr.UpdateScheduleMaster(item);
                    }
                    catch (Exception ex)
                    {
                        Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                        logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                        logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                        log.Error(logMessage);
                    }
                    
                }
                
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }
            //this.Response.Clear();
            //this.Response.Write();
            //this.Response.End();
            return this.Response;
        }
        }// 獲取 config數據

        public HttpResponseBase GetSchedulePeriodList()// 獲取period數據
        {
            string json = string.Empty;
            SchedulePeriodQuery query = new SchedulePeriodQuery();
            if (!string.IsNullOrEmpty(Request.Params["schedule_code"]))
            {
                query.schedule_code = Request.Params["schedule_code"];
            }
            try
            {
                List<SchedulePeriodQuery> ipodStore = new List<SchedulePeriodQuery>();
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                ipodStore = _secheduleServiceMgr.GetSchedulePeriodList(query);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                json = "{success:true,data:" + JsonConvert.SerializeObject(ipodStore, Formatting.Indented, timeConverter) + "}";//返回json數據
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;

        }
Exemplo n.º 8
0
 //schedule_period判断是新增 还是 编辑 
 public int SaveSchedulePeriodInfo(SchedulePeriodQuery query)
 {
     try
     {
         if (query.rowid == 0)//新增
         {
             return _secheduleServiceDao.SchedulePeriodInfoInsert(query);
         }
         else//編輯
         {
             return _secheduleServiceDao.SchedulePeriodInfoUpdate(query);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("ScheduleServiceMgr-->SaveSchedulePeriodInfo-->" + ex.Message);
     } 
 }
Exemplo n.º 9
0
        public List<SchedulePeriodQuery> GetSchedulePeriodList(SchedulePeriodQuery query)// period 
        {
            try
            {
                List<SchedulePeriodQuery> store = new List<SchedulePeriodQuery>();
                store = _secheduleServiceDao.GetSchedulePeriodList(query);
                foreach (var item in store)
                {
                    item.show_create_time = CommonFunction.GetNetTime(item.create_time).ToString("yyyy-MM-dd HH:mm:ss ");
                    item.show_change_time = CommonFunction.GetNetTime(item.change_time).ToString("yyyy-MM-dd HH:mm:ss ");
                   // item.show_begin_datetime = CommonFunction.GetNetTime(item.begin_datetime).ToString("yyyy-MM-dd HH:mm:ss ");
                    item.show_begin_datetime = CommonFunction.GetNetTime(item.begin_datetime);
                    if (item.period_type == 1)
                    {
                        item.show_period_type = "year";
                    }
                    if (item.period_type == 2)
                    {
                        item.show_period_type = "month";
                    }
                    if (item.period_type == 3)
                    {
                        item.show_period_type = "week";
                    }
                    if (item.period_type == 4)
                    {
                        item.show_period_type = "day";
                    }
                    if (item.period_type == 5)
                    {
                        item.show_period_type = "hour";
                    }
                    if (item.period_type == 6)
                    {
                        item.show_period_type = "minute";
                    }
                }
                return store;

            }
            catch (Exception ex)
            {

                throw new Exception("SecheduleServiceMgr-->GetSchedulePeriodList-->" + ex.Message, ex);
            }
        }
Exemplo n.º 10
0
 public int SchedulePeriodInfoUpdate(SchedulePeriodQuery query) //更新schedule_period信息
 {
     StringBuilder sql = new StringBuilder();
     query.Replace4MySQL();
     try
     {
         sql.AppendFormat("update schedule_period set schedule_code = '{0}', period_type = '{1}', period_nums = '{2}',begin_datetime='{3}',current_nums='{4}',create_user='******',change_user='******',change_time='{7}',limit_nums='{8}' where rowid='{9}' ", query.schedule_code, query.period_type, query.period_nums, query.begin_datetime, query.current_nums, query.create_user, query.change_user, CommonFunction.GetPHPTime(DateTime.Now.ToString()), query.limit_nums, query.rowid);
         return _access.execCommand(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ScheduleServiceDao-->SchedulePeriodInfoUpdate-->" + sql.ToString() + ex.Message);
     }
 }
Exemplo n.º 11
0
 public int SchedulePeriodInfoInsert(SchedulePeriodQuery query)//插入schedule_period信息
 {
     StringBuilder sql = new StringBuilder();
     query.Replace4MySQL();
     try
     {
         sql.Append("insert into schedule_period ( schedule_code,period_type,period_nums,current_nums,limit_nums,begin_datetime,create_user,change_user, create_time, change_time) values ");
         sql.AppendFormat("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", query.schedule_code, query.period_type, query.period_nums, query.current_nums, query.limit_nums, query.begin_datetime, query.create_user, query.change_user, CommonFunction.GetPHPTime(DateTime.Now.ToString()), CommonFunction.GetPHPTime(DateTime.Now.ToString()));
         return _access.execCommand(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ScheduleServiceDao-->SchedulePeriodInfoInsert-->" + sql.ToString() + ex.Message);
     }
 }
Exemplo n.º 12
0
 public List<SchedulePeriodQuery> GetSchedulePeriodList(SchedulePeriodQuery query)// 得到 period表中的記錄
 {
     StringBuilder sql = new StringBuilder();
     StringBuilder sqlCondi = new StringBuilder();
     try
     {
         sql.AppendFormat("SELECT sp.rowid,sp.schedule_code,sp.period_type,sp.period_nums,sp.begin_datetime,sp.current_nums,sp.limit_nums,mu1.user_username as create_username,mu2.user_username as change_username,sp.create_time,sp.change_time  FROM schedule_period sp");
         sqlCondi.Append(" LEFT JOIN schedule_master sm on sm.schedule_code=sp.schedule_code ");
         sqlCondi.Append(" LEFT JOIN manage_user mu1 on mu1.user_id=sp.create_user ");
         sqlCondi.Append(" LEFT JOIN manage_user mu2 on mu2.user_id=sp.change_user ");
         sqlCondi.Append(" where 1=1 ");
         if (!string.IsNullOrEmpty(query.schedule_code))
         {
             sqlCondi.AppendFormat(" and sm.schedule_code='{0}' ", query.schedule_code);
         }
         sql.Append(sqlCondi.ToString());
         return _access.getDataTableForObj<SchedulePeriodQuery>(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ScheduleServiceDao-->GetSchedulePeriodList-->" + ex.Message, ex);
     }
 }
Exemplo n.º 13
0
          public int UpdateSchedulePeriod(SchedulePeriodQuery query)
          {
              StringBuilder sql = new StringBuilder();
              try
              {
                  sql.AppendFormat(@"
UPDATE  `schedule_period` SET `schedule_code`='{0}', `period_type`='{1}', `period_nums`='{2}', `begin_datetime`='{3}', `current_nums`='{4}', `limit_nums`='{5}', `create_user`='{6}', `create_time`='{7}', `change_user`='{8}', `change_time`='{9}' WHERE `rowid`='{10}'
;", query.schedule_code, query.period_type, query.period_nums, query.begin_datetime, query.current_nums, query.limit_nums, query.create_user, query.create_time, query.change_user, Common.CommonFunction.GetPHPTime(DateTime.Now.ToString()), query.rowid);
                  return _access.execCommand(sql.ToString());
              }
              catch (Exception ex)
              {

                  throw new Exception("ScheduleServiceDao-->UpdateSchedulePeriod-->" + ex.Message, ex);
              }
          }