Tuesday, August 11, 2009

Final Project code as promised - C#

It only took me 3 months to post...good Lord I need to stop being so busy with life..

Screenshots and code below (all graphics are mine too - P.S. I know - my commentation needs word =0P )


















/*
* File: XtremeCinema
* Description: Final Project (excludes chapt 7 - uploaded chpt 7 as its own project)
* Programmer: Kade
* Source: Used text and website examples as a guide
*/
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 XtremeCinema
{
public partial class xtremeForm : Form
{
//set class variables
decimal rentalRate = 0.0m;
decimal totalRentalRate = 0.0m;
decimal discount = 0.0m;
int customerCount = 0;
decimal subtotal = 0.0m;


public xtremeForm()
{
InitializeComponent();
}

private void calcButton_Click(object sender, EventArgs e)
{
//verify movie text box has data in it and a vhs/dvd radio button is checked
if ((movieTitleTextBox.Text != "") && ((vhsRadioButton.Checked == true) || (dvdRadioButton.Checked == true)))
{
//figure out the rental rate
rentalRate = findRentalRate();

//check to see if member discount is given and calculate special price
if (memberCheckBox.Checked == true)
{
discount = (rentalRate * .10m);
totalRentalRate = (rentalRate - discount);
//add to subtotal
subtotal = subtotal + totalRentalRate;


//displays amount saved, rental fee, and total cost of item
discountTextBox.Text = discount.ToString("C");
rentalFeeTextBox.Text = rentalRate.ToString("C");
costTextBox.Text = totalRentalRate.ToString("C");

//disable user access to member field until it is a new customer (order completed)
memberCheckBox.Enabled = false;
}
else
{
//set regular price and add to subtotal

totalRentalRate = rentalRate;
subtotal = subtotal + totalRentalRate;
//display the rental fee, total cost of item
rentalFeeTextBox.Text = rentalRate.ToString("C");
costTextBox.Text = totalRentalRate.ToString("C");
}


}
else
{
//Displays an error message
MessageBox.Show("You are missing data!", "Insufficient Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

//Method for finding rentalRate

private decimal findRentalRate()
{
decimal rentCost = 0;
//method calculates and returns rental rate

//checks to see if new release rate applies
if (newReleaseCheckBox.Checked == true)
{
//checks to see if vhs new release rate applies
if (vhsRadioButton.Checked == true)
{
rentCost = 2.00m;
return (rentCost);
}
//checks to see if dvd new release rate applies
else
{
rentCost = 3.00m;
return (rentCost);
}
}
else
{
//checks to see if regular vhs rate applies
if (vhsRadioButton.Checked == true)
{
rentCost = 1.80m;
return (rentCost);
}
//checks to see if regular dvd rate applies
else
{
rentCost = 2.50m;
return (rentCost);
}
}


}

private void clearButton_Click(object sender, EventArgs e)
{
//clear fields for next order

movieTitleTextBox.Clear();
vhsRadioButton.Checked = false;
dvdRadioButton.Checked = false;
rentalFeeTextBox.Clear();
discountTextBox.Clear();
costTextBox.Clear();
newReleaseCheckBox.Checked = false;
rentalRate = 0.0m;
discount = 0.0m;


}

private void completeButton_Click(object sender, EventArgs e)
{
//Prompt user verification

DialogResult confirmDialogResult = MessageBox.Show("Start a new order?", "Order complete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

//if the user confirms, all items are cleared

if (confirmDialogResult == DialogResult.Yes)
{

//re-enable the member field for new customer and enable summary
memberCheckBox.Enabled = true;

summaryButton.Enabled = true;

movieTitleTextBox.Clear();
vhsRadioButton.Checked = false;
dvdRadioButton.Checked = false;
rentalFeeTextBox.Clear();
discountTextBox.Clear();
costTextBox.Clear();
memberCheckBox.Checked = false;
newReleaseCheckBox.Checked = false;
rentalRate = 0.0m;
discount = 0.0m;

// Increment customerCount
customerCount++;

}
}

private void summaryButton_Click(object sender, EventArgs e)
{
//Show the SummaryForm

//declaring a variable and instantiating the new object
SummaryForm aSummaryForm = new SummaryForm();


//Load values
aSummaryForm.TotalSales = subtotal;
aSummaryForm.CustomerTotal = customerCount;

//Show the new form
aSummaryForm.ShowDialog();
}

private void exitButton_Click(object sender, EventArgs e)
{
//End the project
this.Close();
}

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
//create new instance of about box
AboutBox1 aboutForm = new AboutBox1();

//Show the new about box
aboutForm.Show();

}

private void colorToolStripMenuItem_Click(object sender, EventArgs e)
{
//Changes form's Forecolor
colorDialog1.Color = this.BackColor;

//Display dialog box
colorDialog1.ShowDialog();

//Assign new color
this.BackColor = colorDialog1.Color;
}

private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
//Change Movie Title's font

//Display dialog box
fontDialog1.ShowDialog();

//set movTitleLbl font
movTitleLbl.Font = fontDialog1.Font;



}

private void lookupButton_Click(object sender, EventArgs e)
{
//Show the AisleForm

//declaring a variable and instantiating the new object
AisleForm anAisleForm = new AisleForm();
//Show the new form
anAisleForm.ShowDialog();

}
}
}


AISLE FORM:

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 XtremeCinema
{
public partial class AisleForm : Form
{
//declare array that holds category locations

string[] locationArray = {"Aisle 1", "Aisle 2", "Aisle 3", "Aisle 4", "Aisle 5", "Back Wall"};

//declare class variables

int indexInteger = 0;

public AisleForm()
{
InitializeComponent();
}

private void searchButton_Click(object sender, EventArgs e)
{
//look up category
indexInteger = genreComboBox.SelectedIndex;
//display location in displayLbl.Text
displayLbl.Text = locationArray[indexInteger];

}

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


SPLASH FORM:
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 XtremeCinema
{
public partial class SplashForm : Form
{
public SplashForm()
{
InitializeComponent();
}

private void timer1_Tick(object sender, EventArgs e)
{
//Close splash screen
this.Close();
}

private void SplashForm_Load(object sender, EventArgs e)
{

}


}
}

SUMMARY FORM:

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 XtremeCinema
{
public partial class SummaryForm : Form
{
//set up local variables
decimal subtotal;
int customerCount;

//setting values in SummaryForm
public decimal TotalSales
{
set
{
subtotal = value;
}

}

public int CustomerTotal
{
set
{
customerCount = value;
}
}



public SummaryForm()
{
InitializeComponent();
}

private void SummaryForm_Activated(object sender, EventArgs e)
{
//display data

totalTextBox.Text = subtotal.ToString("C");
customerTextBox.Text = customerCount.ToString("N");
}

private void okButton_Click(object sender, EventArgs e)
{
//Close summary form
this.Close();
}



}
}

0 comments: