• 第十章汽车租凭系统


      1 namespace Vehicle
      2 {
      3     /// <summary>
      4     /// 车辆类
      5     /// </summary>
      6    public abstract class Abstract
      7     {
      8        //颜色
      9        public string Color { get; set;}
     10        //日租金
     11        public double DailyRent { get; set;}
     12 
     13        //车牌号
     14        public string LicenseNo { get; set; }
     15 
     16        //车名
     17        public string Name { get; set;}
     18 
     19 
     20        public int RentDate { get; set;}
     21 
     22        //租凭者
     23        public string RentUser { get; set;}
     24 
     25        public int YearsOfService { get; set;}
     26 
     27 
     28        public Abstract(string licenseNo, string name, string color,double dailyRent, int rentDate)
     29        {
     30            this.Color = color;
     31            this.DailyRent = dailyRent;
     32            this.LicenseNo = licenseNo;
     33            this.Name = name;
     34            this.RentDate = rentDate;
     35            this.Name = name;
     36            //this.YearsOfService = yearsOfService;
     37           
     38        }
     39        public Abstract()
     40        {
     41        }
     42 
     43 
     44        ////方法重载
     45        //public abstract double Calcprice(double a);
     46 
     47 
     48     }
     49 }
     50 ------------------------------------------------------------------------------------
     51 //小轿车类
     52 namespace Vehicle
     53 {
     54    public class Car:Abstract
     55     {
     56        public Car(string licenseNo, string name, string color, double dailyRent, int rentDate)
     57           : base(licenseNo,name,color,dailyRent,rentDate)
     58        {
     59        }
     60        public Car() { }
     61       
     62       }
     63                    
     64        
     65     }     
     66 
     67     }
     68 ------------------------------------------------------------------------------------
     69 namespace Vehicle
     70 {
     71     //卡车类
     72   public  class Truck:Abstract
     73     {
     74 
     75           public Truck(string licenseNo, string name, string color,double dailyRent, int rentDate,int Load)
     76           : base(licenseNo, name, color, dailyRent, rentDate)
     77         {
     78           this.Load = Load;
     79         }
     80           public Truck() { }
     81     
     82 
     83       public int Load { get; set;}
     84 
     85 
     86     }
     87 }
     88 -------------------------------------------------------------------------------------
     89 namespace Vehicle
     90 {
     91     public partial class Form1 : Form
     92     {
     93         public Form1()
     94         {
     95             InitializeComponent();
     96         }
     97 
     98         //保存可租车的车的集合
     99         Dictionary<string, Abstract> abstracts = new Dictionary<string, Abstract>();
    100 
    101         //保存租出的车的集合
    102         Dictionary<string, Abstract> renVehicles = new Dictionary<string, Abstract>();
    103 
    104 
    105         //加载事件
    106         private void Form1_Load(object sender, EventArgs e)
    107         {
    108             abstracts.Add(new Truck("粤233654", "奥迪A7", "黑色", 3, 240, 12).LicenseNo, new Truck("粤233654", "奥迪A7", "黑色", 3, 240, 12));
    109             abstracts.Add(new Truck("粤66666", "奥迪A6", "白色", 4, 200, 13).LicenseNo, new Truck("粤66666", "奥迪A6", "白色", 4, 200, 13));
    110             abstracts.Add(new Car("粤88888", "京123456", "红色", 6, 150).LicenseNo, new Car("粤88888", "京123456", "红色", 6, 150));
    111         }
    112         //添加到listView里
    113         public void Info()
    114         {
    115             list_view.Items.Clear();
    116             foreach (var item in abstracts)
    117             {
    118                 ListViewItem view = new ListViewItem(item.Key);
    119                 view.SubItems.Add(item.Value.Name);
    120                 view.SubItems.Add(item.Value.Color);
    121                 view.SubItems.Add(item.Value.DailyRent.ToString());
    122                 view.SubItems.Add(item.Value.RentDate.ToString());
    123                 //判断一下是否是小轿车还是卡车
    124                 if (item.Value is Truck)
    125                 {
    126                     view.SubItems.Add((item.Value as Truck).Load.ToString());
    127                 }
    128                 if (item.Value is Car)
    129                 {
    130 
    131                     view.SubItems.Add("");
    132                 }
    133 
    134                 list_view.Items.Add(view);
    135             }
    136         }
    137 
    138         public void Info2()
    139         {
    140             listView2.Items.Clear();
    141             foreach (var items1 in renVehicles)
    142             {
    143                 ListViewItem list = new ListViewItem(items1.Key);
    144                 list.SubItems.Add(items1.Value.Name);
    145                 list.SubItems.Add(items1.Value.Color);
    146                 list.SubItems.Add(items1.Value.DailyRent.ToString());
    147                 list.SubItems.Add(items1.Value.RentDate.ToString());  
    148                 //判断是否是卡车还是轿车
    149                 if (items1.Value is Truck)
    150                 {
    151                     list.SubItems.Add((items1.Value as Truck).Load.ToString());
    152                 }
    153                 else
    154                 {
    155 
    156                     list.SubItems.Add("");
    157                 }
    158                 //刷新
    159                 listView2.Items.Add(list);
    160             }
    161 
    162 
    163         }
    164 
    165         //出租车刷新的事件
    166         private void btn_shuaxin_Click(object sender, EventArgs e)
    167         {
    168             Info();
    169         }
    170         //租车的事件
    171         private void btn_zhuche_Click(object sender, EventArgs e)
    172         {
    173             if (string.IsNullOrEmpty(txt_name.Text.Trim()))
    174             {
    175 
    176                 MessageBox.Show("请输入租凭者");
    177                 return;
    178 
    179             }
    180             if (list_view.SelectedItems.Count!= 1)
    181             {
    182                 MessageBox.Show("请选择车辆");
    183                 return;
    184             }
    185             string Rows = list_view.SelectedItems[0].Text;
    186             renVehicles.Add(Rows, abstracts[Rows]);
    187             abstracts.Remove(Rows);
    188             Info();
    189             MessageBox.Show("租车成功");
    190 
    191         }
    192         //还车的刷新事件
    193         private void button1_Click(object sender, EventArgs e)
    194         {
    195             Info2();
    196         }
    197         //结算
    198         private void button2_Click(object sender, EventArgs e)
    
    199         {
    200             if (string.IsNullOrEmpty(txt_day.Text.Trim()))
    201             {
    202                 MessageBox.Show("请输入天数");
    203                 return;
    204             }
    205             if (list_view.SelectedItems.Count != 0)
    206             {
    207                 MessageBox.Show("请选择车辆");
    208                 return;
    209             }
    210             string listview = listView2.SelectedItems[0].Text;
    211 
    212             MessageBox.Show(((renVehicles[listview].RentDate) * (double.Parse(txt_day.Text))).ToString());
    213 
    214             abstracts.Add(renVehicles[listview].LicenseNo, renVehicles[listview]);
    215             renVehicles.Remove(listview);
    216             Info2();
    217         }
    218 
    219         private void rad_car_CheckedChanged(object sender, EventArgs e)
    220         {
    221             //判断是选中的是小轿车还是卡车
    222             if (rad_car.Checked == true)
    223             {
    224                 txt_load.Text = "";
    225                 txt_load.Enabled = false;
    226             }
    227             else
    228             {
    229 
    230                 txt_load.Enabled = true;
    231             }
    232 
    233 
    234         }
    235         //入库的事件
    236         private void btn_add_Click(object sender, EventArgs e)
    237         {
    238             if(string.IsNullOrEmpty(txt_datetime.Text.Trim())||string.IsNullOrEmpty(txt_day.Text.Trim())||string.IsNullOrEmpty(txt_load.Text.Trim())||string.IsNullOrEmpty(txt_name.Text.Trim())||string.IsNullOrEmpty(txt_no.Text.Trim())||string.IsNullOrEmpty(txt_Rentday.Text.Trim())||string.IsNullOrEmpty(txt_day.Text.Trim()))
    239             {
    240                 MessageBox.Show("入库的信息不能为空");
    241                 return;
    242 
    243             }
    244             if (rad_car.Checked == true)
    245             {
    246                 abstracts.Add(new Car(txt_no.Text,txt_type.Text, cmb_color.Text, double.Parse(txt_Rentday.Text), int.Parse(txt_datetime.Text)).LicenseNo, new Car(txt_no.Text,txt_type.Text, cmb_color.Text, double.Parse(txt_datetime.Text), int.Parse(txt_Rentday.Text)));
    247             }
    248             else
    249             {
    250 
    251                 abstracts.Add(new Truck(txt_no.Text,txt_type.Text, cmb_color.Text, double.Parse(txt_Rentday.Text), int.Parse(txt_datetime.Text), int.Parse(txt_load.Text)).LicenseNo, new Truck(txt_no.Text,txt_type.Text, cmb_color.Text, double.Parse(txt_Rentday.Text), int.Parse(txt_datetime.Text), int.Parse(txt_load.Text)));
    252 
    253             }
    254             MessageBox.Show("添加成功");
    255             //刷新
    256             Info();
    257 
    258         }
    259 
    260     }
    261 }
    第十章汽车租凭系统
  • 相关阅读:
    【Express系列】第3篇——接入mysql
    【Express系列】第2篇——主程序的改造
    【Express系列】第1篇——项目创建
    AngularJS内置指令
    node服务端搭建学习笔记
    生成ssh key
    webstorm的常用操作
    VSCode 常用插件
    php集成包
    composer安装特别慢的解决方案
  • 原文地址:https://www.cnblogs.com/1-9-9-5/p/6705883.html
Copyright © 2020-2023  润新知