<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Story Board</title>
<script type="text/javascript">
var scene = 0;
function changeImg(num)
{
if (scene==0)
{
alert("Your journey begins at a fork in the road.");
scene=1;
}
else if (scene==1)
{
if(num==1)
{
alert("You have arrived at a cute little house in the woods.");
scene=2;
}
else if (num ==2)
{
alert("You are standing on the bridge overlooking a peaceful stream.");
scene=3;
}
}
else if (scene==2)
{
if(num==1)
{
alert("Peeking through the window, you see a witch inside the house.");
scene=4;
}
else if (num ==2)
{
alert("Sorry, a witch lives in the house and you just became part of her stew.");
scene=5;
}
}
else if (scene==4)
{
if(num==1)
{
scene=8;
}
else if (num ==2)
{
alert("Sorry, a witch lives in the house and you just became part of her stew.");
scene=5;
}
}
else if (scene==5)
{
scene=0;
}
else if (scene==3)
{
if(num==1)
{
alert("Sorry, a troll lives on the other side of the bridge and you just became his lunch.");
scene=6;
}
else if (num ==2)
{
alert("Your stare is interrupted by the arrival of a huge troll.");
scene=7;
}
}
else if (scene==6)
{
scene=0;
}
else if (scene==7)
{
if(num==1)
{
alert("Sorry, a troll lives on the other side of the bridge and you just became his lunch.");
scene=6;
}
else if (num ==2)
{
scene=9;
}
}
document.getElementById("img").src ="scene"+scene+".png";
}
</script>
</head>
<body>
<div style="margin: 0 auto; text-align:center">
<img src="scene0.png" alt="Choose your path" id="img"/>
<br />
<input type="button" id="decision1" value="1" onclick="changeImg(1)" />
<input type="button" id="decision2" value="2" onclick="changeImg(2)" />
</div>
</body>
</html>
Wednesday, April 29, 2009
Stick Figure Storyboard with Javascript
Assume that all pictures are in the same folder with the HTML page...
Monday, April 27, 2009
Phonebook for Shanti - 27/04
I made use of 3 forms for this question.
FORM 1:
The first form contains all the buttons for the Phonebook application.

The code for FORM 1 is as follows:
FORM 2:
The second form will enable the user to enter name and phone number in the Phonebook.

Code is as follows:
FORM 3:
The third and last form enables the user to enter a phone number for the purpose of modifying an existing contact's phone number.

Code is as follows:
FORM 1:
The first form contains all the buttons for the Phonebook application.

The code for FORM 1 is as follows:
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 PhoneProgram
{
public partial class frmAddressBook : Form
{
public static int iCount = 0;
public static string[,] sName = { { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" } };
public static string sFriendModify = "";
frmAddForm addForm = new frmAddForm();
Prompt promptForm = new Prompt();
public frmAddressBook()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
addForm.ShowDialog();
cmbName.Items.Clear();
//add new items
for (int i = 0; i < 10; i++)
{
if ((sName[i, 0] != "") || (sName[i, 0] != null))
{
//cmbName.Items.Add(sName[i,0]);
cmbName.Items.Add(sName[i, 0].ToString());
}
}
}
private void btnFind_Click(object sender, EventArgs e)
{
if (cmbName.Text != "")
{
for (int i = 0; i < 10; i++)
{
if (sName[i, 0] == cmbName.Text)
{
MessageBox.Show(sName[i, 0].ToString() + " has phone number " + sName[i, 1].ToString(), sName[i, 0].ToString() + " Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
//reached end of array for search
{
MessageBox.Show(cmbName.Text.ToString() + " was not found. ", cmbName.Text.ToString() + " Not Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show("No friend selected", "Select a Friend to find", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnCount_Click(object sender, EventArgs e)
{
int iFriends = 0;
for (int i = 0; i < 10; i++)
{
if (sName[i, 0] != "")//empty
{
++iFriends;
}
}
MessageBox.Show("You have " + iFriends + " friends in your Address Book.", iFriends.ToString() + " Friends Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void btnModify_Click(object sender, EventArgs e)
{
if (cmbName.Text == "")
{
MessageBox.Show("No friend selected", "No friend selected to modify", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
//modify
sFriendModify = cmbName.Text;
promptForm.ShowDialog();
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (cmbName.Text == "")
{
MessageBox.Show("No friend selected", "No friend selected to modify", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
for (int i = 0; i < 10; i++)
{
if (cmbName.Text == sName[i, 0])
{
cmbName.Items.Remove(sName[i, 0].ToString());
//perform delete
sName[i, 0] = "";
sName[i, 1] = "";
MessageBox.Show("Contact Details deleted", "Contact Details deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
}
}
}
}
FORM 2:
The second form will enable the user to enter name and phone number in the Phonebook.

Code is as follows:
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 PhoneProgram
{
public partial class frmAddForm : Form
{
public frmAddForm()
{
InitializeComponent();
}
private void btnCancel_Click(object sender, EventArgs e)
{
frmAddForm.ActiveForm.Close();
}
private void btnConfirm_Click(object sender, EventArgs e)
{
if (fnValidate() == 0)
{
for (int i = 0; i < 10; i++)
{
if ((frmAddressBook.sName[i, 0] == "") || (frmAddressBook.sName[i, 0] == null)) //empty element
{
frmAddressBook.sName[i, 0] = txtName.Text.Trim();
frmAddressBook.sName[i, 1] = txtPhone.Text.Trim();
txtName.Text = "";
txtPhone.Text = "";
MessageBox.Show("Friend added", "AddressBook Updated", MessageBoxButtons.OK, MessageBoxIcon.Information);
//update combobox
return;
}
}
/* Array Full */
MessageBox.Show("Address Book is Full", "Address Book Full", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/***********************Function Lists *************************/
private int fnValidate()
{
if (txtName.Text == "")
{
MessageBox.Show("Enter a Name", "Name missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtName.Focus();
return -1;
}
if (txtPhone.Text != "")
{
try
{
int iPhoneNum = int.Parse(txtPhone.Text);
if ((txtPhone.Text.Length > 10) || (txtPhone.Text.Length < 8))
{
MessageBox.Show("Phone Number is not valid", "Invalid Phone Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPhone.SelectAll();
return -1;
}
}
catch
{
MessageBox.Show("Phone Number is not valid", "Invalid Phone Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPhone.SelectAll();
return -1;
}
return 0; //success
}
else
{
MessageBox.Show("Enter a Phone Number", "Enter Phone Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPhone.Focus();
return -1;
}
}
}
}
FORM 3:
The third and last form enables the user to enter a phone number for the purpose of modifying an existing contact's phone number.

Code is as follows:
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 PhoneProgram
{
public partial class Prompt : Form
{
public Prompt()
{
InitializeComponent();
}
private void btnModify_Click(object sender, EventArgs e)
{
if (txtPhoneNum.Text != "")
{
try
{
int iPhoneNum = int.Parse(txtPhoneNum.Text);
if ((txtPhoneNum.Text.Length > 10) || (txtPhoneNum.Text.Length < 8))
{
MessageBox.Show("Phone Number is not valid", "Invalid Phone Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPhoneNum.SelectAll();
return;
}
}
catch
{
MessageBox.Show("Phone Number is not valid", "Invalid Phone Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPhoneNum.SelectAll();
return;
}
//modify phone number
for (int i = 0; i < 10 ; i++)
{
if (frmAddressBook.sName[i, 0] == frmAddressBook.sFriendModify)
{
frmAddressBook.sName[i, 1] = txtPhoneNum.ToString().Trim();
MessageBox.Show(frmAddressBook.sName[i, 0].ToString() + ", Phone Number is updated to " + txtPhoneNum.Text.ToString(), "Phone Number Updated", MessageBoxButtons.OK, MessageBoxIcon.Information);
Prompt.ActiveForm.Close();
}
}
}
else
{
MessageBox.Show("Enter a Phone Number", "Enter Phone Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPhoneNum.Focus();
return;
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
Prompt.ActiveForm.Close();
}
private void Prompt_Load(object sender, EventArgs e)
{
lblFriendName.Text = frmAddressBook.sFriendModify.ToString();
}
}
}
Saturday, April 18, 2009
Amit's NPV, Payback, ROI
Shanti Javascript Holiday Homework
Howdie!
The javascript output is as follows:
0
10
10
0
-5
3
0
NaN
value=54
9=value
0.5
2
0.5
Infinity
-Infinity
NaN
5
NaN
one=2 two=2
one=2 two=1
false
false
false
false
true
true
false
true
true
true
true
false
true
true
false
false
false
true
false
false
null
null
false
0
0
false
0
undefined
undefined
true
false
1
undefined
The HTML code can be found below:
The javascript output is as follows:
0
10
10
0
-5
3
0
NaN
value=54
9=value
0.5
2
0.5
Infinity
-Infinity
NaN
5
NaN
one=2 two=2
one=2 two=1
false
false
false
false
true
true
false
true
true
true
true
false
true
true
false
false
false
true
false
false
null
null
false
0
0
false
0
undefined
undefined
true
false
1
undefined
The HTML code can be found below:
<html>
<head>
</head>
<body>
<pre>
<script type="text/javascript">
document.writeln("1" * "0");
document.writeln("1" + 0);
document.writeln(1 + "0");
document.writeln("1"* "0");
document.writeln(- - -5);
document.writeln(true ? 3 : false ? 5 : 0);
document.writeln("1" * false);
document.writeln("1" * "false");
document.writeln("value=" + 5 + 4);
document.writeln(5 + 4 + "=value");
document.writeln(2/4);
document.writeln(4.0/2.0);
document.writeln(2.0/4);
document.writeln(5/0);
document.writeln(-5/0);
document.writeln(0/0);
document.writeln(+ "5");
document.writeln(+ "a");
var one=1; var two=++one; document.writeln("one=" + one + " two=" + two);
var one=1; var two=one++; document.writeln("one=" + one + " two=" + two);
document.writeln(5==="5");
document.writeln("hello" === "HELLO");
document.writeln(NaN === 5);
document.writeln(NaN === NaN);
document.writeln(null===null);
document.writeln(undefined===undefined);
document.writeln(null===undefined);
document.writeln(null==undefined);
document.writeln("1" == true);
document.writeln("1" ==1);
document.writeln(1==true);
document.writeln("Z" < "A");
document.writeln("Z" < "a");
document.writeln("Zelda" < "Zoo");
document.writeln("zelda" < "Zoo");
document.writeln(true < 1);
document.writeln(1 < "true");
document.writeln("11" < "3");
document.writeln("11" < 3);
document.writeln("one" <3);
document.writeln(null && true);
document.writeln(null && false);
document.writeln(false && null);
document.writeln(0 && true);
document.writeln(0 && false);
document.writeln(false && 0);
document.writeln(true && 0);
document.writeln("" && true);
document.writeln("" && false);
document.writeln(undefined && true);
document.writeln(undefined && false);
document.writeln(!!5);
document.writeln(!!null);
document.writeln(null ? 0 : 1);
document.writeln(void (1+2));
</script>
</pre>
</body>
</html>
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);
}
}
}
}
Monday, April 6, 2009
Pizza Hot!
Free publicity to the pizza house :)

Some interesting things I found while doing this:
1) Scroll bar required when the order list is too long
2) Window should resize on Adding a pizza to the order
Everything is in the code. It might be confusing so let me know if you need some help on that.
PS: I am using some methods/functions. They work like events, so I don't think you'll struggle with understanding that :)
Some interesting things I found while doing this:
1) Scroll bar required when the order list is too long
2) Window should resize on Adding a pizza to the order
Everything is in the code. It might be confusing so let me know if you need some help on that.
PS: I am using some methods/functions. They work like events, so I don't think you'll struggle with understanding that :)
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
int[] iPostCode = { 2000, 2002, 2312, 2492, 2121, 2765};
string[] sSuburb = { "City", "Chippendale", "Rose Hill", "Balmain", "Edgecliff", "Bondi" };
int[] iPizzaQuantity = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int iOrder = 0;
string sPizzaOrdered= "";
double dPizzaPrice = 0.0;
double dTotalAmount = 0.0;
string sPizzaExtras = "";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
fnClearForm();
fnLoadDefaultValues();
}
/* Update Suburb on PostCode change */
private void cmbPostCode_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < iPostCode.Length; i++)
{
if (iPostCode[i].ToString() == cmbPostCode.Text)
{
txtSuburb.Text = sSuburb[i];
}
}
}
private void btnAddPizza_Click(object sender, EventArgs e)
{
if (fnValidateAllFields() == 0)
{
fnResizeMax();
string sOrder = "Order #" + lblOrder.Text + " Date: " + lblDate.Text +
"\n\nClient Name: " + txtFName.Text + " " + txtLName.Text ;
double dPizzaCost = fnCountPizzaCost();
dTotalAmount += dPizzaCost;
string sDetails = cmbQuantity.Text.ToString() + " - " + sPizzaOrdered + " - $" + dPizzaCost;
sDetails += "\n" + sPizzaExtras;
lblPizzaSummary.Text +="\n\n" + sDetails;
lblResult.Text = sOrder;
sPizzaExtras = ""; //reset the pizza toppings and extra
lblSubTotal.Text = dTotalAmount.ToString("F2");
lblTax.Text = (dTotalAmount * 0.13).ToString("F2");
lblGrandTotal.Text = (dTotalAmount * 1.13).ToString("F2");
}
}
private void radLarge_CheckedChanged(object sender, EventArgs e)
{
sPizzaOrdered = "Large";
dPizzaPrice = 25;
}
private void radRegular_CheckedChanged(object sender, EventArgs e)
{
sPizzaOrdered = "Regular";
dPizzaPrice = 18;
}
private void radSmall_CheckedChanged(object sender, EventArgs e)
{
sPizzaOrdered = "Small";
dPizzaPrice = 15;
}
private void radPersonal_CheckedChanged(object sender, EventArgs e)
{
sPizzaOrdered = "Personal";
dPizzaPrice = 11;
}
private void btnExit_Click(object sender, EventArgs e)
{
Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
fnClearForm();
fnLoadDefaultValues();
fnResizeMin();
}
private void radVisa_Click(object sender, EventArgs e)
{
MessageBox.Show("Request to see ID and Visa Card", "Visa Verification", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtCC.Enabled = true;
txtCVC.Enabled = true;
dtpExpDate.Enabled = true;
txtCC.BackColor = Color.White;
txtCVC.BackColor = Color.White;
dtpExpDate.BackColor = Color.White;
}
private void radMasterCard_Click(object sender, EventArgs e)
{
MessageBox.Show("Request to see ID and MasterCard", "Mastercard Verification", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtCC.Enabled = true;
txtCVC.Enabled = true;
dtpExpDate.Enabled = true;
txtCC.BackColor = Color.White;
txtCVC.BackColor = Color.White;
dtpExpDate.BackColor = Color.White;
}
private void radDebit_Click(object sender, EventArgs e)
{
MessageBox.Show("Customer may swipe card now", "Debit", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtCC.Enabled = false;
txtCVC.Enabled = false;
dtpExpDate.Enabled = false;
txtCC.BackColor = Color.Black;
txtCVC.BackColor = Color.Black;
dtpExpDate.BackColor = Color.Black;
}
private void radCheque_Click(object sender, EventArgs e)
{
MessageBox.Show("-Please request ID\n-Verify address on Cheque\n-Write LIC # on Cheque\n-Write Phone Number on Cheque", "Cheque Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtCC.Enabled = false;
txtCVC.Enabled = false;
dtpExpDate.Enabled = false;
txtCC.BackColor = Color.Black;
txtCVC.BackColor = Color.Black;
dtpExpDate.BackColor = Color.Black;
}
private void radCash_Click(object sender, EventArgs e)
{
txtCC.Enabled = false;
txtCVC.Enabled = false;
dtpExpDate.Enabled = false;
txtCC.BackColor = Color.Black;
txtCVC.BackColor = Color.Black;
dtpExpDate.BackColor = Color.Black;
}
/******************************* FUNCTIONS LIST ***************************/
private void fnClearForm()
{
txtFName.Clear();
txtLName.Clear();
txtApt.Clear();
txtPhone.Clear();
txtStreet.Clear();
txtSuburb.Clear();
lblDate.Text = "";
chkAnchovies.Checked = false;
chkOnion.Checked = false;
chkPepperoni.Checked = false;
chkSausage.Checked = false;
radCheeseNo.Checked = false;
radCheeseYes.Checked = false;
radLarge.Checked = false;
radPersonal.Checked = false;
radRegular.Checked = false;
radSmall.Checked = false;
cmbQuantity.Items.Clear();
cmbPostCode.Items.Clear();
lblResult.Text = "";
lblPizzaSummary.Text = "";
sPizzaExtras = "";
lblSubTotal.Text = "";
lblTax.Text = "";
lblGrandTotal.Text = "";
dTotalAmount = 0;
txtCC.Enabled = false;
txtCVC.Enabled = false;
dtpExpDate.Enabled = false;
txtCC.BackColor = Color.Black;
txtCVC.BackColor = Color.Black;
dtpExpDate.BackColor = Color.Black;
}
private void fnLoadDefaultValues()
{
lblDate.Text = DateTime.Now.ToString();
lblOrder.Text = (++iOrder).ToString();
radCheeseNo.Checked = true;
radCash.Checked = true;
/* Load Combo values for PostCode */
for (int i = 0; i < iPostCode.Length; i++)
{
cmbPostCode.Items.Add(iPostCode[i]);
}
for (int i = 0; i < iPizzaQuantity.Length; i++)
{
cmbQuantity.Items.Add(iPizzaQuantity[i]);
}
}
private int fnValidateAllFields()
{
if (txtFName.Text == "")
{
MessageBox.Show("Enter first name", "Field Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtFName.Focus();
return -1;
}
if (txtLName.Text == "")
{
MessageBox.Show("Enter last name", "Field Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtLName.Focus();
return -1;
}
if (txtApt.Text == "")
{
MessageBox.Show("Enter appartment number", "Field Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtApt.Focus();
return -1;
}
if (txtStreet.Text == "")
{
MessageBox.Show("Enter street address", "Field Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtStreet.Focus();
return -1;
}
if (txtPhone.Text == "")
{
MessageBox.Show("Enter phone number", "Field Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPhone.Focus();
return -1;
}
if (txtSuburb.Text == "")
{
MessageBox.Show("Enter suburb", "Field Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtSuburb.Focus();
return -1;
}
if (cmbPostCode.Text == "")
{
MessageBox.Show("Enter Postcode", "Field Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
cmbPostCode.Focus();
return -1;
}
if (cmbQuantity.Text == "")
{
MessageBox.Show("Enter Quantity", "Field Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
cmbQuantity.Focus();
return -1;
}
if ((chkAnchovies.Checked == false) && (chkOnion.Checked == false) && (chkPepperoni.Checked == false) && (chkSausage.Checked == false))
{
MessageBox.Show("Choose at least 1 topping", "Field Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
chkSausage.Focus();
return -1;
}
return 0; //success
}
private void btnPlaceOrder_Click(object sender, EventArgs e)
{
if (fnValidateAllFields() == -1)
MessageBox.Show("Please click Add Pizza before placing Order", "Order Rejected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
MessageBox.Show("Order has been placed", "Order Confirmed", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private double fnCountPizzaCost()
{
double dPizzaOnlyPrice = int.Parse(cmbQuantity.Text) * dPizzaPrice;
if (chkAnchovies.Checked == true)
{
dPizzaOnlyPrice += 0.75;
sPizzaExtras += "Anchovies\n";
}
if (chkSausage.Checked == true)
{
dPizzaOnlyPrice += 0.75;
sPizzaExtras += "Sausage\n";
}
if (chkPepperoni.Checked == true)
{
dPizzaOnlyPrice += 0.75;
sPizzaExtras += "Pepperoni\n";
}
if (chkOnion.Checked == true)
{
dPizzaOnlyPrice += 0.75;
sPizzaExtras += "Onion\n";
}
if (radCheeseYes.Checked == true)
{
dPizzaOnlyPrice += 0.50;
sPizzaExtras += "Extra Cheese\n";
}
return dPizzaOnlyPrice;
}
private void fnResizeMax()
{
Form1.ActiveForm.Size = new Size(700, 762);
}
private void fnResizeMin()
{
Form1.ActiveForm.Size = new Size(399, 762);
}
}
}
Thursday, April 2, 2009
Assignment due next week - Shanti's Travel Agency
I have uploaded my assignment on my website. It's nothing exceptional, pretty plain but straight to the point. Some plain javascript validations on the form.
http://denisk.webs.com/creative.html
Pages are XHTML & CSS1.2 compliant. What do you think?
http://denisk.webs.com/creative.html
Pages are XHTML & CSS1.2 compliant. What do you think?
C# Classwork - Allan - Book Seat
This question is taxing if you want to validate everything, like check if booking has already made, smoker/non smoker and the seat validation.

Another problem concerns the display of the seat arrangement, as shown in the picture.
Check it out for yourself...

Another problem concerns the display of the seat arrangement, as shown in the picture.
Check it out for yourself...
private void btnBook_Click(object sender, EventArgs e)
{
try{
int iSeatNo = 0;
iSeatNo = int.Parse(txtSeat.Text);
if (iSeatNo <= 10)
{
}
else
{
MessageBox.Show("Seat Number not valid");
txtSeat.Clear();
txtSeat.Focus();
}
if ((iSeatNo <= 5) && (iSeatNo > 0) && (radSmoke.Checked == true))
{
if (book[iSeatNo - 1] == false)
{
book[iSeatNo - 1] = true;
grpSmokingArea.Controls[iSeatNo-1].Text = "BOOKED";
grpSmokingArea.Controls[iSeatNo-1].ForeColor = Color.Red;
lblInfo.Text = "You have booked Seat # " + iSeatNo + " \nin the
Smoking Area";
}
else
{
MessageBox.Show("Seat already taken");
}
}
else if (radSmoke.Checked== true)
{
MessageBox.Show("Seat allowed in non-smoking section only");
txtSeat.Clear();
txtSeat.Focus();
return;
}
/* Non Smoking */
if ((iSeatNo > 5) && (iSeatNo <= 10) && (radNoSmoke.Checked == true))
{
if (book[iSeatNo - 1] == false)
{
book[iSeatNo - 1] = true;
grpNonSmokingArea.Controls[iSeatNo - 6].Text = "BOOKED";
grpNonSmokingArea.Controls[iSeatNo - 6].ForeColor = Color.Red;
lblInfo.Text = "You have booked Seat # " + iSeatNo + " \nin the Non
Smoking Area";
}
else
{
MessageBox.Show("Seat already taken");
}
}
else if (radNoSmoke.Checked== true)
{
MessageBox.Show("Seat allowed in smoking section only");
txtSeat.Clear();
txtSeat.Focus();
return;
}
}
catch
{
MessageBox.Show("Please enter correct Seat Number");
txtSeat.Text = "";
txtSeat.Focus();
}
}
Wednesday, April 1, 2009
Javascript Homework
Here are my homework answers. Anyone managed to find the exact age, without using if-else structures using the Month values?
Question 1,2,3,4
Question 5
Question 1,2,3,4
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<script type="text/javascript">
document.write("<h1>Question 1</h1>");
document.write("Result of 0xab00 + 0xcd = ");
document.write(0xab00 + 0xcd + "<br />");
document.write("Result of 0xff - 0123 = ");
document.write(0xff - 0123 + "<br />");
document.write("<br /><br />"); /* Some Space */
document.write("<h1>Question 2</h1>");
document.write("Result of -4.321 + 55. = ");
document.write(-4.321 + 55. + "<br/>");
document.write("Result of 12e2 - 1e-2 = ");
document.write(12e2 - 1e-2 + "<br/>");
document.write("Result of .5 - 4e-4 = ");
document.write(.5 - 4e-4 + "<br/>");
document.write("<br /><br />"); /* Some Space */
document.write("<h1>Question 3</h1>");
document.write("Result of true * 5 + false * 7 = ");
document.write(true * 5 + false * 7 + "<br/>");
document.write("<br /><br />"); /* Some Space */
document.write("<h1>Question 4 - Create a face</h1>");
document.write("<pre> \"\"\"\"\"\"\"<br />
\"\"\"\"\"\"\"\"\"<br /> --\"\"\" \"\"\"--<br /> <
<.> <.> ><br /> / \\<br />
\\-----/<br /> --\"--<br /></pre>");
document.write("<br /><br />"); /* Some Space */
</script>
</body>
</html>
Question 5
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<p>
Use pop-up boxes to get a name, date of birth (date, month, and year in separate boxes) and
display the name, date of birth, and age on a table.
</p>
<script type="text/javascript">
var name = prompt("Enter name ");
var date = prompt("Enter birth date ");
var month = prompt("Enter birth month ");
var year = prompt("Enter birth year ");
var todate = new Date();
var elapsedYear= todate.getYear();
var currentYear= parseInt(elapsedYear) + 1900;
var age = currentYear - year;
document.write( "<table style=\"border:solid 2px\"'><tr><td>Name<
/td><td>DOB</td><td>Age</td><tr><td>"+ name +
"</td> <td>" + date+"/"+month+ "/" + year +"</td> <td>" + age +
"</td></tr></table>");
</script>
</body>
</html>
Subscribe to:
Posts (Atom)