Do you know the key points of the car rental system ?, Key points of the vehicle rental system

Source: Internet
Author: User

Do you know the key points of the car rental system ?, Key points of the vehicle rental system

Vehicle rental system

The main interface is as follows:

 

Key Aspect 1: How to clarify the relationships between classes?

Four classes are required: Car class, Truck class, Vehicle class, And VehicleUtil class.

Car: small cars mainly include the calculation method of Car price.

Truck: Calculation of Freight Car fees

Vehicle: Describes basic information about a Vehicle.

VehicleUtil class: tool class for creating car objects

The following is a class diagram:

Key Aspect 2: Car Rental

There must be two verifications: "Enter the lessor name verification" and "select a vehicle verification". The Code is as follows:

 

1 if (String.IsNullOrEmpty(this.txt Renter. Text) 2 {3 MessageBox. Show ("enter the name of the taxi owner", "prompt! ", MessageBoxButtons. OK, MessageBoxIcon. information); 4 return; 5} 6 if (this. lvRent. selectedItems. count = 0) 7 {8 MessageBox. show ("select a vehicle", "prompt! ", MessageBoxButtons. OK, MessageBoxIcon. Information); 9}

 

 

The complete code for renting a car is as follows:

 

1 private void btn1__click (object sender, EventArgs e) 2 {3 string key = null; 4 if (String.IsNullOrEmpty(this.txt Renter. text) 5 {6 MessageBox. show ("enter the name of the person renting a car", "prompt! ", MessageBoxButtons. OK, MessageBoxIcon. information); 7 return; 8} 9 if (this. lvRent. selectedItems. count = 0) 10 {11 MessageBox. show ("select a vehicle", "prompt! ", MessageBoxButtons. OK, MessageBoxIcon. information); 12} 13 else14 {15 key = lvRent. selectedItems [0]. text; 16 vehicles [key]. specified user = this.txt Renter. text; 17 incluvehicles. add (vehicles [key]. licenseNO, vehicles [key]); 18 if (vehicles. containsKey (key) 19 {20 vehicles. remove (key); 21} 22 PrintVehicles (vehicles, lvRent); 23 MessageBox. show ("rented. "," Prompt! ", MessageBoxButtons. OK, MessageBoxIcon. Information); 24} 25}

 

Key Aspect 3: Vehicle return

There are still two verification methods at the beginning, with the above pattern.

Verify the key code "select a vehicle" and "Enter the number of days for renting a car:

 

1 if (String.IsNullOrEmpty(this.txt latest date. Text) 2 {3 MessageBox. Show ("Enter the number of days to rent a car", "prompt! ", MessageBoxButtons. OK, MessageBoxIcon. information); 4 return; 5} 6 if (this. lvReturn. selectedItems. count = 0) 7 {8 MessageBox. show ("select a vehicle", "prompt! ", MessageBoxButtons. OK, MessageBoxIcon. Information); 9}

 

The complete vehicle return settlement code is as follows:

1 private void btnCompute_Click (object sender, EventArgs e) 2 {3 double totalPrice = 0; 4 string key = null; 5 if (String.IsNullOrEmpty(this.txt 1_date. text) 6 {7 MessageBox. show ("Enter the number of days for renting a car", "prompt! ", MessageBoxButtons. OK, MessageBoxIcon. information); 8 return; 9} 10 if (this. lvReturn. selectedItems. count = 0) 11 {12 MessageBox. show ("select a vehicle", "prompt! ", MessageBoxButtons. OK, MessageBoxIcon. information); 13} 14 else15 {16 key = lvReturn. selectedItems [0]. text; 17 incluvehicles [key]. interval date = int.Parse(this.txt interval date. text); 18 // call the abstract method 19 totalPrice = incluvehicles [key]. calcPrice (); 20 string msg = string. format ("your total price is {0 }. ", TotalPrice. ToString (); 21 MessageBox. Show (msg," prompt! ", MessageBoxButtons. OK, MessageBoxIcon. information); 22 23 vehicles. add (incluvehicles [key]. licenseNO, incluvehicles [key]); 24 25 if (incluvehicles. containsKey (key) 26 {27 incluvehicles. remove (key); 28} 29 this. printVehicles (incluvehicles, lvReturn); 30} 31}

Key Aspect 4: new car warehouse receiving

Note: When selecting a single button for a car, the truck load text box is unavailable. Select the truck radio button to be available

The key code is as follows:

 

1           if (rdoCar.Checked)2                 {3                     type = "car";4                 }5                 if (rdoTruck.Checked)6                 {7                     type = "truck";8                     load = int.Parse(this.txtLoad.Text);9                 }

 

The complete code for new car warehouse receiving is as follows:

1 private void btnAdd_Click (object sender, EventArgs e) 2 {3 try 4 {5 string LicenseNO = this.txt AutoNum. text; 6 string name = this.txt Name. text; 7 string color = this. cobColor. text; 8 int years = int.Parse(this.txt Years. text); 9 double DailyRent = double.Parse(this.txt le.txt. text); 10 int load = 0; 11 string type = null; 12 if (rdoCar. checked) 13 {14 type = "car"; 15} 16 if (rdoTruck. checked) 17 {18 Type = "truck"; 19 load = int.Parse(this.txt Load. text); 20} 21 Vehicle auto = VehicleUtil. createVehicle (LicenseNO, name, color, years, DailyRent, load, type); 22 vehicles. add (auto. licenseNO, auto); 23 MessageBox. show ("added successfully. "," Prompt! ", MessageBoxButtons. OK, MessageBoxIcon. Information); 24} 25 catch (Exception ex) 26 {27 MessageBox. Show (" the incoming data is incorrect! "," Error! ", MessageBoxButtons. OK, MessageBoxIcon. error); 28} 29 finally30 {31 this.txt AutoNum. text = ""; 32 this.txt leader. text = ""; 33 this.txt Load. text = ""; 34 this.txt Name. text = ""; 35 this.txt updated date. text = ""; 36 this.txt Renter. text = ""; 37 this.txt Years. text = ""; 38} 39}

Key Aspect 5: refresh

First, clear the listView items:

 

1 listView.Items.Clear();

 

The key code for refreshing is as follows:

1 private void PrintVehicles (Dictionary <string, Vehicle> autos, ListView listView) 2 {3 listView. items. clear (); 4 if (autos. count = 0) 5 {6 MessageBox. show ("no data", "prompt! ", MessageBoxButtons. OK, MessageBoxIcon. information); 7} 8 else 9 {10 foreach (Vehicle auto in autos. values) 11 {12 ListViewItem item = new ListViewItem (auto. licenseNO); 13 if (auto is Car) 14 {15 item. subItems. addRange (new string [] {auto. name, auto. color, auto. yearsOfService. toString (), 16 auto. dailyRent. toString (), "NONE"}); 17} 18 if (auto is Truck) 19 {20 item. subItems. addRange (new string [] {auto. name, auto. color, auto. yearsOfService. toString (), 21 auto. dailyRent. toString (), (Truck) auto ). load. toString ()}); 22} 23 listView. items. add (item); 24} 25} 26}

Then, call the method in the button:

1 private void btnQueryRent_Click(object sender, EventArgs e)2         {3             this.PrintVehicles(vehicles, lvRent);4         }

 

Knowledge Review: form value passing

 

Method 1: use the property to pass the value BackGround: ① click the Button to transfer the value in textBox1 in the main form Form1 to textBox2 in Form2. ② Click the button in Form2 to pass the value of textBox in Form2 to the text box of the main form. 1. Define a field in Form2 and encapsulate it as a private string flag; /// <summary> /// receives the passed value /// </summary> public string Flag {get {return flag;} set {flag = value ;}} 2. In the Form1 Button event, instantiate a Form2 form object and assign the value in textBox1 to the Flag in Form2, in this way, you can obtain the value passed in form Form1 in the form Form2 logon event. Code in form: Form1: private void button#click (object sender, EventArgs e) {Form2 f2 = new Form2 (); f2.Flag = textBox1.Text; // encode if (f2.ShowDialog () = DialogResult. OK) {textBox1.Text = f2.Flag;} form: Form2 Load () event private void Form2_Load (object sender, EventArgs e) {textBox1.Text = this. flag;} 3. Pass the value of the child form to the parent form (return). click the button in Form2 to send the value of textBox in Form2 to the Form1. form of the parent form: private void button#click (object sender, EventArgs e) {flag = this. textBox1.Text; // specify this in key fields. dialogResult = DialogResult. OK;} Method 2: Use the constructor in the child form (the value passed by the parent form to the child form, but the value returned by the child form is not implemented yet) 1. Reload the constructor string str = String in the form Form2. empty; // receives the passed value public Form2 (string textValue) {InitializeComponent (); this. str = textValue;} 2. When the main form calls the subform, pass the parameter: the Button event Form2 f2 of the main form Form1 = new Form2 (textBox1.Text); f2.ShowDialog ();

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.