68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Globalization;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace Lab1
|
|||
|
{
|
|||
|
public partial class Form1 : Form
|
|||
|
{
|
|||
|
RadioButton selection = null;
|
|||
|
ParkingType parkingType;
|
|||
|
|
|||
|
public Form1()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
private void CustomerTypeChange_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
selection = (RadioButton)sender;
|
|||
|
if (selection == radioButton1) parkingType = new CustomerParking();
|
|||
|
else parkingType = new StaffParking();
|
|||
|
UpdateValue();
|
|||
|
}
|
|||
|
|
|||
|
private void HoursEntered_TextChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
UpdateValue();
|
|||
|
}
|
|||
|
|
|||
|
private void UpdateValue()
|
|||
|
{
|
|||
|
string hoursEnteredText = hoursEntered.Text.Length > 0 ? hoursEntered.Text : "0";
|
|||
|
try
|
|||
|
{
|
|||
|
totalValue.Text = parkingType.Calculate(Convert.ToDecimal(hoursEnteredText)).ToString("C", CultureInfo.GetCultureInfo("en-NZ"));
|
|||
|
WarningLabel.Visible = false;
|
|||
|
}
|
|||
|
catch (ParkingException ex)
|
|||
|
{
|
|||
|
WarningLabel.Visible = true;
|
|||
|
totalValue.Text = "$-.--";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void HoursEntered_KeyPress(object sender, KeyPressEventArgs e)
|
|||
|
{
|
|||
|
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
|
|||
|
(e.KeyChar != '.'))
|
|||
|
{
|
|||
|
e.Handled = true;
|
|||
|
}
|
|||
|
|
|||
|
// only allow one decimal point
|
|||
|
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
|
|||
|
{
|
|||
|
e.Handled = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|