--租车系统--2017-4-13

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 第十章.Entity
 8 {
 9 //汽车类继承车类
10     class Car:Vehicle
11     {
12         public Car(string Color, double DailyRent, string LicenseNo, string Name, int RenDate, string RenUser, int YearsOfServic)
13            : base(Color,DailyRent,LicenseNo,Name,RenDate,RenUser,YearsOfServic)
14        {
15           
16        }
17 
18         
19     }
20 }
汽车类
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 第十章.Entity
 8 {
 9     //卡车类继承车类
10 
11    public class Truck:Vehicle
12     {
13        public Truck(string Color, double DailyRent, string LicenseNo, string Name, int RenDate, string RenUser, int YearsOfServic, int Load)
14            : base(Color,DailyRent,LicenseNo,Name,RenDate,RenUser,YearsOfServic)
15        {
16            this.Load = Load;
17        }
18        public int Load { get; set; }
19 
20     }
21 }
卡车类
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 第十章.Entity
 8 {
 9   public abstract class Vehicle
10     {
11       
12       public Vehicle(string Color, double DailyRent, string LicenseNo, string Name, int RenDate, string RenUser, int YearsOfServic)
13       {
14           this.Color = Color;
15           this.DailyRent = DailyRent;
16           this.LicenseNo = LicenseNo;
17           this.Name = Name;
18           this.RenDate = RenDate;
19           this.RenUser = RenUser;
20           this.YearsOfServic = YearsOfServic;
21       }
22       public string Color { get; set; }//颜色
23       public double DailyRent { get; set; }//日租金
24       public string LicenseNo { get; set; }//车牌号
25       public string Name { get; set; }//车型名
26       public int RenDate { get; set; }//使用时间
27       public string RenUser { get; set; }//使用人
28       public int YearsOfServic { get; set; }//使用年限
29 
30     }
31 }
车类
  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Threading.Tasks;
  9 using System.Windows.Forms;
 10 using 第十章.Entity;
 11 
 12 namespace 第十章
 13 {
 14     public partial class Form1 : Form
 15     {
 16         public Form1()
 17         {
 18             InitializeComponent();
 19         }
 20         Dictionary<string, Vehicle> zu = new Dictionary<string, Vehicle>();
 21         Dictionary<string, Vehicle> huan = new Dictionary<string, Vehicle>();
 22         /// <summary>
 23         /// 单选项
 24         /// </summary>
 25         /// <param name="sender"></param>
 26         /// <param name="e"></param>
 27         private void radioButton1_CheckedChanged(object sender, EventArgs e)
 28         {
 29             if (radioButton1.Checked == true)
 30             {
 31                 txtzai.Enabled = false;
 32             }
 33             else {
 34                 txtzai.Enabled = true;
 35             }
 36         }
 37         /// <summary>
 38         /// 租车界面的刷新按钮的点击事件
 39         /// </summary>
 40         /// <param name="sender"></param>
 41         /// <param name="e"></param>
 42         private void button1_Click(object sender, EventArgs e)
 43         {
 44             ZuLoad();
 45         }
 46         /// <summary>
 47         /// 绑定租车信息
 48         /// </summary>
 49         public void ZuLoad() {
 50             lvzu.Items.Clear();
 51             foreach (var item in zu)
 52             {
 53                 ListViewItem i = new ListViewItem(item.Key);
 54                 i.SubItems.Add(item.Value.Name);
 55                 i.SubItems.Add(item.Value.Color);
 56                 i.SubItems.Add(item.Value.RenDate.ToString());
 57                 i.SubItems.Add(item.Value.DailyRent.ToString());
 58                 if (item.Value is Truck)
 59                 {
 60                     i.SubItems.Add(((item.Value) as Truck).Load.ToString());
 61                 }
 62                 else {
 63                     i.SubItems.Add("");
 64                 }
 65                 lvzu.Items.Add(i);
 66 
 67             }
 68         
 69         }
 70         /// <summary>
 71         /// 加载事件
 72         /// </summary>
 73         /// <param name="sender"></param>
 74         /// <param name="e"></param>
 75         private void Form1_Load(object sender, EventArgs e)
 76         {
 77             zu.Add(new Car("白色", 250, "粤A88888", "宝马", 3, "张三", 2).LicenseNo, new Car("白色", 250, "粤A88888", "宝马", 3, "张三", 2));
 78             zu.Add(new Truck("黑色", 230, "粤B88888", "宝马", 2, "张三", 1, 20).LicenseNo, new Truck("黑色", 230, "粤B88888", "宝马", 2, "张三", 1, 20)); ;
 79         }
 80 
 81         /// <summary>
 82         /// 点击租车按钮
 83         /// </summary>
 84         /// <param name="sender"></param>
 85         /// <param name="e"></param>
 86         private void button2_Click(object sender, EventArgs e)
 87         {
 88             if(lvzu.SelectedItems.Count!=1){
 89                 MessageBox.Show("请选中一行");
 90                 return;
 91             }
 92             if(string.IsNullOrEmpty(textBox1.Text.Trim())){
 93                 MessageBox.Show("请输入租车人");
 94                 return;
 95             }
 96 
 97             string key = lvzu.SelectedItems[0].Text;
 98             huan.Add(zu[key].LicenseNo,zu[key]);
 99             zu[key].RenUser = textBox1.Text;
100             zu.Remove(key);
101             ZuLoad();
102         }
103         /// <summary>
104         /// 还车界面的刷新按钮
105         /// </summary>
106         /// <param name="sender"></param>
107         /// <param name="e"></param>
108         private void button4_Click(object sender, EventArgs e)
109         {
110             HuanLoad();
111         }
112         /// <summary>
113         /// 绑定还车信息
114         /// </summary>
115         public void HuanLoad()
116         {
117 
118             lvhuang.Items.Clear();
119             foreach (var item in huan)
120             {
121                 ListViewItem i = new ListViewItem(item.Key);
122                 i.SubItems.Add(item.Value.Name);
123                 i.SubItems.Add(item.Value.Color);
124                 i.SubItems.Add(item.Value.RenDate.ToString());
125                 i.SubItems.Add(item.Value.DailyRent.ToString());
126                 if (item.Value is Truck)
127                 {
128                     i.SubItems.Add(((item.Value) as Truck).Load.ToString());
129                 }
130                 else
131                 {
132                     i.SubItems.Add("");
133                 }
134                 lvhuang.Items.Add(i);
135 
136             }
137 
138         }
139         /// <summary>
140         /// 点击还车按钮
141         /// </summary>
142         /// <param name="sender"></param>
143         /// <param name="e"></param>
144         private void button3_Click(object sender, EventArgs e)
145         {
146             if (lvhuang.SelectedItems.Count != 1)
147             {
148                 MessageBox.Show("请选择一行");
149                 return;
150             }
151             else if (string.IsNullOrEmpty(textBox2.Text))
152             {
153                 MessageBox.Show("请输入租车天数");
154                 return;
155             }
156             string key = lvhuang.SelectedItems[0].Text;
157             double mun =(double.Parse(lvhuang.SelectedItems[0].SubItems[4].Text))*(double.Parse(textBox2.Text));
158             MessageBox.Show("还车成功,需要金额:"+mun.ToString());
159             zu.Add(huan[key].LicenseNo,huan[key]);
160             huan.Remove(key);
161             HuanLoad();
162         }
163         /// <summary>
164         /// 点击入库添加车辆
165         /// </summary>
166         /// <param name="sender"></param>
167         /// <param name="e"></param>
168         private void button5_Click(object sender, EventArgs e)
169         {
170             foreach (string item in zu.Keys)
171             {
172                 if(txtNo.Text.Trim().Equals(item)){
173                     MessageBox.Show("不能有一样的车牌号");
174                     return;
175                 }
176             }
177             foreach (string item in huan.Keys)
178             {
179                 if (txtNo.Text.Trim().Equals(item))
180                 {
181                     MessageBox.Show("不能有一样的车牌号");
182                     return;
183                 }
184             }
185             if (radioButton1.Checked == true)
186             {
187                 zu.Add(new Car(txtse.Text, double.Parse(txtzu.Text), txtNo.Text, txtxin.Text, 1, "张三", 2).LicenseNo, new Car(txtse.Text, double.Parse(txtzu.Text), txtNo.Text, txtxin.Text, 1, "张三", 2));
188             }
189             else {
190                 zu.Add(new Truck(txtse.Text, double.Parse(txtzu.Text), txtNo.Text, txtxin.Text, 1, "张三", 2,int.Parse(txtzai.Text)).LicenseNo, new Truck(txtse.Text, double.Parse(txtzu.Text), txtNo.Text, txtxin.Text, 1, "张三", 2,int.Parse(txtzai.Text)));
191             }
192             MessageBox.Show("添加成功");
193         }
194 
195        
196     }
197 }
租车窗体

 

posted @ 2017-04-13 21:34  霖权锅锅  阅读(127)  评论(0编辑  收藏  举报