类图:

父类(车类,抽象类)

 /// <summary>
/// 车辆基本信息类。搞一个抽象类玩玩
/// </summary>
public abstract class Vehicle
{
public string Color { get; set; }//颜色
public double DailyRent { get; set; }//日租金
public string LicenseNo { get; set; }//车牌号
public string Name { get; set; }//车名
public int RentDate { get; set; }//使用时间
public string RentUser { get; set; }//租用者
public int YearsOfService { get; set; }//租用天数
public Vehicle()
{ }
//构造
public Vehicle(string color, double dailyRent, string licenseNo,string name,int rentDate)
{
this.Color = color;
this.Name = name;
this.RentDate = rentDate;
this.LicenseNo = licenseNo;
this.DailyRent = dailyRent;
}
//结算租金抽象方法
public abstract double GetJieSuang(); }

汽车类:

 /// <summary>
/// 汽车类
/// </summary>
public class Car:Vehicle
{
public Car()
{
}
//构造
public Car(string licenseNo, string name, string color, int rentDate, double dailyRent)
:base(color, dailyRent,licenseNo,name, rentDate)
{ }
//重写父类计算价格的方法
public override double GetJieSuang()
{
//日租金*租的天数
double result = this.DailyRent * this.YearsOfService;
return result;
}
}

卡车类:

  /// <summary>
/// 卡车类
/// </summary>
public class Truck:Vehicle
{
public int Load { get; set; }//卡车载重
//无参构造
public Truck()
{ }
//构造
public Truck(string licenseNo, string name, string color, int rentDate, double dailyRent, int load)
: base(color, dailyRent, licenseNo, name, rentDate)
{
this.Load = load;
}
//重写父类计算租金的方法
public override double GetJieSuang()
{
//日租金*租的天数
double result = this.DailyRent * this.YearsOfService;
return result;
}
}

具体实现:

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 CarRentalSystem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.cbColor.SelectedIndex = 0;//显示颜色
this.txtTruckLoad.Visible = false;
}
//保存可租用车的集合
Dictionary<string, Vehicle> vehicle = new Dictionary<string,Vehicle>();
//保存已租出的车的集合
Dictionary<string, Vehicle> rentvehcile = new Dictionary<string,Vehicle>(); //动态加载listview的方法
public void carZaiZhong()
{
if (rbcar.Checked == true)
{
this.txtTruckLoad.Visible = false;
}
else if(rbTruck.Checked==true)
{
this.txtTruckLoad.Visible = true;
}
}
/// <summary>
/// 刷新ListView的带参方法,传两个不同集合 和刷新对应的ListView
/// </summary>
/// <param name="list"></param>
/// <param name="lvlist"></param>
public void New(Dictionary<string, Vehicle> list, ListView lvlist)
{
ListViewItem listview = null;//局部变量要赋初始值
lvlist.Items.Clear();//清除项
foreach (Vehicle item in list.Values)
{
//如果是Car,对应的ListView添加数据
if (item is Car)
{
listview = new ListViewItem();//new出ListViewItem视图
listview.Text = item.LicenseNo;//listView第一列
listview.SubItems.Add(item.Name);//添加子项车名
listview.SubItems.Add(item.Color);//颜色
listview.SubItems.Add(item.RentDate.ToString());//使用时间
listview.SubItems.Add(item.DailyRent.ToString());//日租金
listview.SubItems.Add("无");

}
else if (item is Truck)
{
listview = new ListViewItem();
listview.Text = item.LicenseNo;
listview.SubItems.Add(item.Name);
listview.SubItems.Add(item.Color);
listview.SubItems.Add(item.RentDate.ToString());
listview.SubItems.Add(item.DailyRent.ToString());
listview.SubItems.Add(((Truck)item).Load.ToString());
}
lvlist.Items.Add(listview);//添加到对应集合的ListView中
} }
/// <summary>
/// 初始化可租用车集合信息
/// </summary>
public void initial()
{
Truck truck = new Truck("京A88888", "大卡", "红色", 3, 900, 20);//卡车
Car car = new Car("京A99999", "奔驰", "黑色", 3, 300);//汽车信息 vehicle.Add(truck.LicenseNo, truck);//添加到可租车集合
vehicle.Add(car.LicenseNo, car);
//租车数据
New(vehicle, lvCarkezu);
}
/// <summary>
/// 初始化已租出车的信息
/// </summary>
public void initialHc()
{
//对象初始化信息
Truck truck1 = new Truck("京B99999", "小卡", "红色", 3, 280, 10);//卡车
Car car1 = new Car("京B99999", "红旗", "黑色", 3, 280);//汽车信息
rentvehcile.Add(truck1.LicenseNo, truck1);//添加到已租车集合
rentvehcile.Add(car1.LicenseNo, car1);
//还车数据
New(rentvehcile, lvHuanche);
}
//选择结算,还车
private void button5_Click(object sender, EventArgs e)
{ //租用天数非空验证
if (this.txtRendDay.Text == "")
{
MessageBox.Show("请输入天数!");
return;
}
//确定是否选中一行
if (this.lvHuanche.SelectedItems.Count == 0)
{
MessageBox.Show("请选择一行!");
return;
}
//获取车牌号的值
string carnum1 = this.lvHuanche.SelectedItems[0].Text;
//根据车牌号获得对应的车辆对象
Vehicle ve = rentvehcile[carnum1]; //获取租用天数
int num = Convert.ToInt32(this.txtRendDay.Text);
//给属性使用天数赋值
ve.YearsOfService = num;
//结算租金
double money = ve.GetJieSuang();
DialogResult result = MessageBox.Show("你要支付" + money + "元", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
//直接把获得要还的信息放入vehicles集合
vehicle.Add(carnum1, ve); //删除原来的集合
rentvehcile.Remove(carnum1); //重新加载
New(rentvehcile, lvHuanche);
MessageBox.Show("还车成功");
} }
private void textBox5_TextChanged(object sender, EventArgs e)
{ } private void Form1_Load(object sender, EventArgs e)
{
initial();//初始化信息
initialHc(); }
private void button1_Click(object sender, EventArgs e)
{
//退出
DialogResult choice = MessageBox.Show("确定要退出吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if(choice==DialogResult.OK)
{
Application.Exit();
}
}
//新车入库车型验证,非空验证
public bool emptyNo()
{
//如果选择了汽车
if (this.rbcar.Checked == true)
{
if (this.txtLicenseNo.Text != "" && this.
txtDailyRent.Text != "" && this.txtName.Text != "" && this.txtRentDate.Text != "")
{
try
{
//文本框数字验证
int rntDate = int.Parse(this.txtRentDate.Text);
int dailyRent = int.Parse(this.txtDailyRent.Text);
//double truckLoad = double.Parse(this.txtTruckLoad.Text);
return true;
}
catch (Exception)
{
MessageBox.Show("使用时间,日租金应输入数字!");
return false;
}
}
else
{
MessageBox.Show("请完善新入库汽车信息!");
return false;
} }
else if (this.rbTruck.Checked == true)
{
if (this.txtLicenseNo.Text != "" && this.txtDailyRent.Text != "" && this.txtName.Text != "" && this.txtRentDate.Text != ""&&this.txtTruckLoad.Text!="")
{
try
{
//文本框数字验证
int rntDate = int.Parse(this.txtRentDate.Text);
int dailyRent = int.Parse(this.txtDailyRent.Text);
double truckLoad = double.Parse(this.txtTruckLoad.Text);
return true; }
catch (Exception)
{
MessageBox.Show("使用时间,日租金或卡车载重应输入数字!");
return false;
}
}
else
{
MessageBox.Show("请完善新入库卡车信息!");
return false;
}
}
return true;//防止报错
}
//新车入库
private void btnRuku_Click(object sender, EventArgs e)
{
//文本框非空验证
if (emptyNo())
{
//对车载重的值做一个判断,然后存入不同的集合
if(this.txtTruckLoad.Visible==false)
{
//车牌号是唯一的
string licenseNo=this.txtLicenseNo.Text;//车牌号
foreach (string ve in vehicle.Keys)//循环查看是否有相同的车牌号,有给出提示
{
if (ve == licenseNo)
{
MessageBox.Show("已经有相同的汽车车牌号,请您重新确认车牌号!");
return;
}
} string name =this.txtName.Text;//车名
string cbColor = this.cbColor.SelectedItem.ToString();//颜色
int rentDate=Convert.ToInt32(this.txtRentDate.Text);//使用时间
double dailyRent = Convert.ToDouble(this.txtDailyRent.Text);//每日租金
//双列集合一般用对象初始化器,单列集合用集合初始化器,在添加数据的时候比较清晰,方便但是我这里没用。。。
Car car = new Car(licenseNo, name, cbColor, rentDate, dailyRent);
//添加到可租车集合
vehicle.Add(car.LicenseNo,car);
MessageBox.Show("汽车入库成功!");
}
else if (this.txtTruckLoad.Visible == true)
{
//车牌号是唯一的
string licenseNo = this.txtLicenseNo.Text;//车牌号
foreach (string rve in vehicle.Keys)//循环查看是否有相同的车牌号,有给出提示
{
if (rve== licenseNo)
{
MessageBox.Show("已经有相同的卡车车牌号,请您重新确认车牌号!");
return;
}
}
string name = this.txtName.Text;//车名
string cbColor = this.cbColor.SelectedItem.ToString();//颜色
int rentDate = Convert.ToInt32(this.txtRentDate.Text);//使用时间
double dailyRent = Convert.ToDouble(this.txtDailyRent.Text);//每日租金
int load = Convert.ToInt32(this.txtTruckLoad.Text);
//初始化信息
Truck tk = new Truck(licenseNo, name, cbColor, rentDate, dailyRent,load);
//添加到可租车集合
vehicle.Add(tk.LicenseNo, tk); MessageBox.Show("卡车入库成功!");
} }
} private void btnBreak_Click(object sender, EventArgs e)
{
//刷新
New(vehicle, lvCarkezu); } private void btnRent_Click(object sender, EventArgs e)
{
//租车
if (this.lvCarkezu.SelectedItems.Count == 0)
{
MessageBox.Show("请选中一行!");
return;
}
if (txtRentUser.Text == "")//非空判断
{
MessageBox.Show("请输入租用者!");
return; }
//执行租车.
//获取车牌号的值
string carnum = this.lvCarkezu.SelectedItems[0].Text;
Vehicle ve = vehicle[carnum];
//直接把获得要租的信息放入rentvehicles集合
rentvehcile.Add(carnum, ve);
//删除原来的集合
vehicle.Remove(carnum); //重新加载
New(vehicle, lvCarkezu);
MessageBox.Show("租车成功");
} private void btnBreakor_Click(object sender, EventArgs e)
{
//刷新租出车的信息
New(rentvehcile, lvHuanche);
} private void rbcar_CheckedChanged(object sender, EventArgs e)
{
//选中则显示文本框
if (this.rbcar.Checked == true)
{
this.txtTruckLoad.Visible = false;
}
} private void rbTruck_CheckedChanged(object sender, EventArgs e)
{
//判断是否选中
//carZaiZhong();
if (this.rbTruck.Checked == true)
{
this.txtTruckLoad.Visible = true;
}
}
private void tabPage3_Click(object sender, EventArgs e)
{ }
private void lvCarkezu_SelectedIndexChanged(object sender, EventArgs e)
{ }
}
}

C#汽车租赁系统的更多相关文章

  1. Java汽车租赁系统[源码+数据库]

    系统名称 Java汽车租赁系统   (源码在文末) 系统概要 汽车租赁系统总共分为两个大的模块,分别是系统模块和业务模块.其中系统模块和业务模块底下又有其子模块. 功能模块 一.业务模块 1.客户管理 ...

  2. Java代码~~汽车租赁系统

    租车信息: 输出结果: 代码: 1.先定义抽象类(汽车类:Moto) package cn.aura.demo01; public abstract class Moto { //公共属性 priva ...

  3. 深入.NET和C#的小型汽车租赁系统的框架

    前言:写这个小型系统之前呢,我们应该要猜测可能要用到哪些知识点. 那么对于这个小型系统:主要用到了如下的知识:  封装,集合(ArrayList和HashTable)和泛型和非泛型集合(泛型:List ...

  4. 一种基于Java Swing/HTML/MySQL的汽车租赁系统

    该项目是一个Java的课程作业(大二),主要运用Java.Swing.HTML.MySQL,实现基本的租车逻辑.界面可视化.信息导出.数据存储等功能.实现管理员.用户两种角色登录,并结合Java开发中 ...

  5. Springboot+vue 实现汽车租赁系统(毕业设计二)(前后端项目分离)

    文章目录 1.系统功能列表 2.管理员端界面 2.1 商家登录界面 2.2 用户信息管理界面 2.3 汽车管理界面 2.4 订单界面 2.5 汽车图形报表 2.6 优惠券新增界面 3.普通用户界面 3 ...

  6. C#汽车租赁系统 完整版

      Truck.cs类 //卡车类 public class Truck : Vehicle1 { //重载 public int Load { get; set; } //构造函数 public T ...

  7. .Net中的AOP系列之构建一个汽车租赁应用

    返回<.Net中的AOP>系列学习总目录 本篇目录 开始一个新项目 没有AOP的生活 变更的代价 使用AOP重构 本系列的源码本人已托管于Coding上:点击查看. 本系列的实验环境:VS ...

  8. 《Java从入门到放弃》JavaSE篇:综合练习——单身狗租赁系统(数组版)

    因为现在只学习了基本语法,所以在综合练习之前,先补充关于方法概念. 方法的作用:把一系列的代码放在一起,然后再取个别名.之后通过这个别名的调用,就相当于执行了这一系列的代码. 方法的语法:([]中的内 ...

  9. 《Java从入门到放弃》JavaSE入门篇:练习——单身狗租赁系统

    今天,我们要玩个大的!!! 我们把之前使用数组做的这个单身狗系统改版成数据库版本,并且使用面向对象里面的一些简单思想.如果有不知道这个系统的看官,请跳转到目录页,然后再选择单身狗系统(数组版)先围观五 ...

随机推荐

  1. [Vue]浅谈Vue3组合式API带来的好处以及选项API的坏处

    前言 如果是经验不够多的同志在学习Vue的时候,在最开始会接触到Vue传统的方式(选项式API),后边会接触到Vue3的新方式 -- 组合式API.相信会有不少同志会陷入迷茫,因为我第一次听到新的名词 ...

  2. silky微服务框架服务注册中心介绍

    目录 服务注册中心简介 服务元数据 主机名称(hostName) 服务列表(services) 终结点 时间戳 使用Zookeeper作为服务注册中心 使用Nacos作为服务注册中心 使用Consul ...

  3. Redis篇:事务和lua脚本的使用

    现在多数秒杀,抽奖,抢红包等大并发高流量的功能一般都是基于 redis 实现,然而在选择 redis 的时候,我们也要了解 redis 如何保证服务正确运行的原理 前言 redis 如何实现高性能和高 ...

  4. [gym101981F]Frank

    在本题中,每一步是独立的,因此即可以看作从$s$移动到$t$的期望步数(对于每一对$s$和$t$都求出答案) 令$f_{i,j}$表示当$s=i$且$t=j$时的答案,则有$f_{i,j}=\begi ...

  5. 深度揭秘Netty中的FastThreadLocal为什么比ThreadLocal效率更高?

    阅读这篇文章之前,建议先阅读和这篇文章关联的内容. 1. 详细剖析分布式微服务架构下网络通信的底层实现原理(图解) 2. (年薪60W的技巧)工作了5年,你真的理解Netty以及为什么要用吗?(深度干 ...

  6. 多线程01.newThread的方式创建线程

    1.java应用程序的main函数是一个线程,是被jvm启动的时候调用,线程的名字叫main 2.实现一个线程,必须创建一个thread实例,override run方法,并且调用start方法. 3 ...

  7. 7.4 k8s结合ceph rbd、cephfs实现数据的持久化和共享

    1.在ceph集群中创建rbd存储池.镜像及普通用户 1.1.存储池接镜像配置 创建存储池 root@u20-deploy:~# ceph osd pool create rbd-test-pool1 ...

  8. 【CTSC1999】【带权并查集 】月亮之眼

    Description 吉儿是一家古董店的老板娘,由于她经营有道,小店开得红红火火.昨天,吉儿无意之中得到了散落民间几百年的珍宝-月亮之眼.吉儿深知"月亮之眼"价值连城:它是由许多 ...

  9. Mysql查询优化汇总 order by优化例子,group by优化例子,limit优化例子,优化建议

    Mysql查询优化汇总 order by优化例子,group by优化例子,limit优化例子,优化建议 索引 索引是一种存储引擎快速查询记录的一种数据结构. 注意 MYSQL一次查询只能使用一个索引 ...

  10. Mysql的delimiter

    告诉MySQL解释器,该段命令是否已经结束了,mysql是否可以执行了.默认情况下,delimiter是分号;.在命令行客户端中,如果有一行命令以分号结束,那么回车后,mysql将会执行该命令. 有时 ...