Beispiel #1
0
        /// <summary>
        /// 保存用户分数
        /// </summary>
        private void setUserTest(int score)
        {
            string  sql = "select ID,Score from tbl_User_Test where testId=" + testId.ToString() + " and userId=" + userId.ToString();
            DataSet ds  = db.ReturnDataSet(sql);

            if (ds.Tables[0].Rows.Count == 1)
            {
                int Id    = (int)ds.Tables[0].Rows[0]["ID"];
                int total = score + (int)ds.Tables[0].Rows[0]["Score"];
                sql = "update tbl_User_Test set Score = " + total + " where Id=" + Id.ToString();
                if (!db.ExeSQL(sql))
                {
                    MessageBox.Show("分数更新失败!");
                }
                else
                {
                    lblScore.Text = total.ToString() + "分";
                }
            }
            else
            {
                sql = "insert into tbl_User_Test(userId,testId,Score) values( "
                      + "" + userId + ""
                      + "," + testId + ""
                      + "," + score + ")";
                if (!db.ExeSQL(sql))
                {
                    MessageBox.Show("分数更新失败!");
                }
                else
                {
                    lblScore.Text = score.ToString();
                }
            }
        }
        /// <summary>
        /// 用户注册
        /// </summary>
        private void regist()
        {
            string userName = txtUserName.Text;
            string password = txtPassword.Text;
            string birthday = "2016/01/01";//dtpBirthday.Value.ToShortDateString();
            bool   sex      = true;
            //if (rdoWoman.Checked) sex = false;
            string mail    = txtMail.Text;
            string tel     = txtTel.Text;
            string address = txtAddress.Text;

            if (userId > 0)
            {
                string sql = "update [tbl_User] set "
                             + "[UserName] ='" + userName + "'"
                             + ",[Password]='" + password + "'"
                             + ",[Birthday]=" + birthday + ""
                             + ",[Sex]=" + sex + ""
                             + ",[Mail]='" + mail + "'"
                             + ",[Tel]='" + tel + "'"
                             + ",[Address]='" + address + "'"
                             + " where id=" + userId;
                bool ret = db.ExeSQL(sql);
                if (ret)
                {
                    MessageBox.Show("更新成功!");
                    Close();
                }
                else
                {
                    MessageBox.Show("更新失败!");
                }
            }
            else
            {
                string sql = "insert into [tbl_User]([UserName],[Password],[Birthday],[Sex],[Mail],[Tel],[Address],[IsAdmin]) values("
                             + "'" + userName + "'"
                             + ",'" + password + "'"
                             + "," + birthday + ""
                             + "," + sex + ""
                             + ",'" + mail + "'"
                             + ",'" + tel + "'"
                             + ",'" + address + "'"
                             + ",False)";
                bool ret = db.ExeSQL(sql);
                if (ret)
                {
                    MessageBox.Show("注册成功!");
                    Close();
                }
                else
                {
                    MessageBox.Show("注册失败!");
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 确定用户排名
        /// </summary>
        public void btn_OnClick(object sender, EventArgs e)
        {
            string  sql = "select ID,userId,Score from tbl_User_Test where testId=" + testId.ToString() + " order by Score desc";
            DataSet ds  = db.ReturnDataSet(sql);

            if (ds.Tables[0].Rows.Count > 0)
            {
                int prevScore = -1;
                int rank      = 0;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    int Id     = (int)ds.Tables[0].Rows[i]["ID"];
                    int userId = (int)ds.Tables[0].Rows[i]["userId"];
                    int Score  = (int)ds.Tables[0].Rows[i]["Score"];
                    if (Score != prevScore)
                    {
                        rank++;
                        prevScore = Score;
                    }
                    sql = "update tbl_User_Test set rank = " + rank + " where Id=" + Id.ToString();
                    if (!db.ExeSQL(sql))
                    {
                        MessageBox.Show("排名更新失败!");
                    }
                    for (int j = 0; j < userTests.Length; j++)
                    {
                        if (userTests[j].getUserId() == userId)
                        {
                            userTests[j].setRank(rank);
                            break;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string id  = dgvUser.SelectedRows[0].Cells[0].Value.ToString();
            string sql = "delete from tbl_test where id=" + id;

            if (db.ExeSQL(sql))
            {
                sql = "delete from tbl_Test_Detail where testid=" + id;
                if (!db.ExeSQL(sql))
                {
                    MessageBox.Show("清除会议答题选题失败!");
                    return;
                }
                sql = "delete from tbl_Test_User where testid=" + id;
                if (!db.ExeSQL(sql))
                {
                    MessageBox.Show("清除会议参赛者失败!");
                    return;
                }
                sql = "delete from tbl_User_Test where testid=" + id;
                if (!db.ExeSQL(sql))
                {
                    MessageBox.Show("清除参赛排名失败!");
                    return;
                }
                sql = "delete from tbl_User_Test_Detail where testid=" + id;
                if (!db.ExeSQL(sql))
                {
                    MessageBox.Show("清除参赛答题详细失败!");
                    return;
                }
                MessageBox.Show("清除成功!");
                getAllTest();
            }
            else
            {
                MessageBox.Show("删除失败!");
            }
        }
Beispiel #5
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string id  = dgvUser.SelectedRows[0].Cells[0].Value.ToString();
            string sql = "delete from tbl_User where id=" + id;

            if (db.ExeSQL(sql))
            {
                getAllTest();
            }
            else
            {
                MessageBox.Show("删除失败!");
            }
        }
Beispiel #6
0
        /// <summary>
        /// 更新当前记录
        /// </summary>
        private void update()
        {
            int    id      = Convert.ToInt32(lblNo.Text);
            string content = txtContent.Text;
            string answerA = txtA.Text;
            string answerB = txtB.Text;
            string answerC = txtC.Text;
            string answerD = txtD.Text;
            int    score   = (int)nudScore.Value;
            string answer  = "A";

            if (rdoB.Checked)
            {
                answer = "B";
            }
            else if (rdoC.Checked)
            {
                answer = "C";
            }
            else if (rdoD.Checked)
            {
                answer = "D";
            }

            string sql = "update tbl_Question_Single set "
                         + "Content='" + content + "'"
                         + ",SelectionA='" + answerA + "'"
                         + ",SelectionB='" + answerB + "'"
                         + ",SelectionC='" + answerC + "'"
                         + ",SelectionD='" + answerD + "'"
                         + ",Score=" + score + ""
                         + ",Answer='" + answer + "'"
                         + " where ID=" + id.ToString();
            bool ret = db.ExeSQL(sql);

            if (ret)
            {
                MessageBox.Show("更新成功!");
            }
            else
            {
                MessageBox.Show("更新失败!");
            }
        }
Beispiel #7
0
 /// <summary>
 /// 确认
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnConfirm_Click(object sender, EventArgs e)
 {
     if (check())
     {
         if (id > -1)//更新
         {
             string sql = "delete from tbl_test where id=" + id;
             if (db.ExeSQL(sql))
             {
                 sql = "delete from tbl_Test_Detail where testid=" + id;
                 if (!db.ExeSQL(sql))
                 {
                     MessageBox.Show("清除会议答题选题失败!");
                     return;
                 }
                 sql = "delete from tbl_Test_User where testid=" + id;
                 if (!db.ExeSQL(sql))
                 {
                     MessageBox.Show("清除会议参赛者失败!");
                     return;
                 }
                 sql = "delete from tbl_User_Test where testid=" + id;
                 if (!db.ExeSQL(sql))
                 {
                     MessageBox.Show("清除参赛排名失败!");
                     return;
                 }
                 sql = "delete from tbl_User_Test_Detail where testid=" + id;
                 if (!db.ExeSQL(sql))
                 {
                     MessageBox.Show("清除参赛答题详细失败!");
                     return;
                 }
             }
         }
         if (CreateTest())
         {
             int testId = getTestId();
             if (testId > 0)
             {
                 if (CreateTestUser(testId))
                 {
                     MessageBox.Show("会议创建成功!");
                 }
                 else
                 {
                     MessageBox.Show("会议参赛人员添加失败!");
                 }
                 if (CreateTestDetail(testId))
                 {
                     MessageBox.Show("选题成功!");
                     Close();
                 }
                 else
                 {
                     MessageBox.Show("选题失败!");
                 }
             }
             else
             {
                 MessageBox.Show("会议创建失败!");
             }
         }
         else
         {
             MessageBox.Show("会议创建失败!");
         }
     }
 }
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newpasswordConfirm_Click(object sender, EventArgs e)
        {
            string  sql = "select * from tbl_User where Mail='" + txtUserId.Text + "' and password='******'";
            DataSet ds  = db.ReturnDataSet(sql);

            //判断四个文本框内是否有空项没填写
            if (txtPassword.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入旧密码!");
                txtPassword.Focus();
                return;
            }
            else if (newTxtPassword.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入新密码!");
                newTxtPassword.Focus();
                return;
            }
            else if (newPWordConfirmagain.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入确认密码!");
                newPWordConfirmagain.Focus();
                return;
            }

            //判断两次输入的新密码是否一致
            if (newTxtPassword.Text.Trim() != newPWordConfirmagain.Text.Trim())
            {
                MessageBox.Show("新密码和确认密码不一致!");
                return;
            }

            //判断新旧密码是否相同
            if (txtPassword.Text.Trim() == newPWordConfirmagain.Text.Trim())
            {
                MessageBox.Show("旧密码与新密码相同!");
                return;
            }


            //写入新密码
            if (ds.Tables[0].Rows.Count == 1)
            {
                sql = "update tbl_User set [password] = '" + newTxtPassword.Text + "' where Mail='" + txtUserId.Text + "';";
                if (db.ExeSQL(sql))
                {
                    MessageBox.Show("密码更新成功!");
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("密码更新失败!");
                }
            }
            else
            {
                sql = "select * from tbl_User where Mail='" + txtUserId.Text + "'";
                ds  = db.ReturnDataSet(sql);
                if (ds.Tables[0].Rows.Count == 1)
                {
                    MessageBox.Show("旧密码不正确!");
                }
                else
                {
                    MessageBox.Show("用户不存在!");
                }
            }
        }