SoFunction
Updated on 2025-03-06

C# implements car rental system project

This article shares the specific code of C# to implement the car rental system for your reference. The specific content is as follows

Parent class of cars and trucks

using System;
using ;
using ;
using ;
using ;
// Parent class variables and methodsnamespace Car rental system
{
 public class Inheritance
  {
   public Inheritance()
   { }
   public Inheritance(string color,double everydaymoney,string no,string name,int rentdate,string load,string rentuser,int services)
   {
      = color;
      = everydaymoney;
      = no;
      = name;
      = rentdate;
      = load;
 
 
      = rentuser;
      = 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; }
   // Parent class calculates rent    public virtual double Vehicle()
    {
      double rentMoney;
      rentMoney =  * ;
      return rentMoney;
    }
   
   
 }
}

car

using System;
using ;
using ;
using ;
using ;
 
namespace Car rental system
{
  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)
    {
      
    }
    //Omit the method of rewritten the car's price calculation    
  }
}

truck

using System;
using ;
using ;
using ;
using ;
 
 
namespace Car rental system
{
  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)
    {
      
    }
    //Omit the calculation method of rewriting the truck    
  }
}

Main interface

using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
 
namespace Car rental system
{
  public partial class Main : Form
  {
    public Main()
    {
      InitializeComponent();
 
    }
    Inheritance inheri = new Inheritance();
    //Save the collection of unrented cars    Dictionary<string, Inheritance> rentDic = new Dictionary<string, Inheritance>();
    //Save the collection of rented cars    Dictionary<string, Inheritance> rentedDic = new Dictionary<string, Inheritance>();
    //Bind the unrented collection into the listview container 
    //Bind data to listview container    public void BangDing(ListView listview,Dictionary<string ,Inheritance> dic)
    {
       = true;
      ListViewItem items;
      ();
 
      foreach (Inheritance item in )
      {
 
        items = new ListViewItem();
         = ;
        ();
        ();
        (());
        (());
        ();
        (items);
      }
    }
    //Initialize unrentaled collection    public void AddRent()
    {
 
      Car car1 = new Car("black", 100, "001", "Audi", 0, "none","",3);
      Car car2 = new Car("black", 100, "002", "Audi", 0, "none","",3);
      Truck truck1 = new Truck("red", 200, "A001", "FAW", 0, "20","",6);
      (, car1);
      (, car2);
      (, truck1);
      
    }
 
 
    //Show no car rental information    private void button2_Click(object sender, EventArgs e)
    {
 
      BangDing(listView1,rentDic);
    }
 
    private void Main_Load(object sender, EventArgs e)
    {
      AddRent();
    }
 
    // Car rental operation    private void button1_Click(object sender, EventArgs e)
    {
      string key = this.[0].Text;
      rentDic[key].RentUser = this.;
      (rentDic[key].No,rentDic[key]);
      if ((key))
      {
        (key);
      }
      BangDing(listView1,rentDic);
      ("Leased");
 
 
    }
    
 
    private void button4_Click(object sender, EventArgs e)
    {
      BangDing(listView2,rentedDic);
    }
    //Check the return settlement    public void JieSuan()
    {
      string key = this.[0].Text;
      rentedDic[key].RentDate = Convert.ToInt32(this.);
      (rentedDic[key].No,rentedDic[key]);
      double rentMoney = rentedDic[key].Vehicle();
      if ((key))
      {
        (key);
      }
 
 
      BangDing(listView2,rentedDic);
      ("Rent is:",());
      
 
    
    }
    private void button5_Click(object sender, EventArgs e)
    {
      JieSuan();
    }
    //New car entry operation    private void button6_Click(object sender, EventArgs e)
    {
      string no = this.;
      string name = this.;
      string color = this.;
      int services = Convert.ToInt32(this.);
      double renteverydaymoney = Convert.ToInt32(this.);
      string load = this.;
      // Make type judgment      if (load=="none")
      {
        inheri = new Car(color,renteverydaymoney,no,name,0,load,"",services);
      }
      else
      {
        inheri = new Truck(color,renteverydaymoney,no,name,0,load,"",services);
      }
       
      (,inheri);
      ("Added successfully","hint",,);
     // Perform text clearing operation      foreach (TabPage page in )
      { 
 
        foreach (Control control in )
        {
          if (control is TextBox)
          {
            ="";
 
          }
 
        }
      }
      
    }
  }
}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.