protected void btnServiceToggle_Click(object sender, EventArgs e)
        {
            try
            {
                BusinessServices.AppConfig ac = new BusinessServices.AppConfig();
                BusinessServices.Email     em = new BusinessServices.Email();

                DataTable dt = ac.getMailServices();

                String[] strArr;

                ServiceController scQueueMail    = null;
                ServiceController scQueueReports = null;
                ServiceController scSendMail     = null;


                foreach (DataRow dr in dt.Rows)
                {
                    strArr = dr.ItemArray[1].ToString().Split(';');

                    if (dr.ItemArray[0].Equals("MailService_QueueMail"))
                    {
                        scQueueMail = new ServiceController(strArr[1], strArr[0]);
                    }
                    else if (dr.ItemArray[0].Equals("MailService_QueueReports"))
                    {
                        scQueueReports = new ServiceController(strArr[1], strArr[0]);
                    }
                    else if (dr.ItemArray[0].Equals("MailService_SendMail"))
                    {
                        scSendMail = new ServiceController(strArr[1], strArr[0]);
                    }
                }

                //String username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;// used for debugging

                // if its stopped then start it
                if (scSendMail.Status == ServiceControllerStatus.Stopped)
                {
                    em.purgeAutoEmails();

                    // set the send mail flag to allow emails to be sent
                    ac.Update("SEND_AUTO_EMAILS", "YES");

                    scSendMail.Start();
                    scSendMail.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 10));
                    scSendMail.Refresh();
                }
                // if its started then stop it
                else if (scSendMail.Status == ServiceControllerStatus.Running)
                {
                    em.purgeAutoEmails();

                    // set the send mail flag to stop emails from being sent
                    ac.Update("SEND_AUTO_EMAILS", "NO");

                    // restart report queuing
                    restartService(scQueueReports);

                    scSendMail.Stop();
                    scSendMail.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 10));
                    scSendMail.Refresh();

                    // restart mail queuing service
                    restartService(scQueueMail);
                }

                //username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                setButtonLabel();
            }
            catch (Exception ex)
            {
                ErrorHandler.ErrorLog el = new ErrorHandler.ErrorLog(ex, ErrorLevel.High, "Service Control", "Panic button pressed", ex.Message);
            }
        }