| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2654 人关注过本帖
标题:c#窗体应用程序 (信息的保存与查询)
只看楼主 加入收藏
李宇蕊
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-4-5
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
c#窗体应用程序 (信息的保存与查询)
我的构想是 1.姓名,学号,家庭住址任何一个都不能为空,如果有一个为空,那么程序终结。
           2.学号必须是12位数,如果不是那么出现一个提示框提示:学号应为12位数。
           3.按键盘上的esc键和窗体中的button3(即退出)都会实现退出程序;按键盘上的enter键和窗体中的button1(即保存)都会保存信息;
           按删除键会删除文档里的信息,但不会删除文档。
图片附件: 游客没有浏览图片的权限,请 登录注册

           4.按查询键,会出现一个提示框提示:请输入姓名进行查询;然后只在姓名一栏输入姓名再点击查询键
           即可进行查询,richtextbox中会显示出所查询学生的信息(必须是以前保存过的学生信息)。
           5.选中radiobutton,CheckBox,ComboBox,然后点击保存,也会实现保存爱好,性别,出生等信息。

目前 小菜只实现了1,2,3步;第4和第5尚未实现,恳请各位大神指教,先献上崇拜的目光,谢谢了!!!

小菜写的代码如下:


using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using
using System.Data.SqlClient;
using System.Configuration;

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length != 0 && textBox2.Text.Length != 0 && textBox3.Text.Length != 0)
            {
                FileStream message = File.Create("E:\\" + textBox1.Text + ".txt");
                StreamWriter text = new StreamWriter(message);

                text.WriteLine(textBox1.Text);
                text.WriteLine(textBox2.Text);
                if (textBox2.Text.Length != 12)
                {
                    MessageBox.Show("学号应为12位数");
                }

                text.WriteLine(textBox3.Text);
                text.Close();
                message.Close();
                MessageBox.Show("保存成功");
            }
            else
            {
                MessageBox.Show("出现错误,程序终结");
                Close();
            }
        }

        private void button1_KeyDown(object sender, KeyEventArgs e)
        {

            if (e.KeyCode == Keys.Enter)//如果输入的是回车键
            {
                this.button1_Click(sender, e);//触发button事件
            }



        }

        private void button2_Click(object sender, EventArgs e)
        {
            FileStream message = new FileStream("E:\\" + textBox1.Text + ".txt", FileMode.Create, FileAccess.Write);
            message.SetLength(0);
            MessageBox.Show("删除信息成功");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)//如果输入的是esc键
            {
                this.button3_Click(sender, e);//触发button事件
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            
        }
    }
}
搜索更多相关主题的帖子: 保存 Text using System sender 
2017-09-15 11:40
花间酒
Rank: 2
等 级:论坛游民
帖 子:13
专家分:24
注 册:2017-4-4
收藏
得分:20 
DirectoryInfo.GetFileSystemInfos 方法 ()
2017-09-16 10:36
快速回复:c#窗体应用程序 (信息的保存与查询)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016216 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved