コード例 #1
0
        //更新成绩
        private void button6_Click(object sender, EventArgs e)
        {
            ScoreInfo.id        = textBox6.Text;
            ScoreInfo.course_id = textBox7.Text;
            ScoreInfo.score     = numericUpDown1.Value.ToString();
            string Str3 = "select count(*) from score_info where Id = '" + ScoreInfo.id + "'and Course_Id = '" + ScoreInfo.course_id + "'";
            string str5 = "update score_info set score = '" + ScoreInfo.score + "'where Course_Id = '" + ScoreInfo.course_id + "'and Id = '" + ScoreInfo.id + "'";
            DBlink db   = new DBlink(); //创建数据库连接对象
            DBlink db4  = new DBlink(); //创建数据库连接对象

            if (db4.DBconn())
            { //连接数据库
                string Str1 = "select Course_name from course_information where Course_Id = " + ScoreInfo.course_id;
                string Str2 = "select name from user_information where Id = " + ScoreInfo.id;
                ScoreInfo.course_name = db4.Getstringsearch(Str1);
                ScoreInfo.name        = db4.Getstringsearch(Str2);
                //MessageBox.Show(ScoreInfo.course_id + ScoreInfo.course_name);
                int count = db4.GetIntsearch(Str3);
                if (count == 0)
                {
                    string str4 = "insert into score_info(name,Id,Course_name,Course_Id,score) " +
                                  "values('" + ScoreInfo.name + "','" + ScoreInfo.id + "','" + ScoreInfo.course_name + "','" + ScoreInfo.course_id + "','"
                                  + ScoreInfo.score + "');";
                    bool bool6 = db4.UpdataDeletAdd(str4);// 执行查询
                    if (bool6)
                    {
                        MessageBox.Show("更新记录成功!");
                    }
                    else
                    {
                        MessageBox.Show("更新记录失败!");
                    }
                }
                else
                {
                    bool bool7 = db4.UpdataDeletAdd(str5);// 执行查询
                    if (bool7)
                    {
                        MessageBox.Show("更新记录成功!");
                    }
                    else
                    {
                        MessageBox.Show("更新记录失败!");
                    }
                }
            }
            db4.DBclose();//关闭数据连接
            string sql = "SELECT score_info.Id as 学号, score_info.name as 姓名,score_info.course_name as 课程,score_info.score as 成绩 FROM score_info";

            BindsocreData(sql);
        }
コード例 #2
0
        //删除用户的按钮事件
        private void button2_Click(object sender, EventArgs e)
        {
            string str = "delete from login_info where username='******' and SF!= 'a'";
            DBlink db  = new DBlink();

            if (db.DBconn())
            {
                if (db.UpdataDeletAdd(str))//修改当前用户的tag标志
                {
                    DialogResult dr = MessageBox.Show("用户" + textBox1.Text + "删除成功!", "标题", MessageBoxButtons.OK, MessageBoxIcon.Question);
                    除用户ToolStripMenuItem_Click(null, null); //重新加载数据
                    //将用户输入的内容和提示信息文本置空
                    textBox2.Text = "";
                    label5.Text   = "";
                }
            }
        }
コード例 #3
0
        //退出
        //删除成绩
        private void button7_Click(object sender, EventArgs e)
        {
            ScoreInfo.id        = textBox6.Text;
            ScoreInfo.course_id = textBox7.Text;
            string delsql = "delete from score_info where Id= '" + ScoreInfo.id + "'and Course_Id = '" + ScoreInfo.course_id + "'";
            DBlink db4    = new DBlink(); //创建数据库连接对象

            if (db4.DBconn())
            { //连接数据库
                if (db4.UpdataDeletAdd(delsql))
                {
                    MessageBox.Show("删除记录成功!");
                }
                else
                {
                    MessageBox.Show("删除失败!");
                }
            }
            db4.DBclose();//关闭数据连接
            string sql = "SELECT score_info.Id as 学号, score_info.name as 姓名,score_info.course_name as 课程,score_info.score as 成绩 FROM score_info";

            BindsocreData(sql);
        }