예제 #1
0
파일: VRForm.cs 프로젝트: redjser/C_project
        private void cboMajorsInit()
        {
            cboMajors.Items.Clear();
            DBHelper db  = new DBHelper();
            string   sql = "select * from majors where id in(" + UserInfoForm.convertPermission(UserHelper.user.permission) + ")";

            try
            {
                DbCommand cmd = db.GetSqlStringCommand(sql);
                using (DbDataReader reader = db.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        Major major = new Major();
                        major.id   = (int)reader["id"];
                        major.name = (string)reader["name"];
                        cboMajors.Items.Add(major);
                    }
                }
                //   cboMajors.Text = UserInfoForm.getMajorByMajorId(UserHelper.currentMajorId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
 private void btnAutoSetQuestionConfirm_Click(object sender, EventArgs e)
 {
     //MessageBox.Show(nudSelectNum.Tag.ToString());
     if (!checkInput())
     {
         return;
     }
     if (pNameDialog.ShowDialog() == DialogResult.OK)
     {
         Paper paper = new Paper();
         paper.name        = pNameDialog.paperName;
         paper.publishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
         paper.major       = UserInfoForm.getMajorByMajorId(UserHelper.currentMajorId);
         paper.teacherName = UserHelper.user.name;
         if (extractQuestion() == null)
         {
             MessageBox.Show("题库中没有足够的题目,详情请联系管理员···", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         if (addPaper(paper, extractQuestion()))
         {
             MessageBox.Show("试卷 ”" + paper.name + "“ 添加失败···", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         MessageBox.Show("试卷 ”" + paper.name + "“ 添加成功!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Information);
         showAllPapers();
         paperInfoPanel.Show();
         autoSetQuestionPanel.Hide();
     }
 }
예제 #3
0
        //“登录”按钮的单击事件
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!checkInput())
            {
                return;     //检查输入
            }
            bool     loginResult = false;
            DBHelper db          = new DBHelper();
            string   sql         = "select * from users where loginId='" + txtLoginId.Text + "' and password='******'";

            try
            {
                DbCommand cmd = db.GetSqlStringCommand(sql);
                using (DbDataReader reader = db.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        if ((int)reader["state"] != 0)
                        {
                            MessageBox.Show("该用户已被锁定,详细情况请联系管理员!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        rememberPwd();
                        loginResult = true;
                        int roleId = (int)reader["roleId"];
                        UserHelper.loginId = txtLoginId.Text.Trim();
                        if (roleId != 3)
                        {
                            UserHelper.user           = UserInfoForm.readerToUser(reader);
                            UserHelper.currentMajorId = (int)reader["majorId"];
                        }
                        switch (roleId)
                        {
                        case 1: UserHelper.loginType = "student";
                            break;

                        case 2: UserHelper.loginType = "teacher";
                            break;

                        case 3: UserHelper.loginType = "admin";
                            break;
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("数据库连接失败,请检查网络连接!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (loginResult)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("登录失败,请检查用户名或密码是否有误!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #4
0
        public static Role readerToRole(DbDataReader reader)
        {
            Role role = new Role();

            role.id      = (int)reader["id"];
            role.name    = reader["name"].ToString();
            role.major   = UserInfoForm.getMajorByMajorId((int)reader["majorId"]);
            role.sceneId = (int)reader["VR_scene_id"];
            role.isRobot = (bool)reader["isRobot"];
            return(role);
        }
예제 #5
0
        public static Question readerToQuestion(DbDataReader reader)
        {
            Question question = new Question();

            question.id         = (int)reader["id"];
            question.question   = (string)reader["question"];
            question.answer     = (string)reader["answer"];
            question.difficulty = (reader["difficulty"] is DBNull) ? null : ((string)reader["difficulty"]);
            question.major      = UserInfoForm.getMajorByMajorId((int)reader["majorId"]);
            question.type       = getTypeByTypeId((int)reader["typeId"]);
            question.optionA    = (reader["OptionA"] is DBNull) ? null : ((string)reader["OptionA"]);
            question.optionB    = (reader["OptionB"] is DBNull) ? null : ((string)reader["OptionB"]);
            question.optionC    = (reader["OptionC"] is DBNull) ? null : ((string)reader["OptionC"]);
            question.optionD    = (reader["OptionD"] is DBNull) ? null : ((string)reader["OptionD"]);
            return(question);
        }
예제 #6
0
        //添加
        public int add_role(Role role)
        {
            int result = 0;

            if (checkTable(role.name, "vr_roleid", "name"))
            {
                MessageBox.Show("此名称已存在!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DBHelper db  = new DBHelper();
                string   sql = "insert into vr_roleid values('" + role.name + "'," + UserInfoForm.getMajorIdByMajor(role.major) + ")";
                try
                {
                    DbCommand cmd = db.GetSqlStringCommand(sql);
                    result = db.ExecuteNonQuery(cmd);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(result);
        }
예제 #7
0
        //添加
        public int add_video(Video video)
        {
            int result = 0;

            if (checkTable(video.name, "game_questions", "question"))
            {
                MessageBox.Show("此项目已存在!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DBHelper db  = new DBHelper();
                string   sql = "insert into game_questions values('" + video.name + "',null," + UserInfoForm.getMajorIdByMajor(video.major) + ",2,null,null,null,null,'" + video.url + "'," + video.startTime + "," + video.endTime + ")";
                try
                {
                    DbCommand cmd = db.GetSqlStringCommand(sql);
                    result = db.ExecuteNonQuery(cmd);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(result);
        }
예제 #8
0
        //更新题目
        public int update_video(Video video)
        {
            int result = 0;

            if (checkTable(video.name, video.id, "game_questions", "question"))
            {
                MessageBox.Show("存在相同项目,请更改!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DBHelper db  = new DBHelper();
                string   sql = "update game_questions set question='" + video.name + "',startTime='" + video.startTime + "',endTime='" + video.endTime + "',majorId=" + UserInfoForm.getMajorIdByMajor(video.major) + ",fileName='" + video.url + "' where id=" + video.id;
                try
                {
                    DbCommand cmd = db.GetSqlStringCommand(sql);
                    result = db.ExecuteNonQuery(cmd);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(result);
        }
예제 #9
0
        //添加题目
        public int add_i_Question(Question question)
        {
            int result = 0;

            if (checkTable(question.question, "game_questions", "question"))
            {
                MessageBox.Show("此题目已存在!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DBHelper db  = new DBHelper();
                string   sql = "insert into game_questions values('" + question.question + "','" + question.answer + "'," + UserInfoForm.getMajorIdByMajor(question.major) + ",1,null,null,null,null," + (question.multiOption == null ? "null" : "'" + list2string(question.multiOption) + "'") + ",null,null)";
                try
                {
                    DbCommand cmd = db.GetSqlStringCommand(sql);
                    result = db.ExecuteNonQuery(cmd);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(result);
        }
예제 #10
0
        //更新题目
        public int update_i_Question(Question question)
        {
            int result = 0;

            if (checkTable(question.question, question.id, "game_questions", "question"))
            {
                MessageBox.Show("存在相同题目,请更改题目!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DBHelper db  = new DBHelper();
                string   sql = "update game_questions set question='" + question.question + "',answer='" + question.answer + "',majorId=" + UserInfoForm.getMajorIdByMajor(question.major) + ",type=1,fileName=" + (question.multiOption == null ? "null" : "'" + list2string(question.multiOption) + "'") + " where id=" + question.id;
                try
                {
                    DbCommand cmd = db.GetSqlStringCommand(sql);
                    result = db.ExecuteNonQuery(cmd);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(result);
        }
예제 #11
0
        //更新
        public int update_role(Role role)
        {
            int result = 0;

            if (checkTable(role.name, role.id, "vr_roleid", "name"))
            {
                MessageBox.Show("存在相同名称,请更改名称!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DBHelper db  = new DBHelper();
                string   sql = "update vr_roleid set name='" + role.name + "',majorId=" + UserInfoForm.getMajorIdByMajor(role.major) + " where id=" + role.id;
                try
                {
                    DbCommand cmd = db.GetSqlStringCommand(sql);
                    result = db.ExecuteNonQuery(cmd);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(result);
        }
예제 #12
0
        //添加题目
        public int addQuestion(Question question)
        {
            int result = 0;

            if (checkQuestion(question.question))
            {
                MessageBox.Show("此题目已存在!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DBHelper db  = new DBHelper();
                string   sql = "insert into questions values('" + question.question + "','" + question.answer + "','" + question.difficulty + "'," + UserInfoForm.getMajorIdByMajor(question.major) + "," + getTypeIdByType(question.type) + "," + (question.optionA == null ? "null" : "'" + question.optionA + "'") + "," + (question.optionB == null ? "null" : "'" + question.optionB + "'") + "," + (question.optionC == null ? "null" : "'" + question.optionC + "'") + "," + (question.optionD == null ? "null" : "'" + question.optionD + "'") + ")";
                try
                {
                    DbCommand cmd = db.GetSqlStringCommand(sql);
                    result = db.ExecuteNonQuery(cmd);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(result);
        }
예제 #13
0
        //更新题目
        public int updateQuestion(Question question)
        {
            int result = 0;

            if (checkQuestion(question.question, question.id))
            {
                MessageBox.Show("存在相同题目,请更改题目!", "基于虚拟现实的铁路综合运输训练系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DBHelper db  = new DBHelper();
                string   sql = "update questions set question='" + question.question + "',answer='" + question.answer + "',difficulty='" + question.difficulty + "',majorId=" + UserInfoForm.getMajorIdByMajor(question.major) + ",typeId=" + getTypeIdByType(question.type) + ",OptionA=" + (question.optionA == null ? "null" : "'" + question.optionA + "'") + ",OptionB=" + (question.optionB == null ? "null" : "'" + question.optionB + "'") + ",OptionC=" + (question.optionC == null ? "null" : "'" + question.optionC + "'") + ",OptionD=" + (question.optionD == null ? "null" : "'" + question.optionD + "'") + " where id=" + question.id;
                try
                {
                    DbCommand cmd = db.GetSqlStringCommand(sql);
                    result = db.ExecuteNonQuery(cmd);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(result);
        }