📄 displaystudentdetails.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Text;
namespace ApplicationForm
{
/// <summary>
/// Summary description for DisplayDetails.
/// </summary>
public class DisplayStudentDetailsForm : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnFinish;
protected internal System.Windows.Forms.Label lblCourseTypeDetail;
protected internal System.Windows.Forms.Label lblCourseType;
protected internal System.Windows.Forms.Label lblCoursesDetail;
protected internal System.Windows.Forms.Label lblTelephoneDetail;
protected internal System.Windows.Forms.Label lblPerAddressDetail;
protected internal System.Windows.Forms.Label lblAddressDetail;
protected internal System.Windows.Forms.Label lblSexDetail;
protected internal System.Windows.Forms.Label lblNameDetails;
private System.Windows.Forms.Label lblSex;
private System.Windows.Forms.Label lblPerAddress;
private System.Windows.Forms.Label lblCourseSelected;
protected internal System.Windows.Forms.Label lblStdEnNo;
protected internal System.Windows.Forms.Label lblStdEnNoDetail;
private System.Windows.Forms.Label lblTelephone;
private System.Windows.Forms.Label lblAddress;
private System.Windows.Forms.Label lblName;
string [] split = null;
private int startIndex=0, endIndex=0;
int pages = 0, curpages=0;
private System.Windows.Forms.Button btnNext;
private System.Windows.Forms.Label lblRecords;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private FileStream fstream;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public DisplayStudentDetailsForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lblRecords = new System.Windows.Forms.Label();
this.lblCourseTypeDetail = new System.Windows.Forms.Label();
this.lblCourseType = new System.Windows.Forms.Label();
this.lblCoursesDetail = new System.Windows.Forms.Label();
this.lblTelephoneDetail = new System.Windows.Forms.Label();
this.lblPerAddressDetail = new System.Windows.Forms.Label();
this.lblAddressDetail = new System.Windows.Forms.Label();
this.lblSexDetail = new System.Windows.Forms.Label();
this.lblNameDetails = new System.Windows.Forms.Label();
this.lblSex = new System.Windows.Forms.Label();
this.lblPerAddress = new System.Windows.Forms.Label();
this.lblCourseSelected = new System.Windows.Forms.Label();
this.lblStdEnNo = new System.Windows.Forms.Label();
this.lblStdEnNoDetail = new System.Windows.Forms.Label();
this.lblTelephone = new System.Windows.Forms.Label();
this.lblAddress = new System.Windows.Forms.Label();
this.lblName = new System.Windows.Forms.Label();
this.btnFinish = new System.Windows.Forms.Button();
this.btnNext = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lblRecords);
this.groupBox1.Controls.Add(this.lblCourseTypeDetail);
this.groupBox1.Controls.Add(this.lblCourseType);
this.groupBox1.Controls.Add(this.lblCoursesDetail);
this.groupBox1.Controls.Add(this.lblTelephoneDetail);
this.groupBox1.Controls.Add(this.lblPerAddressDetail);
this.groupBox1.Controls.Add(this.lblAddressDetail);
this.groupBox1.Controls.Add(this.lblSexDetail);
this.groupBox1.Controls.Add(this.lblNameDetails);
this.groupBox1.Controls.Add(this.lblSex);
this.groupBox1.Controls.Add(this.lblPerAddress);
this.groupBox1.Controls.Add(this.lblCourseSelected);
this.groupBox1.Controls.Add(this.lblStdEnNo);
this.groupBox1.Controls.Add(this.lblStdEnNoDetail);
this.groupBox1.Controls.Add(this.lblTelephone);
this.groupBox1.Controls.Add(this.lblAddress);
this.groupBox1.Controls.Add(this.lblName);
this.groupBox1.Location = new System.Drawing.Point(10, 9);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(451, 517);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "学生详细信息";
//
// lblRecords
//
this.lblRecords.Location = new System.Drawing.Point(293, 491);
this.lblRecords.Name = "lblRecords";
this.lblRecords.Size = new System.Drawing.Size(120, 17);
this.lblRecords.TabIndex = 31;
this.lblRecords.Text = "记录:";
//
// lblCourseTypeDetail
//
this.lblCourseTypeDetail.Location = new System.Drawing.Point(161, 457);
this.lblCourseTypeDetail.Name = "lblCourseTypeDetail";
this.lblCourseTypeDetail.Size = new System.Drawing.Size(252, 24);
this.lblCourseTypeDetail.TabIndex = 28;
//
// lblCourseType
//
this.lblCourseType.Location = new System.Drawing.Point(19, 457);
this.lblCourseType.Name = "lblCourseType";
this.lblCourseType.Size = new System.Drawing.Size(96, 25);
this.lblCourseType.TabIndex = 27;
this.lblCourseType.Text = "课程类型:";
//
// lblCoursesDetail
//
this.lblCoursesDetail.Location = new System.Drawing.Point(161, 379);
this.lblCoursesDetail.Name = "lblCoursesDetail";
this.lblCoursesDetail.Size = new System.Drawing.Size(252, 69);
this.lblCoursesDetail.TabIndex = 24;
//
// lblTelephoneDetail
//
this.lblTelephoneDetail.Location = new System.Drawing.Point(161, 336);
this.lblTelephoneDetail.Name = "lblTelephoneDetail";
this.lblTelephoneDetail.Size = new System.Drawing.Size(252, 25);
this.lblTelephoneDetail.TabIndex = 23;
//
// lblPerAddressDetail
//
this.lblPerAddressDetail.Location = new System.Drawing.Point(161, 250);
this.lblPerAddressDetail.Name = "lblPerAddressDetail";
this.lblPerAddressDetail.Size = new System.Drawing.Size(252, 77);
this.lblPerAddressDetail.TabIndex = 21;
//
// lblAddressDetail
//
this.lblAddressDetail.Location = new System.Drawing.Point(161, 146);
this.lblAddressDetail.Name = "lblAddressDetail";
this.lblAddressDetail.Size = new System.Drawing.Size(252, 79);
this.lblAddressDetail.TabIndex = 18;
//
// lblSexDetail
//
this.lblSexDetail.Location = new System.Drawing.Point(163, 112);
this.lblSexDetail.Name = "lblSexDetail";
this.lblSexDetail.Size = new System.Drawing.Size(67, 25);
this.lblSexDetail.TabIndex = 16;
//
// lblNameDetails
//
this.lblNameDetails.Location = new System.Drawing.Point(163, 78);
this.lblNameDetails.Name = "lblNameDetails";
this.lblNameDetails.Size = new System.Drawing.Size(240, 24);
this.lblNameDetails.TabIndex = 15;
//
// lblSex
//
this.lblSex.Location = new System.Drawing.Point(19, 112);
this.lblSex.Name = "lblSex";
this.lblSex.Size = new System.Drawing.Size(66, 25);
this.lblSex.TabIndex = 25;
this.lblSex.Text = "性别:";
//
// lblPerAddress
//
this.lblPerAddress.Location = new System.Drawing.Point(19, 250);
this.lblPerAddress.Name = "lblPerAddress";
this.lblPerAddress.Size = new System.Drawing.Size(77, 34);
this.lblPerAddress.TabIndex = 20;
this.lblPerAddress.Text = "户籍地址:";
//
// lblCourseSelected
//
this.lblCourseSelected.Location = new System.Drawing.Point(19, 379);
this.lblCourseSelected.Name = "lblCourseSelected";
this.lblCourseSelected.Size = new System.Drawing.Size(87, 40);
this.lblCourseSelected.TabIndex = 26;
this.lblCourseSelected.Text = "已选择的课程:";
//
// lblStdEnNo
//
this.lblStdEnNo.Location = new System.Drawing.Point(19, 32);
this.lblStdEnNo.Name = "lblStdEnNo";
this.lblStdEnNo.Size = new System.Drawing.Size(96, 26);
this.lblStdEnNo.TabIndex = 30;
this.lblStdEnNo.Text = "注册编号:";
//
// lblStdEnNoDetail
//
this.lblStdEnNoDetail.Location = new System.Drawing.Point(164, 34);
this.lblStdEnNoDetail.Name = "lblStdEnNoDetail";
this.lblStdEnNoDetail.Size = new System.Drawing.Size(192, 25);
this.lblStdEnNoDetail.TabIndex = 29;
//
// lblTelephone
//
this.lblTelephone.Location = new System.Drawing.Point(19, 336);
this.lblTelephone.Name = "lblTelephone";
this.lblTelephone.Size = new System.Drawing.Size(77, 17);
this.lblTelephone.TabIndex = 22;
this.lblTelephone.Text = "电话:";
//
// lblAddress
//
this.lblAddress.Location = new System.Drawing.Point(19, 146);
this.lblAddress.Name = "lblAddress";
this.lblAddress.Size = new System.Drawing.Size(66, 25);
this.lblAddress.TabIndex = 19;
this.lblAddress.Text = "地址:";
//
// lblName
//
this.lblName.Location = new System.Drawing.Point(19, 78);
this.lblName.Name = "lblName";
this.lblName.Size = new System.Drawing.Size(66, 24);
this.lblName.TabIndex = 17;
this.lblName.Text = "姓名:";
//
// btnFinish
//
this.btnFinish.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnFinish.Location = new System.Drawing.Point(371, 801);
this.btnFinish.Name = "btnFinish";
this.btnFinish.Size = new System.Drawing.Size(90, 25);
this.btnFinish.TabIndex = 11;
this.btnFinish.Text = "&Finish";
//
// btnNext
//
this.btnNext.Location = new System.Drawing.Point(240, 801);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(115, 25);
this.btnNext.TabIndex = 12;
this.btnNext.Text = "&Next";
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(245, 538);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(115, 25);
this.button1.TabIndex = 33;
this.button1.Text = "下一步(&N)";
this.button1.Click += new System.EventHandler(this.btnNext_Click);
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(370, 538);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(90, 25);
this.button2.TabIndex = 32;
this.button2.Text = "完成(&F)";
//
// DisplayStudentDetailsForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(470, 573);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnFinish);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "DisplayStudentDetailsForm";
this.ShowInTaskbar = false;
this.Text = "显示详细信息";
this.Load += new System.EventHandler(this.DisplayStudentDetailsForm_Load);
this.Closed += new System.EventHandler(this.DisplayStudentDetailsForm_Closed);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnFinish_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void DisplayStudentDetailsForm_Load(object sender, System.EventArgs e)
{
// retrieve first record from the file c:\\Student.txt
// call DisplayRecords method to display data on the form
fstream = File.OpenRead("C:\\Student.txt");
long filesize = fstream.Length;
if(fstream.Length!=0)
{
//create a byte array to read the data
byte[] arr = new byte[filesize];
UTF8Encoding data = new UTF8Encoding(true);
//read the contents of the file into an array
fstream.Read(arr,0,arr.Length);
//split the array to retrieve individual field values
string text = data.GetString(arr);
string delim = " ";
char [] delimiter = delim.ToCharArray();
//split individual items of the records and store in into string array
split = text.Split(delimiter);
pages = split.Length/10; //10 belongs to no. of items per record
this.lblRecords.Text+= pages.ToString();
this.endIndex = this.DisplayRecords(split,0);
}
}
//Displays the details on the form
//takes splited array and starting index as input parameters
//returns last displayed item index
private int DisplayRecords(string [] spl, int startIndex)
{
int i=0;
curpages++;
if(curpages>pages)
{
MessageBox.Show("没有更多记录");
this.Close();
}
else
{
i= startIndex;
this.lblStdEnNoDetail.Text = split[i++];
this.lblNameDetails.Text = split[i++]+ " " + split[i++]+" "+split[i++];
split[i] = split[i].Replace(";"," ");
if(split[i] == "空")
split[i] = split[i].Replace("空"," ");
this.lblAddressDetail.Text = split[i++];
split[i] = split[i].Replace(";"," ");
if(split[i] == "空")
split[i] = split[i].Replace("空"," ");
this.lblPerAddressDetail.Text = split[i++];
this.lblSexDetail.Text = split[i++];
if(split[i] == "空")
split[i] = split[i].Replace("空"," ");
this.lblTelephoneDetail.Text = split[i++];
this.lblCourseTypeDetail.Text = split[i++];
split[i] = split[i].Replace(";","\n");
this.lblCoursesDetail.Text = split[i++];
i++;
if(curpages == pages)
{
this.btnNext.Enabled = false;
}
}
return i;
}
private void btnNext_Click(object sender, System.EventArgs e)
{
this.startIndex = this.endIndex;
this.endIndex = this.DisplayRecords(split,startIndex);
}
private void DisplayStudentDetailsForm_Closed(object sender, System.EventArgs e)
{
this.fstream.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -