Thursday, April 9, 2009

Pre-Test :)



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace myPreTest
{
public partial class Form1 : Form
{
int iMin = 0;
int iMax = 0;
string[] sCarModel = { "Dodge Viper", "Ford Mustang", "Ford Thunderbird", "Pontiac Grandprix", "Ford Windstar", "Dodge RAM Van", "Blue Bird Mini Bus" };
int[] iMaxStringNo = { 2, 3, 4, 6, 8, 10, 16 };

public Form1()
{
InitializeComponent();
}

private void btnExit_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Do you really want to close the application?", "Exiting Application", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
Close();
}

}

private void Form1_Load(object sender, EventArgs e)
{

}

private void btnFindCar_Click(object sender, EventArgs e)
{
if (CheckAllFields()) //all fields are valid
{
try
{
iMin = int.Parse(txtMin.Text);
iMax = int.Parse(txtMax.Text);

for (int i = 0; i < sCarModel.Length; i++)
{
if ((iMaxStringNo[i] <= iMax) && (iMaxStringNo[i] >= iMin))
{
string sModelandMax = "" + sCarModel[i] + " - Max: " + iMaxStringNo[i] + " people";
lisModels.Items.Add(sModelandMax);
}
}
}
catch
{
MessageBox.Show("Please enter a integer values for Maximum and Minimum fields", "Integer values required", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

}



}

/******************************* FUNCTION LIST *****************************/
private bool CheckAllFields()
{
if (txtCustomerName.Text == "")
{
MessageBox.Show("Please enter a customer name", "Customer Name missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtCustomerName.Focus();
return false;
}
else if ((txtCustomerName.Text.Contains("0"))||(txtCustomerName.Text.Contains("1"))||(txtCustomerName.Text.Contains("2"))||(txtCustomerName.Text.Contains("3"))||(txtCustomerName.Text.Contains("4"))||(txtCustomerName.Text.Contains("5"))||(txtCustomerName.Text.Contains("6"))||(txtCustomerName.Text.Contains("7"))||(txtCustomerName.Text.Contains("8"))||(txtCustomerName.Text.Contains("9")))
{
MessageBox.Show("Please enter a customer name with Alphabets only", "Customer Name error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtCustomerName.Focus();
return false;
}
else if (txtMin.Text == "")
{
MessageBox.Show("Please enter Minimum passengers", "Minimum Passengers number missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtMin.Focus();
return false;
}
else if (txtMax.Text == "")
{
MessageBox.Show("Please enter Maximum passengers", "Maximum Passengers number missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtMax.Focus();
return false;
}
else
{
return true;
}
}

private void btnReserveCar_Click(object sender, EventArgs e)
{
try
{
if (CheckAllFields() == true)
{
if (lisModels.Text != "")
{
string sResult = "Customer Name: " + txtCustomerName.Text + "\n" +
"Number of Passengers requested: " + iMin + " Minimum, " + iMax + " Maximum\n" +
"Selected Car: " + lisModels.Text;

MessageBox.Show(sResult, "Reservation Made", MessageBoxButtons.OK, MessageBoxIcon.Information);

lblReservations.Text += DateTime.Now.ToShortDateString().ToString() + "\n" + sResult + "\n\n";
}
else
{
MessageBox.Show("Please choose a car model", "No car model selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch
{
MessageBox.Show("Unable to make reservation - Please check all input", "Error in Reservation", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

}
}

No comments:

Post a Comment