Exemplo n.º 1
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");
        }
Exemplo n.º 2
0
        protected void CreatePostButton_Click(object sender, EventArgs e)
        {
            {
                SQLDatabase.DatabaseTable posts_table = new SQLDatabase.DatabaseTable("Posts"); // Need to load the table we're going to insert into.

                SQLDatabase.DatabaseRow new_row = posts_table.NewRow();                         // Create a new based on the format of the rows in this table.

                string new_id       = posts_table.GetNextID().ToString();                       // Use this to create a new ID number for this module. This new ID follows on from the last row's ID number.
                string creatorname  = "1";
                int    creatorid    = int.Parse(creatorname);
                string boardnum     = "1";
                int    boardid      = int.Parse(boardnum);
                string creationdate = "";
                string creationtime = "";

                new_row["ID"]          = new_id;                            // Add some data to the row (using the columns names in the table).
                new_row["Text"]        = CreatePostTextBox.Text.ToString(); // post contents.
                new_row["CreatorID"]   = creatorid.ToString();
                new_row["BoardID"]     = boardid.ToString();
                new_row["DateCreated"] = creationdate;
                new_row["TimeCreated"] = creationtime;

                posts_table.Insert(new_row);                           // Execute the insert - add this new row into the database.
            }
        }
Exemplo n.º 3
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
        }
Exemplo n.º 4
0
        protected void CreatePostButton_Click(object sender, EventArgs e)
        {
            {
                SQLDatabase.DatabaseTable posts_table = new SQLDatabase.DatabaseTable("Posts");                                                                     // Need to load the table we're going to insert into.

                SQLDatabase.DatabaseRow new_row = posts_table.NewRow();                                                                                             // Create a new based on the format of the rows in this table.

                string new_id = posts_table.GetNextID().ToString();                                                                                                 // Use this to create a new ID number for this module. This new ID follows on from the last row's ID number.
                SQLDatabase.DatabaseTable loggedintable = new SQLDatabase.DatabaseTable("Users", "SELECT Username from Users WHERE ID = " + Session["LoggedinID"]); // get username from userdb using sessionid

                //get username from loggedintable where userid == LoggedinID
                string creatorname = loggedintable.GetRow(0)["Username"];
                string str         = "";
                if (Session["LoggedinID"] != null)
                {
                    str = Session["LoggedinID"].ToString();
                }
                int    creatorid    = Convert.ToInt32(str);
                string boardnum     = Session["Boards"].ToString();
                int    boardid      = int.Parse(boardnum);
                string creationdate = DateTime.Today.ToString("ddd dd MMM yyyy");
                string creationtime = DateTime.Now.ToString("HH:mm");

                new_row["ID"]          = new_id;                            // Add some data to the row (using the columns names in the table).
                new_row["Text"]        = CreatePostTextBox.Text.ToString(); // post contents.
                new_row["CreatorID"]   = creatorid.ToString();
                new_row["BoardID"]     = boardid.ToString();
                new_row["DateCreated"] = creationdate;
                new_row["TimeCreated"] = creationtime;

                posts_table.Insert(new_row);                           // Execute the insert - add this new row into the database.
            }
        }
Exemplo n.º 5
0
        protected void CreateBoardButton_Click(object sender, EventArgs e)
        {
            SQLDatabase.DatabaseTable boards_table = new SQLDatabase.DatabaseTable("Boards"); // Need to load the table we're going to insert into.

            SQLDatabase.DatabaseRow new_row = boards_table.NewRow();                          // Create a new based on the format of the rows in this table.

            string new_id      = boards_table.GetNextID().ToString();                         // Use this to create a new ID number for this module. This new ID follows on from the last row's ID number.
            string creatorname = "1";
            int    creatorid   = int.Parse(creatorname);

            new_row["ID"]        = new_id;                             // Add some data to the row (using the columns names in the table).
            new_row["Name"]      = CreateBoardTextbox.Text.ToString(); // topic name.
            new_row["CreatorID"] = creatorid.ToString();

            boards_table.Insert(new_row);                           // Execute the insert - add this new row into the database.
        }
Exemplo n.º 6
0
        protected void DataList3_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "View")    // ViewButton clicked - but which one?
            {
                // Find the index of the button - which indicates which row...

                int index = int.Parse((string)e.CommandArgument);                               // The 'Command Argument' is a string, so turn it into an integer...

                SQLDatabase.DatabaseTable users_table = new SQLDatabase.DatabaseTable("Users"); // Need to load the table again, to extract the row in which the button was clicked.

                SQLDatabase.DatabaseRow row = users_table.GetRow(index);                        // Get the row from the table.

                Session["ID"] = row;                                                            // Store this on the Session, so we can access this module in the other page.

                Response.Redirect("#");                                                         // Now to go the other page to view the module information...
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            SQLDatabase.DatabaseTable user_table = new SQLDatabase.DatabaseTable("Users");
            // Need to load the table we're going to insert into.

            SQLDatabase.DatabaseRow new_row = user_table.NewRow();
            // Create new row based on the format of the rows in this table.

            string new_id = user_table.GetNextID().ToString();

            // Use this to create a new ID number for this user. This new ID follows on from the last row's ID number.

            new_row["ID"] = new_id;
            // Add some data to the row (using the columns names in the table).
            new_row["Name"]     = TextBox3.Text.ToString();
            new_row["Username"] = TextBox1.Text.ToString();
            new_row["Password"] = TextBox2.Text.ToString();

            user_table.Insert(new_row);
            Label1.Text = "You have registered as: " + TextBox1.Text.ToString() + " password: "******", " + TextBox3.Text.ToString() + ".";
            // Execute the insert - add this new row into the database.
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            SQLDatabase.DatabaseTable users_table = new SQLDatabase.DatabaseTable("Users");
            string UserText = UsernameTextbox.Text;
            string PassText = PasswordTextbox.Text;

            //initialise some empty strings
            string userIdHolder   = "";
            string UserNameHolder = "";
            string PasswordHolder = "";
            string UserTypeHolder = "";


            //iterate through the users database rows to find the user

            for (int i = 0; i < users_table.RowCount; i++)
            {
                userIdHolder   = users_table.GetRow(i)["ID"];
                UserNameHolder = users_table.GetRow(i)["Username"];
                PasswordHolder = users_table.GetRow(i)["Password"];
                UserTypeHolder = users_table.GetRow(i)["UserType"];

                if (UserNameHolder == UserText)
                //if usernames match
                {
                    if (PasswordHolder == PassText)
                    //if passwords also match
                    {  //Log them in
                       //store info in session variable to be accessed later
                        Session["LoggedinID"] = userIdHolder;
                        //Can call it later with
                        //string abc = Session["LoggedinID"].ToString();

                        //update last loggin in date

                        Session["LastLoginDay"]  = DateTime.Today.ToString("ddd dd MMM yyyy");
                        Session["LastLoginTime"] = DateTime.Now.ToString("HH:mm");
                        //ErrorLabel.Text = "Logging in as " + Session["LoggedinID"].ToString() + "...";

                        //update the database with the logging in date and logging in time


                        for (int n = 0; n < users_table.RowCount; ++n)
                        {
                            SQLDatabase.DatabaseRow row = users_table.GetRow(n); //get current ID.
                            if (userIdHolder == users_table.GetRow(n)["ID"])     //if userID is the same as it's in the row
                            {
                                row["LastLoginDate"] = Session["LastLoginDay"].ToString();
                                row["LastLoginTime"] = Session["LastLoginTime"].ToString();
                                users_table.Update(row);
                            }
                        }

                        //go to boards page
                        Response.Redirect("~/board.aspx");
                    }
                    else
                    {
                        ErrorLabel.Text = "wrong password";
                    }
                }
                else
                {
                    ErrorLabel.Text = "No user by that name!";
                }
            }
        }
Exemplo n.º 10
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");
        }