ACCP 7.0 C#项目 汽车租赁系统
来源:互联网 发布:新疆广电网络网上营业厅 编辑:程序博客网 时间:2024/05/01 10:06
//先 写出 1个 父类 2个子类 ////// 父类 /// 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 abstract double CalcPrice(); public Vehicle() { } public Vehicle(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; } }
//继承 为多态做准备 卡车类 class Truck : Vehicle { //载重 public int Load { get; set; } public Truck() { } 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; } ////// 卡车费用计算方法 /// 30天以内(含30)按日租金计算 /// 30天以上超出部分:每天,每吨(载重量)增加日租金10% /// public override double CalcPrice() { double totalPrice = 0; double basicPrice = this.RentDate * this.DailyRent; if (this.RentDate <= 30) { totalPrice = basicPrice; } else { //30天以上超出部分:每天,每吨(载重量)增加日租金10% totalPrice = basicPrice + (this.RentDate - 30) * this.Load * this.DailyRent * 0.1; } return totalPrice; } }
//继承 为多态做准备 轿车类class Car : Vehicle { public Car() { } public Car(string color, double dailyrent, string licenseno, string name, int rentdate, string rentuser, int yearsofservice) : base(color, dailyrent, licenseno, name, rentdate, rentuser, yearsofservice) { } ////// 轿车的价格计算方法: /// 30天以内(含30)按日租金计算 /// 30天以上超出部分:每天增加日租金10% /// public override double CalcPrice() { double totalPrice = 0; double basicPrice = this.RentDate * this.DailyRent; if (this.RentDate <= 30) { totalPrice = basicPrice; } else { totalPrice = basicPrice + (this.RentDate - 30) * this.DailyRent * 0.1; } return totalPrice; } }
//先写 2个泛型集合 一个是可出租的 一个是 可以还的 DictionaryrentCar = new Dictionary (); Dictionary rentCarl = new Dictionary ();
private void Form1_Load(object sender, EventArgs e) { Car c1 = new Car() { LicenseNO="湘A888888", Name="法拉利A5", Color="白色", DailyRent =5000, YearsOFService =2 }; rentCar.Add(c1.LicenseNO, c1); Car c2 = new Car() { LicenseNO = "湘A666666", Name = "保时捷A5", Color = "红色", DailyRent = 4000, YearsOFService = 2 }; rentCar.Add(c2.LicenseNO, c2); Truck t1 = new Truck { LicenseNO = "湘B666666", Name = "东风A5", Color = "蓝色", DailyRent = 2000, YearsOFService = 2, Load =120 }; rentCar.Add(t1.LicenseNO, t1); Initlt(); //刷新 listView1 可以租的车 textBox7.Enabled = false; //这是 添加车辆 是 载重的txt控件 }
//初始化 可出租的车辆 的信息 到listView private void Initlt() { InitListView(listView1,rentCar); } //初始化 已经出租的车辆 的信息 到listView private void Initlt2() { InitListView(listView2,rentCarl); } //初始化 信息 重用 private void InitListView(ListView lvt,Dictionarydic) { lvt.Items.Clear(); foreach (Vehicle item in dic.Values) { ListViewItem lv = new ListViewItem(); lv.Text = item.LicenseNO; lv.SubItems.Add(item.Name); lv.SubItems.Add(item.Color); lv.SubItems.Add(item.YearsOFService.ToString()); lv.SubItems.Add(item.DailyRent.ToString()); //判断 是 轿车 还是卡车 是卡车 显示载重 ,轿车就显示 无 if (item is Truck) lv.SubItems.Add((item as Truck).Load.ToString()); else lv.SubItems.Add("无"); lvt.Items.Add(lv); } }
//ListView1 控件 列宽自适应 租车 private void listView1_SizeChanged(object sender, EventArgs e) { int _Count = listView1.Columns.Count; int _Width = listView1.Width; foreach (ColumnHeader ch in listView1.Columns) { ch.Width = _Width / _Count; } }
// listView2 列宽 自适应 还车 private void listView2_SizeChanged(object sender, EventArgs e) { int _Count = listView2.Columns.Count; int _Width = listView2.Width; foreach (ColumnHeader ch in listView2.Columns) { ch.Width = _Width / _Count; } }
//点击 租车按钮 时的事件 private void btuZC_Click(object sender, EventArgs e) { //租车人 txtbox 里 是否为空 if (textBox1.Text.Trim()=="") { MessageBox.Show("请输入租用者姓名"); textBox1.Focus(); return; } //是否 选中 listView1 的一行数据 if (listView1.SelectedItems.Count<=0) { MessageBox.Show("请选择你要租用的车"); return; } //获取 当前选中的 车的 车牌号 string lino = listView1.SelectedItems[0].Text; //可以被还的车 集合 添加一辆车 rentCarl.Add(lino, rentCar[lino]); rentCar[lino].RentUser = textBox1.Text.Trim(); //可被 租的车 集合删除一辆车 rentCar.Remove(lino); MessageBox.Show("租车成功"); textBox1.Clear(); //清空 租车人信息 Initlt(); Initlt2(); } //listView1 刷新 按钮 private void button3_Click(object sender, EventArgs e) { Initlt2(); }
//还车 结算 private void button2_Click(object sender, EventArgs e) { if (textBox2.Text.Trim()=="") { MessageBox.Show("请输入租用的天数"); textBox2.Focus(); return; } if (listView2.SelectedItems.Count<=0) { MessageBox.Show("请选择你要结算的车辆"); return; } string lin = listView2.SelectedItems[0].Text; rentCarl[lin].RentDate = int.Parse(this.textBox2.Text); double tota = rentCarl[lin].CalcPrice();//CalcPrice 前面的抽象方法 计算价格 string msg = string.Format("您的总价是{0}。", tota.ToString()); MessageBox.Show(msg, "注意!", MessageBoxButtons.OK, MessageBoxIcon.Information); //可以被租的车 集合 添加一辆车 rentCar.Add(lin, rentCarl[lin]); //可以被还的车 集合 删除一辆车 rentCarl.Remove(lin); //刷新 listView 1,2 Initlt(); Initlt2(); }
//汽车 入库 单选键 选中 汽车是 载重 隐藏 选中 卡车 载重 出现private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked) { textBox7.Enabled = false; } else { textBox7.Enabled = true; } }
//汽车 入库 private void button4_Click(object sender, EventArgs e) { if (textBox3.Text.Trim() =="") { MessageBox.Show("请输入车牌号"); return; } if (textBox4.Text.Trim() == "") { MessageBox.Show("请输入车型"); return; } if (textBox5.Text.Trim() == "") { MessageBox.Show("请输入使用时间"); return; } if (textBox6.Text.Trim() == "") { MessageBox.Show("请输入每日租金"); return; } Vehicle vs = null; if (radioButton1.Checked) { vs = new Car(); } else { Truck t = new Truck(); t.Load = Convert.ToInt32(textBox7.Text.Trim()); vs = t; } vs.LicenseNO = textBox3.Text.Trim(); vs.Name = textBox4.Text.Trim(); vs.Color = comboBox2.Text.Trim(); vs.YearsOFService = Convert.ToInt32(textBox5.Text.Trim()); vs.DailyRent = Convert.ToDouble(textBox6.Text.Trim()); //向泛型集合 添加数据 rentCar.Add(vs.LicenseNO,vs); MessageBox.Show("添加成功"); Initlt();//刷新 可租车的 列表 //清空 texbox ComboBox 数据 foreach (Control item in textBox3.Controls) { if (item is TextBox ) { (item as TextBox).Clear(); } else if(item is ComboBox) { (item as ComboBox).SelectedIndex = -1; } } }
阅读全文
2 0
- ACCP 7.0 C#项目 汽车租赁系统
- 汽车租赁系统项目
- C# 第十章 汽车租赁系统
- 汽车租赁管理系统-期末项目
- 汽车租赁管理系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁管理系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁系统
- 继承、多态:汽车租赁系统
- java汽车租赁系统代码
- 金石汽车租赁管理系统 下载
- 实现汽车租赁系统的计价功能
- 深入.NET 第十章 汽车租赁系统
- 汽车租赁系统的简单实现
- Java程序员适合哪种人去做
- FCC--Confirm the Ending(确认字符串的结尾)
- 数据结构上机实验3——N皇后问题栈求解
- java连接hbase长时间无反应问题
- linux-在线(动态)识别新插入的物理磁盘
- ACCP 7.0 C#项目 汽车租赁系统
- 系统异常,异常信息:java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable d
- 广电情况简介
- kotlin 一用就爱上
- 模拟阻塞队列-使用notify和wait
- 利用LR做性能测试中出现的常见问题解决方案
- 22岁程序媛的迷茫
- DOM based XSS
- SSD性能评判