Recently received such a project, require the use of C # to write manager scoring system, requirements, to display employee information, to achieve the project manager to the staff scoring function, today small part of the steps to introduce you, the needs of the friend reference
Write Requirements First:
01. Show Employee Information
02. Achieve the project manager's ability to score employees
The first step:
Build two classes, employee class and project manager class
Defining Properties and methods
Employee Category: Work number, age, name, popularity value, project manager annual rating, manager evaluation
Project Manager class: ID, age, name, gender, seniority, because the manager can score the employee, so there are scoring methods
First two pictures to say:
View Form Frmshow
Scoring Form Frmjudge
No, that's the code.
The first is the employee class
Using System.text;using System.threading.tasks;namespace Manager scoring System {public class SE { //Employee worker number public int Engineerid {get; set;} Employee ages public int Age {get; set;} Employee gender public char sex {get; set;} Employee Name Public string name {get; set;} Employee sentiment value Public int Popularvalue {get; set;} Manager Annual rating Public int Mscore {get; set;} Manager evaluates public string Assess {get; set;}} }
Then the manager class
Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Namespace Manager Rating System { class PM { //manager ID public int MId {get; set;} Manager age Public int mage{get; set;} Manager name Public string Mname {get; set;} Manager Gender Public Char msex{get; set;} Define the scoring method public void Judge (SE se,string assess,int score) { SE. Assess = Assess; Se. Mscore = score;}} }
Next, look at the code in the form
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using System.windows.forms;namespace Manager scoring System {public Partial class Frmshow:form {//define employee array public se[] Engineer=new se[3]; Public Frmshow () {InitializeComponent (); Init (); Initializes the SE Collection Information updateview (); }//Initialize employee information public void Init () {SE S1 = new SE (); S1. Engineerid = 111; S1. Age = 26; S1. Name = "Wang Xiao"; S1. Assess = "not evaluated"; S1. Mscore = 0; ENGINEER[0]=S1; SE s2 = new SE (); S2. Engineerid = 112; S2. age = 22; S2. Name = "Zhou Xinyu"; S2. Assess = "not evaluated"; S2. Mscore = 0; ENGINEER[1] = s2; Se s3 = new SE (); S3. Engineerid = 113; S3. Age = 30; S3. Name = "Zhang Ye"; S3. Assess = "not evaluated"; S3. Mscore = 0; ENGINEER[2] = S3; }//Bind data to the Lvassess on the ListView object public void Updateview () {LvasseSs. Items.clear ();//The data is refreshed after evaluation for (int i = 0; I < Engineer. length;i++) {ListViewItem item = new ListViewItem (); Binds the employee information to item in the ListView. Text = Engineer[i]. Engineerid.tostring (); Item. SubItems.Add (Engineer[i]. Name); Item. SubItems.Add (Engineer[i]. Age.tostring ()); Item. SubItems.Add (Engineer[i]. Mscore.tostring ()); Item. SubItems.Add (Engineer[i]. Assess); THIS.LVASSESS.ITEMS.ADD (item); }}//Double-click the ListView private void Lvassess_doubleclick (object sender, EventArgs e) {//Get the currently selected object if (this . lvassess.selecteditems.count==0) {return;//must first select a row} int index = 0; for (int i = 0; I < Engineer. length;i++) {if (Engineer[i]. Engineerid.tostring () ==this.lvassess.selecteditems[0]. Text.trim ()) {index = i; Break }}//Selected object rating Frmjudge frm = new Frmjudge (this,index); frm. Show (); } }}
Finally the code written in the manager scoring form
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using System.windows.forms;namespace Manager scoring System {public Partial class Frmjudge:form {//Save instance of parent form public frmshow myparent; The employee object to evaluate private SE se; Parameters: an instance of the parent form, the position of the employee being scored in the employee array, public Frmjudge (frmshow Fparent,int index) {InitializeComponent (); This.myparent = fparent; this.se = Myparent.engineer[index]; } private void Frmjudge_load (object sender, EventArgs e) {//form loaded, displaying information about the employee's name and score to be evaluated This.txtName.Text = SE . Name; This.txtPingJia.Text = se. Assess; This.txtPingFen.Text = se. Mscore.tostring (); }//Click the score button to respond to the event private void Btnpingfen_click (object sender, EventArgs e) {try {pm pm = new PM ( ); Pm. Judge (Se,this.txtpingjia.text.trim (), Int32.Parse (This.txtPingFen.Text.Trim ())); Refresh main form This.myParent.UpdateView (); This. Close (); } catch (Exception ex) {MessageBox.Show ("Score failed!") +ex. ToString ()); }} private void Btncancel_click (object sender, EventArgs e) {this. Close (); } }}