C#实现汽车租赁系统项目
本文实例为大家分享了C#实现汽车租赁系统的具体代码,供大家参考,具体内容如下
汽车和卡车的父类
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; //父类变量和方法 namespace汽车租赁系统 { publicclassInheritance { publicInheritance() {} publicInheritance(stringcolor,doubleeverydaymoney,stringno,stringname,intrentdate,stringload,stringrentuser,intservices) { this.Color=color; this.EverydayMoney=everydaymoney; this.No=no; this.Name=name; this.RentDate=rentdate; this.Load=load; this.RentUser=rentuser; this.Services=services; } publicstringColor{get;set;} publicdoubleEverydayMoney{get;set;} publicstringNo{get;set;} publicstringName{get;set;} publicintRentDate{get;set;} publicstringLoad{get;set;} publicstringRentUser{get;set;} publicintServices{get;set;} //父类计算租金方法 publicvirtualdoubleVehicle() { doublerentMoney; rentMoney=this.RentDate*this.EverydayMoney; returnrentMoney; } } }
汽车
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; namespace汽车租赁系统 { publicclassCar:Inheritance { publicCar() {} publicCar(stringcolor,doubleeverydaymoney,stringno,stringname,intrentdate,stringload,stringrentuser,intservices) :base(color,everydaymoney,no,name,rentdate,load,rentuser,services) { } //省略重写汽车计算价格方法 } }
卡车
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; namespace汽车租赁系统 { publicclassTruck:Inheritance { publicTruck() {} publicTruck(stringcolor,doubleeverydaymoney,stringno,stringname,intrentdate,stringload,stringrentuser,intservices) :base(color,everydaymoney,no,name,rentdate,load,rentuser,services) { } //省略重写卡车计算方法 } }
主界面
usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; usingSystem.Windows.Forms; namespace汽车租赁系统 { publicpartialclassMain:Form { publicMain() { InitializeComponent(); } Inheritanceinheri=newInheritance(); //保存未租车的集合 DictionaryrentDic=newDictionary (); //保存已租车的集合 Dictionary rentedDic=newDictionary (); //将未租车集合绑定到listview容器中 //将数据绑定到listview容器上 publicvoidBangDing(ListViewlistview,Dictionary dic) { listview.FullRowSelect=true; ListViewItemitems; listview.Items.Clear(); foreach(Inheritanceitemindic.Values) { items=newListViewItem(); items.Text=item.No; items.SubItems.Add(item.Name); items.SubItems.Add(item.Color); items.SubItems.Add(item.Services.ToString()); items.SubItems.Add(item.EverydayMoney.ToString()); items.SubItems.Add(item.Load); listview.Items.Add(items); } } //进行未租车集合初始化 publicvoidAddRent() { Carcar1=newCar("黑色",100,"001","奥迪",0,"无","",3); Carcar2=newCar("黑色",100,"002","奥迪",0,"无","",3); Trucktruck1=newTruck("红色",200,"A001","一汽",0,"20","",6); rentDic.Add(car1.No,car1); rentDic.Add(car2.No,car2); rentDic.Add(truck1.No,truck1); } //显示未租车信息 privatevoidbutton2_Click(objectsender,EventArgse) { BangDing(listView1,rentDic); } privatevoidMain_Load(objectsender,EventArgse) { AddRent(); } //进行租车操作 privatevoidbutton1_Click(objectsender,EventArgse) { stringkey=this.listView1.SelectedItems[0].Text; rentDic[key].RentUser=this.textBox1.Text; rentedDic.Add(rentDic[key].No,rentDic[key]); if(rentDic.ContainsKey(key)) { rentDic.Remove(key); } BangDing(listView1,rentDic); MessageBox.Show("已出租"); } privatevoidbutton4_Click(objectsender,EventArgse) { BangDing(listView2,rentedDic); } //进行还车结算 publicvoidJieSuan() { stringkey=this.listView2.SelectedItems[0].Text; rentedDic[key].RentDate=Convert.ToInt32(this.textBox2.Text); rentDic.Add(rentedDic[key].No,rentedDic[key]); doublerentMoney=rentedDic[key].Vehicle(); if(rentedDic.ContainsKey(key)) { rentedDic.Remove(key); } BangDing(listView2,rentedDic); MessageBox.Show("租金为:",rentMoney.ToString()); } privatevoidbutton5_Click(objectsender,EventArgse) { JieSuan(); } //新车入库操作 privatevoidbutton6_Click(objectsender,EventArgse) { stringno=this.textBox3.Text; stringname=this.textBox4.Text; stringcolor=this.textBox5.Text; intservices=Convert.ToInt32(this.textBox6.Text); doublerenteverydaymoney=Convert.ToInt32(this.textBox7.Text); stringload=this.textBox8.Text; //进行类型判断 if(load=="无") { inheri=newCar(color,renteverydaymoney,no,name,0,load,"",services); } else { inheri=newTruck(color,renteverydaymoney,no,name,0,load,"",services); } rentDic.Add(inheri.No,inheri); MessageBox.Show("添加成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Error); //进行文本清空操作 foreach(TabPagepageintabControl1.TabPages) { foreach(Controlcontrolinpage.Controls) { if(controlisTextBox) { control.Text=""; } } } } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。