protected void loadPageDefaults()
 {
     if (userDrop.Items.Count > 0)
     {
         userDrop.Items.Clear();
     }
     if (gr.DataSource != null)
     {
         gr.DataSource = null;
         gr.DataBind();
     }
     SQL sql = new SQL();
     DataTable DT = sql.getCandidates();
     gr.DataSource = DT;
     gr.DataBind();
     foreach (DataRow r in DT.Rows)
     {
         string name = r["Candidate"].ToString();
         string guid = r["UserKey"].ToString();
         if (!userDrop.Items.Contains(new ListItem(name, guid)))
         {
             ListItem item = new ListItem(name, guid);
             userDrop.Items.Add(item);
         }
     }
 }
        protected void Reload()
        {
            testDrop.Items.Clear();
            gr.DataSource = "";
            gr.DataBind();
            questionsWrap.InnerHtml = "";

            SQL sql = new SQL();
            DataTable DT = sql.GetTests();
            if (DT.Rows.Count > 0)
            {
                foreach (DataRow r in DT.Rows)
                {
                    string id = r["TestID"].ToString();
                    string name = r["Name"].ToString();
                    if (!testDrop.Items.Contains(new ListItem(name, id)))
                    {
                        ListItem item = new ListItem(name, id);
                        testDrop.Items.Add(item);
                    }
                }
            }
            gr.DataSource = DT;
            gr.DataBind();

            error.Visible = false;
        }
 protected void add_Click(object sender, EventArgs e)
 {
     error.Visible = false;
     success.Visible = false;
     encrypt en = new encrypt();
     SQL sql = new SQL();
     string username = user.Value.ToString().Trim();
     string password = pas.Value.ToString();
     string conf = confirm.Value.ToString();
     bool checknewUser = sql.checkNewUser(username);
     if (checknewUser)
     {
         errmsg.InnerText = "This user already exsists!";
         error.Visible = true;
     }
     else
     {
         if (password == conf && password != string.Empty)
         {
             string enpassword = en.Encrypt(password);
             sql.addUser(username, enpassword);
         }
         else
         {
             errmsg.InnerText = "The passwords do not match..";
             error.Visible = true;
         }
     }
     Reload();
 }
        //POST check Time
        public int checkTime([FromBody]string key)
        {
            SQL sql = new SQL();
            Guid gu = new Guid(key);
            times times = sql.checkTime(gu);
            DateTime start = Convert.ToDateTime(times.start_time);

            int lesstime = times.allowed_time - 5;

            if (DateTime.Now < start.AddMinutes(times.allowed_time))
            {
                if (DateTime.Now > start.AddMinutes(lesstime))
                {
                    return 3;
                }
                else
                {
                    return 2;
                }
            }
            else
            {
                return 1;
            }
        }
        protected void Login_Click(object sender, EventArgs e)
        {
            if (errorView.Visible)
            {
                errorView.Visible = false;
            }
            AD.ADAccountManagement ADinterface = new AD.ADAccountManagement();
            SQL sql = new SQL();
            try
            {
                bool check = sql.authUser(user.Value.ToString(), pass.Value.ToString());

                if (check)
                {
                    FormsAuthentication.SetAuthCookie(user.Value.ToString(), false);
                    Response.Redirect("~/Admin/Home.aspx");
                }
                else
                {
                    errorView.InnerText = "Bad Username or Password";
                    errorView.Visible = true;
                }

            }
            catch (Exception ex)
            {
                errorView.InnerText = "Error Validating account " + ex.Message.ToString();
                errorView.Visible = true;
            }
        }
 // POST Add
 public void AddQuestions([FromBody]object questionArray)
 {
     List<questions> questions = JsonConvert.DeserializeObject<List<questions>>(questionArray.ToString());
     SQL sql = new SQL();
     foreach (questions q in questions)
     {
         sql.addQuestions(q.question, q.test_id, q.qtype, q.points);
     }
 }
 protected void Button1_Click(object sender, EventArgs e)
 {
     string guid = userDrop.SelectedItem.Value;
     Guid gu = new Guid(guid);
     SQL sql = new SQL();
     sql.cleanUpUser(gu);
     loadPageDefaults();
     content.InnerHtml = "";
     times.Visible = false;
 }
Exemple #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string userkey = Request.QueryString["userkey"];
            questionsWrap.Attributes.Add("userkey", userkey);
            Guid gu = new Guid(userkey);
            SQL sql = new SQL();
            bool hasTaken = sql.checkIFTaken(gu);
            if (hasTaken)
            {
                string name = sql.CheckCandidate(gu);
                username.InnerText = "Candidate: " + name;
                int testId = sql.getTestID(gu);
                List<questions> list = GetQuestions(testId);

                foreach (questions q in list)
                {
                    switch (q.qtype)
                    {
                        case 1:
                            //create textarea
                            StringBuilder sbq = new StringBuilder();
                            sbq.Append("<div class='well well-small'>");
                            sbq.Append("<p>" + q.question + "</p>");
                            sbq.Append("<textarea class='span12' qid='" + q.question_id + "' runat='server' ");
                            sbq.Append("onKeyDown='limitText(this, 2600);' ");
                            sbq.Append("onKeyUp='limitText(this, 2600);' >");
                            sbq.Append("</textarea></div>");
                            questionsWrap.InnerHtml += sbq.ToString();
                            break;
                        case 2:
                            //create true/false
                            StringBuilder sbtf = new StringBuilder();
                            sbtf.Append("<div class='well well-small'>");
                            sbtf.Append("<p>" + q.question + "</p>");
                            sbtf.Append("<select qid='" + q.question_id + "'><option>true</option><option>false</option></select>");
                            sbtf.Append("</div>");
                            questionsWrap.InnerHtml += sbtf.ToString();
                            break;
                        default:
                            //nothing
                            break;
                    }
                }
                startTime(gu, DateTime.Now);
            }
            else
            {
                Response.Redirect("Entry.aspx");
            }
        }
Exemple #9
0
        protected List<questions> GetQuestions(int id)
        {
            SQL sql = new SQL();
            DataTable DT = sql.getTestQuestions(id);
            List<questions> list = new List<questions>();
            foreach(DataRow dr in DT.Rows)
            {
                Objects.questions question = new Objects.questions();
                question.question = dr["question"].ToString().Replace("@!@", "<br>");
                question.qtype = int.Parse(dr["type"].ToString());
                question.question_id = int.Parse(dr["identity"].ToString());
                list.Add(question);
            }

            return list;
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     SQL sql = new SQL();
     DataTable DT = sql.getUserNames();
     if (DT.Rows.Count > 0)
     {
         foreach (DataRow r in DT.Rows)
         {
             ListItem item = new ListItem(r["username"].ToString(), r["identity"].ToString());
             if (!userDrop.Items.Contains(item))
             {
                 userDrop.Items.Add(item);
             }
         }
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     SQL sql = new SQL();
     DataTable DT = sql.getCandidates();
     gr.DataSource = DT;
     gr.DataBind();
     foreach (DataRow r in DT.Rows)
     {
         string name = r["Candidate"].ToString();
         string guid = r["UserKey"].ToString();
         if (!userDrop.Items.Contains(new ListItem(name, guid)))
         {
             ListItem item = new ListItem(name, guid);
             userDrop.Items.Add(item);
         }
     }
 }
 protected void delete_Click(object sender, EventArgs e)
 {
     error.Visible = false;
     success.Visible = false;
     string user = userDrop.SelectedItem.Text;
     int id = int.Parse(userDrop.SelectedItem.Value);
     if (user != "Admin")
     {
         SQL sql = new SQL();
         sql.removeUser(id);
     }
     else
     {
         errmsg.InnerText = "You cannot delete the Admin user!";
         error.Visible = true;
     }
     Reload();
 }
        public bool AddAnswers([FromBody]object answerArray)
        {
            List<answers> answers = JsonConvert.DeserializeObject<List<answers>>(answerArray.ToString());
            SQL sql = new SQL();
            string user = answers[1].userguid.ToString();
            Guid gu = new Guid(user);
            bool hasTaken = sql.checkEndTime(gu);
            if (hasTaken)
            {
                return false;
            }
            else
            {

                foreach (answers a in answers)
                {
                    sql.addAnswer(a.userguid, a.question_id, a.answer);
                }
                sql.addEndTime(gu, DateTime.Now);
                return true;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SQL sql = new SQL();
            DataTable DT = sql.GetTests();
            if (DT.Rows.Count > 0)
            {
                foreach (DataRow r in DT.Rows)
                {
                    string id = r["TestID"].ToString();
                    string name = r["Name"].ToString();
                    if (!testDrop.Items.Contains(new ListItem(name, id)))
                    {
                        ListItem item = new ListItem(name, id);
                        testDrop.Items.Add(item);
                    }
                }
            }
            gr.DataSource = DT;
            gr.DataBind();

            error.Visible = false;
        }
 protected void delete_Click(object sender, EventArgs e)
 {
     try
     {
         int id = int.Parse(testDrop.SelectedItem.Value.ToString());
         SQL sql = new SQL();
         bool check = sql.preTestCleanChecks(id);
         if (check)
         {
             error.InnerText = "There are still users associated with the following test id: " + id;
             error.Visible = true;
         }
         else
         {
             sql.cleanupTests(id);
             Reload();
         }
     }
     catch (Exception)
     {
         error.Visible = true;
     }
 }
        protected void view_Click(object sender, EventArgs e)
        {
            content.InnerHtml = "";
            times.Visible = false;
            error.Visible = false;
            if (userDrop.Items.Count > 0)
            {
                string guid = userDrop.SelectedItem.Value;

                SQL sql = new SQL();
                Guid gu = new Guid(guid);
                DataTable DT = sql.getUserResults(gu);

                if (DT.Rows.Count > 0)
                {
                    string test_id = DT.Rows[0]["TestID"].ToString();
                    hiddeninput.Value = test_id;
                    hiddeninput.Attributes.Add("userKey", gu.ToString());
                    string startTime = DT.Rows[0]["StartTime"].ToString();
                    string endTime = DT.Rows[0]["EndTime"].ToString();
                    DateTime started = Convert.ToDateTime(startTime);
                    DateTime ended = Convert.ToDateTime(endTime);
                    TimeSpan timeTaken = ended - started;
                    total.InnerText = timeTaken.ToString();
                    start.InnerText = startTime;
                    end.InnerText = endTime;
                    foreach (DataRow r in DT.Rows)
                    {
                        int type = int.Parse(r["Type"].ToString());
                        string question = r["Question"].ToString().Replace("@!@", "<br>"); ;
                        string answer = r["Answer"].ToString().Replace("@!@", "\n");
                        int points = int.Parse(r["Points"].ToString());
                        switch (type)
                        {
                            case 1:
                                //create textarea
                                StringBuilder sb = new StringBuilder();
                                sb.Append("<div class='well well-small'>");
                                sb.Append("<p>" + question + "</p>");
                                sb.Append("<textarea class='span12' runat='server'>" + answer + "</textarea><br />");
                                sb.Append("Number of Points: <input type='text' style='width:20px;' /> /<span name='points'>" + points + "</span></div>");
                                content.InnerHtml += sb.ToString();
                                break;
                            case 2:
                                //create textarea
                                StringBuilder sbtf = new StringBuilder();
                                sbtf.Append("<div class='well well-small'>");
                                sbtf.Append("<p>True/False " + question + "</p>");
                                sbtf.Append("<textarea class='span12' runat='server'>" + answer + "</textarea><br />");
                                sbtf.Append("Number of Points: <input type='text' style='width:20px;' /> /<span name='points'>" + points + "</span></div>");
                                content.InnerHtml += sbtf.ToString();
                                break;
                        }
                    }

                    times.Visible = true;
                }

                else
                {
                    error.Visible = true;
                }
            }
            else
            {
                error.Visible = true;
            }
        }
 public bool setScore([FromBody]object pointsArray)
 {
     try
     {
         List<Score> scoreObject = JsonConvert.DeserializeObject<List<Score>>(pointsArray.ToString());
         int test_id = int.Parse(scoreObject[0].test_id.ToString());
         double userPoints = int.Parse(scoreObject[0].totalPoints.ToString());
         Guid gu = new Guid(scoreObject[0].userKey.ToString());
         SQL sql = new SQL();
         double total = sql.getPoints(test_id);
         double divide = (userPoints / total);
         double result = (divide * 100);
         int percent = Convert.ToInt32(result);
         string score = percent + "%";
         sql.setScore(gu, score);
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
        protected void reset_Click(object sender, EventArgs e)
        {
            error.Visible = false;
            success.Visible = false;
            int id = int.Parse(userDrop.SelectedItem.Value);
            string password = pas.Value.ToString();
            string conf = confirm.Value.ToString();
            encrypt en = new encrypt();
            if (password == conf && password != string.Empty)
            {
                string enpassword = en.Encrypt(password);
                try
                {
                    SQL sql = new SQL();
                    sql.resetPassword(id, enpassword);
                    successmsg.InnerText = "Password Reset";
                    success.Visible = true;
                }
                catch (Exception ex)
                {
                    errmsg.InnerText = "Error occoured changing password " + ex.Message.ToString();
                    error.Visible = true;
                }

            }
            else
            {
                errmsg.InnerText = "The passwords do not match..";
                error.Visible = true;
            }
        }
        protected void view_Click(object sender, EventArgs e)
        {
            questionsWrap.InnerHtml = "";
            try{
                int id = int.Parse(testDrop.SelectedItem.Value.ToString());
                SQL sql = new SQL();
                DataTable data = sql.getTestQuestions(id);

                if (data.Rows.Count > 0)
                {
                    foreach (DataRow r in data.Rows)
                    {
                        int qid = int.Parse(r["identity"].ToString());
                        string question = r["question"].ToString().Replace("@!@", "\n");
                        int type = int.Parse(r["type"].ToString());
                        switch (type) {
                            case 1:
                                StringBuilder sb = new StringBuilder();
                                sb.Append("<div class='row-fluid'><div class='well well-small'>");
                                sb.Append("<textarea disabled='disabled' qid='" + qid + "'>" + question + "</textarea><br />");
                                sb.Append("</div></div>");
                                questionsWrap.InnerHtml += sb.ToString();
                                break;
                            case 2:
                                StringBuilder sbtf = new StringBuilder();
                                sbtf.Append("<div class='row-fluid'><div class='well well-small'>");
                                sbtf.Append("<textarea disabled='disabled' qid='" + qid + "'>" + question + "</textarea>");
                                sbtf.Append("<select><option>True</option><option>False</option></select> <br />");
                                sbtf.Append("</div></div>");
                                questionsWrap.InnerHtml += sbtf.ToString();
                                break;
                        }
                    }
                }
                else
                {
                    error.Visible = true;
                }
            } catch(Exception){
                error.Visible = true;
            }
        }
 //POST Update Quesions
 public void UpdateQuestions([FromBody]object questionArray)
 {
     List<questions> questions = JsonConvert.DeserializeObject<List<questions>>(questionArray.ToString());
     SQL sql = new SQL();
     foreach (questions q in questions)
     {
         sql.updateQuestions(q.question, q.question_id);
     }
 }
 //POST Test Creations
 public int CreateTest([FromBody]string name)
 {
     SQL sql = new SQL();
     var id = sql.CreateTest(name);
     int testId = int.Parse(id.ToString());
     return testId;
 }
Exemple #22
0
        protected void btnCheck_Click(object sender, EventArgs e)
        {
            SQL sql = new SQL();
            try
            {

                Guid gu = new Guid(key.Value.Trim().ToString());
                bool hasTaken = sql.checkIFTaken(gu);
                if (hasTaken)
                {
                    string name = sql.CheckCandidate(gu);
                    if (name == null)
                    {
                        throw new NullReferenceException();
                    }
                    int allowed_time = sql.getAllowedTime(gu);
                    time.InnerText = allowed_time.ToString() + " Minutes";
                    Username.Value = name;
                    if (error.Visible == true)
                    {
                        error.Visible = false;
                        complete.Visible = true;
                        key.Disabled = true;
                    }
                    else
                    {
                        complete.Visible = true;
                        key.Disabled = true;
                    }
                }
                else
                {
                    if (complete.Visible == true)
                    {
                        complete.Visible = false;
                        error.Visible = true;
                        error.InnerText = "It looks like you have already taken this test!";
                    }
                    else
                    {
                        error.Visible = true;
                        error.InnerText = "It looks like you have already taken this test!";
                    }
                }
            } catch(NullReferenceException){
                if (complete.Visible == true)
                {
                    complete.Visible = false;
                    error.Visible = true;
                }
                else
                {
                    error.Visible = true;
                }
            }
            catch (Exception)
            {
                if (complete.Visible == true)
                {
                    complete.Visible = false;
                    error.Visible = true;
                }
                else
                {
                    error.Visible = true;
                }
            }
        }
 //POST Set totalpoins
 public void setPoints([FromBody] object pointsArray)
 {
     List<test> testObject = JsonConvert.DeserializeObject<List<test>>(pointsArray.ToString());
     SQL sql = new SQL();
     sql.setPoints(testObject[0].id, testObject[0].points);
 }
Exemple #24
0
 protected void startTime(Guid gu, DateTime now)
 {
     SQL sql = new SQL();
     sql.addStartTime(gu, now);
 }
 protected void Reload()
 {
     userDrop.Items.Clear();
     SQL sql = new SQL();
     DataTable DT = sql.getUserNames();
     if (DT.Rows.Count > 0)
     {
         foreach (DataRow r in DT.Rows)
         {
             ListItem item = new ListItem(r["username"].ToString(), r["identity"].ToString());
             if (!userDrop.Items.Contains(item))
             {
                 userDrop.Items.Add(item);
             }
         }
     }
 }
 public bool checkName([FromBody] string name)
 {
     SQL sql = new SQL();
     bool check = sql.checkTest(name);
     return check;
 }