PDA

View Full Version : Giúp Đỡ Về Inheritance và Class



hao100
21-10-2010, 02:33
Mình có 3 Class như sau :
class ConNguoi ( Ten,HoDem,NgaySinh);
clas NhanVien : ConNguoi (Ma,PhongBan,HesoLuong,LongCoban )
clas TruongPhong : ....
và 1 Fomr chính để tính lương :
Nhưng ko hiểu sao khi tính luơng Hesoluong ko load từ Texbox Hệ số lương xuống được ,ngiã là lúc nào Hesoluong =0 .Mong mọi người giúp đỡ
Code :
public class ConNguoi
{
private string _ten;
private string _hoDem;
private DateTime _ngaysinh;

public string Ten
{
get { return _ten; }
set { _ten = value; }
}

public string HoDem
{
get { return _hoDem; }
set { _hoDem = value; }
}

public DateTime Ngaysinh
{
get { return _ngaysinh; }
set { _ngaysinh = value; }
}

public ConNguoi(string pTen,string pHoDem, DateTime pNgaySinh)
{
pTen = _ten;
pHoDem = _hoDem;
pNgaySinh = _ngaysinh;
}

}
//////////////////////////////
public class NhanVien :ConNguoi
{
private string _maNV;
private static decimal _luongCoBan;
private string _phongBan;
private float _heSoLuong;

public string MaNV
{
get { return _maNV; }
set { _maNV = value; }
}

public string PhongBan
{
get { return _phongBan; }
set { _phongBan = value; }
}

public float HeSoLuong
{
get { return _heSoLuong; }
set { _heSoLuong = value; }
}

public static decimal LuongCoBan
{
get { return NhanVien._luongCoBan; }
set { NhanVien._luongCoBan = value; }
}
public NhanVien(string pMaNV, string pTen, string pHoDem, DateTime pNgaySinh, string pPhongBan, float pHeSoLuong)
: base(pTen,pHoDem,pNgaySinh)
{
pMaNV = _maNV;
pPhongBan = _phongBan;
pHeSoLuong = _heSoLuong;
}

//TinhLuong :
public virtual decimal Luong()
{
decimal luong = (decimal)_heSoLuong * _luongCoBan;
return luong;
}
}
//////////////////////////////
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
NhanVien.LuongCoBan = 750000;
}
private void TinhLuong()
{
NhanVien nv= null;
if (cbTruongPhong.Checked)
{
nv = new TruongPhong(txtTen.Text, txtHoDem.Text, dtpNgaySinh.Value, txtMa.Text, cbxPhongBan.Text,
float.Parse(txtHsLuong.Text), float.Parse(txtPhuCap.Text));

}
else
{

nv = new NhanVien(txtMa.Text, txtTen.Text, txtHoDem.Text, dtpNgaySinh.Value, cbxPhongBan.Text,float.Parse(txtHsLuong.Text));

}

txtLuong.Text = nv.Luong().ToString();

}

private void TinhLuong_Click(object sender, EventArgs e)
{
TinhLuong();
}

private void cbTruongPhong_CheckedChanged_1(object sender, EventArgs e)
{
if (cbTruongPhong.Checked)
{
txtPhuCap.ReadOnly = false;

}
else
{
txtPhuCap.ReadOnly = true;
txtPhuCap.Text = "0";
}
}


}