汽車租賃系統

来源:http://www.cnblogs.com/yejiaojiao/archive/2016/03/07/5251963.html
-Advertisement-
Play Games

一、系統窗體 二、思路分析: 我們看見這有三個類分別是:Vehicle 交通工具類父類 Car和Truck分別是Vehicle是它的子類 需要用到繼承和多態、簡單工廠的知識點進行書寫 1)vehic類 public abstract class Vehicle { //無參數 public Vehi


一、系統窗體

 

 

 

 

 

二、思路分析:

我們看見這有三個類分別是:Vehicle 交通工具類父類   Car和Truck分別是Vehicle是它的子類   需要用到繼承和多態、簡單工廠的知識點進行書寫

1)vehic類

public abstract   class Vehicle
    {
     //無參數
     public Vehicle()
     {
       }
     //有參數
    
     public Vehicle(string Name, string LicenseNo, string Color, int YearsOfService, double DailyRent)
     {
         this.Name = Name;
         this.LicenseNo = LicenseNo;
         this.Color = Color;
         this.YearsOfService = YearsOfService;
         this.DailyRent = DailyRent;
     }
     //顏色
        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();
       
    }

  2)Car小轎車類

 //小汽車
  public   class Car:Vehicle
    {
        public Car() { }
        public Car(string Name, string LicenseNo, string Color, int YearsOfService, double DailyRent)
            : base(Name, LicenseNo, Color, YearsOfService, DailyRent)
        {
        }
      //計算價格的
        public override double CalcPrice() 
        {
            double totalPrice = 0;
            double baseicPrice = this.RentDate*this.DailyRent;
            if (this.RentDate <= 30)
            {
                totalPrice = baseicPrice;
            }
            else
            {
                totalPrice = baseicPrice + (this.RentDate - 30) * this.DailyRent * 0.1;
            }
            return totalPrice;
        }

      
    }

  3)Truck卡車類

   //大卡車
   public  class Truck:Vehicle
    {
        //載重量
       public Truck() { }
       public Truck(string Name, string LicenseNo, string Color, int YearsOfService, double DailyRent,int Load)
           :base(Name,LicenseNo,Color,YearsOfService,DailyRent)
       {
           this.Load = Load;
       }
       public int Load { get; set; }

       //計算價格的
       public override double CalcPrice()
       {
           double totalPrice = 0;
           double basicPrice = RentDate * DailyRent;
           if (RentDate <= 30)
           {
               totalPrice = basicPrice;
           }
           else
           {
               totalPrice = basicPrice + (RentDate - 30) * (DailyRent * 0.1) * Load;
           }
           return totalPrice;
       }
    }

  4)我們不知道用戶會選擇什麼類型所以我們有藉助一個工廠類幫助我們做這件事。VehicleFactory

public   class VehicleFactory
    {
      public static Vehicle ReadMagenner(string Name, string LicenseNo, string Color, int YearsOfService, double DailyRent, string Type, int Load) 
      {
          Vehicle vehicle = null;
          switch (Type)
          {
              case"Car":
                  vehicle = new Car( Name,LicenseNo,Color,YearsOfService,DailyRent);
                  break;
              case"Truck":
                  vehicle = new Truck(Name, LicenseNo, Color, YearsOfService, DailyRent, Load);
                  break;
          }
          return vehicle;
      }
    }

 5)我們要在FrmMain主窗體進行

 public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }
        //保存可租用車的集合(車輛名稱,車輛對象)
        Dictionary<string, Vehicle> notRent = new Dictionary<string, Vehicle>();
        //保存已租用車輛的集合。
        Dictionary<string, Vehicle> alreadyRent = new Dictionary<string, Vehicle>();
        //構造出兩輛小汽車、卡車在Lind事件中調用
        public void LoadData() 
        {

            Car Car = new Car("奧迪A8", "京R00544", "黑色", 3, 240);
            Truck truck = new Truck("東風", "京A9988770", "藍色", 3, 300, 240);
            notRent.Add(truck.LicenseNo, truck);
            notRent.Add(Car.LicenseNo, Car);

           
            //出租出去的車
            Car rentCar = new Car("奧A001","東風","紅色",3,200);
            rentCar.RentUser = tbPeople.Text;
            Truck rentTruck = new Truck("京B111","寶馬","紅色",3,200,300);
            alreadyRent.Add(rentCar.LicenseNo,rentCar);
            alreadyRent.Add(rentTruck.LicenseNo, rentTruck);

        }
        private void FrmMain_Load(object sender, EventArgs e)
        {
            //將數據載入到集合中
            LoadData();
            //預設我的大卡車載重不能用
            tbBigCar.Enabled = false;
        }

        private void btNew_Click(object sender, EventArgs e)
        {
            //刷新租車          控制項的名字
            MyRefresh(notRent, ListCar);
        }
        //刷新租車的按鈕調用的方法
        public void MyRefresh(Dictionary<string, Vehicle> rnotrent, ListView lvshow) 
        {
            //list(汽車)進行清空
            ListCar.Items.Clear();
            foreach (Vehicle item in rnotrent.Values)
            {
                //ListView  添加值
                ListViewItem lvitem = new ListViewItem(item.LicenseNo);
                if (item is Car)
                {
                    lvitem.SubItems.Add(item.Name);
                    lvitem.SubItems.Add(item.Color);
                    lvitem.SubItems.Add(item.YearsOfService.ToString());
                    lvitem.SubItems.Add(item.DailyRent.ToString());
                }
                if (item is Truck)
                {
                    lvitem.SubItems.Add(item.Name);
                    lvitem.SubItems.Add(item.Color);
                    lvitem.SubItems.Add(item.YearsOfService.ToString());
                    lvitem.SubItems.Add(item.DailyRent.ToString());
                    lvitem.SubItems.Add(((Truck)item).Load.ToString());
                }
                lvshow.Items.Add(lvitem);
            }

        }

        private void btCar_Click(object sender, EventArgs e)
        {
            //判斷是否寫租車人的名稱
            if (tbPeople.Text=="")
            {
                MessageBox.Show("請輸入租車人名稱");
                return;
            }
            //從可租車輛集合中移除車輛A
            //將A添加到已租車輛集合中
            if (ListCar.SelectedItems.Count>0)
            {
                //??看看
                string number = ListCar.SelectedItems[0].SubItems[0].Text;
                Vehicle ve=notRent[number];
                notRent.Remove(number);
                MyRefresh(notRent,ListCar);
                alreadyRent.Add(number,ve);
                MessageBox.Show("租車成功");
            }
        }

        private void btreturnCar_Click(object sender, EventArgs e)
        {
            //用於保存已租的車輛     控制項名
            MyRefresh(alreadyRent, listReturn);
        }

        private void btSelect_Click(object sender, EventArgs e)
        {
            //判斷
            if (tbDay.Text=="")
            {
                MessageBox.Show("請輸入租車時間");
                return;
            }
            //將車A從一組集合中移除
            //將車A加入到可租車輛中
            string number = listReturn.SelectedItems[0].SubItems[0].Text;
            Vehicle ve=alreadyRent[number];
            alreadyRent.Remove(number);
            MyRefresh(alreadyRent,listReturn);
            notRent.Add(number,ve);
            ve.RentDate = Convert.ToInt32(tbDay.Text);
            double money = 0;
            money = ve.CalcPrice();
            MessageBox.Show("您需要支付" + money + "元");
            
        }

        private void btPut_Click(object sender, EventArgs e)
        {
            string lincesNo = tbCarNum.Text;
            string name = tbType.Text;
            string color = cbClor.Text;
            int time = Convert.ToInt32(tbTime.Text);
            double dailyRent = Convert.ToInt32(tbDayMoney.Text);
            if (rbSmallCar.Checked)
            {
                Car car = new Car(lincesNo, name, color, time, dailyRent);
                notRent.Add(lincesNo,car);

            }
            if (rbBigCar.Checked)
            {
                 int load = Convert.ToInt32(tbBigCar.Text);
                Truck truck = new Truck(lincesNo, name, color, time, dailyRent, load);
                notRent.Add(lincesNo, truck);
            }
            MessageBox.Show("添加成功。。。。。。");
        }

        private void rbSmallCar_CheckedChanged(object sender, EventArgs e)
        {
            tbBigCar.Enabled = false;
        }

        private void rbBigCar_CheckedChanged(object sender, EventArgs e)
        {
            tbBigCar.Enabled = true;
        }

        private void btExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }

  這個程式完畢了,也許會有瑕疵,希望我能不斷進步。

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • · 代碼段。這個功能很早就知道了,Framework已經提供了很多代碼段,我們也可以自定義代碼段,不過之前一直沒有用過,今天實踐了一下,還是挺有意思的,這種代碼自動生成的思想其實挺有用的。另外發現一點,Framework中提供的代碼段中,關於C#和VB的數量明顯不一樣,不知道為啥C#要少呢?上網查了
  • 更新日線,是一項我們經常遇到的數據導入功能。 這項功能的說明文字,我是這麼寫的: 用戶在初次使用本系統的時候,需要安裝滬深兩市從開市到本年度的所有歷史數據,這些數據可以從某證券行情軟體獲得,是遵循一定格式的二進位文件。此後,每天兩市交易結束之後,用戶必須更新當天的日線行情,當然,用戶也可能在幾天後一
  • 這些東西是基礎中的基礎,基本上是本書都會講這個。但是很多東西到處都有,所以只撿了以下的這些寫下來。 關於類型的可見性和可訪問性 也就是public,internal這種東西,但是還是有個東西要提一下,那就是友元程式集。 利用System.Runtime.CompilerServices中的Inter
  • 自己編寫Mvvm模式代碼實現一個簡單的登陸畫面。涉及到了INotifyPropertyChanged的實現,ICommand的實現。最重要的還有Xbind
  • 這幾天開始新項目,在AbstractDalFactory反射實例的時候,遇到的問題是load程式集成功,但是Create實例為null. 被反射的程式集名稱和命名空間都為s2s.Dal, 剛開始我在想,會不會是中間的有個點 . 的問題,轉而一想不可能啊,因為我AutoFac依賴註入s2s.BLL對象
  • 最近學習了繼承,多態,集合,設計模式,有一個汽車租憑系統,給大家分享一下: 我們首先來看看我們這個系統的效果 1.做一個項目,我們首先對項目進行分析 根據我們最近學的知識,我們可以看出繼承,多態,集合,設計模式,我們都能用到 我們把所需要的類和簡單模式中的“簡單工廠”的工廠準備好 類圖: 01.車輛
  • 一、系統窗體 1)vehic類 //父類 汽車類 public abstract class Vehicle { //汽車牌照 public string CarID { get; set; } //汽車名 public string Name { get; set; } //顏色 public s
  • 最近在維護一位離職的同事寫的WPF代碼,偶然發現他使用C# string類型的兩個問題,在這裡記錄一下。 1. 使用Trim函數移除字串中的空格、換行符等字元串。 csRet.Trim(new char[] { '\r', '\n', '\t', ' ' });if (!csRet.Equals(s
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...