public static void CloseDialog()
 {
     if (sDialog != null)
     {
         sDialog.Close();
         sDialog = null;
     }
 }
Example #2
0
        private void CheckPowerLineStatus()
        {
            //checks if power has been lost or restored
            PowerLineStatus currPowerLineStatus = SystemInformation.PowerStatus.PowerLineStatus;

            if (prevPowerLineStatus == PowerLineStatus.Online)
            {
                if (currPowerLineStatus == PowerLineStatus.Offline || currPowerLineStatus == PowerLineStatus.Unknown)
                {
                    if (!pNotif)
                    {
                        pNotif = true;
                        switch (cbShutdownAction.SelectedIndex)
                        {
                        case 0:
                            int action = SelectionInputDialog.ShowSelectionInputDialog(this, "Choose Shutdown Action", ShutdownManager.GetShutdownActions(SHUTDOWN_TYPE.SHUTDOWN_POWER_LOSS));
                            //make sure we have a valid shutdown action
                            if (action >= 0)
                            {
                                ShutdownManager.Shutdown((SHUTDOWN_ACTION_POWER_LOSS)action);
                            }
                            break;

                        default:
                            SHUTDOWN_ACTION_POWER_LOSS sdAction = (SHUTDOWN_ACTION_POWER_LOSS)cbShutdownAction.SelectedIndex;
                            ShutdownManager.Shutdown(sdAction);
                            //MessageBox.Show(this, "Computer Shutdown Mode: " + sdAction.ToString(), "Warning");
                            break;
                        }
                        //notifications come as dialogs which will block the
                        //execution of the statements after it
                        //execution continues when the dialog is closed,
                        //when this happens, notification is closed
                        pNotif = false;
                    }
                }
            }
            else
            {
                if (currPowerLineStatus == PowerLineStatus.Online)
                {
                    if (pNotif)
                    {
                        SelectionInputDialog.CloseDialog();
                        pNotif = false;
                    }
                }
            }
            prevPowerLineStatus = currPowerLineStatus;
        }
        public static int ShowSelectionInputDialog(Form parent, string title, string[] items)
        {
            sDialog      = new SelectionInputDialog();
            sDialog.Text = title;
            sDialog.cbAction.Items.AddRange(items);
            sDialog.cbAction.Items.RemoveAt(0);
            sDialog.cbAction.SelectedIndex = 0;

            if (sDialog.ShowDialog(parent) == DialogResult.OK)
            {
                //add one to the result since the first item in the item was removed
                return(sDialog.cbAction.SelectedIndex + 1);
            }
            return(-1); //nothing was selected
        }