Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // metoden ligger i DatabaseConnections
            DatabaseConnection db = new DatabaseConnection();
            List<Person> personer = db.GetNoTestPersons();

            FillGrid(personer);
            //FillGrid(GetNoTestPersons()); alt 2
        }
Exemplo n.º 2
0
 /// <summary>
 /// Button event for user to click if use exceeds the time limit of the test.
 /// Calls method failuser and redirects to start1.aspx.
 /// </summary>
 protected void Button_Go_To_Start_Click(object sender, EventArgs e)
 {
     DatabaseConnection dc = new DatabaseConnection();
     var labelUserName1 = this.ContentPlaceHolder1.FindControl("lblUserName1") as Label;
     var labelTestType = this.ContentPlaceHolder1.FindControl("lblTestType") as Label;
     string userName = labelUserName1.Text;
     string typeOfTest = labelTestType.Text;
     dc.FailUser(userName, typeOfTest);
     Response.Redirect("~/start1.aspx");
 }
Exemplo n.º 3
0
        private void GetTeamMembers(string userName)
        {
            DatabaseConnection dr = new DatabaseConnection();
            string query = "SELECT firstname, lastname, testtype, date, score, passed, username " +
                            "FROM person p LEFT JOIN testoccasion t ON p.id = t.id_user " +
                            "WHERE id_testadmin = (SELECT id FROM person WHERE username = @userName) ";

            List<Person> teamMembers = dr.GetTeamMembers(query, userName);

            List<Person> personsWithUndoneTests = new List<Person>();
            personsWithUndoneTests = GetPersonsWithTestToDo(teamMembers);
            PopulateChart(personsWithUndoneTests, teamMembers);
        }
Exemplo n.º 4
0
        //session[typeofTest]
        protected void btnSend_Click(object sender, EventArgs e)
        {
            if(CheckTestTime() == true)
            {
                //Response.Write("Mer än 30 minuter"); //Test purpose
                DatabaseConnection dc = new DatabaseConnection();
                string typeOfTest = Session["typeOfTest"].ToString();
                string userName = lblUserName1.Text;
                dc.FailUser(userName, typeOfTest);
                btnSend.Enabled = false;
                Response.Redirect("~/FailPage.aspx"); //Sends user to a page to inform user that he/she failed.
            }
            else
            {
                //Response.Write("MIndre än 30 minuter"); //Test purpose.
                if (Session["IsFirstTime"] != null) //after buttonclick page reload will trigger onClick-event
                {
                    CorrectTest();
                }
                else
                {
                    string fileName = GetUserXmlFileName();
                    XDocument xDoc = XDocument.Load(Server.MapPath(fileName));

                    List<Repeater> reps = new List<Repeater>();
                    foreach (Repeater rep in repeaters.Controls.OfType<Repeater>())
                    {
                        reps.Add(rep);
                    }

                    foreach (Repeater rep in reps)
                    {
                        foreach (RepeaterItem item in rep.Items)
                        {
                            Label lbl = (Label)item.FindControl("question");
                            CheckBox chBox1 = (CheckBox)item.FindControl("cBox1");
                            CheckBox chBox2 = (CheckBox)item.FindControl("cBox2");
                            CheckBox chBox3 = (CheckBox)item.FindControl("cBox3");
                            CheckBox[] cBoxes = { chBox1, chBox2, chBox3 };
                            AddXmlAttribute(lbl.Text, cBoxes, xDoc);
                        }
                    }
                    SendUserXmlToDb();
                    CorrectTest();
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Method updates labels on start1.aspx with relevant values.
        /// Uses method GetLoggedInUserInfo to retrieve said information,
        /// </summary>
        private void UpdateWebsiteGUI()
        {
            DatabaseConnection dc = new DatabaseConnection();
            DataTable dt = new DataTable();
            DataTable dtAllInfo = new DataTable();

            dt = dc.GetPersonInfo(userId);
            string userName = dt.Rows[0]["username"].ToString();
            lblUserName.Text = userName;

            dtAllInfo = dc.GetPersonAndTestInfo(userName);

            if (dtAllInfo.Rows.Count <= 0)
            {
                lblresult.Text = "Inget test hittat";
                lbldate.Text = "Inget datum";
                lbltestToDo.Text = "1";
                lblTestType.Text = "LST";
                DateTime today = DateTime.Now;
                lblNextTestDate.Text = today.ToString("yyyy-MM-dd");
                btnGoToOldTest.Enabled = false;
            }
            else
            {
                string passTest = dtAllInfo.Rows[0]["passed"].ToString();

                DateTime date = DateTime.Parse(dtAllInfo.Rows[0]["date"].ToString());
                lblresult.Text = SetPassOrFail(passTest);
                lbltestToDo.Text = CheckDateOfLastTest(date, passTest);
                lbldate.Text = date.ToString("yyyy-MM-dd");
                lblTestType.Text = SetTypeOfTest();
                lblTestTypeDone.Text = dtAllInfo.Rows[0]["testtype"].ToString();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Method evaluates what type of test user should do, either ÅKU or LST.
        /// </summary>
        /// <returns>Returns new string value.</returns>
        private string SetTypeOfTest()
        {
            DatabaseConnection dc = new DatabaseConnection();
            string userName = lblUserName.Text;
            DataTable dt = dc.GetPersonAndTestInfo(userName);
            string typeOfTest = string.Empty;
            string passTest = string.Empty;

            if (dt.Rows.Count <= 0)
            {
                typeOfTest = "LST";
                return typeOfTest;
            }
            else
            {
                typeOfTest = dt.Rows[0]["testtype"].ToString();
                passTest = dt.Rows[0]["passed"].ToString();

                if (typeOfTest == "LST" && passTest == "False")
                {
                    typeOfTest = "LST";
                    return typeOfTest;
                }
                else
                {
                    typeOfTest = "ÅKU";
                    return typeOfTest;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Method assumes that that a user has been redirected from a login page
        /// calls method GetLoggedinuserinfo to retrieve what privielge user have
        /// to see if admin or not. Hides navbar button to get to adminpanel.
        /// Should maybe put this in a class togheter with GeLoggedInUserInfo
        /// to be able to use it on every page? Good enough for the demo,
        /// but will have to be reworked, preferably with a proper nuget or built in
        /// system to restrict access to webpages.
        /// </summary>
        private void CheckPrivilegeHideNavButton()
        {
            DatabaseConnection dc = new DatabaseConnection();
            DataTable dt = dc.GetPersonInfo(userId);
            string userType = dt.Rows[0]["privilege"].ToString();

            if (userType != "Admin")
            {
                //Goes through HTML to find buttons to hide.
                HtmlAnchor menuButton = (HtmlAnchor)Page.Master.FindControl("adminButton");
                HtmlAnchor menuButton1 = (HtmlAnchor)Page.Master.FindControl("a1");
                //Hides buttons.
                menuButton.Visible = false;
                menuButton1.Visible = false;
            }
        }
Exemplo n.º 8
0
        // Request.QueryString["userName"] & Request.QueryString["typeofTest"]
        private void UpdateDbWithResult(Dictionary<string, int> allScores, List<int> totalQuestions, Dictionary<string, double> allPercents)
        {
            DatabaseConnection db = new DatabaseConnection();
            string userName = Request.QueryString["userName"];
            string id = db.GetUserId(userName);
            string typeOfTest = Request.QueryString["typeofTest"];
            //string typeOfTest = "LST"; //will be typeOfTest later
            string totalScore = String.Format("{0}/{1}", allScores["Totalt"], totalQuestions[0]);

            db.UpdateAfterTestIsComplete(id, DateTime.Today, totalScore, IsTestPassed(allPercents), typeOfTest);
        }
Exemplo n.º 9
0
        //Request.QueryString["userName"]
        private void SendUserXmlToDb()
        {
            DatabaseConnection db = new DatabaseConnection();
            string userName = Request.QueryString["userName"];
            string id = db.GetUserId(userName);
            List<string> userXmls = db.RetrieveXmlDocument(id, DateTime.Today);

            if (userXmls.Count < 1)
            {
                string fileName = GetUserXmlFileName();
                XDocument xDoc = XDocument.Load(Server.MapPath(fileName));
                db.SaveUserXml(id, xDoc, DateTime.Today);
            }
            else
            {
                //person has already done a test today
            }
        }
Exemplo n.º 10
0
        //Request.QueryString["userName"]
        private XDocument GetUserXmlFromDb()
        {
            DatabaseConnection db = new DatabaseConnection();
            string userName = Request.QueryString["userName"];
            string id = db.GetUserId(userName);
            List<string> userXmls = db.RetrieveXmlDocument(id, DateTime.Today);

            XDocument xDoc = XDocument.Parse(userXmls[0]);
            XDeclaration xDec = xDoc.Declaration; //for some reason postgres changes encoding to utf-16, changing it back!
            xDec.Encoding = "utf-8";

            string fileName = GetUserXmlFileName();
            xDoc.Save(Server.MapPath(fileName));

            return xDoc;
        }
Exemplo n.º 11
0
 //session[typeoftest]
 /// <summary>
 /// Tick event for timer. At the moment its on 3 minutes.
 /// Calls methods in databaseconnection to failuser.
 /// </summary>
 protected void Timer1_Tick(object sender, EventArgs e)
 {
     DatabaseConnection dc = new DatabaseConnection();
     string userName = lblUserName1.Text;
     string typeOfTest = Session["typeOfTest"].ToString();
     dc.FailUser(userName, typeOfTest);
     Response.Redirect("~/start1.aspx");
 }
Exemplo n.º 12
0
        private List<Person> GetTeamMembers(string userName)
        {
            DatabaseConnection dr = new DatabaseConnection();
            string query = "SELECT firstname, lastname, testtype, date, score, passed, username " +
                            "FROM person p LEFT JOIN testoccasion t ON p.id = t.id_user " +
                            "WHERE id_testadmin = (SELECT id FROM person WHERE username = @userName) "+
                            "ORDER BY lastname, firstname, username, date DESC ";

            List<Person> teamMembers = dr.GetTeamMembers(query, userName);
            return teamMembers;
        }
Exemplo n.º 13
0
        //Session["userName"]
        /// <summary>
        /// Updated to only get latest test from one specific user. 
        /// </summary>
        /// <returns></returns>
        private XDocument GetUserXmlFromDb()
        {
            DatabaseConnection db = new DatabaseConnection();
            string userName = Session["userName"].ToString();
            string id = db.GetUserId(userName);
            List<string> userXmls = db.GetUserLatestTest(id);

            XDocument xDoc = XDocument.Parse(userXmls[0]);
            XDeclaration xDec = xDoc.Declaration; //for some reason postgres changes encoding to utf-16, changing it back!
            xDec.Encoding = "utf-8";

            string fileName = GetUserXmlFileName();
            xDoc.Save(Server.MapPath(fileName));

            return xDoc;
        }
Exemplo n.º 14
0
 //Request.Querystring["username"]
 private List<Person> GetAlltests()
 {
     DatabaseConnection dr = new DatabaseConnection();
     string userName = Request.QueryString["userName"];
     //string userName = "******"; //will be replaced by above code later
     return dr.RetrieveAllXmlDocuments(pickTestType.Text, userName);
 }
Exemplo n.º 15
0
 //Session["username"]
 private List<Person> GetAllTestsRegardlessType()
 {
     DatabaseConnection dr = new DatabaseConnection();
     string userName = Session["userName"].ToString();
     return dr.RetrieveAllXmlDocuments(userName);
 }