using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace project10_22
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(152, 152);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 7;
this.button1.Text = "Total cost";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(248, 152);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(64, 20);
this.textBox2.TabIndex = 8;
this.textBox2.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(208, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(136, 24);
this.label3.TabIndex = 20;
this.label3.Text = "$ 0.00 per day";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// checkBox2
//
this.checkBox2.Enabled = false;
this.checkBox2.Location = new System.Drawing.Point(168, 56);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(80, 16);
this.checkBox2.TabIndex = 19;
this.checkBox2.Text = "Automatic";
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
//
// checkBox1
//
this.checkBox1.Enabled = false;
this.checkBox1.Location = new System.Drawing.Point(96, 56);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(48, 16);
this.checkBox1.TabIndex = 18;
this.checkBox1.Text = "Air";
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(96, 88);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(72, 20);
this.textBox1.TabIndex = 17;
this.textBox1.Text = "0";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 88);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 16);
this.label2.TabIndex = 16;
this.label2.Text = "Rent days";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"Ford Taurus",
"Ford Focus",
"Ford Escape"});
this.comboBox1.Location = new System.Drawing.Point(96, 24);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(88, 21);
this.comboBox1.TabIndex = 15;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 16);
this.label1.TabIndex = 14;
this.label1.Text = "Car make";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(360, 196);
this.Controls.Add(this.label3);
this.Controls.Add(this.checkBox2);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Car Rental";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
UpdatePrice();
}
private void checkBox2_CheckedChanged(object sender, System.EventArgs e)
{
UpdatePrice();
}
private void button1_Click(object sender, System.EventArgs e)
{
UpdatePrice();
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
checkBox1.Enabled = true;
checkBox2.Enabled = true;
UpdatePrice();
}
private void UpdatePrice()
{
double price = 0.0;
string make = comboBox1.SelectedItem.ToString();
if(make=="Ford Taurus")
price = 50.0;
else if(make=="Ford Focus")
price = 40.0;
else if(make =="Ford Escape")
price = 60.0;
if(checkBox1.Checked)
price += 2.50;
if(checkBox2.Checked)
price += 7.25;
label3.Text = string.Format("{0:C2} per day",price);
int days = int.Parse(textBox1.Text);
double total = price*days;
textBox2.Text = string.Format("{0:C2}", total);
}
}
}