private void AddClass_Click(object sender, EventArgs e)
 {
     try
     {
         string classname = dataGridView2.SelectedRows[0].Cells[0].Value.ToString();
         string teacher   = dataGridView2.SelectedRows[0].Cells[1].Value.ToString();
         string credit    = dataGridView2.SelectedRows[0].Cells[2].Value.ToString();
         label13.Text = classname;
         label14.Text = teacher;
         DialogResult dr = MessageBox.Show("确认选这门课吗?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
         if (dr == DialogResult.OK)
         {
             string sql = $"insert into TempSelectClassTB values ('{StuData.StuID}','{classname}',{credit})";
             pipe   pip = new pipe();
             if (pip.Execute(sql) > 0)
             {
                 MessageBox.Show("添加成功");
                 SelectClassTB();
             }
             else
             {
                 MessageBox.Show("添加失败" + sql);
             }
             pip.PipClose();
         }
     }
     catch
     {
         MessageBox.Show("请选择课程!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void button2_Click(object sender, EventArgs e)//提交选课按钮
        {
            try
            {
                string classname = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                string credit    = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();

                DialogResult dr = MessageBox.Show("确认提交这门课吗?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.OK)
                {
                    if (JudgeClass(credit) == 0)//符合规则
                    {
                        string sql1 = $"insert into SelectClassTB values ('{StuData.StuID}','{classname}',{credit})";
                        pipe   pip  = new pipe();
                        if (pip.Execute(sql1) > 0)
                        {
                            MessageBox.Show("添加成功");
                            SelectClassTB();
                        }
                        else
                        {
                            MessageBox.Show("添加失败" + sql1);
                        }

                        //插入学分到学生信息表
                        ClassData.credit   = int.Parse(label5.Text) + int.Parse(credit);//已选学分
                        ClassData.classnum = int.Parse(label6.Text) + 1;
                        string sql2 = $"UPDATE StuInfoTB SET StuCredit = {ClassData.credit},ClassNum = {ClassData.classnum} WHERE StuID = '{StuData.StuID}'";
                        if (pip.Execute(sql2) > 0)
                        {
                            label6.Text = ClassData.classnum.ToString();
                            label5.Text = ClassData.credit.ToString();
                            MessageBox.Show("更改成功!");
                        }
                        else
                        {
                            MessageBox.Show("更改失败" + sql2);
                        }
                        pip.PipClose();
                    }
                    else//不符合规则
                    {
                        MessageBox.Show("不符合选课规则");
                    }
                }
            }
            catch
            {
                MessageBox.Show("请选择课程!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        public void MyClassTable()
        {
            dataGridView1.Rows.Clear();//清空旧数据
            pipe        pip = new pipe();
            string      sql = $"select * from SelectClassTB WHERE StuID = '{StuData.StuID}'";
            IDataReader dc = pip.read(sql);
            string      a0, a1;

            while (dc.Read())
            {
                a0 = dc[1].ToString();//便于对数据进行处理
                a1 = dc[2].ToString();
                string[] table = { a0, a1 };
                dataGridView1.Rows.Add(table);
            }
            dc.Close();
            pip.PipClose();
        }
        public void LeadinStuInfo()
        {
            pipe        pip = new pipe();
            string      sql = $"select * from StuInfoTB where StuID='{StuData.StuID}'";
            IDataReader dc  = pip.read(sql);

            if (dc.Read())
            {
                string name     = dc[1].ToString();
                string classnum = dc[3].ToString();
                string credit   = dc[2].ToString();
                label6.Text = classnum;
                label5.Text = credit;
            }
            else
            {
                MessageBox.Show("读取学生信息失败");
            }
        }
        public void ClassInfoTB()       //从数据库读取数据显示在可选表格中
        {
            dataGridView2.Rows.Clear(); //清空就数据
            pipe        pip = new pipe();
            string      sql = "select * from ClassInfoTB";
            IDataReader dc = pip.read(sql);
            string      a0, a1, a2, a3;

            while (dc.Read())
            {
                a0 = dc[0].ToString();//便于对数据进行处理
                a1 = dc[2].ToString();
                a2 = dc[1].ToString();
                a3 = dc[3].ToString();
                string[] table = { a0, a1, a2, a3 };
                dataGridView2.Rows.Add(table);
            }
            dc.Close();
            pip.PipClose();
        }
Esempio n. 6
0
 private void tbStuID_TextChanged(object sender, EventArgs e)
 {
     if (tbStuID.Text.Length == 10)
     {
         //查询学号
         pipe        pip = new pipe();
         string      sql = $"select * from StuInfoTB where StuID='{tbStuID.Text}'";
         IDataReader dc  = pip.read(sql);
         if (dc.Read())
         {
             string name = dc[1].ToString();
             label4.Text     = name;
             StuData.StuName = name;
         }
         else
         {
             MessageBox.Show("查询失败");
         }
         pip.PipClose();
     }
 }
        public void SelectClassTB()
        {
            dataGridView1.Rows.Clear();//清空就数据
            pipe        pip = new pipe();
            string      sql = $"select * from TempSelectClassTB where StuID = '{StuData.StuID}'";
            IDataReader dc = pip.read(sql);
            string      a0, a1;
            int         classnum = 0;
            int         credit   = 0;

            while (dc.Read())
            {
                a0 = dc[1].ToString();//便于对数据进行处理
                a1 = dc[2].ToString();
                string[] table = { a0, a1 };
                dataGridView1.Rows.Add(table);
                classnum++;
                credit += int.Parse(a1);
            }

            dc.Close();
            pip.PipClose();
        }
        private void DeleteClass_Click(object sender, EventArgs e)
        {
            string classname = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            string credit    = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();

            DialogResult dr = MessageBox.Show("确认删除这门课吗?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.OK)
            {
                string sql = $"delete from TempSelectClassTB where ClassName = '{classname}'";
                pipe   pip = new pipe();
                if (pip.Execute(sql) > 0)
                {
                    MessageBox.Show("删除成功");
                    SelectClassTB();
                }
                else
                {
                    MessageBox.Show("删除失败" + sql);
                }
                pip.PipClose();
            }
        }