protected void logoutButton_Click(object sender, EventArgs e)
 {
     Session["ID"]        = null;        // end session
     Session["firstName"] = null;        // delete stored info
     Response.Redirect("../index.aspx"); // redirect to homepage
     dbm.closeConnection();              // close connection to db
 }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                result.Visible = false;
            }
            DBMaster      dbm    = new DBMaster();
            SqlDataReader reader = dbm.getReader("SELECT [name],[email] FROM [dbo].[DWUser]");

            if (!IsPostBack)
            {
            }

            string temp = "";


            while (reader.Read())
            {
                temp += reader["name"].ToString();
                temp += "<br/>";
                temp += reader["email"].ToString();
                temp += "<br/>";
            }

            dbm.closeConnection();
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Vars
            string id = Session["userID"].ToString(),
                   firstName, lastName, user, pw, addr, e_mail, phonenum;
            // Reader
            SqlDataReader reader = dbm.getReader("SELECT * FROM [dbo].[person] where id=" + id);

            reader.Read();

            // save info from db into vars
            firstName = reader["firstName"].ToString();
            lastName  = reader["lastName"].ToString();
            user      = reader["userName"].ToString();
            pw        = reader["password"].ToString();
            addr      = reader["address"].ToString();
            e_mail    = reader["email"].ToString();
            phonenum  = reader["phone"].ToString();

            // close connection
            dbm.closeConnection();

            // display info
            first.Text         = firstName;
            last.Text          = lastName;
            username.Text      = user;
            password.Text      = pw;
            address.Text       = addr;
            email_address.Text = e_mail;
            phone_number.Text  = phonenum;
        }
示例#4
0
        protected void submitButton_Click(object sender, EventArgs e)
        {
            // get DBM object
            DBMaster dbm = new DBMaster();

            // get vars from input
            string productName        = newProductNameInput.Text,
                   productDescription = newProductDescriptionInput.Text,
                   productPrice       = newProductPriceInput.Text,
                   productQuantity    = newProductQuantityInput.Text,

            // generate query
                   query = "INSERT INTO [dbo].[products] ([productName],[description],[price],[currentAmount]) VALUES (\'" + productName + "\',\'" + productDescription + "\',\'" + productPrice + "\',\'" + productQuantity + "\')";

            // execute the query
            dbm.executeQuery(query);

            // close connection
            dbm.closeConnection();

            // clear text fields
            newProductNameInput.Text        = "";
            newProductDescriptionInput.Text = "";
            newProductPriceInput.Text       = "";
            newProductQuantityInput.Text    = "";
        }
示例#5
0
        } // end method Page_Load(object sender, EventArgs e)

        protected void logoutButton_Click(object sender, EventArgs e)
        {
            Session["ID"]        = null;
            Session["firstName"] = null;
            Response.Redirect("../index.aspx");
            dbm.closeConnection();
        }
示例#6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Vars
            string query     = "INSERT INTO [dbo].[person] ( [firstName],[lastName],[userName],[password],[address],[email],[phone] ) VALUES ( '" + Request.Form["fname"] + "', '" + Request.Form["lname"] + "', '" + Request.Form["user"] + "', '" + Request.Form["pw"] + "', '" + Request.Form["addr"] + "', '" + Request.Form["email"] + "', '" + Request.Form["phone"] + "' ) SELECT SCOPE_IDENTITY();",
                   firstName = "<b>First Name: </b>" + Request.Form["fname"],
                   lastName  = "<b>Last Name: </b>" + Request.Form["lname"],
                   user      = "******" + Request.Form["user"],
                   pw        = "<b>Password: </b>" + Request.Form["pw"],
                   addr      = "<b>Address: </b>" + Request.Form["addr"],
                   e_mail    = "<b>Email: </b>" + Request.Form["email"],
                   phonenum  = "<b>Phone Number: </b>" + Request.Form["phone"],
                   id        = "";
            // Reader
            SqlDataReader reader = dbm.getReader(query);

            // get input
            first.Text         = firstName;
            last.Text          = lastName;
            username.Text      = user;
            password.Text      = pw;
            address.Text       = addr;
            email_address.Text = e_mail;
            phone_number.Text  = phonenum;

            // read and save id
            reader.Read();
            id = reader[0].ToString();

            // close connection
            dbm.closeConnection();

            // save the id to session
            Session["userID"] = id;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Vars
                string id = Session["userID"].ToString(),
                       firstName,
                       lastName,
                       user,
                       pw,
                       addr,
                       e_mail,
                       phonenum;
                // Reader
                SqlDataReader reader = dbm.getReader("SELECT * FROM [dbo].[person] where id=" + id);

                reader.Read();

                // get vars from DB
                firstName = reader["firstName"].ToString();
                lastName  = reader["lastName"].ToString();
                user      = reader["userName"].ToString();
                pw        = reader["password"].ToString();
                addr      = reader["address"].ToString();
                e_mail    = reader["email"].ToString();
                phonenum  = reader["phone"].ToString();

                // close connection
                dbm.closeConnection();

                // display the info taken from db
                fname.Text  = firstName;
                lname.Text  = lastName;
                usernm.Text = user;
                passw.Text  = pw;
                addrs.Text  = addr;
                email.Text  = e_mail;
                phone.Text  = phonenum;
            }
        }
        protected void loginButton_Click(object sender, EventArgs e)
        {
            // get reader from DBMaster
            SqlDataReader reader = dbm.getReader("SELECT [firstName], [ID] FROM [dbo].[person] WHERE userName = '******' AND password = '******'");

            // vars
            string fname = "",
                   id    = "";

            // login successfull
            if (reader.Read())
            {
                // get name and ID from DB
                Session["firstName"] = fname = reader["firstName"].ToString();
                Session["ID"]        = id = reader["ID"].ToString();

                // display welcome message
                Welcome_Message.Text = "Welcome " + fname;

                // hide loginbox and show logout button
                loginBox.Visible  = false;
                logoutBox.Visible = true;
            }

            // login failed
            else
            {
                usernameBox.Text     = "Login Failed.";
                Welcome_Message.Text = "";
                loginBox.Visible     = true;
                logoutBox.Visible    = false;
            }

            // close connection to db
            dbm.closeConnection();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // check if user logged in
            if (Session["ID"] == null)
            {
                Response.Redirect("../index.aspx");
            }

            // Vars
            string ID              = Session["ID"].ToString(),                               // user ID
                   PID             = Request.QueryString["id"],                              // product id passed from product page
                   query           = "select * from [dbo].[person] where id = '" + ID + "'", // query to get personal details of user
                   emailMsg        = "",                                                     // msg that will be emailed to customer
                   customerName    = "",                                                     // first name of customer
                   customerAddress = "",                                                     // customer's address
                   customerEmail   = "",                                                     // customer's email
                   productName     = "",                                                     // name of product with PID
                   productPrice    = "";                                                     // price of product with PID
            uint productAmount     = 0;                                                      // uint ensures positive values only

            // Establish DB connection
            dbm = new DBMaster();

            // Get reader for DB
            SqlDataReader reader = dbm.getReader(query);

            if (reader.Read()) // ensure that valid id was passed
            {
                customerAddress = reader["address"].ToString();
                customerName    = reader["firstName"].ToString();
                customerEmail   = reader["email"].ToString();
            }
            else // Session ID is incorrect, force user to log in again
            {
                Session["ID"] = null;
                Response.Redirect("../index.aspx");
            }

            // get new reader for person table
            reader.Close();

            query  = "select * from [dbo].[products] where pid = '" + PID + "'";
            reader = dbm.getReader(query);

            if (reader.Read())
            {
                productName  = reader["productName"].ToString();
                productPrice = reader["price"].ToString();
                string temp = reader["currentAmount"].ToString(); // temp storage

                try                                               // this will fail if currentAmount is not a positive integer
                {
                    if (!UInt32.TryParse(temp, out productAmount))
                    {
                        throw new FormatException("invalid database entry 'currentAmount'"); // the conversion did not succeed
                    } // end if (!UInt32.TryParse(temp, out productAmount))
                } // end try
                catch (FormatException error)
                {
                    reader.Close();                                                                                                 // close reader
                    query = "update [dbo].[products] set [currentAmount] = '0' where pid = '" + PID + "'";
                    dbm.executeQuery(query);                                                                                        // set currentAmount to 0 to correct this error
                    Msg.Text = "We are sorry, the item you attempted to purchase is out of stock. You will be redirected shortly."; // display error to user
                    Thread.Sleep(5000);                                                                                             // allow time for user to read error
                    dbm.closeConnection();                                                                                          // close connection to db
                    Response.Redirect("productPage.aspx?error=" + error.Message);                                                   // return user to product page
                } // end catch
            } // end if (reader.Read())
            else // the PID passed was invalid
            {
                Response.Redirect("productPage.aspx");
            }

            // update DB to account for the sale
            query = "update [dbo].[products] set [currentAmount] = '" + (productAmount - 1) + "' where pid = '" + PID + "'";
            dbm.executeQuery(query);

            // close connection
            dbm.closeConnection();

            // send email to customer
            emailMsg = "Hi " + customerName + " Thank you for your purchase of " + productName + ". <br /> Your credit card on file will be charged $" + productPrice + ", and the item will be shipped to your address at: <br /> " + customerAddress + " <br /> We hope to see you again soon!";
            sendEmail(customerEmail, emailMsg);

            // display message to user that sale was completed
            Msg.Text = "Thank you for your purchase, " + customerName + ". <br /> Your credit card on file will be charged $" + productPrice + " for your purchase of " + productName + ", and the item will be shipped to your address at: <br /> " + customerAddress + " <br /> We hope to see you again soon! <br /> <br /> <b>Note:</b> A copy of this invoice will also be sent to your email on file.";
        }
示例#10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // check if user logged in
            if (Session["ID"] == null)
            {
                Response.Redirect("../index.aspx");
            }

            // Connect to DB
            dbm = new DBMaster();

            // vars
            string query = "select * from [dbo].[products] where currentAmount > 0",
                   productName, productDescription, productPrice, productID;

            // get reader
            SqlDataReader reader = dbm.getReader(query);

            // read from DB
            while (reader.Read())
            {
                // read values from DB
                productName        = reader["productName"].ToString();
                productDescription = reader["description"].ToString();
                productPrice       = reader["price"].ToString();
                productID          = reader["pid"].ToString();

                // create new row
                TableRow row = new TableRow();

                // create the 4 cells
                TableCell nCell = new TableCell(); // name
                TableCell dCell = new TableCell(); // description
                TableCell pCell = new TableCell(); // price
                TableCell bCell = new TableCell(); // buy link

                nCell.Attributes.Add("class", "cells");
                dCell.Attributes.Add("class", "cells");
                pCell.Attributes.Add("class", "cells");
                bCell.Attributes.Add("class", "cells");

                // create buy link
                HtmlAnchor buyLink = new HtmlAnchor();
                buyLink.Attributes.Add("style", "color: #003B6F"); // change from default(silver) to blue
                buyLink.HRef      = "buyNow.aspx?id=" + productID;
                buyLink.InnerText = "Buy Now";

                // set cell text
                nCell.Text = productName;
                dCell.Text = productDescription;
                pCell.Text = "$" + productPrice;
                bCell.Controls.Add(buyLink);

                // add cells to row
                row.Cells.Add(nCell);
                row.Cells.Add(dCell);
                row.Cells.Add(pCell);
                row.Cells.Add(bCell);

                // add row to table
                productTable.Rows.Add(row);
            } // end while(reader.Read())

            // close connection to db
            dbm.closeConnection();
        } // end method Page_Load(object sender, EventArgs e)
示例#11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Establish connection to database, retrieve the latest entry, just for demonstratino purposes
            DBMaster      dbm      = new DBMaster();
            SqlDataReader reader   = dbm.getReader("SELECT TOP 1 * FROM [dbo].[tblFullname] ORDER BY ID DESC");
            string        userName = "";

            while (reader.Read())
            {
                userName += reader["Fullname"].ToString();
            }
            dbm.closeConnection();
            //user Greeting
            userGreeting.Text += userName;



            //This retrives the user's tags from the database
            //string[] userTagArr = new string[100];
            List <string> userTagList = new List <string>();
            //int n = 0;
            SqlDataReader reader1 = dbm.getReader("SELECT * FROM tblPersontags WHERE Fullname='" + userName + "'");

            while (reader1.Read())
            {
                //userTagArr[n] = reader1["tag"].ToString();
                //n++;
                userTagList.Add(reader1["tag"].ToString().TrimEnd());
            }
            dbm.closeConnection();

            //This populates the URL dictionary
            Dictionary <string, string> siteURL =
                new Dictionary <string, string>();
            SqlDataReader reader2 = dbm.getReader("SELECT * FROM [dbo].[tblSiteurl] ORDER BY ID DESC");

            while (reader2.Read())
            {
                string sitenametemp = reader2["Sitename"].ToString();
                string sitelinktemp = reader2["Siteurl"].ToString();
                siteURL.Add(sitenametemp, sitelinktemp);
            }
            dbm.closeConnection();



            //This populates the tag dictionary
            string temp2 = "";
            Dictionary <string, int> siteCompatibilityIndex =
                new Dictionary <string, int>();

            foreach (KeyValuePair <string, string> x in siteURL)
            {
                //string[] siteTagArr = new string[100];
                List <string> siteTagList = new List <string>();
                //int i = 0;
                SqlDataReader reader3 = dbm.getReader("SELECT * FROM tblSitetags WHERE Sitename='" + x.Key + "'");
                while (reader3.Read())
                {
                    siteTagList.Add(reader3["Sitetag"].ToString().TrimEnd());
                    //siteTagArr[i] = reader3["Sitetag"].ToString();
                    //i++;
                }
                dbm.closeConnection();
                TagHandler tagHandler = new TagHandler();

                int compatibilityIndex = userTagList.Intersect(siteTagList).Count();
                siteCompatibilityIndex.Add(x.Key.ToString(), compatibilityIndex);
                //temp2 += x.Key.ToString();
                //temp2 += compatibilityIndex;
                //temp2 += "</br>";
            }
            //lbl_test.Text = temp2;

            var top5 = siteCompatibilityIndex.OrderByDescending(pair => pair.Value).Take(5)
                       .ToDictionary(pair => pair.Key, pair => pair.Value);


            //Populate the links with the best-fit sites
            int recommendedSiteCount = 0;

            string[] recommendedSites = new string[5];
            foreach (KeyValuePair <string, int> x in top5)
            {
                recommendedSites[recommendedSiteCount] = x.Key;
                recommendedSiteCount++;
            }
            HyperLink0.Text        = recommendedSites[0];
            HyperLink0.NavigateUrl = siteURL[recommendedSites[0]];
            HyperLink1.Text        = recommendedSites[1];
            HyperLink1.NavigateUrl = siteURL[recommendedSites[1]];
            HyperLink2.Text        = recommendedSites[2];
            HyperLink2.NavigateUrl = siteURL[recommendedSites[2]];
            HyperLink3.Text        = recommendedSites[3];
            HyperLink3.NavigateUrl = siteURL[recommendedSites[3]];
            HyperLink4.Text        = recommendedSites[4];
            HyperLink4.NavigateUrl = siteURL[recommendedSites[4]];
        }