//程式員類(員工類) amespace MyOffice { //程式員類(員工類) public class SE { // 工號 public string ID { get; set; } // 年齡 public int Age { get; set; } ///姓名 public str ...
//程式員類(員工類)
amespace MyOffice
{
//程式員類(員工類)
public class SE
{
// 工號
public string ID { get; set; }
// 年齡
public int Age { get; set; }
///姓名
public string Name { get; set; }
// 性別
public Gender Gender { get; set; }
// 人氣值
private int _popularity = 0;
public int Popularity
{
get { return _popularity; }
set { _popularity = value; }
}
// 經理年度評分
private int _score = 0;
public int Score
{
get { return _score; }
set { _score = value; }
}
// 經理評價
private String _assess = "未評價";
public String Assess
{
get { return _assess; }
set { _assess = value; }
}
//public string SayHi()
//{
// string message = string.Format("大家好,我是 {0}, 今年 {1}歲,工號是 {2},我的人氣值高達 {3}!",this.Name,this.Age,this.ID,this.Popularity);
// return message;
//}
}
}
// 項目經理類
class PM
{
// ID
private string _id;
public string ID
{
set { _id = value; }
get { return _id; }
}
// 年齡
private int _age;
public int Age
{
get { return _age; }
set
{
if (value >= 30 && value <= 100)
{
_age = value;
}
else
{
_age = 30;
}
}
}
//姓名
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
// 性別
private Gender _gender;
public Gender Gender
{
get { return _gender; }
set { _gender = value; }
}
//資歷
private int _yearOfExperience;
public int YearOfExperience
{
get { return _yearOfExperience; }
set { _yearOfExperience = value; }
}
// 問好
// <returns>問好的內容</returns>
public string SayHi()
{
string message;
message = string.Format(
"大家好,我是 {0} ,今年 {1} 歲,項目管理經驗 {2}年。",
this._name, this._age, this._yearOfExperience
);
return message;
}
// 項目經理評分
// <param name="se"></param>
public void Judge(SE se, String assess, int score)
{
se.Assess = assess;
se.Score = score;
}
}
}
//性別枚舉
public enum Gender
{
male,
female
}
}
//主窗體
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyOffice
{
public partial class FrmJudge : Form
{
private FrmShow myParent; //主窗體
private SE se; //被評分的員工對象
public FrmJudge(FrmShow fparent,int index)
{
InitializeComponent();
this.myParent = fparent;
this.se = myParent.engineers[index];
}
//載入時填充信息
private void FrmJudge_Load(object sender, EventArgs e)
{
this.txtName.Text = se.Name;
this.txtAssess.Text = se.Assess;
this.txtScore.Text = se.Score.ToString();
}
//評分響應事件
private void btnOK_Click(object sender, EventArgs e)
{
try
{
PM pm = new PM();
pm.Judge(se,this.txtAssess.Text.Trim(),Int32.Parse(this.txtScore.Text.Trim()));
this.myParent.UpdateView(); //刷新主窗體
this.Close();
}
catch (Exception ex)
{
MessageBox.Show("評分失敗!" + ex.ToString());
}
}
//取消按鈕
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.txtScore = new System.Windows.Forms.TextBox();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.txtAssess = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(17, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 12);
this.label1.TabIndex = 0;
this.label1.Text = "員工姓名";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(17, 70);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(53, 12);
this.label2.TabIndex = 1;
this.label2.Text = "填寫評價";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(17, 128);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(53, 12);
this.label3.TabIndex = 2;
this.label3.Text = "年度評分";
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(90, 21);
this.txtName.Name = "txtName";
this.txtName.ReadOnly = true;
this.txtName.Size = new System.Drawing.Size(212, 21);
this.txtName.TabIndex = 3;
//
// txtScore
//
this.txtScore.Location = new System.Drawing.Point(90, 120);
this.txtScore.Name = "txtScore";
this.txtScore.Size = new System.Drawing.Size(212, 21);
this.txtScore.TabIndex = 5;
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(90, 160);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 7;
this.btnOK.Text = "評分";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(171, 160);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 8;
this.btnCancel.Text = "取消";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// txtAssess
//
this.txtAssess.Location = new System.Drawing.Point(90, 61);
this.txtAssess.Multiline = true;
this.txtAssess.Name = "txtAssess";
this.txtAssess.Size = new System.Drawing.Size(217, 53);
this.txtAssess.TabIndex = 9;
//
// FrmJudge
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(319, 204);
this.Controls.Add(this.txtAssess);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.txtScore);
this.Controls.Add(this.txtName);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "FrmJudge";
this.Text = "評分";
this.Load += new System.EventHandler(this.FrmJudge_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.TextBox txtScore;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.TextBox txtAssess;
}
}
//員工集合信息
public partial class FrmShow : Form
{
public SE[] engineers = new SE[3]; //員工集合信息
public FrmShow()
{
InitializeComponent();
this.Init(); //初始化員工集合信息
this.UpdateView(); //刷新顯示
}
// 員工信息初始化
public void Init()
{
SE jack = new SE();
jack.Name = "王小毛";
jack.Age = 26;
jack.Gender = Gender.male;
jack.ID = "111";
SE joe = new SE();
joe.Name = "周新雨";
joe.Age = 22;
joe.Gender = Gender.female;
joe.ID = "112";
SE ema = new SE();
ema.Name = "張燁";
ema.Age = 30;
ema.Gender = Gender.male;
ema.ID = "113";
engineers[0] = jack;
engineers[1] = joe;
engineers[2] = ema;
}
// 刷新ListView顯示
public void UpdateView()
{
lvAssess.Items.Clear(); //清空信息
for (int i = 0; i < engineers.Length; i++)
{
ListViewItem item = new ListViewItem();
item.Text = engineers[i].ID;
item.SubItems.Add(engineers[i].Name); //設置姓名
item.SubItems.Add(engineers[i].Age.ToString()); //設置年齡
item.SubItems.Add(engineers[i].Score.ToString()); //設置評分
item.SubItems.Add(engineers[i].Assess); //設置評價
this.lvAssess.Items.Add(item); //添加項
}
}
//雙擊執行評分
//<param name="sender"></param>
// <param name="e"></param>
private void lvAssess_DoubleClick(object sender, EventArgs e)
{
//獲取當前選中的員工對象
if (this.lvAssess.SelectedItems.Count == 0)
{
return;
}
int index = 0;
for(int i = 0; i<engineers.Length;i++)
{
if (engineers[i].ID == this.lvAssess.SelectedItems[0].Text.Trim())
{
index = i;
break;
}
}
//對選中對象評分
FrmJudge frm = new FrmJudge(this,index);
frm.Show();
}
}
}
namespace MyOffice
{
partial class FrmShow
{
//Required designer variable.
private System.ComponentModel.IContainer components = null;
//Clean up any resources being used.
//<param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
// Required method for Designer support - do not modify
//the contents of this method with the code editor.
private void InitiaryalizeComponent()
{
this.lvAssess = new System.Windows.Forms.ListView();
this.cheaderName = new System.Windows.Forms.ColumnHeader();
this.cheaderID = new System.Windows.Forms.ColumnHeader();
this.cheaderAge = new System.Windows.Forms.ColumnHeader();
this.cheaderAsess = new System.Windows.Forms.ColumnHeader();
this.cheaderScore = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
//
// lvAssess
//
this.lvAssess.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.cheaderID,
this.cheaderName,
this.cheaderAge,
this.cheaderScore,
this.cheaderAsess});
this.lvAssess.FullRowSelect = true;
this.lvAssess.GridLines = true;
this.lvAssess.Location = new System.Drawing.Point(12, 12);
this.lvAssess.Name = "lvAssess";
this.lvAssess.Size = new System.Drawing.Size(453, 230);
this.lvAssess.TabIndex = 0;
this.lvAssess.UseCompatibleStateImageBehavior = false;
this.lvAssess.View = System.Windows.Forms.View.Details;
this.lvAssess.DoubleClick += new System.EventHandler(this.lvAssess_DoubleClick);
//
// cheaderName
//
this.cheaderName.Text = "姓名";
//
// cheaderID
//
this.cheaderID.Text = "工號";
//
// cheaderAge
//
this.cheaderAge.Text = "年齡";
//
// cheaderAsess
//
this.cheaderAsess.DisplayIndex = 3;
this.cheaderAsess.Text = "評價";
//
// cheaderScore
//
this.cheaderScore.DisplayIndex = 4;
this.cheaderScore.Text = "年度得分";
//
// FrmShow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(477, 254);
this.Controls.Add(this.lvAssess);
this.Name = "FrmShow";
this.Text = "查看評分";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListView lvAssess;
private System.Windows.Forms.ColumnHeader cheaderID;
private System.Windows.Forms.ColumnHeader cheaderName;
private System.Windows.Forms.ColumnHeader cheaderAge;
private System.Windows.Forms.ColumnHeader cheaderAsess;
private System.Windows.Forms.ColumnHeader cheaderScore;
}
}
// 應用程式的主入口點。
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmShow());
}
}