您的位置:首页 > 其它

学生登记系统

2013-09-06 17:07 155 查看
学生登记系统的要求:

1)能够录入如下信息:学号,姓名,性别,手机号,家庭地址,报考系别,领取奖品,高考分数

2)能够根据姓名或者手机查询学生信息

3)能够查询奖品发放情况,如T恤发放多少件,U盘发放多少个,VIP充值卡发放多少张

4)能够更改学生信息(这在学生信息录入错误的情况下是有用的)

5)能够选择的就不要输入

利用winform和数据库编写程序

第一步:数据库以及表格的创建

create table information

(

     name varchar(32),

     Id   varchar(32) primary key,

     sex varchar(32),

     Mobile varchar(32),

     fasten varchar(32),

     award varchar(32),

     scord varchar(32),

     address varchar(32)

)

第二步: windows窗体中进行拖拽控件,进行编写码

1)建立三个窗体:第一个是:主窗体(父窗体)    第二个是:学生信息录入窗体(子窗体)   第三个是:学生信息查询、更改窗体(子窗体)

2)主窗体编写程序

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 xiangmu

{

    public partial class 学生登录系统 : Form

    {

        public 学生登录系统()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

        }

        private void 信息录入ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            信息录入 xinxi = new 信息录入();

            xinxi.Show();

            xinxi.MdiParent = this;

        }

        private void xiToolStripMenuItem_Click(object sender, EventArgs e)

        {

            信息查询 chaxun = new 信息查询();

            chaxun.Show();

            chaxun.MdiParent = this;

        }

    }

}

3)学生信息录入窗体编写程序

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;

using System.Data.SqlClient;

namespace xiangmu

{

    public partial class 信息录入 : Form

    {

        public 信息录入()

        {

            InitializeComponent();

        }

        private void 信息录入_Load(object sender, EventArgs e)

        {

            this.comboBox4.SelectedIndex = 0;

            this.comboBox5.SelectedIndex = 0;

        }

        private void button1_Click(object sender, EventArgs e)

        {

            string sql = "Data Source=(local);Initial Catalog=denglu;Integrated Security=True";

            SqlConnection conn = new SqlConnection(sql);

            conn.Open();

            SqlCommand comm = conn.CreateCommand();

            comm.CommandText = "insert into  information( name,Id, sex, Mobile,  fasten,  award,  scord,address) values(@name,@Id, @sex,@Mobile,@fasten,@award,@scord,@address)";

            comm.Parameters.AddWithValue("@name",textBox1.Text.ToString());

            comm.Parameters.AddWithValue("@Id",textBox2.Text.ToString());

            comm.Parameters.AddWithValue("@sex",comboBox6.Text.ToString());

            comm.Parameters.AddWithValue("@Mobile",textBox3.Text.ToString());

            comm.Parameters.AddWithValue("@fasten", comboBox4.Text.ToString());

            comm.Parameters.AddWithValue("@award",comboBox5.Text.ToString());

            comm.Parameters.AddWithValue("@scord",textBox4.Text.ToString());

            comm.Parameters.AddWithValue("@address", textBox5.Text.ToString());

            comm.ExecuteNonQuery();

            MessageBox.Show("录入成功");

            conn.Close();

            conn.Dispose();

            comm.Dispose();

            Console.Read();

        }

    }

}

4)学生信息查询以及更改以及奖品的查询编写程序

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;

using System.Data.SqlClient;

namespace xiangmu

{

    public partial class 信息查询 : Form

    {

        public 信息查询()

        {

            InitializeComponent();

        }

        private void label2_Click(object sender, EventArgs e)

        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)

        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)

        {

        }

        private void label5_Click(object sender, EventArgs e)

        {

        }

        private void label6_Click(object sender, EventArgs e)

        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)

        {

        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

        {

        }

        private void 信息查询_Load(object sender, EventArgs e)

        {

            this.comboBox1.SelectedIndex = 0;

            this.comboBox2.SelectedIndex = 0;

        }

        private void button1_Click(object sender, EventArgs e)

        {

            string sql = "Data Source=(local);Initial Catalog=denglu;Integrated Security=True";

            SqlConnection conn = new SqlConnection(sql);

            conn.Open();

            SqlCommand comm = conn.CreateCommand();

            string id = textBox1.Text;

            comm.CommandText = "select name, sex ,Mobile, fasten ,award ,scord ,address from information where
Id=@Id";

            comm.Parameters.AddWithValue("@Id", id);

            SqlDataAdapter adapter = new SqlDataAdapter(comm);

            DataTable data = new DataTable();

            adapter.Fill(data);

            for (int i = 0; i < data.Rows.Count; i++)

            {

                textBox2.Text = data.Rows[i][0].ToString();

                textBox6.Text = data.Rows[i][1].ToString();

                textBox3.Text = data.Rows[i][2].ToString();

                comboBox1.Text = data.Rows[i][3].ToString();

                comboBox2.Text = data.Rows[i][4].ToString();

                textBox4.Text = data.Rows[i][5].ToString();

                textBox5.Text = data.Rows[i][6].ToString();

            }

            conn.Close();

            conn.Dispose();

            comm.Dispose();

            MessageBox.Show("查询成功");

        }

        private void button2_Click(object sender, EventArgs e)

        {

            string sql = "Data Source=(local);Initial Catalog=denglu;Integrated Security=True";

            SqlConnection conn = new SqlConnection(sql);

            conn.Open();

            SqlCommand comm = conn.CreateCommand();

            comm.CommandText = "select *from information";

            SqlDataAdapter adapter = new SqlDataAdapter(comm);

            DataTable data = new DataTable();

            adapter.Fill(data);

            this.dataGridView1.DataSource = data;

            conn.Close();

            conn.Dispose();

            comm.Dispose();

        }

        private void button3_Click(object sender, EventArgs e)

        {

            string sql = "Data Source=(local);Initial Catalog=denglu;Integrated Security=True";

            SqlConnection conn = new SqlConnection(sql);

            conn.Open();

            SqlCommand comm = conn.CreateCommand();

            string id = textBox1.Text;

            comm.CommandText = "update information set 
name=@name, sex=@sex ,Mobile=@Mobile,
fasten=@fasten ,award=@award ,scord=@scord ,address=@address where Id=id";

            comm.Parameters.AddWithValue("@name", textBox2.Text.ToString());

            comm.Parameters.AddWithValue("@sex", textBox6.Text.ToString());

            comm.Parameters.AddWithValue("@Mobile", textBox3.Text.ToString());

            comm.Parameters.AddWithValue("@fasten", comboBox1.Text.ToString());

            comm.Parameters.AddWithValue("@award", comboBox2.Text.ToString());

            comm.Parameters.AddWithValue("@scord ", textBox4.Text.ToString());

            comm.Parameters.AddWithValue("@address", textBox5.Text.ToString());

            comm.ExecuteNonQuery();

            conn.Close();

            comm.Dispose();

            conn.Dispose();

            MessageBox.Show("更改成功");

        }

        private void button4_Click(object sender, EventArgs e)

        {

            string sql = "Data Source=(local);Initial Catalog=denglu;Integrated Security=True";

            SqlConnection conn = new SqlConnection(sql);

            conn.Open();

            SqlCommand comm = conn.CreateCommand();

            comm.CommandText = "select COUNT(Id) U盘 from information where
award=@award ";

            comm.Parameters.AddWithValue("@award", "U盘");

            SqlDataAdapter adapter = new SqlDataAdapter(comm);

            DataTable data = new DataTable();

            adapter.Fill(data);

            this.dataGridView1.DataSource = data;

            conn.Close();

            comm.Dispose();

            conn.Dispose();

        }

        private void button5_Click(object sender, EventArgs e)

        {

            string sql = "Data Source=(local);Initial Catalog=denglu;Integrated Security=True";

            SqlConnection conn = new SqlConnection(sql);

            conn.Open();

            SqlCommand comm = conn.CreateCommand();

            comm.CommandText = "select COUNT(Id) T恤 from information where
award=@award1 ";

            comm.Parameters.AddWithValue("@award1", "T恤");

            SqlDataAdapter adapter1 = new SqlDataAdapter(comm);

            DataTable data1 = new DataTable();

            adapter1.Fill(data1);

            this.dataGridView1.DataSource = data1;

            conn.Close();

            comm.Dispose();

            conn.Dispose();

        }

        private void button6_Click(object sender, EventArgs e)

        {

            string sql = "Data Source=(local);Initial Catalog=denglu;Integrated Security=True";

            SqlConnection conn = new SqlConnection(sql);

            conn.Open();

            SqlCommand comm = conn.CreateCommand();

            comm.CommandText = "select COUNT(Id) CSDNVIP充值卡 from information where
award=@award2";

            comm.Parameters.AddWithValue("@award2","CSDNVIP充值卡");

            SqlDataAdapter adapter2 = new SqlDataAdapter(comm);

            DataTable data2 = new DataTable();

            adapter2.Fill(data2);

            this.dataGridView1.DataSource = data2;

            conn.Close();

            comm.Dispose();

            conn.Dispose();

        }

    }

}

 

 

 

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  winform windows