📄 displayemployeedetails.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 DisplayEmployeeDetailsForm : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnFinish;
protected internal System.Windows.Forms.Label lblCourseWorkDetail;
private System.Windows.Forms.Label lblEmpID;
private System.Windows.Forms.Label lblSex;
protected internal System.Windows.Forms.Label lblTelephoneDetail;
private System.Windows.Forms.Label lblTelephone;
protected internal System.Windows.Forms.Label lblPerAddressDetail;
protected internal System.Windows.Forms.Label label1;
protected internal System.Windows.Forms.Label lblAddressDetail;
protected internal System.Windows.Forms.Label lblEmpStatusDetail;
protected internal System.Windows.Forms.Label lblEmpDesg;
protected internal System.Windows.Forms.Label lblEmployeeDesignation;
protected internal System.Windows.Forms.Label lblCourseWorkload;
protected internal System.Windows.Forms.Label lblSexDetail;
private System.Windows.Forms.Label lblPerAddress;
private System.Windows.Forms.Label lblAddress;
private System.Windows.Forms.Label lblName;
protected internal System.Windows.Forms.Label lblEmployeeIDDetail;
protected internal System.Windows.Forms.Label lblNameDetails;
private FileStream fstream;
string [] split = null;
private int startIndex=0, endIndex=0;
int pages = 0, curpages=0;
private System.Windows.Forms.Label lblRecords;
private System.Windows.Forms.Button btnNext;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public DisplayEmployeeDetailsForm()
{
//
// 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.lblCourseWorkDetail = new System.Windows.Forms.Label();
this.lblEmpID = new System.Windows.Forms.Label();
this.lblSex = new System.Windows.Forms.Label();
this.lblTelephoneDetail = new System.Windows.Forms.Label();
this.lblTelephone = new System.Windows.Forms.Label();
this.lblPerAddressDetail = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.lblAddressDetail = new System.Windows.Forms.Label();
this.lblEmpStatusDetail = new System.Windows.Forms.Label();
this.lblEmpDesg = new System.Windows.Forms.Label();
this.lblEmployeeDesignation = new System.Windows.Forms.Label();
this.lblCourseWorkload = new System.Windows.Forms.Label();
this.lblSexDetail = new System.Windows.Forms.Label();
this.lblPerAddress = new System.Windows.Forms.Label();
this.lblAddress = new System.Windows.Forms.Label();
this.lblName = new System.Windows.Forms.Label();
this.lblEmployeeIDDetail = new System.Windows.Forms.Label();
this.lblNameDetails = new System.Windows.Forms.Label();
this.lblRecords = new System.Windows.Forms.Label();
this.btnFinish = new System.Windows.Forms.Button();
this.btnNext = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lblCourseWorkDetail);
this.groupBox1.Controls.Add(this.lblEmpID);
this.groupBox1.Controls.Add(this.lblSex);
this.groupBox1.Controls.Add(this.lblTelephoneDetail);
this.groupBox1.Controls.Add(this.lblTelephone);
this.groupBox1.Controls.Add(this.lblPerAddressDetail);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.lblAddressDetail);
this.groupBox1.Controls.Add(this.lblEmpStatusDetail);
this.groupBox1.Controls.Add(this.lblEmpDesg);
this.groupBox1.Controls.Add(this.lblEmployeeDesignation);
this.groupBox1.Controls.Add(this.lblCourseWorkload);
this.groupBox1.Controls.Add(this.lblSexDetail);
this.groupBox1.Controls.Add(this.lblPerAddress);
this.groupBox1.Controls.Add(this.lblAddress);
this.groupBox1.Controls.Add(this.lblName);
this.groupBox1.Controls.Add(this.lblEmployeeIDDetail);
this.groupBox1.Controls.Add(this.lblNameDetails);
this.groupBox1.Controls.Add(this.lblRecords);
this.groupBox1.Location = new System.Drawing.Point(10, 9);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(470, 585);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "职员详细信息";
//
// lblCourseWorkDetail
//
this.lblCourseWorkDetail.Location = new System.Drawing.Point(206, 458);
this.lblCourseWorkDetail.Name = "lblCourseWorkDetail";
this.lblCourseWorkDetail.Size = new System.Drawing.Size(255, 64);
this.lblCourseWorkDetail.TabIndex = 28;
//
// lblEmpID
//
this.lblEmpID.Location = new System.Drawing.Point(19, 28);
this.lblEmpID.Name = "lblEmpID";
this.lblEmpID.Size = new System.Drawing.Size(96, 25);
this.lblEmpID.TabIndex = 31;
this.lblEmpID.Text = "职员编号:";
//
// lblSex
//
this.lblSex.Location = new System.Drawing.Point(19, 191);
this.lblSex.Name = "lblSex";
this.lblSex.Size = new System.Drawing.Size(66, 24);
this.lblSex.TabIndex = 27;
this.lblSex.Text = "性别:";
//
// lblTelephoneDetail
//
this.lblTelephoneDetail.Location = new System.Drawing.Point(206, 419);
this.lblTelephoneDetail.Name = "lblTelephoneDetail";
this.lblTelephoneDetail.Size = new System.Drawing.Size(221, 25);
this.lblTelephoneDetail.TabIndex = 26;
//
// lblTelephone
//
this.lblTelephone.Location = new System.Drawing.Point(19, 419);
this.lblTelephone.Name = "lblTelephone";
this.lblTelephone.Size = new System.Drawing.Size(77, 17);
this.lblTelephone.TabIndex = 25;
this.lblTelephone.Text = "电话:";
//
// lblPerAddressDetail
//
this.lblPerAddressDetail.Location = new System.Drawing.Point(206, 327);
this.lblPerAddressDetail.Name = "lblPerAddressDetail";
this.lblPerAddressDetail.Size = new System.Drawing.Size(252, 87);
this.lblPerAddressDetail.TabIndex = 24;
//
// label1
//
this.label1.Location = new System.Drawing.Point(19, 155);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(144, 17);
this.label1.TabIndex = 35;
this.label1.Text = "职员状态:";
//
// lblAddressDetail
//
this.lblAddressDetail.Location = new System.Drawing.Point(206, 233);
this.lblAddressDetail.Name = "lblAddressDetail";
this.lblAddressDetail.Size = new System.Drawing.Size(252, 86);
this.lblAddressDetail.TabIndex = 21;
//
// lblEmpStatusDetail
//
this.lblEmpStatusDetail.Location = new System.Drawing.Point(206, 155);
this.lblEmpStatusDetail.Name = "lblEmpStatusDetail";
this.lblEmpStatusDetail.Size = new System.Drawing.Size(154, 25);
this.lblEmpStatusDetail.TabIndex = 34;
//
// lblEmpDesg
//
this.lblEmpDesg.Location = new System.Drawing.Point(19, 121);
this.lblEmpDesg.Name = "lblEmpDesg";
this.lblEmpDesg.Size = new System.Drawing.Size(154, 17);
this.lblEmpDesg.TabIndex = 33;
this.lblEmpDesg.Text = "职员职称:";
//
// lblEmployeeDesignation
//
this.lblEmployeeDesignation.Location = new System.Drawing.Point(206, 121);
this.lblEmployeeDesignation.Name = "lblEmployeeDesignation";
this.lblEmployeeDesignation.Size = new System.Drawing.Size(154, 24);
this.lblEmployeeDesignation.TabIndex = 32;
//
// lblCourseWorkload
//
this.lblCourseWorkload.Location = new System.Drawing.Point(19, 458);
this.lblCourseWorkload.Name = "lblCourseWorkload";
this.lblCourseWorkload.Size = new System.Drawing.Size(135, 26);
this.lblCourseWorkload.TabIndex = 30;
this.lblCourseWorkload.Text = "已选择的课程:";
//
// lblSexDetail
//
this.lblSexDetail.Location = new System.Drawing.Point(206, 191);
this.lblSexDetail.Name = "lblSexDetail";
this.lblSexDetail.Size = new System.Drawing.Size(68, 24);
this.lblSexDetail.TabIndex = 19;
//
// lblPerAddress
//
this.lblPerAddress.Location = new System.Drawing.Point(19, 327);
this.lblPerAddress.Name = "lblPerAddress";
this.lblPerAddress.Size = new System.Drawing.Size(144, 23);
this.lblPerAddress.TabIndex = 23;
this.lblPerAddress.Text = "户籍地址:";
//
// lblAddress
//
this.lblAddress.Location = new System.Drawing.Point(19, 233);
this.lblAddress.Name = "lblAddress";
this.lblAddress.Size = new System.Drawing.Size(66, 24);
this.lblAddress.TabIndex = 22;
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 = 20;
this.lblName.Text = "名字:";
//
// lblEmployeeIDDetail
//
this.lblEmployeeIDDetail.Location = new System.Drawing.Point(206, 28);
this.lblEmployeeIDDetail.Name = "lblEmployeeIDDetail";
this.lblEmployeeIDDetail.Size = new System.Drawing.Size(154, 25);
this.lblEmployeeIDDetail.TabIndex = 29;
//
// lblNameDetails
//
this.lblNameDetails.Location = new System.Drawing.Point(206, 78);
this.lblNameDetails.Name = "lblNameDetails";
this.lblNameDetails.Size = new System.Drawing.Size(240, 24);
this.lblNameDetails.TabIndex = 18;
//
// lblRecords
//
this.lblRecords.Location = new System.Drawing.Point(341, 551);
this.lblRecords.Name = "lblRecords";
this.lblRecords.Size = new System.Drawing.Size(120, 18);
this.lblRecords.TabIndex = 32;
this.lblRecords.Text = "记录:";
//
// btnFinish
//
this.btnFinish.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnFinish.Location = new System.Drawing.Point(390, 613);
this.btnFinish.Name = "btnFinish";
this.btnFinish.Size = new System.Drawing.Size(90, 25);
this.btnFinish.TabIndex = 11;
this.btnFinish.Text = "完成(&F)";
this.btnFinish.Click += new System.EventHandler(this.btnFinish_Click);
//
// btnNext
//
this.btnNext.Location = new System.Drawing.Point(259, 613);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(115, 25);
this.btnNext.TabIndex = 12;
this.btnNext.Text = "下一步(&N)";
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// DisplayEmployeeDetailsForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(489, 645);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnFinish);
this.Controls.Add(this.groupBox1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "DisplayEmployeeDetailsForm";
this.ShowInTaskbar = false;
this.Text = "显示详细信息";
this.Load += new System.EventHandler(this.DisplayEmployeeDetailsForm_Load);
this.Closed += new System.EventHandler(this.DisplayEmployeeDetailsForm_Closed);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnFinish_Click(object sender, System.EventArgs e)
{
this.Close();
}
// retrieve first record from the file c:\\Employee.txt
// call DisplayRecords method to display data on the form
private void DisplayEmployeeDetailsForm_Load(object sender, System.EventArgs e)
{
this.btnNext.Focus();
fstream = File.OpenRead("C:\\Employee.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.lblEmployeeIDDetail.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++];
if(string.Compare(split[i].ToString(),"Clerk",false)==0)
this.lblCourseWorkload.Text = "已分配的工作量:";
else if(string.Compare(split[i].ToString(),"Professor",false)==0)
this.lblCourseWorkload.Text = "已分配的课程:";
this.lblEmployeeDesignation.Text = split[i++];
this.lblEmpStatusDetail.Text = split[i++];
split[i] = split[i].Replace(";","\n");
this.lblCourseWorkDetail.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 DisplayEmployeeDetailsForm_Closed(object sender, System.EventArgs e)
{
this.fstream.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -