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

lab9源码

时间:2015-06-10 13:51:54      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

Form.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StudentMangeSystem
{
    //用于保存个窗体采集的信息
    public  class Class1
    {
       
        public Form1 form1=null;
        public Form2 form2=null;
        public Form3 form3=null;
        public Form4 form4=null;
        public Form5 form5=null;
        
        
        string []form1S;
        public string[] Form1_S
        {
            get { return form1S;}
            set {form1S =value;}
        }
        string []form3S;
        public string[] Form3_S
        {
            get { return form3S; }
            set { form3S = value; }
        }
        string []form4S;
        public string[] Form4_S
        {
            get { return form4S; }
            set { form4S = value; }
        }
       
        
        public ListView listView;
        public PictureBox pictureBox;
        public CheckBox checkB1;
        public CheckBox checkB2;
        public CheckBox checkB3;
        public CheckBox checkB4;
    }
}

 Form2.cs

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 StudentMangeSystem
{
    public partial class Form2 : Form
    {
        private Class1 class1;                          //保存信息管理器

        public Form2(Class1 cl)
        {
            class1 = cl;
            class1.form2 = this;
            InitializeComponent();
        }


        //窗体加载事件
        private void Form2_Load(object sender, EventArgs e)
        {
            label1.Text = "前四人为考勤人员!";
            label2.Text = "姓名";
            label3.Text = "学号";
            label4.Text = "年龄";
            label5.Text = "性别";
            label6.Text = "籍贯";

            button1.Text = "<<back";
            button2.Text = "删除";
            button3.Text = "添加";
            button4.Text = "next>>";

            button4.Enabled = button2.Enabled = false;

     
            comboBox1.Items.AddRange(new String[10]{"18","19","20","21","22","23","24","25","26","27"});
            comboBox2.Items.AddRange(new String[2] { "男", "女" });
            comboBox3.Items.AddRange(new String[] { "北京市","天津市 ","上海市","重庆市","河北省","河南省","云南省","辽宁省",
            "黑龙江省","湖南省","安徽省","江苏省","浙江省","江西省"});
            comboBox1.Text = "20";
            comboBox2.Text = "男";
            comboBox3.Text = "浙江省";
            comboBox1.DropDownStyle = comboBox2.DropDownStyle = comboBox3.DropDownStyle = ComboBoxStyle.DropDownList;

            listView1.Columns.Add("姓名");
            listView1.Columns.Add("学号");
            listView1.Columns.Add("年龄");
            listView1.Columns.Add("性别");
            listView1.Columns.Add("籍贯");

            listView1.View = View.Details;
            listView1.GridLines = true;
           
        }


        //返回事件
        private void button1_Click(object sender, EventArgs e)
        {
            class1.form1.Show();
            this.Hide();
        }

        //删除事件
        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listView1.Items.Count; i++) {
                if (listView1.Items[i].Selected)
                {
                    listView1.Items.RemoveAt(i);
                }
            }

            if (listView1.Items.Count > 0)
            {
                button2.Enabled = button4.Enabled = true;
            }
            else
            {
                button2.Enabled = button4.Enabled = false;
            }
        }

        //添加事件
        private void button3_Click(object sender, EventArgs e)
        {

            if (textBox1.Text == "" | textBox2.Text == "" || comboBox1.Text == "" || comboBox2.Text == "" || comboBox3.Text == "") {
                MessageBox.Show("请填写完整信息");
                return;
            }
            
            foreach (ListViewItem lVI in listView1.Items) {
               if (lVI.SubItems[1].Text==textBox2.Text) { 
                    MessageBox.Show("该学生已存在");
                    return;
               }
            }
            
            ListViewItem listViewItem=new ListViewItem(textBox1.Text);
            listViewItem.SubItems.AddRange(new string[]{textBox2.Text,comboBox1.Text,comboBox2.Text,comboBox3.Text});    
            listView1.Items.Add(listViewItem);

            if (listView1.Items.Count > 0)
            {
                button2.Enabled = button4.Enabled = true;
            }
            else
            {
                button2.Enabled = button4.Enabled = false;
            }
        }

        //next事件
        private void button4_Click(object sender, EventArgs e)
        {
            class1.listView = listView1;
            if (class1.form3 == null)
            {
                Form3 f3 = new Form3(class1);
                f3.Show();
                this.Hide();
            }
            else {
                class1.form3.Show();
                this.Hide();
            }    
        }

        
        //学号输入验证事件
        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < ‘0‘ || e.KeyChar > ‘9‘) && e.KeyChar != 8)
            {
                e.Handled = true;
            } 
        }


    }
}

 Form3.cs

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 StudentMangeSystem
{
    public partial class Form3 : Form{
   
        private int imageIndex = 1;             //用于滚动图片

        private Class1 class1;
        public Form3(Class1 cl)
        {
            class1 = cl;
            class1.form3 = this;
            InitializeComponent();
        }

        //窗体加载事件
        private void Form3_Load(object sender, EventArgs e)
        {
            button1.Text = "添加";
            button2.Text = "下一张";
            button3.Text = "<<back";
            button4.Text = "next>>";

            label1.Text = "班徽:";
            label2.Text = "班歌:";
            label3.Text = "班训:";

            button4.Enabled = false;

          
            pictureBox1.Image = Image.FromFile(Application.StartupPath + @"\1.jpg");
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

            comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
            comboBox1.Items.AddRange(new String[] { "我们都是好孩子", "我相信", "光辉岁月", "年轻的战场", "最初的梦想" });
            comboBox1.Text = comboBox1.Items[0].ToString();

            richTextBox1.Font = new Font("楷体",18);
        }

        //下一张图片事件
        private void button2_Click(object sender, EventArgs e)
        {
            if(imageIndex==4){
                imageIndex=1;
            }
            else{
                 imageIndex++;
            }
           
            pictureBox1.Image=Image.FromFile(Application.StartupPath+"\\"+imageIndex.ToString()+".jpg");
        }

         //上传自定义图片
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog oFD = new OpenFileDialog();
            oFD.Filter = "图片文件|*.bmp;*.jpg;*.jpeg;*.gif;*.png";                 //只显示图片
            oFD.RestoreDirectory = true;
            oFD.FileName = "";
            if (oFD.ShowDialog() == DialogResult.OK)
            {
                Bitmap bm = new Bitmap(Image.FromFile(oFD.FileName));                //从文件对话框获得路径
                bm = new Bitmap(bm, this.pictureBox1.Width, pictureBox1.Height);
                pictureBox1.Image = bm;
            }
        }

        //返回
        private void button3_Click(object sender, EventArgs e)
        {
            class1.form2.Show();
            this.Hide();
        }

        //next
        private void button4_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image == null) {
                MessageBox.Show("请选择班徽");
                return;
            }
            if (richTextBox1.Text.Length == 0) {
                MessageBox.Show("请输入班训");
                return;
            }

            class1.Form3_S = new string[] { comboBox1.Text, richTextBox1.Text };
            class1.pictureBox = pictureBox1;
            
            if (class1.form4 == null)
            {
                Form4 f4 = new Form4(class1);
                f4.Show();
                this.Hide();
            }
            else {
                class1.form4.Show();
                this.Hide();
            }
            
        }

        //班训输入
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            if (richTextBox1.Text.Trim().Length > 0)
            {
                button4.Enabled = true;
            }
            else {
                button4.Enabled = true;
            }
        }
    }
}

 Form4.cs

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 StudentMangeSystem
{
    public partial class Form4 : Form
    {
        private Class1 class1;
        public Form4(Class1 cl)
        {
            
            InitializeComponent();
            class1 = cl;
            class1.form4 = this;
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            label1.Text = "自习时间:";
            label2.Text = "自习教室:";

            button1.Text = "<<back";
            button2.Text = "next>>";

            groupBox1.Text = "考勤人员:";

            comboBox1.DropDownStyle = comboBox2.DropDownStyle = ComboBoxStyle.DropDownList;
            comboBox1.Items.AddRange(new string[] { "周一、三、五晚6:30——9:00", "周二、四、六晚6:30——9:00" });
            comboBox2.Items.AddRange(new string[] { "7B312", "7A112", "6B321", "6B120", "7A123", "7Aj123" });
            comboBox1.Text = comboBox1.Items[0].ToString();
            comboBox2.Text = comboBox2.Items[0].ToString();

            for (int i = 0; i <= 3 && i < class1.listView.Items.Count; i++) {
                CheckBox checkbox = new CheckBox();
                checkbox.Top = i * 30+groupBox1.Top;
                checkbox.Checked = true;
                checkbox.Text = class1.listView.Items[i].Text;
                groupBox1.Controls.Add(checkbox);  
            }
        }

        //back
        private void button1_Click(object sender, EventArgs e)
        {
            class1.form3.Show();
            this.Hide();
        }

        //next
        private void button2_Click(object sender, EventArgs e)
        {
            
            class1.form4 = this;

            string temp = "";
            foreach (Control cl in groupBox1.Controls) {
                CheckBox x =  cl as CheckBox;
                if (x.Checked) {
                    temp+= x.Text+"\n";
                }
            }
            class1.Form4_S = new string[] { comboBox1.Text, comboBox2.Text,temp };

            Form5 f5 = new Form5(class1);
            f5.Show();
            this.Hide();
        }
    }
}

 Form5.cs

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 StudentMangeSystem
{
    public partial class Form5 : Form
    {
        private Class1 class1;
        public Form5(Class1 cl)
        {
            class1 = cl;
            InitializeComponent();

            richTextBox1.Text = "学院:" + class1.Form1_S[0] +
                "\n系:" + class1.Form1_S[1] +
                "\n年级:" + class1.Form1_S[2] +
                "\n入学时间"+class1.Form1_S[3]+
                "\n辅导员:" + class1.Form1_S[4] +
                "\n班主任:" + class1.Form1_S[5] +
                "\n\n\n\n\n班训:" + class1.Form3_S[1] +
                "\n班歌:" + class1.Form3_S[0] +
                "\n自习时间:" + class1.Form4_S[0] +
                "\n自习教室:" + class1.Form4_S[1] +
                "\n考勤员: "+class1.Form4_S[2];
            Font ft = new Font("楷体", 15);
            richTextBox1.Font = ft;

            class1.pictureBox.Left = richTextBox1.Width + richTextBox1.Left - class1.pictureBox.Width;
            class1.pictureBox.Top = richTextBox1.Top;
            richTextBox1.Controls.Add(class1.pictureBox);

            class1.listView.Top = richTextBox1.Height + richTextBox1.Top+50;
            class1.listView.Width = richTextBox1.Width;
            this.Controls.Add(class1.listView);
            

        }

        
    }
}

 

lab9源码

标签:

原文地址:http://www.cnblogs.com/2014fhj/p/4565658.html

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