深入.NET 第十章 汽车租赁系统
来源:互联网 发布:阿里云重新挂载硬盘 编辑:程序博客网 时间:2024/05/01 20:13
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace 第十章_汽车租赁系统{ public class Car:Vehicle { public Car() { } public Car(string licenseno, string name, string color, string rendate, double dailyRent, double dailyrent) : base(licenseno, name, color, rendate, dailyrent) { } public Car(string licenseno, string name, string color, string rendate, double dailyRent) { this.LicenseNO = licenseno; this.Name = name; this.Color = color; this.RenDate = rendate; this.DailyRent = dailyRent; } public override double GetNum() { 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 第十章_汽车租赁系统{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } //保存可租车辆的集合 Dictionary<string, Vehicle> Vehicles = new Dictionary<string, Vehicle>(); //保存租出车 的集合 Dictionary<string,Vehicle> rentvehicles=new Dictionary<string, Vehicle>(); //动态加载listView的方法 public void New(Dictionary<string, Vehicle> list, ListView listView2) { ListViewItem listView = null; listView2.Items.Clear(); foreach (Vehicle item in list.Values) { if (item is Car) { listView = new ListViewItem(); listView.Text = item.LicenseNO; listView.SubItems.Add(item.Name); listView.SubItems.Add(item.Color); listView.SubItems.Add(item.RenDate.ToString()); listView.SubItems.Add(item.DailyRent.ToString()); } 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.RenDate.ToString()); listView.SubItems.Add(item.DailyRent.ToString()); listView.SubItems.Add(((Truck) item).Load.ToString()); } listView2.Items.Add(listView); } } public void Intitle() { Truck truck=new Truck("京A888","奥迪","红色","3",240,10); Car car = new Car("京A111", "宝马", "绿色", "3", 240); Vehicles.Add(truck.LicenseNO,truck); Vehicles.Add(car.LicenseNO, car); //加载数据 New(Vehicles,listView2); } private void button4_Click(object sender, EventArgs e) { if (listView2.SelectedItems.Count == 0) { MessageBox.Show("请选中一行!"); return; } if (textBox2.Text == "") { MessageBox.Show("请输入姓名!"); return; } string carnum = listView2.SelectedItems[0].Text; Vehicle ve = Vehicles[carnum]; //直接把获得要租的信息放入rentvehicles集合 rentvehicles.Add(carnum, ve); //删除原来的集合 Vehicles.Remove(carnum); New(Vehicles, listView2); MessageBox.Show("出租成功"); } private void button3_Click(object sender, EventArgs e) { this.Close(); } private void button6_Click(object sender, EventArgs e) { if (Good()) { foreach (string item in Vehicles.Keys) { if (textBox3.Text == item) { MessageBox.Show("此车牌已经有库存,请你确认"); return; } } //使用简单工厂 Vehicle ve = null; if (radioButton1.Checked == true) { ve = VehicleUtil.CreateVehicle(textBox3.Text, textBox4.Text, comboBox1.Text, textBox5.Text, Convert.ToDouble(textBox6.Text), Convert.ToInt32(textBox7.Text), radioButton1.Text); } else { ve = VehicleUtil.CreateVehicle(textBox3.Text, textBox4.Text, comboBox1.Text, textBox5.Text, Convert.ToDouble(textBox6.Text), Convert.ToInt32(textBox7.Text), radioButton2.Text); } Vehicles.Add(textBox3.Text, ve); MessageBox.Show("入库成功"); textBox3.Text = ""; textBox4.Text = ""; comboBox1.Text = ""; textBox5.Text = ""; textBox6.Text = ""; textBox7.Text = ""; } else { MessageBox.Show("请完善信息的填写!"); } } private void Form1_Load(object sender, EventArgs e) { Intitle(); } private void listView2_SelectedIndexChanged(object sender, EventArgs e) { } private void button5_Click(object sender, EventArgs e) { New(Vehicles, listView2); } private void button2_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("请输入天数"); return; } if (listView3.SelectedItems.Count == 0) { MessageBox.Show("请选择一行"); return; } string carnum1 = listView3.SelectedItems[0].Text; Vehicle ve = rentvehicles[carnum1]; //获取租的天数 int num = Convert.ToInt32(textBox1.Text); ve.YearsOfService = num; double money = ve.GetNum(); DialogResult result = MessageBox.Show("你要支付" + money + "元", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { //直接把获得要还的信息放入vehicles集合 Vehicles.Add(carnum1, ve); //删除原来的集合 rentvehicles.Remove(carnum1); //重新加载 New(rentvehicles, listView3); MessageBox.Show("还车成功"); } } private void button1_Click(object sender, EventArgs e) { New(rentvehicles, listView3); } public bool Good() { bool flag = true; if (textBox3.Text == "" || textBox4.Text == "" || comboBox1.Text == "" || textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "" || radioButton1.Text == "") { flag = false; } return flag; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 第十章_汽车租赁系统{ public class Truck:Vehicle { public int Load { get; set; } public Truck() { } public Truck(string licenseno, string name, string color, string rendate, double dailyrent,int load) : base(licenseno, name, color, rendate, dailyrent) { this.Load = load; } public override double GetNum() { double result = this.DailyRent*this.YearsOfService; return result; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 第十章_汽车租赁系统{ 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 string RenDate { get; set; } public string RenUser { get; set; } public int YearsOfService{ get; set; } public Vehicle() { } public Vehicle(string licenseno, string name, string color, string rendate , double dailyren) { this.Color = color; this.DailyRent = dailyren; this.LicenseNO = licenseno; this.Name = name; this.RenDate = rendate; } public abstract double GetNum();} }
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 第十章_汽车租赁系统{ public class VehicleUtil { public static Vehicle CreateVehicle (string liceseno, string name, string color,string rendate, double dailyRent, int load, string type) { Vehicle vehicle = null; switch (type) { case "卡车": vehicle = new Truck(liceseno, name, color, rendate, dailyRent,load); break; case "轿车": vehicle = new Car(liceseno, name, color,rendate, dailyRent); break; } return vehicle; } }}
0 0
- 深入.NET 第十章 汽车租赁系统
- C# 第十章 汽车租赁系统
- 汽车租赁管理系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁管理系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁系统项目
- 继承、多态:汽车租赁系统
- java汽车租赁系统代码
- 金石汽车租赁管理系统 下载
- 汽车租赁管理系统-期末项目
- 实现汽车租赁系统的计价功能
- 汽车租赁系统的简单实现
- ACCP 7.0 C#项目 汽车租赁系统
- iOS回顾笔记( 01 )
- 携手共进,再创辉煌
- JS快捷键
- 华南师范大学自考专业-人力资源管理
- tomcat配置web项目路径映射
- 深入.NET 第十章 汽车租赁系统
- Android常用框架混淆代码
- Bioperl在window下的安装
- 高斯消元模板
- 求组合数
- 重写equals和hasCode 方法 JDK1.7
- juery实现ul li标签切换
- angular2子组件的事件传递(任意组件事件传递)
- 实验2 运算器的编程实现