zoukankan      html  css  js  c++  java
  • (深入.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 }
    View Code 父类
     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 }
    View Code 轿车类
     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 }
    View Code 卡车类
      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 }
    View Code 主窗体

  • 相关阅读:
    Jmeter安装与环境部署
    BVT & BAT (版本验证测试和版本验收测试)
    测试计划(Test Plan)
    小米8se从miui12降级刷机手记
    网络传输---HttpURLConnection
    mybatis 中 foreach collection的三种用法
    XStream--java对象与xml形式文件相互转换
    idea问题总结记录
    ssh框架配置过程
    ssm框架配置过程
  • 原文地址:https://www.cnblogs.com/qq2835200767/p/6706982.html
Copyright © 2011-2022 走看看