Example #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cbUserId.Text))
            {
                MessageBox.Show("Please select a User id", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (string.IsNullOrEmpty(txtPassword.Text))
            {
                MessageBox.Show("Please key in Password", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            bool isConnected = ConnectionService.CheckForInternetConnection();
            DeviceRegistrationProcessingForm lapf = new DeviceRegistrationProcessingForm(_mp);

            lapf.ShowDialog();

            if (isConnected)
            {
                bool result = _mp.AuthSvc.Authenticate(cbUserId.Text, txtPassword.Text);
                if (!result)
                {
                    MessageBox.Show("Login failed. Please try again.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                var user = _systemUserSvc.GetByUserId(cbUserId.Text);
                if (user == null)
                {
                    MessageBox.Show("Login failed. Please try again.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                _mp.UserProfile = user.ProfileInfo;
            }
            else
            {
                if (MessageBox.Show("There is no connection with the server.\nClick Yes to continue with Offline verification.", "No Connection", MessageBoxButtons.YesNoCancel) != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }

                MyKadVerifcationForm f = new MyKadVerifcationForm();
                f.ShowDialog();
                if (f.ProfileInfo == null)
                {
                    MessageBox.Show("Verification Failed");
                    return;
                }
                if (!f.ProfileInfo.IsVerified)
                {
                    MessageBox.Show("Verification Failed");
                    return;
                }
                _mp.UserProfile = f.ProfileInfo;
            }

            _mp.ShowForm(FormType.MainForm);
            this.Hide();
        }