Beispiel #1
0
        protected void Login_Click(object sender, EventArgs e)
        {
            try
            {
                DatabaseDAO userObj = new DatabaseDAO();
                UserAddInfo user    = new UserAddInfo();


                // Get user Roles, Name and Email to store in session of MasterPage and
                user = userObj.GetData(User_Login.Value);
                string role = user.Role;

                string Name  = user.Name;
                string Email = user.Email;
                if (role != null || Name != null || Email != null)
                {
                    // If User information correct, let user login
                    if (role.Length > 1)
                    {
                        //Store role in session
                        Session.Add("role", role);
                        Session.Add("name", Name);
                        Session.Add("email", Email);

                        // After user successfully login
                        // Rirect to index2.aspx
                        Session["check"] = "";
                        Response.Redirect("User_Management.aspx");
                    }
                    else
                    {
                        // If User Information Wrong, display error message
                        Login_Alert.Attributes.CssStyle.Add("display", "block");
                    }
                }
                else
                {
                    // If system error, display error message through alert box
                    ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('There seems to be a problem with the system! Contact the local Administrator');", true);
                }
            }
            catch (Exception ex)
            {
                //Catch all errors and write to ErrorLog.txt
                ErrorLog.WriteErrorLog(ex.ToString());
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string UserID = (string)(Session["UserID"]);
                if (UserID == null)
                {
                    //If session "UserID" is equals null, means edit button event was triggered from User_Management.aspx table

                    title.InnerText = "User Management > Create User";
                    UserRegisterHeader.InnerText  = "Create Account Details";
                    User_Input_Name.Value         = "";
                    User_Input_Email.Value        = "";
                    Select_Permission_Level.Value = "";
                    User_Input_Username.Value     = "";
                }
                else
                {
                    DatabaseDAO dao  = new DatabaseDAO();
                    UserAddInfo user = new UserAddInfo();

                    //Get User data from GetData Method in DatabaseDAO
                    user = dao.GetData(UserID);
                    if (user.Name != null)
                    {
                        //If retrieved data "user.Name" is not equals null, means edit button event was triggered from User_Management.aspx table
                        //Change alert message text to updated


                        //Change title of page to Edit User
                        title.InnerText = "User Management > Edit User";
                        UserRegisterHeader.InnerText = "Update Account Details";

                        //Sets the textbox values to the values retrieved from GetData Method in DatabaseDAO
                        User_Input_Username.Value     = UserID;
                        User_Input_Email.Value        = user.Email;
                        Select_Permission_Level.Value = user.Role;
                        User_Input_Name.Value         = user.Name;
                    }
                    else
                    {
                        //If error, display failure message
                        ScriptManager.RegisterStartupScript(Page, GetType(), "AlertFailureDisplay", "displayFailure();", true);
                    }
                }
            }
        }