Ejemplo n.º 1
0
        protected void btnCreatePost_Click(object sender, EventArgs e)
        {
            string   text = txtPost.Text;
            DateTime dt   = DateTime.Now;     //gets current Date and Time from the system

            if (txtPost.Text == String.Empty) //validation to make sure the textbox has been filled in
            {
                lblCreatePostMessage.Text    = "You have not completed one or more required fields";
                lblCreatePostMessage.Visible = true;
                return;
            }

            SQLDatabase.DatabaseTable tPosts = new SQLDatabase.DatabaseTable("Posts");

            SQLDatabase.DatabaseRow row = tPosts.NewRow();

            row.Add("ID", tPosts.GetNextID().ToString());       // adding all the information neccessary to create a post in the db
            row.Add("Text", text);
            row.Add("CreatorID", Session["UserID"].ToString()); //need to make it so it displays the user ID.
            row.Add("CreatorName", Session["Name"].ToString());
            row.Add("BoardID", Session["BoardID"].ToString());  //need to make it so it displays the user ID.
            row.Add("BoardName", Session["BoardName"].ToString());
            row.Add("DateCreated", dt.ToString("dddd, dd MMMM yyyy"));
            row.Add("TimeCreated", dt.ToString("h: mm tt"));

            tPosts.Insert(row);

            Response.Redirect("Boards.aspx"); // takes you back to the boards page after you have created the post
        }
Ejemplo n.º 2
0
        protected void btnCreateBoard_Click(object sender, EventArgs e)
        {
            string   subject = txtSubject.Text;
            DateTime dt      = DateTime.Now; //gets current Date and Time from the system

            //Session["BoardName"] = subject; //stores the boardname in a session for later use


            if (txtSubject.Text == String.Empty) // validation for empty textboxes
            {
                lblCreateBoardMessage.Text    = "You have not completed one or more required fields";
                lblCreateBoardMessage.Visible = true;
                return;
            }

            SQLDatabase.DatabaseTable tBoards = new SQLDatabase.DatabaseTable("Boards");

            SQLDatabase.DatabaseRow row = tBoards.NewRow();

            row.Add("ID", tBoards.GetNextID().ToString());      // adds all the info needed to create a new board in the db
            row.Add("Name", subject);
            row.Add("CreatorID", Session["UserID"].ToString()); //need to make it so it displays the user ID.
            row.Add("CreatorName", Session["Name"].ToString());
            row.Add("DateCreated", dt.ToString("dddd, dd MMMM yyyy"));
            row.Add("TimeCreated", dt.ToString("h: mm tt"));

            tBoards.Insert(row);

            Response.Redirect("Boards.aspx");
        }
Ejemplo n.º 3
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string   email    = txtEmail.Text;
            string   password = txtPassword.Text;
            DateTime dt       = DateTime.Now; //gets current Date and Time from the system

            SQLDatabase.DatabaseTable usernames = new SQLDatabase.DatabaseTable("Users", "SELECT * FROM Users");

            for (int i = 0; i < usernames.RowCount; i++) //loops through the users table to validate if the username and password are linked to a user in the db
            {
                SQLDatabase.DatabaseRow row = usernames.GetRow(i);
                if (row["Username"] == email && row["Password"] == password)
                {
                    Session["TempLastLoginDate"] = row["LastLoginDate"];    //stores the last login date/time before they log in and it is updated.
                    Session["TempLastLoginTime"] = row["LastLoginTime"];    //this is to show them their last login date/time after they login


                    row.Add("LastLoginDate", dt.ToString("dddd, dd MMMM yyyy")); //updates their last login date/time to the current date/time
                    row.Add("LastLoginTime", dt.ToString("h: mm tt"));
                    usernames.Update(row);



                    Session["UserID"]        = row["ID"]; //stores all their info in sessions for easy access later.
                    Session["Name"]          = row["Name"];
                    Session["Username"]      = row["Username"];
                    Session["UserType"]      = row["UserType"];
                    Session["LastLoginDate"] = row["LastLoginDate"];
                    Session["LastLoginTime"] = row["LastLoginTime"];

                    Response.Redirect("Boards.aspx");
                }
            }

            lblLogMessage.Text    = "Username or Password not valid";
            lblLogMessage.Visible = true;
        }
Ejemplo n.º 4
0
        protected void btnRegister_Click1(object sender, EventArgs e)
        {
            string id;
            string email       = txtEmail.Text;
            string password    = txtPassword.Text;
            string displayName = txtDisplayName.Text;
            string userType    = "User";
            bool   emailFound  = false;
            bool   nameFound   = false;


            if (txtDisplayName.Text == String.Empty || txtEmail.Text == String.Empty || txtPassword.Text == String.Empty) //validation for empty textboxes
            {
                lblRegMessage.Text    = "You have not completed one or more required fields";
                lblRegMessage.Visible = true;
                return;
            }

            SQLDatabase.DatabaseTable tUsers = new SQLDatabase.DatabaseTable("Users");

            SQLDatabase.DatabaseRow row = tUsers.NewRow();

            row.Add("ID", tUsers.GetNextID().ToString()); // adds all required details to create a user
            row.Add("Name", displayName);
            row.Add("Username", email);
            row.Add("Password", password);
            row.Add("UserType", userType);

            SQLDatabase.DatabaseTable usernames = new SQLDatabase.DatabaseTable("Users", "SELECT * FROM Users");

            for (int i = 0; i < usernames.RowCount; i++) //loops through the user table to check if the inputted email is already taken by another user
            {
                if (usernames.GetRow(i)["Username"] == email)
                {
                    emailFound = true;
                    break;
                }
            }

            for (int n = 0; n < usernames.RowCount; n++) //loops through the user table to check if the inputted email is already taken by another user
            {
                if (usernames.GetRow(n)["Name"] == displayName)
                {
                    nameFound = true;
                    break;
                }
            }

            if (!emailFound && !nameFound) // if neither are duplicates then add the user
            {
                tUsers.Insert(row);
            }
            else
            {
                if (emailFound && !nameFound) //if email is taken but display name not, tell the user
                {
                    lblRegMessage.Text = "That Email Address is already taken, please enter a different one.";
                }
                if (nameFound && !emailFound) //if display name is taken but email not, tell the user
                {
                    lblRegMessage.Text = "That Display Name is already taken, please enter a different one.";
                }
                if (nameFound && emailFound) //if display name  and email are taken, tell the user
                {
                    lblRegMessage.Text = "That Display Name and Email Address is already taken, please enter a different one.";
                }

                lblRegMessage.Visible = true;
                return;
            }

            SQLDatabase.User u = tUsers.GetUser(0); // stores the users into a class incase they are needed in the future

            id          = u.ID;
            displayName = u.displayName;
            email       = u.email;
            password    = u.password;
            u.userType  = userType;

            Response.Redirect("Default.aspx");
        }