First of all, let's take a look at the requirements: what we want to do is show the employee information and realize the project manager's ability to score the staff!
First of all, the project manager is a scoring person so no use, because we write ourselves, the score is our own. So what we're going to do is build a project in VS, our environment, construct a Windows Forms application, and then drag the controls!
On the left is the View information form for the employee, and the right is the form for the employee rating;
1. We now start the Code section
We need an auxiliary class first, what are we going to do in the helper class? We're going to write these things.
public int id;
public int age;
public string name;
public char sex;
public int popularitymoods;
public int score;
public string appraise;
These things are some public fields!
Then initialize an array of objects
public static se[] SE = new SE[10];
Initialization of two employee information for testing purposes
public static void Insert ()
{
Se s1 = new SE ();
S1.id = 111;
S1.age = 26;
S1.name = "Wang Xiao";
S1.appraise = "not evaluated";
S1.score = 0;
Se.se[0] = S1;
se s2 = new SE ();
s2.id = 112;
s2.age = 22;
s2.name = "Zhou Xinyu";
s2.appraise = "not evaluated";
s2.score = 0;
se.se[1] = s2;
Se s3 = new SE ();
S3.id = 113;
S3.age = 30;
S3.name = "Zhang Ye";
S3.appraise = "not evaluated";
S3.score = 0;
SE.SE[2] = S3;
}
Initializing the good data is really starting to work, and we're going to write such a piece of code in the Employee Information Form Loal event.
private void Frmfirst_load (object sender, EventArgs e)
{
if (se.se[0] = = NULL) This is the judgment array is empty to insert data
{
SE. Insert (); Method of invoking initialization data
}
LvList.Items.Clear (); Clears all items in the ListView
Iterate over the object data, and if not empty, give the data of the object array to Lvlist, so that all the data of the Lvlist real object array
for (int i = 0; i < SE.se.Length; i++)
{
if (se.se[i]! = NULL)
{
ListViewItem item = new ListViewItem (se.se[i].id. ToString ());
Item. SubItems.Add (Se.se[i].name);
Item. SubItems.Add (se.se[i].age. ToString ());
Item. SubItems.Add (se.se[i].appraise);
Item. SubItems.Add (Se.se[i].score. ToString ());
LVLIST.ITEMS.ADD (item);
}
}
}
Then double-click the lvlist item to call the employee scoring form
private void Lvlist_doubleclick (object sender, EventArgs e) This is a double-click event for Lvlist
{
This involves the transfer of the value of the form, I passed three values, can actually pass a value. Because it is the employee's evaluation of the manager.
Frmjudge FJ = new Frmjudge ();
Fj.name = Lvlist.items[0]. SUBITEMS[1]. Text;
Fj.appraise = Lvlist.items[0]. SUBITEMS[3]. Text;
Fj.score = Lvlist.items[0]. SUBITEMS[4]. Text;
This. Hide ();
Fj. Show ();
}
Then receive the passed value in the employee scoring form, with three public variables.
public string name;
public string appraise;
public string score;
These three have been built before the public variable, otherwise it is impossible. Come out!
We're going to use the TextBox on the form to receive the passed value so that he can see the displayed value as soon as he opens the form.
So the Load event assigns the value to the textbox
private void Frmjudge_load (object sender, EventArgs e)
{
Txt1. text= name;
Txt2. Text = appraise;
Txt3. Text=score;
}
This is the code I wrote on the Cancel button
private void Btn2_click (object sender, EventArgs e)
{
Frmshow fs = new Frmshow ();
This. Hide ();
Fs. Show ();
}
This means that as soon as I click Cancel, the Employee information form is called and the employee scoring form is hidden!
The added button is to have him modify a piece of data in the object array. Then appear in the Employee Information form!
private void Btn1_click (object sender, EventArgs e)
{
for (int i = 0; i < SE.se.Length; i++) iterates over the array
& nbsp; {
if (se.se[i]!=null) if the array is not empty
{
if (se.se[i].name = = Txt1. Text) and the elements within the array are equal to my txt1d textbox
{
I'll change his rating and score to the data I added in the text box
se.se[i].appraise = Txt2. Text;
Se.se[i].score = Convert.ToInt32 (txt3. Text);
}
}
}
Finally I'm calling the employee information form and my data will reload! will be updated in time!
Frmshow fs = new Frmshow ();
This. Hide ();
Fs. Show ();
WinForm form a small project with an array of objects