コード例 #1
0
ファイル: Manager.cs プロジェクト: wwkkww1983/ShanxiEPM
        private void SetButtonState()
        {
            if (InRefreshStateing)
            {
                return;
            }

            InRefreshStateing = true;
            Application.DoEvents();

            try
            {
                tsmClose.Enabled     = true;
                cmsMain.Enabled      = true;
                this.tsmShow.Enabled = !this.Visible;
                this.tsmHide.Enabled = this.Visible;
                try
                {
                    if (!this.HasGetRegistry)
                    {
                        this.btnStart.Enabled = false;
                        tbMsg.Text            = "服务未注册!";
                    }
                    else
                    {
                        sc = new ServiceController(svcName);
                        if (sc.Status == ServiceControllerStatus.Running)
                        {
                            tbMsg.Text                = "服务已经启动,正在运行。";
                            StateProgressBar.Style    = ProgressBarStyle.Marquee;
                            this.btnInstall.Enabled   = false;
                            this.btnUnInstall.Enabled = false;
                            this.btnStart.Enabled     = false;
                            this.tsmStart.Enabled     = false;
                            this.btnStop.Enabled      = true;
                            this.tsmStop.Enabled      = true;
                            btnImportKey.Enabled      = false;
                            btnDBTest.Enabled         = false;
                            if (!HasResetIcon)
                            {
                                string FileName = AppDomain.CurrentDomain.BaseDirectory + "Run.ico";
                                if (System.IO.File.Exists(FileName))
                                {
                                    MainnotifyIcon.Icon = Icon.ExtractAssociatedIcon("Run.ico");
                                    this.Icon           = Icon.ExtractAssociatedIcon("Run.ico");
                                }
                                HasResetIcon = true;
                            }
                        }
                        else
                        {
                            tbMsg.Text                = "服务未启动";
                            StateProgressBar.Style    = ProgressBarStyle.Continuous;
                            this.btnInstall.Enabled   = false;
                            this.btnUnInstall.Enabled = true;
                            this.btnStart.Enabled     = true;
                            this.tsmStart.Enabled     = true;
                            this.btnStop.Enabled      = false;
                            this.tsmStop.Enabled      = false;
                            btnImportKey.Enabled      = true;
                            btnDBTest.Enabled         = true;
                        }
                        tsmClose.Enabled         = true;
                        this.cbAutoStart.Enabled = true;

                        ServiceInstaller si = new ServiceInstaller();
                        this.cbAutoStart.Checked = si.GetServiceStart_Type(svcName);
                    }
                }
                catch (Exception ex)
                {
                    //if (ex.InnerException.Message == "指定的服务未安装。")
                    //{
                    this.btnInstall.Enabled   = true;
                    this.cbAutoStart.Enabled  = false;
                    this.btnUnInstall.Enabled = false;
                    this.btnStart.Enabled     = false;
                    this.btnStop.Enabled      = false;
                    this.tsmStart.Enabled     = false;
                    this.tsmStop.Enabled      = false;
                    btnDBTest.Enabled         = false;
                    btnImportKey.Enabled      = false;
                    //}

                    this.MainnotifyIcon.BalloonTipText = ex.Message;
                    this.MainnotifyIcon.ShowBalloonTip(1000);
                }
            }
            finally
            {
                InRefreshStateing = false;
            }
        }
コード例 #2
0
ファイル: Manager.cs プロジェクト: wwkkww1983/ShanxiEPM
        private void cbAutoStart_CheckedChanged(object sender, EventArgs e)
        {
            ServiceInstaller si = new ServiceInstaller();

            si.SetServiceStart_Type(svcName, cbAutoStart.Checked);
        }