Esempio n. 1
0
        /// <summary>
        /// Validate LDAP user & give access to appplication.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string strErrMsg = "";
                if (ValidateUserInputs(out strErrMsg))
                {
                    //bool blStatus = ChemistryOperations.MoleculeComparisonTest("", "");

                    //Get User Details
                    DataTable dtUserDetails = UserMasterDAL.GetUserDetailsByUserNameAndRoleId(txtUserName.Text.Trim(), Convert.ToInt32(cmbRole.SelectedValue), cmbModule.Text);
                    if (dtUserDetails != null && dtUserDetails.Rows.Count > 0)
                    {
                        char isLDAPUser = Convert.ToChar(dtUserDetails.Rows[0]["IS_LDAP_USER"]);
                        if (isLDAPUser == 'N')
                        {
                            DataTable dtUserCredentilas = UserMasterDAL.GetUserCredentialsByUserNameAndPassword(txtUserName.Text.Trim(), txtPassword.Text.Trim());
                            if (dtUserCredentilas != null && dtUserCredentilas.Rows.Count > 0)
                            {
                                //Filling Data into Global variables.
                                GlobalVariables.UserName       = txtUserName.Text.Trim();
                                GlobalVariables.RoleName       = cmbRole.Text;
                                GlobalVariables.Module         = cmbModule.Text;
                                GlobalVariables.RoleId         = Convert.ToInt32(cmbRole.SelectedValue);
                                GlobalVariables.UserID         = Convert.ToInt32(dtUserDetails.Rows[0]["USER_ID"].ToString());
                                GlobalVariables.UR_ID          = Convert.ToInt32(dtUserDetails.Rows[0]["UR_ID"].ToString());
                                GlobalVariables.IsLoginSuccess = true;

                                DialogResult = DialogResult.OK;
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Invalid User Name / Password", GlobalVariables.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            // LDAP user exists or not
                            if (ValidateUserAgainstLDAP())
                            {
                                //Filling Data into Global variables.
                                GlobalVariables.UserName       = txtUserName.Text.Trim();
                                GlobalVariables.RoleName       = cmbRole.Text;
                                GlobalVariables.Module         = cmbModule.Text;
                                GlobalVariables.RoleId         = Convert.ToInt32(cmbRole.SelectedValue);
                                GlobalVariables.UserID         = Convert.ToInt32(dtUserDetails.Rows[0]["USER_ID"].ToString());
                                GlobalVariables.UR_ID          = Convert.ToInt32(dtUserDetails.Rows[0]["UR_ID"].ToString());
                                GlobalVariables.IsLoginSuccess = true;

                                DialogResult = DialogResult.OK;
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Invalid User Name / Password", GlobalVariables.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }//End LDAP.
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid User Name / Password / Role", GlobalVariables.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show(strErrMsg, GlobalVariables.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                ErrorHandling.WriteErrorLog(ex.ToString());
            }
        }