Thiết kế class Hóa Đơn đáp ứng yêu cầu xử lý của giao diện
Lớp HoaDon
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai02
{
class HoaDon
{
//properties
private String hoten;
private String diachi;
private String dienthoai;
private double giatien;
private double thue;
private bool muaxeden;
private static double sokhachhang=0;
private static double sokhachmuaxeden=0;
private static double doanhthu=0;
//get , set
public string Hoten
{
get { return hoten; }
set { hoten = value; }
}
public string Diachi
{
get { return diachi; }
set { diachi = value; }
}
public string Dienthoai
{
get { return dienthoai; }
set { dienthoai = value; }
}
public static double Sokhachhang
{
get { return sokhachhang; }
}
public static double Sokhachmuaxeden
{
get { return sokhachmuaxeden; }
}
public static double Doanhthu
{
get { return doanhthu; }
}
public double Giatien
{
get { return giatien; }
set { giatien = value; }
}
public double Thue
{
get { return giatien*0.1; }
set { thue = value; }
}
//constructors
public HoaDon()
{
sokhachhang = 0;
sokhachmuaxeden = 0;
doanhthu = 0;
}
public HoaDon(string hoten, string diachi, string dienthoai, double giatien, bool muaxeden)
{
this.hoten = hoten;
this.dienthoai = dienthoai;
this.diachi = diachi;
this.giatien = giatien;
this.muaxeden = muaxeden;
sokhachhang++;
if (muaxeden) sokhachmuaxeden++;
}
public double phuThu()
{
if(muaxeden)
{
return giatien*0.05;
}
return 0;
}
public double TinhThanhTien()
{
double thanhTien = this.phuThu() + this.Giatien + this.Thue;
doanhthu += thanhTien;
return thanhTien;
}
public double getTongKH()
{
return sokhachhang;
}
public double getKhMuaXeDen()
{
return sokhachmuaxeden;
}
public double TongDoanhThu()
{
return doanhthu;
}
}
}
Lớp Form1
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 Bai02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private HoaDon hd;
private void btnTinh_Click(object sender, EventArgs e)
{
bool muaxeden = rbnMauDen.Checked;
hd = new HoaDon(txtHoTen.Text,txtDiaChi.Text,txtDienThoai.Text,double.Parse(txtGiaTien.Text),muaxeden);
txtPhuThu.Text = hd.phuThu().ToString();
txtThue.Text = hd.Thue.ToString();
txtThanhTien.Text = hd.TinhThanhTien().ToString();
}
private void btnTiep_Click(object sender, EventArgs e)
{
txtHoTen.Clear();
txtDiaChi.Clear();
txtDienThoai.Clear();
txtGiaTien.Clear();
txtPhuThu.Clear();
txtThue.Clear();
txtThanhTien.Clear();
}
private void btnThongKe_Click(object sender, EventArgs e)
{
txtTongKH.Text = hd.getTongKH().ToString();
txtTongKHMuaXeDen.Text = hd.getKhMuaXeDen().ToString();
txtTongDoanhThu.Text = hd.TongDoanhThu().ToString();
}
private void btnKetThuc_Click(object sender, EventArgs e)
{
this.Close();
}
}
}