欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#实现汽车租赁系统项目

程序员文章站 2023-12-12 09:43:04
本文实例为大家分享了c#实现汽车租赁系统的具体代码,供大家参考,具体内容如下 汽车和卡车的父类 using system; using system.coll...

本文实例为大家分享了c#实现汽车租赁系统的具体代码,供大家参考,具体内容如下

汽车和卡车的父类

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;
//父类变量和方法
namespace 汽车租赁系统
{
 public class inheritance
  {
   public inheritance()
   { }
   public inheritance(string color,double everydaymoney,string no,string name,int rentdate,string load,string rentuser,int services)
   {
     this.color = color;
     this.everydaymoney = everydaymoney;
     this.no = no;
     this.name = name;
     this.rentdate = rentdate;
     this.load = load;
 
 
     this.rentuser = rentuser;
     this.services = services;
   }
    public string color { get; set; }
    public double everydaymoney { get; set; }
    public string no { get; set; }
    public string name { get; set; }
    public int rentdate { get; set; }
    public string load { get; set; }
    public string rentuser { get; set; }
    public int services { get; set; }
   //父类计算租金方法
    public virtual double vehicle()
    {
      double rentmoney;
      rentmoney = this.rentdate * this.everydaymoney;
      return rentmoney;
    }
   
   
 }
}

汽车

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;
 
namespace 汽车租赁系统
{
  public class car:inheritance
  {
    public car()
    { }
    public car( string color,double everydaymoney,string no,string name,int rentdate,string load,string rentuser,int services)
      :base(color,everydaymoney,no,name ,rentdate,load,rentuser,services)
    {
      
    }
    //省略重写汽车计算价格方法
    
  }
}

卡车

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;
 
 
namespace 汽车租赁系统
{
  public class truck:inheritance
  {
    public truck()
    { }
    public truck( string color,double everydaymoney,string no,string name,int rentdate,string load, string rentuser,int services)
      :base(color,everydaymoney,no,name ,rentdate,load,rentuser,services)
    {
      
    }
    //省略重写卡车计算方法
    
  }
}

主界面

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 汽车租赁系统
{
  public partial class main : form
  {
    public main()
    {
      initializecomponent();
 
    }
    inheritance inheri = new inheritance();
    //保存未租车的集合
    dictionary<string, inheritance> rentdic = new dictionary<string, inheritance>();
    //保存已租车的集合
    dictionary<string, inheritance> renteddic = new dictionary<string, inheritance>();
    //将未租车集合绑定到listview容器中
 
    //将数据绑定到listview容器上
    public void bangding(listview listview,dictionary<string ,inheritance> dic)
    {
      listview.fullrowselect = true;
      listviewitem items;
      listview.items.clear();
 
      foreach (inheritance item in dic.values)
      {
 
        items = new listviewitem();
        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);
      }
    }
    //进行未租车集合初始化
    public void addrent()
    {
 
      car car1 = new car("黑色", 100, "001", "奥迪", 0, "无","",3);
      car car2 = new car("黑色", 100, "002", "奥迪", 0, "无","",3);
      truck truck1 = new truck("红色", 200, "a001", "一汽", 0, "20","",6);
      rentdic.add(car1.no, car1);
      rentdic.add(car2.no, car2);
      rentdic.add(truck1.no, truck1);
      
    }
 
 
    //显示未租车信息
    private void button2_click(object sender, eventargs e)
    {
 
      bangding(listview1,rentdic);
    }
 
    private void main_load(object sender, eventargs e)
    {
      addrent();
    }
 
    //进行租车操作
    private void button1_click(object sender, eventargs e)
    {
      string key = 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("已出租");
 
 
    }
    
 
    private void button4_click(object sender, eventargs e)
    {
      bangding(listview2,renteddic);
    }
    //进行还车结算
    public void jiesuan()
    {
      string key = this.listview2.selecteditems[0].text;
      renteddic[key].rentdate = convert.toint32(this.textbox2.text);
      rentdic.add(renteddic[key].no,renteddic[key]);
      double rentmoney = renteddic[key].vehicle();
      if (renteddic.containskey(key))
      {
        renteddic.remove(key);
      }
 
 
      bangding(listview2,renteddic);
      messagebox.show("租金为:",rentmoney.tostring());
      
 
    
    }
    private void button5_click(object sender, eventargs e)
    {
      jiesuan();
    }
    //新车入库操作
    private void button6_click(object sender, eventargs e)
    {
      string no = this.textbox3.text;
      string name = this.textbox4.text;
      string color = this.textbox5.text;
      int services = convert.toint32(this.textbox6.text);
      double renteverydaymoney = convert.toint32(this.textbox7.text);
      string load = this.textbox8.text;
      //进行类型判断
      if (load=="无")
      {
        inheri = new car(color,renteverydaymoney,no,name,0,load,"",services);
      }
      else
      {
        inheri = new truck(color,renteverydaymoney,no,name,0,load,"",services);
      }
       
      rentdic.add(inheri.no,inheri);
      messagebox.show("添加成功","提示",messageboxbuttons.ok,messageboxicon.error);
     //进行文本清空操作
      foreach (tabpage page in tabcontrol1.tabpages)
      { 
 
        foreach (control control in page.controls)
        {
          if (control is textbox)
          {
            control.text="";
 
          }
 
        }
      }
      
    }
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: