Exemplo n.º 1
0
        //public string apiKey = "AIzaSyAVbJ6aCml5pLODHHIPEexJAd8GJ9Ev6l4";

        protected void Page_Load(object sender, EventArgs e)
        {
            SQLFunctions conn = new SQLFunctions();

            //Check who is logged in
            string currentUser = HttpContext.Current.User.Identity.Name;
            int    userId      = conn.getUserID(currentUser);


            draw_table();
        }
Exemplo n.º 2
0
        public List <resultsTally> returnTiedTopBooks()
        {
            SQLFunctions conn = new SQLFunctions();

            List <resultsTally> lrt     = conn.getNumberOneBook();
            List <resultsTally> lrtally = new List <resultsTally>();


            int book1 = lrt[0].numberVotes;
            int book2 = lrt[1].numberVotes;

            lrtally.Add(lrt[0]);
            lrtally.Add(lrt[1]);
            return(lrtally);
        }
Exemplo n.º 3
0
        protected void draw_table(int userID)
        {
            SQLFunctions conn = new SQLFunctions();
            TableRow     row;
            TableCell    cell;
            int          x = 0;

            tableContent.Rows.Clear();

            row  = new TableRow();
            cell = new TableCell();

            cell.Text = "Ranking";
            row.Cells.Add(cell);

            cell      = new TableCell();
            cell.Text = "Author";
            row.Cells.Add(cell);

            cell      = new TableCell();
            cell.Text = "Title";
            row.Cells.Add(cell);

            tableContent.Rows.Add(row);

            List <resultsModel> results = conn.get2018PersonalizedRankings(userID);

            foreach (resultsModel rs in results)
            {
                x++;
                row  = new TableRow();
                cell = new TableCell();

                cell.Text = x.ToString();
                row.Cells.Add(cell);

                cell      = new TableCell();
                cell.Text = rs.bookAuthor;
                row.Cells.Add(cell);

                cell      = new TableCell();
                cell.Text = rs.bookTitle;
                row.Cells.Add(cell);

                tableContent.Rows.Add(row);
            }
        }
Exemplo n.º 4
0
        protected void ddlUsers_Populate()
        {
            SQLFunctions conn = new SQLFunctions();

            if (!IsPostBack)
            {
                ddlUsers.Items.Clear();
                ddlUsers.Items.Add("---Overall Ranking---");
                List <string> fullNames = conn.getAllUserFullNames();

                foreach (string s in fullNames)
                {
                    ddlUsers.Items.Add(s);
                }

                ddlUsers.Items.Add("---Other Statistics---");
            }
        }
Exemplo n.º 5
0
        protected void ddlUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
            SQLFunctions conn = new SQLFunctions();

            if (ddlUsers.SelectedItem.Text == "---Other Statistics---")
            {
                draw_custom_table();
            }
            else
            {
                int id = conn.getUserIDByFullName(ddlUsers.SelectedItem.Text);
                if (id == -1)
                {
                    draw_table();
                }
                else
                {
                    draw_table(id);
                }
            }
        }
Exemplo n.º 6
0
        //protected List<resultsTally> evaluateTopBookPlurality()
        //{
        //    SQLFunctions conn = new SQLFunctions();
        //    int X = -1;
        //    List<resultsTally> lrtresult = new List<resultsTally>();

        //    List<resultsTally> lrt = conn.getNumberOnePlurality();
        //    foreach (resultsTally rt in lrt)
        //    {
        //        // Check for a tie
        //        if (rt.numberVotes == 3)
        //        {

        //        }


        //        if (X > -1)
        //        {
        //            if (X == rt.numberVotes)
        //            {
        //                lrtresult.Add(rt);
        //            }
        //        } else
        //        {
        //            X = rt.numberVotes;
        //            lrtresult.Add(rt);
        //        }
        //    }

        //    return lrt;
        //}

        protected resultsTally evaluateBottomBooks()
        {
            SQLFunctions conn = new SQLFunctions();

            List <resultsTally> lrt = conn.getLastPlaceBook();
            resultsTally        rt;


            int book1 = lrt[0].numberVotes;
            int book2 = lrt[1].numberVotes;

            if (book1 > book2)
            {
                return(lrt[0]);
            }
            else
            {
                rt         = new resultsTally();
                rt.book_id = -1;
                return(rt);
            }
        }
Exemplo n.º 7
0
        public void LoginButton_Click(object sender, EventArgs e)
        {
            SQLFunctions conn = new SQLFunctions();

            if (conn.authenticateUser(txtUserName.Text, txtPassword.Text) == true)
            {
                //Response.Redirect("index.aspx");
                FormsAuthenticationTicket tkt;
                string     cookiestr;
                HttpCookie ck;
                tkt       = new FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now, DateTime.Now.AddMinutes(30), true, "Extra data");
                cookiestr = FormsAuthentication.Encrypt(tkt);
                ck        = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);

                ck.Expires = tkt.Expiration;
                ck.Path    = FormsAuthentication.FormsCookiePath;
                Response.Cookies.Add(ck);
                Response.Redirect("voting.aspx");
            }
            else
            {
                InvalidCredentialsMessage.Visible = true;
            }
        }
Exemplo n.º 8
0
        protected void draw_custom_table()
        {
            SQLFunctions conn = new SQLFunctions();
            TableRow     row;
            TableCell    cell;

            tableContent.Rows.Clear();

            resultsTally        rt  = evaluateTopBooks();
            List <resultsTally> lrt = new List <resultsTally>();


            row  = new TableRow();
            cell = new TableCell();

            if (rt.book_id > -1)
            {
                cell.Text = "With " + rt.numberVotes + " number one votes, the clear #1 is : " + rt.bookTitle;
                row.Cells.Add(cell);
            }
            else if (rt.book_id == -2)
            {
                lrt       = returnTiedTopBooks();
                cell.Text = "Tied with " + lrt[0].numberVotes + " number one votes, the two best books are : " + lrt[0].bookTitle + " and " + lrt[1].bookTitle;
                row.Cells.Add(cell);
            }
            else
            {
                cell.Text = "There no was no clear #1 pick for best book!";
                row.Cells.Add(cell);

                //cell = new TableCell();
                //List<resultsTally> lrt = evaluateTopBookPlurality();
                //cell.Text = "With " + lrt[0].numberVotes + " the plurality of people voted #1 as : " + lrt[0].bookTitle;
            }

            tableContent.Rows.Add(row);


            rt = new resultsTally();
            rt = evaluateBottomBooks();

            row  = new TableRow();
            cell = new TableCell();

            if (rt.book_id > -1)
            {
                cell.Text = "With " + rt.numberVotes + " number seven votes, the most disliked book is : " + rt.bookTitle;
                row.Cells.Add(cell);
            }
            else if (rt.book_id == -2)
            {
                lrt = new List <resultsTally>();
                //lrt = returnTiedBottomBooks();
                cell.Text = "Tied with " + lrt[0].numberVotes + " number seven votes, the two worst books are : " + lrt[0].bookTitle + " and " + lrt[1].bookTitle;
                row.Cells.Add(cell);
            }
            else
            {
                cell.Text = "There no was no clear #1 pick for worst book!";
                row.Cells.Add(cell);
            }

            tableContent.Rows.Add(row);

            int pages = conn.getTotalPagesRead(2018);

            if (pages > -1)
            {
                row       = new TableRow();
                cell      = new TableCell();
                cell.Text = "We have read " + pages + " number of pages in 2018";
                row.Cells.Add(cell);
                tableContent.Rows.Add(row);
            }

            bookModel highCount = conn.getHighPageCount();

            if (highCount.bookPageLength > -1)
            {
                row  = new TableRow();
                cell = new TableCell();

                cell.Text = "The high page count is " + highCount.bookTitle + " with " + highCount.bookPageLength + " pages.";
                row.Cells.Add(cell);
                tableContent.Rows.Add(row);
            }

            bookModel lowCount = conn.getLowPageCount();

            if (highCount.bookPageLength > -1)
            {
                row  = new TableRow();
                cell = new TableCell();

                cell.Text = "The low page count is " + lowCount.bookTitle + " with " + lowCount.bookPageLength + " pages.";
                row.Cells.Add(cell);
                tableContent.Rows.Add(row);
            }

            int pubdate = conn.getAvgBookPublishYear(2018);

            if (pubdate > -1)
            {
                row       = new TableRow();
                cell      = new TableCell();
                cell.Text = "The average first published year is " + pubdate;
                row.Cells.Add(cell);
                tableContent.Rows.Add(row);
            }
        }
Exemplo n.º 9
0
        public void btnSubmit_Click(object sender, EventArgs e)
        {
            string currentUser = HttpContext.Current.User.Identity.Name;


            if (validateSubmission())
            {
                SQLFunctions    conn   = new SQLFunctions();
                int             userId = conn.getUserID(currentUser);
                annualVoteModel voting = new annualVoteModel();
                voting.voterID  = userId;
                voting.voteDate = DateTime.Now;

                List <bookVote> choiceList = new List <bookVote>();
                bookVote        choices;

                foreach (HtmlTableRow row in tableContent.Rows)
                {
                    choices = new bookVote();

                    foreach (Control ctl in row.Cells[0].Controls.OfType <TextBox>())
                    {
                        string S = ((TextBox)ctl).Text;
                        choices.votePref = Convert.ToInt32(S);
                    }

                    if (row.Cells[2].InnerText != "Title")
                    {
                        choices.bookTitle = row.Cells[2].InnerText;
                        choiceList.Add(choices);
                    }
                    else
                    {
                        // Do nothing
                    }
                }

                for (int X = 0; X <= choiceList.Count - 1; X++)
                {
                    switch (choiceList[X].votePref)
                    {
                    case 1:
                        voting.votePref_1 = conn.getBookID(choiceList[X].bookTitle);
                        break;

                    case 2:
                        voting.votePref_2 = conn.getBookID(choiceList[X].bookTitle);
                        break;

                    case 3:
                        voting.votePref_3 = conn.getBookID(choiceList[X].bookTitle);
                        break;

                    case 4:
                        voting.votePref_4 = conn.getBookID(choiceList[X].bookTitle);
                        break;

                    case 5:
                        voting.votePref_5 = conn.getBookID(choiceList[X].bookTitle);
                        break;

                    case 6:
                        voting.votePref_6 = conn.getBookID(choiceList[X].bookTitle);
                        break;

                    case 7:
                        voting.votePref_7 = conn.getBookID(choiceList[X].bookTitle);
                        break;

                    default:
                        break;
                    }
                }

                // Submit answers
                conn.submitAnnualVote(voting);
                tableContent.Visible      = false;
                btnSubmit.Visible         = false;
                ThankYouForVoting.Visible = true;
            }
            else
            {
                // Testing
            }
        }
Exemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Load Book information

            HtmlTableRow  row;
            HtmlTableCell cell;
            TextBox       txtBox;
            int           x = 0;



            row  = new HtmlTableRow();
            cell = new HtmlTableCell();

            cell.InnerText = "Vote Preference";
            row.Cells.Add(cell);

            cell           = new HtmlTableCell();
            cell.InnerText = "Author";
            row.Cells.Add(cell);

            cell           = new HtmlTableCell();
            cell.InnerText = "Title";
            row.Cells.Add(cell);

            tableContent.Rows.Add(row);


            SQLFunctions conn = new SQLFunctions();

            //Check if user has already voted
            string currentUser = HttpContext.Current.User.Identity.Name;
            int    userId      = conn.getUserID(currentUser);

            if (conn.hasUserVoted(userId, 2019))
            {
                tableContent.Visible      = false;
                btnSubmit.Visible         = false;
                ThankYouForVoting.Text    = "You have already voted!";
                ThankYouForVoting.Visible = true;
            }
            else
            {
                //int count = conn.getBookCount();
                List <bookModel> book = conn.getBookAuthorTitle(2018);


                foreach (bookModel items in book)
                {
                    x++;
                    row    = new HtmlTableRow();
                    cell   = new HtmlTableCell();
                    txtBox = new TextBox();
                    //txtBox.ID = x.ToString();

                    txtBox.Width = 50;
                    cell.Controls.Add(txtBox);
                    row.Cells.Add(cell);
                    //cell.InnerText = "Vote!";
                    //row.Cells.Add(txtBox);

                    cell           = new HtmlTableCell();
                    cell.InnerText = items.bookAuthor;
                    row.Cells.Add(cell);

                    cell           = new HtmlTableCell();
                    cell.InnerText = items.bookTitle;
                    row.Cells.Add(cell);

                    tableContent.Rows.Add(row);
                }
            }
        }