Exemplo n.º 1
0
        protected void InitializeService()
        {
            try
            {
                DataTable          dt           = BaseService.Open("SystemService_All", null);
                List <Sys_Service> sys_Services = EntityHelper.GetEntities <Sys_Service>(dt);
                foreach (Sys_Service svr in sys_Services)
                {
                    Timer timer = new Timer();
                    int   ti    = 1000 * svr.Service_Unit * svr.Service_Interval;
                    timer.Interval = ti > 0 ? ti : 1000;
                    timer.Tick    += delegate
                    {
                        //加载页面
                        if (!string.IsNullOrEmpty(svr.Service_Page))
                        {
                            ChildPage cp = SharedFunc.LoadPage(svr.Service_Page);
                            if (cp == null || cp.SysPage == null)
                            {
                                return;
                            }
                            switch ((Sys_Menu_Show)cp.SysPage.Menu_Show)
                            {
                            case Sys_Menu_Show.MdiChild:
                                cp.MdiParent = this;
                                cp.Show();
                                break;

                            case Sys_Menu_Show.Dialog:
                                cp.ShowDialog();
                                break;

                            case Sys_Menu_Show.NewForm:
                                cp.Show();
                                break;

                            default:
                                break;
                            }
                        }
                        //执行WorkSet
                        if (!string.IsNullOrEmpty(svr.Service_WorkSet))
                        {
                            BaseService.Execute(svr.Service_WorkSet, null);
                        }
                        //执行文件
                        if (!string.IsNullOrEmpty(svr.Service_File))
                        {
                            Process.Start(svr.Service_File, svr.Service_Parameter);
                        }
                        if (svr.Service_Once)
                        {
                            timer.Enabled = false;
                        }
                    };
                    timer.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }