Truck.cs类

      //卡车类
public class Truck : Vehicle1
{
//重载
public int Load { get; set; }
//构造函数
public Truck(string color, double dailyrent, string licenseNO, string name, int rentDate, string rentUser, int yearsOfService, int load)
:base(color, dailyrent, licenseNO, name, rentDate, rentUser, yearsOfService)
{
this.Load = load;
}
//计算价格
public override double CalcPrice()
{
double Price = ;
Price = this.DailyRent * this.RentDate;
return Price;
}
}
}
Vehicle1.cs类
   //交通工具类
public abstract class Vehicle1
{
//颜色
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 Vehicle1(string color, double dailyrent, string licenseNO, string name, int rentDate, string rentUser, int yearsOfService) {
this.Color = color;
this.DailyRent = dailyrent;
this.LicenseNO = licenseNO;
this.Name = name;
this.RentDate = rentDate;
this.RentUser = rentUser;
this.YearsOfService = yearsOfService; }
//方法重写
public Vehicle1() { }
//执行
public abstract double CalcPrice();
}
}

主窗体代码:

    //可以出租车的集合
Dictionary<string, Vehicle1> dy = new Dictionary<string, Vehicle1>();
//已出租车的集合
Dictionary<string, Vehicle1> doy = new Dictionary<string, Vehicle1>(); private void Form1_Load(object sender, EventArgs e)
{ //调用方法
Init();
//绑定下拉框
cmba.Text = "请选择";
cmba.Text = "白色";
//卡车载重的文本框不可用
textBox6.Enabled = false; } public void Init()
{
//初始化租车
Vehicle1 c = new Car("白色", , "京A666666", "兰博基尼", , "xs", );
//添加车
dy.Add(c.LicenseNO, c); Vehicle1 car = new Car("红色", , "鲁A999999", "法拉利", , "zs", );
dy.Add(car.LicenseNO, car); Vehicle1 t = new Truck("黑色", , "鲁A333333", "本田思域", , "hs", , );
doy.Add(t.LicenseNO, t); Vehicle1 tk = new Truck("金色", , "鲁A888888", "东风雪铁龙", , "ps", , );
doy.Add(tk.LicenseNO, tk);
} private void button3_Click(object sender, EventArgs e)
{
//退出
this.Close();
}
// listView1绑定数据(租车)
public void show()
{
//清空租车的ListView1
listzc.Items.Clear();
//循环遍历(租车的双列集合)
foreach (var item in dy)
{
//
ListViewItem cc = new ListViewItem(item.Key);
cc.SubItems.Add(item.Value.Name);
cc.SubItems.Add(item.Value.Color);
//
cc.SubItems.Add(item.Value.RentDate.ToString());
cc.SubItems.Add(item.Value.DailyRent.ToString()); if (item.Value is Truck)
{
//
cc.SubItems.Add(((item.Value) as Truck).Load.ToString()); }
else
{
cc.SubItems.Add("");
}
listzc.Items.Add(cc);
}
}

     // listView2绑定数据(还车)
public void showw()
{
listhc.Items.Clear();
foreach (var item in doy)
{
//创建对象 并取K键,值
ListViewItem ccc = new ListViewItem(item.Key);
//
ccc.SubItems.Add(item.Value.Name);
ccc.SubItems.Add(item.Value.Color);
ccc.SubItems.Add(item.Value.RentDate.ToString());
ccc.SubItems.Add(item.Value.DailyRent.ToString()); if (item.Value is Truck)
{
ccc.SubItems.Add(((item.Value) as Truck).Load.ToString()); }
else
{
ccc.SubItems.Add("");
}
listhc.Items.Add(ccc);
} }
//刷新listView (zc)
private void button1_Click(object sender, EventArgs e)
{
showw();
}
//刷新listView(hc)
private void button5_Click(object sender, EventArgs e)
{
show();
}
// 租车
private void button4_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox2.Text.Trim()))
{
MessageBox.Show("请填写租车姓名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
if (listhc.SelectedItems.Count < )
{
MessageBox.Show("请选择租车", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{ string key = listzc.SelectedItems[].Text;
doy.Add(dy[key].LicenseNO, dy[key]);
if (dy.ContainsKey(key))
{
dy.Remove(key);
show();
}
}
}
}

  // 结算
private void button2_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox1.Text.Trim()))
{
MessageBox.Show("请输入租车天数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
if (listhc.SelectedItems.Count < )
{
MessageBox.Show("请选择还车", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
string key = listhc.SelectedItems[].Text;
doy[key].RentDate = int.Parse(this.textBox1.Text);
double a = doy[key].DailyRent;
double totalPrice = doy[key].CalcPrice();
string msg = string.Format("您的总价是:" + totalPrice.ToString());
MessageBox.Show(msg, "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
dy.Add(doy[key].LicenseNO, doy[key]);
if (doy.ContainsKey(key))
{
doy.Remove(key);
this.showw();
}
}
} }
//入库
private void button6_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtchep.Text.Trim()) || string.IsNullOrEmpty(txtchex.Text.Trim())
|| string.IsNullOrEmpty(cmba.Text.Trim()) || string.IsNullOrEmpty(txtje.Text.Trim())
|| string.IsNullOrEmpty(txtsj.Text.Trim()))
{
MessageBox.Show("请完善新车入库信息","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
Vehicle1 vehicle = null;
if (radioButton1.Checked == true)
{
vehicle = new Car(cmba.Text, int.Parse(txtje.Text), txtchep.Text, txtchex.Text, , "s", int.Parse(txtsj.Text));
}
else
{
vehicle = new Truck(cmba.Text, int.Parse(txtje.Text), txtchep.Text, txtchex.Text, int.Parse(txtsj.Text), txtsj.Text, , int.Parse(textBox6.Text));
}
try
{
dy.Add(vehicle.LicenseNO, vehicle);
MessageBox.Show("添加成功");
}
catch (Exception)
{
MessageBox.Show("车牌号重复");
}
}
}
// 轿车
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
//
radioButton1.Enabled = false;
}
//卡车
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
radioButton2.Enabled = true;
}

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. 新手之VM下安装centos版本Linux系统完整版!

    一.安装必备软件 1:下载好VM workstations虚拟机 2:下载好你要安装的centos版本. 如果没有,请自己先百度下载好~或者找我要. 二.开始安装 VM workstation部分 1 ...

  5. xshell连接vmware系统完整版

    设置静态ip需要修改文件一共有两个要修改的文件vi /etc/resolv.confvi /etc/sysconfig/network-scripts/ifcfg-eno16777736 第一个文件 ...

  6. C#汽车租赁系统

    类图: 父类(车类,抽象类) /// <summary> /// 车辆基本信息类.搞一个抽象类玩玩 /// </summary> public abstract class V ...

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

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

  8. SVN 添加账号密码的方法(Windows 系统完整版)

    前言: 本人新接了一个项目,目前该项目基本完工,现在想要将该项目上传至SVN上保管,然后设置并添加账号密码信息,以便于后期加入这个项目的小伙伴可以通过新增加的账号密码信息获取到SVN项目,以便后期项目 ...

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

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

随机推荐

  1. Linux上vim的使用

    .........以下是我在使用vim时的操作经验........... (首先要了解vim主要是命令模式,输入模式,可视化模式,主要区别就是在不同模式下可以完成不同的操作,只是个编辑器,没有必要太纠 ...

  2. RequestMapping原理分析和RequestMappingHandlerMapping

    转载https://juejin.im/post/5cbeadb96fb9a031ff0d18b5 源码版本spring-webmvc-4.3.7.RELEASE 使用Spring MVC的同学一般都 ...

  3. Unity Shader常用函数,标签,指令,宏总结(持续更新)

    极端常用: UnityObjectToClipPos(v.vertex); 最基本的顶点变换,模型空间 ==>裁剪空间 mul(unity_ObjectToWorld, v.vertex); 顶 ...

  4. java源码解析之String类(五)

    /* * 切片函数,非常重要,这里一定要牢记beginIndex是开始位置,endIndex是结束位置,区别于以前学的offset是开始位置,而count或length是个数和长度 * 比如说,new ...

  5. Programming In Lua 第二章

    1,lua基本类型:nil,boolean,number,string,userdata,function,thread,table.可以用函数type获取变量的类型. 2,lua中的字符串可以用单引 ...

  6. Java并发之Semaphore和Exchanger工具类简单介绍

    一.Semaphore介绍 Semaphore意思为信号量,是用来控制同时访问特定资源的线程数数量.它的本质上其实也是一个共享锁.Semaphore可以用于做流量控制,特别是公用资源有限的应用场景.例 ...

  7. SQL经典练习题50--mysql

    --1.学生表 Student(Sid,Sname,Sage,Ssex)? --Sid 学生编号,Sname 学生姓名,Sage 出生年月,Ssex 学生性别 --2.课程表? Course(Cid, ...

  8. python的自定义函数

    今天想把上次参考着网上教程写的scrapy爬虫改写成requests和beautifulsoup的普通爬虫,写着写着发现自己对python的自定义函数还不是太熟悉(自己TCL了.........流泪) ...

  9. 并发编程-concurrent指南-交换机Exchanger

    java.util.concurrent包中的Exchanger类可用于两个线程之间交换信息.可简单地将Exchanger对象理解为一个包含两个格子的容器,通过exchanger方法可以向两个格子中填 ...

  10. 关于char[]转换成LPCWSTR的有关问题[转]

    一.问题的原因:VS2010默认采用宽字符UNICODE编码方式,定义了Unicode,因此相关的字符串必须为unicode字符串,而非ascii字符串. LPCWSTR中的W是宽字符的意思,是UNI ...