Ejemplo n.º 1
0
        //获取查询学生信息
        public static DataSet getStudentInfo(Student.StudentInfoData data)
        {
            string condition = "";

            if (data.Sno != null && data.Sno != "")
            {
                condition += "and Sno='" + data.Sno + "'";
            }
            if (data.Sname != null && data.Sname != "")
            {
                condition += "and Sname='" + data.Sname + "'";
            }
            if (data.Sex != null && data.Sex != "")
            {
                condition += "and Sex='" + data.Sex + "'";
            }
            if (data.Grade != null && data.Grade != "")
            {
                condition += "and Grade='" + data.Grade + "'";
            }
            if (data.Dept != null && data.Dept != "")
            {
                condition += "and Dept='" + data.Dept + "'";
            }
            string sql = "select Sno StudentNumber,Sname StudentName, Sex,Grade,Dept Department from Student where 2=2 " + condition;

            return(dataAccess.GetDataSet(sql, "Student"));
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string Sno   = textBox1.Text.Trim();
            string Sname = textBox2.Text;
            string Sex   = textBox3.Text;
            string Grade = textBox4.Text;
            string Dept  = textBox7.Text;

            Student.StudentInfoData data = new Student.StudentInfoData();

            data.Sno   = Sno;
            data.Sname = Sname;
            data.Sex   = Sex;
            data.Grade = Grade;
            data.Dept  = Dept;

            try
            {
                ds = Student.StudentInfoOperation.getStudentInfo(data);
                this.dataGridView1.DataSource = ds.Tables[0];
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Ejemplo n.º 3
0
 public InsertStudent(string flag)
 {
     InitializeComponent();
     this.FLAG = flag;
     if (flag != "")
     {
         Student.StudentInfoData data = new Student.StudentInfoData();
         data.Sno = flag;
         DataSet ds = Student.StudentInfoOperation.getStudentInfo(data);
         this.textBox1.Text    = flag;
         this.textBox2.Text    = ds.Tables[0].Rows[0]["StudentName"].ToString();
         this.textBox3.Text    = ds.Tables[0].Rows[0]["Sex"].ToString();
         this.textBox4.Text    = ds.Tables[0].Rows[0]["Grade"].ToString();
         this.textBox5.Text    = ds.Tables[0].Rows[0]["Department"].ToString();
         this.textBox1.Enabled = false;
         this.Text             = "Update";
     }
 }
Ejemplo n.º 4
0
        //修改学生信息
        public static bool updateStudentInfo(Student.StudentInfoData data)
        {
            string sql = "update Student set Sname='" + data.Sname + "',Sex='" + data.Sex + "',Grade=" + data.Grade + ",Dept='" + data.Dept + "' where Sno='" + data.Sno + "'";

            return(dataAccess.ExecuteSQL(sql));
        }
Ejemplo n.º 5
0
        //插入学生记录
        public static bool insertStudentInfo(Student.StudentInfoData data)
        {
            string sql = "insert into Student(Sno,Sname,Sex,Grade,Dept) values('" + data.Sno + "','" + data.Sname + "','" + data.Sex + "'," + data.Grade + ",'" + data.Dept + "')";

            return(dataAccess.ExecuteSQL(sql));
        }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            string Sno   = textBox1.Text.Trim();
            string Sname = textBox2.Text;
            string Sex   = textBox3.Text;
            string Grade = textBox4.Text;
            string Dept  = textBox5.Text;

            if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" || textBox4.Text.Trim() == "" || textBox5.Text.Trim() == "")
            {
                MessageBox.Show("请输入完整信息!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (textBox1.Text.Trim() == null || textBox2.Text.Trim() == null || textBox3.Text.Trim() == null || textBox4.Text.Trim() == null || textBox5.Text.Trim() == null)
            {
                MessageBox.Show("请输入完整信息!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            Student.StudentInfoData data = new Student.StudentInfoData();

            data.Sno   = Sno;
            data.Sname = Sname;
            data.Sex   = Sex;
            data.Grade = Grade;
            data.Dept  = Dept;

            try
            {
                if (FLAG == "")
                {
                    if (Student.StudentInfoOperation.insertStudentInfo(data))
                    {
                        MessageBox.Show("添加成功", "提示");
                        this.textBox1.Text = "";
                        this.textBox2.Text = "";
                        this.textBox3.Text = "";
                        this.textBox4.Text = "";
                        this.textBox5.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("添加失败", "提示");
                    }
                }
                else
                {
                    if (Student.StudentInfoOperation.updateStudentInfo(data))
                    {
                        MessageBox.Show("修改成功", "提示");
                    }
                    else
                    {
                        MessageBox.Show("修改失败", "提示");
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                MessageBox.Show("保存失败", "错误");
            }
        }
Ejemplo n.º 7
0
        private void button3_Click(object sender, EventArgs e)
        {
            int index = this.dataGridView1.CurrentRow.Index;

            if (index < 0)
            {
                MessageBox.Show("请选择要删除的记录!", "提示");
                return;
            }
            else
            {
                if (MessageBox.Show("确定要删除吗?", "删除后无法撤回", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    string sno = ds.Tables[0].Rows[index]["StudentNumber"].ToString();
                    try
                    {
                        if (Student.StudentInfoOperation.deleteStudentInfo(sno))
                        {
                            MessageBox.Show("删除成功!", "提示");
                            //binddatagrid
                            string Sno   = textBox1.Text.Trim();
                            string Sname = textBox2.Text;
                            string Sex   = textBox3.Text;
                            string Grade = textBox4.Text;
                            string Dept  = textBox7.Text;

                            Student.StudentInfoData data = new Student.StudentInfoData();


                            data.Sno   = Sno;
                            data.Sname = Sname;
                            data.Sex   = Sex;
                            data.Grade = Grade;
                            data.Dept  = Dept;

                            try
                            {
                                ds = Student.StudentInfoOperation.getStudentInfo(data);
                                this.dataGridView1.DataSource = ds.Tables[0];
                            }
                            catch (Exception ex)
                            {
                                ex.ToString();
                            }
                        }
                        else
                        {
                            MessageBox.Show("删除失败", "错误");
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                        MessageBox.Show("删除失败", "错误");
                    }
                    finally
                    {
                        Student_overview_Load(sender, e);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private void Student_overview_Load(object sender, EventArgs e)
 {
     Student.StudentInfoData data = new Student.StudentInfoData();
     ds = Student.StudentInfoOperation.getStudentInfo(data);
     this.dataGridView1.DataSource = ds.Tables[0];
 }