(深入.Net平台和C#编程)第十章.课程总复习.20170413

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6
 7 namespace PK10.Etity
 8 {
 9     /// <summary>
10     /// 父类
11     /// </summary>
12     public abstract class Vebicle
13     {
14         //颜色
15         public string Color { get; set; }
16         /// <summary>
17         ///租金
18         /// </summary>
19         public double DailyRent { get; set; }
20         //车牌号
21         public string LicenseNo { get; set; }
22         //车名
23         public string Name { get; set; }
24         //租用天数
25         public int RentDate { get; set; }
26         //租用人
27         public string RentUser { get; set; }
28         //租用时间
29         public int YearsOfService { get; set; }
30
31         public string Load { get; set; }
32         /// <summary>
33         /// 构造函数
34         /// </summary>
35         /// <param name="color"></param>
36         /// <param name="dilyrent"></param>
37         /// <param name="licenseno"></param>
38         /// <param name="name"></param>
39         /// <param name="rentdate"></param>
40         /// <param name="rentuser"></param>
41         /// <param name="yearofservice"></param>
42         public Vebicle(string load, string color, double dailyrent, string licenseno, string name, int yearofservice)
43         {
44             this.Color = color;
45             this.DailyRent = dailyrent;
46             this.LicenseNo = licenseno;
47             this.Name = name;
48             this.Load = load;
49             //this.RentDate = rentdate;
50             this.YearsOfService = yearofservice;
51         }
52         /// <summary>
53         /// 结算总金额的抽象方法
54         /// </summary>
55         /// <returns></returns>
56         public abstract double Money();
57         public Vebicle()
58         { }
59     }
60 }

父类

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6
 7 namespace PK10.Etity
 8 {
 9     /// <summary>
10     ///轿车子类
11     /// </summary>
12    public  class Car:Vebicle
13     {
14
15        /// <summary>
16        /// 构造函数
17        /// </summary>
18        public Car(string  load ,string color, double dilyrent, string licenseno, string name, int yearofservice)
19             : base( load,color, dilyrent, licenseno, name,yearofservice)
20        { }
21
22        public Car()
23        { }
24        /// <summary>
25        /// 计算租金总价(租车时间*租车日租金)
26        /// </summary>
27        /// <returns></returns>
28        public override double Money()
29        {
30            double money = (base.RentDate * base.DailyRent);
31            return money;
32        }
33     }
34 }

轿车类

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6
 7 namespace PK10.Etity
 8 {
 9     /// <summary>
10     /// 卡车子类
11     /// </summary>
12     public class Truck : Vebicle
13     {
14
15         /// <summary>
16         /// 构造函数
17         /// </summary>
18         public Truck(string load, string color, double dilyrent, string licenseno, string name, int yearofservice)
19             : base(load, color, dilyrent, licenseno, name, yearofservice)
20         {
21
22         }
23         public Truck() { }
24
25         /// <summary>
26         /// 结算从写
27         /// </summary>
28         /// <returns></returns>
29         public override double Money()
30         {
31             double money = (base.DailyRent * base.DailyRent);
32             return money;
33         }
34
35     }
36
37 }

卡车类

  1 using PK10.Etity;
  2 using System;
  3 using System.Collections.Generic;
  4 using System.ComponentModel;
  5 using System.Data;
  6 using System.Drawing;
  7 using System.Linq;
  8 using System.Text;
  9 using System.Threading.Tasks;
 10 using System.Windows.Forms;
 11
 12 namespace PK10
 13 {
 14     public partial class FrmMain : Form
 15     {
 16         public FrmMain()
 17         {
 18             InitializeComponent();
 19             Init();
 20             BingDing();
 21         }
 22         /// <summary>
 23         /// 保存可租车的集合
 24         /// </summary>
 25         Dictionary<string, Vebicle> vebicles = new Dictionary<string, Vebicle>();
 26
 27         /// <summary>
 28         ///保存出租的车的集合
 29         /// </summary>
 30         Dictionary<string, Vebicle> rentvebicles = new Dictionary<string, Vebicle>();
 31
 32         /// <summary>
 33         /// 初始化可出租车辆信息
 34         /// </summary>
 35         public void Init()
 36         {
 37             dgvZhuChe.AutoGenerateColumns = false;
 38             dgvHuanChe.AutoGenerateColumns = false;
 39             Vebicle ds = new Car(null, "红色", 250, "粤A52445", "奥迪A6", 3);
 40             Vebicle ds1 = new Car(null, "蓝色", 240, "粤B54666", "奔驰", 3);
 41             Vebicle ds2 = new Truck("20", "白色", 260, "泸C515547", "宝马R8", 3);
 42
 43             //添加到可租集合
 44             vebicles.Add(ds.LicenseNo, ds);
 45             vebicles.Add(ds1.LicenseNo, ds1);
 46             vebicles.Add(ds2.LicenseNo, ds2);
 47             foreach (var item in vebicles.Values)
 48             {
 49                 if (item.Load == null)
 50                 {
 51                     item.Load = "无";
 52                 }
 53             }
 54
 55             //已出租车辆
 56             Vebicle bb = new Car(null, "红色", 250, "粤A88888", "奥迪A6", 3);
 57             Vebicle bb1 = new Car(null, "蓝色", 240, "粤B66666", "奔驰", 3);
 58             Vebicle bb2 = new Truck("30", "白色", 260, "泸C545557", "宝马R8", 3);
 59
 60             //添加到已租集合
 61             rentvebicles.Add(bb.LicenseNo, bb);
 62             rentvebicles.Add(bb1.LicenseNo, bb1);
 63             rentvebicles.Add(bb2.LicenseNo, bb2);
 64             foreach (var item in rentvebicles.Values)
 65             {
 66                 if (item.Load == null)
 67                 {
 68                     item.Load = "无";
 69                 }
 70             }
 71
 72         }
 73         /// <summary>
 74         /// 绑定
 75         /// </summary>
 76         public void BingDing()
 77         {
 78             ////绑定可租车
 79             BindingSource bd = new BindingSource();
 80             bd.DataSource = vebicles.Values.ToList();
 81             this.dgvZhuChe.DataSource = bd;
 82
 83             //已出租车辆
 84             BindingSource ds = new BindingSource();
 85             ds.DataSource = rentvebicles.Values.ToList();
 86             this.dgvHuanChe.DataSource = ds;
 87
 88         }
 89         /// <summary>
 90         /// 租车
 91         /// </summary>
 92         /// <param name="sender"></param>
 93         /// <param name="e"></param>
 94         private void btnZuChe_Click(object sender, EventArgs e)
 95         {
 96             //判断
 97             if (dgvZhuChe.SelectedRows.Count > 0)
 98             {
 99                 if (!string.IsNullOrEmpty(txtName.Text.Trim()))
100                 {
101                     string LicenseNO = dgvZhuChe.SelectedRows[0].Cells[0].Value.ToString();
102                     Vebicle Che = null;
103                     if (vebicles[LicenseNO] is Car)
104                     {
105                         Che = new Car();
106                         Che = vebicles[LicenseNO];
107                     }
108                     if (vebicles[LicenseNO] is Truck)
109                     {
110                         Che = new Truck();
111                         Che = vebicles[LicenseNO];
112                     }
113                     Che.RentUser = txtName.Text;
114                     //添加车辆到已租车集合
115                     rentvebicles.Add(Che.LicenseNo, Che);
116                     //删除指定车辆的可租车集合
117                     vebicles.Remove(LicenseNO);
118                     MessageBox.Show("客户" + Che.RentUser + "租车成功!");
119                     BingDing();
120                 }
121                 else
122                 {
123                     MessageBox.Show("请填写租用者", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
124                 }
125             }
126             else
127             {
128                 MessageBox.Show("请选择租用车辆", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
129             }
130         }
131
132         /// <summary>
133         ///刷新可租用车辆列表
134         /// </summary>
135         /// <param name="sender"></param>
136         /// <param name="e"></param>
137         private void btnNew_Click(object sender, EventArgs e)
138         {
139             BingDing();
140         }
141         /// <summary>
142         /// 退出
143         /// </summary>
144         /// <param name="sender"></param>
145         /// <param name="e"></param>
146         private void btnOut_Click(object sender, EventArgs e)
147         {
148             Application.Exit();
149         }
150         /// <summary>
151         /// 选择结算
152         /// </summary>
153         /// <param name="sender"></param>
154         /// <param name="e"></param>
155         private void btnJieSuan_Click(object sender, EventArgs e)
156         {
157             if (dgvHuanChe.SelectedRows.Count > 0)
158             {
159                 if (!string.IsNullOrEmpty(txtDay.Text.Trim()))
160                 {
161                     //找到还哪一辆车
162                     string Key = dgvHuanChe.SelectedRows[0].Cells[0].Value.ToString();
163                     //按照天数给该车属性赋值
164                     rentvebicles[Key].RentDate = int.Parse(txtDay.Text);
165                     //调用计算总价方法 该车总价
166                     MessageBox.Show("还车成功!总价为:" + rentvebicles[Key].Money() + "元");
167                     //还车成功,添加到可租车集合
168                     vebicles.Add(rentvebicles[Key].LicenseNo, rentvebicles[Key]);
169                     //还车成功!在已租车删除该车
170                     rentvebicles.Remove(Key);
171                     BingDing();
172                 }
173                 else
174                 {
175                     MessageBox.Show("请输入租用天数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
176                 }
177             }
178             else
179             {
180                 MessageBox.Show("请选择需要归还的车", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
181             }
182         }
183         /// <summary>
184         /// 车辆入库
185         /// </summary>
186         /// <param name="sender"></param>
187         /// <param name="e"></param>
188         private void btnRuKu_Click(object sender, EventArgs e)
189         {
190             Vebicle Pand = null;
191             //判断输入是否为空
192             if (string.IsNullOrEmpty(txtChePaiHao.Text.Trim()))
193             { }
194             else if (string.IsNullOrEmpty(txtCheType.Text.Trim()))
195             { }
196             else if (string.IsNullOrEmpty(txtColor.Text.Trim()))
197             { }
198             else if (string.IsNullOrEmpty(txtShiJian.Text.Trim()))
199             { }
200             else if (string.IsNullOrEmpty(txtZuJin.Text.Trim()))
201             { }
202             else if (string.IsNullOrEmpty(txtZaiZhon.Text.Trim()))
203             {
204                 MessageBox.Show("信息不能为空!");
205             }
206             else
207             {
208                 if (rbtCar.Checked == true)
209                 {
210                     Pand = new Car();
211                 }
212                 else if (rbtTruck.Checked == true)
213                 {
214                     Pand = new Truck();
215                     (Pand as Truck).Load = txtZaiZhon.Text;
216                 }
217
218
219                 Pand.LicenseNo = txtChePaiHao.Text;
220                 Pand.Name = txtCheType.Text;
221                 Pand.Color = txtColor.Text;
222                 Pand.YearsOfService = int.Parse(txtShiJian.Text);
223                 Pand.DailyRent = int.Parse(txtZuJin.Text);
224
225                 try
226                 {
227                     vebicles.Add(Pand.LicenseNo, Pand);
228                     MessageBox.Show("添加成功~!");
229                 }
230                 catch (Exception)
231                 {
232                     MessageBox.Show("不能有重复的车辆!");
233                 }
234             }
235         }
236     }
237 }

主窗体

时间: 2024-08-07 08:39:52

(深入.Net平台和C#编程)第十章.课程总复习.20170413的相关文章

S2---深入.NET平台和C#编程的完美总结

1.NET简单解说 l 面向对象提升 OOP(Object Oriented  Programming)面向对象编程 AOP:(Aspache  Oriented Programming):面向切面编程 OOD(Object Oriented  Designer)面向对象设计(架构师)   3万/month OOA(Object Oriented  Analysis)面向对象分析  (分析师) 10万/month DBA(Database Administrator,简称DBA) l 泛型集合对

使用ReactiveCocoa实现iOS平台响应式编程

使用ReactiveCocoa实现iOS平台响应式编程 ReactiveCocoa和响应式编程 在说ReactiveCocoa之前,先要介绍一下FRP(Functional Reactive Programming,响应式编程),在维基百科中有这样一个例子介绍: 在命令式编程环境中,a = b + c 表示将表达式的结果赋给a,而之后改变b或c的值不会影响a.但在响应式编程中,a的值会随着b或c的更新而更新. Excel就是响应式编程的一个例子.单元格可以包含字面值或类似"=B1+C1″的公式,

深入.net平台和c#编程 学习笔记

深入.net平台和c#编程 一:理解.nteFramwork与c# 1.1,:Microsoft.net框架概述 1.2:.net框架结构 1.3.:c#语言概述 1.4:体验框架类库的强大功能 二:用对象思考:属性和方法 2.1:类和对象 2.2::编写一个自己的类 2..3:综合实践 三:用对象思考:值类型和应用类型 3.1:在类中使用几种新的数据类型 3.2::理解c#中的值类型和引用类型 3.3:在类中使用索引器 3.4:使用类图描述类和类成员 四:用集合组织相关数据 4.1::集合概述

Linux平台QT数据库编程(来自网络)

Linux平台QT数据库编程 在linux平台使用qt来编写GUI程序,在进行数据库编程的时候,有两种选择方式,分别是:基于linux平台的数据库接口函数编程,另一种是使用qt自带的有关数据库类.那在这里我分别来讲一下这两种方式的实现. 一.使用linux平台的数据库接口编程: 在这里我使用的是一款免费的数据库sqlite,从网络上下一个sqlite-3.0.8.tar.gz源码包,然后进行安装,安装好后就可以使用它提供的函数接口.接下来我们用安装好的sqlite提供的函数接口,在QT中使用的,

python核心编程--第十章 11.11 练习

#!/usr/bin/python # -*- coding: utf-8 -*- # 11-3 函数.在这个练习中,我们将实现max()和min()内建函数. # (a) 写分别带两个元素返回一个较大和较小元素,简单的max2()核min2()函数. # 他们应该可以用任意的python 对象运作.举例来说,max2(4,8)和min2(4,8)会各自每次返回8 和4. # (b) 创建使用了在a 部分中的解来重构max()和min()的新函数my_max()和my_min(). # 这些函数

S2--《深入.NET平台和C#编程》

第一章    深入.NET框架 1.1  Microsoft  .NET框架概述 .NET框架的优势 * 提供了一个面向对象的编程环境,完全支持面向对象编程,.NET 框架提高了软件的可复用性,可扩展性,可维护性和灵活性 * 对Web应用的强大支持 * 对Web Service(Web服务)的支持,Web Service是.NET非常重要的内容,它可以实现不同应用程序之间相互通信 * 实现SOA,支持云计算,同时,.NET 也提供了对云计算的支持,Windows Azure 就是一个构建在微软数

S2 第二本书 深入.NET平台和C#编程 总结 by天命

第一章 深入.NET框架 .NET框架 包含 CLR公共语言运行时 FCL框架类库 CLR(Common Language Runtime)公共语言运行时 CLS(Common Language Specific)公共语言规范 CTS(Common Type System)公共类型系统 FCL(Framework Class Library)框架类库 基本框架类(线程 ADO.NET XML类 文件IO类...... Web窗体 MVC WinForms ADO.NET SqlConnectio

Java8函数OA现金盘平台出租式编程实践精华

现在是OA现金盘平台出租haozbbs.comQ1446595067 资源共享的时代,同样也是知识分享的时代,如果你觉得本文能学到知识,请把知识与别人分享. 绪论 从java8开始,我们就可以通过java8中的StrameAPI与Lambda表达式实现函数式编程,可以让代码变得更加高效简洁. 现在很多企业的生产代码已经开始使用java8了,对于还没有使用过java8进行的编程的朋友们可以好好的学习一下,我在企业中写java8也有一段时间了,我想把我在实际开发中用到的一些场景与大家分享一下,大部分

深入.net平台和C#编程

第一讲 :深入.NET框架 第二讲:深入C#数据类型 第三讲 :使用结合组织相关数据 第四讲 :深入类的方法 第六讲 :初识继承和多态 第七讲 :深入理解多态 第八讲 :可扩展标记语言(XML) 第九讲:文件操作 第一讲:深入.NET框架 知识拓展: 线程睡眠:1.导入命名空间 System.Treading;  2.Thread.Sleed(毫秒); .NET框架具有两个主要组件:公共语言运行时(CLR)与框架类库(.NET Framework类库,即FCL).CLR是.NET框架的基础.CL