Пример #1
0
 public void validateConnection()
 {
     try
     {
         // Access the name property. This will throw an exception is connection is not valid
         string localName = this.Name;
     }
     catch (Exception ex)
     {
         if (ex.Message.Contains("(401)"))
         {
             // this is an acess denied!
             LogonForm logonForm = new LogonForm();
             logonForm.ShowDialog();
         }
     }
 }
Пример #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            LoadConfig();

            // Instantiate logon form
            LogonForm logonForm = new LogonForm();

            this.WindowState = FormWindowState.Minimized;
            #if DEBUG
            isLoggedIn = true;
            #else
            isLoggedIn = false;
            #endif


            // Logon routine
            while (isLoggedIn == false)
            {
                // If the form was disposed (due to mistakes in code)
                // the app will be killed in last instance
                if (logonForm.IsDisposed)
                {
                    break;
                }
                switch (logonForm.ShowDialog())
                {
                // This is not supposed to happen and will kill the app
                case DialogResult.Cancel:
                    isLoggedIn = false;
                    Application.Exit();
                    return;

                // This is not supposed to happen and will kill the app
                case DialogResult.None:
                    isLoggedIn = false;
                    Application.Exit();
                    return;

                // The Dialog Result returns DialogResult.OK
                // if the authentification succeeded.
                case DialogResult.OK:
                    isLoggedIn = true;
                    // gather all the data to provide them to other forms
                    _accountName = logonForm.AccountName;
                    _displayName = logonForm.DisplayName;
                    _domain      = logonForm.Domain;
                    break;

                // This is not supposed to happen and will kill the app
                default:
                    NotifyUserLog(LogMessage.UserLogonError);
                    isLoggedIn = false;
                    return;
                }
            }
            // Kill the app in last instance, if an error occured and the while block was exited
            if (isLoggedIn == false)
            {
                Application.Exit();
            }

            // Reset the form to apply the culture
            this.Controls.Clear();
            InitializeComponent();

            // Display the Main Form in full size
            this.WindowState   = FormWindowState.Maximized;
            this.ShowInTaskbar = true;

            PopulateList();
        }