C # University Course (fifth edition) after class exercise 17.3 student Achievement Document

Source: Internet
Author: User

/*17.3
(Student achievement file) creates a program that saves students ' scores to one by one text files. This file should contain each student's name, ID number, course, and score information. The user should be allowed to manned the file and display its contents in a read-only text box mode. You should have the following format when displaying information:
lastnane,firstname:id# Class Grade
Some data samples are as follows:
Jones,bob:1 "Introduction to Computer Science" "A-"
Johnson,sarah:2 "Data Structures" "B +"
Smith,sam:3 "Data Structures" "C"
*/
Using System;
Using System.Windows.Forms;
Using System.IO;
Namespace Grades
{
public partial class Gradesform:form
{
Private StreamWriter output;
private StreamReader input;
private bool saved = false;
Public Gradesform ()
{
InitializeComponent ();
}
private void Alltextbox_textchanged (object sender, EventArgs e)
{

Enableenterbutton ();
}
private void Saveasbutton_click (object sender, EventArgs e)
{
DialogResult result;
String FileName;
using (SaveFileDialog chooser = new SaveFileDialog ())
{
result = Chooser. ShowDialog ();
FileName = Chooser. FileName;
}
if (result = = DialogResult.OK)
{
if (FileName = = string. Empty)
MessageBox.Show ("entered an invalid file name.",
"Invalid File name", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Else
{
Output = new StreamWriter (fileName);
saveasbutton.enabled = false;
Saved = true;
}
Enableenterbutton ();
}
}
private void Enableenterbutton ()
{
if (lasttextbox.text! = string. Empty &&
Firsttextbox.text! = string. Empty &&
Idtextbox.text! = string. Empty &&
Classtextbox.text! = string. Empty &&
Gradetextbox.text! = string. Empty && Saved)
Enterbutton.enabled = true;
Else
enterbutton.enabled = false;
}
private void Enterbutton_click (object sender, EventArgs e)
{
string last = Lasttextbox.text;
string first = Firsttextbox.text;
string id = idtextbox.text;
string className = Classtextbox.text;
string grade = Gradetextbox.text;
Output. WriteLine (last + "\ T" + first + "\ T" + ID +
"\ t" + ClassName + "\ T" + grade);
Statuslabel.text = "Entry saved";
Lasttextbox.clear ();
Firsttextbox.clear ();
Idtextbox.clear ();
Classtextbox.clear ();
Gradetextbox.clear ();
}
private void Loadbutton_click (object sender, EventArgs e)
{
if (output! = NULL)
{
Output. Close ();
output = null;
Statuslabel.text = "Closing file";
Saveasbutton.enabled = true;
Saved = false;
}
DialogResult result;
String FileName;
using (OpenFileDialog chooser = new OpenFileDialog ())
{
result = Chooser. ShowDialog ();
FileName = Chooser. FileName;
}
if (result = = DialogResult.OK)
{
if (FileName = = string. Empty)
MessageBox.Show ("Invalid file name", "Invalid file name",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Else
{
input = new StreamReader (fileName);
String entry = input. ReadLine ();
Gradestextbox.clear ();
while (entry! = NULL)
{
Gradestextbox.appendtext (Formatentry (entry) +
"\ r \ n");
Entry = input. ReadLine ();
}
Statuslabel.text = "File loaded";
}
}
}
private string Formatentry (String fromfile)
{
Char[] splitters = {' \ t '};
string[] data = fromfile.split (splitters);
string result = data[0] + "," + data[1] +
": \ T" + data[2] + "\ T" + data[3] + "\ T" + data[4];
return result;
}
}
}

C # University Course (fifth edition) after class exercise 17.3 student Achievement Document

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.