境外人员来访信息管理系统(C#)

用windows窗体应用程序做一个简单的
“境外人员来访信息管理系统”。它主要可以实现的功能:对来访人员进行国籍,姓名,性别,手机号,出生日期等信息开始统计,并保存到已有的文件中,在另外的一个窗口可以查看已存的人员的信息,并在另一个窗口进行显示。(可以根据自己的喜欢调整窗口的颜色和大小)

插上图片:

在这里插入图片描述
在这里插入图片描述

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 WindowsFormsApplication1
{
    
    
    public partial class Form1 : Form
    {
    
    
        string[] stuinf;
        int num = 0;
        int stuindex = 0;//已存信息的下标
        int delnum = 0;//欲删除的的信息计数
        public Form1()
        {
    
    
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
    
    
            stuinf = new string[100];
            this.cboGender.SelectedIndex = 0;
            string[] stuinfsaved = System.IO.File.ReadAllLines("stu.txt");//信息存在文件
            for (int i = 0; i < stuinfsaved.Length; i++)
            {
    
    
                stuinf[i] = stuinfsaved[i];
                num++;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
    
    
            if (this.txtChain.Text.Trim() == "")//输入信息要无空格;
            {
    
    
                MessageBox.Show("您好,来访人员国籍是不能为空!");
                return;
            }
            if (this.txtName.Text.Trim() == "")
            {
    
    
                MessageBox.Show("您好,来访人员姓名是不能为空!");
                return;
            }
            if (this.dtpBirthday.Text.Trim() == "")
            {
    
    
                MessageBox.Show("您好,来访人员出生日期是不能为空!");
                return;
            }
            if (this.txtPhone.Text.Trim() == "")
            {
    
    
                MessageBox.Show("您好,来访人员手机号码是不能为空!");
                return;
            }
            if (this.txtTag.Text.Trim() == "")
            {
    
    
                MessageBox.Show("您好,请输入来访人员的位号!");
                return;
            }
            string info;
            info ="人员位号:"+this.txtTag.Text+";"+"人员国籍:" + this.txtChain.Text + ";" +"人员姓名:" + this.txtName.Text + ";" + "人员性别:"+this.cboGender.Text + ";" +"出生日期:"+ this.dtpBirthday.Text + ";"
               +"电话号码:"+ this.txtPhone.Text;
            stuinf[num] = info;
            num++;
            MessageBox.Show("录入成功!");
            this.txtName.Text = "";
            this.txtPhone.Text = "";
            this.txtChain.Text = "";
            this.cboGender.SelectedIndex = 0;

        }

        private void button1_Click(object sender, EventArgs e)
        {
    
    
            string[] stuData = new string[num - delnum];
            for (int i = 0,k=0; i < num; i++)//将信息删除后重新有顺序的记录在数组中
            {
    
    
                if (stuinf[i][0] != '*')
                {
    
    
                    stuData[k] = stuinf[i];
                    k++;
                }
            }
            System.IO.File.WriteAllLines("stu.txt", stuData, Encoding.Unicode);
            this.Close();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
    
    
            this.txtName.Text = "";
            this.txtPhone.Text = "";
            this.txtChain.Text = "";
            this.cboGender.SelectedIndex = 0;
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
    
    
            if (this.tabControl1.SelectedIndex == 1)  //进入学生信息显示界面
            {
    
    
                this.txtStuinf.Lines = stuinf[0].Split(';');
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
    
    
           // stuindex++;
           do
           {
    
    
            stuindex = (stuindex + 1) % num;
           } while (stuinf[stuindex][0]=='*');
          this.txtStuinf.Lines = stuinf[stuindex].Split(';');
        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {
    
    

        }

        private void txtStuid_TextChanged(object sender, EventArgs e)
        {
    
    

        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
    
    
            stuinf[stuindex] = "*" + stuinf[stuindex];//用“*”记录要删除的相关人员的信息
            MessageBox.Show("删除成功!");
            delnum++;
            do
           {
    
    
                 stuindex = (stuindex + 1) % num;
           } while (stuinf[stuindex][0]=='*');
            this.txtStuinf.Lines = stuinf[stuindex].Split(';');
        }

        private void button2_Click(object sender, EventArgs e)
        {
    
    
            if (stuindex == 0)
                stuindex = num;
            stuindex = (stuindex -1) % num;
            this.txtStuinf.Lines = stuinf[stuindex].Split(';');
        }

        private void txtStuinf_TextChanged(object sender, EventArgs e)
        {
    
    

        }

        private void txtTag_TextChanged(object sender, EventArgs e)
        {
    
    

        }

        
    }
}

小萌新刚刚学习C#,就已经被其强大的功能所振服~~~

猜你喜欢

转载自blog.csdn.net/cuijunrongaa/article/details/107226361
今日推荐