Chủ Nhật, 30 tháng 8, 2015
Thứ Ba, 25 tháng 8, 2015
//lớp vé tàu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vetau
{
abstract public class vetau
{
protected string tenve;
protected string loaive;
protected string ngayph;
protected double giave;
public string TENVE
{
get {
return tenve;
}
set
{
tenve = value;
}
}
public string LOAIVE
{
get
{
return loaive;
}
set
{
loaive = value;
}
}
public string NGAYPH
{
get
{
return ngayph;
}
set
{
ngayph = value;
}
}
public double GIAVE
{
get
{
return giave;
}
set
{
giave = value;
}
}
public vetau(string ten,string loai,string ngay,double gia)
{
this.tenve = ten;
this.loaive = loai;
this.ngayph = ngay;
this.giave = gia;
}
abstract public double tinhtoan();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vetau
{
abstract public class vetau
{
protected string tenve;
protected string loaive;
protected string ngayph;
protected double giave;
public string TENVE
{
get {
return tenve;
}
set
{
tenve = value;
}
}
public string LOAIVE
{
get
{
return loaive;
}
set
{
loaive = value;
}
}
public string NGAYPH
{
get
{
return ngayph;
}
set
{
ngayph = value;
}
}
public double GIAVE
{
get
{
return giave;
}
set
{
giave = value;
}
}
public vetau(string ten,string loai,string ngay,double gia)
{
this.tenve = ten;
this.loaive = loai;
this.ngayph = ngay;
this.giave = gia;
}
abstract public double tinhtoan();
}
}
//lớp vé cứng kế thừa vé tàu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vetau
{
class VeCung:vetau
{
private int soluong;
public int SOLUONG
{
get
{
return soluong;
}
set
{
soluong = value;
}
}
public VeCung(string ten,string loai,string ngay,double gia,int sol):base(ten,loai,ngay,gia)
{
this.soluong = sol;
}
public override double tinhtoan()
{
if(soluong<=50)giave-=giave*0.02;
else giave-=giave*0.05;
return giave;
}
}
}
//lớp vé mềm kế thừa lớp vé
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vetau
{
class VeMem:vetau
{
private string loaighe;
public string LOAIGHE
{
get { return loaighe; }
set { loaighe = value; }
}
public VeMem(string ten,string loai,string ngay,double gia,string loaighe):base(ten,loai,ngay,gia)
{
this.loaighe = loaighe;
}
public override double tinhtoan()
{
if(loaighe=="1")giave-=giave*0.02;
else giave-=giave*0.04;
return giave;
}
}
}
//form main
code view
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 vetau
{
public partial class Form1 : Form
{
private bool kt()
{
txtSoLuong.Enabled = true;
txtLoai.Enabled =false;
return true;
}
public Form1()
{
InitializeComponent();
}
VeMem vm = null;
VeCung vc = null;
string tenv;
string loaiv;
string ngaypv;
int solv;
double giav;
string loaighev;
public string LOAIGHEV
{
get
{
return loaighev ;
}
}
public string TENV
{
get
{
return tenv;
}
}
public int SOLCV
{
get
{
return solv;
}
}
public string LOAIV
{
get
{
return loaiv ;
}
}
string NGAYPHV
{
get
{
return ngaypv ;
}
}
public double GIAV
{
get
{
return
giav ;
}
}
private void Form1_Load(object sender, EventArgs e)
{
txtTenVe.Focus();
}
private void btnSaVe_Click(object sender, EventArgs e)
{
btnIn.Enabled = true;
try
{
if (txtTenVe.Text == "")
MessageBox.Show("Không Được Để Trống", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
string ten = txtTenVe.Text.Trim();
if (txtLoaiVe.Text == "")
MessageBox.Show("Không Được Để Trống", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
string loai = txtLoaiVe.Text.Trim();
string ngay = dpicNgayph.Value.ToShortDateString();
if (txtGia.Text ==null)
MessageBox.Show("Không Được Để Trống", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
double gia = double.Parse(txtGia.Text.Trim());
int soluong = int.Parse(txtSoLuong.Text.Trim());
string loaighe = txtLoai.Text.ToString();
if(rdVeCung.Checked==true)
{
vc = new VeCung(ten, loai, ngay, gia, soluong);
giav = vc.tinhtoan();
tenv = vc.TENVE;
solv = vc.SOLUONG;
loaiv=vc.LOAIVE;
ngaypv=vc.NGAYPH;
}
if(rdVeMem.Checked==true)
{
vm = new VeMem(ten, loai, ngay, gia, loaighe);
giav = vm.tinhtoan();
tenv = vm.TENVE;
loaiv = vm.LOAIVE;
ngaypv = vm.NGAYPH;
loaighev = vm.LOAIGHE;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnIn_Click(object sender, EventArgs e)
{
if (txtSoLuong.Text == null)
MessageBox.Show("Không Được Để Trống", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (txtLoai.Text == null)
MessageBox.Show("Không Được Để Trống", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
if(rdVeCung.Checked==true)
{
VeC vec = new VeC();
vec.TENVC = TENV;
vec.LOAIC = LOAIV;
vec.NGAYPHC = NGAYPHV;
vec.GIAVC =GIAV;
vec.SOLC = SOLCV;
vec.Show();
}
if(rdVeMem.Checked==true)
{
VeM vem = new VeM();
vem.TENVM = TENV;
vem.LOAIM = LOAIV;
vem.NGAYPHM = NGAYPHV;
vem.GIAVM = GIAV;
vem.LOAIGM
= LOAIGHEV;
vem.Show();
}
}
private void rdVeCung_CheckedChanged(object sender, EventArgs e)
{
if (rdVeCung.Checked == true) txtSoLuong.Enabled = true;
}
private void rdVeMem_CheckedChanged(object sender, EventArgs e)
{
if (rdVeMem.Checked == true) txtLoai.Enabled = true;
}
private void txtGia_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar < 48 || e.KeyChar > 58)
MessageBox.Show("Bạn không Được nhập chữ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
//code form ve cung
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 vetau
{
public partial class VeC : Form
{
string tenvC;
string loaiC;
string ngaypC;
int solC;
double giaC;
public string TENVC
{
set
{
tenvC = value;
}
}
public int SOLC
{
set
{
solC = value;
}
}
public string LOAIC
{
set
{
loaiC = value;
}
}
public string NGAYPHC
{
set
{
ngaypC = value;
}
}
public double GIAVC
{
set
{
giaC = value;
}
}
public VeC()
{
InitializeComponent();
}
private void VeC_Load(object sender, EventArgs e)
{
lblTeVeCung.Text += tenvC;
lblLoaVeCung.Text += loaiC;
lblNamphCung.Text += ngaypC;
lblSolCung.Text += solC;
lblGiaVeCung.Text =lblGiaVeCung.Text+ giaC+"VND";
}
}
}
//code form ve mem
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 vetau
{
public partial class VeC : Form
{
string tenvC;
string loaiC;
string ngaypC;
int solC;
double giaC;
public string TENVC
{
set
{
tenvC = value;
}
}
public int SOLC
{
set
{
solC = value;
}
}
public string LOAIC
{
set
{
loaiC = value;
}
}
public string NGAYPHC
{
set
{
ngaypC = value;
}
}
public double GIAVC
{
set
{
giaC = value;
}
}
public VeC()
{
InitializeComponent();
}
private void VeC_Load(object sender, EventArgs e)
{
lblTeVeCung.Text += tenvC;
lblLoaVeCung.Text += loaiC;
lblNamphCung.Text += ngaypC;
lblSolCung.Text += solC;
lblGiaVeCung.Text =lblGiaVeCung.Text+ giaC+"VND";
}
}
}
Đăng ký:
Bài đăng (Atom)