Esempio n. 1
0
        protected void signup_Click(object sender, EventArgs e)
        {
            string sql      = null;
            string userid   = userid_sign.Text.Trim();
            string email    = email_sign.Text.Trim();
            string username = username_sign.Text.Trim();
            string pwd      = password_sign.Text.Trim();

            userid_signCustomValidator2.Validate();
            username_signRequiredFieldValidator1.Validate();
            email_signValidator1.Validate();
            passwordValidator.Validate();
            PasswordCompareValidator.Validate();
            if (userid_signCustomValidator2.IsValid && username_signRequiredFieldValidator1.IsValid && email_signValidator1.IsValid && passwordValidator.IsValid && PasswordCompareValidator.IsValid)
            {
                try
                {
                    sql = "insert into user (sn, name, password, email) values (@userid, @username, @pwd, @email)";
                    Mysqldb         mysqldb    = new Mysqldb();
                    MySqlConnection connection = mysqldb.getConnection();
                    MySqlCommand    cmd        = mysqldb.getCommand(connection);
                    cmd.CommandText = sql;
                    cmd.Parameters.AddWithValue("@userid", userid);
                    cmd.Parameters.AddWithValue("@username", username);
                    cmd.Parameters.AddWithValue("@pwd", pwd);
                    cmd.Parameters.AddWithValue("@email", email);
                    if (mysqldb.ExceSql(cmd, connection))
                    {
                        //成功插入,注册成功,重新登陆
                        mysqldb.Close();
                        this.RegisterStartupScript("hello", "<script>alert('注册成功,请登录!')</script>");
                    }
                    else
                    {
                        login_result.Text = "<a class='error'>注册失败,请稍后重试</a>";
                    }
                }
                catch (Exception error)
                {
                    //login_result.Text = "<a class='error'>服务器繁忙,请稍后重试</a>";
                    login_result.Text = error.ToString();
                    Console.WriteLine("An error occurred when connection trys to connect: '{0}'", error);
                }
            }
        }
Esempio n. 2
0
        protected void Submit1_Click(object sender, EventArgs e)
        {
            if (count_total == 15)
            {
                Mysqldb         mysqldb                = new Mysqldb();
                MySqlConnection connection             = mysqldb.getConnection();
                MySqlCommand    cmd                    = mysqldb.getCommand(connection);
                ArrayList       questions_one_chosed   = null;
                ArrayList       questions_more_chosed  = null;
                ArrayList       questions_judge_chosed = null;

                ConnectMongo();

                int       score_total              = 0;
                string    userid                   = Session["sn"].ToString();
                Hashtable Question_Save            = (Hashtable)Session["Question_Save"];
                ArrayList question_one             = (ArrayList)Question_Save["questions_one"];
                ArrayList question_more            = (ArrayList)Question_Save["questions_more"];
                ArrayList question_judge           = (ArrayList)Question_Save["questions_judge"];
                Hashtable hashtable_question_one   = Exam_Drector.Get_Score(DataList_Questoin_One, question_one, "questions_one");
                Hashtable hashtable_question_more  = Exam_Drector.Get_Score(DataList_Questoin_More, question_more, "questions_more");
                Hashtable hashtable_question_judge = Exam_Drector.Get_Score(DataList_Questoin_Judge, question_judge, "questions_judge");
                score_total = Convert.ToInt32(hashtable_question_one["questions_one_score"]) + Convert.ToInt32(hashtable_question_more["questions_more_score"]) + Convert.ToInt32(hashtable_question_judge["questions_judge_score"]);
                Session["hashtable_question_one"]   = hashtable_question_one;
                Session["hashtable_question_more"]  = hashtable_question_more;
                Session["hashtable_question_judge"] = hashtable_question_judge;
                Session["score_total"] = score_total;
                count_total            = 0;                 // 对进度条清0
                // 存储这次考试记录
                DateTime datetime = DateTime.Now;
                string   exam_id  = userid.ToString() + "_" + datetime.ToString();
                string   sql      = "insert into exam_record (userId, examId, score, datetime) VALUES (@userid, @exam_id, @score_total, @datetime)";
                cmd.CommandText = sql;
                cmd.Parameters.AddWithValue("@userid", userid);
                cmd.Parameters.AddWithValue("@exam_id", exam_id);
                cmd.Parameters.AddWithValue("@score_total", score_total.ToString());
                cmd.Parameters.AddWithValue("@datetime", datetime.ToString());
                if (mysqldb.ExceSql(cmd, connection))
                {
                    //成功插入
                    mysqldb.Close();
                }
                else
                {
                    Response.Write("mysql 插入失败");
                }
                mysqldb.ExceSql(cmd, connection);
                // 将这次考试的试题信息,以及答题信息存储到 mongodb 中
                var document = new BsonDocument
                {
                    { "examId", exam_id },
                };
                // 用户题目 选择
                question_one   = ArraylistToObject(question_one);
                question_more  = ArraylistToObject(question_more);
                question_judge = ArraylistToObject(question_judge);

                questions_one_chosed   = (ArrayList)hashtable_question_one["questions_one_chosed"];
                questions_more_chosed  = (ArrayList)hashtable_question_more["questions_more_chosed"];
                questions_judge_chosed = (ArrayList)hashtable_question_judge["questions_judge_chosed"];

                var question_one_save = new List <ArrayList> {
                    question_one
                };
                var question_more_save = new List <ArrayList> {
                    question_more
                };
                var question_judge_save = new List <ArrayList> {
                    question_judge
                };

                var question_one_chosed_save = new List <ArrayList> {
                    questions_one_chosed
                };
                var question_more_chosed_save = new List <ArrayList> {
                    questions_more_chosed
                };
                var question_judge_chosed_save = new List <ArrayList> {
                    questions_judge_chosed
                };

                document.Add("question_one", new BsonArray(question_one_save));
                document.Add("question_more", new BsonArray(question_more_save));
                document.Add("question_judge", new BsonArray(question_judge_save));
                document.Add("questions_one_chosed", new BsonArray(question_one_chosed_save));
                document.Add("questions_more_chosed", new BsonArray(question_more_chosed_save));
                document.Add("questions_judge_chosed", new BsonArray(question_judge_chosed_save));

                //document.Add("question_chosed", new BsonArray(question_chosed));
                mongodb.GetCollection("exam");
                mongodb.Insert(document);
                Response.Redirect("~/Result.aspx");
            }
            else
            {
#pragma warning disable CS0618 // 类型或成员已过时
                this.RegisterStartupScript("hello", "<script>alert('还有题目未完成哦!')</script>");
#pragma warning restore CS0618 // 类型或成员已过时
            }
        }