冲刺阶段 day 7

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了冲刺阶段 day 7相关的知识,希望对你有一定的参考价值。

项目进展:教师部分包括教师所属系别、工号、姓名、性别、电话、邮箱、地址。我们已经基本完成窗体的构建和代码编写。可以实现教师信息的增加查询。

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GengdanContactsMIS_WinForm
{
    public partial class TeacherFrm : Form
    {
        public TeacherFrm()
        {
            InitializeComponent();
            BindMajor();
            BindTeacher();
        }
        void BindMajor()
        {
            string sql = "select MajorId ,MajorName from Major";
            DB db = new DB();
            DataSet ds = db.GetDataSet(sql, "Major");
            cbMajor.DataSource = ds.Tables["Major"];
            cbMajor.DisplayMember = "MajorName";
            cbMajor.ValueMember = "MajorId";
            BindTeacher();
        }
        void BindTeacher()
        {
            string sql = "select TNo as 工号,TName as 姓名,MajorName as 专业,Sex as 性别,Phone as 电话,Email as 邮箱,Adress as 地址 from Teacher,Major where Teacher.MajorId=Major.MajorId";
            DB db = new DB();
            DataSet ds = db.GetDataSet(sql, "Teacher");
            dataGridView1.DataSource = ds.Tables["Teacher"];
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string sql = "insert into Teacher(TNo,TName,Sex,MajorId,Phone,Email,Adress)values(‘"
                 + txtTNo.Text + "‘,‘" + txtTName.Text + "‘,‘" + txtSex.Text + "‘," + cbMajor.SelectedValue + ",‘" + txtPhone.Text + "‘,‘" + txtEmail.Text + "‘,‘" + txtAdress.Text + "‘)";
            DB db = new DB();
            if (db.ExecuteSQL(sql))
                MessageBox.Show("教师增加成功");
            else
                MessageBox.Show("教师信息增加失败,请检查工号号是否已存在");
            BindTeacher();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string sql = "select TNo,TName,Sex,MajorName,Phone,Email,Adress from Major,Teacher where Major.MajorId=Teacher.MajorId and TName=‘" + txtTName.Text + "‘";
            DB db = new DB();
            DataSet ds = db.GetDataSet(sql, "a");
            dataGridView1.DataSource = ds.Tables["a"];
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void TeacherFrm_Load(object sender, EventArgs e)
        {

        }
    }
}

 

 

以上是关于冲刺阶段 day 7的主要内容,如果未能解决你的问题,请参考以下文章

冲刺阶段 day11

冲刺阶段 day 10

冲刺阶段 day12

冲刺阶段 day 9

软工网络15团队作业8——Beta阶段敏捷冲刺

Alpha版本冲刺阶段 - Day7 - 靠泊