读书日记系统
一、语言和环境
A、实现语言
C#
B、环境要求
Visual Studio 2012
二、功能要求
为方便老师对学生阅读的书籍进行记录,学校要求使用.Net WinForms技术开发一个读书日记管理系统,记录的信息包括阅读书籍的作者、书名、以及内容简要介绍,日记信息保存在文本文件中,添加读书日记的窗体界面如图-1所示:
图-1 读书日记窗体
保存的文本文件如图-2所示。
图-2 保存文本文件
要求
1、窗体标题为“读书日记”,窗体不允许最大化。
2、点击“保存”按钮后,将作者、书名、内容记录到文本文件中。
3、文件保存到D盘根目录中,以作者名保存文件。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace S2_02_内测 { public partial class FrmMain : Form { public FrmMain() { InitializeComponent(); } private void FrmMain_Load(object sender, EventArgs e) { } private void btnSave_Click(object sender, EventArgs e) { StreamWriter sw = null; try { string path = "D:"; FileStream fs = new FileStream(path, FileMode.Append); sw = new StreamWriter(fs); sw.WriteLine("作者:{0} 标题:{1} 内容:{2}", txtAuthor.Text, txtBookName.Text, txtContent.Text); MessageBox.Show("写入成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { sw.Close(); } } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } } }