汽车租屏系统

来源:互联网 发布:雏菊知乎 编辑:程序博客网 时间:2024/04/27 22:14

一:汽车类

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. public abstract  class Vehicle  
  2.   {  
  3.     public Vehicle() { }  
  4.     public Vehicle(string licenseNO,string name,string color,int yearOfService,double dailyRent)  
  5.     {  
  6.         this.licenseNO = licenseNO;  
  7.         this.name = name;  
  8.         this.color = color;  
  9.         this.yearOfService = yearOfService;a  
  10.         this.dailyRent = dailyRent;  
  11.     }  
  12.     //租用日期  
  13.       private int rentDate;  
  14.   
  15.       public int RentDate  
  16.       {  
  17.           get { return rentDate; }  
  18.           set { rentDate = value; }  
  19.       }  
  20.     //租用者  
  21.       private string rentUser;  
  22.   
  23.       public string RentUser  
  24.       {  
  25.           get { return rentUser; }  
  26.           set { rentUser = value; }  
  27.       }  
  28.     //日租金  
  29.       private double dailyRent;  
  30.   
  31.       public double DailyRent  
  32.       {  
  33.           get { return dailyRent; }  
  34.           set { dailyRent = value; }  
  35.       }  
  36.     //使用时间  
  37.       private int yearOfService;  
  38.   
  39.       public int YearOfService  
  40.       {  
  41.           get { return yearOfService; }  
  42.           set { yearOfService = value; }  
  43.       }  
  44.     //颜色  
  45.       private string color;  
  46.   
  47.       public string Color  
  48.       {  
  49.           get { return color; }  
  50.           set { color = value; }  
  51.       }  
  52.     //车名  
  53.       private string name;  
  54.   
  55.       public string Name  
  56.       {  
  57.           get { return name; }  
  58.           set { name = value; }  
  59.       }  
  60.     //车牌号  
  61.       private string licenseNO;  
  62.   
  63.       public string LicenseNO  
  64.       {  
  65.           get { return licenseNO; }  
  66.           set { licenseNO = value; }  
  67.       }  
  68.     //计算价格的方法  
  69.       public abstract double CalcPrice();  
  70.   }  


二:轿车类

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. public class Car:Vehicle  
  2.     {  
  3.        public Car(string licenseNO, string name, string color, int yearsOfService, double dailyRent)  
  4.            : base(licenseNO, name, color, yearsOfService, dailyRent)  
  5.        {  
  6.            ;  
  7.        }  
  8.        public override double CalcPrice()  
  9.        {  
  10.            double totalPrice = 0;  
  11.            double basicPrice = this.RentDate * this.DailyRent;  
  12.            if (this.RentDate <= 30)  
  13.            {  
  14.                totalPrice = basicPrice;  
  15.            }  
  16.            else  
  17.            {  
  18.                totalPrice = basicPrice + (this.RentDate - 30) * this.DailyRent * 0.1;  
  19.            }  
  20.            return totalPrice;  
  21.        }  
  22.     }  

三:卡车类

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. public class Truck:Vehicle  
  2.     {  
  3.        public Truck() { }  
  4.        public Truck(string licenseNO, string name, string color, int yearsOfService, double dailyRent, int load)  
  5.            : base(licenseNO, name, color, yearsOfService, dailyRent)  
  6.        {  
  7.            this.Load = load;  
  8.        }  
  9.        //载重量  
  10.         private int load;  
  11.   
  12.         public int Load  
  13.         {  
  14.             get { return load; }  
  15.             set { load = value; }  
  16.         }  
  17.        //卡车费用计算方法  
  18.         // 30天以内(含30)按日租金计算  
  19.         // 30天以上超出部分:每天,每吨(载重量)增加日租金10%  
  20.         public override double CalcPrice()  
  21.         {  
  22.             double totalPrice = 0;  
  23.             double basicPrice = RentDate * DailyRent;  
  24.             if (RentDate<=30)  
  25.             {  
  26.                 totalPrice = basicPrice;  
  27.             }  
  28.             else  
  29.             {  
  30.                 totalPrice = basicPrice + (RentDate - 30) * (DailyRent * 0.1)*load;  
  31.             }  
  32.             return totalPrice;  
  33.         }  
  34.     }  

四:汽车类型"工厂"
[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. public class VehicleFactory  
  2.     {  
  3.        public static Vehicle CreateVehicle(string licenseNO,string name,string color,int yearOfService,double dailyRent,int load,string type)  
  4.        {  
  5.            Vehicle vehicle = null;  
  6.            switch (type)  
  7.            {  
  8.                case "car":  
  9.                    vehicle = new Car(licenseNO, name, color, yearOfService, dailyRent);  
  10.                    break;  
  11.                case "truck":  
  12.                    vehicle = new Truck(licenseNO,name,color,yearOfService,dailyRent,load);  
  13.                    break;  
  14.                default:  
  15.                    break;  
  16.            }  
  17.            return vehicle;  
  18.        }  
  19.     }  

五:在主窗体加载汽车信息

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. public partial class Rent : Form  
  2.    {  
  3.        public Rent()  
  4.        {  
  5.            InitializeComponent();  
  6.        }  
  7.        //保存可租用车的集合(车辆名称,车辆对象)  
  8.        Dictionary<string, Vehicle> notRent;  
  9.        //保存已租用车辆的集合。  
  10.        Dictionary<string, Vehicle> alreadyRent;  
  11.        private void btnQueryRent_Click(object sender, EventArgs e)  
  12.        {  
  13.            //刷新  
  14.            MyRefresh(notRent, lvRent);  
  15.        }  
  16.        //构造出两辆小汽车,两辆卡车  
  17.        public void LoadData()  
  18.        {  
  19.            //实例化未出租字典类型的集合  
  20.            notRent = new Dictionary<string, Vehicle>();  
  21.            Car car = new Car("京R00544""奥迪A8""黑色", 3, 240);  
  22.            Truck truck = new Truck("京R44944""东风""蓝色", 3, 300, 20);  
  23.            notRent.Add(car.LicenseNO,car);  
  24.            notRent.Add(truck.LicenseNO,truck);  
  25.   
  26.            //实例化已出租字典类型的集合  
  27.            alreadyRent = new Dictionary<string, Vehicle>();  
  28.            //出租出去的车  
  29.            Car rentCar = new Car("粤A001""宝马318""白色", 3, 250);  
  30.            rentCar.RentUser = txtRenter.Text;  
  31.            Truck rentTruck = new Truck("粤A002""东风""蓝色", 3, 400, 30);  
  32.             
  33.            alreadyRent.Add(rentCar.LicenseNO, rentCar);  
  34.            alreadyRent.Add(rentTruck.LicenseNO,rentTruck);  
  35.        }  

六:绑定TreeView,刷新显示

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. public void MyRefresh(Dictionary<string,Vehicle> rnotrent, ListView lvshow)  
  2.        {  
  3.            lvshow.Items.Clear();  
  4.            foreach (Vehicle item in rnotrent.Values)  
  5.            {  
  6.                ListViewItem lvitem = new ListViewItem(item.LicenseNO);  
  7.                if (item is Car)  
  8.                {  
  9.                    lvitem.SubItems.Add(item.Name);  
  10.                    lvitem.SubItems.Add(item.Color);  
  11.                    lvitem.SubItems.Add(item.YearOfService.ToString());  
  12.                    lvitem.SubItems.Add(item.DailyRent.ToString());  
  13.                }  
  14.                if (item is Truck)  
  15.                {  
  16.                    lvitem.SubItems.Add(item.Name);  
  17.                    lvitem.SubItems.Add(item.Color);  
  18.                    lvitem.SubItems.Add(item.YearOfService.ToString());  
  19.                    lvitem.SubItems.Add(item.DailyRent.ToString());  
  20.                    lvitem.SubItems.Add(((Truck)item).Load.ToString());  
  21.                }  
  22.                lvshow.Items.Add(lvitem);  
  23.            }  
  24.        }  
[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. //刷新  
  2.        private void btnQueryReturn_Click(object sender, EventArgs e)  
  3.        {  
  4.            MyRefresh(alreadyRent,lvReturn);  
  5.        }  

七:租车

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. private void btnRent_Click(object sender, EventArgs e)  
  2.        {  
  3.            if (txtRenter.Text=="")  
  4.            {  
  5.                MessageBox.Show("请输入租车人名称");  
  6.                return;  
  7.            }  
  8.            //从可租车辆集合中移除车辆A  
  9.            //将A添加到已租车辆集合中  
  10.            if (lvRent.SelectedItems.Count>0)  
  11.            {  
  12.                string number = lvRent.SelectedItems[0].Text;  
  13.                Vehicle ve = notRent[number];  
  14.                notRent.Remove(number);  
  15.                MyRefresh(notRent,lvRent);  
  16.                alreadyRent.Add(number, ve);  
  17.                MessageBox.Show("租车成功!");  
  18.            }  
  19.             
  20.        }  

八:还车界面的结算

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. private void btnCompute_Click(object sender, EventArgs e)  
  2.        {  
  3.            if (txtRentDate.Text=="")  
  4.            {  
  5.                MessageBox.Show("请输入租车时间");  
  6.                return;  
  7.            }  
  8.            //01.将车A从已租集合中移除   //02,将车A加入到可租车辆中  
  9.            string number=lvReturn.SelectedItems[0].Text;  
  10.            Vehicle ve = alreadyRent[number];  
  11.            alreadyRent.Remove(number);  
  12.            MyRefresh(alreadyRent, lvReturn);  
  13.            notRent.Add(number, ve);  
  14.            ve.RentDate = Convert.ToInt32(txtRentDate.Text);  
  15.            double money=0;  
  16.             
  17.            money = ve.CalcPrice();  
  18.            MessageBox.Show("您需要支付"+money+"元");  
  19.   
  20.        }  

九:新车入库的添加

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. private void btnAdd_Click(object sender, EventArgs e)  
  2.         {  
  3.             string lincesN0=txtAutoNum.Text;  
  4.             string name=txtName.Text;  
  5.             string color=cobColor.Text;  
  6.             int time=Convert.ToInt32(txtYears.Text);  
  7.             double dailyRent=Convert.ToInt32(txtLetting.Text);  
  8.              
  9.             if (rdoCar.Checked)  
  10.             {  
  11.                   
  12.                 Car car = new Car(lincesN0, name, color, time, dailyRent);  
  13.                 notRent.Add(lincesN0, car);  
  14.             }  
  15.             if (rdoTruck.Checked)  
  16.             {  
  17.                 int load = Convert.ToInt32(txtLoad.Text);  
  18.                 Truck truck = new Truck(lincesN0, name, color, time, dailyRent, load);  
  19.                 notRent.Add(lincesN0, truck);  
  20.             }  
  21.             MessageBox.Show("添加成功!");  
  22.         }  

十:轿车和卡车的按钮

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. private void rdoCar_CheckedChanged(object sender, EventArgs e)  
  2.        {  
  3.            txtLoad.Enabled = false;  
  4.        }  
  5.   
  6.        private void rdoTruck_CheckedChanged(object sender, EventArgs e)  
  7.        {  
  8.            txtLoad.Enabled = true;  
  9.        }  
1 0
原创粉丝点击