Exemple #1
0
        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {
                UserName = txtUserName.Text.ToLower().Trim();
                Password = txtPassword.Text.Trim();
                if (UserName.Contains("@iau.edu.sa") || UserName.Contains("@uod.edu.sa") || !UserName.Contains('@'))
                {
                    #region Active Directory Login
                    if (IsUserExist())
                    {
                        string FullName = string.Empty, Email = string.Empty, Phone = string.Empty, Mobile = string.Empty, NationalID = string.Empty;
                        nsWebServices.GetUser[] oArray;
                        oArray = GetUserDetails();
                        if (oArray != null)
                        {
                            if (oArray[0].ID != null && oArray[0].ID != string.Empty)
                            {
                                #region Person details from webservice
                                NationalID = oArray[0].ID;
                                if (oArray[0].FullName != null)
                                {
                                    FullName = oArray[0].FullName;
                                }
                                if (oArray[0].Email != null)
                                {
                                    Email = oArray[0].Email;
                                }
                                if (oArray[0].Phone != null)
                                {
                                    Phone = oArray[0].Phone;
                                }
                                if (oArray[0].Mobile != null)
                                {
                                    Mobile = oArray[0].Mobile;
                                }
                                #endregion
                                DataSet dSet = new DataSet();
                                dSet = AdoUDIRS.AddUpdateUserDetailsByNationalID(NationalID, FullName, Email, Phone, Mobile);
                                if (dSet != null)
                                {
                                    if (dSet.Tables[0] != null)
                                    {
                                        if (dSet.Tables[0].Rows.Count > 0)
                                        {
                                            SetPersonDetails(dSet.Tables[0]);
                                        }
                                        else
                                        {
                                            Label lbl = (Label)Page.Master.FindControl("lblMessage");
                                            Message.Success("PersonRoles does not exist/Database error", lbl);//Person does not exist/Database error
                                        }
                                        #region Set PersonRoleDetails Entity
                                        if (dSet.Tables[1] != null)
                                        {
                                            if (dSet.Tables[1].Rows.Count > 0)
                                            {
                                                SetPersonRoleDetails(dSet.Tables[1]);
                                                Response.Redirect("~/Web/Home.aspx", true);
                                            }
                                        }
                                        else
                                        {
                                            Label lbl = (Label)Page.Master.FindControl("lblMessage");
                                            Message.Failure("PersonRoles does not exist/Database error", lbl); ///// Pass label saleem//PersonRoles does not exist/Database error
                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        Label lbl = (Label)Page.Master.FindControl("lblMessage");
                                        Message.Failure("PersonRoles does not exist/Database error", lbl);//Person does not exist/Database error
                                    }
                                }
                                else
                                {
                                    Label lbl = (Label)Page.Master.FindControl("lblMessage");
                                    Message.Failure("PersonRoles does not exist/Database error", lbl);//Person does not exist/Database error
                                }
                            }
                            else
                            {
                                Label lbl = (Label)Page.Master.FindControl("lblMessage");
                                Message.Failure("Your NationalID not found, Please contact [email protected] or 31111.", lbl);//Message: Your NationalID not found, Please contact [email protected] or 31111.
                            }
                        }
                        else
                        {
                            Label lbl = (Label)Page.Master.FindControl("lblMessage");
                            Message.Failure("Server not responding, Please try after some time.", lbl);//Message: Server not responding, Please try after some time.
                        }
                    }
                    else
                    {
                        Label lbl = (Label)Page.Master.FindControl("lblMessage");
                        Message.Failure("Incorrect login credentials", lbl);//Message: incorrect login credentials
                    }
                    #endregion
                }
                else
                {
                    #region Other Login
                    DataSet dSet = new DataSet();
                    dSet = AdoUDIRS.CheckAndGetDataForOthersLogin(UserName);
                    if (dSet != null)
                    {
                        if (dSet.Tables[0] != null)
                        {
                            if (dSet.Tables[0].Rows.Count > 0)
                            {
                                SetPersonDetails(dSet.Tables[0]);
                            }
                            else
                            {
                                return;
                                //Person does not exist/Database error
                            }
                            #region Set PersonRoleDetails Entity
                            if (dSet.Tables[1] != null)
                            {
                                if (dSet.Tables[1].Rows.Count > 0)
                                {
                                    SetPersonRoleDetails(dSet.Tables[1]);
                                    Response.Redirect("~/Web/Home.aspx", true);
                                }
                            }
                            else
                            {
                                Label lbl = (Label)Page.Master.FindControl("lblMessage");
                                Message.Success("PersonRoles does not exist/Database error", lbl);//PersonRoles does not exist/Database error
                            }
                            #endregion
                        }
                        else
                        {
                            Label lbl = (Label)Page.Master.FindControl("lblMessage");
                            Message.Success("Incorrect Username/Password", lbl);//Incorrect Username/Password
                        }
                    }
                    else
                    {
                        Label lbl = (Label)Page.Master.FindControl("lblMessage");
                        Message.Success("Incorrect Username/Password", lbl);//Incorrect Username/Password
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
            }
        }