码迷,mamicode.com
首页 > 其他好文 > 详细

学生信息管理系统 (初级版)

时间:2016-07-03 00:27:35      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

form1

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 WindowsFormsApplication1.DataOperation;
using WindowsFormsApplication1.Model;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            ShuaXin();
        }



        public void ShuaXin()
        {
            listView1.Items.Clear();
            List<Student> data = new StudentData().SelectAll();

            foreach (Student s in data)
            {
                ListViewItem li = new ListViewItem();
                li.Text = s.Code;
                li.SubItems.Add(s.Name);
                li.SubItems.Add(s.Sex ? "" : "");
                li.SubItems.Add(s.Birthday.ToString("yyyy年MM月dd日"));
                li.SubItems[3].Tag = s.Birthday;

                li.SubItems.Add(s.Score.ToString("#.##"));

                listView1.Items.Add(li);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(this);
            f2.Owner = this;
            f2.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Student s = new Student();
            if (listView1.SelectedItems.Count != 1)
            {
                MessageBox.Show("只能选择一个学员进行修改!");
                return;
            }

            foreach (ListViewItem li in listView1.SelectedItems)
            {
                s.Code = li.Text;
                s.Name = li.SubItems[1].Text;
                if (li.SubItems[2].Text == "")
                {
                    s.Sex = true;
                }
                else
                {
                    s.Sex = false;
                }
                s.Birthday = Convert.ToDateTime(li.SubItems[3].Tag);
                s.Score = Convert.ToDecimal(li.SubItems[4].Text);
            }
            Form3 f3 = new Form3(s);
            f3.Owner = this;
            f3.Show();
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

    }
}

form2

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 WindowsFormsApplication1.DataOperation;
using WindowsFormsApplication1.Model;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        Form1 F1 = null;
        public Form2(Form1 f1)
        {
            InitializeComponent();

            label_Code.Text = new StudentData().ReturnCode();
            F1 = f1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // text =="" && text == null
            if (String.IsNullOrEmpty(textBox1.Text))
            {
                name_error.Text = "不能为空";
                return;
            }
            else
            {
                name_error.Text = "";
            }

            Student s = new Student();
            s.Code = label_Code.Text;
            s.Name = textBox1.Text;
            s.Sex = radioButton_Nan.Checked;
            s.Birthday = dateTimePicker1.Value;
            s.Score = Convert.ToDecimal(maskedTextBox1.Text);

            bool isok = new StudentData().Insert(s);
            if (isok)
            {
                MessageBox.Show("添加成功!");
                if (F1 != null)
                {
                    F1.ShuaXin();
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败!");
            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }
    }
}

form3

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 WindowsFormsApplication1.DataOperation;
using WindowsFormsApplication1.Model;

namespace WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        public Form3(Student s)
        {
            InitializeComponent();

            label_Code.Text = s.Code;
            textBox1.Text = s.Name;
            if (s.Sex)
            {
                radioButton_Nan.Checked = true;
            }
            else
            {
                radioButton_Nv.Checked = true;
            }
            dateTimePicker1.Value = s.Birthday;
            maskedTextBox1.Text = s.Score.ToString();

        }

        private void Form3_Load(object sender, EventArgs e)
        {

        }
    }
}

 

学生信息管理系统 (初级版)

标签:

原文地址:http://www.cnblogs.com/suiyuejinghao123/p/5636335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!